jquery-atwho-rails 0.4.1 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/javascripts/jquery.atwho.js +66 -70
- data/lib/jquery-atwho-rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2dd59a48f6a65bb4ecd8be26f8375c12aae7c0b
|
4
|
+
data.tar.gz: 7663cd82b31f3989bfa58fbc785cceaebff87e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4ba905d140575cf2c20de6d3bbf625fee4defdc2c0d97b4d9ebb05466f0fffba8bcbd62730daa98f79c57a556facc79d25bb2f7b07f23d9f08a3720839e3edd
|
7
|
+
data.tar.gz: 3116c072145617a20e6ee19797dc1a07cb9e9ab02749543d5f8a7d2ab1df809c8f2c32a6b1774dd5e73d0c47685525f020ff5e4942f147f2bcb0484ddd16bf37
|
@@ -24,8 +24,7 @@
|
|
24
24
|
}
|
25
25
|
})(function($) {
|
26
26
|
"use strict";
|
27
|
-
var EditableCaret, InputCaret, Mirror, Utils, methods, pluginName;
|
28
|
-
|
27
|
+
var EditableCaret, InputCaret, Mirror, Utils, methods, oDocument, oFrame, oWindow, pluginName;
|
29
28
|
pluginName = 'caret';
|
30
29
|
EditableCaret = (function() {
|
31
30
|
function EditableCaret($inputor) {
|
@@ -47,9 +46,8 @@
|
|
47
46
|
|
48
47
|
EditableCaret.prototype.getOldIEPos = function() {
|
49
48
|
var preCaretTextRange, textRange;
|
50
|
-
|
51
|
-
|
52
|
-
preCaretTextRange = document.body.createTextRange();
|
49
|
+
textRange = oDocument.selection.createRange();
|
50
|
+
preCaretTextRange = oDocument.body.createTextRange();
|
53
51
|
preCaretTextRange.moveToElementText(this.domInputor);
|
54
52
|
preCaretTextRange.setEndPoint("EndToEnd", textRange);
|
55
53
|
return preCaretTextRange.text.length;
|
@@ -57,7 +55,6 @@
|
|
57
55
|
|
58
56
|
EditableCaret.prototype.getPos = function() {
|
59
57
|
var clonedRange, pos, range;
|
60
|
-
|
61
58
|
if (range = this.range()) {
|
62
59
|
clonedRange = range.cloneRange();
|
63
60
|
clonedRange.selectNodeContents(this.domInputor);
|
@@ -65,15 +62,14 @@
|
|
65
62
|
pos = clonedRange.toString().length;
|
66
63
|
clonedRange.detach();
|
67
64
|
return pos;
|
68
|
-
} else if (
|
65
|
+
} else if (oDocument.selection) {
|
69
66
|
return this.getOldIEPos();
|
70
67
|
}
|
71
68
|
};
|
72
69
|
|
73
70
|
EditableCaret.prototype.getOldIEOffset = function() {
|
74
71
|
var range, rect;
|
75
|
-
|
76
|
-
range = document.selection.createRange().duplicate();
|
72
|
+
range = oDocument.selection.createRange().duplicate();
|
77
73
|
range.moveStart("character", -1);
|
78
74
|
rect = range.getBoundingClientRect();
|
79
75
|
return {
|
@@ -85,9 +81,7 @@
|
|
85
81
|
|
86
82
|
EditableCaret.prototype.getOffset = function(pos) {
|
87
83
|
var clonedRange, offset, range, rect;
|
88
|
-
|
89
|
-
offset = null;
|
90
|
-
if (window.getSelection && (range = this.range())) {
|
84
|
+
if (oWindow.getSelection && (range = this.range())) {
|
91
85
|
if (range.endOffset - 1 < 0) {
|
92
86
|
return null;
|
93
87
|
}
|
@@ -101,20 +95,22 @@
|
|
101
95
|
top: rect.top
|
102
96
|
};
|
103
97
|
clonedRange.detach();
|
104
|
-
|
105
|
-
|
106
|
-
|
98
|
+
} else if (oDocument.selection) {
|
99
|
+
offset = this.getOldIEOffset();
|
100
|
+
}
|
101
|
+
if (offset && !oFrame) {
|
102
|
+
offset.top += $(oWindow).scrollTop();
|
103
|
+
offset.left += $(oWindow).scrollLeft();
|
107
104
|
}
|
108
|
-
return
|
105
|
+
return offset;
|
109
106
|
};
|
110
107
|
|
111
108
|
EditableCaret.prototype.range = function() {
|
112
109
|
var sel;
|
113
|
-
|
114
|
-
if (!window.getSelection) {
|
110
|
+
if (!oWindow.getSelection) {
|
115
111
|
return;
|
116
112
|
}
|
117
|
-
sel =
|
113
|
+
sel = oWindow.getSelection();
|
118
114
|
if (sel.rangeCount > 0) {
|
119
115
|
return sel.getRangeAt(0);
|
120
116
|
} else {
|
@@ -133,9 +129,8 @@
|
|
133
129
|
|
134
130
|
InputCaret.prototype.getIEPos = function() {
|
135
131
|
var endRange, inputor, len, normalizedValue, pos, range, textInputRange;
|
136
|
-
|
137
132
|
inputor = this.domInputor;
|
138
|
-
range =
|
133
|
+
range = oDocument.selection.createRange();
|
139
134
|
pos = 0;
|
140
135
|
if (range && range.parentElement() === inputor) {
|
141
136
|
normalizedValue = inputor.value.replace(/\r\n/g, "\n");
|
@@ -154,7 +149,7 @@
|
|
154
149
|
};
|
155
150
|
|
156
151
|
InputCaret.prototype.getPos = function() {
|
157
|
-
if (
|
152
|
+
if (oDocument.selection) {
|
158
153
|
return this.getIEPos();
|
159
154
|
} else {
|
160
155
|
return this.domInputor.selectionStart;
|
@@ -163,9 +158,8 @@
|
|
163
158
|
|
164
159
|
InputCaret.prototype.setPos = function(pos) {
|
165
160
|
var inputor, range;
|
166
|
-
|
167
161
|
inputor = this.domInputor;
|
168
|
-
if (
|
162
|
+
if (oDocument.selection) {
|
169
163
|
range = inputor.createTextRange();
|
170
164
|
range.move("character", pos);
|
171
165
|
range.select();
|
@@ -176,15 +170,10 @@
|
|
176
170
|
};
|
177
171
|
|
178
172
|
InputCaret.prototype.getIEOffset = function(pos) {
|
179
|
-
var h,
|
180
|
-
|
173
|
+
var h, textRange, x, y;
|
181
174
|
textRange = this.domInputor.createTextRange();
|
182
|
-
|
183
|
-
|
184
|
-
} else {
|
185
|
-
range = document.selection.createRange();
|
186
|
-
textRange.moveToBookmark(range.getBookmark());
|
187
|
-
}
|
175
|
+
pos || (pos = this.getPos());
|
176
|
+
textRange.move('character', pos);
|
188
177
|
x = textRange.boundingLeft;
|
189
178
|
y = textRange.boundingTop;
|
190
179
|
h = textRange.boundingHeight;
|
@@ -197,16 +186,18 @@
|
|
197
186
|
|
198
187
|
InputCaret.prototype.getOffset = function(pos) {
|
199
188
|
var $inputor, offset, position;
|
200
|
-
|
201
189
|
$inputor = this.$inputor;
|
202
|
-
if (
|
203
|
-
|
190
|
+
if (oDocument.selection) {
|
191
|
+
offset = this.getIEOffset(pos);
|
192
|
+
offset.top += $(oWindow).scrollTop() + $inputor.scrollTop();
|
193
|
+
offset.left += $(oWindow).scrollLeft() + $inputor.scrollLeft();
|
194
|
+
return offset;
|
204
195
|
} else {
|
205
196
|
offset = $inputor.offset();
|
206
197
|
position = this.getPosition(pos);
|
207
198
|
return offset = {
|
208
|
-
left: offset.left + position.left,
|
209
|
-
top: offset.top + position.top,
|
199
|
+
left: offset.left + position.left - $inputor.scrollLeft(),
|
200
|
+
top: offset.top + position.top - $inputor.scrollTop(),
|
210
201
|
height: position.height
|
211
202
|
};
|
212
203
|
}
|
@@ -214,7 +205,6 @@
|
|
214
205
|
|
215
206
|
InputCaret.prototype.getPosition = function(pos) {
|
216
207
|
var $inputor, at_rect, format, html, mirror, start_range;
|
217
|
-
|
218
208
|
$inputor = this.$inputor;
|
219
209
|
format = function(value) {
|
220
210
|
return value.replace(/</g, '<').replace(/>/g, '>').replace(/`/g, '`').replace(/"/g, '"').replace(/\r\n|\r|\n/g, "<br />");
|
@@ -231,7 +221,6 @@
|
|
231
221
|
|
232
222
|
InputCaret.prototype.getIEPosition = function(pos) {
|
233
223
|
var h, inputorOffset, offset, x, y;
|
234
|
-
|
235
224
|
offset = this.getIEOffset(pos);
|
236
225
|
inputorOffset = this.$inputor.offset();
|
237
226
|
x = offset.left - inputorOffset.left;
|
@@ -257,7 +246,6 @@
|
|
257
246
|
Mirror.prototype.mirrorCss = function() {
|
258
247
|
var css,
|
259
248
|
_this = this;
|
260
|
-
|
261
249
|
css = {
|
262
250
|
position: 'absolute',
|
263
251
|
left: -9999,
|
@@ -281,7 +269,6 @@
|
|
281
269
|
|
282
270
|
Mirror.prototype.rect = function() {
|
283
271
|
var $flag, pos, rect;
|
284
|
-
|
285
272
|
$flag = this.$mirror.find("#caret");
|
286
273
|
pos = $flag.position();
|
287
274
|
rect = {
|
@@ -297,14 +284,6 @@
|
|
297
284
|
|
298
285
|
})();
|
299
286
|
Utils = {
|
300
|
-
adjustOffset: function(offset, $inputor) {
|
301
|
-
if (!offset) {
|
302
|
-
return;
|
303
|
-
}
|
304
|
-
offset.top += $(window).scrollTop() + $inputor.scrollTop();
|
305
|
-
offset.left += +$(window).scrollLeft() + $inputor.scrollLeft();
|
306
|
-
return offset;
|
307
|
-
},
|
308
287
|
contentEditable: function($inputor) {
|
309
288
|
return !!($inputor[0].contentEditable && $inputor[0].contentEditable === 'true');
|
310
289
|
}
|
@@ -318,19 +297,31 @@
|
|
318
297
|
}
|
319
298
|
},
|
320
299
|
position: function(pos) {
|
321
|
-
if (
|
300
|
+
if (oDocument.selection) {
|
322
301
|
return this.getIEPosition(pos);
|
323
302
|
} else {
|
324
303
|
return this.getPosition(pos);
|
325
304
|
}
|
326
305
|
},
|
327
306
|
offset: function(pos) {
|
328
|
-
|
307
|
+
var iOffset, offset;
|
308
|
+
offset = this.getOffset(pos);
|
309
|
+
if (oFrame) {
|
310
|
+
iOffset = $(oFrame).offset();
|
311
|
+
offset.top += iOffset.top;
|
312
|
+
offset.left += iOffset.left;
|
313
|
+
}
|
314
|
+
return offset;
|
329
315
|
}
|
330
316
|
};
|
317
|
+
oDocument = null;
|
318
|
+
oWindow = null;
|
319
|
+
oFrame = null;
|
331
320
|
$.fn.caret = function(method) {
|
332
321
|
var caret;
|
333
|
-
|
322
|
+
oDocument = this[0].ownerDocument;
|
323
|
+
oWindow = oDocument.defaultView || oDocument.parentWindow;
|
324
|
+
oFrame = oWindow.frameElement;
|
334
325
|
caret = Utils.contentEditable(this) ? new EditableCaret(this) : new InputCaret(this);
|
335
326
|
if (methods[method]) {
|
336
327
|
return methods[method].apply(caret, Array.prototype.slice.call(arguments, 1));
|
@@ -372,12 +363,13 @@
|
|
372
363
|
function App(inputor) {
|
373
364
|
this.current_flag = null;
|
374
365
|
this.controllers = {};
|
366
|
+
this.alias_maps = {};
|
375
367
|
this.$inputor = $(inputor);
|
376
368
|
this.listen();
|
377
369
|
}
|
378
370
|
|
379
371
|
App.prototype.controller = function(at) {
|
380
|
-
return this.controllers[at || this.current_flag];
|
372
|
+
return this.controllers[this.alias_maps[at] || at || this.current_flag];
|
381
373
|
};
|
382
374
|
|
383
375
|
App.prototype.set_context_for = function(at) {
|
@@ -389,7 +381,7 @@
|
|
389
381
|
var controller, _base;
|
390
382
|
controller = (_base = this.controllers)[flag] || (_base[flag] = new Controller(this, flag));
|
391
383
|
if (setting.alias) {
|
392
|
-
this.
|
384
|
+
this.alias_maps[setting.alias] = flag;
|
393
385
|
}
|
394
386
|
controller.init(setting);
|
395
387
|
return this;
|
@@ -487,6 +479,8 @@
|
|
487
479
|
this.app = app;
|
488
480
|
this.at = at;
|
489
481
|
this.$inputor = this.app.$inputor;
|
482
|
+
this.oDocument = this.$inputor[0].ownerDocument;
|
483
|
+
this.oWindow = this.oDocument.defaultView || this.oDocument.parentWindow;
|
490
484
|
this.id = this.$inputor[0].id || uuid();
|
491
485
|
this.setting = null;
|
492
486
|
this.query = null;
|
@@ -587,7 +581,8 @@
|
|
587
581
|
};
|
588
582
|
|
589
583
|
Controller.prototype.mark_range = function() {
|
590
|
-
|
584
|
+
this.range = this.get_range();
|
585
|
+
return this.ie_range = this.get_ie_range();
|
591
586
|
};
|
592
587
|
|
593
588
|
Controller.prototype.clear_range = function() {
|
@@ -595,11 +590,11 @@
|
|
595
590
|
};
|
596
591
|
|
597
592
|
Controller.prototype.get_range = function() {
|
598
|
-
return this.range || (
|
593
|
+
return this.range || (this.oWindow.getSelection ? this.oWindow.getSelection().getRangeAt(0) : void 0);
|
599
594
|
};
|
600
595
|
|
601
596
|
Controller.prototype.get_ie_range = function() {
|
602
|
-
return this.
|
597
|
+
return this.ie_range || (this.oDocument.selection ? this.oDocument.selection.createRange() : void 0);
|
603
598
|
};
|
604
599
|
|
605
600
|
Controller.prototype.insert_content_for = function($li) {
|
@@ -624,7 +619,7 @@
|
|
624
619
|
content_node = "" + content + "<span contenteditable='false'> <span>";
|
625
620
|
insert_node = "<span contenteditable='false' class='" + class_name + "'>" + content_node + "</span>";
|
626
621
|
$insert_node = $(insert_node).data('atwho-data-item', $li.data('item-data'));
|
627
|
-
if (
|
622
|
+
if (this.oDocument.selection) {
|
628
623
|
$insert_node = $("<span contenteditable='true'></span>").html($insert_node);
|
629
624
|
}
|
630
625
|
}
|
@@ -642,12 +637,12 @@
|
|
642
637
|
range.deleteContents();
|
643
638
|
range.insertNode($insert_node[0]);
|
644
639
|
range.collapse(false);
|
645
|
-
sel =
|
640
|
+
sel = this.oWindow.getSelection();
|
646
641
|
sel.removeAllRanges();
|
647
642
|
sel.addRange(range);
|
648
643
|
} else if (range = this.get_ie_range()) {
|
649
644
|
range.moveStart('character', this.query.end_pos - this.query.head_pos - this.at.length);
|
650
|
-
range.pasteHTML(
|
645
|
+
range.pasteHTML(content_node);
|
651
646
|
range.collapse(false);
|
652
647
|
range.select();
|
653
648
|
}
|
@@ -682,13 +677,11 @@
|
|
682
677
|
|
683
678
|
})();
|
684
679
|
Model = (function() {
|
685
|
-
var _storage;
|
686
|
-
|
687
|
-
_storage = {};
|
688
680
|
|
689
681
|
function Model(context) {
|
690
682
|
this.context = context;
|
691
683
|
this.at = this.context.at;
|
684
|
+
this.storage = this.context.$inputor;
|
692
685
|
}
|
693
686
|
|
694
687
|
Model.prototype.saved = function() {
|
@@ -696,21 +689,24 @@
|
|
696
689
|
};
|
697
690
|
|
698
691
|
Model.prototype.query = function(query, callback) {
|
699
|
-
var data, search_key,
|
692
|
+
var data, search_key, _remote_filter;
|
700
693
|
data = this.fetch();
|
701
694
|
search_key = this.context.get_opt("search_key");
|
702
|
-
|
703
|
-
|
704
|
-
|
695
|
+
data = this.context.callbacks('filter').call(this.context, query, data, search_key) || [];
|
696
|
+
_remote_filter = this.context.callbacks('remote_filter');
|
697
|
+
if (data.length > 0 || (!_remote_filter && data.length === 0)) {
|
698
|
+
return callback(data);
|
699
|
+
} else {
|
700
|
+
return _remote_filter.call(this.context, query, callback);
|
705
701
|
}
|
706
702
|
};
|
707
703
|
|
708
704
|
Model.prototype.fetch = function() {
|
709
|
-
return
|
705
|
+
return this.storage.data(this.at) || [];
|
710
706
|
};
|
711
707
|
|
712
708
|
Model.prototype.save = function(data) {
|
713
|
-
return
|
709
|
+
return this.storage.data(this.at, this.context.callbacks("before_save").call(this.context, data || []));
|
714
710
|
};
|
715
711
|
|
716
712
|
Model.prototype.load = function(data) {
|
@@ -848,7 +844,7 @@
|
|
848
844
|
|
849
845
|
View.prototype.render = function(list) {
|
850
846
|
var $li, $ul, item, li, tpl, _i, _len;
|
851
|
-
if (
|
847
|
+
if (!($.isArray(list) && list.length > 0)) {
|
852
848
|
this.hide();
|
853
849
|
return;
|
854
850
|
}
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ichord
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|