jquery-atwho-rails 0.4.11 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +3 -0
- data/Gemfile +7 -2
- data/README.md +7 -5
- data/Rakefile +2 -0
- data/gemfiles/rails30.gemfile +8 -0
- data/gemfiles/rails30.gemfile.lock +105 -0
- data/lib/assets/javascripts/jquery.atwho/jquery.atwho.js +97 -91
- data/lib/assets/javascripts/jquery.atwho/jquery.caret.js +39 -33
- data/lib/assets/stylesheets/jquery.atwho.css +1 -1
- data/lib/generators/atwho/install_generator.rb +2 -1
- data/lib/jquery-atwho-rails/version.rb +1 -1
- data/spec/generators/install_generator_spec.rb +5 -9
- data/spec/spec_helper.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec1b0e0e1b0876d6881d5bc64f8a08ab858a3399
|
4
|
+
data.tar.gz: 97e3bfd53d3df6ce4b6223d9532711563bc86510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c61673d1cb967107e63e150726e4b0780b5f349caa140b4460a0e8d20334054263f9dd3c85e95277de1af5f0afd64eb9c6a7115687849a8f21c65846509d59d8
|
7
|
+
data.tar.gz: e02326f5c3ae2782022b11c349951efa636f80afb72549368f1a89c5bbd63995dafff2210e797e1af03286cd9722fa44b02e019a68f4b12b20a756e2b93bf161
|
data/Appraisals
ADDED
data/Gemfile
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
|
2
|
-
source
|
1
|
+
if ENV['TRAVIS']
|
2
|
+
source 'https://rubygems.org'
|
3
|
+
else
|
4
|
+
source 'http://ruby.taobao.org'
|
5
|
+
end
|
3
6
|
|
4
7
|
# Specify your gem's dependencies in jquery-atwho-rails.gemspec
|
5
8
|
gemspec
|
9
|
+
|
10
|
+
gem 'appraisal'
|
data/README.md
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
Bind your textarea
|
4
4
|
|
5
5
|
```javascript
|
6
|
-
|
7
|
-
|
6
|
+
$(function(){
|
7
|
+
data = ['tom','john'];
|
8
|
+
$('textarea').atwho({at:"@", 'data':data});
|
9
|
+
});
|
8
10
|
```
|
9
11
|
|
10
12
|
that's it, check it out!
|
@@ -17,12 +19,12 @@ Issue command line bellow:
|
|
17
19
|
`rails generate atwho:install`
|
18
20
|
then It will show in `public/[javascript|stylesheets]/` directory.
|
19
21
|
|
20
|
-
#### Rails 3.1.x
|
22
|
+
#### Rails >= 3.1.x
|
21
23
|
Add this gem in `Gemfile` like this:
|
22
24
|
`gem jquery-atwho-rails`
|
23
25
|
|
24
26
|
then add
|
25
|
-
` //= require jquery.atwho
|
27
|
+
` //= require jquery.atwho ` to `app/assets/javascripts/application.js`
|
26
28
|
and add ` //=require jquery.atwho ` to `app/assets/stylesheets/applications.css`
|
27
29
|
|
28
30
|
#### History Versions
|
@@ -32,4 +34,4 @@ All in [At.js](https://github.com/ichord/At.js) project.
|
|
32
34
|
---
|
33
35
|
#### Test generator
|
34
36
|
Just issue
|
35
|
-
`bundle` then `rspec`
|
37
|
+
`bundle` then `appraisal rails30 rspec`
|
data/Rakefile
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
jquery-atwho-rails (0.4.11)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://ruby.taobao.org/
|
8
|
+
specs:
|
9
|
+
abstract (1.0.0)
|
10
|
+
actionmailer (3.0.20)
|
11
|
+
actionpack (= 3.0.20)
|
12
|
+
mail (~> 2.2.19)
|
13
|
+
actionpack (3.0.20)
|
14
|
+
activemodel (= 3.0.20)
|
15
|
+
activesupport (= 3.0.20)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
erubis (~> 2.6.6)
|
18
|
+
i18n (~> 0.5.0)
|
19
|
+
rack (~> 1.2.5)
|
20
|
+
rack-mount (~> 0.6.14)
|
21
|
+
rack-test (~> 0.5.7)
|
22
|
+
tzinfo (~> 0.3.23)
|
23
|
+
activemodel (3.0.20)
|
24
|
+
activesupport (= 3.0.20)
|
25
|
+
builder (~> 2.1.2)
|
26
|
+
i18n (~> 0.5.0)
|
27
|
+
activerecord (3.0.20)
|
28
|
+
activemodel (= 3.0.20)
|
29
|
+
activesupport (= 3.0.20)
|
30
|
+
arel (~> 2.0.10)
|
31
|
+
tzinfo (~> 0.3.23)
|
32
|
+
activeresource (3.0.20)
|
33
|
+
activemodel (= 3.0.20)
|
34
|
+
activesupport (= 3.0.20)
|
35
|
+
activesupport (3.0.20)
|
36
|
+
appraisal (1.0.0)
|
37
|
+
bundler
|
38
|
+
rake
|
39
|
+
thor (>= 0.14.0)
|
40
|
+
arel (2.0.10)
|
41
|
+
builder (2.1.2)
|
42
|
+
diff-lcs (1.2.5)
|
43
|
+
erubis (2.6.6)
|
44
|
+
abstract (>= 1.0.0)
|
45
|
+
generator_spec (0.9.2)
|
46
|
+
activesupport (>= 3.0.0)
|
47
|
+
railties (>= 3.0.0)
|
48
|
+
i18n (0.5.4)
|
49
|
+
json (1.8.1)
|
50
|
+
mail (2.2.20)
|
51
|
+
activesupport (>= 2.3.6)
|
52
|
+
i18n (>= 0.4.0)
|
53
|
+
mime-types (~> 1.16)
|
54
|
+
treetop (~> 1.4.8)
|
55
|
+
mime-types (1.25.1)
|
56
|
+
polyglot (0.3.5)
|
57
|
+
rack (1.2.8)
|
58
|
+
rack-mount (0.6.14)
|
59
|
+
rack (>= 1.0.0)
|
60
|
+
rack-test (0.5.7)
|
61
|
+
rack (>= 1.0)
|
62
|
+
rails (3.0.20)
|
63
|
+
actionmailer (= 3.0.20)
|
64
|
+
actionpack (= 3.0.20)
|
65
|
+
activerecord (= 3.0.20)
|
66
|
+
activeresource (= 3.0.20)
|
67
|
+
activesupport (= 3.0.20)
|
68
|
+
bundler (~> 1.0)
|
69
|
+
railties (= 3.0.20)
|
70
|
+
railties (3.0.20)
|
71
|
+
actionpack (= 3.0.20)
|
72
|
+
activesupport (= 3.0.20)
|
73
|
+
rake (>= 0.8.7)
|
74
|
+
rdoc (~> 3.4)
|
75
|
+
thor (~> 0.14.4)
|
76
|
+
rake (10.3.2)
|
77
|
+
rdoc (3.12.2)
|
78
|
+
json (~> 1.4)
|
79
|
+
rspec (3.0.0)
|
80
|
+
rspec-core (~> 3.0.0)
|
81
|
+
rspec-expectations (~> 3.0.0)
|
82
|
+
rspec-mocks (~> 3.0.0)
|
83
|
+
rspec-core (3.0.4)
|
84
|
+
rspec-support (~> 3.0.0)
|
85
|
+
rspec-expectations (3.0.4)
|
86
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
87
|
+
rspec-support (~> 3.0.0)
|
88
|
+
rspec-mocks (3.0.4)
|
89
|
+
rspec-support (~> 3.0.0)
|
90
|
+
rspec-support (3.0.4)
|
91
|
+
thor (0.14.6)
|
92
|
+
treetop (1.4.15)
|
93
|
+
polyglot
|
94
|
+
polyglot (>= 0.3.1)
|
95
|
+
tzinfo (0.3.41)
|
96
|
+
|
97
|
+
PLATFORMS
|
98
|
+
ruby
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
appraisal
|
102
|
+
generator_spec
|
103
|
+
jquery-atwho-rails!
|
104
|
+
rails (~> 3.0.0)
|
105
|
+
rspec
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! jquery.atwho - v0.
|
1
|
+
/*! jquery.atwho - v0.5.0 - 2014-07-14
|
2
2
|
* Copyright (c) 2014 chord.luo <chord.luo@gmail.com>;
|
3
3
|
* homepage: http://ichord.github.com/At.js
|
4
4
|
* Licensed MIT
|
@@ -13,7 +13,7 @@
|
|
13
13
|
}
|
14
14
|
})(function($) {
|
15
15
|
|
16
|
-
var $CONTAINER, Api, App,
|
16
|
+
var $CONTAINER, Api, App, Controller, DEFAULT_CALLBACKS, KEY_CODE, Model, View,
|
17
17
|
__slice = [].slice;
|
18
18
|
|
19
19
|
App = (function() {
|
@@ -28,25 +28,36 @@ App = (function() {
|
|
28
28
|
}
|
29
29
|
|
30
30
|
App.prototype.setIframe = function(iframe) {
|
31
|
-
var error;
|
32
31
|
if (iframe) {
|
33
32
|
this.window = iframe.contentWindow;
|
34
33
|
this.document = iframe.contentDocument || this.window.document;
|
35
|
-
this.iframe = iframe;
|
36
|
-
return this;
|
34
|
+
return this.iframe = iframe;
|
37
35
|
} else {
|
38
|
-
this.document =
|
39
|
-
this.window =
|
40
|
-
|
41
|
-
return this.iframe = this.window.frameElement;
|
42
|
-
} catch (_error) {
|
43
|
-
error = _error;
|
44
|
-
}
|
36
|
+
this.document = document;
|
37
|
+
this.window = window;
|
38
|
+
return this.iframe = null;
|
45
39
|
}
|
46
40
|
};
|
47
41
|
|
48
42
|
App.prototype.controller = function(at) {
|
49
|
-
|
43
|
+
var c, current, current_flag, _ref;
|
44
|
+
if (this.alias_maps[at]) {
|
45
|
+
current = this.controllers[this.alias_maps[at]];
|
46
|
+
} else {
|
47
|
+
_ref = this.controllers;
|
48
|
+
for (current_flag in _ref) {
|
49
|
+
c = _ref[current_flag];
|
50
|
+
if (current_flag === at) {
|
51
|
+
current = c;
|
52
|
+
break;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
if (current) {
|
57
|
+
return current;
|
58
|
+
} else {
|
59
|
+
return this.controllers[this.current_flag];
|
60
|
+
}
|
50
61
|
};
|
51
62
|
|
52
63
|
App.prototype.set_context_for = function(at) {
|
@@ -76,15 +87,20 @@ App = (function() {
|
|
76
87
|
})(this)).on('scroll.atwhoInner', (function(_this) {
|
77
88
|
return function(e) {
|
78
89
|
var _ref;
|
79
|
-
return (_ref = _this.controller()) != null ? _ref.view.hide() : void 0;
|
90
|
+
return (_ref = _this.controller()) != null ? _ref.view.hide(e) : void 0;
|
80
91
|
};
|
81
92
|
})(this)).on('blur.atwhoInner', (function(_this) {
|
82
93
|
return function(e) {
|
83
94
|
var c;
|
84
95
|
if (c = _this.controller()) {
|
85
|
-
return c.view.hide(c.get_opt("display_timeout"));
|
96
|
+
return c.view.hide(e, c.get_opt("display_timeout"));
|
86
97
|
}
|
87
98
|
};
|
99
|
+
})(this)).on('click.atwhoInner', (function(_this) {
|
100
|
+
return function(e) {
|
101
|
+
var _ref;
|
102
|
+
return (_ref = _this.controller()) != null ? _ref.view.hide(e) : void 0;
|
103
|
+
};
|
88
104
|
})(this));
|
89
105
|
};
|
90
106
|
|
@@ -153,7 +169,7 @@ App = (function() {
|
|
153
169
|
switch (e.keyCode) {
|
154
170
|
case KEY_CODE.ESC:
|
155
171
|
e.preventDefault();
|
156
|
-
view.hide();
|
172
|
+
view.hide(e);
|
157
173
|
break;
|
158
174
|
case KEY_CODE.UP:
|
159
175
|
e.preventDefault();
|
@@ -183,7 +199,7 @@ App = (function() {
|
|
183
199
|
return;
|
184
200
|
}
|
185
201
|
e.preventDefault();
|
186
|
-
view.choose();
|
202
|
+
view.choose(e);
|
187
203
|
break;
|
188
204
|
default:
|
189
205
|
$.noop();
|
@@ -274,7 +290,9 @@ Controller = (function() {
|
|
274
290
|
Controller.prototype.catch_query = function() {
|
275
291
|
var caret_pos, content, end, query, start, subtext;
|
276
292
|
content = this.content();
|
277
|
-
caret_pos = this.$inputor.caret('pos'
|
293
|
+
caret_pos = this.$inputor.caret('pos', {
|
294
|
+
iframe: this.app.iframe
|
295
|
+
});
|
278
296
|
subtext = content.slice(0, caret_pos);
|
279
297
|
query = this.callbacks("matcher").call(this, this.at, subtext, this.get_opt('start_with_space'));
|
280
298
|
if (typeof query === "string" && query.length <= this.get_opt('max_len', 20)) {
|
@@ -296,9 +314,9 @@ Controller = (function() {
|
|
296
314
|
|
297
315
|
Controller.prototype.rect = function() {
|
298
316
|
var c, scale_bottom;
|
299
|
-
if (!(c = this.$inputor.caret({
|
317
|
+
if (!(c = this.$inputor.caret('offset', this.pos - 1, {
|
300
318
|
iframe: this.app.iframe
|
301
|
-
})
|
319
|
+
}))) {
|
302
320
|
return;
|
303
321
|
}
|
304
322
|
if (this.$inputor.attr('contentEditable') === 'true') {
|
@@ -344,37 +362,32 @@ Controller = (function() {
|
|
344
362
|
};
|
345
363
|
|
346
364
|
Controller.prototype.insert = function(content, $li) {
|
347
|
-
var $inputor,
|
365
|
+
var $inputor, content_node, pos, range, sel, source, start_str, text, wrapped_content;
|
348
366
|
$inputor = this.$inputor;
|
349
|
-
|
350
|
-
class_name = "atwho-view-flag atwho-view-flag-" + (this.get_opt('alias') || this.at);
|
351
|
-
content_node = "" + content + "<span contenteditable='false'> <span>";
|
352
|
-
insert_node = "<span contenteditable='false' class='" + class_name + "'>" + content_node + "</span>";
|
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);
|
356
|
-
}
|
357
|
-
}
|
367
|
+
wrapped_content = this.callbacks('inserting_wrapper').call(this, $inputor, content, this.get_opt("suffix"));
|
358
368
|
if ($inputor.is('textarea, input')) {
|
359
|
-
content = '' + content;
|
360
369
|
source = $inputor.val();
|
361
370
|
start_str = source.slice(0, Math.max(this.query.head_pos - this.at.length, 0));
|
362
|
-
text = "" + start_str +
|
371
|
+
text = "" + start_str + wrapped_content + (source.slice(this.query['end_pos'] || 0));
|
363
372
|
$inputor.val(text);
|
364
|
-
$inputor.caret('pos', start_str.length +
|
373
|
+
$inputor.caret('pos', start_str.length + wrapped_content.length, {
|
374
|
+
iframe: this.app.iframe
|
375
|
+
});
|
365
376
|
} else if (range = this.range) {
|
366
377
|
pos = range.startOffset - (this.query.end_pos - this.query.head_pos) - this.at.length;
|
367
378
|
range.setStart(range.endContainer, Math.max(pos, 0));
|
368
379
|
range.setEnd(range.endContainer, range.endOffset);
|
369
380
|
range.deleteContents();
|
370
|
-
|
381
|
+
content_node = $(wrapped_content, this.app.document)[0];
|
382
|
+
range.insertNode(content_node);
|
383
|
+
range.setEndAfter(content_node);
|
371
384
|
range.collapse(false);
|
372
385
|
sel = this.app.window.getSelection();
|
373
386
|
sel.removeAllRanges();
|
374
387
|
sel.addRange(range);
|
375
388
|
} else if (range = this.ie8_range) {
|
376
389
|
range.moveStart('character', this.query.end_pos - this.query.head_pos - this.at.length);
|
377
|
-
range.pasteHTML(
|
390
|
+
range.pasteHTML(wrapped_content);
|
378
391
|
range.collapse(false);
|
379
392
|
range.select();
|
380
393
|
}
|
@@ -504,7 +517,7 @@ View = (function() {
|
|
504
517
|
return $(e.currentTarget).addClass('cur');
|
505
518
|
}).on('click', (function(_this) {
|
506
519
|
return function(e) {
|
507
|
-
_this.choose();
|
520
|
+
_this.choose(e);
|
508
521
|
return e.preventDefault();
|
509
522
|
};
|
510
523
|
})(this));
|
@@ -514,13 +527,16 @@ View = (function() {
|
|
514
527
|
return this.$el.is(":visible");
|
515
528
|
};
|
516
529
|
|
517
|
-
View.prototype.choose = function() {
|
530
|
+
View.prototype.choose = function(e) {
|
518
531
|
var $li, content;
|
519
532
|
if (($li = this.$el.find(".cur")).length) {
|
520
533
|
content = this.context.insert_content_for($li);
|
521
534
|
this.context.insert(this.context.callbacks("before_insert").call(this.context, content, $li), $li);
|
522
|
-
this.context.trigger("inserted", [$li]);
|
523
|
-
|
535
|
+
this.context.trigger("inserted", [$li, e]);
|
536
|
+
this.hide(e);
|
537
|
+
}
|
538
|
+
if (this.context.get_opt("hide_without_suffix")) {
|
539
|
+
return this.stop_showing = true;
|
524
540
|
}
|
525
541
|
};
|
526
542
|
|
@@ -562,6 +578,10 @@ View = (function() {
|
|
562
578
|
|
563
579
|
View.prototype.show = function() {
|
564
580
|
var rect;
|
581
|
+
if (this.stop_showing) {
|
582
|
+
this.stop_showing = false;
|
583
|
+
return;
|
584
|
+
}
|
565
585
|
this.context.mark_range();
|
566
586
|
if (!this.visible()) {
|
567
587
|
this.$el.show();
|
@@ -572,12 +592,15 @@ View = (function() {
|
|
572
592
|
}
|
573
593
|
};
|
574
594
|
|
575
|
-
View.prototype.hide = function(time) {
|
595
|
+
View.prototype.hide = function(e, time) {
|
576
596
|
var callback;
|
577
|
-
if (
|
597
|
+
if (!this.visible()) {
|
598
|
+
return;
|
599
|
+
}
|
600
|
+
if (isNaN(time)) {
|
578
601
|
this.context.reset_rect();
|
579
602
|
this.$el.hide();
|
580
|
-
return this.context.trigger('hidden');
|
603
|
+
return this.context.trigger('hidden', [e]);
|
581
604
|
} else {
|
582
605
|
callback = (function(_this) {
|
583
606
|
return function() {
|
@@ -707,13 +730,32 @@ DEFAULT_CALLBACKS = {
|
|
707
730
|
if (!query) {
|
708
731
|
return li;
|
709
732
|
}
|
710
|
-
regexp = new RegExp(">\\s*(\\w
|
733
|
+
regexp = new RegExp(">\\s*(\\w*?)(" + query.replace("+", "\\+") + ")(\\w*)\\s*<", 'ig');
|
711
734
|
return li.replace(regexp, function(str, $1, $2, $3) {
|
712
735
|
return '> ' + $1 + '<strong>' + $2 + '</strong>' + $3 + ' <';
|
713
736
|
});
|
714
737
|
},
|
715
738
|
before_insert: function(value, $li) {
|
716
739
|
return value;
|
740
|
+
},
|
741
|
+
inserting_wrapper: function($inputor, content, suffix) {
|
742
|
+
var new_suffix, wrapped_content;
|
743
|
+
new_suffix = suffix === "" ? suffix : suffix || " ";
|
744
|
+
if ($inputor.is('textarea, input')) {
|
745
|
+
return '' + content + new_suffix;
|
746
|
+
} else if ($inputor.attr('contentEditable') === 'true') {
|
747
|
+
new_suffix = suffix === "" ? suffix : suffix || " ";
|
748
|
+
if (/firefox/i.test(navigator.userAgent)) {
|
749
|
+
wrapped_content = "<span>" + content + new_suffix + "</span>";
|
750
|
+
} else {
|
751
|
+
suffix = "<span contenteditable='false'>" + new_suffix + "<span>";
|
752
|
+
wrapped_content = "<span contenteditable='false'>" + content + suffix + "</span>";
|
753
|
+
}
|
754
|
+
if (this.app.document.selection) {
|
755
|
+
wrapped_content = "<span contenteditable='true'>" + content + "</span>";
|
756
|
+
}
|
757
|
+
return wrapped_content;
|
758
|
+
}
|
717
759
|
}
|
718
760
|
};
|
719
761
|
|
@@ -724,36 +766,9 @@ Api = {
|
|
724
766
|
return c.model.load(data);
|
725
767
|
}
|
726
768
|
},
|
727
|
-
getInsertedItemsWithIDs: function(at) {
|
728
|
-
var c, ids, items;
|
729
|
-
if (!(c = this.controller(at))) {
|
730
|
-
return [null, null];
|
731
|
-
}
|
732
|
-
if (at) {
|
733
|
-
at = "-" + (c.get_opt('alias') || c.at);
|
734
|
-
}
|
735
|
-
ids = [];
|
736
|
-
items = $.map(this.$inputor.find("span.atwho-view-flag" + (at || "")), function(item) {
|
737
|
-
var data;
|
738
|
-
data = $(item).data('atwho-data-item');
|
739
|
-
if (ids.indexOf(data.id) > -1) {
|
740
|
-
return;
|
741
|
-
}
|
742
|
-
if (data.id) {
|
743
|
-
ids.push = data.id;
|
744
|
-
}
|
745
|
-
return data;
|
746
|
-
});
|
747
|
-
return [ids, items];
|
748
|
-
},
|
749
|
-
getInsertedItems: function(at) {
|
750
|
-
return Api.getInsertedItemsWithIDs.apply(this, [at])[1];
|
751
|
-
},
|
752
|
-
getInsertedIDs: function(at) {
|
753
|
-
return Api.getInsertedItemsWithIDs.apply(this, [at])[0];
|
754
|
-
},
|
755
769
|
setIframe: function(iframe) {
|
756
|
-
|
770
|
+
this.setIframe(iframe);
|
771
|
+
return null;
|
757
772
|
},
|
758
773
|
run: function() {
|
759
774
|
return this.dispatch();
|
@@ -764,18 +779,6 @@ Api = {
|
|
764
779
|
}
|
765
780
|
};
|
766
781
|
|
767
|
-
Atwho = {
|
768
|
-
init: function(options) {
|
769
|
-
var $this, app;
|
770
|
-
app = ($this = $(this)).data("atwho");
|
771
|
-
if (!app) {
|
772
|
-
$this.data('atwho', (app = new App(this)));
|
773
|
-
}
|
774
|
-
app.reg(options.at, options);
|
775
|
-
return this;
|
776
|
-
}
|
777
|
-
};
|
778
|
-
|
779
782
|
$CONTAINER = $("<div id='atwho-container'></div>");
|
780
783
|
|
781
784
|
$.fn.atwho = function(method) {
|
@@ -784,13 +787,14 @@ $.fn.atwho = function(method) {
|
|
784
787
|
$('body').append($CONTAINER);
|
785
788
|
result = null;
|
786
789
|
this.filter('textarea, input, [contenteditable=true]').each(function() {
|
787
|
-
var app;
|
790
|
+
var $this, app;
|
791
|
+
if (!(app = ($this = $(this)).data("atwho"))) {
|
792
|
+
$this.data('atwho', (app = new App(this)));
|
793
|
+
}
|
788
794
|
if (typeof method === 'object' || !method) {
|
789
|
-
return
|
790
|
-
} else if (Api[method]) {
|
791
|
-
|
792
|
-
return result = Api[method].apply(app, Array.prototype.slice.call(_args, 1));
|
793
|
-
}
|
795
|
+
return app.reg(method.at, method);
|
796
|
+
} else if (Api[method] && app) {
|
797
|
+
return result = Api[method].apply(app, Array.prototype.slice.call(_args, 1));
|
794
798
|
} else {
|
795
799
|
return $.error("Method " + method + " does not exist on jQuery.caret");
|
796
800
|
}
|
@@ -803,9 +807,11 @@ $.fn.atwho["default"] = {
|
|
803
807
|
alias: void 0,
|
804
808
|
data: null,
|
805
809
|
tpl: "<li data-value='${atwho-at}${name}'>${name}</li>",
|
806
|
-
insert_tpl: "<span>${atwho-data-value}</span>",
|
810
|
+
insert_tpl: "<span id='${id}'>${atwho-data-value}</span>",
|
807
811
|
callbacks: DEFAULT_CALLBACKS,
|
808
812
|
search_key: "name",
|
813
|
+
suffix: void 0,
|
814
|
+
hide_without_suffix: false,
|
809
815
|
start_with_space: true,
|
810
816
|
highlight_first: true,
|
811
817
|
limit: 5,
|
@@ -24,7 +24,7 @@
|
|
24
24
|
}
|
25
25
|
})(function($) {
|
26
26
|
"use strict";
|
27
|
-
var EditableCaret, InputCaret, Mirror, Utils,
|
27
|
+
var EditableCaret, InputCaret, Mirror, Utils, discoveryIframeOf, methods, oDocument, oFrame, oWindow, pluginName, setContextBy;
|
28
28
|
pluginName = 'caret';
|
29
29
|
EditableCaret = (function() {
|
30
30
|
function EditableCaret($inputor) {
|
@@ -204,7 +204,7 @@
|
|
204
204
|
};
|
205
205
|
|
206
206
|
InputCaret.prototype.getPosition = function(pos) {
|
207
|
-
var $inputor, at_rect, format, html, mirror, start_range;
|
207
|
+
var $inputor, at_rect, end_range, format, html, mirror, start_range;
|
208
208
|
$inputor = this.$inputor;
|
209
209
|
format = function(value) {
|
210
210
|
return value.replace(/</g, '<').replace(/>/g, '>').replace(/`/g, '`').replace(/"/g, '"').replace(/\r\n|\r|\n/g, "<br />");
|
@@ -213,8 +213,10 @@
|
|
213
213
|
pos = this.getPos();
|
214
214
|
}
|
215
215
|
start_range = $inputor.val().slice(0, pos);
|
216
|
-
|
217
|
-
html
|
216
|
+
end_range = $inputor.val().slice(pos);
|
217
|
+
html = "<span style='position: relative; display: inline;'>" + format(start_range) + "</span>";
|
218
|
+
html += "<span id='caret' style='position: relative; display: inline;'>|</span>";
|
219
|
+
html += "<span style='position: relative; display: inline;'>" + format(end_range) + "</span>";
|
218
220
|
mirror = new Mirror($inputor);
|
219
221
|
return at_rect = mirror.create(html).rect();
|
220
222
|
};
|
@@ -237,7 +239,7 @@
|
|
237
239
|
|
238
240
|
})();
|
239
241
|
Mirror = (function() {
|
240
|
-
Mirror.prototype.css_attr = ["
|
242
|
+
Mirror.prototype.css_attr = ["borderBottomWidth", "borderLeftWidth", "borderRightWidth", "borderTopStyle", "borderRightStyle", "borderBottomStyle", "borderLeftStyle", "borderTopWidth", "boxSizing", "fontFamily", "fontSize", "fontWeight", "height", "letterSpacing", "lineHeight", "marginBottom", "marginLeft", "marginRight", "marginTop", "outlineWidth", "overflow", "overflowX", "overflowY", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop", "textAlign", "textOverflow", "textTransform", "whiteSpace", "wordBreak", "wordWrap"];
|
241
243
|
|
242
244
|
function Mirror($inputor) {
|
243
245
|
this.$inputor = $inputor;
|
@@ -250,9 +252,11 @@
|
|
250
252
|
position: 'absolute',
|
251
253
|
left: -9999,
|
252
254
|
top: 0,
|
253
|
-
zIndex: -20000
|
254
|
-
'white-space': 'pre-wrap'
|
255
|
+
zIndex: -20000
|
255
256
|
};
|
257
|
+
if (this.$inputor.prop('tagName') === 'TEXTAREA') {
|
258
|
+
this.css_attr.push('width');
|
259
|
+
}
|
256
260
|
$.each(this.css_attr, function(i, p) {
|
257
261
|
return css[p] = _this.$inputor.css(p);
|
258
262
|
});
|
@@ -317,37 +321,39 @@
|
|
317
321
|
oDocument = null;
|
318
322
|
oWindow = null;
|
319
323
|
oFrame = null;
|
320
|
-
setContextBy = function(
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
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);
|
324
|
+
setContextBy = function(settings) {
|
325
|
+
var iframe;
|
326
|
+
if (iframe = settings != null ? settings.iframe : void 0) {
|
327
|
+
oFrame = iframe;
|
328
|
+
oWindow = iframe.contentWindow;
|
329
|
+
return oDocument = iframe.contentDocument || oWindow.document;
|
332
330
|
} else {
|
333
|
-
|
334
|
-
oWindow =
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
331
|
+
oFrame = void 0;
|
332
|
+
oWindow = window;
|
333
|
+
return oDocument = document;
|
334
|
+
}
|
335
|
+
};
|
336
|
+
discoveryIframeOf = function($dom) {
|
337
|
+
var error;
|
338
|
+
oDocument = $dom[0].ownerDocument;
|
339
|
+
oWindow = oDocument.defaultView || oDocument.parentWindow;
|
340
|
+
try {
|
341
|
+
return oFrame = oWindow.frameElement;
|
342
|
+
} catch (_error) {
|
343
|
+
error = _error;
|
340
344
|
}
|
341
345
|
};
|
342
|
-
$.fn.caret = function(method) {
|
346
|
+
$.fn.caret = function(method, value, settings) {
|
343
347
|
var caret;
|
344
|
-
if (
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
348
|
+
if (methods[method]) {
|
349
|
+
if ($.isPlainObject(value)) {
|
350
|
+
setContextBy(value);
|
351
|
+
value = void 0;
|
352
|
+
} else {
|
353
|
+
setContextBy(settings);
|
354
|
+
}
|
349
355
|
caret = Utils.contentEditable(this) ? new EditableCaret(this) : new InputCaret(this);
|
350
|
-
return methods[method].apply(caret,
|
356
|
+
return methods[method].apply(caret, [value]);
|
351
357
|
} else {
|
352
358
|
return $.error("Method " + method + " does not exist on jQuery.caret");
|
353
359
|
}
|
@@ -12,7 +12,8 @@ if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
|
|
12
12
|
|
13
13
|
def copy_js
|
14
14
|
say_status("copying js", " jquery.atwho.js (#{Jquery::Atwho::Rails::VERSION})", :green)
|
15
|
-
copy_file "javascripts/jquery.atwho.js", "public/javascripts/jquery.atwho.js"
|
15
|
+
copy_file "javascripts/jquery.atwho/jquery.caret.js", "public/javascripts/jquery.atwho/jquery.caret.js"
|
16
|
+
copy_file "javascripts/jquery.atwho/jquery.atwho.js", "public/javascripts/jquery.atwho/jquery.atwho.js"
|
16
17
|
#copy_file "javascripts/jquery.atwho.min.js", "public/javascripts/jquery.atwho.min.js"
|
17
18
|
end
|
18
19
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Atwho::Generators::InstallGenerator do
|
4
4
|
include GeneratorSpec::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
destination File.expand_path("../../../tmp/", __FILE__)
|
7
7
|
before(:all) do
|
8
8
|
prepare_destination
|
@@ -10,13 +10,9 @@ describe Atwho::Generators::InstallGenerator do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "generate assets files" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#assert_file "#{js_prefix}/jquery.atwho.min.js"
|
18
|
-
|
19
|
-
assert_file "#{css_prefix}/jquery.atwho.css"
|
20
|
-
#assert_file "#{css_prefix}/jquery.atwho.min.css"
|
13
|
+
if ::Rails.version < "3.1"
|
14
|
+
assert_file "public/javascripts/jquery.atwho/jquery.atwho.js"
|
15
|
+
assert_file "public/stylesheets/jquery.atwho.css"
|
16
|
+
end
|
21
17
|
end
|
22
18
|
end
|
data/spec/spec_helper.rb
CHANGED
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
|
+
version: 0.5.0
|
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-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -48,11 +48,14 @@ extensions: []
|
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
50
|
- .gitignore
|
51
|
+
- Appraisals
|
51
52
|
- Gemfile
|
52
53
|
- LICENSE-MIT
|
53
54
|
- README.md
|
54
55
|
- Rakefile
|
55
56
|
- changelog.md
|
57
|
+
- gemfiles/rails30.gemfile
|
58
|
+
- gemfiles/rails30.gemfile.lock
|
56
59
|
- jquery-atwho-rails.gemspec
|
57
60
|
- lib/assets/javascripts/jquery.atwho/index.js
|
58
61
|
- lib/assets/javascripts/jquery.atwho/jquery.atwho.js
|