Skip to content

Commit 5493b7f

Browse files
committed
update to v1.1.0
close #17
1 parent 0245f7a commit 5493b7f

File tree

4 files changed

+57
-41
lines changed

4 files changed

+57
-41
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pkg/*
55
*.swp
66
tmp/*
77
build/*
8+
bower_components/

Rakefile

+5-15
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,18 @@ require 'rubygems'
22
require 'bundler/setup'
33
require "bundler/gem_tasks"
44

5-
at_dir = "tmp/At.js"
6-
bower_dir = "#{at_dir}/bower_components/"
5+
bower_dir = "bower_components/"
76

87
desc "sync from At.js"
98
task :sync do
10-
puts " * syncing..."
11-
FileUtils.mkdir_p("tmp") unless Dir.exist? "tmp"
12-
unless Dir.exist? at_dir
13-
system "git clone git://github.com/ichord/At.js.git #{at_dir}"
14-
else
15-
Dir.chdir(at_dir) { puts %x{git pull -X theirs} }
16-
end
17-
Dir.chdir(at_dir) {
18-
puts "* bower install..."
19-
puts %x{bower install}
20-
}
9+
puts "* bower install..."
10+
puts %x{bower install}
2111
end
2212

2313
desc "copy assets"
24-
task fresh: :sync do
14+
task refresh: :sync do
2515
puts " * Copying..."
26-
source_dir = "tmp/At.js/dist"
16+
source_dir = "bower_components/At.js/dist"
2717
dist_dir = "lib/assets"
2818

2919
js_dist_dir = "#{dist_dir}/javascripts/jquery.atwho/"

lib/assets/javascripts/jquery.atwho/jquery.atwho.js

+50-25
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/*! jquery.atwho - v1.0.1 %>
1+
/*! jquery.atwho - v1.1.0 %>
22
* Copyright (c) 2015 chord.luo <chord.luo@gmail.com>;
33
* homepage: http://ichord.github.com/At.js
44
* Licensed MIT
55
*/
66
(function (root, factory) {
77
if (typeof define === 'function' && define.amd) {
88
// AMD. Register as an anonymous module.
9-
define(["jquery"], function ($) {
10-
return (root.returnExportsGlobal = factory($));
9+
define(["jquery"], function (jquery) {
10+
return (root.returnExportsGlobal = factory(jquery));
1111
});
1212
} else if (typeof exports === 'object') {
1313
// Node. Does not work with strict CommonJS, but
@@ -17,7 +17,7 @@
1717
} else {
1818
factory(jQuery);
1919
}
20-
}(this, function ($) {
20+
}(this, function (jquery) {
2121

2222
var Api, App, Controller, DEFAULT_CALLBACKS, EditableController, KEY_CODE, Model, TextareaController, View,
2323
__slice = [].slice,
@@ -35,13 +35,15 @@ App = (function() {
3535
}
3636

3737
App.prototype.createContainer = function(doc) {
38-
if ((this.$el = $("#atwho-container", doc)).length === 0) {
39-
return $(doc.body).append(this.$el = $("<div id='atwho-container'></div>"));
38+
var _ref;
39+
if ((_ref = this.$el) != null) {
40+
_ref.remove();
4041
}
42+
return $(doc.body).append(this.$el = $("<div class='atwho-container'></div>"));
4143
};
4244

4345
App.prototype.setupRootElement = function(iframe, asRoot) {
44-
var error, _ref;
46+
var error;
4547
if (asRoot == null) {
4648
asRoot = false;
4749
}
@@ -57,17 +59,10 @@ App = (function() {
5759
} catch (_error) {
5860
error = _error;
5961
this.iframe = null;
60-
throw new Error("iframe auto-discovery is failed.\nPlease use `serIframe` to set the target iframe manually.");
61-
}
62-
}
63-
if (this.iframeAsRoot = asRoot) {
64-
if ((_ref = this.$el) != null) {
65-
_ref.remove();
62+
throw new Error("iframe auto-discovery is failed.\nPlease use `setIframe` to set the target iframe manually.");
6663
}
67-
return this.createContainer(this.document);
68-
} else {
69-
return this.createContainer(document);
7064
}
65+
return this.createContainer((this.iframeAsRoot = asRoot) ? this.document : document);
7166
};
7267

7368
App.prototype.controller = function(at) {
@@ -107,7 +102,19 @@ App = (function() {
107102
};
108103

109104
App.prototype.listen = function() {
110-
return this.$inputor.on('keyup.atwhoInner', (function(_this) {
105+
return this.$inputor.on('compositionstart', (function(_this) {
106+
return function(e) {
107+
var _ref;
108+
if ((_ref = _this.controller()) != null) {
109+
_ref.view.hide();
110+
}
111+
return _this.isComposing = true;
112+
};
113+
})(this)).on('compositionend', (function(_this) {
114+
return function(e) {
115+
return _this.isComposing = false;
116+
};
117+
})(this)).on('keyup.atwhoInner', (function(_this) {
111118
return function(e) {
112119
return _this.onKeyup(e);
113120
};
@@ -226,9 +233,13 @@ App = (function() {
226233
break;
227234
case KEY_CODE.TAB:
228235
case KEY_CODE.ENTER:
236+
case KEY_CODE.SPACE:
229237
if (!view.visible()) {
230238
return;
231239
}
240+
if (!this.controller().getOpt('spaceSelectsMatch') && e.keyCode === KEY_CODE.SPACE) {
241+
return;
242+
}
232243
e.preventDefault();
233244
view.choose(e);
234245
break;
@@ -501,6 +512,9 @@ EditableController = (function(_super) {
501512

502513
EditableController.prototype.catchQuery = function(e) {
503514
var $inserted, $query, index, inserted, lastNode, matched, offset, query, range, _range;
515+
if (this.app.isComposing) {
516+
return;
517+
}
504518
if (!(range = this._getRange())) {
505519
return;
506520
}
@@ -544,7 +558,8 @@ EditableController = (function(_super) {
544558
matched = this.callbacks("matcher").call(this, this.at, _range.toString(), this.getOpt('startWithSpace'));
545559
if ($query.length === 0 && typeof matched === 'string' && (index = range.startOffset - this.at.length - matched.length) >= 0) {
546560
range.setStart(range.startContainer, index);
547-
range.surroundContents(($query = $("<span class='atwho-query'/>", this.app.document))[0]);
561+
$query = $("<span/>", this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass('atwho-query');
562+
range.surroundContents($query.get(0));
548563
lastNode = $query.contents().last().get(0);
549564
if (/firefox/i.test(navigator.userAgent)) {
550565
range.setStart(lastNode, lastNode.length);
@@ -560,18 +575,21 @@ EditableController = (function(_super) {
560575
el: $query
561576
};
562577
this.trigger("matched", [this.at, query.text]);
578+
return this.query = query;
563579
} else {
564580
this.view.hide();
565-
query = null;
581+
this.query = {
582+
el: $query
583+
};
566584
if ($query.text().indexOf(this.at) >= 0) {
567585
if (this._movingEvent(e) && $query.hasClass('atwho-inserted')) {
568586
$query.removeClass('atwho-query');
569587
} else if (false !== this.callbacks('afterMatchFailed').call(this, this.at, $query)) {
570588
this._setRange("after", this._unwrap($query.text($query.text()).contents().first()));
571589
}
572590
}
591+
return null;
573592
}
574-
return this.query = query;
575593
};
576594

577595
EditableController.prototype.rect = function() {
@@ -847,7 +865,8 @@ KEY_CODE = {
847865
UP: 38,
848866
RIGHT: 39,
849867
DOWN: 40,
850-
BACKSPACE: 8
868+
BACKSPACE: 8,
869+
SPACE: 32
851870
};
852871

853872
DEFAULT_CALLBACKS = {
@@ -862,7 +881,7 @@ DEFAULT_CALLBACKS = {
862881
}
863882
_a = decodeURI("%C3%80");
864883
_y = decodeURI("%C3%BF");
865-
regexp = new RegExp("" + flag + "([A-Za-z" + _a + "-" + _y + "0-9_\+\-]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi');
884+
regexp = new RegExp("" + flag + "([A-Za-z" + _a + "-" + _y + "0-9_\.\+\-]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi');
866885
match = regexp.exec(subtext);
867886
if (match) {
868887
return match[2] || match[1];
@@ -900,9 +919,13 @@ DEFAULT_CALLBACKS = {
900919
});
901920
},
902921
tplEval: function(tpl, map) {
903-
var error;
922+
var error, template;
923+
template = tpl;
904924
try {
905-
return tpl.replace(/\$\{([^\}]*)\}/g, function(tag, key, pos) {
925+
if (typeof tpl !== 'string') {
926+
template = tpl(map);
927+
}
928+
return template.replace(/\$\{([^\}]*)\}/g, function(tag, key, pos) {
906929
return map[key];
907930
});
908931
} catch (_error) {
@@ -988,7 +1011,9 @@ $.fn.atwho["default"] = {
9881011
limit: 5,
9891012
maxLen: 20,
9901013
displayTimeout: 300,
991-
delay: null
1014+
delay: null,
1015+
spaceSelectsMatch: false,
1016+
editableAtwhoQueryAttrs: {}
9921017
};
9931018

9941019

lib/jquery-atwho-rails/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Jquery
22
module Atwho
33
module Rails
4-
VERSION = '1.0.1'
4+
VERSION = '1.1.0'
55
end
66
end
77
end

0 commit comments

Comments
 (0)