recordselect 3.10.9 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,657 @@
1
+ //= require jquery.visible.min
2
+
3
+
4
+ (function() {
5
+ var recordselectInit = function($, undefined) {
6
+
7
+ if (typeof(Class) === 'undefined') {
8
+ /* Simple JavaScript Inheritance for ES 5.1
9
+ * based on http://ejohn.org/blog/simple-javascript-inheritance/
10
+ * (inspired by base2 and Prototype)
11
+ * MIT Licensed.
12
+ */
13
+ (function(global) {
14
+ "use strict";
15
+ var fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
16
+
17
+ // The base Class implementation (does nothing)
18
+ function BaseClass(){}
19
+
20
+ // Create a new Class that inherits from this class
21
+ BaseClass.extend = function(props) {
22
+ var _super = this.prototype;
23
+
24
+ // Set up the prototype to inherit from the base class
25
+ // (but without running the init constructor)
26
+ var proto = Object.create(_super);
27
+
28
+ // Copy the properties over onto the new prototype
29
+ for (var name in props) {
30
+ // Check if we're overwriting an existing function
31
+ proto[name] = typeof props[name] === "function" &&
32
+ typeof _super[name] == "function" && fnTest.test(props[name])
33
+ ? (function(name, fn){
34
+ return function() {
35
+ var tmp = this._super;
36
+
37
+ // Add a new ._super() method that is the same method
38
+ // but on the super-class
39
+ this._super = _super[name];
40
+
41
+ // The method only need to be bound temporarily, so we
42
+ // remove it when we're done executing
43
+ var ret = fn.apply(this, arguments);
44
+ this._super = tmp;
45
+
46
+ return ret;
47
+ };
48
+ })(name, props[name])
49
+ : props[name];
50
+ }
51
+
52
+ // The new constructor
53
+ var newClass = typeof proto.init === "function"
54
+ ? proto.hasOwnProperty("init")
55
+ ? proto.init // All construction is actually done in the init method
56
+ : function SubClass(){ _super.init.apply(this, arguments); }
57
+ : function EmptyClass(){};
58
+
59
+ // Populate our constructed prototype object
60
+ newClass.prototype = proto;
61
+
62
+ // Enforce the constructor to be what we expect
63
+ proto.constructor = newClass;
64
+
65
+ // And make this class extendable
66
+ newClass.extend = BaseClass.extend;
67
+
68
+ return newClass;
69
+ };
70
+
71
+ // export
72
+ global.Class = BaseClass;
73
+ })(window);
74
+ }
75
+
76
+ /*
77
+ jQuery delayed observer
78
+ (c) 2007 - Maxime Haineault (max@centdessin.com)
79
+
80
+ Special thanks to Stephen Goguen & Tane Piper.
81
+
82
+ Slight modifications by Elliot Winkler
83
+ */
84
+
85
+ if (typeof(jQuery.fn.delayedObserver) === 'undefined') {
86
+ (function($){
87
+ $.extend($.fn, {
88
+ delayedObserver: function(callback, delay, options){
89
+ return this.each(function(){
90
+ var el = $(this);
91
+ var op = options || {};
92
+ el.data('oldval', el.val())
93
+ .data('delay', delay === 0 ? delay : (delay || 0.5))
94
+ .data('condition', op.condition || function() { return ($(this).data('oldval') == $(this).val()); })
95
+ .data('callback', callback)
96
+ [(op.event||'keyup')](function(){
97
+ if (el.data('condition').apply(el)) { return; }
98
+ else {
99
+ if (el.data('timer')) { clearTimeout(el.data('timer')); }
100
+ el.data('timer', setTimeout(function(){
101
+ var callback = el.data('callback');
102
+ if (callback) callback.apply(el);
103
+ }, el.data('delay') * 1000));
104
+ el.data('oldval', el.val());
105
+ }
106
+ });
107
+ });
108
+ }
109
+ });
110
+ })(jQuery);
111
+ }
112
+
113
+ jQuery(document).ready(function() {
114
+ RecordSelect.document_loaded = true;
115
+ jQuery('[data-rs-type]').each(function() { RecordSelect.from_attributes(jQuery(this)); });
116
+ jQuery(document).on('click', 'div.record-select li.record', function(event) {
117
+ var link = jQuery(this);
118
+ if (link.length) {
119
+ RecordSelect.select_item(link);
120
+ return false;
121
+ }
122
+ return true;
123
+ });
124
+ jQuery(document).on('click', '.record-select-option .remove', function(event) {
125
+ var line = jQuery(this).parent(), value = line.find(':input:hidden').val();
126
+ line.parent().data('recordselect').obj.trigger('recordselect:remove', [value]);
127
+ line.remove();
128
+ return false;
129
+ });
130
+ jQuery(document).on('ajax:beforeSend', '.record-select-container', function(event, xhr) {
131
+ var rs = jQuery(this).data('recordselect'), cur = rs.current_xhr, found = jQuery(this).find('.found');
132
+ jQuery(this).find('.record, .pagination').remove();
133
+ found.html(found.data('searching'));
134
+ rs.current_xhr = xhr;
135
+ console.log(rs.current_xhr);
136
+ if (cur) cur.abort();
137
+ });
138
+ jQuery(document).on('ajax:complete', '.record-select-container', function(event, xhr, status) {
139
+ var rs = jQuery(this).data('recordselect');
140
+ if (status != 'abort' || rs.current_xhr == xhr) {
141
+ if (rs.is_open()) rs.show();
142
+ rs.current_xhr = null;
143
+ }
144
+ });
145
+ jQuery(document).on('click', 'input.recordselect ~ .clear-input-button', function(event) {
146
+ var $clear_button = jQuery(event.target), $input = $clear_button.prevAll('input');
147
+ if (!$input.length) return;
148
+ $input.val('').removeClass('selected');
149
+ $clear_button.removeClass('enabled');
150
+ });
151
+ jQuery(document).on('input recordselect:change', 'input.recordselect', function(event) {
152
+ var $clear_button = jQuery(event.target).nextAll('.clear-input-button').first();
153
+ if (!$clear_button.length) return;
154
+ if (jQuery(event.target).val()) $clear_button.addClass('enabled');
155
+ else $clear_button.removeClass('enabled');
156
+ });
157
+ jQuery(document).on('ajax:beforeSend', 'a.rs-mode', function() {
158
+ $(this).closest('.record-select').find('form input[name="rs_mode"]').val($(this).data('value'));
159
+ });
160
+ });
161
+
162
+ window.RecordSelect = new Object();
163
+ RecordSelect.document_loaded = false;
164
+
165
+ RecordSelect.from_attributes = function(item) {
166
+ var rs_class = RecordSelect[item.data('rs-type')];
167
+ new rs_class(item.data('rs-id'), item.data('rs-url'), item.data('rs-options'));
168
+ }
169
+
170
+ RecordSelect.select_item = function(item) {
171
+ var rs = item.closest('.record-select-handler').data('recordselect');
172
+ if (rs) {
173
+ try {
174
+ var label = item.find('label').first().text().trim(), text = item.text().trim();
175
+ rs.obj.focus();
176
+ rs.onselect(item.attr('id').substr(2), label || text, text, item);
177
+ } catch(e) {
178
+ alert(e);
179
+ }
180
+ }
181
+ }
182
+
183
+ RecordSelect.observe = function(form) {
184
+ if (typeof(form) == 'string') form = '#' + form;
185
+ form = jQuery(form);
186
+ var min_length = 0, rs = form.closest('.record-select-container').data('recordselect');
187
+ if (rs) min_length = rs.min_length;
188
+ var callback = function() {
189
+ if (form.closest('body').length) form.trigger("submit");
190
+ };
191
+ var delay = parseFloat(rs.obj.data('rsDelay'));
192
+ if (isNaN(delay)) delay = 0.35;
193
+ form.find('input.text-input').delayedObserver(callback, delay, {
194
+ condition: function() {
195
+ var item = jQuery(this);
196
+ return item.data('oldval') == item.val() || item.val().length < min_length;
197
+ }
198
+ }).on('paste', function() {
199
+ if (form.closest('body').length) form.trigger("submit");
200
+ });
201
+ }
202
+
203
+ RecordSelect.render_page = function(record_select_id, page) {
204
+ jQuery('#' + record_select_id + ' ol').first().replaceWith(page);
205
+ };
206
+
207
+ RecordSelect.Abstract = Class.extend({
208
+ /**
209
+ * obj - the id or element that will anchor the recordselect to the page
210
+ * url - the url to run the recordselect
211
+ * options - ??? (check concrete classes)
212
+ */
213
+ init: function(obj, url, options) {
214
+ if (typeof(obj) == 'string') obj = '#' + obj;
215
+ this.obj = jQuery(obj);
216
+ this.url = url;
217
+ this.options = options;
218
+ this.container;
219
+ this.min_length = options.min_length || 0;
220
+ if (this.options.onchange && typeof this.options.onchange != 'function') {
221
+ this.options.onchange = eval(this.options.onchange);
222
+ }
223
+ if (this.options.onselect && typeof this.options.onselect != 'function') {
224
+ this.options.onselect = eval(this.options.onselect);
225
+ }
226
+
227
+ if (RecordSelect.document_loaded) {
228
+ this.onload();
229
+ } else {
230
+ var _this = this;
231
+ jQuery(document).ready(function() { _this.onload(); });
232
+ }
233
+ },
234
+
235
+ /**
236
+ * Finish the setup - IE doesn't like doing certain things before the page loads
237
+ * --override--
238
+ */
239
+ onload: function() {},
240
+
241
+ /**
242
+ * the onselect event handler - when someone clicks on a record
243
+ * --override--
244
+ */
245
+ onselect: function(id, value, text, item) {
246
+ alert(id + ': ' + value);
247
+ },
248
+
249
+ /**
250
+ * opens the recordselect
251
+ */
252
+ open: function() {
253
+ if (this.is_open()) return;
254
+ var _this = this;
255
+ jQuery.rails.fire(_this.obj, 'recordselect:before', this);
256
+ _this.create_form();
257
+ _this.container.show();
258
+ var params = _this.obj.data('params'), text = _this.obj.val();
259
+
260
+ var search_params = jQuery.param({search: text});
261
+ params = params ? [params, search_params].join("&") : search_params;
262
+ this.current_xhr = jQuery.ajax({
263
+ url: this.url,
264
+ data: params,
265
+ success: function(data, status, xhr) {
266
+ if (_this.current_xhr != xhr) return;
267
+ if (status != 'abort') _this.current_xhr = null;
268
+ _this.container.html(data);
269
+ if (!_this.container.is(':visible')) _this.close();
270
+ else {
271
+ _this.container.find('.text-input').val(_this.obj.val());
272
+ RecordSelect.observe(_this.container.find('form'));
273
+ _this.container.hide(); // needed to get right document height to position first time
274
+ if (text.length >= _this.min_length) _this.show();
275
+ }
276
+ }
277
+ });
278
+ },
279
+
280
+ /**
281
+ * positions and reveals the recordselect
282
+ */
283
+ show: function() {
284
+ var offset = this.obj.offset(), scroll = jQuery(window).scrollTop(), window_height = jQuery(window).height();
285
+ if (this.fixed) offset.top -= scroll; // get fixed position
286
+ var top = this.obj.outerHeight() + offset.top, document_height = jQuery(document).height();
287
+
288
+ this.container.show();
289
+ var height = this.container.outerHeight();
290
+ this.container.css('left', offset.left);
291
+ this.container.css('top', '');
292
+ this.container.css('bottom', '');
293
+ if (this.above || (this.fixed || this.body_static) && top + height > window_height) {
294
+ this.container.css('bottom', window_height - offset.top);
295
+ } else {
296
+ var below_space = window_height-(top-scroll), above_space = offset.top - scroll, position;
297
+ if (below_space < height) {
298
+ if (above_space >= height) position = 'bottom';
299
+ else position = above_space < below_space ? 'top' : 'bottom';
300
+ } else position = 'top';
301
+ if (position == 'top') this.container.css('top', top);
302
+ else {
303
+ var bottom = document_height - offset.top, body_height = $(document.body).height();
304
+ if (body_height < document_height) bottom -= document_height - body_height;
305
+ this.container.css('bottom', bottom);
306
+ }
307
+ }
308
+
309
+ if (this._use_iframe_mask()) {
310
+ this.container.after('<iframe src="javascript:false;" class="record-select-mask" />');
311
+ var mask = this.container.next('iframe');
312
+ mask.css('left', this.container.css('left'))
313
+ .css('top', this.container.css('top'));
314
+ }
315
+
316
+ if (this._use_iframe_mask()) {
317
+ var dimensions = this.container.children().first();
318
+ mask.css('width', dimensions.css('width'))
319
+ .css('height', dimensions.css('height'));
320
+ }
321
+ },
322
+
323
+ /**
324
+ * closes the recordselect by emptying the container
325
+ */
326
+ close: function() {
327
+ if (this._use_iframe_mask()) {
328
+ this.container.next('iframe').remove();
329
+ }
330
+
331
+ this.container.hide();
332
+ // hopefully by using remove() instead of innerHTML we won't leak memory
333
+ this.container.children().remove();
334
+ },
335
+
336
+ /**
337
+ * returns true/false for whether the recordselect is open
338
+ */
339
+ is_open: function() {
340
+ return jQuery.trim(this.container.html()).length != 0;
341
+ },
342
+
343
+ /**
344
+ * when the user clicks outside the dropdown
345
+ */
346
+ onbodyclick: function(event) {
347
+ if (!this.is_open()) return;
348
+ if (this.container.has(jQuery(event.target)).length > 0) {
349
+ return;
350
+ } else if (!this.obj.is(event.target)) {
351
+ this.close();
352
+ }
353
+ },
354
+
355
+ /**
356
+ * creates and initializes (and returns) the recordselect container
357
+ */
358
+ create_container: function() {
359
+ var e = jQuery("<div />", {'class': "record-select-container record-select-handler"}), rs = this;
360
+ e.css('display', 'none');
361
+ e.data('recordselect', rs);
362
+ jQuery(this.obj).add(this.obj.parents()).each(function() {
363
+ if (jQuery(this).css('position') == 'fixed') {
364
+ rs.fixed = jQuery(this);
365
+ e.css('position', 'fixed');
366
+ return false;
367
+ }
368
+ });
369
+ jQuery(this.obj).each(function() {
370
+ if (jQuery(this).data('rs-above')) {
371
+ rs.above = true;
372
+ return false;
373
+ }
374
+ });
375
+ jQuery(document.body).append(e);
376
+ jQuery(document.body).mousedown(jQuery.proxy(this, "onbodyclick"));
377
+ if (!rs.fixed && e.offsetParent().css('position') == 'static') rs.body_static = true;
378
+ e.get(0).onselect = jQuery.proxy(this, "onselect")
379
+ return e;
380
+ },
381
+
382
+ create_form: function() {
383
+ var div = jQuery('<div>').addClass('record-select').attr('id', this.options.id);
384
+ var form = jQuery('<form>').attr('action', this.url).attr('data-remote', true).attr('method', 'get');
385
+ form.append(jQuery('<input type="text" name="search" class="text-input">'));
386
+ form.append(jQuery('<input type="hidden" name="page" value="1">'));
387
+ form.append(jQuery('<input type="hidden" name="update" value="1">'));
388
+ div.append(form).append(jQuery('<ol>'));
389
+ this.container.html(div);
390
+ RecordSelect.observe(form);
391
+ },
392
+
393
+ onkeyup: function(event) {
394
+ if (!this.is_open()) return;
395
+ this.container.find('.text-input').val(this.obj.val()).trigger(event);
396
+ },
397
+
398
+ onpaste: function(event) {
399
+ if (!this.is_open()) return;
400
+ setTimeout(function () {
401
+ this.container.find('.text-input').val(this.obj.val()).trigger(event);
402
+ }.bind(this), 0);
403
+ },
404
+
405
+ /**
406
+ * all the behavior to respond to a text field as a search box
407
+ */
408
+ _respond_to_text_field: function(text_field) {
409
+ // attach the events to start this party
410
+ text_field.focus(jQuery.proxy(this, 'open'));
411
+
412
+ // the autosearch event - needs to happen slightly late (keyup is later than keypress)
413
+ text_field.keyup(jQuery.proxy(this, 'onkeyup'));
414
+
415
+ // the autosearch event - needs to happen slightly late (keyup is later than keypress)
416
+ text_field.on('paste', jQuery.proxy(this, 'onpaste'));
417
+
418
+ // keyboard navigation, if available
419
+ if (this.onkeydown) {
420
+ text_field.keydown(jQuery.proxy(this, "onkeydown"));
421
+ }
422
+ },
423
+
424
+ _use_iframe_mask: function() {
425
+ return this.container.insertAdjacentHTML ? true : false;
426
+ }
427
+ });
428
+
429
+
430
+
431
+ /**
432
+ * Adds keyboard navigation to RecordSelect objects
433
+ */
434
+ jQuery.extend(RecordSelect.Abstract.prototype, {
435
+ current: null,
436
+
437
+ /**
438
+ * keyboard navigation - where to intercept the keys is up to the concrete class
439
+ */
440
+ onkeydown: function(ev) {
441
+ var elem;
442
+ switch (ev.keyCode) {
443
+ case 38: //Event.KEY_UP
444
+ if (this.current && this.current.closest('html').length) elem = this.current.prev();
445
+ if (!elem) elem = this.container.find('ol li.record').last();
446
+ this.highlight(elem);
447
+ break;
448
+ case 40: //Event.KEY_DOWN
449
+ if (this.current && this.current.closest('html').length) elem = this.current.next();
450
+ if (!elem) elem = this.container.find('ol li.record').first();
451
+ this.highlight(elem);
452
+ break;
453
+ case 13: // Event.KEY_RETURN
454
+ if (this.current) this.current.click();
455
+ break;
456
+ case 39: // Event.KEY_RIGHT
457
+ elem = this.container.find('li.pagination.next');
458
+ if (elem) elem.find('a').click();
459
+ break;
460
+ case 37: // Event.KEY_LEFT
461
+ elem = this.container.find('li.pagination.previous');
462
+ if (elem) elem.find('a').click();
463
+ break;
464
+ case 27: // Event.KEY_ESC
465
+ case 9: // Event.KEY_TAB
466
+ this.close();
467
+ break;
468
+ default:
469
+ return true;
470
+ }
471
+ if (ev.keyCode != 9) { // don't prevent tabbing
472
+ ev.preventDefault(); // so "enter" doesn't submit the form, among other things(?)
473
+ }
474
+ },
475
+
476
+ /**
477
+ * moves the highlight to a new object
478
+ */
479
+ highlight: function(obj) {
480
+ if (this.current) this.current.removeClass('current');
481
+ this.current = jQuery(obj);
482
+ obj.addClass('current');
483
+ }
484
+ });
485
+
486
+ /**
487
+ * Used by link_to_record_select
488
+ * The options hash should contain a onselect: key, with a javascript function as value
489
+ */
490
+ RecordSelect.Dialog = RecordSelect.Abstract.extend({
491
+ onload: function() {
492
+ this.container = this.create_container();
493
+ this.obj.click(jQuery.proxy(this, "toggle"));
494
+ if (this.onkeypress) this.obj.keypress(jQuery.proxy(this, 'onkeypress'));
495
+ },
496
+
497
+ onselect: function(id, value, text, item) {
498
+ if (this.options.onselect(id, value, text, item) != false) this.close();
499
+ },
500
+
501
+ toggle: function(e) {
502
+ e.preventDefault();
503
+ if (this.is_open()) this.close();
504
+ else this.open();
505
+ }
506
+ });
507
+
508
+ /**
509
+ * Used by record_select_field helper
510
+ * The options hash may contain id: and label: keys, designating the current value
511
+ * The options hash may also include an onchange: key, where the value is a javascript function (or eval-able string) for an callback routine
512
+ * and field_name: key, where value will be set as name of the input field.
513
+ */
514
+ RecordSelect.Single = RecordSelect.Abstract.extend({
515
+ onload: function() {
516
+ var rs = this;
517
+ // initialize the container
518
+ this.container = this.create_container();
519
+ this.container.addClass('record-select-autocomplete');
520
+ this.container.submit(function() {
521
+ rs.hidden_input.val('');
522
+ rs.obj.removeClass('selected');
523
+ rs.obj.trigger('recordselect:unset', [rs]);
524
+ });
525
+
526
+ // create the hidden input
527
+ this.obj.after('<input type="hidden" name="" value="" />');
528
+ this.hidden_input = this.obj.next();
529
+
530
+ // transfer the input name from the text input to the hidden input
531
+ this.hidden_input.attr('name', this.obj.attr('name'));
532
+ this.obj.attr('name', this.options.field_name || '');
533
+
534
+ // initialize the values
535
+ if (this.options.label) this.set(this.options.id, this.options.label);
536
+
537
+ this._respond_to_text_field(this.obj);
538
+ if (this.obj.prop('focused')) this.open(); // if it was focused before we could attach observers
539
+ },
540
+
541
+ onselect: function(id, value, text, item) {
542
+ this.set(id, value);
543
+ if (this.options.onchange) this.options.onchange.call(this, id, value, text, item);
544
+ this.obj.trigger("recordselect:change", [id, value, text, item]);
545
+ this.close();
546
+ },
547
+
548
+ /**
549
+ * sets the id/label
550
+ */
551
+ set: function(id, label) {
552
+ // unescaped html missing for label
553
+ this.obj.val(label);
554
+ this.hidden_input.val(id);
555
+ this.obj.addClass('selected');
556
+ }
557
+ });
558
+
559
+ /**
560
+ * Used by record_select_autocomplete helper
561
+ * The options hash may contain label: key, designating the current value
562
+ * The options hash may also include an onchange: key, where the value is a javascript function (or eval-able string) for an callback routine.
563
+ */
564
+ RecordSelect.Autocomplete = RecordSelect.Abstract.extend({
565
+ onload: function() {
566
+ // initialize the container
567
+ this.container = this.create_container();
568
+ this.container.addClass('record-select-autocomplete');
569
+
570
+ // initialize the values
571
+ if (this.options.label) this.set(this.options.label);
572
+
573
+ this._respond_to_text_field(this.obj);
574
+ if (this.obj.prop('focused')) this.open(); // if it was focused before we could attach observers
575
+ },
576
+
577
+ close: function() {
578
+ // if they close the dialog with the text field empty, then delete the id value
579
+ if (this.obj.val() == '') this.set('');
580
+
581
+ RecordSelect.Abstract.prototype.close.call(this);
582
+ },
583
+
584
+ onselect: function(id, value, text, item) {
585
+ this.set(value);
586
+ if (this.options.onchange) this.options.onchange.call(this, id, value, text, item);
587
+ this.obj.trigger("recordselect:change", [id, value, text, item]);
588
+ this.close();
589
+ },
590
+
591
+ /**
592
+ * sets the id/label
593
+ */
594
+ set: function(label) {
595
+ // unescaped html missing for label
596
+ this.obj.val(label);
597
+ }
598
+ });
599
+
600
+ /**
601
+ * Used by record_multi_select_field helper.
602
+ * Options:
603
+ * list - the id (or object) of the <ul> to contain the <li>s of selected entries
604
+ * current - an array of id:/label: keys designating the currently selected entries
605
+ */
606
+ RecordSelect.Multiple = RecordSelect.Abstract.extend({
607
+ onload: function() {
608
+ // initialize the container
609
+ this.container = this.create_container();
610
+ this.container.addClass('record-select-autocomplete');
611
+
612
+ // decide where the <li> entries should be placed
613
+ if (this.options.list) this.list_container = jQuery(this.options.list);
614
+ else this.list_container = this.obj.siblings('ul');
615
+ this.list_container.data('recordselect', this);
616
+
617
+ // take the input name from the text input, and store it for this.add()
618
+ this.input_name = this.obj.attr('name');
619
+ this.obj.attr('name', '');
620
+
621
+ // initialize the list
622
+ for(var i = 0, length = this.options.current.length; i < length; i++) {
623
+ this.add(this.options.current[i].id, this.options.current[i].label);
624
+ }
625
+
626
+ this._respond_to_text_field(this.obj);
627
+ if (this.obj.prop('focused')) this.open(); // if it was focused before we could attach observers
628
+ },
629
+
630
+ onselect: function(id, value, text, item) {
631
+ this.add(id, value);
632
+ this.obj.trigger("recordselect:add", [id, value, text, item]);
633
+ },
634
+
635
+ /**
636
+ * Adds a record to the selected list
637
+ */
638
+ add: function(id, label) {
639
+ // return silently if this value has already been selected
640
+ if (this.list_container.has('input[value=' + id + ']').length > 0) return;
641
+
642
+ var entry = '<li class="record-select-option">'
643
+ + '<a href="#" class="remove">remove</a>'
644
+ + '<input type="hidden" name="' + this.input_name + '" value="' + id + '" />'
645
+ + '<label>' + label + '</label>'
646
+ + '</li>';
647
+ this.list_container.prepend(entry)
648
+ }
649
+ });
650
+ };
651
+
652
+ if (window.jQuery) {
653
+ recordselectInit(jQuery);
654
+ } else if (typeof exports === 'object' && typeof module === 'object') {
655
+ module.exports = recordselectInit;
656
+ }
657
+ })();
@@ -13,18 +13,6 @@ module RecordSelect
13
13
  @pagination = options.include?(:pagination) ? options[:pagination] : true
14
14
  @toggle_search_mode = options[:toggle_search_mode]
15
15
  end
16
-
17
- def self.js_framework=(framework)
18
- @@js_framework = framework
19
- end
20
-
21
- def self.js_framework
22
- @@js_framework ||= if defined? Jquery
23
- :jquery
24
- elsif defined? PrototypeRails
25
- :prototype
26
- end
27
- end
28
16
 
29
17
  def pagination?
30
18
  @pagination
@@ -1,6 +1,6 @@
1
1
  module RecordSelect
2
2
  class Engine < Rails::Engine
3
- initializer 'active_scaffold.action_controller' do
3
+ initializer 'recordselect.action_controller' do
4
4
  ActiveSupport.on_load :action_controller do
5
5
  include RecordSelect
6
6
  end