jquery-atwho-rails 0.4.7 → 0.4.11
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edd22436434bb09eecdc9e926d6a14a1f1f9a177
|
4
|
+
data.tar.gz: bbd43f1b9adf1c0294327d166f7b33d1b5b5a961
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b51f3042fb10491bfb2b09ed3c5df937b9006086a7e40e898111b730c7fc48ae14907ff44214c5ce5daee8c82724b90083f7be603384ac74ae43ab89bb3e879
|
7
|
+
data.tar.gz: d4a0286f34a546f694f46ee7d93b27cf98687db0bc724056129b863804a1b0b0a1d3da21f31da6a996f9dd17c2420db31f50aaeca043a0669152dbe2e6b0644a
|
data/README.md
CHANGED
@@ -22,9 +22,8 @@ Add this gem in `Gemfile` like this:
|
|
22
22
|
`gem jquery-atwho-rails`
|
23
23
|
|
24
24
|
then add
|
25
|
-
` //= require jquery.atwho `
|
26
|
-
to `app/assets/
|
27
|
-
and `app/assets/stylesheets/applications.css`
|
25
|
+
` //= require jquery.atwho/index ` to `app/assets/javascripts/application.js`
|
26
|
+
and add ` //=require jquery.atwho ` to `app/assets/stylesheets/applications.css`
|
28
27
|
|
29
28
|
#### History Versions
|
30
29
|
All in [At.js](https://github.com/ichord/At.js) project.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! jquery.atwho - v0.4.
|
1
|
+
/*! jquery.atwho - v0.4.11 - 2014-04-27
|
2
2
|
* Copyright (c) 2014 chord.luo <chord.luo@gmail.com>;
|
3
3
|
* homepage: http://ichord.github.com/At.js
|
4
4
|
* Licensed MIT
|
@@ -22,9 +22,29 @@ App = (function() {
|
|
22
22
|
this.controllers = {};
|
23
23
|
this.alias_maps = {};
|
24
24
|
this.$inputor = $(inputor);
|
25
|
+
this.iframe = null;
|
26
|
+
this.setIframe();
|
25
27
|
this.listen();
|
26
28
|
}
|
27
29
|
|
30
|
+
App.prototype.setIframe = function(iframe) {
|
31
|
+
var error;
|
32
|
+
if (iframe) {
|
33
|
+
this.window = iframe.contentWindow;
|
34
|
+
this.document = iframe.contentDocument || this.window.document;
|
35
|
+
this.iframe = iframe;
|
36
|
+
return this;
|
37
|
+
} else {
|
38
|
+
this.document = this.$inputor[0].ownerDocument;
|
39
|
+
this.window = this.document.defaultView || this.document.parentWindow;
|
40
|
+
try {
|
41
|
+
return this.iframe = this.window.frameElement;
|
42
|
+
} catch (_error) {
|
43
|
+
error = _error;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
};
|
47
|
+
|
28
48
|
App.prototype.controller = function(at) {
|
29
49
|
return this.controllers[this.alias_maps[at] || at || this.current_flag];
|
30
50
|
};
|
@@ -74,6 +94,7 @@ App = (function() {
|
|
74
94
|
for (_ in _ref) {
|
75
95
|
c = _ref[_];
|
76
96
|
c.destroy();
|
97
|
+
delete this.controllers[_];
|
77
98
|
}
|
78
99
|
return this.$inputor.off('.atwhoInner');
|
79
100
|
};
|
@@ -81,8 +102,18 @@ App = (function() {
|
|
81
102
|
App.prototype.dispatch = function() {
|
82
103
|
return $.map(this.controllers, (function(_this) {
|
83
104
|
return function(c) {
|
84
|
-
|
85
|
-
|
105
|
+
var delay;
|
106
|
+
if (delay = c.get_opt('delay')) {
|
107
|
+
clearTimeout(_this.delayedCallback);
|
108
|
+
return _this.delayedCallback = setTimeout(function() {
|
109
|
+
if (c.look_up()) {
|
110
|
+
return _this.set_context_for(c.at);
|
111
|
+
}
|
112
|
+
}, delay);
|
113
|
+
} else {
|
114
|
+
if (c.look_up()) {
|
115
|
+
return _this.set_context_for(c.at);
|
116
|
+
}
|
86
117
|
}
|
87
118
|
};
|
88
119
|
})(this));
|
@@ -99,8 +130,15 @@ App = (function() {
|
|
99
130
|
break;
|
100
131
|
case KEY_CODE.DOWN:
|
101
132
|
case KEY_CODE.UP:
|
133
|
+
case KEY_CODE.CTRL:
|
102
134
|
$.noop();
|
103
135
|
break;
|
136
|
+
case KEY_CODE.P:
|
137
|
+
case KEY_CODE.N:
|
138
|
+
if (!e.ctrlKey) {
|
139
|
+
this.dispatch();
|
140
|
+
}
|
141
|
+
break;
|
104
142
|
default:
|
105
143
|
this.dispatch();
|
106
144
|
}
|
@@ -125,6 +163,20 @@ App = (function() {
|
|
125
163
|
e.preventDefault();
|
126
164
|
view.next();
|
127
165
|
break;
|
166
|
+
case KEY_CODE.P:
|
167
|
+
if (!e.ctrlKey) {
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
e.preventDefault();
|
171
|
+
view.prev();
|
172
|
+
break;
|
173
|
+
case KEY_CODE.N:
|
174
|
+
if (!e.ctrlKey) {
|
175
|
+
return;
|
176
|
+
}
|
177
|
+
e.preventDefault();
|
178
|
+
view.next();
|
179
|
+
break;
|
128
180
|
case KEY_CODE.TAB:
|
129
181
|
case KEY_CODE.ENTER:
|
130
182
|
if (!view.visible()) {
|
@@ -143,21 +195,15 @@ App = (function() {
|
|
143
195
|
})();
|
144
196
|
|
145
197
|
Controller = (function() {
|
146
|
-
|
147
|
-
|
148
|
-
_uuid = 0;
|
149
|
-
|
150
|
-
uuid = function() {
|
151
|
-
return _uuid += 1;
|
198
|
+
Controller.prototype.uid = function() {
|
199
|
+
return (Math.random().toString(16) + "000000000").substr(2, 8) + (new Date().getTime());
|
152
200
|
};
|
153
201
|
|
154
202
|
function Controller(app, at) {
|
155
203
|
this.app = app;
|
156
204
|
this.at = at;
|
157
205
|
this.$inputor = this.app.$inputor;
|
158
|
-
this.
|
159
|
-
this.oWindow = this.oDocument.defaultView || this.oDocument.parentWindow;
|
160
|
-
this.id = this.$inputor[0].id || uuid();
|
206
|
+
this.id = this.$inputor[0].id || this.uid();
|
161
207
|
this.setting = null;
|
162
208
|
this.query = null;
|
163
209
|
this.pos = 0;
|
@@ -177,7 +223,8 @@ Controller = (function() {
|
|
177
223
|
Controller.prototype.destroy = function() {
|
178
224
|
this.trigger('beforeDestroy');
|
179
225
|
this.model.destroy();
|
180
|
-
|
226
|
+
this.view.destroy();
|
227
|
+
return this.$el.remove();
|
181
228
|
};
|
182
229
|
|
183
230
|
Controller.prototype.call_default = function() {
|
@@ -235,12 +282,13 @@ Controller = (function() {
|
|
235
282
|
end = start + query.length;
|
236
283
|
this.pos = start;
|
237
284
|
query = {
|
238
|
-
'text': query
|
285
|
+
'text': query,
|
239
286
|
'head_pos': start,
|
240
287
|
'end_pos': end
|
241
288
|
};
|
242
289
|
this.trigger("matched", [this.at, query.text]);
|
243
290
|
} else {
|
291
|
+
query = null;
|
244
292
|
this.view.hide();
|
245
293
|
}
|
246
294
|
return this.query = query;
|
@@ -248,13 +296,15 @@ Controller = (function() {
|
|
248
296
|
|
249
297
|
Controller.prototype.rect = function() {
|
250
298
|
var c, scale_bottom;
|
251
|
-
if (!(c = this.$inputor.caret(
|
299
|
+
if (!(c = this.$inputor.caret({
|
300
|
+
iframe: this.app.iframe
|
301
|
+
}).caret('offset', this.pos - 1))) {
|
252
302
|
return;
|
253
303
|
}
|
254
304
|
if (this.$inputor.attr('contentEditable') === 'true') {
|
255
305
|
c = (this.cur_rect || (this.cur_rect = c)) || c;
|
256
306
|
}
|
257
|
-
scale_bottom = document.selection ? 0 : 2;
|
307
|
+
scale_bottom = this.app.document.selection ? 0 : 2;
|
258
308
|
return {
|
259
309
|
left: c.left,
|
260
310
|
top: c.top,
|
@@ -270,11 +320,11 @@ Controller = (function() {
|
|
270
320
|
|
271
321
|
Controller.prototype.mark_range = function() {
|
272
322
|
if (this.$inputor.attr('contentEditable') === 'true') {
|
273
|
-
if (this.
|
274
|
-
this.range = this.
|
323
|
+
if (this.app.window.getSelection) {
|
324
|
+
this.range = this.app.window.getSelection().getRangeAt(0);
|
275
325
|
}
|
276
|
-
if (this.
|
277
|
-
return this.ie8_range = this.
|
326
|
+
if (this.app.document.selection) {
|
327
|
+
return this.ie8_range = this.app.document.selection.createRange();
|
278
328
|
}
|
279
329
|
}
|
280
330
|
};
|
@@ -300,9 +350,9 @@ Controller = (function() {
|
|
300
350
|
class_name = "atwho-view-flag atwho-view-flag-" + (this.get_opt('alias') || this.at);
|
301
351
|
content_node = "" + content + "<span contenteditable='false'> <span>";
|
302
352
|
insert_node = "<span contenteditable='false' class='" + class_name + "'>" + content_node + "</span>";
|
303
|
-
$insert_node = $(insert_node, this.
|
304
|
-
if (this.
|
305
|
-
$insert_node = $("<span contenteditable='true'></span>", this.
|
353
|
+
$insert_node = $(insert_node, this.app.document).data('atwho-data-item', $li.data('item-data'));
|
354
|
+
if (this.app.document.selection) {
|
355
|
+
$insert_node = $("<span contenteditable='true'></span>", this.app.document).html($insert_node);
|
306
356
|
}
|
307
357
|
}
|
308
358
|
if ($inputor.is('textarea, input')) {
|
@@ -319,7 +369,7 @@ Controller = (function() {
|
|
319
369
|
range.deleteContents();
|
320
370
|
range.insertNode($insert_node[0]);
|
321
371
|
range.collapse(false);
|
322
|
-
sel = this.
|
372
|
+
sel = this.app.window.getSelection();
|
323
373
|
sel.removeAllRanges();
|
324
374
|
sel.addRange(range);
|
325
375
|
} else if (range = this.ie8_range) {
|
@@ -466,15 +516,16 @@ View = (function() {
|
|
466
516
|
|
467
517
|
View.prototype.choose = function() {
|
468
518
|
var $li, content;
|
469
|
-
$li = this.$el.find(".cur")
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
519
|
+
if (($li = this.$el.find(".cur")).length) {
|
520
|
+
content = this.context.insert_content_for($li);
|
521
|
+
this.context.insert(this.context.callbacks("before_insert").call(this.context, content, $li), $li);
|
522
|
+
this.context.trigger("inserted", [$li]);
|
523
|
+
return this.hide();
|
524
|
+
}
|
474
525
|
};
|
475
526
|
|
476
527
|
View.prototype.reposition = function(rect) {
|
477
|
-
var offset;
|
528
|
+
var offset, _ref;
|
478
529
|
if (rect.bottom + this.$el.height() - $(window).scrollTop() > $(window).height()) {
|
479
530
|
rect.bottom = rect.top - this.$el.height();
|
480
531
|
}
|
@@ -482,6 +533,9 @@ View = (function() {
|
|
482
533
|
left: rect.left,
|
483
534
|
top: rect.bottom
|
484
535
|
};
|
536
|
+
if ((_ref = this.context.callbacks("before_reposition")) != null) {
|
537
|
+
_ref.call(this.context, offset);
|
538
|
+
}
|
485
539
|
this.$el.offset(offset);
|
486
540
|
return this.context.trigger("reposition", [offset]);
|
487
541
|
};
|
@@ -511,6 +565,7 @@ View = (function() {
|
|
511
565
|
this.context.mark_range();
|
512
566
|
if (!this.visible()) {
|
513
567
|
this.$el.show();
|
568
|
+
this.context.trigger('shown');
|
514
569
|
}
|
515
570
|
if (rect = this.context.rect()) {
|
516
571
|
return this.reposition(rect);
|
@@ -521,7 +576,8 @@ View = (function() {
|
|
521
576
|
var callback;
|
522
577
|
if (isNaN(time && this.visible())) {
|
523
578
|
this.context.reset_rect();
|
524
|
-
|
579
|
+
this.$el.hide();
|
580
|
+
return this.context.trigger('hidden');
|
525
581
|
} else {
|
526
582
|
callback = (function(_this) {
|
527
583
|
return function() {
|
@@ -553,7 +609,9 @@ View = (function() {
|
|
553
609
|
$ul.append($li);
|
554
610
|
}
|
555
611
|
this.show();
|
556
|
-
|
612
|
+
if (this.context.get_opt('highlight_first')) {
|
613
|
+
return $ul.find("li:first").addClass("cur");
|
614
|
+
}
|
557
615
|
};
|
558
616
|
|
559
617
|
return View;
|
@@ -565,7 +623,10 @@ KEY_CODE = {
|
|
565
623
|
UP: 38,
|
566
624
|
ESC: 27,
|
567
625
|
TAB: 9,
|
568
|
-
ENTER: 13
|
626
|
+
ENTER: 13,
|
627
|
+
CTRL: 17,
|
628
|
+
P: 80,
|
629
|
+
N: 78
|
569
630
|
};
|
570
631
|
|
571
632
|
DEFAULT_CALLBACKS = {
|
@@ -606,7 +667,7 @@ DEFAULT_CALLBACKS = {
|
|
606
667
|
_results = [];
|
607
668
|
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
608
669
|
item = data[_i];
|
609
|
-
if (~item[search_key].toLowerCase().indexOf(query)) {
|
670
|
+
if (~item[search_key].toLowerCase().indexOf(query.toLowerCase())) {
|
610
671
|
_results.push(item);
|
611
672
|
}
|
612
673
|
}
|
@@ -621,7 +682,7 @@ DEFAULT_CALLBACKS = {
|
|
621
682
|
_results = [];
|
622
683
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
623
684
|
item = items[_i];
|
624
|
-
item.atwho_order = item[search_key].toLowerCase().indexOf(query);
|
685
|
+
item.atwho_order = item[search_key].toLowerCase().indexOf(query.toLowerCase());
|
625
686
|
if (item.atwho_order > -1) {
|
626
687
|
_results.push(item);
|
627
688
|
}
|
@@ -691,6 +752,9 @@ Api = {
|
|
691
752
|
getInsertedIDs: function(at) {
|
692
753
|
return Api.getInsertedItemsWithIDs.apply(this, [at])[0];
|
693
754
|
},
|
755
|
+
setIframe: function(iframe) {
|
756
|
+
return this.setIframe(iframe);
|
757
|
+
},
|
694
758
|
run: function() {
|
695
759
|
return this.dispatch();
|
696
760
|
},
|
@@ -743,9 +807,11 @@ $.fn.atwho["default"] = {
|
|
743
807
|
callbacks: DEFAULT_CALLBACKS,
|
744
808
|
search_key: "name",
|
745
809
|
start_with_space: true,
|
810
|
+
highlight_first: true,
|
746
811
|
limit: 5,
|
747
812
|
max_len: 20,
|
748
|
-
display_timeout: 300
|
813
|
+
display_timeout: 300,
|
814
|
+
delay: null
|
749
815
|
};
|
750
816
|
|
751
817
|
});
|
@@ -24,7 +24,7 @@
|
|
24
24
|
}
|
25
25
|
})(function($) {
|
26
26
|
"use strict";
|
27
|
-
var EditableCaret, InputCaret, Mirror, Utils, methods, oDocument, oFrame, oWindow, pluginName;
|
27
|
+
var EditableCaret, InputCaret, Mirror, Utils, configure, methods, oDocument, oFrame, oWindow, pluginName, setContextBy;
|
28
28
|
pluginName = 'caret';
|
29
29
|
EditableCaret = (function() {
|
30
30
|
function EditableCaret($inputor) {
|
@@ -290,7 +290,7 @@
|
|
290
290
|
};
|
291
291
|
methods = {
|
292
292
|
pos: function(pos) {
|
293
|
-
if (pos) {
|
293
|
+
if (pos || pos === 0) {
|
294
294
|
return this.setPos(pos);
|
295
295
|
} else {
|
296
296
|
return this.getPos();
|
@@ -317,13 +317,36 @@
|
|
317
317
|
oDocument = null;
|
318
318
|
oWindow = null;
|
319
319
|
oFrame = null;
|
320
|
+
setContextBy = function(iframe) {
|
321
|
+
oFrame = iframe;
|
322
|
+
oWindow = iframe.contentWindow;
|
323
|
+
return oDocument = iframe.contentDocument || oWindow.document;
|
324
|
+
};
|
325
|
+
configure = function($dom, settings) {
|
326
|
+
var error, iframe;
|
327
|
+
if ($.isPlainObject(settings) && (iframe = settings.iframe)) {
|
328
|
+
$dom.data('caret-iframe', iframe);
|
329
|
+
return setContextBy(iframe);
|
330
|
+
} else if (iframe = $dom.data('caret-iframe')) {
|
331
|
+
return setContextBy(iframe);
|
332
|
+
} else {
|
333
|
+
oDocument = $dom[0].ownerDocument;
|
334
|
+
oWindow = oDocument.defaultView || oDocument.parentWindow;
|
335
|
+
try {
|
336
|
+
return oFrame = oWindow.frameElement;
|
337
|
+
} catch (_error) {
|
338
|
+
error = _error;
|
339
|
+
}
|
340
|
+
}
|
341
|
+
};
|
320
342
|
$.fn.caret = function(method) {
|
321
343
|
var caret;
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
344
|
+
if (typeof method === 'object') {
|
345
|
+
configure(this, method);
|
346
|
+
return this;
|
347
|
+
} else if (methods[method]) {
|
348
|
+
configure(this);
|
349
|
+
caret = Utils.contentEditable(this) ? new EditableCaret(this) : new InputCaret(this);
|
327
350
|
return methods[method].apply(caret, Array.prototype.slice.call(arguments, 1));
|
328
351
|
} else {
|
329
352
|
return $.error("Method " + method + " does not exist on jQuery.caret");
|
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: 0.4.
|
4
|
+
version: 0.4.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ichord
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
84
|
rubyforge_project: jquery-atwho-rails
|
85
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.2.2
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: 'jquery plugin: @mentions'
|