jquery-atwho-rails 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -18,7 +18,7 @@
|
|
18
18
|
return factory(window.jQuery);
|
19
19
|
}
|
20
20
|
})(function($) {
|
21
|
-
var Controller, DEFAULT_CALLBACKS, DEFAULT_TPL, KEY_CODE, Model, View;
|
21
|
+
var $CONTAINER, Api, Controller, DEFAULT_CALLBACKS, DEFAULT_TPL, KEY_CODE, Model, View;
|
22
22
|
KEY_CODE = {
|
23
23
|
DOWN: 40,
|
24
24
|
UP: 38,
|
@@ -27,77 +27,67 @@
|
|
27
27
|
ENTER: 13
|
28
28
|
};
|
29
29
|
DEFAULT_CALLBACKS = {
|
30
|
-
|
30
|
+
before_save: function(data) {
|
31
|
+
var item, _i, _len, _results;
|
31
32
|
if (!$.isArray(data)) {
|
32
33
|
return data;
|
33
34
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
_results = [];
|
36
|
+
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
37
|
+
item = data[_i];
|
38
|
+
if ($.isPlainObject(item)) {
|
39
|
+
_results.push(item);
|
40
|
+
} else {
|
41
|
+
_results.push({
|
37
42
|
name: item
|
38
|
-
};
|
43
|
+
});
|
39
44
|
}
|
40
|
-
|
41
|
-
|
45
|
+
}
|
46
|
+
return _results;
|
42
47
|
},
|
43
48
|
matcher: function(flag, subtext) {
|
44
|
-
var match,
|
45
|
-
flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
49
|
+
var match, regexp;
|
50
|
+
flag = '(?:^|\\s)' + flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
46
51
|
regexp = new RegExp(flag + '([A-Za-z0-9_\+\-]*)$|' + flag + '([^\\x00-\\xff]*)$', 'gi');
|
47
52
|
match = regexp.exec(subtext);
|
48
|
-
matched = null;
|
49
53
|
if (match) {
|
50
|
-
|
54
|
+
return match[2] || match[1];
|
55
|
+
} else {
|
56
|
+
return null;
|
51
57
|
}
|
52
|
-
return matched;
|
53
58
|
},
|
54
59
|
filter: function(query, data, search_key) {
|
55
|
-
var
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
if (
|
60
|
-
|
60
|
+
var item, _i, _len, _results;
|
61
|
+
_results = [];
|
62
|
+
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
63
|
+
item = data[_i];
|
64
|
+
if (~item[search_key].toLowerCase().indexOf(query)) {
|
65
|
+
_results.push(item);
|
61
66
|
}
|
62
|
-
}
|
67
|
+
}
|
68
|
+
return _results;
|
63
69
|
},
|
64
70
|
remote_filter: null,
|
65
71
|
sorter: function(query, items, search_key) {
|
66
|
-
var item,
|
72
|
+
var item, _i, _len, _results;
|
67
73
|
if (!query) {
|
68
|
-
return items
|
69
|
-
if (a[search_key].toLowerCase() > b[search_key].toLowerCase()) {
|
70
|
-
return 1;
|
71
|
-
} else {
|
72
|
-
return -1;
|
73
|
-
}
|
74
|
-
});
|
74
|
+
return items;
|
75
75
|
}
|
76
|
-
|
76
|
+
_results = [];
|
77
77
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
78
78
|
item = items[_i];
|
79
|
-
|
80
|
-
item.atwho_order
|
81
|
-
|
79
|
+
item.atwho_order = item[search_key].toLowerCase().indexOf(query);
|
80
|
+
if (item.atwho_order > -1) {
|
81
|
+
_results.push(item);
|
82
|
+
}
|
82
83
|
}
|
83
|
-
|
84
|
+
return _results.sort(function(a, b) {
|
84
85
|
return a.atwho_order - b.atwho_order;
|
85
86
|
});
|
86
|
-
return results = (function() {
|
87
|
-
var _j, _len1, _results;
|
88
|
-
_results = [];
|
89
|
-
for (_j = 0, _len1 = results.length; _j < _len1; _j++) {
|
90
|
-
item = results[_j];
|
91
|
-
delete item["atwho_order"];
|
92
|
-
_results.push(item);
|
93
|
-
}
|
94
|
-
return _results;
|
95
|
-
})();
|
96
87
|
},
|
97
88
|
tpl_eval: function(tpl, map) {
|
98
|
-
var el;
|
99
89
|
try {
|
100
|
-
return
|
90
|
+
return tpl.replace(/\$\{([^\}]*)\}/g, function(tag, key, pos) {
|
101
91
|
return map[key];
|
102
92
|
});
|
103
93
|
} catch (error) {
|
@@ -105,80 +95,97 @@
|
|
105
95
|
}
|
106
96
|
},
|
107
97
|
highlighter: function(li, query) {
|
98
|
+
var regexp;
|
108
99
|
if (!query) {
|
109
100
|
return li;
|
110
101
|
}
|
111
|
-
|
102
|
+
regexp = new RegExp(">\\s*(\\w*)(" + query.replace("+", "\\+") + ")(\\w*)\\s*<", 'ig');
|
103
|
+
return li.replace(regexp, function(str, $1, $2, $3) {
|
112
104
|
return '> ' + $1 + '<strong>' + $2 + '</strong>' + $3 + ' <';
|
113
105
|
});
|
114
106
|
},
|
115
|
-
|
116
|
-
|
117
|
-
return this.replace_str($li.data("value") || "");
|
118
|
-
}
|
107
|
+
before_insert: function(value, $li) {
|
108
|
+
return value;
|
119
109
|
}
|
120
110
|
};
|
121
111
|
Model = (function() {
|
112
|
+
var _storage;
|
122
113
|
|
123
|
-
|
114
|
+
_storage = {};
|
115
|
+
|
116
|
+
function Model(context, key) {
|
124
117
|
this.context = context;
|
125
|
-
this.
|
118
|
+
this.key = key;
|
126
119
|
}
|
127
120
|
|
121
|
+
Model.prototype.saved = function() {
|
122
|
+
return this.fetch() > 0;
|
123
|
+
};
|
124
|
+
|
128
125
|
Model.prototype.query = function(query, callback) {
|
129
|
-
var data,
|
130
|
-
data = this.
|
126
|
+
var data, search_key, _ref;
|
127
|
+
data = this.fetch();
|
131
128
|
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
|
-
|
135
|
-
} else if ((remote_filter = this.context.callbacks('remote_filter'))) {
|
136
|
-
remote_filter.call(this.context, query.text, callback);
|
137
|
-
} else {
|
138
|
-
return false;
|
129
|
+
callback(data = this.context.callbacks('filter').call(this.context, query, data, search_key));
|
130
|
+
if (!(data && data.length > 0)) {
|
131
|
+
return (_ref = this.context.callbacks('remote_filter')) != null ? _ref.call(this.context, query, callback) : void 0;
|
139
132
|
}
|
140
|
-
return true;
|
141
133
|
};
|
142
134
|
|
143
|
-
Model.prototype.
|
144
|
-
return this.
|
135
|
+
Model.prototype.fetch = function() {
|
136
|
+
return _storage[this.key] || [];
|
145
137
|
};
|
146
138
|
|
147
|
-
Model.prototype.
|
148
|
-
return this.
|
139
|
+
Model.prototype.save = function(data) {
|
140
|
+
return _storage[this.key] = this.context.callbacks("before_save").call(this.context, data || []);
|
149
141
|
};
|
150
142
|
|
151
143
|
Model.prototype.load = function(data) {
|
152
|
-
if (
|
153
|
-
return this.
|
154
|
-
} else {
|
155
|
-
return this.reset(data);
|
144
|
+
if (!(this.saved() || !data)) {
|
145
|
+
return this._load(data);
|
156
146
|
}
|
157
147
|
};
|
158
148
|
|
159
|
-
Model.prototype.
|
149
|
+
Model.prototype.reload = function(data) {
|
150
|
+
return this._load(data);
|
151
|
+
};
|
152
|
+
|
153
|
+
Model.prototype._load = function(data) {
|
160
154
|
var _this = this;
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
155
|
+
if (typeof data === "string") {
|
156
|
+
return $.ajax(data, {
|
157
|
+
dataType: "json"
|
158
|
+
}).done(function(data) {
|
159
|
+
return _this.save(data);
|
160
|
+
});
|
161
|
+
} else {
|
162
|
+
return this.save(data);
|
163
|
+
}
|
166
164
|
};
|
167
165
|
|
168
166
|
return Model;
|
169
167
|
|
170
168
|
})();
|
171
169
|
Controller = (function() {
|
170
|
+
var uuid, _uuid;
|
171
|
+
|
172
|
+
_uuid = 0;
|
173
|
+
|
174
|
+
uuid = function() {
|
175
|
+
return _uuid += 1;
|
176
|
+
};
|
172
177
|
|
173
178
|
function Controller(inputor) {
|
179
|
+
this.id = inputor.id || uuid();
|
174
180
|
this.settings = {};
|
175
181
|
this.pos = 0;
|
176
|
-
this.flags = null;
|
177
182
|
this.current_flag = null;
|
178
183
|
this.query = null;
|
184
|
+
this.the_flag = {};
|
185
|
+
this._views = {};
|
186
|
+
this._models = {};
|
179
187
|
this.$inputor = $(inputor);
|
180
|
-
this
|
181
|
-
this.model = new Model(this);
|
188
|
+
$CONTAINER.append(this.$el = $("<div id='atwho-ground-" + this.id + "'></div>"));
|
182
189
|
this.listen();
|
183
190
|
}
|
184
191
|
|
@@ -189,24 +196,36 @@
|
|
189
196
|
}).on('keydown.atwho', function(e) {
|
190
197
|
return _this.on_keydown(e);
|
191
198
|
}).on('scroll.atwho', function(e) {
|
192
|
-
|
199
|
+
var _ref;
|
200
|
+
return (_ref = _this.view) != null ? _ref.hide() : void 0;
|
193
201
|
}).on('blur.atwho', function(e) {
|
194
|
-
|
202
|
+
var _ref;
|
203
|
+
return (_ref = _this.view) != null ? _ref.hide(_this.get_opt("display_timeout")) : void 0;
|
195
204
|
});
|
196
205
|
};
|
197
206
|
|
207
|
+
Controller.prototype.set_context_for = function(flag) {
|
208
|
+
flag = this.current_flag = this.the_flag[flag];
|
209
|
+
this.view = this._views[flag];
|
210
|
+
this.model = this._models[flag];
|
211
|
+
return this;
|
212
|
+
};
|
213
|
+
|
198
214
|
Controller.prototype.reg = function(flag, settings) {
|
199
|
-
var
|
200
|
-
this.
|
201
|
-
|
202
|
-
this.
|
215
|
+
var setting;
|
216
|
+
setting = this.settings[flag] = $.extend({}, this.settings[flag] || $.fn.atwho["default"], settings);
|
217
|
+
this.set_context_for(flag = (setting.alias ? this.the_flag[setting.alias] = flag : void 0, this.the_flag[flag] = flag));
|
218
|
+
(this._models[flag] = new Model(this, flag)).reload(setting.data);
|
219
|
+
this._views[flag] = new View(this, flag);
|
203
220
|
return this;
|
204
221
|
};
|
205
222
|
|
206
223
|
Controller.prototype.trigger = function(name, data) {
|
207
|
-
|
224
|
+
var alias, event_name;
|
208
225
|
data.push(this);
|
209
|
-
|
226
|
+
alias = this.get_opt('alias');
|
227
|
+
event_name = alias ? "" + name + "-" + alias + ".atwho" : "" + name + ".atwho";
|
228
|
+
return this.$inputor.trigger(event_name, data);
|
210
229
|
};
|
211
230
|
|
212
231
|
Controller.prototype.super_call = function() {
|
@@ -220,12 +239,7 @@
|
|
220
239
|
};
|
221
240
|
|
222
241
|
Controller.prototype.callbacks = function(func_name) {
|
223
|
-
|
224
|
-
func = this.get_opt("callbacks")[func_name];
|
225
|
-
if (!func) {
|
226
|
-
func = DEFAULT_CALLBACKS[func_name];
|
227
|
-
}
|
228
|
-
return func;
|
242
|
+
return this.get_opt("callbacks")[func_name] || DEFAULT_CALLBACKS[func_name];
|
229
243
|
};
|
230
244
|
|
231
245
|
Controller.prototype.get_opt = function(key, default_value) {
|
@@ -237,36 +251,32 @@
|
|
237
251
|
};
|
238
252
|
|
239
253
|
Controller.prototype.rect = function() {
|
240
|
-
var c,
|
254
|
+
var c, scale_bottom;
|
241
255
|
c = this.$inputor.caret('offset', this.pos - 1);
|
242
|
-
|
243
|
-
scale_bottom = scale = 0;
|
244
|
-
} else {
|
245
|
-
scale = 0;
|
246
|
-
scale_bottom = 2;
|
247
|
-
}
|
256
|
+
scale_bottom = document.selection ? 0 : 2;
|
248
257
|
return {
|
249
|
-
left: c.left
|
250
|
-
top: c.top
|
258
|
+
left: c.left,
|
259
|
+
top: c.top,
|
251
260
|
bottom: c.top + c.height + scale_bottom
|
252
261
|
};
|
253
262
|
};
|
254
263
|
|
255
264
|
Controller.prototype.catch_query = function() {
|
256
|
-
var caret_pos, content, end, query, start, subtext,
|
265
|
+
var caret_pos, content, end, query, start, subtext, _ref,
|
257
266
|
_this = this;
|
258
267
|
content = this.$inputor.val();
|
259
268
|
caret_pos = this.$inputor.caret('pos');
|
260
269
|
subtext = content.slice(0, caret_pos);
|
261
270
|
query = null;
|
262
|
-
$.
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
271
|
+
$.map(this.settings, function(setting) {
|
272
|
+
var _result;
|
273
|
+
_result = _this.callbacks("matcher").call(_this, setting.at, subtext);
|
274
|
+
if (_result != null) {
|
275
|
+
query = _result;
|
276
|
+
return _this.set_context_for(setting.at);
|
267
277
|
}
|
268
278
|
});
|
269
|
-
if (typeof query === "string" && query.length <= 20) {
|
279
|
+
if (typeof query === "string" && query.length <= this.get_opt('max_len', 20)) {
|
270
280
|
start = caret_pos - query.length;
|
271
281
|
end = start + query.length;
|
272
282
|
this.pos = start;
|
@@ -277,12 +287,14 @@
|
|
277
287
|
};
|
278
288
|
this.trigger("matched", [this.current_flag, query.text]);
|
279
289
|
} else {
|
280
|
-
this.view
|
290
|
+
if ((_ref = this.view) != null) {
|
291
|
+
_ref.hide();
|
292
|
+
}
|
281
293
|
}
|
282
294
|
return this.query = query;
|
283
295
|
};
|
284
296
|
|
285
|
-
Controller.prototype.
|
297
|
+
Controller.prototype.insert = function(str) {
|
286
298
|
var $inputor, flag_len, source, start_str, text;
|
287
299
|
$inputor = this.$inputor;
|
288
300
|
str = '' + str;
|
@@ -311,7 +323,8 @@
|
|
311
323
|
};
|
312
324
|
|
313
325
|
Controller.prototype.on_keydown = function(e) {
|
314
|
-
|
326
|
+
var _ref;
|
327
|
+
if (!((_ref = this.view) != null ? _ref.visible() : void 0)) {
|
315
328
|
return;
|
316
329
|
}
|
317
330
|
switch (e.keyCode) {
|
@@ -343,28 +356,23 @@
|
|
343
356
|
Controller.prototype.render_view = function(data) {
|
344
357
|
var search_key;
|
345
358
|
search_key = this.get_opt("search_key");
|
346
|
-
data = this.callbacks("sorter").call(this, this.query.text, data, search_key);
|
347
|
-
|
348
|
-
return this.view.render(data);
|
359
|
+
data = this.callbacks("sorter").call(this, this.query.text, data.slice(0, 1001), search_key);
|
360
|
+
return this.view.render(data.slice(0, this.get_opt('limit')));
|
349
361
|
};
|
350
362
|
|
351
363
|
Controller.prototype.look_up = function() {
|
352
364
|
var query, _callback;
|
353
|
-
query = this.catch_query()
|
354
|
-
if (!query) {
|
365
|
+
if (!(query = this.catch_query())) {
|
355
366
|
return;
|
356
367
|
}
|
357
368
|
_callback = function(data) {
|
358
|
-
if (data) {
|
369
|
+
if (data && data.length > 0) {
|
359
370
|
return this.render_view(data);
|
360
371
|
} else {
|
361
372
|
return this.view.hide();
|
362
373
|
}
|
363
374
|
};
|
364
|
-
|
365
|
-
if (!this.model.query(query.text, _callback)) {
|
366
|
-
return this.view.hide();
|
367
|
-
}
|
375
|
+
return this.model.query(query.text, $.proxy(_callback, this));
|
368
376
|
};
|
369
377
|
|
370
378
|
return Controller;
|
@@ -372,37 +380,29 @@
|
|
372
380
|
})();
|
373
381
|
View = (function() {
|
374
382
|
|
375
|
-
function View(context) {
|
383
|
+
function View(context, key) {
|
376
384
|
this.context = context;
|
377
|
-
this.
|
385
|
+
this.key = key;
|
386
|
+
this.id = this.context.get_opt("alias") || ("at-view-" + (this.key.charCodeAt(0)));
|
387
|
+
this.$el = $("<div id='" + this.id + "' class='atwho-view'><ul id='" + this.id + "-ul' class='atwho-view-url'></ul></div>");
|
378
388
|
this.timeout_id = null;
|
379
|
-
this.$el
|
380
|
-
this.
|
389
|
+
this.context.$el.append(this.$el);
|
390
|
+
this.bind_event();
|
381
391
|
}
|
382
392
|
|
383
|
-
View.prototype.
|
384
|
-
var $menu,
|
393
|
+
View.prototype.bind_event = function() {
|
394
|
+
var $menu,
|
385
395
|
_this = this;
|
386
|
-
if (this.exist()) {
|
387
|
-
return;
|
388
|
-
}
|
389
|
-
tpl = "<div id='" + this.id + "' class='at-view'><ul id='" + this.id + "-ul'></ul></div>";
|
390
|
-
$("body").append(tpl);
|
391
|
-
this.$el = $("#" + this.id);
|
392
396
|
$menu = this.$el.find('ul');
|
393
397
|
return $menu.on('mouseenter.view', 'li', function(e) {
|
394
398
|
$menu.find('.cur').removeClass('cur');
|
395
399
|
return $(e.currentTarget).addClass('cur');
|
396
400
|
}).on('click', function(e) {
|
397
|
-
|
398
|
-
return
|
401
|
+
_this.choose();
|
402
|
+
return e.preventDefault();
|
399
403
|
});
|
400
404
|
};
|
401
405
|
|
402
|
-
View.prototype.exist = function() {
|
403
|
-
return $("#" + this.id).length > 0;
|
404
|
-
};
|
405
|
-
|
406
406
|
View.prototype.visible = function() {
|
407
407
|
return this.$el.is(":visible");
|
408
408
|
};
|
@@ -410,8 +410,8 @@
|
|
410
410
|
View.prototype.choose = function() {
|
411
411
|
var $li;
|
412
412
|
$li = this.$el.find(".cur");
|
413
|
-
this.context.callbacks("
|
414
|
-
this.context.trigger("
|
413
|
+
this.context.insert(this.context.callbacks("before_insert").call(this.context, $li.data("value"), $li));
|
414
|
+
this.context.trigger("inserted", [$li]);
|
415
415
|
return this.hide();
|
416
416
|
};
|
417
417
|
|
@@ -434,7 +434,7 @@
|
|
434
434
|
cur = this.$el.find('.cur').removeClass('cur');
|
435
435
|
next = cur.next();
|
436
436
|
if (!next.length) {
|
437
|
-
next =
|
437
|
+
next = this.$el.find('li:first');
|
438
438
|
}
|
439
439
|
return next.addClass('cur');
|
440
440
|
};
|
@@ -444,7 +444,7 @@
|
|
444
444
|
cur = this.$el.find('.cur').removeClass('cur');
|
445
445
|
prev = cur.prev();
|
446
446
|
if (!prev.length) {
|
447
|
-
prev = this.$el.find('li')
|
447
|
+
prev = this.$el.find('li:last');
|
448
448
|
}
|
449
449
|
return prev.addClass('cur');
|
450
450
|
};
|
@@ -459,10 +459,8 @@
|
|
459
459
|
View.prototype.hide = function(time) {
|
460
460
|
var callback,
|
461
461
|
_this = this;
|
462
|
-
if (isNaN(time)) {
|
463
|
-
|
464
|
-
return this.$el.hide();
|
465
|
-
}
|
462
|
+
if (isNaN(time && this.visible())) {
|
463
|
+
return this.$el.hide();
|
466
464
|
} else {
|
467
465
|
callback = function() {
|
468
466
|
return _this.hide();
|
@@ -472,59 +470,76 @@
|
|
472
470
|
}
|
473
471
|
};
|
474
472
|
|
475
|
-
View.prototype.clear = function() {
|
476
|
-
return this.$el.find('ul').empty();
|
477
|
-
};
|
478
|
-
|
479
473
|
View.prototype.render = function(list) {
|
480
|
-
var $ul, tpl,
|
481
|
-
|
482
|
-
if (!$.isArray(list)) {
|
483
|
-
return false;
|
484
|
-
}
|
485
|
-
if (list.length <= 0) {
|
474
|
+
var $li, $ul, item, li, tpl, _i, _len;
|
475
|
+
if (!$.isArray(list || list.length <= 0)) {
|
486
476
|
this.hide();
|
487
|
-
return
|
477
|
+
return;
|
488
478
|
}
|
489
|
-
this.
|
490
|
-
this.$el.data("_view", this);
|
479
|
+
this.$el.find('ul').empty();
|
491
480
|
$ul = this.$el.find('ul');
|
492
481
|
tpl = this.context.get_opt('tpl', DEFAULT_TPL);
|
493
|
-
|
494
|
-
|
495
|
-
li =
|
496
|
-
$li = $(
|
497
|
-
$li.data("info", item);
|
498
|
-
|
499
|
-
}
|
482
|
+
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
483
|
+
item = list[_i];
|
484
|
+
li = this.context.callbacks("tpl_eval").call(this.context, tpl, item);
|
485
|
+
$li = $(this.context.callbacks("highlighter").call(this.context, li, this.context.query.text));
|
486
|
+
$li.data("atwho-info", item);
|
487
|
+
$ul.append($li);
|
488
|
+
}
|
500
489
|
this.show();
|
501
|
-
return $ul.find("li:
|
490
|
+
return $ul.find("li:first").addClass("cur");
|
502
491
|
};
|
503
492
|
|
504
493
|
return View;
|
505
494
|
|
506
495
|
})();
|
507
496
|
DEFAULT_TPL = "<li data-value='${name}'>${name}</li>";
|
508
|
-
|
497
|
+
Api = {
|
498
|
+
init: function(options) {
|
499
|
+
var $this, app;
|
500
|
+
app = ($this = $(this)).data("atwho");
|
501
|
+
if (!app) {
|
502
|
+
$this.data('atwho', (app = new Controller(this)));
|
503
|
+
}
|
504
|
+
return app.reg(options.at, options);
|
505
|
+
},
|
506
|
+
load: function(flag, data) {
|
507
|
+
this.set_context_for(flag);
|
508
|
+
return this.model.load(data);
|
509
|
+
},
|
510
|
+
run: function() {
|
511
|
+
return this.look_up();
|
512
|
+
}
|
513
|
+
};
|
514
|
+
$CONTAINER = $("<div id='atwho-container'></div>");
|
515
|
+
$.fn.atwho = function(method) {
|
516
|
+
var _args;
|
517
|
+
_args = arguments;
|
518
|
+
$('body').append($CONTAINER);
|
509
519
|
return this.filter('textarea, input').each(function() {
|
510
|
-
var
|
511
|
-
|
512
|
-
|
513
|
-
if (
|
514
|
-
$this.data('atwho'
|
520
|
+
var app;
|
521
|
+
if (typeof method === 'object' || !method) {
|
522
|
+
return Api.init.apply(this, _args);
|
523
|
+
} else if (Api[method]) {
|
524
|
+
if (app = $(this).data('atwho')) {
|
525
|
+
return Api[method].apply(app, Array.prototype.slice.call(_args, 1));
|
526
|
+
}
|
527
|
+
} else {
|
528
|
+
return $.error("Method " + method + " does not exist on jQuery.caret");
|
515
529
|
}
|
516
|
-
return data.reg(flag, options);
|
517
530
|
});
|
518
531
|
};
|
519
|
-
$.fn.atwho.Controller = Controller;
|
520
532
|
return $.fn.atwho["default"] = {
|
533
|
+
at: void 0,
|
534
|
+
alias: void 0,
|
521
535
|
data: null,
|
522
|
-
|
536
|
+
tpl: DEFAULT_TPL,
|
523
537
|
callbacks: DEFAULT_CALLBACKS,
|
538
|
+
search_key: "name",
|
524
539
|
limit: 5,
|
540
|
+
max_len: 20,
|
525
541
|
display_flag: true,
|
526
|
-
display_timeout: 300
|
527
|
-
tpl: DEFAULT_TPL
|
542
|
+
display_timeout: 300
|
528
543
|
};
|
529
544
|
});
|
530
545
|
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
.atwho-view{position:absolute;top:0;left:0;display:none;margin-top:18px;background:#fff;border:1px solid #DDD;border-radius:3px;box-shadow:0 0 5px rgba(0,0,0,.1);min-width:120px;z-index:10}.atwho-view .cur{background:#36F;color:#fff}.atwho-view .cur small{color:#fff}.atwho-view strong{color:#36F}.atwho-view .cur strong{color:#fff;font:bold}.atwho-view ul{list-style:none;padding:0;margin:auto}.atwho-view ul li{display:block;padding:5px 10px;border-bottom:1px solid #DDD;cursor:pointer}.atwho-view small{font-size:smaller;color:#777;font-weight:400}
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -77,18 +77,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
77
|
- - '>='
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
|
-
segments:
|
81
|
-
- 0
|
82
|
-
hash: 3505150916323372414
|
83
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
81
|
none: false
|
85
82
|
requirements:
|
86
83
|
- - '>='
|
87
84
|
- !ruby/object:Gem::Version
|
88
85
|
version: '0'
|
89
|
-
segments:
|
90
|
-
- 0
|
91
|
-
hash: 3505150916323372414
|
92
86
|
requirements: []
|
93
87
|
rubyforge_project: jquery-atwho-rails
|
94
88
|
rubygems_version: 1.8.25
|
@@ -98,3 +92,4 @@ summary: 'jquery plugin: @mentions'
|
|
98
92
|
test_files:
|
99
93
|
- spec/generators/install_generator_spec.rb
|
100
94
|
- spec/spec_helper.rb
|
95
|
+
has_rdoc:
|