-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy pathjquery.responsiveTabs.js
708 lines (612 loc) · 26.4 KB
/
jquery.responsiveTabs.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
;(function ( $, window, undefined ) {
/** Default settings */
var defaults = {
active: null,
event: 'click',
disabled: [],
collapsible: 'accordion',
startCollapsed: false,
rotate: false,
setHash: false,
animation: 'default',
animationQueue: false,
duration: 500,
fluidHeight: true,
scrollToAccordion: false,
scrollToAccordionOnLoad: true,
scrollToAccordionOffset: 0,
accordionTabElement: '<div></div>',
navigationContainer: '',
click: function(){},
activate: function(){},
deactivate: function(){},
load: function(){},
activateState: function(){},
classes: {
stateDefault: 'r-tabs-state-default',
stateActive: 'r-tabs-state-active',
stateDisabled: 'r-tabs-state-disabled',
stateExcluded: 'r-tabs-state-excluded',
container: 'r-tabs',
ul: 'r-tabs-nav',
tab: 'r-tabs-tab',
anchor: 'r-tabs-anchor',
panel: 'r-tabs-panel',
accordionTitle: 'r-tabs-accordion-title'
}
};
/**
* Responsive Tabs
* @constructor
* @param {object} element - The HTML element the validator should be bound to
* @param {object} options - An option map
*/
function ResponsiveTabs(element, options) {
this.element = element; // Selected DOM element
this.$element = $(element); // Selected jQuery element
this.tabs = []; // Create tabs array
this.state = ''; // Define the plugin state (tabs/accordion)
this.rotateInterval = 0; // Define rotate interval
this.$queue = $({});
// Extend the defaults with the passed options
this.options = $.extend( {}, defaults, options);
this.init();
}
/**
* This function initializes the tab plugin
*/
ResponsiveTabs.prototype.init = function () {
var _this = this;
// Load all the elements
this.tabs = this._loadElements();
this._loadClasses();
this._loadEvents();
// Window resize bind to check state
$(window).on('resize', function(e) {
_this._setState(e);
if(_this.options.fluidHeight !== true) {
_this._equaliseHeights();
}
});
// Hashchange event
$(window).on('hashchange', function(e) {
var tabRef = _this._getTabRefBySelector(window.location.hash);
var oTab = _this._getTab(tabRef);
// Check if a tab is found that matches the hash
if(tabRef >= 0 && !oTab._ignoreHashChange && !oTab.disabled) {
// If so, open the tab and auto close the current one
_this._openTab(e, _this._getTab(tabRef), true);
}
});
// Start rotate event if rotate option is defined
if(this.options.rotate !== false) {
this.startRotation();
}
// Set fluid height
if(this.options.fluidHeight !== true) {
_this._equaliseHeights();
}
// --------------------
// Define plugin events
//
// Activate: this event is called when a tab is selected
this.$element.bind('tabs-click', function(e, oTab) {
_this.options.click.call(this, e, oTab);
});
// Activate: this event is called when a tab is selected
this.$element.bind('tabs-activate', function(e, oTab) {
_this.options.activate.call(this, e, oTab);
});
// Deactivate: this event is called when a tab is closed
this.$element.bind('tabs-deactivate', function(e, oTab) {
_this.options.deactivate.call(this, e, oTab);
});
// Activate State: this event is called when the plugin switches states
this.$element.bind('tabs-activate-state', function(e, state) {
_this.options.activateState.call(this, e, state);
});
// Load: this event is called when the plugin has been loaded
this.$element.bind('tabs-load', function(e) {
var startTab;
_this._setState(e); // Set state
// Check if the panel should be collaped on load
if(_this.options.startCollapsed !== true && !(_this.options.startCollapsed === 'accordion' && _this.state === 'accordion')) {
startTab = _this._getStartTab();
// Open the initial tab
_this._openTab(e, startTab); // Open first tab
// Call the callback function
_this.options.load.call(this, e, startTab); // Call the load callback
}
});
// Trigger loaded event
this.$element.trigger('tabs-load');
};
//
// PRIVATE FUNCTIONS
//
/**
* This function loads the tab elements and stores them in an array
* @returns {Array} Array of tab elements
*/
ResponsiveTabs.prototype._loadElements = function() {
var _this = this;
var $ul = (_this.options.navigationContainer === '') ? this.$element.children('ul:first') : this.$element.find(_this.options.navigationContainer).children('ul:first');
var tabs = [];
var id = 0;
// Add the classes to the basic html elements
this.$element.addClass(_this.options.classes.container); // Tab container
$ul.addClass(_this.options.classes.ul); // List container
// Get tab buttons and store their data in an array
$('li', $ul).each(function() {
var $tab = $(this);
var isExcluded = $tab.hasClass(_this.options.classes.stateExcluded);
var $anchor, $panel, $accordionTab, $accordionAnchor, panelSelector;
// Check if the tab should be excluded
if(!isExcluded) {
$anchor = $('a', $tab);
panelSelector = $anchor.attr('href');
$panel = $(panelSelector);
$accordionTab = $(_this.options.accordionTabElement).insertBefore($panel);
$accordionAnchor = $('<a></a>').attr('href', panelSelector).html($anchor.html()).appendTo($accordionTab);
var oTab = {
_ignoreHashChange: false,
id: id,
disabled: ($.inArray(id, _this.options.disabled) !== -1),
tab: $(this),
anchor: $('a', $tab),
panel: $panel,
selector: panelSelector,
accordionTab: $accordionTab,
accordionAnchor: $accordionAnchor,
active: false
};
// 1up the ID
id++;
// Add to tab array
tabs.push(oTab);
}
});
return tabs;
};
/**
* This function adds classes to the tab elements based on the options
*/
ResponsiveTabs.prototype._loadClasses = function() {
for (var i=0; i<this.tabs.length; i++) {
this.tabs[i].tab.addClass(this.options.classes.stateDefault).addClass(this.options.classes.tab);
this.tabs[i].anchor.addClass(this.options.classes.anchor);
this.tabs[i].panel.addClass(this.options.classes.stateDefault).addClass(this.options.classes.panel);
this.tabs[i].accordionTab.addClass(this.options.classes.accordionTitle);
this.tabs[i].accordionAnchor.addClass(this.options.classes.anchor);
if(this.tabs[i].disabled) {
this.tabs[i].tab.removeClass(this.options.classes.stateDefault).addClass(this.options.classes.stateDisabled);
this.tabs[i].accordionTab.removeClass(this.options.classes.stateDefault).addClass(this.options.classes.stateDisabled);
}
}
};
/**
* This function adds events to the tab elements
*/
ResponsiveTabs.prototype._loadEvents = function() {
var _this = this;
// Define activate event on a tab element
var fActivate = function(e) {
var current = _this._getCurrentTab(); // Fetch current tab
var activatedTab = e.data.tab;
e.preventDefault();
// Trigger click event for whenever a tab is clicked/touched even if the tab is disabled
activatedTab.tab.trigger('tabs-click', activatedTab);
// Make sure this tab isn't disabled
if(!activatedTab.disabled) {
// Check if hash has to be set in the URL location
if(_this.options.setHash) {
// Set the hash using the history api if available to tackle Chromes repaint bug on hash change
if(history.pushState) {
// Fix for missing window.location.origin in IE
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
}
history.pushState(null, null, window.location.origin + window.location.pathname + window.location.search + activatedTab.selector);
} else {
// Otherwise fallback to the hash update for sites that don't support the history api
window.location.hash = activatedTab.selector;
}
}
e.data.tab._ignoreHashChange = true;
// Check if the activated tab isnt the current one or if its collapsible. If not, do nothing
if(current !== activatedTab || _this._isCollapisble()) {
// The activated tab is either another tab of the current one. If it's the current tab it is collapsible
// Either way, the current tab can be closed
_this._closeTab(e, current);
// Check if the activated tab isnt the current one or if it isnt collapsible
if(current !== activatedTab || !_this._isCollapisble()) {
_this._openTab(e, activatedTab, false, true);
}
}
}
};
// Loop tabs
for (var i=0; i<this.tabs.length; i++) {
// Add activate function to the tab and accordion selection element
this.tabs[i].anchor.on(_this.options.event, {tab: _this.tabs[i]}, fActivate);
this.tabs[i].accordionAnchor.on(_this.options.event, {tab: _this.tabs[i]}, fActivate);
}
};
/**
* This function gets the tab that should be opened at start
* @returns {Object} Tab object
*/
ResponsiveTabs.prototype._getStartTab = function() {
var tabRef = this._getTabRefBySelector(window.location.hash);
var startTab;
// Check if the page has a hash set that is linked to a tab
if(tabRef >= 0 && !this._getTab(tabRef).disabled) {
// If so, set the current tab to the linked tab
startTab = this._getTab(tabRef);
} else if(this.options.active > 0 && !this._getTab(this.options.active).disabled) {
startTab = this._getTab(this.options.active);
} else (!window.matchMedia('(max-width: 646px)').matches) {
// If not, just get the first one
startTab = this._getTab(0);
}
return startTab;
};
/**
* This function sets the current state of the plugin
* @param {Event} e - The event that triggers the state change
*/
ResponsiveTabs.prototype._setState = function(e) {
var $ul = $('ul:first', this.$element);
var oldState = this.state;
var startCollapsedIsState = (typeof this.options.startCollapsed === 'string');
var startTab;
// The state is based on the visibility of the tabs list
if($ul.is(':visible')){
// Tab list is visible, so the state is 'tabs'
this.state = 'tabs';
} else {
// Tab list is invisible, so the state is 'accordion'
this.state = 'accordion';
}
// If the new state is different from the old state
if(this.state !== oldState) {
// If so, the state activate trigger must be called
this.$element.trigger('tabs-activate-state', {oldState: oldState, newState: this.state});
// Check if the state switch should open a tab
if(oldState && startCollapsedIsState && this.options.startCollapsed !== this.state && this._getCurrentTab() === undefined) {
// Get initial tab
startTab = this._getStartTab(e);
// Open the initial tab
this._openTab(e, startTab); // Open first tab
}
}
};
/**
* This function opens a tab
* @param {Event} e - The event that triggers the tab opening
* @param {Object} oTab - The tab object that should be opened
* @param {Boolean} closeCurrent - Defines if the current tab should be closed
* @param {Boolean} stopRotation - Defines if the tab rotation loop should be stopped
*/
ResponsiveTabs.prototype._openTab = function(e, oTab, closeCurrent, stopRotation) {
if (oTab === undefined) {
return;
}
var _this = this;
var scrollOffset;
// Check if the current tab has to be closed
if(closeCurrent) {
this._closeTab(e, this._getCurrentTab());
}
// Check if the rotation has to be stopped when activated
if(stopRotation && this.rotateInterval > 0) {
this.stopRotation();
}
// Set this tab to active
oTab.active = true;
// Set active classes to the tab button and accordion tab button
oTab.tab.removeClass(_this.options.classes.stateDefault).addClass(_this.options.classes.stateActive);
oTab.accordionTab.removeClass(_this.options.classes.stateDefault).addClass(_this.options.classes.stateActive);
// Run panel transiton
_this._doTransition(oTab.panel, _this.options.animation, 'open', function() {
var scrollOnLoad = (e.type !== 'tabs-load' || _this.options.scrollToAccordionOnLoad);
// When finished, set active class to the panel
oTab.panel.removeClass(_this.options.classes.stateDefault).addClass(_this.options.classes.stateActive);
// And if enabled and state is accordion, scroll to the accordion tab
if(_this.getState() === 'accordion' && _this.options.scrollToAccordion && (!_this._isInView(oTab.accordionTab) || _this.options.animation !== 'default') && scrollOnLoad) {
// Add offset element's height to scroll position
scrollOffset = oTab.accordionTab.offset().top - _this.options.scrollToAccordionOffset;
// Check if the animation option is enabled, and if the duration isn't 0
if(_this.options.animation !== 'default' && _this.options.duration > 0) {
// If so, set scrollTop with animate and use the 'animation' duration
$('html, body').animate({
scrollTop: scrollOffset
}, _this.options.duration);
} else {
// If not, just set scrollTop
$('html, body').scrollTop(scrollOffset);
}
}
});
this.$element.trigger('tabs-activate', oTab);
};
/**
* This function closes a tab
* @param {Event} e - The event that is triggered when a tab is closed
* @param {Object} oTab - The tab object that should be closed
*/
ResponsiveTabs.prototype._closeTab = function(e, oTab) {
var _this = this;
var doQueueOnState = typeof _this.options.animationQueue === 'string';
var doQueue;
if(oTab !== undefined) {
if(doQueueOnState && _this.getState() === _this.options.animationQueue) {
doQueue = true;
} else if(doQueueOnState) {
doQueue = false;
} else {
doQueue = _this.options.animationQueue;
}
// Deactivate tab
oTab.active = false;
// Set default class to the tab button
oTab.tab.removeClass(_this.options.classes.stateActive).addClass(_this.options.classes.stateDefault);
// Run panel transition
_this._doTransition(oTab.panel, _this.options.animation, 'close', function() {
// Set default class to the accordion tab button and tab panel
oTab.accordionTab.removeClass(_this.options.classes.stateActive).addClass(_this.options.classes.stateDefault);
oTab.panel.removeClass(_this.options.classes.stateActive).addClass(_this.options.classes.stateDefault);
}, !doQueue);
this.$element.trigger('tabs-deactivate', oTab);
}
};
/**
* This function runs an effect on a panel
* @param {Element} panel - The HTML element of the tab panel
* @param {String} method - The transition method reference
* @param {String} state - The state (open/closed) that the panel should transition to
* @param {Function} callback - The callback function that is called after the transition
* @param {Boolean} dequeue - Defines if the event queue should be dequeued after the transition
*/
ResponsiveTabs.prototype._doTransition = function(panel, method, state, callback, dequeue) {
var effect;
var _this = this;
// Get effect based on method
switch(method) {
case 'slide':
effect = (state === 'open') ? 'slideDown' : 'slideUp';
break;
case 'fade':
effect = (state === 'open') ? 'fadeIn' : 'fadeOut';
break;
default:
effect = (state === 'open') ? 'show' : 'hide';
// When default is used, set the duration to 0
_this.options.duration = 0;
break;
}
// Add the transition to a custom queue
this.$queue.queue('responsive-tabs',function(next){
// Run the transition on the panel
panel[effect]({
duration: _this.options.duration,
complete: function() {
// Call the callback function
callback.call(panel, method, state);
// Run the next function in the queue
next();
}
});
});
// When the panel is openend, dequeue everything so the animation starts
if(state === 'open' || dequeue) {
this.$queue.dequeue('responsive-tabs');
}
};
/**
* This function returns the collapsibility of the tab in this state
* @returns {Boolean} The collapsibility of the tab
*/
ResponsiveTabs.prototype._isCollapisble = function() {
return (typeof this.options.collapsible === 'boolean' && this.options.collapsible) || (typeof this.options.collapsible === 'string' && this.options.collapsible === this.getState());
};
/**
* This function returns a tab by numeric reference
* @param {Integer} numRef - Numeric tab reference
* @returns {Object} Tab object
*/
ResponsiveTabs.prototype._getTab = function(numRef) {
return this.tabs[numRef];
};
/**
* This function returns the numeric tab reference based on a hash selector
* @param {String} selector - Hash selector
* @returns {Integer} Numeric tab reference
*/
ResponsiveTabs.prototype._getTabRefBySelector = function(selector) {
// Loop all tabs
for (var i=0; i<this.tabs.length; i++) {
// Check if the hash selector is equal to the tab selector
if(this.tabs[i].selector === selector) {
return i;
}
}
// If none is found return a negative index
return -1;
};
/**
* This function returns the current tab element
* @returns {Object} Current tab element
*/
ResponsiveTabs.prototype._getCurrentTab = function() {
return this._getTab(this._getCurrentTabRef());
};
/**
* This function returns the next tab's numeric reference
* @param {Integer} currentTabRef - Current numeric tab reference
* @returns {Integer} Numeric tab reference
*/
ResponsiveTabs.prototype._getNextTabRef = function(currentTabRef) {
var tabRef = (currentTabRef || this._getCurrentTabRef());
var nextTabRef = (tabRef === this.tabs.length - 1) ? 0 : tabRef + 1;
return (this._getTab(nextTabRef).disabled) ? this._getNextTabRef(nextTabRef) : nextTabRef;
};
/**
* This function returns the previous tab's numeric reference
* @returns {Integer} Numeric tab reference
*/
ResponsiveTabs.prototype._getPreviousTabRef = function() {
return (this._getCurrentTabRef() === 0) ? this.tabs.length - 1 : this._getCurrentTabRef() - 1;
};
/**
* This function returns the current tab's numeric reference
* @returns {Integer} Numeric tab reference
*/
ResponsiveTabs.prototype._getCurrentTabRef = function() {
// Loop all tabs
for (var i=0; i<this.tabs.length; i++) {
// If this tab is active, return it
if(this.tabs[i].active) {
return i;
}
}
// No tabs have been found, return negative index
return -1;
};
/**
* This function gets the tallest tab and applied the height to all tabs
*/
ResponsiveTabs.prototype._equaliseHeights = function() {
var maxHeight = 0;
$.each($.map(this.tabs, function(tab) {
maxHeight = Math.max(maxHeight, tab.panel.css('minHeight', '').height());
return tab.panel;
}), function() {
this.css('minHeight', maxHeight);
});
};
//
// HELPER FUNCTIONS
//
ResponsiveTabs.prototype._isInView = function($element) {
var docViewTop = $(window).scrollTop(),
docViewBottom = docViewTop + $(window).height(),
elemTop = $element.offset().top,
elemBottom = elemTop + $element.height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
};
//
// PUBLIC FUNCTIONS
//
/**
* This function activates a tab
* @param {Integer} tabRef - Numeric tab reference
* @param {Boolean} stopRotation - Defines if the tab rotation should stop after activation
*/
ResponsiveTabs.prototype.activate = function(tabRef, stopRotation) {
var e = jQuery.Event('tabs-activate');
var oTab = this._getTab(tabRef);
if(!oTab.disabled) {
this._openTab(e, oTab, true, stopRotation || true);
}
};
/**
* This function deactivates a tab
* @param {Integer} tabRef - Numeric tab reference
*/
ResponsiveTabs.prototype.deactivate = function(tabRef) {
var e = jQuery.Event('tabs-dectivate');
var oTab = this._getTab(tabRef);
if(!oTab.disabled) {
this._closeTab(e, oTab);
}
};
/**
* This function enables a tab
* @param {Integer} tabRef - Numeric tab reference
*/
ResponsiveTabs.prototype.enable = function(tabRef) {
var oTab = this._getTab(tabRef);
if(oTab){
oTab.disabled = false;
oTab.tab.addClass(this.options.classes.stateDefault).removeClass(this.options.classes.stateDisabled);
oTab.accordionTab.addClass(this.options.classes.stateDefault).removeClass(this.options.classes.stateDisabled);
}
};
/**
* This function disable a tab
* @param {Integer} tabRef - Numeric tab reference
*/
ResponsiveTabs.prototype.disable = function(tabRef) {
var oTab = this._getTab(tabRef);
if(oTab){
oTab.disabled = true;
oTab.tab.removeClass(this.options.classes.stateDefault).addClass(this.options.classes.stateDisabled);
oTab.accordionTab.removeClass(this.options.classes.stateDefault).addClass(this.options.classes.stateDisabled);
}
};
/**
* This function gets the current state of the plugin
* @returns {String} State of the plugin
*/
ResponsiveTabs.prototype.getState = function() {
return this.state;
};
/**
* This function starts the rotation of the tabs
* @param {Integer} speed - The speed of the rotation
*/
ResponsiveTabs.prototype.startRotation = function(speed) {
var _this = this;
// Make sure not all tabs are disabled
if(this.tabs.length > this.options.disabled.length) {
this.rotateInterval = setInterval(function(){
var e = jQuery.Event('rotate');
_this._openTab(e, _this._getTab(_this._getNextTabRef()), true);
}, speed || (($.isNumeric(_this.options.rotate)) ? _this.options.rotate : 4000) );
} else {
throw new Error("Rotation is not possible if all tabs are disabled");
}
};
/**
* This function stops the rotation of the tabs
*/
ResponsiveTabs.prototype.stopRotation = function() {
window.clearInterval(this.rotateInterval);
this.rotateInterval = 0;
};
/**
* This function can be used to get/set options
* @return {any} Option value
*/
ResponsiveTabs.prototype.option = function(key, value) {
if(value) {
this.options[key] = value;
}
return this.options[key];
};
/** jQuery wrapper */
$.fn.responsiveTabs = function ( options ) {
var args = arguments;
var instance;
if (options === undefined || typeof options === 'object') {
return this.each(function () {
if (!$.data(this, 'responsivetabs')) {
$.data(this, 'responsivetabs', new ResponsiveTabs( this, options ));
}
});
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
instance = $.data(this[0], 'responsivetabs');
// Allow instances to be destroyed via the 'destroy' method
if (options === 'destroy') {
// TODO: destroy instance classes, etc
$.data(this, 'responsivetabs', null);
}
if (instance instanceof ResponsiveTabs && typeof instance[options] === 'function') {
return instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) );
} else {
return this;
}
}
};
}(jQuery, window));