1 | /* eslint-disable prefer-arrow-callback, func-names, strict, no-var */
|
2 | /* eslint-disable vars-on-top, no-plusplus, no-bitwise, no-multi-assign */
|
3 | /* eslint-disable no-nested-ternary, no-labels, no-restricted-syntax */
|
4 | /* eslint-disable no-continue, import/no-amd, import/no-dynamic-require */
|
5 | /* eslint-disable prefer-template, global-require */
|
6 |
|
7 | define('leven', function () {
|
8 | /*
|
9 | The MIT License (MIT)
|
10 |
|
11 | Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
12 |
|
13 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
14 | of this software and associated documentation files (the "Software"), to deal
|
15 | in the Software without restriction, including without limitation the rights
|
16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17 | copies of the Software, and to permit persons to whom the Software is
|
18 | furnished to do so, subject to the following conditions:
|
19 |
|
20 | The above copyright notice and this permission notice shall be included in
|
21 | all copies or substantial portions of the Software.
|
22 |
|
23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
29 | THE SOFTWARE.
|
30 | */
|
31 |
|
32 | ;
|
33 |
|
34 | var arr = [];
|
35 | var charCodeCache = [];
|
36 |
|
37 | return function (a, b) {
|
38 | if (a === b) {
|
39 | return 0;
|
40 | }
|
41 |
|
42 | var swap = a;
|
43 |
|
44 | // Swapping the strings if `a` is longer than `b` so we know which one is the
|
45 | // shortest & which one is the longest
|
46 | if (a.length > b.length) {
|
47 | a = b;
|
48 | b = swap;
|
49 | }
|
50 |
|
51 | var aLen = a.length;
|
52 | var bLen = b.length;
|
53 |
|
54 | // Performing suffix trimming:
|
55 | // We can linearly drop suffix common to both strings since they
|
56 | // don't increase distance at all
|
57 | // Note: `~-` is the bitwise way to perform a `- 1` operation
|
58 | while (aLen > 0 && (a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen))) {
|
59 | aLen--;
|
60 | bLen--;
|
61 | }
|
62 |
|
63 | // Performing prefix trimming
|
64 | // We can linearly drop prefix common to both strings since they
|
65 | // don't increase distance at all
|
66 | var start = 0;
|
67 |
|
68 | while (start < aLen && (a.charCodeAt(start) === b.charCodeAt(start))) {
|
69 | start++;
|
70 | }
|
71 |
|
72 | aLen -= start;
|
73 | bLen -= start;
|
74 |
|
75 | if (aLen === 0) {
|
76 | return bLen;
|
77 | }
|
78 |
|
79 | var bCharCode;
|
80 | var ret;
|
81 | var tmp;
|
82 | var tmp2;
|
83 | var i = 0;
|
84 | var j = 0;
|
85 |
|
86 | while (i < aLen) {
|
87 | charCodeCache[i] = a.charCodeAt(start + i);
|
88 | arr[i] = ++i;
|
89 | }
|
90 |
|
91 | while (j < bLen) {
|
92 | bCharCode = b.charCodeAt(start + j);
|
93 | tmp = j++;
|
94 | ret = j;
|
95 |
|
96 | for (i = 0; i < aLen; i++) {
|
97 | tmp2 = bCharCode === charCodeCache[i] ? tmp : tmp + 1;
|
98 | tmp = arr[i];
|
99 | ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;
|
100 | }
|
101 | }
|
102 |
|
103 | return ret;
|
104 | };
|
105 | });
|
106 |
|
107 | define('fuzzysearch', function () {
|
108 | /*
|
109 | The MIT License (MIT)
|
110 |
|
111 | Copyright © 2015 Nicolas Bevacqua
|
112 |
|
113 | Permission is hereby granted, free of charge, to any person obtaining a copy of
|
114 | this software and associated documentation files (the "Software"), to deal in
|
115 | the Software without restriction, including without limitation the rights to
|
116 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
117 | the Software, and to permit persons to whom the Software is furnished to do so,
|
118 | subject to the following conditions:
|
119 |
|
120 | The above copyright notice and this permission notice shall be included in all
|
121 | copies or substantial portions of the Software.
|
122 |
|
123 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
124 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
125 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
126 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
127 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
128 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
129 | */
|
130 |
|
131 | ;
|
132 |
|
133 | function fuzzysearch(needle, haystack) {
|
134 | var hlen = haystack.length;
|
135 | var nlen = needle.length;
|
136 | if (nlen > hlen) {
|
137 | return false;
|
138 | }
|
139 | if (nlen === hlen) {
|
140 | return needle === haystack;
|
141 | }
|
142 | outer: for (var i = 0, j = 0; i < nlen; i++) {
|
143 | var nch = needle.charCodeAt(i);
|
144 | while (j < hlen) {
|
145 | if (haystack.charCodeAt(j++) === nch) {
|
146 | continue outer;
|
147 | }
|
148 | }
|
149 | return false;
|
150 | }
|
151 | return true;
|
152 | }
|
153 |
|
154 | return fuzzysearch;
|
155 | });
|
156 |
|
157 | require(['emoji'], function (emoji) {
|
158 | $(window).on('composer:autocomplete:init chat:autocomplete:init', function (e, data) {
|
159 | emoji.init();
|
160 | data.strategies.push(emoji.strategy);
|
161 | });
|
162 | });
|