Skip to content

Commit 81446fa

Browse files
committed
sync at c3845e5 of At.js
1 parent d655890 commit 81446fa

File tree

3 files changed

+94
-60
lines changed

3 files changed

+94
-60
lines changed

Diff for: changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
The following date is in changelog file of At.js
3+
https://github.com/ichord/At.js/blob/master/CHANGELOG.md
4+
5+
* sync at 2013-04-23 - At.js(c3845e5)
6+
27
#### 2013.4.15 - v0.2.4
38

49
* `data` setting will be used to load data either local or remote. If it's String as URL it will preload data from remote by launch a ajax request (every times At.js call `reg` to update settings)

Diff for: lib/assets/javascripts/jquery.atwho.js

+88-59
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
(function() {
12+
var __slice = [].slice;
1213

1314
(function(factory) {
1415
if (typeof define === 'function' && define.amd) {
@@ -17,7 +18,7 @@
1718
return factory(window.jQuery);
1819
}
1920
})(function($) {
20-
var Controller, DEFAULT_CALLBACKS, DEFAULT_TPL, KEY_CODE, View;
21+
var Controller, DEFAULT_CALLBACKS, DEFAULT_TPL, KEY_CODE, Model, View;
2122
KEY_CODE = {
2223
DOWN: 40,
2324
UP: 38,
@@ -41,6 +42,7 @@
4142
},
4243
matcher: function(flag, subtext) {
4344
var match, matched, regexp;
45+
flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
4446
regexp = new RegExp(flag + '([A-Za-z0-9_\+\-]*)$|' + flag + '([^\\x00-\\xff]*)$', 'gi');
4547
match = regexp.exec(subtext);
4648
matched = null;
@@ -116,6 +118,56 @@
116118
}
117119
}
118120
};
121+
Model = (function() {
122+
123+
function Model(context) {
124+
this.context = context;
125+
this._data_sets = {};
126+
}
127+
128+
Model.prototype.query = function(query, callback) {
129+
var data, remote_filter, search_key;
130+
data = this.all() || [];
131+
search_key = this.context.get_opt("search_key");
132+
data = this.context.callbacks('filter').call(this.context, query, data, search_key);
133+
if (data && data.length > 0) {
134+
callback(data);
135+
} else if ((remote_filter = this.context.callbacks('remote_filter'))) {
136+
remote_filter.call(this.context, query.text, callback);
137+
} else {
138+
return false;
139+
}
140+
return true;
141+
};
142+
143+
Model.prototype.all = function(key) {
144+
return this._data_sets[key || (key = this.context.current_flag)];
145+
};
146+
147+
Model.prototype.reset = function(data, key) {
148+
return this._data_sets[key || (key = this.context.current_flag)] = this.context.callbacks("data_refactor").call(this.context, data);
149+
};
150+
151+
Model.prototype.load = function(data) {
152+
if (typeof data === "string") {
153+
return this._load_remote_data(data);
154+
} else {
155+
return this.reset(data);
156+
}
157+
};
158+
159+
Model.prototype._load_remote_data = function(url) {
160+
var _this = this;
161+
return $.ajax(url, {
162+
dataType: "json"
163+
}).done(function(data) {
164+
return _this.reset(data);
165+
});
166+
};
167+
168+
return Model;
169+
170+
})();
119171
Controller = (function() {
120172

121173
function Controller(inputor) {
@@ -124,9 +176,9 @@
124176
this.flags = null;
125177
this.current_flag = null;
126178
this.query = null;
127-
this._data_sets = {};
128179
this.$inputor = $(inputor);
129180
this.view = new View(this, this.$el);
181+
this.model = new Model(this);
130182
this.listen();
131183
}
132184

@@ -144,15 +196,10 @@
144196
};
145197

146198
Controller.prototype.reg = function(flag, settings) {
147-
var current_settings, data;
199+
var current_settings;
148200
this.current_flag = flag;
149201
current_settings = this.settings[flag] ? this.settings[flag] = $.extend({}, this.settings[flag], settings) : this.settings[flag] = $.extend({}, $.fn.atwho["default"], settings);
150-
data = current_settings.data;
151-
if (typeof data === "string") {
152-
this.load_remote_data(data);
153-
} else {
154-
this.save_data(data);
155-
}
202+
this.model.load(current_settings.data);
156203
return this;
157204
};
158205

@@ -162,12 +209,14 @@
162209
return this.$inputor.trigger("" + name + ".atwho", data);
163210
};
164211

165-
Controller.prototype.get_data = function(key) {
166-
return this._data_sets[key || (key = this.current_flag)];
167-
};
168-
169-
Controller.prototype.save_data = function(data, key) {
170-
return this._data_sets[key || (key = this.current_flag)] = this.callbacks("data_refactor").call(this, data);
212+
Controller.prototype.super_call = function() {
213+
var args, func_name;
214+
func_name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
215+
try {
216+
return DEFAULT_CALLBACKS[func_name].apply(this, args);
217+
} catch (error) {
218+
return $.error("" + error + " Or maybe At.js doesn't have function " + func_name);
219+
}
171220
};
172221

173222
Controller.prototype.callbacks = function(func_name) {
@@ -191,7 +240,7 @@
191240
var c, scale, scale_bottom;
192241
c = this.$inputor.caret('offset', this.pos - 1);
193242
if (document.selection) {
194-
scale_bottom = scale = -2;
243+
scale_bottom = scale = 0;
195244
} else {
196245
scale = 0;
197246
scale_bottom = 2;
@@ -259,7 +308,6 @@
259308
default:
260309
this.look_up();
261310
}
262-
return e.stopPropagation();
263311
};
264312

265313
Controller.prototype.on_keydown = function(e) {
@@ -290,7 +338,6 @@
290338
default:
291339
$.noop();
292340
}
293-
return e.stopPropagation();
294341
};
295342

296343
Controller.prototype.render_view = function(data) {
@@ -301,49 +348,33 @@
301348
return this.view.render(data);
302349
};
303350

304-
Controller.prototype.remote_call = function(query) {
305-
var _callback;
306-
_callback = function(data) {
307-
return this.render_view(data);
308-
};
309-
_callback = $.proxy(_callback, this);
310-
return this.callbacks('remote_filter').call(this, query.text, _callback);
311-
};
312-
313-
Controller.prototype.load_remote_data = function(url) {
314-
var _this = this;
315-
return $.get(url).done(function(data) {
316-
return _this.save_data(data);
317-
});
318-
};
319-
320351
Controller.prototype.look_up = function() {
321-
var data, query, search_key;
352+
var query, _callback;
322353
query = this.catch_query();
323354
if (!query) {
324-
return false;
355+
return;
325356
}
326-
data = this.get_data();
327-
search_key = this.get_opt("search_key");
328-
data = this.callbacks('filter').call(this, query.text, data || [], search_key);
329-
if (data && data.length > 0) {
330-
this.render_view(data);
331-
} else if (this.callbacks('remote_filter')) {
332-
this.remote_call(query);
333-
} else {
334-
this.view.hide();
357+
_callback = function(data) {
358+
if (data) {
359+
return this.render_view(data);
360+
} else {
361+
return this.view.hide();
362+
}
363+
};
364+
_callback = $.proxy(_callback, this);
365+
if (!this.model.query(query.text, _callback)) {
366+
return this.view.hide();
335367
}
336-
return $.noop();
337368
};
338369

339370
return Controller;
340371

341372
})();
342373
View = (function() {
343374

344-
function View(controller) {
345-
this.controller = controller;
346-
this.id = this.controller.get_opt("view_id") || "at-view";
375+
function View(context) {
376+
this.context = context;
377+
this.id = this.context.get_opt("view_id") || "at-view";
347378
this.timeout_id = null;
348379
this.$el = $("#" + this.id);
349380
this.create_view();
@@ -363,7 +394,6 @@
363394
$menu.find('.cur').removeClass('cur');
364395
return $(e.currentTarget).addClass('cur');
365396
}).on('click', function(e) {
366-
e.stopPropagation();
367397
e.preventDefault();
368398
return _this.$el.data("_view").choose();
369399
});
@@ -380,14 +410,14 @@
380410
View.prototype.choose = function() {
381411
var $li;
382412
$li = this.$el.find(".cur");
383-
this.controller.callbacks("selector").call(this.controller, $li);
384-
this.controller.trigger("choose", [$li]);
413+
this.context.callbacks("selector").call(this.context, $li);
414+
this.context.trigger("choose", [$li]);
385415
return this.hide();
386416
};
387417

388418
View.prototype.reposition = function() {
389419
var offset, rect;
390-
rect = this.controller.rect();
420+
rect = this.context.rect();
391421
if (rect.bottom + this.$el.height() - $(window).scrollTop() > $(window).height()) {
392422
rect.bottom = rect.top - this.$el.height();
393423
}
@@ -396,7 +426,7 @@
396426
top: rect.bottom
397427
};
398428
this.$el.offset(offset);
399-
return this.controller.trigger("reposition", [offset]);
429+
return this.context.trigger("reposition", [offset]);
400430
};
401431

402432
View.prototype.next = function() {
@@ -459,11 +489,11 @@
459489
this.clear();
460490
this.$el.data("_view", this);
461491
$ul = this.$el.find('ul');
462-
tpl = this.controller.get_opt('tpl', DEFAULT_TPL);
492+
tpl = this.context.get_opt('tpl', DEFAULT_TPL);
463493
$.each(list, function(i, item) {
464494
var $li, li;
465-
li = _this.controller.callbacks("tpl_eval").call(_this.controller, tpl, item);
466-
$li = $(_this.controller.callbacks("highlighter").call(_this.controller, li, _this.controller.query.text));
495+
li = _this.context.callbacks("tpl_eval").call(_this.context, tpl, item);
496+
$li = $(_this.context.callbacks("highlighter").call(_this.context, li, _this.context.query.text));
467497
$li.data("info", item);
468498
return $ul.append($li);
469499
});
@@ -487,7 +517,6 @@
487517
});
488518
};
489519
$.fn.atwho.Controller = Controller;
490-
$.fn.atwho.View = View;
491520
return $.fn.atwho["default"] = {
492521
data: null,
493522
search_key: "name",
@@ -655,7 +684,7 @@
655684
var $inputor, h, offset, position, range, x, y;
656685
$inputor = this.$inputor;
657686
if (document.selection) {
658-
range = this.domInputor.createRange();
687+
range = this.domInputor.createTextRange();
659688
if (pos) {
660689
range.move('character', pos);
661690
}

Diff for: 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 = "0.2.4"
4+
VERSION = "0.2.5"
55
end
66
end
77
end

0 commit comments

Comments
 (0)