jquery-atwho-rails 1.3.2 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80acb080f644075e726726590ef4844a29fcaaf1
4
- data.tar.gz: 738cc9113f6208dd94674f646d77a6decc0b07f4
3
+ metadata.gz: 25dacabb78625142ac94373b2d12d7d8fde3090a
4
+ data.tar.gz: 5aeb2f0904ee79152d8e7bcb7e5bdda9aefe0036
5
5
  SHA512:
6
- metadata.gz: 6bfd5e521b619a0fb9794c9c03677b6d7dcc27b636da3f8bfda4da0e000818726081880c6a65eca467e2074f5beceb19ca1dc9ecbf49c29b4ae34de11879be78
7
- data.tar.gz: 9b2daefbe83e0569098e5e46e8feb61f1540312bea3bf13de4bbf2c1943e7b582af0643b6094fd23a7a09f6aa8bc7803a3f0359faa158d528673abc17d7085d2
6
+ metadata.gz: b3dac3daf434ec2d143fdf5990ee5dbdb9929e898e761df9b31137db58feef997fc7d678b76dd6048c354f06e0b09feff261c82a874415666b411b41d66c6ca6
7
+ data.tar.gz: c2b0ac76bf5416ef2efc54f4088229d5e108c96366c0f69fba3353b798022fd206493e63a52b2625a964ab104816e2f82ae37904b902b50fb910c490f6125467
data/Gemfile CHANGED
@@ -1,8 +1,4 @@
1
- if ENV['TRAVIS']
2
- source 'https://rubygems.org'
3
- else
4
- source 'http://ruby.taobao.org'
5
- end
1
+ source 'https://rubygems.org'
6
2
 
7
3
  # Specify your gem's dependencies in jquery-atwho-rails.gemspec
8
4
  gemspec
data/README.md CHANGED
@@ -20,12 +20,24 @@ Issue command line bellow:
20
20
  then It will show in `public/[javascript|stylesheets]/` directory.
21
21
 
22
22
  #### Rails >= 3.1.x
23
- Add this gem in `Gemfile` like this:
24
- `gem jquery-atwho-rails`
23
+ Add this gem in `Gemfile` like this:
25
24
 
26
- then add
27
- ` //= require jquery.atwho ` to `app/assets/javascripts/application.js`
28
- and add ` //=require jquery.atwho ` to `app/assets/stylesheets/applications.css`
25
+ ```ruby
26
+ gem 'jquery-atwho-rails'
27
+ ```
28
+
29
+ add in `app/assets/javascripts/application.js`:
30
+
31
+ ```
32
+ //= require jquery
33
+ //= require jquery.atwho
34
+ ```
35
+
36
+ and in `app/assets/stylesheets/applications.css`:
37
+
38
+ ```
39
+ //=require jquery.atwho
40
+ ```
29
41
 
30
42
  #### History Versions
31
43
  All in [At.js](https://github.com/ichord/At.js) project.
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jquery-atwho-rails",
3
- "version": "1.3.2",
3
+ "version": "1.5.2",
4
4
  "homepage": "https://github.com/ichord/jquery-atwho-rails",
5
5
  "authors": [
6
6
  "ichord <chord.luo@gmail.com>"
@@ -14,6 +14,6 @@
14
14
  "tests"
15
15
  ],
16
16
  "dependencies": {
17
- "At.js": "~1.3.0"
17
+ "At.js": "~1.5.2"
18
18
  }
19
19
  }
@@ -1,8 +1,9 @@
1
- /*! jquery.atwho - v1.3.2 %>
2
- * Copyright (c) 2015 chord.luo <chord.luo@gmail.com>;
3
- * homepage: http://ichord.github.com/At.js
4
- * Licensed MIT
5
- */
1
+ /**
2
+ * at.js - 1.5.4
3
+ * Copyright (c) 2017 chord.luo <chord.luo@gmail.com>;
4
+ * Homepage: http://ichord.github.com/At.js
5
+ * License: MIT
6
+ */
6
7
  (function (root, factory) {
7
8
  if (typeof define === 'function' && define.amd) {
8
9
  // AMD. Register as an anonymous module unless amdModuleId is set
@@ -17,14 +18,110 @@
17
18
  } else {
18
19
  factory(jQuery);
19
20
  }
20
- }(this, function (jquery) {
21
+ }(this, function ($) {
22
+ var DEFAULT_CALLBACKS, KEY_CODE;
21
23
 
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;
24
+ KEY_CODE = {
25
+ ESC: 27,
26
+ TAB: 9,
27
+ ENTER: 13,
28
+ CTRL: 17,
29
+ A: 65,
30
+ P: 80,
31
+ N: 78,
32
+ LEFT: 37,
33
+ UP: 38,
34
+ RIGHT: 39,
35
+ DOWN: 40,
36
+ BACKSPACE: 8,
37
+ SPACE: 32
38
+ };
39
+
40
+ DEFAULT_CALLBACKS = {
41
+ beforeSave: function(data) {
42
+ return Controller.arrayToDefaultHash(data);
43
+ },
44
+ matcher: function(flag, subtext, should_startWithSpace, acceptSpaceBar) {
45
+ var _a, _y, match, regexp, space;
46
+ flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
47
+ if (should_startWithSpace) {
48
+ flag = '(?:^|\\s)' + flag;
49
+ }
50
+ _a = decodeURI("%C3%80");
51
+ _y = decodeURI("%C3%BF");
52
+ space = acceptSpaceBar ? "\ " : "";
53
+ regexp = new RegExp(flag + "([A-Za-z" + _a + "-" + _y + "0-9_" + space + "\'\.\+\-]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi');
54
+ match = regexp.exec(subtext);
55
+ if (match) {
56
+ return match[2] || match[1];
57
+ } else {
58
+ return null;
59
+ }
60
+ },
61
+ filter: function(query, data, searchKey) {
62
+ var _results, i, item, len;
63
+ _results = [];
64
+ for (i = 0, len = data.length; i < len; i++) {
65
+ item = data[i];
66
+ if (~new String(item[searchKey]).toLowerCase().indexOf(query.toLowerCase())) {
67
+ _results.push(item);
68
+ }
69
+ }
70
+ return _results;
71
+ },
72
+ remoteFilter: null,
73
+ sorter: function(query, items, searchKey) {
74
+ var _results, i, item, len;
75
+ if (!query) {
76
+ return items;
77
+ }
78
+ _results = [];
79
+ for (i = 0, len = items.length; i < len; i++) {
80
+ item = items[i];
81
+ item.atwho_order = new String(item[searchKey]).toLowerCase().indexOf(query.toLowerCase());
82
+ if (item.atwho_order > -1) {
83
+ _results.push(item);
84
+ }
85
+ }
86
+ return _results.sort(function(a, b) {
87
+ return a.atwho_order - b.atwho_order;
88
+ });
89
+ },
90
+ tplEval: function(tpl, map) {
91
+ var error, error1, template;
92
+ template = tpl;
93
+ try {
94
+ if (typeof tpl !== 'string') {
95
+ template = tpl(map);
96
+ }
97
+ return template.replace(/\$\{([^\}]*)\}/g, function(tag, key, pos) {
98
+ return map[key];
99
+ });
100
+ } catch (error1) {
101
+ error = error1;
102
+ return "";
103
+ }
104
+ },
105
+ highlighter: function(li, query) {
106
+ var regexp;
107
+ if (!query) {
108
+ return li;
109
+ }
110
+ regexp = new RegExp(">\\s*([^\<]*?)(" + query.replace("+", "\\+") + ")([^\<]*)\\s*<", 'ig');
111
+ return li.replace(regexp, function(str, $1, $2, $3) {
112
+ return '> ' + $1 + '<strong>' + $2 + '</strong>' + $3 + ' <';
113
+ });
114
+ },
115
+ beforeInsert: function(value, $li, e) {
116
+ return value;
117
+ },
118
+ beforeReposition: function(offset) {
119
+ return offset;
120
+ },
121
+ afterMatchFailed: function(at, el) {}
122
+ };
26
123
 
27
- $ = jquery;
124
+ var App;
28
125
 
29
126
  App = (function() {
30
127
  function App(inputor) {
@@ -45,7 +142,7 @@ App = (function() {
45
142
  };
46
143
 
47
144
  App.prototype.setupRootElement = function(iframe, asRoot) {
48
- var error;
145
+ var error, error1;
49
146
  if (asRoot == null) {
50
147
  asRoot = false;
51
148
  }
@@ -58,8 +155,8 @@ App = (function() {
58
155
  this.window = this.document.defaultView || this.document.parentWindow;
59
156
  try {
60
157
  this.iframe = this.window.frameElement;
61
- } catch (_error) {
62
- error = _error;
158
+ } catch (error1) {
159
+ error = error1;
63
160
  this.iframe = null;
64
161
  if ($.fn.atwho.debug) {
65
162
  throw new Error("iframe auto-discovery is failed.\nPlease use `setIframe` to set the target iframe manually.\n" + error);
@@ -112,11 +209,16 @@ App = (function() {
112
209
  if ((ref = _this.controller()) != null) {
113
210
  ref.view.hide();
114
211
  }
115
- return _this.isComposing = true;
212
+ _this.isComposing = true;
213
+ return null;
116
214
  };
117
215
  })(this)).on('compositionend', (function(_this) {
118
216
  return function(e) {
119
- return _this.isComposing = false;
217
+ _this.isComposing = false;
218
+ setTimeout(function(e) {
219
+ return _this.dispatch(e);
220
+ });
221
+ return null;
120
222
  };
121
223
  })(this)).on('keyup.atwhoInner', (function(_this) {
122
224
  return function(e) {
@@ -192,6 +294,7 @@ App = (function() {
192
294
  case KEY_CODE.DOWN:
193
295
  case KEY_CODE.UP:
194
296
  case KEY_CODE.CTRL:
297
+ case KEY_CODE.ENTER:
195
298
  $.noop();
196
299
  break;
197
300
  case KEY_CODE.P:
@@ -266,13 +369,16 @@ App = (function() {
266
369
 
267
370
  })();
268
371
 
372
+ var Controller,
373
+ slice = [].slice;
374
+
269
375
  Controller = (function() {
270
376
  Controller.prototype.uid = function() {
271
377
  return (Math.random().toString(16) + "000000000").substr(2, 8) + (new Date().getTime());
272
378
  };
273
379
 
274
- function Controller(app1, at1) {
275
- this.app = app1;
380
+ function Controller(app, at1) {
381
+ this.app = app;
276
382
  this.at = at1;
277
383
  this.$inputor = this.app.$inputor;
278
384
  this.id = this.$inputor[0].id || this.uid();
@@ -302,12 +408,12 @@ Controller = (function() {
302
408
  };
303
409
 
304
410
  Controller.prototype.callDefault = function() {
305
- var args, error, funcName;
411
+ var args, error, error1, funcName;
306
412
  funcName = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
307
413
  try {
308
414
  return DEFAULT_CALLBACKS[funcName].apply(this, args);
309
- } catch (_error) {
310
- error = _error;
415
+ } catch (error1) {
416
+ error = error1;
311
417
  return $.error(error + " Or maybe At.js doesn't have function " + funcName);
312
418
  }
313
419
  };
@@ -328,11 +434,11 @@ Controller = (function() {
328
434
  };
329
435
 
330
436
  Controller.prototype.getOpt = function(at, default_value) {
331
- var e;
437
+ var e, error1;
332
438
  try {
333
439
  return this.setting[at];
334
- } catch (_error) {
335
- e = _error;
440
+ } catch (error1) {
441
+ e = error1;
336
442
  return null;
337
443
  }
338
444
  };
@@ -374,6 +480,12 @@ Controller = (function() {
374
480
 
375
481
  Controller.prototype.lookUp = function(e) {
376
482
  var query, wait;
483
+ if (e && e.type === 'click' && !this.getOpt('lookUpOnClick')) {
484
+ return;
485
+ }
486
+ if (this.getOpt('suspendOnComposing') && this.app.isComposing) {
487
+ return;
488
+ }
377
489
  query = this.catchQuery(e);
378
490
  if (!query) {
379
491
  this.expectedQueryCBId = null;
@@ -443,6 +555,10 @@ Controller = (function() {
443
555
 
444
556
  })();
445
557
 
558
+ var TextareaController,
559
+ 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; },
560
+ hasProp = {}.hasOwnProperty;
561
+
446
562
  TextareaController = (function(superClass) {
447
563
  extend(TextareaController, superClass);
448
564
 
@@ -451,14 +567,18 @@ TextareaController = (function(superClass) {
451
567
  }
452
568
 
453
569
  TextareaController.prototype.catchQuery = function() {
454
- var caretPos, content, end, query, start, subtext;
570
+ var caretPos, content, end, isString, query, start, subtext;
455
571
  content = this.$inputor.val();
456
572
  caretPos = this.$inputor.caret('pos', {
457
573
  iframe: this.app.iframe
458
574
  });
459
575
  subtext = content.slice(0, caretPos);
460
- query = this.callbacks("matcher").call(this, this.at, subtext, this.getOpt('startWithSpace'));
461
- if (typeof query === "string" && query.length <= this.getOpt('maxLen', 20)) {
576
+ query = this.callbacks("matcher").call(this, this.at, subtext, this.getOpt('startWithSpace'), this.getOpt("acceptSpaceBar"));
577
+ isString = typeof query === 'string';
578
+ if (isString && query.length < this.getOpt('minLen', 0)) {
579
+ return;
580
+ }
581
+ if (isString && query.length <= this.getOpt('maxLen', 20)) {
462
582
  start = caretPos - query.length;
463
583
  end = start + query.length;
464
584
  this.pos = start;
@@ -517,6 +637,10 @@ TextareaController = (function(superClass) {
517
637
 
518
638
  })(Controller);
519
639
 
640
+ var EditableController,
641
+ 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; },
642
+ hasProp = {}.hasOwnProperty;
643
+
520
644
  EditableController = (function(superClass) {
521
645
  extend(EditableController, superClass);
522
646
 
@@ -536,7 +660,7 @@ EditableController = (function(superClass) {
536
660
  if (range == null) {
537
661
  range = this._getRange();
538
662
  }
539
- if (!range) {
663
+ if (!(range && node)) {
540
664
  return;
541
665
  }
542
666
  node = $(node)[0];
@@ -579,22 +703,12 @@ EditableController = (function(superClass) {
579
703
  };
580
704
 
581
705
  EditableController.prototype.catchQuery = function(e) {
582
- var $inserted, $query, _range, index, inserted, lastNode, matched, offset, query, range;
583
- if (this.app.isComposing) {
584
- return;
585
- }
706
+ var $inserted, $query, _range, index, inserted, isString, lastNode, matched, offset, query, query_content, range;
586
707
  if (!(range = this._getRange())) {
587
708
  return;
588
709
  }
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;
710
+ if (!range.collapsed) {
711
+ return;
598
712
  }
599
713
  if (e.which === KEY_CODE.ENTER) {
600
714
  ($query = $(range.startContainer).closest('.atwho-query')).contents().unwrap();
@@ -631,23 +745,45 @@ EditableController = (function(superClass) {
631
745
  if (!this._movingEvent(e)) {
632
746
  $query.removeClass('atwho-inserted');
633
747
  }
748
+ if ($query.length > 0) {
749
+ switch (e.which) {
750
+ case KEY_CODE.LEFT:
751
+ this._setRange('before', $query.get(0), range);
752
+ $query.removeClass('atwho-query');
753
+ return;
754
+ case KEY_CODE.RIGHT:
755
+ this._setRange('after', $query.get(0).nextSibling, range);
756
+ $query.removeClass('atwho-query');
757
+ return;
758
+ }
759
+ }
760
+ if ($query.length > 0 && (query_content = $query.attr('data-atwho-at-query'))) {
761
+ $query.empty().html(query_content).attr('data-atwho-at-query', null);
762
+ this._setRange('after', $query.get(0), range);
763
+ }
634
764
  _range = range.cloneRange();
635
765
  _range.setStart(range.startContainer, 0);
636
- matched = this.callbacks("matcher").call(this, this.at, _range.toString(), this.getOpt('startWithSpace'));
637
- if ($query.length === 0 && typeof matched === 'string' && (index = range.startOffset - this.at.length - matched.length) >= 0) {
766
+ matched = this.callbacks("matcher").call(this, this.at, _range.toString(), this.getOpt('startWithSpace'), this.getOpt("acceptSpaceBar"));
767
+ isString = typeof matched === 'string';
768
+ if ($query.length === 0 && isString && (index = range.startOffset - this.at.length - matched.length) >= 0) {
638
769
  range.setStart(range.startContainer, index);
639
770
  $query = $('<span/>', this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass('atwho-query');
640
771
  range.surroundContents($query.get(0));
641
772
  lastNode = $query.contents().last().get(0);
642
- if (/firefox/i.test(navigator.userAgent)) {
643
- range.setStart(lastNode, lastNode.length);
644
- range.setEnd(lastNode, lastNode.length);
645
- this._clearRange(range);
646
- } else {
647
- this._setRange('after', lastNode, range);
773
+ if (lastNode) {
774
+ if (/firefox/i.test(navigator.userAgent)) {
775
+ range.setStart(lastNode, lastNode.length);
776
+ range.setEnd(lastNode, lastNode.length);
777
+ this._clearRange(range);
778
+ } else {
779
+ this._setRange('after', lastNode, range);
780
+ }
648
781
  }
649
782
  }
650
- if (typeof matched === 'string' && matched.length <= this.getOpt('maxLen', 20)) {
783
+ if (isString && matched.length < this.getOpt('minLen', 0)) {
784
+ return;
785
+ }
786
+ if (isString && matched.length <= this.getOpt('maxLen', 20)) {
651
787
  query = {
652
788
  text: matched,
653
789
  el: $query
@@ -673,6 +809,9 @@ EditableController = (function(superClass) {
673
809
  EditableController.prototype.rect = function() {
674
810
  var $iframe, iframeOffset, rect;
675
811
  rect = this.query.el.offset();
812
+ if (!(rect && this.query.el[0].getClientRects().length)) {
813
+ return;
814
+ }
676
815
  if (this.app.iframe && !this.app.iframeAsRoot) {
677
816
  iframeOffset = ($iframe = $(this.app.iframe)).offset();
678
817
  rect.left += iframeOffset.left - this.$inputor.scrollLeft();
@@ -683,13 +822,23 @@ EditableController = (function(superClass) {
683
822
  };
684
823
 
685
824
  EditableController.prototype.insert = function(content, $li) {
686
- var range, suffix, suffixNode;
825
+ var data, overrides, range, suffix, suffixNode;
826
+ if (!this.$inputor.is(':focus')) {
827
+ this.$inputor.focus();
828
+ }
829
+ overrides = this.getOpt('functionOverrides');
830
+ if (overrides.insert) {
831
+ return overrides.insert.call(this, content, $li);
832
+ }
687
833
  suffix = (suffix = this.getOpt('suffix')) === "" ? suffix : suffix || "\u00A0";
688
- this.query.el.removeClass('atwho-query').addClass('atwho-inserted').html(content);
834
+ data = $li.data('item-data');
835
+ this.query.el.removeClass('atwho-query').addClass('atwho-inserted').html(content).attr('data-atwho-at-query', "" + data['atwho-at'] + this.query.text).attr('contenteditable', "false");
689
836
  if (range = this._getRange()) {
690
- range.setEndAfter(this.query.el[0]);
837
+ if (this.query.el.length) {
838
+ range.setEndAfter(this.query.el[0]);
839
+ }
691
840
  range.collapse(false);
692
- range.insertNode(suffixNode = this.app.document.createTextNode(suffix));
841
+ range.insertNode(suffixNode = this.app.document.createTextNode("" + suffix));
693
842
  this._setRange('after', suffixNode, range);
694
843
  }
695
844
  if (!this.$inputor.is(':focus')) {
@@ -702,6 +851,8 @@ EditableController = (function(superClass) {
702
851
 
703
852
  })(Controller);
704
853
 
854
+ var Model;
855
+
705
856
  Model = (function() {
706
857
  function Model(context) {
707
858
  this.context = context;
@@ -766,18 +917,25 @@ Model = (function() {
766
917
 
767
918
  })();
768
919
 
920
+ var View;
921
+
769
922
  View = (function() {
770
923
  function View(context) {
771
924
  this.context = context;
772
925
  this.$el = $("<div class='atwho-view'><ul class='atwho-view-ul'></ul></div>");
926
+ this.$elUl = this.$el.children();
773
927
  this.timeoutID = null;
774
928
  this.context.$el.append(this.$el);
775
929
  this.bindEvent();
776
930
  }
777
931
 
778
932
  View.prototype.init = function() {
779
- var id;
933
+ var header_tpl, id;
780
934
  id = this.context.getOpt("alias") || this.context.at.charCodeAt(0);
935
+ header_tpl = this.context.getOpt("headerTpl");
936
+ if (header_tpl && this.$el.children().length === 1) {
937
+ this.$el.prepend(header_tpl);
938
+ }
781
939
  return this.$el.attr({
782
940
  'id': "at-view-" + id
783
941
  });
@@ -788,12 +946,26 @@ View = (function() {
788
946
  };
789
947
 
790
948
  View.prototype.bindEvent = function() {
791
- var $menu;
949
+ var $menu, lastCoordX, lastCoordY;
792
950
  $menu = this.$el.find('ul');
793
- return $menu.on('mouseenter.atwho-view', 'li', function(e) {
794
- $menu.find('.cur').removeClass('cur');
795
- return $(e.currentTarget).addClass('cur');
796
- }).on('click.atwho-view', 'li', (function(_this) {
951
+ lastCoordX = 0;
952
+ lastCoordY = 0;
953
+ return $menu.on('mousemove.atwho-view', 'li', (function(_this) {
954
+ return function(e) {
955
+ var $cur;
956
+ if (lastCoordX === e.clientX && lastCoordY === e.clientY) {
957
+ return;
958
+ }
959
+ lastCoordX = e.clientX;
960
+ lastCoordY = e.clientY;
961
+ $cur = $(e.currentTarget);
962
+ if ($cur.hasClass('cur')) {
963
+ return;
964
+ }
965
+ $menu.find('.cur').removeClass('cur');
966
+ return $cur.addClass('cur');
967
+ };
968
+ })(this)).on('click.atwho-view', 'li', (function(_this) {
797
969
  return function(e) {
798
970
  $menu.find('.cur').removeClass('cur');
799
971
  $(e.currentTarget).addClass('cur');
@@ -804,7 +976,7 @@ View = (function() {
804
976
  };
805
977
 
806
978
  View.prototype.visible = function() {
807
- return this.$el.is(":visible");
979
+ return $.expr.filters.visible(this.$el[0]);
808
980
  };
809
981
 
810
982
  View.prototype.highlighted = function() {
@@ -815,7 +987,8 @@ View = (function() {
815
987
  var $li, content;
816
988
  if (($li = this.$el.find(".cur")).length) {
817
989
  content = this.context.insertContentFor($li);
818
- this.context.insert(this.context.callbacks("beforeInsert").call(this.context, content, $li), $li);
990
+ this.context._stopDelayedCall();
991
+ this.context.insert(this.context.callbacks("beforeInsert").call(this.context, content, $li, e), $li);
819
992
  this.context.trigger("inserted", [$li, e]);
820
993
  this.hide(e);
821
994
  }
@@ -845,36 +1018,40 @@ View = (function() {
845
1018
  };
846
1019
 
847
1020
  View.prototype.next = function() {
848
- var cur, next;
1021
+ var cur, next, nextEl, offset;
849
1022
  cur = this.$el.find('.cur').removeClass('cur');
850
1023
  next = cur.next();
851
1024
  if (!next.length) {
852
1025
  next = this.$el.find('li:first');
853
1026
  }
854
1027
  next.addClass('cur');
855
- return this.scrollTop(Math.max(0, cur.innerHeight() * (next.index() + 2) - this.$el.height()));
1028
+ nextEl = next[0];
1029
+ offset = nextEl.offsetTop + nextEl.offsetHeight + (nextEl.nextSibling ? nextEl.nextSibling.offsetHeight : 0);
1030
+ return this.scrollTop(Math.max(0, offset - this.$el.height()));
856
1031
  };
857
1032
 
858
1033
  View.prototype.prev = function() {
859
- var cur, prev;
1034
+ var cur, offset, prev, prevEl;
860
1035
  cur = this.$el.find('.cur').removeClass('cur');
861
1036
  prev = cur.prev();
862
1037
  if (!prev.length) {
863
1038
  prev = this.$el.find('li:last');
864
1039
  }
865
1040
  prev.addClass('cur');
866
- return this.scrollTop(Math.max(0, cur.innerHeight() * (prev.index() + 2) - this.$el.height()));
1041
+ prevEl = prev[0];
1042
+ offset = prevEl.offsetTop + prevEl.offsetHeight + (prevEl.nextSibling ? prevEl.nextSibling.offsetHeight : 0);
1043
+ return this.scrollTop(Math.max(0, offset - this.$el.height()));
867
1044
  };
868
1045
 
869
1046
  View.prototype.scrollTop = function(scrollTop) {
870
1047
  var scrollDuration;
871
1048
  scrollDuration = this.context.getOpt('scrollDuration');
872
1049
  if (scrollDuration) {
873
- return this.$el.animate({
1050
+ return this.$elUl.animate({
874
1051
  scrollTop: scrollTop
875
1052
  }, scrollDuration);
876
1053
  } else {
877
- return this.$el.scrollTop(scrollTop);
1054
+ return this.$elUl.scrollTop(scrollTop);
878
1055
  }
879
1056
  };
880
1057
 
@@ -942,107 +1119,7 @@ View = (function() {
942
1119
 
943
1120
  })();
944
1121
 
945
- KEY_CODE = {
946
- DOWN: 40,
947
- UP: 38,
948
- ESC: 27,
949
- TAB: 9,
950
- ENTER: 13,
951
- CTRL: 17,
952
- A: 65,
953
- P: 80,
954
- N: 78,
955
- LEFT: 37,
956
- UP: 38,
957
- RIGHT: 39,
958
- DOWN: 40,
959
- BACKSPACE: 8,
960
- SPACE: 32
961
- };
962
-
963
- DEFAULT_CALLBACKS = {
964
- beforeSave: function(data) {
965
- return Controller.arrayToDefaultHash(data);
966
- },
967
- matcher: function(flag, subtext, should_startWithSpace, acceptSpaceBar) {
968
- var _a, _y, match, regexp, space;
969
- flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
970
- if (should_startWithSpace) {
971
- flag = '(?:^|\\s)' + flag;
972
- }
973
- _a = decodeURI("%C3%80");
974
- _y = decodeURI("%C3%BF");
975
- space = acceptSpaceBar ? "\ " : "";
976
- regexp = new RegExp(flag + "([A-Za-z" + _a + "-" + _y + "0-9_" + space + "\.\+\-]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi');
977
- match = regexp.exec(subtext);
978
- if (match) {
979
- return match[2] || match[1];
980
- } else {
981
- return null;
982
- }
983
- },
984
- filter: function(query, data, searchKey) {
985
- var _results, i, item, len;
986
- _results = [];
987
- for (i = 0, len = data.length; i < len; i++) {
988
- item = data[i];
989
- if (~new String(item[searchKey]).toLowerCase().indexOf(query.toLowerCase())) {
990
- _results.push(item);
991
- }
992
- }
993
- return _results;
994
- },
995
- remoteFilter: null,
996
- sorter: function(query, items, searchKey) {
997
- var _results, i, item, len;
998
- if (!query) {
999
- return items;
1000
- }
1001
- _results = [];
1002
- for (i = 0, len = items.length; i < len; i++) {
1003
- item = items[i];
1004
- item.atwho_order = new String(item[searchKey]).toLowerCase().indexOf(query.toLowerCase());
1005
- if (item.atwho_order > -1) {
1006
- _results.push(item);
1007
- }
1008
- }
1009
- return _results.sort(function(a, b) {
1010
- return a.atwho_order - b.atwho_order;
1011
- });
1012
- },
1013
- tplEval: function(tpl, map) {
1014
- var error, template;
1015
- template = tpl;
1016
- try {
1017
- if (typeof tpl !== 'string') {
1018
- template = tpl(map);
1019
- }
1020
- return template.replace(/\$\{([^\}]*)\}/g, function(tag, key, pos) {
1021
- return map[key];
1022
- });
1023
- } catch (_error) {
1024
- error = _error;
1025
- return "";
1026
- }
1027
- },
1028
- highlighter: function(li, query) {
1029
- var regexp;
1030
- if (!query) {
1031
- return li;
1032
- }
1033
- regexp = new RegExp(">\\s*(\\w*?)(" + query.replace("+", "\\+") + ")(\\w*)\\s*<", 'ig');
1034
- return li.replace(regexp, function(str, $1, $2, $3) {
1035
- return '> ' + $1 + '<strong>' + $2 + '</strong>' + $3 + ' <';
1036
- });
1037
- },
1038
- beforeInsert: function(value, $li) {
1039
- return value;
1040
- },
1041
- beforeReposition: function(offset) {
1042
- return offset;
1043
- },
1044
- afterMatchFailed: function(at, el) {}
1045
- };
1122
+ var Api;
1046
1123
 
1047
1124
  Api = {
1048
1125
  load: function(at, data) {
@@ -1053,7 +1130,7 @@ Api = {
1053
1130
  },
1054
1131
  isSelecting: function() {
1055
1132
  var ref;
1056
- return (ref = this.controller()) != null ? ref.view.visible() : void 0;
1133
+ return !!((ref = this.controller()) != null ? ref.view.visible() : void 0);
1057
1134
  },
1058
1135
  hide: function() {
1059
1136
  var ref;
@@ -1108,23 +1185,28 @@ $.fn.atwho["default"] = {
1108
1185
  data: null,
1109
1186
  displayTpl: "<li>${name}</li>",
1110
1187
  insertTpl: "${atwho-at}${name}",
1188
+ headerTpl: null,
1111
1189
  callbacks: DEFAULT_CALLBACKS,
1190
+ functionOverrides: {},
1112
1191
  searchKey: "name",
1113
1192
  suffix: void 0,
1114
1193
  hideWithoutSuffix: false,
1115
1194
  startWithSpace: true,
1195
+ acceptSpaceBar: false,
1116
1196
  highlightFirst: true,
1117
1197
  limit: 5,
1118
1198
  maxLen: 20,
1199
+ minLen: 0,
1119
1200
  displayTimeout: 300,
1120
1201
  delay: null,
1121
1202
  spaceSelectsMatch: false,
1122
1203
  tabSelectsMatch: true,
1123
1204
  editableAtwhoQueryAttrs: {},
1124
- scrollDuration: 150
1205
+ scrollDuration: 150,
1206
+ suspendOnComposing: true,
1207
+ lookUpOnClick: true
1125
1208
  };
1126
1209
 
1127
1210
  $.fn.atwho.debug = false;
1128
1211
 
1129
-
1130
1212
  }));
@@ -10,11 +10,32 @@
10
10
  border-radius: 3px;
11
11
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
12
12
  min-width: 120px;
13
- max-height: 200px;
14
- overflow: auto;
15
13
  z-index: 11110 !important;
16
14
  }
17
15
 
16
+ .atwho-view .atwho-header {
17
+ padding: 5px;
18
+ margin: 5px;
19
+ cursor: pointer;
20
+ border-bottom: solid 1px #eaeff1;
21
+ color: #6f8092;
22
+ font-size: 11px;
23
+ font-weight: bold;
24
+ }
25
+
26
+ .atwho-view .atwho-header .small {
27
+ color: #6f8092;
28
+ float: right;
29
+ padding-top: 2px;
30
+ margin-right: -5px;
31
+ font-size: 12px;
32
+ font-weight: normal;
33
+ }
34
+
35
+ .atwho-view .atwho-header:hover {
36
+ cursor: default;
37
+ }
38
+
18
39
  .atwho-view .cur {
19
40
  background: #3366FF;
20
41
  color: white;
@@ -34,6 +55,8 @@
34
55
  list-style:none;
35
56
  padding:0;
36
57
  margin:auto;
58
+ max-height: 200px;
59
+ overflow-y: auto;
37
60
  }
38
61
  .atwho-view ul li {
39
62
  display: block;
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Atwho
3
3
  module Rails
4
- VERSION = '1.3.2'
4
+ VERSION = '1.5.4'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-atwho-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ichord
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-25 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project: jquery-atwho-rails
89
- rubygems_version: 2.4.8
89
+ rubygems_version: 2.6.7
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: 'jquery plugin: @mentions'