jquery-atwho-rails 1.1.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bower.json +19 -0
- data/lib/assets/javascripts/jquery.atwho/jquery.atwho.js +226 -117
- data/lib/jquery-atwho-rails/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80acb080f644075e726726590ef4844a29fcaaf1
|
4
|
+
data.tar.gz: 738cc9113f6208dd94674f646d77a6decc0b07f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bfd5e521b619a0fb9794c9c03677b6d7dcc27b636da3f8bfda4da0e000818726081880c6a65eca467e2074f5beceb19ca1dc9ecbf49c29b4ae34de11879be78
|
7
|
+
data.tar.gz: 9b2daefbe83e0569098e5e46e8feb61f1540312bea3bf13de4bbf2c1943e7b582af0643b6094fd23a7a09f6aa8bc7803a3f0359faa158d528673abc17d7085d2
|
data/bower.json
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"name": "jquery-atwho-rails",
|
3
|
+
"version": "1.3.2",
|
4
|
+
"homepage": "https://github.com/ichord/jquery-atwho-rails",
|
5
|
+
"authors": [
|
6
|
+
"ichord <chord.luo@gmail.com>"
|
7
|
+
],
|
8
|
+
"license": "MIT",
|
9
|
+
"ignore": [
|
10
|
+
"**/.*",
|
11
|
+
"node_modules",
|
12
|
+
"bower_components",
|
13
|
+
"test",
|
14
|
+
"tests"
|
15
|
+
],
|
16
|
+
"dependencies": {
|
17
|
+
"At.js": "~1.3.0"
|
18
|
+
}
|
19
|
+
}
|
@@ -1,17 +1,17 @@
|
|
1
|
-
/*! jquery.atwho - v1.
|
1
|
+
/*! jquery.atwho - v1.3.2 %>
|
2
2
|
* Copyright (c) 2015 chord.luo <chord.luo@gmail.com>;
|
3
3
|
* homepage: http://ichord.github.com/At.js
|
4
4
|
* Licensed MIT
|
5
5
|
*/
|
6
6
|
(function (root, factory) {
|
7
7
|
if (typeof define === 'function' && define.amd) {
|
8
|
-
// AMD. Register as an anonymous module
|
9
|
-
define(["jquery"], function (
|
10
|
-
return (
|
8
|
+
// AMD. Register as an anonymous module unless amdModuleId is set
|
9
|
+
define(["jquery"], function (a0) {
|
10
|
+
return (factory(a0));
|
11
11
|
});
|
12
12
|
} else if (typeof exports === 'object') {
|
13
13
|
// Node. Does not work with strict CommonJS, but
|
14
|
-
// only CommonJS-like
|
14
|
+
// only CommonJS-like environments that support module.exports,
|
15
15
|
// like Node.
|
16
16
|
module.exports = factory(require("jquery"));
|
17
17
|
} else {
|
@@ -19,10 +19,12 @@
|
|
19
19
|
}
|
20
20
|
}(this, function (jquery) {
|
21
21
|
|
22
|
-
var Api, App, Controller, DEFAULT_CALLBACKS, EditableController, KEY_CODE, Model, TextareaController, View,
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
var $, Api, App, Controller, DEFAULT_CALLBACKS, EditableController, KEY_CODE, Model, TextareaController, View,
|
23
|
+
slice = [].slice,
|
24
|
+
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
25
|
+
hasProp = {}.hasOwnProperty;
|
26
|
+
|
27
|
+
$ = jquery;
|
26
28
|
|
27
29
|
App = (function() {
|
28
30
|
function App(inputor) {
|
@@ -35,9 +37,9 @@ App = (function() {
|
|
35
37
|
}
|
36
38
|
|
37
39
|
App.prototype.createContainer = function(doc) {
|
38
|
-
var
|
39
|
-
if ((
|
40
|
-
|
40
|
+
var ref;
|
41
|
+
if ((ref = this.$el) != null) {
|
42
|
+
ref.remove();
|
41
43
|
}
|
42
44
|
return $(doc.body).append(this.$el = $("<div class='atwho-container'></div>"));
|
43
45
|
};
|
@@ -59,20 +61,22 @@ App = (function() {
|
|
59
61
|
} catch (_error) {
|
60
62
|
error = _error;
|
61
63
|
this.iframe = null;
|
62
|
-
|
64
|
+
if ($.fn.atwho.debug) {
|
65
|
+
throw new Error("iframe auto-discovery is failed.\nPlease use `setIframe` to set the target iframe manually.\n" + error);
|
66
|
+
}
|
63
67
|
}
|
64
68
|
}
|
65
69
|
return this.createContainer((this.iframeAsRoot = asRoot) ? this.document : document);
|
66
70
|
};
|
67
71
|
|
68
72
|
App.prototype.controller = function(at) {
|
69
|
-
var c, current, currentFlag,
|
73
|
+
var c, current, currentFlag, ref;
|
70
74
|
if (this.aliasMaps[at]) {
|
71
75
|
current = this.controllers[this.aliasMaps[at]];
|
72
76
|
} else {
|
73
|
-
|
74
|
-
for (currentFlag in
|
75
|
-
c =
|
77
|
+
ref = this.controllers;
|
78
|
+
for (currentFlag in ref) {
|
79
|
+
c = ref[currentFlag];
|
76
80
|
if (currentFlag === at) {
|
77
81
|
current = c;
|
78
82
|
break;
|
@@ -92,8 +96,8 @@ App = (function() {
|
|
92
96
|
};
|
93
97
|
|
94
98
|
App.prototype.reg = function(flag, setting) {
|
95
|
-
var
|
96
|
-
controller = (
|
99
|
+
var base, controller;
|
100
|
+
controller = (base = this.controllers)[flag] || (base[flag] = this.$inputor.is('[contentEditable]') ? new EditableController(this, flag) : new TextareaController(this, flag));
|
97
101
|
if (setting.alias) {
|
98
102
|
this.aliasMaps[setting.alias] = flag;
|
99
103
|
}
|
@@ -104,9 +108,9 @@ App = (function() {
|
|
104
108
|
App.prototype.listen = function() {
|
105
109
|
return this.$inputor.on('compositionstart', (function(_this) {
|
106
110
|
return function(e) {
|
107
|
-
var
|
108
|
-
if ((
|
109
|
-
|
111
|
+
var ref;
|
112
|
+
if ((ref = _this.controller()) != null) {
|
113
|
+
ref.view.hide();
|
110
114
|
}
|
111
115
|
return _this.isComposing = true;
|
112
116
|
};
|
@@ -122,15 +126,11 @@ App = (function() {
|
|
122
126
|
return function(e) {
|
123
127
|
return _this.onKeydown(e);
|
124
128
|
};
|
125
|
-
})(this)).on('scroll.atwhoInner', (function(_this) {
|
126
|
-
return function(e) {
|
127
|
-
var _ref;
|
128
|
-
return (_ref = _this.controller()) != null ? _ref.view.hide(e) : void 0;
|
129
|
-
};
|
130
129
|
})(this)).on('blur.atwhoInner', (function(_this) {
|
131
130
|
return function(e) {
|
132
131
|
var c;
|
133
132
|
if (c = _this.controller()) {
|
133
|
+
c.expectedQueryCBId = null;
|
134
134
|
return c.view.hide(e, c.getOpt("displayTimeout"));
|
135
135
|
}
|
136
136
|
};
|
@@ -138,14 +138,30 @@ App = (function() {
|
|
138
138
|
return function(e) {
|
139
139
|
return _this.dispatch(e);
|
140
140
|
};
|
141
|
-
})(this))
|
141
|
+
})(this)).on('scroll.atwhoInner', (function(_this) {
|
142
|
+
return function() {
|
143
|
+
var lastScrollTop;
|
144
|
+
lastScrollTop = _this.$inputor.scrollTop();
|
145
|
+
return function(e) {
|
146
|
+
var currentScrollTop, ref;
|
147
|
+
currentScrollTop = e.target.scrollTop;
|
148
|
+
if (lastScrollTop !== currentScrollTop) {
|
149
|
+
if ((ref = _this.controller()) != null) {
|
150
|
+
ref.view.hide(e);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
lastScrollTop = currentScrollTop;
|
154
|
+
return true;
|
155
|
+
};
|
156
|
+
};
|
157
|
+
})(this)());
|
142
158
|
};
|
143
159
|
|
144
160
|
App.prototype.shutdown = function() {
|
145
|
-
var
|
146
|
-
|
147
|
-
for (_ in
|
148
|
-
c =
|
161
|
+
var _, c, ref;
|
162
|
+
ref = this.controllers;
|
163
|
+
for (_ in ref) {
|
164
|
+
c = ref[_];
|
149
165
|
c.destroy();
|
150
166
|
delete this.controllers[_];
|
151
167
|
}
|
@@ -154,32 +170,23 @@ App = (function() {
|
|
154
170
|
};
|
155
171
|
|
156
172
|
App.prototype.dispatch = function(e) {
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
}
|
166
|
-
}, delay);
|
167
|
-
} else {
|
168
|
-
if (c.lookUp(e)) {
|
169
|
-
return _this.setContextFor(c.at);
|
170
|
-
}
|
171
|
-
}
|
172
|
-
};
|
173
|
-
})(this));
|
173
|
+
var _, c, ref, results;
|
174
|
+
ref = this.controllers;
|
175
|
+
results = [];
|
176
|
+
for (_ in ref) {
|
177
|
+
c = ref[_];
|
178
|
+
results.push(c.lookUp(e));
|
179
|
+
}
|
180
|
+
return results;
|
174
181
|
};
|
175
182
|
|
176
183
|
App.prototype.onKeyup = function(e) {
|
177
|
-
var
|
184
|
+
var ref;
|
178
185
|
switch (e.keyCode) {
|
179
186
|
case KEY_CODE.ESC:
|
180
187
|
e.preventDefault();
|
181
|
-
if ((
|
182
|
-
|
188
|
+
if ((ref = this.controller()) != null) {
|
189
|
+
ref.view.hide();
|
183
190
|
}
|
184
191
|
break;
|
185
192
|
case KEY_CODE.DOWN:
|
@@ -199,8 +206,8 @@ App = (function() {
|
|
199
206
|
};
|
200
207
|
|
201
208
|
App.prototype.onKeydown = function(e) {
|
202
|
-
var
|
203
|
-
view = (
|
209
|
+
var ref, view;
|
210
|
+
view = (ref = this.controller()) != null ? ref.view : void 0;
|
204
211
|
if (!(view && view.visible())) {
|
205
212
|
return;
|
206
213
|
}
|
@@ -240,8 +247,15 @@ App = (function() {
|
|
240
247
|
if (!this.controller().getOpt('spaceSelectsMatch') && e.keyCode === KEY_CODE.SPACE) {
|
241
248
|
return;
|
242
249
|
}
|
243
|
-
|
244
|
-
|
250
|
+
if (!this.controller().getOpt('tabSelectsMatch') && e.keyCode === KEY_CODE.TAB) {
|
251
|
+
return;
|
252
|
+
}
|
253
|
+
if (view.highlighted()) {
|
254
|
+
e.preventDefault();
|
255
|
+
view.choose(e);
|
256
|
+
} else {
|
257
|
+
view.hide(e);
|
258
|
+
}
|
245
259
|
break;
|
246
260
|
default:
|
247
261
|
$.noop();
|
@@ -257,11 +271,12 @@ Controller = (function() {
|
|
257
271
|
return (Math.random().toString(16) + "000000000").substr(2, 8) + (new Date().getTime());
|
258
272
|
};
|
259
273
|
|
260
|
-
function Controller(
|
261
|
-
this.app =
|
262
|
-
this.at =
|
274
|
+
function Controller(app1, at1) {
|
275
|
+
this.app = app1;
|
276
|
+
this.at = at1;
|
263
277
|
this.$inputor = this.app.$inputor;
|
264
278
|
this.id = this.$inputor[0].id || this.uid();
|
279
|
+
this.expectedQueryCBId = null;
|
265
280
|
this.setting = null;
|
266
281
|
this.query = null;
|
267
282
|
this.pos = 0;
|
@@ -288,12 +303,12 @@ Controller = (function() {
|
|
288
303
|
|
289
304
|
Controller.prototype.callDefault = function() {
|
290
305
|
var args, error, funcName;
|
291
|
-
funcName = arguments[0], args = 2 <= arguments.length ?
|
306
|
+
funcName = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
292
307
|
try {
|
293
308
|
return DEFAULT_CALLBACKS[funcName].apply(this, args);
|
294
309
|
} catch (_error) {
|
295
310
|
error = _error;
|
296
|
-
return $.error(
|
311
|
+
return $.error(error + " Or maybe At.js doesn't have function " + funcName);
|
297
312
|
}
|
298
313
|
};
|
299
314
|
|
@@ -304,7 +319,7 @@ Controller = (function() {
|
|
304
319
|
}
|
305
320
|
data.push(this);
|
306
321
|
alias = this.getOpt('alias');
|
307
|
-
eventName = alias ?
|
322
|
+
eventName = alias ? name + "-" + alias + ".atwho" : name + ".atwho";
|
308
323
|
return this.$inputor.trigger(eventName, data);
|
309
324
|
};
|
310
325
|
|
@@ -328,7 +343,7 @@ Controller = (function() {
|
|
328
343
|
data = $.extend({}, $li.data('item-data'), {
|
329
344
|
'atwho-at': this.at
|
330
345
|
});
|
331
|
-
return this.callbacks("tplEval").call(this, tpl, data);
|
346
|
+
return this.callbacks("tplEval").call(this, tpl, data, "onInsert");
|
332
347
|
};
|
333
348
|
|
334
349
|
Controller.prototype.renderView = function(data) {
|
@@ -339,46 +354,97 @@ Controller = (function() {
|
|
339
354
|
};
|
340
355
|
|
341
356
|
Controller.arrayToDefaultHash = function(data) {
|
342
|
-
var
|
357
|
+
var i, item, len, results;
|
343
358
|
if (!$.isArray(data)) {
|
344
359
|
return data;
|
345
360
|
}
|
346
|
-
|
347
|
-
for (
|
348
|
-
item = data[
|
361
|
+
results = [];
|
362
|
+
for (i = 0, len = data.length; i < len; i++) {
|
363
|
+
item = data[i];
|
349
364
|
if ($.isPlainObject(item)) {
|
350
|
-
|
365
|
+
results.push(item);
|
351
366
|
} else {
|
352
|
-
|
367
|
+
results.push({
|
353
368
|
name: item
|
354
369
|
});
|
355
370
|
}
|
356
371
|
}
|
357
|
-
return
|
372
|
+
return results;
|
358
373
|
};
|
359
374
|
|
360
375
|
Controller.prototype.lookUp = function(e) {
|
361
|
-
var query,
|
362
|
-
|
363
|
-
|
376
|
+
var query, wait;
|
377
|
+
query = this.catchQuery(e);
|
378
|
+
if (!query) {
|
379
|
+
this.expectedQueryCBId = null;
|
380
|
+
return query;
|
381
|
+
}
|
382
|
+
this.app.setContextFor(this.at);
|
383
|
+
if (wait = this.getOpt('delay')) {
|
384
|
+
this._delayLookUp(query, wait);
|
385
|
+
} else {
|
386
|
+
this._lookUp(query);
|
387
|
+
}
|
388
|
+
return query;
|
389
|
+
};
|
390
|
+
|
391
|
+
Controller.prototype._delayLookUp = function(query, wait) {
|
392
|
+
var now, remaining;
|
393
|
+
now = Date.now ? Date.now() : new Date().getTime();
|
394
|
+
this.previousCallTime || (this.previousCallTime = now);
|
395
|
+
remaining = wait - (now - this.previousCallTime);
|
396
|
+
if ((0 < remaining && remaining < wait)) {
|
397
|
+
this.previousCallTime = now;
|
398
|
+
this._stopDelayedCall();
|
399
|
+
return this.delayedCallTimeout = setTimeout((function(_this) {
|
400
|
+
return function() {
|
401
|
+
_this.previousCallTime = 0;
|
402
|
+
_this.delayedCallTimeout = null;
|
403
|
+
return _this._lookUp(query);
|
404
|
+
};
|
405
|
+
})(this), wait);
|
406
|
+
} else {
|
407
|
+
this._stopDelayedCall();
|
408
|
+
if (this.previousCallTime !== now) {
|
409
|
+
this.previousCallTime = 0;
|
410
|
+
}
|
411
|
+
return this._lookUp(query);
|
412
|
+
}
|
413
|
+
};
|
414
|
+
|
415
|
+
Controller.prototype._stopDelayedCall = function() {
|
416
|
+
if (this.delayedCallTimeout) {
|
417
|
+
clearTimeout(this.delayedCallTimeout);
|
418
|
+
return this.delayedCallTimeout = null;
|
364
419
|
}
|
365
|
-
|
420
|
+
};
|
421
|
+
|
422
|
+
Controller.prototype._generateQueryCBId = function() {
|
423
|
+
return {};
|
424
|
+
};
|
425
|
+
|
426
|
+
Controller.prototype._lookUp = function(query) {
|
427
|
+
var _callback;
|
428
|
+
_callback = function(queryCBId, data) {
|
429
|
+
if (queryCBId !== this.expectedQueryCBId) {
|
430
|
+
return;
|
431
|
+
}
|
366
432
|
if (data && data.length > 0) {
|
367
433
|
return this.renderView(this.constructor.arrayToDefaultHash(data));
|
368
434
|
} else {
|
369
435
|
return this.view.hide();
|
370
436
|
}
|
371
437
|
};
|
372
|
-
this.
|
373
|
-
return query;
|
438
|
+
this.expectedQueryCBId = this._generateQueryCBId();
|
439
|
+
return this.model.query(query.text, $.proxy(_callback, this, this.expectedQueryCBId));
|
374
440
|
};
|
375
441
|
|
376
442
|
return Controller;
|
377
443
|
|
378
444
|
})();
|
379
445
|
|
380
|
-
TextareaController = (function(
|
381
|
-
|
446
|
+
TextareaController = (function(superClass) {
|
447
|
+
extend(TextareaController, superClass);
|
382
448
|
|
383
449
|
function TextareaController() {
|
384
450
|
return TextareaController.__super__.constructor.apply(this, arguments);
|
@@ -451,8 +517,8 @@ TextareaController = (function(_super) {
|
|
451
517
|
|
452
518
|
})(Controller);
|
453
519
|
|
454
|
-
EditableController = (function(
|
455
|
-
|
520
|
+
EditableController = (function(superClass) {
|
521
|
+
extend(EditableController, superClass);
|
456
522
|
|
457
523
|
function EditableController() {
|
458
524
|
return EditableController.__super__.constructor.apply(this, arguments);
|
@@ -491,13 +557,15 @@ EditableController = (function(_super) {
|
|
491
557
|
range = this._getRange();
|
492
558
|
}
|
493
559
|
sel = this.app.window.getSelection();
|
494
|
-
|
495
|
-
|
560
|
+
if (this.ctrl_a_pressed == null) {
|
561
|
+
sel.removeAllRanges();
|
562
|
+
return sel.addRange(range);
|
563
|
+
}
|
496
564
|
};
|
497
565
|
|
498
566
|
EditableController.prototype._movingEvent = function(e) {
|
499
|
-
var
|
500
|
-
return e.type === 'click' || ((
|
567
|
+
var ref;
|
568
|
+
return e.type === 'click' || ((ref = e.which) === KEY_CODE.RIGHT || ref === KEY_CODE.LEFT || ref === KEY_CODE.UP || ref === KEY_CODE.DOWN);
|
501
569
|
};
|
502
570
|
|
503
571
|
EditableController.prototype._unwrap = function(node) {
|
@@ -511,13 +579,23 @@ EditableController = (function(_super) {
|
|
511
579
|
};
|
512
580
|
|
513
581
|
EditableController.prototype.catchQuery = function(e) {
|
514
|
-
var $inserted, $query, index, inserted, lastNode, matched, offset, query, range
|
582
|
+
var $inserted, $query, _range, index, inserted, lastNode, matched, offset, query, range;
|
515
583
|
if (this.app.isComposing) {
|
516
584
|
return;
|
517
585
|
}
|
518
586
|
if (!(range = this._getRange())) {
|
519
587
|
return;
|
520
588
|
}
|
589
|
+
if (e.which === KEY_CODE.CTRL) {
|
590
|
+
this.ctrl_pressed = true;
|
591
|
+
} else if (e.which === KEY_CODE.A) {
|
592
|
+
if (this.ctrl_pressed == null) {
|
593
|
+
this.ctrl_a_pressed = true;
|
594
|
+
}
|
595
|
+
} else {
|
596
|
+
delete this.ctrl_a_pressed;
|
597
|
+
delete this.ctrl_pressed;
|
598
|
+
}
|
521
599
|
if (e.which === KEY_CODE.ENTER) {
|
522
600
|
($query = $(range.startContainer).closest('.atwho-query')).contents().unwrap();
|
523
601
|
if ($query.is(':empty')) {
|
@@ -537,7 +615,7 @@ EditableController = (function(_super) {
|
|
537
615
|
_range.setStart(range.startContainer, offset);
|
538
616
|
if ($(_range.cloneContents()).contents().last().is('.atwho-inserted')) {
|
539
617
|
inserted = $(range.startContainer).contents().get(offset);
|
540
|
-
this._setRange(
|
618
|
+
this._setRange('after', $(inserted).contents().last());
|
541
619
|
}
|
542
620
|
} else if (e.which === KEY_CODE.LEFT && range.startContainer.nodeType === document.TEXT_NODE) {
|
543
621
|
$inserted = $(range.startContainer.previousSibling);
|
@@ -558,7 +636,7 @@ EditableController = (function(_super) {
|
|
558
636
|
matched = this.callbacks("matcher").call(this, this.at, _range.toString(), this.getOpt('startWithSpace'));
|
559
637
|
if ($query.length === 0 && typeof matched === 'string' && (index = range.startOffset - this.at.length - matched.length) >= 0) {
|
560
638
|
range.setStart(range.startContainer, index);
|
561
|
-
$query = $(
|
639
|
+
$query = $('<span/>', this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass('atwho-query');
|
562
640
|
range.surroundContents($query.get(0));
|
563
641
|
lastNode = $query.contents().last().get(0);
|
564
642
|
if (/firefox/i.test(navigator.userAgent)) {
|
@@ -606,7 +684,7 @@ EditableController = (function(_super) {
|
|
606
684
|
|
607
685
|
EditableController.prototype.insert = function(content, $li) {
|
608
686
|
var range, suffix, suffixNode;
|
609
|
-
suffix = (suffix = this.getOpt('suffix')) ? suffix : suffix || "\u00A0";
|
687
|
+
suffix = (suffix = this.getOpt('suffix')) === "" ? suffix : suffix || "\u00A0";
|
610
688
|
this.query.el.removeClass('atwho-query').addClass('atwho-inserted').html(content);
|
611
689
|
if (range = this._getRange()) {
|
612
690
|
range.setEndAfter(this.query.el[0]);
|
@@ -640,7 +718,7 @@ Model = (function() {
|
|
640
718
|
};
|
641
719
|
|
642
720
|
Model.prototype.query = function(query, callback) {
|
643
|
-
var data, searchKey
|
721
|
+
var _remoteFilter, data, searchKey;
|
644
722
|
data = this.fetch();
|
645
723
|
searchKey = this.context.getOpt("searchKey");
|
646
724
|
data = this.context.callbacks('filter').call(this.context, query, data, searchKey) || [];
|
@@ -729,6 +807,10 @@ View = (function() {
|
|
729
807
|
return this.$el.is(":visible");
|
730
808
|
};
|
731
809
|
|
810
|
+
View.prototype.highlighted = function() {
|
811
|
+
return this.$el.find(".cur").length > 0;
|
812
|
+
};
|
813
|
+
|
732
814
|
View.prototype.choose = function(e) {
|
733
815
|
var $li, content;
|
734
816
|
if (($li = this.$el.find(".cur")).length) {
|
@@ -743,7 +825,7 @@ View = (function() {
|
|
743
825
|
};
|
744
826
|
|
745
827
|
View.prototype.reposition = function(rect) {
|
746
|
-
var offset, overflowOffset,
|
828
|
+
var _window, offset, overflowOffset, ref;
|
747
829
|
_window = this.context.app.iframeAsRoot ? this.context.app.window : window;
|
748
830
|
if (rect.bottom + this.$el.height() - $(_window).scrollTop() > $(_window).height()) {
|
749
831
|
rect.bottom = rect.top - this.$el.height();
|
@@ -755,8 +837,8 @@ View = (function() {
|
|
755
837
|
left: rect.left,
|
756
838
|
top: rect.bottom
|
757
839
|
};
|
758
|
-
if ((
|
759
|
-
|
840
|
+
if ((ref = this.context.callbacks("beforeReposition")) != null) {
|
841
|
+
ref.call(this.context, offset);
|
760
842
|
}
|
761
843
|
this.$el.offset(offset);
|
762
844
|
return this.context.trigger("reposition", [offset]);
|
@@ -770,9 +852,7 @@ View = (function() {
|
|
770
852
|
next = this.$el.find('li:first');
|
771
853
|
}
|
772
854
|
next.addClass('cur');
|
773
|
-
return this.$el.
|
774
|
-
scrollTop: Math.max(0, cur.innerHeight() * (next.index() + 2) - this.$el.height())
|
775
|
-
}, 150);
|
855
|
+
return this.scrollTop(Math.max(0, cur.innerHeight() * (next.index() + 2) - this.$el.height()));
|
776
856
|
};
|
777
857
|
|
778
858
|
View.prototype.prev = function() {
|
@@ -783,9 +863,19 @@ View = (function() {
|
|
783
863
|
prev = this.$el.find('li:last');
|
784
864
|
}
|
785
865
|
prev.addClass('cur');
|
786
|
-
return this.$el.
|
787
|
-
|
788
|
-
|
866
|
+
return this.scrollTop(Math.max(0, cur.innerHeight() * (prev.index() + 2) - this.$el.height()));
|
867
|
+
};
|
868
|
+
|
869
|
+
View.prototype.scrollTop = function(scrollTop) {
|
870
|
+
var scrollDuration;
|
871
|
+
scrollDuration = this.context.getOpt('scrollDuration');
|
872
|
+
if (scrollDuration) {
|
873
|
+
return this.$el.animate({
|
874
|
+
scrollTop: scrollTop
|
875
|
+
}, scrollDuration);
|
876
|
+
} else {
|
877
|
+
return this.$el.scrollTop(scrollTop);
|
878
|
+
}
|
789
879
|
};
|
790
880
|
|
791
881
|
View.prototype.show = function() {
|
@@ -824,7 +914,7 @@ View = (function() {
|
|
824
914
|
};
|
825
915
|
|
826
916
|
View.prototype.render = function(list) {
|
827
|
-
var $li, $ul,
|
917
|
+
var $li, $ul, i, item, len, li, tpl;
|
828
918
|
if (!($.isArray(list) && list.length > 0)) {
|
829
919
|
this.hide();
|
830
920
|
return;
|
@@ -832,12 +922,12 @@ View = (function() {
|
|
832
922
|
this.$el.find('ul').empty();
|
833
923
|
$ul = this.$el.find('ul');
|
834
924
|
tpl = this.context.getOpt('displayTpl');
|
835
|
-
for (
|
836
|
-
item = list[
|
925
|
+
for (i = 0, len = list.length; i < len; i++) {
|
926
|
+
item = list[i];
|
837
927
|
item = $.extend({}, item, {
|
838
928
|
'atwho-at': this.context.at
|
839
929
|
});
|
840
|
-
li = this.context.callbacks("tplEval").call(this.context, tpl, item);
|
930
|
+
li = this.context.callbacks("tplEval").call(this.context, tpl, item, "onDisplay");
|
841
931
|
$li = $(this.context.callbacks("highlighter").call(this.context, li, this.context.query.text));
|
842
932
|
$li.data("item-data", item);
|
843
933
|
$ul.append($li);
|
@@ -859,6 +949,7 @@ KEY_CODE = {
|
|
859
949
|
TAB: 9,
|
860
950
|
ENTER: 13,
|
861
951
|
CTRL: 17,
|
952
|
+
A: 65,
|
862
953
|
P: 80,
|
863
954
|
N: 78,
|
864
955
|
LEFT: 37,
|
@@ -873,15 +964,16 @@ DEFAULT_CALLBACKS = {
|
|
873
964
|
beforeSave: function(data) {
|
874
965
|
return Controller.arrayToDefaultHash(data);
|
875
966
|
},
|
876
|
-
matcher: function(flag, subtext, should_startWithSpace) {
|
877
|
-
var match, regexp,
|
967
|
+
matcher: function(flag, subtext, should_startWithSpace, acceptSpaceBar) {
|
968
|
+
var _a, _y, match, regexp, space;
|
878
969
|
flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
879
970
|
if (should_startWithSpace) {
|
880
971
|
flag = '(?:^|\\s)' + flag;
|
881
972
|
}
|
882
973
|
_a = decodeURI("%C3%80");
|
883
974
|
_y = decodeURI("%C3%BF");
|
884
|
-
|
975
|
+
space = acceptSpaceBar ? "\ " : "";
|
976
|
+
regexp = new RegExp(flag + "([A-Za-z" + _a + "-" + _y + "0-9_" + space + "\.\+\-]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi');
|
885
977
|
match = regexp.exec(subtext);
|
886
978
|
if (match) {
|
887
979
|
return match[2] || match[1];
|
@@ -890,10 +982,10 @@ DEFAULT_CALLBACKS = {
|
|
890
982
|
}
|
891
983
|
},
|
892
984
|
filter: function(query, data, searchKey) {
|
893
|
-
var
|
985
|
+
var _results, i, item, len;
|
894
986
|
_results = [];
|
895
|
-
for (
|
896
|
-
item = data[
|
987
|
+
for (i = 0, len = data.length; i < len; i++) {
|
988
|
+
item = data[i];
|
897
989
|
if (~new String(item[searchKey]).toLowerCase().indexOf(query.toLowerCase())) {
|
898
990
|
_results.push(item);
|
899
991
|
}
|
@@ -902,13 +994,13 @@ DEFAULT_CALLBACKS = {
|
|
902
994
|
},
|
903
995
|
remoteFilter: null,
|
904
996
|
sorter: function(query, items, searchKey) {
|
905
|
-
var
|
997
|
+
var _results, i, item, len;
|
906
998
|
if (!query) {
|
907
999
|
return items;
|
908
1000
|
}
|
909
1001
|
_results = [];
|
910
|
-
for (
|
911
|
-
item = items[
|
1002
|
+
for (i = 0, len = items.length; i < len; i++) {
|
1003
|
+
item = items[i];
|
912
1004
|
item.atwho_order = new String(item[searchKey]).toLowerCase().indexOf(query.toLowerCase());
|
913
1005
|
if (item.atwho_order > -1) {
|
914
1006
|
_results.push(item);
|
@@ -960,8 +1052,18 @@ Api = {
|
|
960
1052
|
}
|
961
1053
|
},
|
962
1054
|
isSelecting: function() {
|
963
|
-
var
|
964
|
-
return (
|
1055
|
+
var ref;
|
1056
|
+
return (ref = this.controller()) != null ? ref.view.visible() : void 0;
|
1057
|
+
},
|
1058
|
+
hide: function() {
|
1059
|
+
var ref;
|
1060
|
+
return (ref = this.controller()) != null ? ref.view.hide() : void 0;
|
1061
|
+
},
|
1062
|
+
reposition: function() {
|
1063
|
+
var c;
|
1064
|
+
if (c = this.controller()) {
|
1065
|
+
return c.view.reposition(c.rect());
|
1066
|
+
}
|
965
1067
|
},
|
966
1068
|
setIframe: function(iframe, asRoot) {
|
967
1069
|
this.setupRootElement(iframe, asRoot);
|
@@ -977,7 +1079,7 @@ Api = {
|
|
977
1079
|
};
|
978
1080
|
|
979
1081
|
$.fn.atwho = function(method) {
|
980
|
-
var
|
1082
|
+
var _args, result;
|
981
1083
|
_args = arguments;
|
982
1084
|
result = null;
|
983
1085
|
this.filter('textarea, input, [contenteditable=""], [contenteditable=true]').each(function() {
|
@@ -990,10 +1092,14 @@ $.fn.atwho = function(method) {
|
|
990
1092
|
} else if (Api[method] && app) {
|
991
1093
|
return result = Api[method].apply(app, Array.prototype.slice.call(_args, 1));
|
992
1094
|
} else {
|
993
|
-
return $.error("Method " + method + " does not exist on jQuery.
|
1095
|
+
return $.error("Method " + method + " does not exist on jQuery.atwho");
|
994
1096
|
}
|
995
1097
|
});
|
996
|
-
|
1098
|
+
if (result != null) {
|
1099
|
+
return result;
|
1100
|
+
} else {
|
1101
|
+
return this;
|
1102
|
+
}
|
997
1103
|
};
|
998
1104
|
|
999
1105
|
$.fn.atwho["default"] = {
|
@@ -1013,9 +1119,12 @@ $.fn.atwho["default"] = {
|
|
1013
1119
|
displayTimeout: 300,
|
1014
1120
|
delay: null,
|
1015
1121
|
spaceSelectsMatch: false,
|
1016
|
-
|
1122
|
+
tabSelectsMatch: true,
|
1123
|
+
editableAtwhoQueryAttrs: {},
|
1124
|
+
scrollDuration: 150
|
1017
1125
|
};
|
1018
1126
|
|
1127
|
+
$.fn.atwho.debug = false;
|
1019
1128
|
|
1020
1129
|
|
1021
1130
|
}));
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-atwho-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ichord
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: generator_spec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: |-
|
@@ -47,12 +47,13 @@ executables: []
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
-
- .gitignore
|
50
|
+
- ".gitignore"
|
51
51
|
- Appraisals
|
52
52
|
- Gemfile
|
53
53
|
- LICENSE-MIT
|
54
54
|
- README.md
|
55
55
|
- Rakefile
|
56
|
+
- bower.json
|
56
57
|
- changelog.md
|
57
58
|
- gemfiles/rails30.gemfile
|
58
59
|
- gemfiles/rails30.gemfile.lock
|
@@ -75,17 +76,17 @@ require_paths:
|
|
75
76
|
- lib
|
76
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
78
|
requirements:
|
78
|
-
- -
|
79
|
+
- - ">="
|
79
80
|
- !ruby/object:Gem::Version
|
80
81
|
version: '0'
|
81
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
83
|
requirements:
|
83
|
-
- -
|
84
|
+
- - ">="
|
84
85
|
- !ruby/object:Gem::Version
|
85
86
|
version: '0'
|
86
87
|
requirements: []
|
87
88
|
rubyforge_project: jquery-atwho-rails
|
88
|
-
rubygems_version: 2.4.
|
89
|
+
rubygems_version: 2.4.8
|
89
90
|
signing_key:
|
90
91
|
specification_version: 4
|
91
92
|
summary: 'jquery plugin: @mentions'
|