jquery-atwho-rails 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1 +1,27 @@
1
1
  require "bundler/gem_tasks"
2
+ #require "uglifier"
3
+
4
+ desc "sync from At.js"
5
+ task :sync do
6
+ at_dir = "tmp/At.js"
7
+ FileUtils.mkdir_p("tmp") if not Dir.exist? "tmp"
8
+ if not Dir.exist? at_dir
9
+ system "git clone git://github.com/ichord/At.js.git #{at_dir}"
10
+ else
11
+ Dir.chdir(at_dir) do
12
+ puts %x{git pull}
13
+ end
14
+ end
15
+ end
16
+
17
+ desc "complie and compress"
18
+ task :fresh => :sync do
19
+ at_dir = "tmp/At.js"
20
+ the_js = "lib/assets/javascripts/jquery.atwho.js"
21
+ sh "coffee -j tmp/atwho.js -c #{at_dir}/coffee"
22
+ #File.open("atwho.js","w") { |f|
23
+ # f.write Uglifier.complie(File.read(the_js))
24
+ #}
25
+ FileUtils.copy_file "tmp/atwho.js", the_js
26
+ FileUtils.copy_file "#{at_dir}/css/jquery.atwho.css", "lib/assets/stylesheets/jquery.atwho.css"
27
+ end
data/changelog.md ADDED
@@ -0,0 +1 @@
1
+ * 2012.7.1 remove the mirror(copy) element of the textarea(inputor) which will disturb css style. increase timeout of displaying the result list view.
@@ -1,44 +1,166 @@
1
- /*
2
- Implement Twitter/Weibo @ mentions
3
1
 
4
- Copyright (c) 2012 chord.luo@gmail.com
2
+ /*
3
+ Implement Twitter/Weibo @ mentions
5
4
 
6
- Permission is hereby granted, free of charge, to any person obtaining
7
- a copy of this software and associated documentation files (the
8
- "Software"), to deal in the Software without restriction, including
9
- without limitation the rights to use, copy, modify, merge, publish,
10
- distribute, sublicense, and/or sell copies of the Software, and to
11
- permit persons to whom the Software is furnished to do so, subject to
12
- the following conditions:
5
+ Copyright (c) 2012 chord.luo@gmail.com
13
6
 
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
16
14
 
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
  */
25
26
 
26
- (function($) {
27
- var At, AtView, Mirror, log, _DEFAULT_TPL, _evalTpl, _highlighter, _isNil, _objectify, _sorter, _unique;
28
- Mirror = function($origin) {
29
- this.init($origin);
30
- return this;
27
+ /*
28
+ 本插件操作 textarea 或者 input 内的插入符
29
+ 只实现了获得插入符在文本框中的位置,我设置
30
+ 插入符的位置.
31
+ */
32
+
33
+ (function() {
34
+
35
+ (function($) {
36
+ var getCaretPos, setCaretPos;
37
+ getCaretPos = function(inputor) {
38
+ var end, endRange, len, normalizedValue, pos, range, start, textInputRange;
39
+ if (document.selection) {
40
+ /*
41
+ #assume we select "HATE" in the inputor such as textarea -> { }.
42
+ * start end-point.
43
+ * /
44
+ * < I really [HATE] IE > between the brackets is the selection range.
45
+ * \
46
+ * end end-point.
47
+ */
48
+ range = document.selection.createRange();
49
+ pos = 0;
50
+ if (range && range.parentElement() === inputor) {
51
+ normalizedValue = inputor.value.replace(/\r\n/g, "\n");
52
+ /* SOMETIME !!!
53
+ "/r/n" is counted as two char.
54
+ one line is two, two will be four. balalala.
55
+ so we have to using the normalized one's length.;
56
+ */
57
+ len = normalizedValue.length;
58
+ /*
59
+ <[ I really HATE IE ]>:
60
+ the whole content in the inputor will be the textInputRange.
61
+ */
62
+ textInputRange = inputor.createTextRange();
63
+ /* _here must be the position of bookmark.
64
+ /
65
+ <[ I really [HATE] IE ]>
66
+ [---------->[ ] : this is what moveToBookmark do.
67
+ < I really [[HATE] IE ]> : here is result.
68
+ \ two brackets in should be in line.
69
+ */
70
+ textInputRange.moveToBookmark(range.getBookmark());
71
+ endRange = inputor.createTextRange();
72
+ /* [--------------------->[] : if set false all end-point goto end.
73
+ < I really [[HATE] IE []]>
74
+ */
75
+ endRange.collapse(false);
76
+ /*
77
+ ___VS____
78
+ / \
79
+ < I really [[HATE] IE []]>
80
+ \_endRange end-point.
81
+
82
+ " > -1" mean the start end-point will be the same or right to the end end-point
83
+ * simplelly, all in the end.
84
+ */
85
+ if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
86
+ start = end = len;
87
+ } else {
88
+ /*
89
+ I really |HATE] IE ]>
90
+ <-|
91
+ I really[ [HATE] IE ]>
92
+ <-[
93
+ I reall[y [HATE] IE ]>
94
+
95
+ will return how many unit have moved.
96
+ */
97
+ start = -textInputRange.moveStart("character", -len);
98
+ end = -textInputRange.moveEnd("character", -len);
99
+ }
100
+ }
101
+ } else {
102
+ start = inputor.selectionStart;
103
+ }
104
+ return start;
31
105
  };
32
- Mirror.prototype = {
106
+ setCaretPos = function(inputor, pos) {
107
+ var range;
108
+ if (document.selection) {
109
+ range = inputor.createTextRange();
110
+ range.move("character", pos);
111
+ return range.select();
112
+ } else {
113
+ return inputor.setSelectionRange(pos, pos);
114
+ }
115
+ };
116
+ return $.fn.caretPos = function(pos) {
117
+ var inputor;
118
+ inputor = this[0];
119
+ inputor.focus();
120
+ if (pos) {
121
+ return setCaretPos(inputor, pos);
122
+ } else {
123
+ return getCaretPos(inputor);
124
+ }
125
+ };
126
+ })(window.jQuery);
127
+
128
+ /*
129
+ Implement Twitter/Weibo @ mentions
130
+
131
+ Copyright (c) 2012 chord.luo@gmail.com
132
+
133
+ Permission is hereby granted, free of charge, to any person obtaining
134
+ a copy of this software and associated documentation files (the
135
+ "Software"), to deal in the Software without restriction, including
136
+ without limitation the rights to use, copy, modify, merge, publish,
137
+ distribute, sublicense, and/or sell copies of the Software, and to
138
+ permit persons to whom the Software is furnished to do so, subject to
139
+ the following conditions:
140
+
141
+ The above copyright notice and this permission notice shall be
142
+ included in all copies or substantial portions of the Software.
143
+
144
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
145
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
146
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
147
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
148
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
149
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
150
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
151
+ */
152
+
153
+ (function($) {
154
+ var At, AtView, Mirror, log, _DEFAULT_TPL, _evalTpl, _highlighter, _isNil, _objectify, _sorter, _unique;
155
+ Mirror = {
33
156
  $mirror: null,
34
157
  css: ["overflowY", "height", "width", "paddingTop", "paddingLeft", "paddingRight", "paddingBottom", "marginTop", "marginLeft", "marginRight", "marginBottom", 'fontFamily', 'borderStyle', 'borderWidth', 'wordWrap', 'fontSize', 'lineHeight', 'overflowX'],
35
158
  init: function($origin) {
36
159
  var $mirror, css;
37
160
  $mirror = $('<div></div>');
38
161
  css = {
39
- opacity: 0,
40
162
  position: 'absolute',
41
- left: 0,
163
+ left: -9999,
42
164
  top: 0,
43
165
  zIndex: -20000,
44
166
  'white-space': 'pre-wrap'
@@ -47,24 +169,25 @@
47
169
  return css[p] = $origin.css(p);
48
170
  });
49
171
  $mirror.css(css);
50
- $('body').append($mirror);
51
- return this.$mirror = $mirror;
172
+ this.$mirror = $mirror;
173
+ $origin.after($mirror);
174
+ return this;
52
175
  },
53
176
  setContent: function(html) {
54
- return this.$mirror.html(html);
177
+ this.$mirror.html(html);
178
+ return this;
55
179
  },
56
180
  getFlagRect: function() {
57
- var $flag, pos;
181
+ var $flag, pos, rect;
58
182
  $flag = this.$mirror.find("span#flag");
59
183
  pos = $flag.position();
60
- return {
184
+ rect = {
61
185
  left: pos.left,
62
186
  top: pos.top,
63
187
  bottom: $flag.height() + pos.top
64
188
  };
65
- },
66
- height: function() {
67
- return this.$mirror.height();
189
+ this.$mirror.remove();
190
+ return rect;
68
191
  }
69
192
  };
70
193
  At = function(inputor) {
@@ -83,7 +206,7 @@
83
206
  this.theflag = null;
84
207
  this.search_word = {};
85
208
  this.view = AtView;
86
- this.mirror = new Mirror($inputor);
209
+ this.mirror = Mirror;
87
210
  $inputor.on("keyup.inputor", function(e) {
88
211
  var lookup, stop;
89
212
  stop = e.keyCode === 40 || e.keyCode === 38;
@@ -110,14 +233,15 @@
110
233
  return log("At.init", this.$inputor[0]);
111
234
  },
112
235
  reg: function(flag, options) {
113
- var opt;
236
+ var opt, _base, _default;
114
237
  opt = {};
115
238
  if ($.isFunction(options)) {
116
239
  opt['callback'] = options;
117
240
  } else {
118
241
  opt = options;
119
242
  }
120
- this.options[flag] = $.extend({}, $.fn.atWho["default"], opt);
243
+ _default = (_base = this.options)[flag] || (_base[flag] = $.fn.atWho["default"]);
244
+ this.options[flag] = $.extend({}, _default, opt);
121
245
  return log("At.reg", this.$inputor[0], flag, options);
122
246
  },
123
247
  dataValue: function() {
@@ -135,7 +259,7 @@
135
259
  }
136
260
  },
137
261
  rect: function() {
138
- var $inputor, Sel, at_rect, bottom, end_range, format, html, mirror, offset, start_range, text, x, y;
262
+ var $inputor, Sel, at_rect, bottom, format, html, offset, start_range, x, y;
139
263
  $inputor = this.$inputor;
140
264
  if (document.selection) {
141
265
  Sel = document.selection.createRange();
@@ -143,25 +267,20 @@
143
267
  y = Sel.boundingTop + $(window).scrollTop() + $inputor.scrollTop();
144
268
  bottom = y + Sel.boundingHeight;
145
269
  return {
146
- top: y,
147
- left: x,
148
- bottom: bottom
270
+ top: y - 2,
271
+ left: x - 2,
272
+ bottom: bottom - 2
149
273
  };
150
274
  }
151
- mirror = this.mirror;
152
275
  format = function(value) {
153
276
  return value.replace(/</g, '&lt').replace(/>/g, '&gt').replace(/`/g, '&#96').replace(/"/g, '&quot').replace(/\r\n|\r|\n/g, "<br />");
154
277
  };
155
278
  /* 克隆完inputor后将原来的文本内容根据
156
279
  @的位置进行分块,以获取@块在inputor(输入框)里的position
157
280
  */
158
- text = $inputor.val();
159
- start_range = text.slice(0, this.pos - 1);
160
- end_range = text.slice(this.pos + 1);
281
+ start_range = $inputor.val().slice(0, this.pos - 1);
161
282
  html = "<span>" + format(start_range) + "</span>";
162
283
  html += "<span id='flag'>@</span>";
163
- html += "<span>" + format(end_range) + "</span>";
164
- mirror.setContent(html);
165
284
  /*
166
285
  将inputor的 offset(相对于document)
167
286
  和@在inputor里的position相加
@@ -169,12 +288,7 @@
169
288
  当然,还要加上行高和滚动条的偏移量.
170
289
  */
171
290
  offset = $inputor.offset();
172
- at_rect = mirror.getFlagRect();
173
- /*
174
- FIXME: -$(window).scrollTop() get "wrong" offset.
175
- but is good for $inputor.scrollTop()
176
- jquey 1. + 07.1 fixed the scrollTop problem!?
177
- */
291
+ at_rect = this.mirror.init($inputor).setContent(html).getFlagRect();
178
292
  x = offset.left + at_rect.left - $inputor.scrollLeft();
179
293
  y = offset.top - $inputor.scrollTop();
180
294
  bottom = y + at_rect.bottom;
@@ -182,7 +296,7 @@
182
296
  return {
183
297
  top: y,
184
298
  left: x,
185
- bottom: bottom
299
+ bottom: bottom + 2
186
300
  };
187
301
  },
188
302
  cache: function(value) {
@@ -366,7 +480,7 @@
366
480
  var cur, next;
367
481
  cur = this.jqo().find('.cur').removeClass('cur');
368
482
  next = cur.next();
369
- if (!cur.length) next = $(this.jqo().find('li')[0]);
483
+ if (!next.length) next = $(this.jqo().find('li')[0]);
370
484
  return next.addClass('cur');
371
485
  },
372
486
  prev: function() {
@@ -507,102 +621,4 @@
507
621
  };
508
622
  })(window.jQuery);
509
623
 
510
-
511
-
512
- /* 本插件操作 textarea 或者 input 内的插入符
513
- * 只实现了获得插入符在文本框中的位置,我设置
514
- * 插入符的位置.
515
- * */
516
- (function($) {
517
- var getCaretPos, setCaretPos;
518
- getCaretPos = function(inputor) {
519
- var end, endRange, len, normalizedValue, pos, range, start, textInputRange;
520
- if (document.selection) {
521
- /*
522
- #assume we select "HATE" in the inputor such as textarea -> { }.
523
- * start end-point.
524
- * /
525
- * < I really [HATE] IE > between the brackets is the selection range.
526
- * \
527
- * end end-point.
528
- */
529
- range = document.selection.createRange();
530
- pos = 0;
531
- if (range && range.parentElement() === inputor) {
532
- normalizedValue = inputor.value.replace(/\r\n/g, "\n");
533
- /* SOMETIME !!!
534
- "/r/n" is counted as two char.
535
- one line is two, two will be four. balalala.
536
- so we have to using the normalized one's length.;
537
- */
538
- len = normalizedValue.length;
539
- /*
540
- <[ I really HATE IE ]>:
541
- the whole content in the inputor will be the textInputRange.
542
- */
543
- textInputRange = inputor.createTextRange();
544
- /* _here must be the position of bookmark.
545
- /
546
- <[ I really [HATE] IE ]>
547
- [---------->[ ] : this is what moveToBookmark do.
548
- < I really [[HATE] IE ]> : here is result.
549
- \ two brackets in should be in line.
550
- */
551
- textInputRange.moveToBookmark(range.getBookmark());
552
- endRange = inputor.createTextRange();
553
- /* [--------------------->[] : if set false all end-point goto end.
554
- < I really [[HATE] IE []]>
555
- */
556
- endRange.collapse(false);
557
- /*
558
- ___VS____
559
- / \
560
- < I really [[HATE] IE []]>
561
- \_endRange end-point.
562
-
563
- " > -1" mean the start end-point will be the same or right to the end end-point
564
- * simplelly, all in the end.
565
- */
566
- if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
567
- start = end = len;
568
- } else {
569
- /*
570
- I really |HATE] IE ]>
571
- <-|
572
- I really[ [HATE] IE ]>
573
- <-[
574
- I reall[y [HATE] IE ]>
575
-
576
- will return how many unit have moved.
577
- */
578
- start = -textInputRange.moveStart("character", -len);
579
- end = -textInputRange.moveEnd("character", -len);
580
- }
581
- }
582
- } else {
583
- start = inputor.selectionStart;
584
- }
585
- return start;
586
- };
587
- setCaretPos = function(inputor, pos) {
588
- var range;
589
- if (document.selection) {
590
- range = inputor.createTextRange();
591
- range.move("character", pos);
592
- return range.select();
593
- } else {
594
- return inputor.setSelectionRange(pos, pos);
595
- }
596
- };
597
- return $.fn.caretPos = function(pos) {
598
- var inputor;
599
- inputor = this[0];
600
- inputor.focus();
601
- if (pos) {
602
- return setCaretPos(inputor, pos);
603
- } else {
604
- return getCaretPos(inputor);
605
- }
606
- };
607
- })(window.jQuery);
608
-
624
+ }).call(this);
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Atwho
3
3
  module Rails
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-atwho-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-08 00:00:00.000000000 Z
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &77809630 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *77809630
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: generator_spec
27
- requirement: &77809240 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *77809240
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  description: ! "This is a jQuery plugin \n that implement Twitter/Weibo like @
37
47
  mentions."
38
48
  email:
@@ -45,6 +55,7 @@ files:
45
55
  - Gemfile
46
56
  - README.md
47
57
  - Rakefile
58
+ - changelog.md
48
59
  - jquery-atwho-rails.gemspec
49
60
  - lib/assets/javascripts/jquery.atwho.js
50
61
  - lib/assets/stylesheets/jquery.atwho.css
@@ -73,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
84
  version: '0'
74
85
  requirements: []
75
86
  rubyforge_project: jquery-atwho-rails
76
- rubygems_version: 1.8.17
87
+ rubygems_version: 1.8.19
77
88
  signing_key:
78
89
  specification_version: 3
79
90
  summary: ! 'jquery plugin: @mentions'