-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
70 lines (64 loc) · 3.04 KB
/
script.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
/**
* Autocomplete script for Emoji plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Patrick Brown <[email protected]>
*/
/* DOKUWIKI:include_once script/jquery.textcomplete.js */
+function(){
'use strict';
var byLengthCompare = function(a,b) { return a.length>b.length; };
var sortByLength = function(a) {
return a.sort(byLengthCompare);
};
jQuery(function(){
var $editForm = jQuery('#wiki__text');
if($editForm.length) {
jQuery.getJSON(DOKU_BASE + 'lib/plugins/emoji/assets/emoji_strategy.json',
function(emojiStrategy) {
var assetUri = 'https://cdn.jsdelivr.net/emojione/assets/png/';
var cacheBustParam = '?v=2.2.7';
var langFooter = '<a href="https://www.emojicopy.com" target="_blank"> ' +
LANG.plugins.emoji.browseall +
'<span class="arrow">⧉</span></a>';
if(emoji_assetsrc) {
assetUri = emoji_assetsrc + 'assets/png/';
}
$editForm.textcomplete([{
match: /(^|\s):([\-+]?[\-+\w]+)$/,
index: 2,
/* TODO disable where emoji is not allowed (code blocks, headings, etc)
context: function(text) {
},
*/
search: function(term, addTerm) {
var names = [], aliases = [], keywords = [];
jQuery.each(emojiStrategy, function(shortname, data) {
if(shortname.indexOf(term) > -1) {
names.push(shortname);
} else if((data.aliases !== null) && (data.aliases.indexOf(term) > -1)) {
aliases.push(shortname);
} else if((data.keywords !== null) && (data.keywords.indexOf(term) > -1)) {
keywords.push(shortname);
}
});
if(term.length >= 3) {
sortByLength(names);
sortByLength(aliases);
keywords.sort();
}
addTerm(names.concat(aliases).concat(keywords));
},
template: function(shortname) {
var fileName = assetUri + emojiStrategy[shortname].unicode + '.png' + cacheBustParam;
return '<img class="emojione" src="' + fileName + '"/> :' + shortname + ':';
},
replace: function(shortname) {
return '$1:' + shortname + ': ';
},
cache: true
}], { footer: langFooter });
});
}
});
}();