forked from FeeiCN/grw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.js
executable file
·4319 lines (3139 loc) · 105 KB
/
plugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
// make it safe to use console.log always
(!window.console||!console.log)&&function(){for(var c=function(){},a="assert clear count debug dir dirxml error exception group groupCollapsed groupEnd info log markTimeline profile profileEnd markTimeline table time timeEnd timeStamp trace warn".split(" "),b=a.length,d=window.console={};b--;)d[a[b]]=c}();
// ! Helper: Does an element contian another?
// - $.fn.has does not have the effect
// I thought it would have. Unlike
// $.fn.has my function returns true/false
// - Options:
// - el: The element to be searched
(function($, undefined){
$.fn.doesHave = function(el){
return !!this.has(el).length;
}
})(jQuery);
// ! Helper: Insert html quickly
// - Options:
// - html: html string/jQuery object to insert
(function($, undefined){
$.fn.insert = function(html){
var el = this[0];
if (typeof html == 'string') { el.innerHTML += html; return $(el.children); }
else if (html.jquery) { el.innerHTML += html.html(); return $(el.children); }
else { return this.append(html); }
};
})(jQuery);
// ! Helper: Give elements equal height/width
(function($, undefined){
$.fn.equalHeight = function() {
var $this = $(this);
$this.height(Math.max.apply(Math, $this.map(function(){ return $(this).height(); }).get()));
return $this;
}
$.fn.equalWidth = function() {
var $this = $(this);
$this.width(Math.max.apply(Math, $this.map(function(){ return $(this).width(); }).get()));
return $this;
}
})(jQuery);
// ! Alert Messages
// - Generate alert messages
// - Options:
// - type: string
// One of: 'information' (default),
// 'warning', 'error', 'success', 'note'
// - position: 'top' or 'bottom'
// Special positioning of the alert message
// - noMargin: boolean (false)
// Give the message full width
// - sticky: boolean (false)
// Make messages sticky or not
(function($, window, undefined){
$.fn.alert = function(message, options) {
return $(this).each(function() {
var $el = $(this),
settings = $.extend({}, $.fn.alert.defaults, options, $el.data());
var alertClass = 'alert ' + settings.type;
if(settings.noMargin) {
alertClass += ' no-margin';
}
if(settings.position) {
alertClass += ' ' + settings.position;
}
var $alert = $('<div style="display:none" class="' + alertClass + ' generated">' + message + '</div>');
$alert.prepend($('<span>').addClass('icon'));
if (!settings.sticky) {
$alert.find('.icon').after($('<span>').addClass('close').text('x'))
}
var alertElement = $el.prepend($alert);
$alert.fadeIn();
}); // End of '$el.each(function ...)'
}; // End of '$.fn.alert = ...'
$.fn.alert.defaults = {
type : 'information',
position : '',
noMargin : false,
sticky: false
};
})(jQuery, this);
// ! Validation Options
// - Set validation options
// - Options:
// - options: object
// The options to set
//
// - Note:
// - If submitHandler is set and
// returns false, the original
// submitHandler won't be executed.
(function($, window, undefined){
$.fn.validationOptions = function(options) {
return $(this).each(function() {
// Get validation engine
var $form = $(this),
validator = $form.validate();
// Handle submitHandler
if (options.submitHandler) {
// Store original submitHandler and given submitHandler
var _submitHandler = validator.settings.submitHandler,
submitHandler = options.submitHandler;
// Set submitHandler
validator.settings.submitHandler = function(){
!!submitHandler.apply(this, arguments) && _submitHandler.apply(this, arguments);
}
delete options.submitHandler;
}
// Handle invalidHandler
if (options.invalidHandler) {
$form.on('invalid-form.validate', options.invalidHandler);
}
// Expand settings
$.extend(validator.settings, options);
}); // End of '$el.each(function ...)'
}; // End of '$.fn.setValidationOptions = ...'
})(jQuery, this);
// ! Sidebar Menu
// - This initializes the sidebar menu.
// - Options:
// - accordion: true/false (true)
// Hide open submenus when opening one (accordion effect).
// Note: you can set this option also by giving the menu the class
// 'accordion' or setting the 'data-accordion'-attribute to true.
// The priority is:
// 1. class='accordion'
// 2. data-accordion='true'
// 3. options = { accordion: true }
(function($, window, undefined){
$.fn.initMenu = function(options) {
var $el = $(this);
// Set up defaults/options
var opts = $.extend({}, {
// Defaults:
accordeon: true
}, options, $el.data());
return $el.each(function() {
var $menu = $(this);
// ! Set options
if ($menu.hasClass('accordion')) {
opts.accordion = true;
}
// ! Append arrow to submenu items
$menu.find('li:has(ul)')
.children('a').addClass('with_sub').end()
.children('ul').addClass('sub');
var $subs = $menu.find('.sub');
// ! Set the container's height
if (opts.accordion) {
// ! Max height: heighest .sub opened
// - Find highest .sub
$subs.show();
var height = 0, $sub = $();
$subs.each(function(){
var $this = $(this),
subHeight = $this.height();
// If .sub is higher than cached highest .sub
if (subHeight > height) {
height = subHeight;
$sub = $this;
}
});
// - Get height of menu with heighest sub opened
$subs.hide();
$sub.show();
// $menu.height($menu.height());
$sub.hide();
} else {
// ! Max height: all .subs opened
$subs.show();
$menu.height($menu.height());
$subs.hide();
}
// ! Show submenus with .open
$subs.filter(function(){ return $(this).prev().is('.open'); }).show();
// ! Handle menu item clicks
$menu.find('li a').click($$.utils.noBubbling);
$menu.find('li a').click(function(e) {
var $this = $(this), $submenu = $this.next(),
speed = $$.config.fxSpeed * 2 / 3;
// Use accordeon
if(opts.accordion) {
// If there is a visible submenu
if($submenu.is('.sub:visible')) {
// Slide up
$submenu.prev().removeClass('open');
$subs.filter(':visible').slideUp(speed);
return false;
// If submenu is not shown
} else if($submenu.is('.sub:hidden')) {
// Slide up other submenus
$subs.filter(':visible').slideUp(speed);
$menu.find('.open').removeClass('open');
// Slide up current submenu
$submenu.slideDown(speed);
$submenu.prev().addClass('open');
}
// Do not use accordeon
} else {
// If there is no submenu to show
if(!$submenu.length) {
// Go to link destination
window.location.href = $this.attr('href');
// If there is a submenu
} else {
// Show/hide it
$submenu.slideToggle(speed);
$submenu.prev().toggleClass('open');
}
return false;
} // End of 'if (opts.accordeon)'
}); // End of '$menu.find('li a').click(function ...)'
}); // End of '$el.each(function ...)'
}; // End of '$.fn.initMenu = ...'
})(jQuery, this);
// ! Dynamic Tables
// - Set up datatables
//
// - Options: see defaults
(function($, window, document){
var PLUGIN_NAME = 'table';
$.fn[PLUGIN_NAME] = function(options){
var $el = $(this);
return $(this).each(function(){
var $table = $(this),
opts = $.extend(true, {}, $.fn[PLUGIN_NAME].defaults, options, $table.data());
// ! Get options
if (_.isString($table.data('tableTools'))) {
$table.data('tableTools', $.parseJSON($table.data('tableTools')));
}
// ! Set up table
$table.dataTable($.extend(true, {
sDom: (opts.filterBar != 'none' ? '<"filters"fl>' : '') + 't<"footer"ip>',
sPaginationType: 'full_numbers',
iDisplayLength: opts.maxItemsPerPage,
oLanguage: {
sLengthMenu: '<span class=text>' + opts.lang.SHOW_ENTRIES + '</span> _MENU_',
sSearch: '<span class=text>' + opts.lang.SEARCH + '</span> _INPUT_'
},
aLengthMenu: [[5, 10, 25, 50, -1], [5, 10, 25, 50, 'All']]
}, opts.dataTable)).parent().find('.dataTables_length select').data('width', 'auto');
var $dataTable = $table.parent(),
$filterBar = $dataTable.find('.filters');
['with-prev-next', 'full'].forEach(function(cls){
$table.hasClass(cls) && $dataTable.addClass(cls);
});
$table.removeClass('full');
// ! Toolbar
$dataTable.prev('.tabletools').insertBefore($table);
// - TableTools
if (opts.tableTools.display || $dataTable.find('.tabletools').length) {
if (opts.tableTools.display) {
var tableTools = new TableTools($table.dataTable(), $.extend(true, {
sSwfPath: opts.tableTools.swfUrl,
aButtons: opts.tableTools.buttons
}, opts.tableTools.extras));
}
var $container = $dataTable.find('.tabletools');
// Create toolbar if it doesn't exist
if (!$container.length) {
$container = $('<div class=tabletools><div class=left></div><div class=right></div></div>').insertBefore($table);
}
if (opts.tableTools.display) {
$container.find('.' + opts.tableTools.pos).append(tableTools.dom.container);
}
}
// ! Set up filter bar button
if (opts.filterBar != 'none') {
// Add button
if (opts.filterBar != 'always') {
var $toggleBtn = $('<div class=toggleFilter></div>').insertBefore($dataTable).click(function(){
$filterBar.slideToggle($$.config.fxSpeed * 2 / 3);
$toggleBtn.toggleClass('active');
});
// Show filter bar initially
if (opts.showFilterBar) {
$toggleBtn.addClass('active');
}
}
// Show filter bar initially
if (opts.filterBar == 'always' || opts.showFilterBar) {
$dataTable.find('.filters').show();
}
}
}); // End of '$(this).each(...)'
} // End of '$.fn[PLUGIN_NAME] = ...'
// Defaults:
$.fn[PLUGIN_NAME].defaults = {
filterBar: 'toggle', // One of: 'always', 'toggle, 'none'
showFilterBar: false, // Show or hide the filter bar initially
maxItemsPerPage: 10,
dataTable: {}, // dataTable options
tableTools: {
display: false, // Show tableTools?
buttons: [ 'csv', 'xls', 'pdf'], // Which buttons to show
pos: 'right', // Show on the left or on the right?
swfUrl: 'extras/datatables/copy_csv_xls_pdf.swf', // Where the swf file is located
extras: {} // Other tableTools options
},
lang: {
SHOW_ENTRIES: 'Número de Registros:',
SEARCH: 'Buscar:'
}
};
})(jQuery, this, document);
// ! Tabbed Box
// - Create the box with tabs
// - The content to be shown
// is set in the html:
// The content corresponding
// to 'ul li.current' will
// be shown initially.
(function($, window, document){
$.fn.tabbedBox = function(options){
options = $.extend({}, {
// Defaults:
fxSpeed: $$.config.fxSpeed / 1.2,
header: '.header',
content: '.content'
}, options);
var $return = $(this).each(function(){
// ! Show a content box
var showContent = function($content, anim) {
if ($content.is(':visible')) {
return;
}
var $actions = $('.actions[rel=' + $content[0].id + ']');
if (!anim) {
$container.children(':visible').hide();
$content.show();
$allActions.hide();
$actions.show();
return;
}
// - Hide old actions and show new
$allActions.hide();
$actions.show();
// - Hide old content
$container.children(':visible').fadeOut(options.fxSpeed, function(){
// - Show current content
$content.fadeIn(options.fxSpeed, function(){
// - Fix for jQuery UI Accordion
$content.find('.ui-accordion').accordion('resize');
});
});
} // End of 'showContent = ...'
// ! Prepare everything
var $box = $(this),
$container = _.isString(options.content) ? $box.find(options.content) : $(options.content),
$allActions = $box.find('.actions[rel]'),
$tabs = _.isString(options.header) ? $box.find(options.header).find('ul') : $(options.header),
current = $tabs.find('li.current').find('a').attr('href'); // Parse li.current
if (!$tabs.is('ul')) {
$tabs = $tabs.find('ul');
}
// - If no li.current was found:
if (!current) {
// Open first tab list item
current = $tabs.find('li').first().find('a').attr('href');
}
// - Hide tab contents
$container.children().hide();
// ! Click on tab
$tabs.on('click', 'a', function(e){
var $li = $(this).parent(), href = $li.find('a').attr('href'), lhash = location.hash;
var old_href = $tabs.find('li.current').find('a').attr('href');
// Hash is in URL
if (lhash.split(',').indexOf(old_href) != -1) {
// Replace hash
location.hash = lhash.replace(old_href, href);
// Hash is not in URL
} else {
// Add hash
location.hash += ((lhash.length && ',') || '') + href;
}
return false;
});
// ! Hashchange
$(window).on('hashchange', {anim: true}, function(e, anim){
var anim = anim == undefined && true || anim;
var hash = location.hash,
$content;
// ! Parse hashes: #id1(,#id2)*
// - Find requested content
hash.trim().split(',').forEach(function(h){
var $tmp = $container.find(h);
if ($tmp.length) {
$content = $tmp;
hash = h;
}
});
// ! No hashes given, try open .current, otherwise open first
if ($content == undefined) {
// Open .current
$content = $container.find($tabs.find('li.current').find('a').attr('href'));
}
if ($content == undefined || !$content.length) {
// Open first tab
$content = $container.find($tabs.find('a').first().attr('href'));
}
// If content was found
if ($content.length) {
// Show content and current tab
showContent($content, anim);
$tabs.find('.current').removeClass('current');
$tabs.find('li:has(a[href=#' + $content.attr('id') + '])').addClass('current');
}
}); // End of '$(window).on('hashchange', ...)'
}); // End of '$(this).each(...)'
// Show current tab
$(window).trigger('hashchange', [false]);
return $return;
} // End of '$.fn.tabbedBox = ...'
})(jQuery, this, document);
// ! Wizard
// - Small wizard plugin
// - Options:
// - onSubmit: Function called on form submit.
// Put your submit AJAX there.
(function($, window, document){
var PLUGIN_NAME = 'wizard',
instances = [];
$.fn[PLUGIN_NAME] = function(options){
options = $.extend({}, {
// Defaults:
onSubmit: function() {
// Alert! :)
alert('Wizard completed successfully! :)');
$(this).parent().fadeOut();
return false;
}
}, options);
return $(this).each(function(){
var $this = $(this);
var isForm = $this.is('form');
if (!_.contains(instances, $this[0])) {
instances.push($this[0]);
} else {
return;
}
// ! Set up frequently used elements
var $el = {
box: $this,
content: $this.find('.content'),
list: $this.find('.steps'),
a_list: $this.find('.steps').find('a'),
prev: $this.find('.actions').find('.left').find('a'),
next: $this.find('.actions').find('.right').find('a').not('.finish'),
finish: $this.find('.actions').find('.right').find('a.finish')
};
// ! Change step
var goToIndex = function(newIndex){
// Old step
var $oldStepLink = $el.a_list.filter('.current'),
$oldStep = $($oldStepLink.attr('href'));
// Fetch new step
var $newStepLink = $el.a_list.eq(newIndex),
$newStep = $($newStepLink.attr('href'));
// ! Validate arguments
if (newIndex > length || newIndex < 0) {
return false;
}
// ! Do validation
if (isForm && $this.hasClass('validate')) {
// Do validation before going to new page
var valid = true,
validator = $this.validate();
$oldStep.find(':input:enabled').each(function(){
var fieldIsValid = validator.element($(this));
if (fieldIsValid === undefined) {
fieldIsValid = true;
}
valid &= fieldIsValid;
});
if (!valid) {
// Show error
$oldStepLink.addClass('error');
return false;
}
}
// ! Check for finish
if (newIndex == length) {
// Do finish
if (isForm) {
$this.submit(options.onSubmit).submit();
}
}
// ! Hide old step and mark is as successfull
$oldStepLink.removeClass('current').addClass('success');
$oldStep.hide();
// ! Show current step
$newStepLink.removeClass('error').removeClass('success').addClass('current');
$newStep.show();
// ! If we are at the first step, disable the 'back' button
if (newIndex == 0) {
$el.prev.addClass('disabled');
} else {
$el.prev.removeClass('disabled');
}
// ! If we are at the last step, show 'Finish' instead of 'Next'
if (newIndex == length - 1) {
$el.next.hide();
$el.finish.show().css('display', 'inline-block');
} else if (!$el.next.is(':visible')) {
$el.next.show();
}
// ! Possibly resize form
if (isForm && $$.utils.forms) {
$$.utils.forms.resize();
}
index = newIndex;
},
index = 0,
length = 0;
// ! Get number of steps
length = $el.list.children().length;
// ! Set up steps links
$el.a_list.click(function(e){
e.preventDefault();
goToIndex($(this).parent().index());
});
// ! Set up prev/next/finish-buttons
$el.prev.addClass('disabled'); // Initially disabled
$el.prev.click(function(e){
e.preventDefault();
goToIndex(index - 1);
});
$el.next.click(function(e){
e.preventDefault();
goToIndex(index + 1);
});
$el.finish.click(function(e){
e.preventDefault();
goToIndex(length); // Go to finish
});
}); // End of '$(this).each(...)'
} // End of '$.fn[PLUGIN_NAME] = ...'
})(jQuery, this, document);
// ! Password Meter
// - Show the strength of a password
(function($, window, document){
var PLUGIN_NAME = 'passwordMeter';
$.fn[PLUGIN_NAME] = function(options){
return $(this).each(function(){
var $input = $(this),
keysBlacklist = _.difference(_.values($.ui.keyCode), /* Whitelist: */ [$.ui.keyCode.DELETE, $.ui.keyCode.COMMA, $.ui.keyCode.PERIOD, $.ui.keyCode.SPACE]),
$indicator = $('<div class=passwordmeter></div>').insertAfter($input),
$wrapper = $('<div class="passwordmeter-wrapper"></div>').insertAfter($indicator);
// TODO?: Better coding
$wrapper.append($indicator).append($input);
var needsReposition = true,
// Reposition the indicator
reposition = function(){
$indicator.position({
my: 'right',
at: 'right',
of: $input,
offset: '-10 0'
});
},
reset = function(){
$input.val('');
update();
};
$input.data('reposition', reposition);
$input.data('reset', reset);
$indicator.css('opacity', 0);
// Calculate gradient width
var bg = new Image();
bg.src = $indicator.css('background-image').replace(/"/g,"").replace(/url\(|\)$/ig, "");
bg.onload = function(){ maxBgPositionX = bg.width - $indicator.width() }; // FIX for webkit
var maxBgPositionX = bg.width - $indicator.width();
// Update gradient on user input
var update = function(){
// Calculate strength
var strength = $.pwdStrength($input.val());
// Update backgound image
$indicator.css('background-position', '-' + maxBgPositionX * (strength / 100) + 'px 0');
// Optional validation: check $(...).data('pwStrength')
$input.data('pwStrength', strength);
}
// Set up events
$input.keypress(function(e){
var $input = $(this);
update();
}).keyup(function(e){
// Handle deletion of characters
if (e.which == $.ui.keyCode.DELETE || e.which == 8) {
update();
}
}).focus(function(){
if (needsReposition) {
needsReposition = false;
reposition();
}
$indicator.animate({
opacity: 1
});
});
}); // End of '$(this).each(...)'
} // End of '$.fn[PLUGIN_NAME] = ...'
})(jQuery, this, document);
// ! Search
// - A live search with results box
//
// - Options: see defaults in code below
// - Note: all options (except lang)
// can be set via data-attributes
// (see data-search in html)
// - Note: The priority of the options is:
// 1. data-tags (data-source='...' etc.)
// 2. $(...).search(options)
//
// - Methods:
// Methods can be called via $(...).search('method name', arguments...);
// - abort: Abort the current ajax search request
// - destroy: Revert the input into the original state
//
// - Note:
// Arrow key navigation is supported :)
(function($, _, window, document, undefined) {
var PLUGIN_NAME = 'search', ns = '.mango_' + PLUGIN_NAME;
// Instances will be stored here
var instances = [];
// The publically callable function
$.fn[PLUGIN_NAME] = $.extend(function (method, options) {
var ret = this,
args = arguments;
$(this).each(function(){
var inst,
$el = $(this);
// ! Create instance
if (inst = instances.filter(function(o){return o.el[0] == $el[0];})[0]) {inst = inst.inst}
else { instances.push({ el: $el, inst: inst = self() }); }
// ! Parse arguments
if (typeof method === "object") {
options = method;
method = undefined;
}
// - Default method is 'init'
method = method || 'init';
// Warning if plugin was not initialized
method != 'init' && !inst.initialized
&& $.error('$.fn.' + PLUGIN_NAME + ' was not initialzed. Please call $.fn.' + PLUGIN_NAME + '(options) first.');
// ! Call the requested method
if ($.isFunction(inst.get(method))) {
// - Get options
var opts;
// 'method' was not given, arguments contains all options
if (args[0] == options) {
opts = $.makeArray(args);
// arguments[1,2,3,...] contains the optinos
} else if (args.length > 1) {
opts = Array.prototype.slice.call(args, 1);
// Only options is given
} else {
opts = [options];
}
var fret = inst.get(method).apply($el, opts);
if (!_.isUndefined(fret)) {
ret = fret;
}
// ! Return property value
} else if (inst.get(method)){
var prop = arguments[0], val = arguments[1];
// Dynamical getter & setter
if (!val) {
ret = inst.get(prop);
} else {
inst.set(prop, val);
}
} else {
// Method or property not found
$.error('Method or property ' + method + ' does not exist on jQuery.fn.' + PLUGIN_NAME);
}
});
return ret;
}, {
// Accessable via $.fn.PLUGIN_NAME[name]
// ! Default settings
defaults: {
interval: 700, // ms: Time to wait after user has stopped typing
minLength: 3, // int: The number of chars to enter before start searching
source: 'search.php', // url: Where to get the search results from
maxResults: 5, // int: Number of results to show at max
resultsClass: 'searchResults', // css-class: The class name for the results container