anything_slider_rails 0.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,814 @@
1
+ /*
2
+ AnythingSlider v1.7.23
3
+ Original by Chris Coyier: http://css-tricks.com
4
+ Get the latest version: https://github.com/ProLoser/AnythingSlider
5
+
6
+ To use the navigationFormatter function, you must have a function that
7
+ accepts two paramaters, and returns a string of HTML text.
8
+
9
+ index = integer index (1 based);
10
+ panel = jQuery wrapped LI item this tab references
11
+ @return = Must return a string of HTML/Text
12
+
13
+ navigationFormatter: function(index, panel){
14
+ return "Panel #" + index; // This would have each tab with the text 'Panel #X' where X = index
15
+ }
16
+ */
17
+
18
+ (function($) {
19
+
20
+ $.anythingSlider = function(el, options) {
21
+
22
+ var base = this, o;
23
+
24
+ // Wraps the ul in the necessary divs and then gives Access to jQuery element
25
+ base.el = el;
26
+ base.$el = $(el).addClass('anythingBase').wrap('<div class="anythingSlider"><div class="anythingWindow" /></div>');
27
+
28
+ // Add a reverse reference to the DOM object
29
+ base.$el.data("AnythingSlider", base);
30
+
31
+ base.init = function(){
32
+
33
+ // Added "o" to be used in the code instead of "base.options" which doesn't get modifed by the compiler - reduces size by ~1k
34
+ base.options = o = $.extend({}, $.anythingSlider.defaults, options);
35
+
36
+ base.initialized = false;
37
+ if ($.isFunction(o.onBeforeInitialize)) { base.$el.bind('before_initialize', o.onBeforeInitialize); }
38
+ base.$el.trigger('before_initialize', base);
39
+
40
+ // Cache existing DOM elements for later
41
+ // base.$el = original ul
42
+ // for wrap - get parent() then closest in case the ul has "anythingSlider" class
43
+ base.$wrapper = base.$el.parent().closest('div.anythingSlider').addClass('anythingSlider-' + o.theme);
44
+ base.$window = base.$el.closest('div.anythingWindow');
45
+ base.win = window;
46
+ base.$win = $(base.win);
47
+
48
+ base.$controls = $('<div class="anythingControls"></div>').appendTo( (o.appendControlsTo && $(o.appendControlsTo).length) ? $(o.appendControlsTo) : base.$wrapper);
49
+ base.$startStop = $('<a href="#" class="start-stop"></a>');
50
+ if (o.buildStartStop) {
51
+ base.$startStop.appendTo( (o.appendStartStopTo && $(o.appendStartStopTo).length) ? $(o.appendStartStopTo) : base.$controls );
52
+ }
53
+ base.$nav = $('<ul class="thumbNav" />').appendTo( (o.appendNavigationTo && $(o.appendNavigationTo).length) ? $(o.appendNavigationTo) : base.$controls );
54
+
55
+ // Set up a few defaults & get details
56
+ base.flag = false; // event flag to prevent multiple calls (used in control click/focusin)
57
+ base.playing = o.autoPlay; // slideshow state; removed "startStopped" option
58
+ base.slideshow = false; // slideshow flag needed to correctly trigger slideshow events
59
+ base.hovered = false; // actively hovering over the slider
60
+ base.panelSize = []; // will contain dimensions and left position of each panel
61
+ base.currentPage = o.startPanel = parseInt(o.startPanel,10) || 1; // make sure this isn't a string
62
+ o.changeBy = parseInt(o.changeBy,10) || 1;
63
+ base.adj = (o.infiniteSlides) ? 0 : 1; // adjust page limits for infinite or limited modes
64
+ base.width = base.$el.width();
65
+ base.height = base.$el.height();
66
+ base.outerPad = [ base.$wrapper.innerWidth() - base.$wrapper.width(), base.$wrapper.innerHeight() - base.$wrapper.height() ];
67
+ if (o.playRtl) { base.$wrapper.addClass('rtl'); }
68
+
69
+ // Expand slider to fit parent
70
+ if (o.expand) {
71
+ base.$outer = base.$wrapper.parent();
72
+ base.$window.css({ width: '100%', height: '100%' }); // needed for Opera
73
+ base.checkResize();
74
+ }
75
+
76
+ // Build start/stop button
77
+ if (o.buildStartStop) { base.buildAutoPlay(); }
78
+
79
+ // Build forwards/backwards buttons
80
+ if (o.buildArrows) { base.buildNextBackButtons(); }
81
+
82
+ // can't lock autoplay it if it's not enabled
83
+ if (!o.autoPlay) { o.autoPlayLocked = false; }
84
+
85
+ base.updateSlider();
86
+
87
+ base.$lastPage = base.$currentPage;
88
+
89
+ // Get index (run time) of this slider on the page
90
+ base.runTimes = $('div.anythingSlider').index(base.$wrapper) + 1;
91
+ base.regex = new RegExp('panel' + base.runTimes + '-(\\d+)', 'i'); // hash tag regex
92
+ if (base.runTimes === 1) { base.makeActive(); } // make the first slider on the page active
93
+
94
+ // Make sure easing function exists.
95
+ if (!$.isFunction($.easing[o.easing])) { o.easing = "swing"; }
96
+
97
+ // If pauseOnHover then add hover effects
98
+ if (o.pauseOnHover) {
99
+ base.$wrapper.hover(function() {
100
+ if (base.playing) {
101
+ base.$el.trigger('slideshow_paused', base);
102
+ base.clearTimer(true);
103
+ }
104
+ }, function() {
105
+ if (base.playing) {
106
+ base.$el.trigger('slideshow_unpaused', base);
107
+ base.startStop(base.playing, true);
108
+ }
109
+ });
110
+ }
111
+
112
+ // If a hash can not be used to trigger the plugin, then go to start panel
113
+ base.setCurrentPage(base.gotoHash() || o.startPage, false);
114
+
115
+ // Hide/Show navigation & play/stop controls
116
+ base.slideControls(false);
117
+ base.$wrapper.bind('mouseenter mouseleave', function(e){
118
+ base.hovered = (e.type === "mouseenter") ? true : false;
119
+ base.slideControls( base.hovered, false );
120
+ });
121
+
122
+ // Add keyboard navigation
123
+ $(document).keyup(function(e){
124
+ // Stop arrow keys from working when focused on form items
125
+ if (o.enableKeyboard && base.$wrapper.is('.activeSlider') && !e.target.tagName.match('TEXTAREA|INPUT|SELECT')) {
126
+ if (!o.vertical && (e.which === 38 || e.which === 40)) { return; }
127
+ switch (e.which) {
128
+ case 39: case 40: // right & down arrow
129
+ base.goForward();
130
+ break;
131
+ case 37: case 38: // left & up arrow
132
+ base.goBack();
133
+ break;
134
+ }
135
+ }
136
+ });
137
+
138
+ // Fix tabbing through the page, but don't change the view if the link is in view (showMultiple = true)
139
+ base.$items.delegate('a', 'focus.AnythingSlider', function(e){
140
+ var panel = $(this).closest('.panel'),
141
+ indx = base.$items.index(panel) + base.adj; // index can be -1 in nested sliders - issue #208
142
+ base.$items.find('.focusedLink').removeClass('focusedLink');
143
+ $(this).addClass('focusedLink');
144
+ base.$window.scrollLeft(0);
145
+ if ( ( indx !== -1 && (indx >= base.currentPage + o.showMultiple || indx < base.currentPage) ) ) {
146
+ base.gotoPage(indx);
147
+ e.preventDefault();
148
+ }
149
+ });
150
+
151
+ // Binds events
152
+ var triggers = "slideshow_paused slideshow_unpaused slide_init slide_begin slideshow_stop slideshow_start initialized swf_completed".split(" ");
153
+ $.each("onShowPause onShowUnpause onSlideInit onSlideBegin onShowStop onShowStart onInitialized onSWFComplete".split(" "), function(i,f){
154
+ if ($.isFunction(o[f])){
155
+ base.$el.bind(triggers[i], o[f]);
156
+ }
157
+ });
158
+ if ($.isFunction(o.onSlideComplete)){
159
+ // Added setTimeout (zero time) to ensure animation is complete... see this bug report: http://bugs.jquery.com/ticket/7157
160
+ base.$el.bind('slide_complete', function(){
161
+ setTimeout(function(){ o.onSlideComplete(base); }, 0);
162
+ });
163
+ }
164
+ base.initialized = true;
165
+ base.$el.trigger('initialized', base);
166
+
167
+ // trigger the slideshow
168
+ base.startStop(base.playing);
169
+
170
+ };
171
+
172
+ // called during initialization & to update the slider if a panel is added or deleted
173
+ base.updateSlider = function(){
174
+ // needed for updating the slider
175
+ base.$el.children('.cloned').remove();
176
+ base.$nav.empty();
177
+ // set currentPage to 1 in case it was zero - occurs when adding slides after removing them all
178
+ base.currentPage = base.currentPage || 1;
179
+
180
+ base.$items = base.$el.children();
181
+ base.pages = base.$items.length;
182
+ base.dir = (o.vertical) ? 'top' : 'left';
183
+ o.showMultiple = (o.vertical) ? 1 : parseInt(o.showMultiple,10) || 1; // only integers allowed
184
+ o.navigationSize = (o.navigationSize === false) ? 0 : parseInt(o.navigationSize,10) || 0;
185
+
186
+ if (o.showMultiple > 1) {
187
+ if (o.showMultiple > base.pages) { o.showMultiple = base.pages; }
188
+ base.adjustMultiple = (o.infiniteSlides && base.pages > 1) ? 0 : o.showMultiple - 1;
189
+ base.pages = base.$items.length - base.adjustMultiple;
190
+ }
191
+
192
+ // Hide navigation & player if there is only one page
193
+ base.$controls
194
+ .add(base.$nav)
195
+ .add(base.$startStop)
196
+ .add(base.$forward)
197
+ .add(base.$back)[(base.pages <= 1) ? 'hide' : 'show']();
198
+ if (base.pages > 1) {
199
+ // Build/update navigation tabs
200
+ base.buildNavigation();
201
+ }
202
+
203
+ // Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
204
+ // This supports the "infinite" scrolling, also ensures any cloned elements don't duplicate an ID
205
+ // Moved removeAttr before addClass otherwise IE7 ignores the addClass: http://bugs.jquery.com/ticket/9871
206
+ if (o.infiniteSlides && base.pages > 1) {
207
+ base.$el.prepend( base.$items.filter(':last').clone().addClass('cloned') );
208
+ // Add support for multiple sliders shown at the same time
209
+ if (o.showMultiple > 1) {
210
+ base.$el.append( base.$items.filter(':lt(' + o.showMultiple + ')').clone().addClass('cloned multiple') );
211
+ } else {
212
+ base.$el.append( base.$items.filter(':first').clone().addClass('cloned') );
213
+ }
214
+ base.$el.find('.cloned').each(function(){
215
+ // disable all focusable elements in cloned panels to prevent shifting the panels by tabbing
216
+ $(this).find('a,input,textarea,select,button,area').attr('disabled', 'disabled');
217
+ $(this).find('[id]').andSelf().removeAttr('id');
218
+ });
219
+ }
220
+
221
+ // We just added two items, time to re-cache the list, then get the dimensions of each panel
222
+ base.$items = base.$el.children().addClass('panel' + (o.vertical ? ' vertical' : ''));
223
+ base.setDimensions();
224
+
225
+ // Set the dimensions of each panel
226
+ if (o.resizeContents) {
227
+ base.$items.css('width', base.width);
228
+ base.$wrapper
229
+ .css('width', base.getDim(base.currentPage)[0])
230
+ .add(base.$items).css('height', base.height);
231
+ } else {
232
+ base.$win.load(function(){ base.setDimensions(); }); // set dimensions after all images load
233
+ }
234
+
235
+ if (base.currentPage > base.pages) {
236
+ base.currentPage = base.pages;
237
+ }
238
+ base.setCurrentPage(base.currentPage, false);
239
+ base.$nav.find('a').eq(base.currentPage - 1).addClass('cur'); // update current selection
240
+
241
+ };
242
+
243
+ // Creates the numbered navigation links
244
+ base.buildNavigation = function() {
245
+ if (o.buildNavigation && (base.pages > 1)) {
246
+ var t, $a;
247
+ base.$items.filter(':not(.cloned)').each(function(i) {
248
+ var index = i + 1;
249
+ t = ((index === 1) ? 'first' : '') + ((index === base.pages) ? 'last' : '');
250
+ $a = $('<a class="panel' + index + '" href="#"><span></span></a>').wrap('<li class="' + t + '" />');
251
+ base.$nav.append($a.parent()); // use $a.parent() so it will add <li> instead of only the <a> to the <ul>
252
+
253
+ // If a formatter function is present, use it
254
+ if ($.isFunction(o.navigationFormatter)) {
255
+ t = o.navigationFormatter(index, $(this));
256
+ // Add formatting to title attribute if text is hidden
257
+ if ($a.find('span').css('visibility') === 'hidden') { $a.addClass(o.tooltipClass).attr('title', t); }
258
+ } else {
259
+ t = index;
260
+ }
261
+
262
+ $a
263
+ .bind(o.clickControls, function(e) {
264
+ if (!base.flag && o.enableNavigation) {
265
+ // prevent running functions twice (once for click, second time for focusin)
266
+ base.flag = true; setTimeout(function(){ base.flag = false; }, 100);
267
+ base.gotoPage(index);
268
+ if (o.hashTags) { base.setHash(index); }
269
+ }
270
+ e.preventDefault();
271
+ })
272
+ .find('span').html(t);
273
+ });
274
+
275
+ // Add navigation tab scrolling - use !! in case someone sets the size to zero
276
+ if (!!o.navigationSize && o.navigationSize < base.pages) {
277
+ if (!base.$controls.find('.anythingNavWindow').length){
278
+ base.$nav
279
+ .before('<ul><li class="prev"><a href="#"><span>' + o.backText + '</span></a></li></ul>')
280
+ .after('<ul><li class="next"><a href="#"><span>' + o.forwardText + '</span></a></li></ul>')
281
+ .wrap('<div class="anythingNavWindow"></div>');
282
+ }
283
+ // include half of the left position to include extra width from themes like tabs-light and tabs-dark (still not perfect)
284
+ base.navWidths = base.$nav.find('li').map(function(){
285
+ return $(this).innerWidth() + Math.ceil(parseInt($(this).find('span').css('left'),10)/2 || 0);
286
+ }).get();
287
+ base.navLeft = 1;
288
+ // add 5 pixels to make sure the tabs don't wrap to the next line
289
+ base.$nav.width( base.navWidth( 1, base.pages + 1 ) + 5 );
290
+ base.$controls.find('.anythingNavWindow')
291
+ .width( base.navWidth( 1, o.navigationSize + 1 ) ).end()
292
+ .find('.prev,.next').bind(o.clickControls, function(e) {
293
+ if (!base.flag) {
294
+ base.flag = true; setTimeout(function(){ base.flag = false; }, 200);
295
+ base.navWindow( base.navLeft + o.navigationSize * ( $(this).is('.prev') ? -1 : 1 ) );
296
+ }
297
+ e.preventDefault();
298
+ });
299
+ }
300
+
301
+ }
302
+ };
303
+
304
+ base.navWidth = function(x,y){
305
+ var i, s = Math.min(x,y),
306
+ e = Math.max(x,y),
307
+ w = 0;
308
+ for (i = s; i < e; i++) {
309
+ w += base.navWidths[i-1] || 0;
310
+ }
311
+ return w;
312
+ };
313
+
314
+ base.navWindow = function(n){
315
+ if (!!o.navigationSize && o.navigationSize < base.pages && base.navWidths) {
316
+ var p = base.pages - o.navigationSize + 1;
317
+ n = (n <= 1) ? 1 : (n > 1 && n < p) ? n : p;
318
+ if (n !== base.navLeft) {
319
+ base.$controls.find('.anythingNavWindow').animate(
320
+ { scrollLeft: base.navWidth(1, n), width: base.navWidth(n, n + o.navigationSize) },
321
+ { queue: false, duration: o.animationTime });
322
+ base.navLeft = n;
323
+ }
324
+ }
325
+ };
326
+
327
+ // Creates the Forward/Backward buttons
328
+ base.buildNextBackButtons = function() {
329
+ base.$forward = $('<span class="arrow forward"><a href="#"><span>' + o.forwardText + '</span></a></span>');
330
+ base.$back = $('<span class="arrow back"><a href="#"><span>' + o.backText + '</span></a></span>');
331
+
332
+ // Bind to the forward and back buttons
333
+ base.$back.bind(o.clickBackArrow, function(e) {
334
+ // prevent running functions twice (once for click, second time for swipe)
335
+ if (o.enableArrows && !base.flag) {
336
+ base.flag = true; setTimeout(function(){ base.flag = false; }, 100);
337
+ base.goBack();
338
+ }
339
+ e.preventDefault();
340
+ });
341
+ base.$forward.bind(o.clickForwardArrow, function(e) {
342
+ // prevent running functions twice (once for click, second time for swipe)
343
+ if (o.enableArrows && !base.flag) {
344
+ base.flag = true; setTimeout(function(){ base.flag = false; }, 100);
345
+ base.goForward();
346
+ }
347
+ e.preventDefault();
348
+ });
349
+ // using tab to get to arrow links will show they have focus (outline is disabled in css)
350
+ base.$back.add(base.$forward).find('a').bind('focusin focusout',function(){
351
+ $(this).toggleClass('hover');
352
+ });
353
+
354
+ // Append elements to page
355
+ base.$back.appendTo( (o.appendBackTo && $(o.appendBackTo).length) ? $(o.appendBackTo) : base.$wrapper );
356
+ base.$forward.appendTo( (o.appendForwardTo && $(o.appendForwardTo).length) ? $(o.appendForwardTo) : base.$wrapper );
357
+
358
+ base.$arrowWidth = base.$forward.width(); // assuming the left & right arrows are the same width - used for toggle
359
+ };
360
+
361
+ // Creates the Start/Stop button
362
+ base.buildAutoPlay = function(){
363
+ base.$startStop
364
+ .html('<span>' + (base.playing ? o.stopText : o.startText) + '</span>')
365
+ .bind(o.clickSlideshow, function(e) {
366
+ if (o.enableStartStop) {
367
+ base.startStop(!base.playing);
368
+ base.makeActive();
369
+ if (base.playing && !o.autoPlayDelayed) {
370
+ base.goForward(true);
371
+ }
372
+ }
373
+ e.preventDefault();
374
+ })
375
+ // show button has focus while tabbing
376
+ .bind('focusin focusout',function(){
377
+ $(this).toggleClass('hover');
378
+ });
379
+ };
380
+
381
+ // Adjust slider dimensions on parent element resize
382
+ base.checkResize = function(stopTimer){
383
+ clearTimeout(base.resizeTimer);
384
+ base.resizeTimer = setTimeout(function(){
385
+ var w = base.$outer.width() - base.outerPad[0],
386
+ h = (base.$outer[0].tagName === "BODY" ? base.$win.height() : base.$outer.height()) - base.outerPad[1];
387
+ // base.width = width of one panel, so multiply by # of panels; outerPad is padding added for arrows.
388
+ if (base.width * o.showMultiple !== w || base.height !== h) {
389
+ base.setDimensions(); // adjust panel sizes
390
+ // make sure page is lined up (use -1 animation time, so we can differeniate it from when animationTime = 0)
391
+ base.gotoPage(base.currentPage, base.playing, null, -1);
392
+ }
393
+ if (typeof(stopTimer) === 'undefined'){ base.checkResize(); }
394
+ }, 500);
395
+ };
396
+
397
+ // Set panel dimensions to either resize content or adjust panel to content
398
+ base.setDimensions = function(){
399
+ var w, h, c, t, edge = 0,
400
+ fullsize = { width: '100%', height: '100%' },
401
+ // determine panel width
402
+ pw = (o.showMultiple > 1) ? base.width || base.$window.width()/o.showMultiple : base.$window.width(),
403
+ winw = base.$win.width();
404
+ if (o.expand){
405
+ w = base.$outer.width() - base.outerPad[0];
406
+ base.height = h = base.$outer.height() - base.outerPad[1];
407
+ base.$wrapper.add(base.$window).add(base.$items).css({ width: w, height: h });
408
+ base.width = pw = (o.showMultiple > 1) ? w/o.showMultiple : w;
409
+ }
410
+ base.$items.each(function(i){
411
+ t = $(this);
412
+ c = t.children();
413
+ if (o.resizeContents){
414
+ // resize panel
415
+ w = base.width;
416
+ h = base.height;
417
+ t.css({ width: w, height: h });
418
+ if (c.length) {
419
+ if (c[0].tagName === "EMBED") { c.attr(fullsize); } // needed for IE7; also c.length > 1 in IE7
420
+ if (c[0].tagName === "OBJECT") { c.find('embed').attr(fullsize); }
421
+ // resize panel contents, if solitary (wrapped content or solitary image)
422
+ if (c.length === 1){ c.css(fullsize); }
423
+ }
424
+ } else {
425
+ // get panel width & height and save it
426
+ w = t.width() || base.width; // if image hasn't finished loading, width will be zero, so set it to base width instead
427
+ if (c.length === 1 && w >= winw){
428
+ w = (c.width() >= winw) ? pw : c.width(); // get width of solitary child
429
+ c.css('max-width', w); // set max width for all children
430
+ }
431
+ t.css('width', w); // set width of panel
432
+ h = (c.length === 1 ? c.outerHeight(true) : t.height()); // get height after setting width
433
+ if (h <= base.outerPad[1]) { h = base.height; } // if height less than the outside padding, then set it to the preset height
434
+ t.css('height', h);
435
+ }
436
+ base.panelSize[i] = [w,h,edge];
437
+ edge += (o.vertical) ? h : w;
438
+ });
439
+ // Set total width of slider, Note that this is limited to 32766 by Opera - option removed
440
+ base.$el.css((o.vertical ? 'height' : 'width'), edge);
441
+ };
442
+
443
+ // get dimension of multiple panels, as needed
444
+ base.getDim = function(page){
445
+ if (base.pages < 1 || isNaN(page)) { return [ base.width, base.height ]; } // prevent errors when base.panelSize is empty
446
+ page = (o.infiniteSlides && base.pages > 1) ? page : page - 1;
447
+ var i,
448
+ w = base.panelSize[page][0],
449
+ h = base.panelSize[page][1];
450
+ if (o.showMultiple > 1) {
451
+ for (i=1; i < o.showMultiple; i++) {
452
+ w += base.panelSize[(page + i)%o.showMultiple][0];
453
+ h = Math.max(h, base.panelSize[page + i][1]);
454
+ }
455
+ }
456
+ return [w,h];
457
+ };
458
+
459
+ base.goForward = function(autoplay) {
460
+ base.gotoPage(base.currentPage + o.changeBy * (o.playRtl ? -1 : 1), autoplay);
461
+ };
462
+
463
+ base.goBack = function(autoplay) {
464
+ base.gotoPage(base.currentPage + o.changeBy * (o.playRtl ? 1 : -1), autoplay);
465
+ };
466
+
467
+ base.gotoPage = function(page, autoplay, callback, time) {
468
+ if (autoplay !== true) {
469
+ autoplay = false;
470
+ base.startStop(false);
471
+ base.makeActive();
472
+ }
473
+ // check if page is an id or class name
474
+ if (/^[#|.]/.test(page) && $(page).length) {
475
+ page = $(page).closest('.panel').index() + base.adj;
476
+ }
477
+ // rewind effect occurs here when changeBy > 1
478
+ if (o.changeBy !== 1){
479
+ if (page < 0) { page += base.pages; }
480
+ if (page > base.pages) { page -= base.pages; }
481
+ }
482
+ if (base.pages <= 1) { return; } // prevents animation
483
+ base.$lastPage = base.$currentPage;
484
+ if (typeof(page) !== "number") {
485
+ page = o.startPanel;
486
+ base.setCurrentPage(page);
487
+ }
488
+
489
+ // pause YouTube videos before scrolling or prevent change if playing
490
+ if (autoplay && o.isVideoPlaying(base)) { return; }
491
+
492
+ base.exactPage = page;
493
+ if (page > base.pages + 1 - base.adj) { page = (!o.infiniteSlides && !o.stopAtEnd) ? 1 : base.pages; }
494
+ if (page < base.adj ) { page = (!o.infiniteSlides && !o.stopAtEnd) ? base.pages : 1; }
495
+ if (!o.infiniteSlides) { base.exactPage = page; } // exact page used by the fx extension
496
+ base.currentPage = ( page > base.pages ) ? base.pages : ( page < 1 ) ? 1 : base.currentPage;
497
+ base.$currentPage = base.$items.eq(base.currentPage - base.adj);
498
+ base.targetPage = (page === 0) ? base.pages : (page > base.pages) ? 1 : page;
499
+ base.$targetPage = base.$items.eq( base.targetPage - 1 );
500
+ time = time || o.animationTime;
501
+ // don't trigger events when time < 0 - to prevent FX from firing multiple times on page resize
502
+ if (time >= 0) { base.$el.trigger('slide_init', base); }
503
+
504
+ base.slideControls(true, false);
505
+
506
+ // When autoplay isn't passed, we stop the timer
507
+ if (autoplay !== true) { autoplay = false; }
508
+ // Stop the slider when we reach the last page, if the option stopAtEnd is set to true
509
+ if (!autoplay || (o.stopAtEnd && page === base.pages)) { base.startStop(false); }
510
+
511
+ if (time >= 0) { base.$el.trigger('slide_begin', base); }
512
+
513
+ // delay starting slide animation
514
+ setTimeout(function(d){
515
+ // resize slider if content size varies
516
+ if (!o.resizeContents) {
517
+ // animating the wrapper resize before the window prevents flickering in Firefox
518
+ d = base.getDim(page);
519
+ base.$wrapper.filter(':not(:animated)').animate(
520
+ // prevent animating a dimension to zero
521
+ { width: d[0] || base.width, height: d[1] || base.height },
522
+ { queue: false, duration: (time < 0 ? 0 : time), easing: o.easing }
523
+ );
524
+ }
525
+ d = {};
526
+ d[base.dir] = -base.panelSize[(o.infiniteSlides && base.pages > 1) ? page : page - 1][2];
527
+ // Animate Slider
528
+ base.$el.filter(':not(:animated)').animate(
529
+ d, { queue: false, duration: time, easing: o.easing, complete: function(){ base.endAnimation(page, callback, time); } }
530
+ );
531
+ }, parseInt(o.delayBeforeAnimate, 10) || 0);
532
+ };
533
+
534
+ base.endAnimation = function(page, callback, time){
535
+ if (page === 0) {
536
+ base.$el.css( base.dir, -base.panelSize[base.pages][2]);
537
+ page = base.pages;
538
+ } else if (page > base.pages) {
539
+ // reset back to start position
540
+ base.$el.css( base.dir, -base.panelSize[1][2]);
541
+ page = 1;
542
+ }
543
+ base.exactPage = page;
544
+ base.setCurrentPage(page, false);
545
+ // Add active panel class
546
+ base.$items.removeClass('activePage').eq(page - base.adj).addClass('activePage');
547
+
548
+ if (!base.hovered) { base.slideControls(false); }
549
+
550
+ if (time >= 0) { base.$el.trigger('slide_complete', base); }
551
+ // callback from external slide control: $('#slider').anythingSlider(4, function(slider){ })
552
+ if (typeof callback === 'function') { callback(base); }
553
+
554
+ // Continue slideshow after a delay
555
+ if (o.autoPlayLocked && !base.playing) {
556
+ setTimeout(function(){
557
+ base.startStop(true);
558
+ // subtract out slide delay as the slideshow waits that additional time.
559
+ }, o.resumeDelay - (o.autoPlayDelayed ? o.delay : 0));
560
+ }
561
+ };
562
+
563
+ base.setCurrentPage = function(page, move) {
564
+ page = parseInt(page, 10);
565
+ if (base.pages < 1 || page === 0 || isNaN(page)) { return; }
566
+ if (page > base.pages + 1 - base.adj) { page = base.pages - base.adj; }
567
+ if (page < base.adj ) { page = 1; }
568
+
569
+ // Set visual
570
+ if (o.buildNavigation){
571
+ base.$nav
572
+ .find('.cur').removeClass('cur').end()
573
+ .find('a').eq(page - 1).addClass('cur');
574
+ }
575
+
576
+ // hide/show arrows based on infinite scroll mode
577
+ if (!o.infiniteSlides && o.stopAtEnd){
578
+ base.$wrapper
579
+ .find('span.forward')[ page === base.pages ? 'addClass' : 'removeClass']('disabled').end()
580
+ .find('span.back')[ page === 1 ? 'addClass' : 'removeClass']('disabled');
581
+ if (page === base.pages && base.playing) { base.startStop(); }
582
+ }
583
+
584
+ // Only change left if move does not equal false
585
+ if (!move) {
586
+ var d = base.getDim(page);
587
+ base.$wrapper
588
+ .css({ width: d[0], height: d[1] })
589
+ .add(base.$window).scrollLeft(0); // reset in case tabbing changed this scrollLeft - probably overly redundant
590
+ base.$el.css( base.dir, -base.panelSize[(o.infiniteSlides && base.pages > 1) ? page : page - 1][2] );
591
+ }
592
+ // Update local variable
593
+ base.currentPage = page;
594
+ base.$currentPage = base.$items.removeClass('activePage').eq(page - base.adj).addClass('activePage');
595
+
596
+ };
597
+
598
+ base.makeActive = function(){
599
+ // Set current slider as active so keyboard navigation works properly
600
+ if (!base.$wrapper.is('.activeSlider')){
601
+ $('.activeSlider').removeClass('activeSlider');
602
+ base.$wrapper.addClass('activeSlider');
603
+ }
604
+ };
605
+
606
+ // This method tries to find a hash that matches an ID and panel-X
607
+ // If either found, it tries to find a matching item
608
+ // If that is found as well, then it returns the page number
609
+ base.gotoHash = function(){
610
+ var h = base.win.location.hash,
611
+ i = h.indexOf('&'),
612
+ n = h.match(base.regex);
613
+ // test for "/#/" or "/#!/" used by the jquery address plugin - $('#/') breaks jQuery
614
+ if (n === null && !/^#&/.test(h) && !/#!?\//.test(h)) {
615
+ // #quote2&panel1-3&panel3-3
616
+ h = h.substring(0, (i >= 0 ? i : h.length));
617
+ // ensure the element is in the same slider
618
+ n = ($(h).length && $(h).closest('.anythingBase')[0] === base.el) ? $(h).closest('.panel').index() : null;
619
+ } else if (n !== null) {
620
+ // #&panel1-3&panel3-3
621
+ n = (o.hashTags) ? parseInt(n[1],10) : null;
622
+ }
623
+ return n;
624
+ };
625
+
626
+ base.setHash = function(n){
627
+ var s = 'panel' + base.runTimes + '-',
628
+ h = base.win.location.hash;
629
+ if ( typeof h !== 'undefined' ) {
630
+ base.win.location.hash = (h.indexOf(s) > 0) ? h.replace(base.regex, s + n) : h + "&" + s + n;
631
+ }
632
+ };
633
+
634
+ // Slide controls (nav and play/stop button up or down)
635
+ base.slideControls = function(toggle){
636
+ var dir = (toggle) ? 'slideDown' : 'slideUp',
637
+ t1 = (toggle) ? 0 : o.animationTime,
638
+ t2 = (toggle) ? o.animationTime: 0,
639
+ op = (toggle) ? 1 : 0,
640
+ sign = (toggle) ? 0 : 1; // 0 = visible, 1 = hidden
641
+ if (o.toggleControls) {
642
+ base.$controls.stop(true,true).delay(t1)[dir](o.animationTime/2).delay(t2);
643
+ }
644
+ if (o.buildArrows && o.toggleArrows) {
645
+ if (!base.hovered && base.playing) { sign = 1; op = 0; } // don't animate arrows during slideshow
646
+ base.$forward.stop(true,true).delay(t1).animate({ right: sign * base.$arrowWidth, opacity: op }, o.animationTime/2);
647
+ base.$back.stop(true,true).delay(t1).animate({ left: sign * base.$arrowWidth, opacity: op }, o.animationTime/2);
648
+ }
649
+ };
650
+
651
+ base.clearTimer = function(paused){
652
+ // Clear the timer only if it is set
653
+ if (base.timer) {
654
+ base.win.clearInterval(base.timer);
655
+ if (!paused && base.slideshow) {
656
+ base.$el.trigger('slideshow_stop', base);
657
+ base.slideshow = false;
658
+ }
659
+ }
660
+ };
661
+
662
+ // Pass startStop(false) to stop and startStop(true) to play
663
+ base.startStop = function(playing, paused) {
664
+ if (playing !== true) { playing = false; } // Default if not supplied is false
665
+ base.playing = playing;
666
+
667
+ if (playing && !paused) {
668
+ base.$el.trigger('slideshow_start', base);
669
+ base.slideshow = true;
670
+ }
671
+
672
+ // Toggle playing and text
673
+ if (o.buildStartStop) {
674
+ base.$startStop.toggleClass('playing', playing).find('span').html( playing ? o.stopText : o.startText );
675
+ // add button text to title attribute if it is hidden by text-indent
676
+ if (parseInt(base.$startStop.find('span').css('text-indent'),10) < 0) {
677
+ base.$startStop.addClass(o.tooltipClass).attr( 'title', playing ? o.stopText : o.startText );
678
+ }
679
+ }
680
+
681
+ // Pause slideshow while video is playing
682
+ if (playing){
683
+ base.clearTimer(true); // Just in case this was triggered twice in a row
684
+ base.timer = base.win.setInterval(function() {
685
+ // prevent autoplay if video is playing
686
+ if ( !o.isVideoPlaying(base) ) {
687
+ base.goForward(true);
688
+ // stop slideshow if resume if false
689
+ } else if (!o.resumeOnVideoEnd) {
690
+ base.startStop();
691
+ }
692
+ }, o.delay);
693
+ } else {
694
+ base.clearTimer();
695
+ }
696
+ };
697
+
698
+ // Trigger the initialization
699
+ base.init();
700
+ };
701
+
702
+ $.anythingSlider.defaults = {
703
+ // Appearance
704
+ theme : "default", // Theme name, add the css stylesheet manually
705
+ expand : false, // If true, the entire slider will expand to fit the parent element
706
+ resizeContents : true, // If true, solitary images/objects in the panel will expand to fit the viewport
707
+ vertical : false, // If true, all panels will slide vertically; they slide horizontally otherwise
708
+ showMultiple : false, // Set this value to a number and it will show that many slides at once
709
+ easing : "swing", // Anything other than "linear" or "swing" requires the easing plugin or jQuery UI
710
+
711
+ buildArrows : true, // If true, builds the forwards and backwards buttons
712
+ buildNavigation : true, // If true, builds a list of anchor links to link to each panel
713
+ buildStartStop : true, // ** If true, builds the start/stop button
714
+
715
+ /*
716
+ // commented out as this will reduce the size of the minified version
717
+ appendForwardTo : null, // Append forward arrow to a HTML element (jQuery Object, selector or HTMLNode), if not null
718
+ appendBackTo : null, // Append back arrow to a HTML element (jQuery Object, selector or HTMLNode), if not null
719
+ appendControlsTo : null, // Append controls (navigation + start-stop) to a HTML element (jQuery Object, selector or HTMLNode), if not null
720
+ appendNavigationTo : null, // Append navigation buttons to a HTML element (jQuery Object, selector or HTMLNode), if not null
721
+ appendStartStopTo : null, // Append start-stop button to a HTML element (jQuery Object, selector or HTMLNode), if not null
722
+ */
723
+
724
+ toggleArrows : false, // If true, side navigation arrows will slide out on hovering & hide @ other times
725
+ toggleControls : false, // if true, slide in controls (navigation + play/stop button) on hover and slide change, hide @ other times
726
+
727
+ startText : "Start", // Start button text
728
+ stopText : "Stop", // Stop button text
729
+ forwardText : "&raquo;", // Link text used to move the slider forward (hidden by CSS, replaced with arrow image)
730
+ backText : "&laquo;", // Link text used to move the slider back (hidden by CSS, replace with arrow image)
731
+ tooltipClass : "tooltip", // Class added to navigation & start/stop button (text copied to title if it is hidden by a negative text indent)
732
+
733
+ // Function
734
+ enableArrows : true, // if false, arrows will be visible, but not clickable.
735
+ enableNavigation : true, // if false, navigation links will still be visible, but not clickable.
736
+ enableStartStop : true, // if false, the play/stop button will still be visible, but not clickable. Previously "enablePlay"
737
+ enableKeyboard : true, // if false, keyboard arrow keys will not work for this slider.
738
+
739
+ // Navigation
740
+ startPanel : 1, // This sets the initial panel
741
+ changeBy : 1, // Amount to go forward or back when changing panels.
742
+ hashTags : true, // Should links change the hashtag in the URL?
743
+ infiniteSlides : true, // if false, the slider will not wrap & not clone any panels
744
+ navigationFormatter : null, // Details at the top of the file on this use (advanced use)
745
+ navigationSize : false, // Set this to the maximum number of visible navigation tabs; false to disable
746
+
747
+ // Slideshow options
748
+ autoPlay : false, // If true, the slideshow will start running; replaces "startStopped" option
749
+ autoPlayLocked : false, // If true, user changing slides will not stop the slideshow
750
+ autoPlayDelayed : false, // If true, starting a slideshow will delay advancing slides; if false, the slider will immediately advance to the next slide when slideshow starts
751
+ pauseOnHover : true, // If true & the slideshow is active, the slideshow will pause on hover
752
+ stopAtEnd : false, // If true & the slideshow is active, the slideshow will stop on the last page. This also stops the rewind effect when infiniteSlides is false.
753
+ playRtl : false, // If true, the slideshow will move right-to-left
754
+
755
+ // Times
756
+ delay : 3000, // How long between slideshow transitions in AutoPlay mode (in milliseconds)
757
+ resumeDelay : 15000, // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds).
758
+ animationTime : 600, // How long the slideshow transition takes (in milliseconds)
759
+ delayBeforeAnimate : 0, // How long to pause slide animation before going to the desired slide (used if you want your "out" FX to show).
760
+
761
+ /*
762
+ // Callbacks - commented out to reduce size of the minified version - they still work
763
+ onBeforeInitialize : function(e, slider) {}, // Callback before the plugin initializes
764
+ onInitialized : function(e, slider) {}, // Callback when the plugin finished initializing
765
+ onShowStart : function(e, slider) {}, // Callback on slideshow start
766
+ onShowStop : function(e, slider) {}, // Callback after slideshow stops
767
+ onShowPause : function(e, slider) {}, // Callback when slideshow pauses
768
+ onShowUnpause : function(e, slider) {}, // Callback when slideshow unpauses - may not trigger properly if user clicks on any controls
769
+ onSlideInit : function(e, slider) {}, // Callback when slide initiates, before control animation
770
+ onSlideBegin : function(e, slider) {}, // Callback before slide animates
771
+ onSlideComplete : function(slider) {}, // Callback when slide completes - no event variable!
772
+ */
773
+
774
+ // Interactivity
775
+ clickForwardArrow : "click", // Event used to activate forward arrow functionality (e.g. add jQuery mobile's "swiperight")
776
+ clickBackArrow : "click", // Event used to activate back arrow functionality (e.g. add jQuery mobile's "swipeleft")
777
+ clickControls : "click focusin", // Events used to activate navigation control functionality
778
+ clickSlideshow : "click", // Event used to activate slideshow play/stop button
779
+
780
+ // Video
781
+ resumeOnVideoEnd : true, // If true & the slideshow is active & a supported video is playing, it will pause the autoplay until the video is complete
782
+ resumeOnVisible : true, // If true the video will resume playing (if previously paused, except for YouTube iframe - known issue); if false, the video remains paused.
783
+ addWmodeToObject : "opaque", // If your slider has an embedded object, the script will automatically add a wmode parameter with this setting
784
+ isVideoPlaying : function(base){ return false; } // return true if video is playing or false if not - used by video extension
785
+
786
+ };
787
+
788
+ $.fn.anythingSlider = function(options, callback) {
789
+
790
+ return this.each(function(){
791
+ var page, anySlide = $(this).data('AnythingSlider');
792
+
793
+ // initialize the slider but prevent multiple initializations
794
+ if ((typeof(options)).match('object|undefined')){
795
+ if (!anySlide) {
796
+ (new $.anythingSlider(this, options));
797
+ } else {
798
+ anySlide.updateSlider();
799
+ }
800
+ // If options is a number, process as an external link to page #: $(element).anythingSlider(#)
801
+ } else if (/\d/.test(options) && !isNaN(options) && anySlide) {
802
+ page = (typeof(options) === "number") ? options : parseInt($.trim(options),10); // accepts " 2 "
803
+ // ignore out of bound pages
804
+ if ( page >= 1 && page <= anySlide.pages ) {
805
+ anySlide.gotoPage(page, false, callback); // page #, autoplay, one time callback
806
+ }
807
+ // Accept id or class name
808
+ } else if (/^[#|.]/.test(options) && $(options).length) {
809
+ anySlide.gotoPage(options, false, callback);
810
+ }
811
+ });
812
+ };
813
+
814
+ })(jQuery);