-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy pathmentions.js
74 lines (67 loc) · 1.75 KB
/
mentions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var fails = [];
var atwhoConfig = {
at: '@',
data: [],
show_the_at: true,
limit: 10,
callbacks: {
matcher: function(flag, subtext, should_start_with_space) {
var match = '', started = false;
var string = subtext.split('');
for (var i = 0; i < string.length; i++)
{
if (string[i] == flag && (!should_start_with_space || i == 0 || /[\s\n]/gi.test(string[i - 1])))
{
started = true;
match = '';
}
else if (started)
match = match + string[i];
}
if (match.length > 0)
return match;
return null;
},
remoteFilter: function (query, callback) {
if (typeof query == 'undefined' || query.length < 2 || query.length > 60)
return;
for (i in fails)
if (query.substr(0, fails[i].length) == fails[i])
return;
$.ajax({
url: smf_scripturl + '?action=suggest;' + smf_session_var + '=' + smf_session_id + ';xml',
method: 'GET',
headers: {
"X-SMF-AJAX": 1
},
xhrFields: {
withCredentials: typeof allow_xhjr_credentials !== "undefined" ? allow_xhjr_credentials : false
},
data: {
search: query,
suggest_type: 'member'
},
success: function (data) {
var members = $(data).find('smf > items > item');
if (members.length == 0)
fails[fails.length] = query;
var callbackArray = [];
$.each(members, function (index, item) {
callbackArray[callbackArray.length] = {
name: $(item).text()
};
});
callback(callbackArray);
}
});
}
}
};
$(function()
{
$('textarea[name=message]').atwho(atwhoConfig);
$('.sceditor-container').find('textarea').atwho(atwhoConfig);
var iframe = $('.sceditor-container').find('iframe')[0];
if (typeof iframe != 'undefined')
$(iframe.contentDocument.body).atwho(atwhoConfig);
});