jquery-atwho-rails 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE-MIT +22 -0
- data/README.md +10 -12
- data/lib/assets/javascripts/jquery.atwho.js +300 -262
- data/lib/jquery-atwho-rails/version.rb +1 -1
- metadata +6 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e175b0c1d92d3d414cbe8cf439b14ab7fcf98e42
|
4
|
+
data.tar.gz: d561cd5c31287188104ed2417af2dd44c2418d91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc281180227c6e072a7bc07b8e1bb409962d9b50681ddd75c80421710ca6afa09435819bc8e2993d8e8715e439da6ff502cadc1f783b607c2cd732309fde5226
|
7
|
+
data.tar.gz: 0a54a8ce1e6018e0925e69352dedce87fb5c1b06045120d0030c9b652e934456327256a0c2cc46e5e160a184bac5e36f358456f3b7360962383ae1222d795c26
|
data/LICENSE-MIT
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 chord.luo@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,29 +1,24 @@
|
|
1
|
-
### Notice
|
2
|
-
updated to `v0.2.0`.
|
3
|
-
The stable and old one would live in branch `stable-v0.1.x` branch taged `v0.1.7`
|
4
|
-
**More details** in [At.js](https://github.com/ichord/At.js) project.
|
5
|
-
|
6
1
|
### Usage
|
7
2
|
---
|
8
|
-
|
3
|
+
Bind your textarea
|
9
4
|
|
10
5
|
```javascript
|
11
6
|
data = ['tom','john'];
|
12
|
-
$('textarea').atwho("@",
|
7
|
+
$('textarea').atwho({at:"@", 'data':data});
|
13
8
|
```
|
14
9
|
|
15
10
|
that's it, check it out!
|
16
11
|
more details in [At.js Home Page](http://ichord.github.com/At.js/)
|
17
12
|
|
18
|
-
###
|
13
|
+
### Installation
|
19
14
|
---
|
20
15
|
#### Rails 3.0.x
|
21
|
-
|
16
|
+
Issue command line bellow:
|
22
17
|
`rails generate atwho:install`
|
23
18
|
then It will show in `public/[javascript|stylesheets]/` directory.
|
24
19
|
|
25
20
|
#### Rails 3.1.x
|
26
|
-
|
21
|
+
Add this gem in `Gemfile` like this:
|
27
22
|
`gem jquery-atwho-rails`
|
28
23
|
|
29
24
|
then add
|
@@ -31,8 +26,11 @@ then add
|
|
31
26
|
to `app/assets/javascripts/application.js`
|
32
27
|
and `app/assets/stylesheets/applications.css`
|
33
28
|
|
34
|
-
|
29
|
+
#### History Versions
|
30
|
+
All in [At.js](https://github.com/ichord/At.js) project.
|
31
|
+
|
32
|
+
### Development
|
35
33
|
---
|
36
34
|
#### Test generator
|
37
|
-
|
35
|
+
Just issue
|
38
36
|
`bundle` then `rspec`
|
@@ -1,3 +1,293 @@
|
|
1
|
+
//@ sourceMappingURL=jquery.caret.map
|
2
|
+
/*
|
3
|
+
Implement Github like autocomplete mentions
|
4
|
+
http://ichord.github.com/At.js
|
5
|
+
|
6
|
+
Copyright (c) 2013 chord.luo@gmail.com
|
7
|
+
Licensed under the MIT license.
|
8
|
+
*/
|
9
|
+
|
10
|
+
|
11
|
+
/*
|
12
|
+
本插件操作 textarea 或者 input 内的插入符
|
13
|
+
只实现了获得插入符在文本框中的位置,我设置
|
14
|
+
插入符的位置.
|
15
|
+
*/
|
16
|
+
|
17
|
+
|
18
|
+
(function() {
|
19
|
+
(function(factory) {
|
20
|
+
if (typeof define === 'function' && define.amd) {
|
21
|
+
return define(['jquery'], factory);
|
22
|
+
} else {
|
23
|
+
return factory(window.jQuery);
|
24
|
+
}
|
25
|
+
})(function($) {
|
26
|
+
"use strict";
|
27
|
+
var Caret, Mirror, methods, pluginName;
|
28
|
+
|
29
|
+
pluginName = 'caret';
|
30
|
+
Caret = (function() {
|
31
|
+
function Caret($inputor) {
|
32
|
+
this.$inputor = $inputor;
|
33
|
+
this.domInputor = this.$inputor[0];
|
34
|
+
}
|
35
|
+
|
36
|
+
Caret.prototype.getPos = function() {
|
37
|
+
var end, endRange, inputor, len, normalizedValue, pos, range, start, textInputRange;
|
38
|
+
|
39
|
+
inputor = this.domInputor;
|
40
|
+
inputor.focus();
|
41
|
+
if (document.selection) {
|
42
|
+
/*
|
43
|
+
#assume we select "HATE" in the inputor such as textarea -> { }.
|
44
|
+
* start end-point.
|
45
|
+
* /
|
46
|
+
* < I really [HATE] IE > between the brackets is the selection range.
|
47
|
+
* \
|
48
|
+
* end end-point.
|
49
|
+
*/
|
50
|
+
|
51
|
+
range = document.selection.createRange();
|
52
|
+
pos = 0;
|
53
|
+
if (range && range.parentElement() === inputor) {
|
54
|
+
normalizedValue = inputor.value.replace(/\r\n/g, "\n");
|
55
|
+
/* SOMETIME !!!
|
56
|
+
"/r/n" is counted as two char.
|
57
|
+
one line is two, two will be four. balalala.
|
58
|
+
so we have to using the normalized one's length.;
|
59
|
+
*/
|
60
|
+
|
61
|
+
len = normalizedValue.length;
|
62
|
+
/*
|
63
|
+
<[ I really HATE IE ]>:
|
64
|
+
the whole content in the inputor will be the textInputRange.
|
65
|
+
*/
|
66
|
+
|
67
|
+
textInputRange = inputor.createTextRange();
|
68
|
+
/* _here must be the position of bookmark.
|
69
|
+
/
|
70
|
+
<[ I really [HATE] IE ]>
|
71
|
+
[---------->[ ] : this is what moveToBookmark do.
|
72
|
+
< I really [[HATE] IE ]> : here is result.
|
73
|
+
\ two brackets in should be in line.
|
74
|
+
*/
|
75
|
+
|
76
|
+
textInputRange.moveToBookmark(range.getBookmark());
|
77
|
+
endRange = inputor.createTextRange();
|
78
|
+
/* [--------------------->[] : if set false all end-point goto end.
|
79
|
+
< I really [[HATE] IE []]>
|
80
|
+
*/
|
81
|
+
|
82
|
+
endRange.collapse(false);
|
83
|
+
/*
|
84
|
+
___VS____
|
85
|
+
/ \
|
86
|
+
< I really [[HATE] IE []]>
|
87
|
+
\_endRange end-point.
|
88
|
+
|
89
|
+
" > -1" mean the start end-point will be the same or right to the end end-point
|
90
|
+
* simplelly, all in the end.
|
91
|
+
*/
|
92
|
+
|
93
|
+
if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
|
94
|
+
start = end = len;
|
95
|
+
} else {
|
96
|
+
/*
|
97
|
+
I really |HATE] IE ]>
|
98
|
+
<-|
|
99
|
+
I really[ [HATE] IE ]>
|
100
|
+
<-[
|
101
|
+
I reall[y [HATE] IE ]>
|
102
|
+
|
103
|
+
will return how many unit have moved.
|
104
|
+
*/
|
105
|
+
|
106
|
+
start = -textInputRange.moveStart("character", -len);
|
107
|
+
end = -textInputRange.moveEnd("character", -len);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
} else {
|
111
|
+
start = inputor.selectionStart;
|
112
|
+
}
|
113
|
+
return start;
|
114
|
+
};
|
115
|
+
|
116
|
+
Caret.prototype.setPos = function(pos) {
|
117
|
+
var inputor, range;
|
118
|
+
|
119
|
+
inputor = this.domInputor;
|
120
|
+
if (document.selection) {
|
121
|
+
range = inputor.createTextRange();
|
122
|
+
range.move("character", pos);
|
123
|
+
return range.select();
|
124
|
+
} else {
|
125
|
+
return inputor.setSelectionRange(pos, pos);
|
126
|
+
}
|
127
|
+
};
|
128
|
+
|
129
|
+
Caret.prototype.getPosition = function(pos) {
|
130
|
+
var $inputor, at_rect, format, h, html, mirror, start_range, x, y;
|
131
|
+
|
132
|
+
$inputor = this.$inputor;
|
133
|
+
format = function(value) {
|
134
|
+
return value.replace(/</g, '<').replace(/>/g, '>').replace(/`/g, '`').replace(/"/g, '"').replace(/\r\n|\r|\n/g, "<br />");
|
135
|
+
};
|
136
|
+
if (pos === void 0) {
|
137
|
+
pos = this.getPos();
|
138
|
+
}
|
139
|
+
start_range = $inputor.val().slice(0, pos);
|
140
|
+
html = "<span>" + format(start_range) + "</span>";
|
141
|
+
html += "<span id='caret'>|</span>";
|
142
|
+
mirror = new Mirror($inputor);
|
143
|
+
at_rect = mirror.create(html).rect();
|
144
|
+
x = at_rect.left - $inputor.scrollLeft();
|
145
|
+
y = at_rect.top - $inputor.scrollTop();
|
146
|
+
h = at_rect.height;
|
147
|
+
return {
|
148
|
+
left: x,
|
149
|
+
top: y,
|
150
|
+
height: h
|
151
|
+
};
|
152
|
+
};
|
153
|
+
|
154
|
+
Caret.prototype.getOffset = function(pos) {
|
155
|
+
var $inputor, h, offset, position, x, y;
|
156
|
+
|
157
|
+
$inputor = this.$inputor;
|
158
|
+
offset = $inputor.offset();
|
159
|
+
position = this.getPosition(pos);
|
160
|
+
x = offset.left + position.left;
|
161
|
+
y = offset.top + position.top;
|
162
|
+
h = position.height;
|
163
|
+
return {
|
164
|
+
left: x,
|
165
|
+
top: y,
|
166
|
+
height: h
|
167
|
+
};
|
168
|
+
};
|
169
|
+
|
170
|
+
Caret.prototype.getIEPosition = function(pos) {
|
171
|
+
var h, inputorOffset, offset, x, y;
|
172
|
+
|
173
|
+
offset = this.getIEOffset(pos);
|
174
|
+
inputorOffset = this.$inputor.offset();
|
175
|
+
x = offset.left - inputorOffset.left;
|
176
|
+
y = offset.top - inputorOffset.top;
|
177
|
+
h = offset.height;
|
178
|
+
return {
|
179
|
+
left: x,
|
180
|
+
top: y,
|
181
|
+
height: h
|
182
|
+
};
|
183
|
+
};
|
184
|
+
|
185
|
+
Caret.prototype.getIEOffset = function(pos) {
|
186
|
+
var h, range, x, y;
|
187
|
+
|
188
|
+
range = this.domInputor.createTextRange();
|
189
|
+
if (pos) {
|
190
|
+
range.move('character', pos);
|
191
|
+
}
|
192
|
+
x = range.boundingLeft + $inputor.scrollLeft();
|
193
|
+
y = range.boundingTop + $(window).scrollTop() + $inputor.scrollTop();
|
194
|
+
h = range.boundingHeight;
|
195
|
+
return {
|
196
|
+
left: x,
|
197
|
+
top: y,
|
198
|
+
height: h
|
199
|
+
};
|
200
|
+
};
|
201
|
+
|
202
|
+
return Caret;
|
203
|
+
|
204
|
+
})();
|
205
|
+
Mirror = (function() {
|
206
|
+
Mirror.prototype.css_attr = ["overflowY", "height", "width", "paddingTop", "paddingLeft", "paddingRight", "paddingBottom", "marginTop", "marginLeft", "marginRight", "marginBottom", "fontFamily", "borderStyle", "borderWidth", "wordWrap", "fontSize", "lineHeight", "overflowX", "text-align"];
|
207
|
+
|
208
|
+
function Mirror($inputor) {
|
209
|
+
this.$inputor = $inputor;
|
210
|
+
}
|
211
|
+
|
212
|
+
Mirror.prototype.mirrorCss = function() {
|
213
|
+
var css,
|
214
|
+
_this = this;
|
215
|
+
|
216
|
+
css = {
|
217
|
+
position: 'absolute',
|
218
|
+
left: -9999,
|
219
|
+
top: 0,
|
220
|
+
zIndex: -20000,
|
221
|
+
'white-space': 'pre-wrap'
|
222
|
+
};
|
223
|
+
$.each(this.css_attr, function(i, p) {
|
224
|
+
return css[p] = _this.$inputor.css(p);
|
225
|
+
});
|
226
|
+
return css;
|
227
|
+
};
|
228
|
+
|
229
|
+
Mirror.prototype.create = function(html) {
|
230
|
+
this.$mirror = $('<div></div>');
|
231
|
+
this.$mirror.css(this.mirrorCss());
|
232
|
+
this.$mirror.html(html);
|
233
|
+
this.$inputor.after(this.$mirror);
|
234
|
+
return this;
|
235
|
+
};
|
236
|
+
|
237
|
+
Mirror.prototype.rect = function() {
|
238
|
+
var $flag, pos, rect;
|
239
|
+
|
240
|
+
$flag = this.$mirror.find("#caret");
|
241
|
+
pos = $flag.position();
|
242
|
+
rect = {
|
243
|
+
left: pos.left,
|
244
|
+
top: pos.top,
|
245
|
+
height: $flag.height()
|
246
|
+
};
|
247
|
+
this.$mirror.remove();
|
248
|
+
return rect;
|
249
|
+
};
|
250
|
+
|
251
|
+
return Mirror;
|
252
|
+
|
253
|
+
})();
|
254
|
+
methods = {
|
255
|
+
pos: function(pos) {
|
256
|
+
if (pos) {
|
257
|
+
return this.setPos(pos);
|
258
|
+
} else {
|
259
|
+
return this.getPos();
|
260
|
+
}
|
261
|
+
},
|
262
|
+
position: function(pos) {
|
263
|
+
if (document.selection) {
|
264
|
+
return this.getIEPosition(pos);
|
265
|
+
} else {
|
266
|
+
return this.getPosition(pos);
|
267
|
+
}
|
268
|
+
},
|
269
|
+
offset: function(pos) {
|
270
|
+
if (document.selection) {
|
271
|
+
return this.getIEOffset(pos);
|
272
|
+
} else {
|
273
|
+
return this.getOffset(pos);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
};
|
277
|
+
return $.fn.caret = function(method) {
|
278
|
+
var caret;
|
279
|
+
|
280
|
+
caret = new Caret(this);
|
281
|
+
if (methods[method]) {
|
282
|
+
return methods[method].apply(caret, Array.prototype.slice.call(arguments, 1));
|
283
|
+
} else {
|
284
|
+
return $.error("Method " + method + " does not exist on jQuery.caret");
|
285
|
+
}
|
286
|
+
};
|
287
|
+
});
|
288
|
+
|
289
|
+
}).call(this);
|
290
|
+
|
1
291
|
|
2
292
|
/*
|
3
293
|
Implement Github like autocomplete mentions
|
@@ -153,7 +443,7 @@
|
|
153
443
|
return this.model.reload(this.setting.data);
|
154
444
|
};
|
155
445
|
|
156
|
-
Controller.prototype.
|
446
|
+
Controller.prototype.call_default = function() {
|
157
447
|
var args, func_name;
|
158
448
|
func_name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
159
449
|
try {
|
@@ -188,7 +478,7 @@
|
|
188
478
|
content = this.$inputor.val();
|
189
479
|
caret_pos = this.$inputor.caret('pos');
|
190
480
|
subtext = content.slice(0, caret_pos);
|
191
|
-
query = this.callbacks("matcher").call(this, this.key, subtext);
|
481
|
+
query = this.callbacks("matcher").call(this, this.key, subtext, this.get_opt('start_with_space'));
|
192
482
|
if (typeof query === "string" && query.length <= this.get_opt('max_len', 20)) {
|
193
483
|
start = caret_pos - query.length;
|
194
484
|
end = start + query.length;
|
@@ -217,12 +507,11 @@
|
|
217
507
|
};
|
218
508
|
|
219
509
|
Controller.prototype.insert = function(str) {
|
220
|
-
var $inputor,
|
510
|
+
var $inputor, source, start_str, text;
|
221
511
|
$inputor = this.$inputor;
|
222
512
|
str = '' + str;
|
223
513
|
source = $inputor.val();
|
224
|
-
|
225
|
-
start_str = source.slice(0, (this.query['head_pos'] || 0) - flag_len);
|
514
|
+
start_str = source.slice(0, this.query['head_pos'] || 0);
|
226
515
|
text = "" + start_str + str + " " + (source.slice(this.query['end_pos'] || 0));
|
227
516
|
$inputor.val(text);
|
228
517
|
$inputor.caret('pos', start_str.length + str.length + 1);
|
@@ -454,9 +743,12 @@
|
|
454
743
|
}
|
455
744
|
return _results;
|
456
745
|
},
|
457
|
-
matcher: function(flag, subtext) {
|
746
|
+
matcher: function(flag, subtext, should_start_with_space) {
|
458
747
|
var match, regexp;
|
459
|
-
flag =
|
748
|
+
flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
749
|
+
if (should_start_with_space) {
|
750
|
+
flag = '(?:^|\\s)' + flag;
|
751
|
+
}
|
460
752
|
regexp = new RegExp(flag + '([A-Za-z0-9_\+\-]*)$|' + flag + '([^\\x00-\\xff]*)$', 'gi');
|
461
753
|
match = regexp.exec(subtext);
|
462
754
|
if (match) {
|
@@ -564,263 +856,9 @@
|
|
564
856
|
search_key: "name",
|
565
857
|
limit: 5,
|
566
858
|
max_len: 20,
|
567
|
-
|
859
|
+
start_with_space: true,
|
568
860
|
display_timeout: 300
|
569
861
|
};
|
570
862
|
});
|
571
863
|
|
572
864
|
}).call(this);
|
573
|
-
|
574
|
-
|
575
|
-
/*
|
576
|
-
Implement Github like autocomplete mentions
|
577
|
-
http://ichord.github.com/At.js
|
578
|
-
|
579
|
-
Copyright (c) 2013 chord.luo@gmail.com
|
580
|
-
Licensed under the MIT license.
|
581
|
-
*/
|
582
|
-
|
583
|
-
|
584
|
-
/*
|
585
|
-
本插件操作 textarea 或者 input 内的插入符
|
586
|
-
只实现了获得插入符在文本框中的位置,我设置
|
587
|
-
插入符的位置.
|
588
|
-
*/
|
589
|
-
|
590
|
-
|
591
|
-
(function() {
|
592
|
-
|
593
|
-
(function(factory) {
|
594
|
-
if (typeof define === 'function' && define.amd) {
|
595
|
-
return define(['jquery'], factory);
|
596
|
-
} else {
|
597
|
-
return factory(window.jQuery);
|
598
|
-
}
|
599
|
-
})(function($) {
|
600
|
-
"use strict";
|
601
|
-
|
602
|
-
var Caret, Mirror, methods, pluginName;
|
603
|
-
pluginName = 'caret';
|
604
|
-
Caret = (function() {
|
605
|
-
|
606
|
-
function Caret($inputor) {
|
607
|
-
this.$inputor = $inputor;
|
608
|
-
this.domInputor = this.$inputor[0];
|
609
|
-
}
|
610
|
-
|
611
|
-
Caret.prototype.getPos = function() {
|
612
|
-
var end, endRange, inputor, len, normalizedValue, pos, range, start, textInputRange;
|
613
|
-
inputor = this.domInputor;
|
614
|
-
inputor.focus();
|
615
|
-
if (document.selection) {
|
616
|
-
/*
|
617
|
-
#assume we select "HATE" in the inputor such as textarea -> { }.
|
618
|
-
* start end-point.
|
619
|
-
* /
|
620
|
-
* < I really [HATE] IE > between the brackets is the selection range.
|
621
|
-
* \
|
622
|
-
* end end-point.
|
623
|
-
*/
|
624
|
-
|
625
|
-
range = document.selection.createRange();
|
626
|
-
pos = 0;
|
627
|
-
if (range && range.parentElement() === inputor) {
|
628
|
-
normalizedValue = inputor.value.replace(/\r\n/g, "\n");
|
629
|
-
/* SOMETIME !!!
|
630
|
-
"/r/n" is counted as two char.
|
631
|
-
one line is two, two will be four. balalala.
|
632
|
-
so we have to using the normalized one's length.;
|
633
|
-
*/
|
634
|
-
|
635
|
-
len = normalizedValue.length;
|
636
|
-
/*
|
637
|
-
<[ I really HATE IE ]>:
|
638
|
-
the whole content in the inputor will be the textInputRange.
|
639
|
-
*/
|
640
|
-
|
641
|
-
textInputRange = inputor.createTextRange();
|
642
|
-
/* _here must be the position of bookmark.
|
643
|
-
/
|
644
|
-
<[ I really [HATE] IE ]>
|
645
|
-
[---------->[ ] : this is what moveToBookmark do.
|
646
|
-
< I really [[HATE] IE ]> : here is result.
|
647
|
-
\ two brackets in should be in line.
|
648
|
-
*/
|
649
|
-
|
650
|
-
textInputRange.moveToBookmark(range.getBookmark());
|
651
|
-
endRange = inputor.createTextRange();
|
652
|
-
/* [--------------------->[] : if set false all end-point goto end.
|
653
|
-
< I really [[HATE] IE []]>
|
654
|
-
*/
|
655
|
-
|
656
|
-
endRange.collapse(false);
|
657
|
-
/*
|
658
|
-
___VS____
|
659
|
-
/ \
|
660
|
-
< I really [[HATE] IE []]>
|
661
|
-
\_endRange end-point.
|
662
|
-
|
663
|
-
" > -1" mean the start end-point will be the same or right to the end end-point
|
664
|
-
* simplelly, all in the end.
|
665
|
-
*/
|
666
|
-
|
667
|
-
if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
|
668
|
-
start = end = len;
|
669
|
-
} else {
|
670
|
-
/*
|
671
|
-
I really |HATE] IE ]>
|
672
|
-
<-|
|
673
|
-
I really[ [HATE] IE ]>
|
674
|
-
<-[
|
675
|
-
I reall[y [HATE] IE ]>
|
676
|
-
|
677
|
-
will return how many unit have moved.
|
678
|
-
*/
|
679
|
-
|
680
|
-
start = -textInputRange.moveStart("character", -len);
|
681
|
-
end = -textInputRange.moveEnd("character", -len);
|
682
|
-
}
|
683
|
-
}
|
684
|
-
} else {
|
685
|
-
start = inputor.selectionStart;
|
686
|
-
}
|
687
|
-
return start;
|
688
|
-
};
|
689
|
-
|
690
|
-
Caret.prototype.setPos = function(pos) {
|
691
|
-
var inputor, range;
|
692
|
-
inputor = this.domInputor;
|
693
|
-
if (document.selection) {
|
694
|
-
range = inputor.createTextRange();
|
695
|
-
range.move("character", pos);
|
696
|
-
return range.select();
|
697
|
-
} else {
|
698
|
-
return inputor.setSelectionRange(pos, pos);
|
699
|
-
}
|
700
|
-
};
|
701
|
-
|
702
|
-
Caret.prototype.getPosition = function(pos) {
|
703
|
-
var $inputor, at_rect, format, h, html, mirror, start_range, x, y;
|
704
|
-
$inputor = this.$inputor;
|
705
|
-
format = function(value) {
|
706
|
-
return value.replace(/</g, '<').replace(/>/g, '>').replace(/`/g, '`').replace(/"/g, '"').replace(/\r\n|\r|\n/g, "<br />");
|
707
|
-
};
|
708
|
-
pos = pos || this.getPos();
|
709
|
-
start_range = $inputor.val().slice(0, pos);
|
710
|
-
html = "<span>" + format(start_range) + "</span>";
|
711
|
-
html += "<span id='caret'>|</span>";
|
712
|
-
mirror = new Mirror($inputor);
|
713
|
-
at_rect = mirror.create(html).rect();
|
714
|
-
x = at_rect.left - $inputor.scrollLeft();
|
715
|
-
y = at_rect.top - $inputor.scrollTop();
|
716
|
-
h = at_rect.height;
|
717
|
-
return {
|
718
|
-
left: x,
|
719
|
-
top: y,
|
720
|
-
height: h
|
721
|
-
};
|
722
|
-
};
|
723
|
-
|
724
|
-
Caret.prototype.getOffset = function(pos) {
|
725
|
-
var $inputor, h, offset, position, range, x, y;
|
726
|
-
$inputor = this.$inputor;
|
727
|
-
if (document.selection) {
|
728
|
-
range = this.domInputor.createTextRange();
|
729
|
-
if (pos) {
|
730
|
-
range.move('character', pos);
|
731
|
-
}
|
732
|
-
x = range.boundingLeft + $inputor.scrollLeft();
|
733
|
-
y = range.boundingTop + $(window).scrollTop() + $inputor.scrollTop();
|
734
|
-
h = range.boundingHeight;
|
735
|
-
} else {
|
736
|
-
offset = $inputor.offset();
|
737
|
-
position = this.getPosition(pos);
|
738
|
-
x = offset.left + position.left;
|
739
|
-
y = offset.top + position.top;
|
740
|
-
h = position.height;
|
741
|
-
}
|
742
|
-
return {
|
743
|
-
left: x,
|
744
|
-
top: y,
|
745
|
-
height: h
|
746
|
-
};
|
747
|
-
};
|
748
|
-
|
749
|
-
return Caret;
|
750
|
-
|
751
|
-
})();
|
752
|
-
Mirror = (function() {
|
753
|
-
|
754
|
-
Mirror.prototype.css_attr = ["overflowY", "height", "width", "paddingTop", "paddingLeft", "paddingRight", "paddingBottom", "marginTop", "marginLeft", "marginRight", "marginBottom", "fontFamily", "borderStyle", "borderWidth", "wordWrap", "fontSize", "lineHeight", "overflowX", "text-align"];
|
755
|
-
|
756
|
-
function Mirror($inputor) {
|
757
|
-
this.$inputor = $inputor;
|
758
|
-
}
|
759
|
-
|
760
|
-
Mirror.prototype.mirrorCss = function() {
|
761
|
-
var css,
|
762
|
-
_this = this;
|
763
|
-
css = {
|
764
|
-
position: 'absolute',
|
765
|
-
left: -9999,
|
766
|
-
top: 0,
|
767
|
-
zIndex: -20000,
|
768
|
-
'white-space': 'pre-wrap'
|
769
|
-
};
|
770
|
-
$.each(this.css_attr, function(i, p) {
|
771
|
-
return css[p] = _this.$inputor.css(p);
|
772
|
-
});
|
773
|
-
return css;
|
774
|
-
};
|
775
|
-
|
776
|
-
Mirror.prototype.create = function(html) {
|
777
|
-
this.$mirror = $('<div></div>');
|
778
|
-
this.$mirror.css(this.mirrorCss());
|
779
|
-
this.$mirror.html(html);
|
780
|
-
this.$inputor.after(this.$mirror);
|
781
|
-
return this;
|
782
|
-
};
|
783
|
-
|
784
|
-
Mirror.prototype.rect = function() {
|
785
|
-
var $flag, pos, rect;
|
786
|
-
$flag = this.$mirror.find("#caret");
|
787
|
-
pos = $flag.position();
|
788
|
-
rect = {
|
789
|
-
left: pos.left,
|
790
|
-
top: pos.top,
|
791
|
-
height: $flag.height()
|
792
|
-
};
|
793
|
-
this.$mirror.remove();
|
794
|
-
return rect;
|
795
|
-
};
|
796
|
-
|
797
|
-
return Mirror;
|
798
|
-
|
799
|
-
})();
|
800
|
-
methods = {
|
801
|
-
pos: function(pos) {
|
802
|
-
if (pos) {
|
803
|
-
return this.setPos(pos);
|
804
|
-
} else {
|
805
|
-
return this.getPos();
|
806
|
-
}
|
807
|
-
},
|
808
|
-
position: function(pos) {
|
809
|
-
return this.getPosition(pos);
|
810
|
-
},
|
811
|
-
offset: function(pos) {
|
812
|
-
return this.getOffset(pos);
|
813
|
-
}
|
814
|
-
};
|
815
|
-
return $.fn.caret = function(method) {
|
816
|
-
var caret;
|
817
|
-
caret = new Caret(this);
|
818
|
-
if (methods[method]) {
|
819
|
-
return methods[method].apply(caret, Array.prototype.slice.call(arguments, 1));
|
820
|
-
} else {
|
821
|
-
return $.error("Method " + method + " does not exist on jQuery.caret");
|
822
|
-
}
|
823
|
-
};
|
824
|
-
});
|
825
|
-
|
826
|
-
}).call(this);
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-atwho-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- ichord
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-10 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: generator_spec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -54,6 +49,7 @@ extra_rdoc_files: []
|
|
54
49
|
files:
|
55
50
|
- .gitignore
|
56
51
|
- Gemfile
|
52
|
+
- LICENSE-MIT
|
57
53
|
- README.md
|
58
54
|
- Rakefile
|
59
55
|
- changelog.md
|
@@ -67,29 +63,27 @@ files:
|
|
67
63
|
- spec/spec_helper.rb
|
68
64
|
homepage: http://ichord.github.com/jquery-atwho-rails
|
69
65
|
licenses: []
|
66
|
+
metadata: {}
|
70
67
|
post_install_message:
|
71
68
|
rdoc_options: []
|
72
69
|
require_paths:
|
73
70
|
- lib
|
74
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
72
|
requirements:
|
77
73
|
- - '>='
|
78
74
|
- !ruby/object:Gem::Version
|
79
75
|
version: '0'
|
80
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
77
|
requirements:
|
83
78
|
- - '>='
|
84
79
|
- !ruby/object:Gem::Version
|
85
80
|
version: '0'
|
86
81
|
requirements: []
|
87
82
|
rubyforge_project: jquery-atwho-rails
|
88
|
-
rubygems_version:
|
83
|
+
rubygems_version: 2.0.3
|
89
84
|
signing_key:
|
90
|
-
specification_version:
|
85
|
+
specification_version: 4
|
91
86
|
summary: 'jquery plugin: @mentions'
|
92
87
|
test_files:
|
93
88
|
- spec/generators/install_generator_spec.rb
|
94
89
|
- spec/spec_helper.rb
|
95
|
-
has_rdoc:
|