diff options
Diffstat (limited to 'nikola/data/themes/default/assets/js')
| -rw-r--r-- | nikola/data/themes/default/assets/js/bootstrap.js | 386 | ||||
| -rwxr-xr-x | nikola/data/themes/default/assets/js/slides.jquery.js | 555 |
2 files changed, 814 insertions, 127 deletions
diff --git a/nikola/data/themes/default/assets/js/bootstrap.js b/nikola/data/themes/default/assets/js/bootstrap.js index 7f303eb..6c15a58 100644 --- a/nikola/data/themes/default/assets/js/bootstrap.js +++ b/nikola/data/themes/default/assets/js/bootstrap.js @@ -1,5 +1,5 @@ /* =================================================== - * bootstrap-transition.js v2.1.0 + * bootstrap-transition.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#transitions * =================================================== * Copyright 2012 Twitter, Inc. @@ -20,13 +20,13 @@ !function ($) { - $(function () { + "use strict"; // jshint ;_; - "use strict"; // jshint ;_; + /* CSS TRANSITION SUPPORT (http://www.modernizr.com/) + * ======================================================= */ - /* CSS TRANSITION SUPPORT (http://www.modernizr.com/) - * ======================================================= */ + $(function () { $.support.transition = (function () { @@ -58,7 +58,7 @@ }) }(window.jQuery);/* ========================================================== - * bootstrap-alert.js v2.1.0 + * bootstrap-alert.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#alerts * ========================================================== * Copyright 2012 Twitter, Inc. @@ -127,6 +127,8 @@ /* ALERT PLUGIN DEFINITION * ======================= */ + var old = $.fn.alert + $.fn.alert = function (option) { return this.each(function () { var $this = $(this) @@ -139,15 +141,22 @@ $.fn.alert.Constructor = Alert + /* ALERT NO CONFLICT + * ================= */ + + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } + + /* ALERT DATA-API * ============== */ - $(function () { - $('body').on('click.alert.data-api', dismiss, Alert.prototype.close) - }) + $(document).on('click.alert.data-api', dismiss, Alert.prototype.close) }(window.jQuery);/* ============================================================ - * bootstrap-button.js v2.1.0 + * bootstrap-button.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#buttons * ============================================================ * Copyright 2012 Twitter, Inc. @@ -199,7 +208,7 @@ } Button.prototype.toggle = function () { - var $parent = this.$element.parent('[data-toggle="buttons-radio"]') + var $parent = this.$element.closest('[data-toggle="buttons-radio"]') $parent && $parent .find('.active') @@ -212,6 +221,8 @@ /* BUTTON PLUGIN DEFINITION * ======================== */ + var old = $.fn.button + $.fn.button = function (option) { return this.each(function () { var $this = $(this) @@ -230,19 +241,26 @@ $.fn.button.Constructor = Button + /* BUTTON NO CONFLICT + * ================== */ + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + /* BUTTON DATA-API * =============== */ - $(function () { - $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) { - var $btn = $(e.target) - if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') - $btn.button('toggle') - }) + $(document).on('click.button.data-api', '[data-toggle^=button]', function (e) { + var $btn = $(e.target) + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') + $btn.button('toggle') }) }(window.jQuery);/* ========================================================== - * bootstrap-carousel.js v2.1.0 + * bootstrap-carousel.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#carousel * ========================================================== * Copyright 2012 Twitter, Inc. @@ -272,7 +290,6 @@ var Carousel = function (element, options) { this.$element = $(element) this.options = options - this.options.slide && this.slide(this.options.slide) this.options.pause == 'hover' && this.$element .on('mouseenter', $.proxy(this.pause, this)) .on('mouseleave', $.proxy(this.cycle, this)) @@ -337,9 +354,7 @@ , direction = type == 'next' ? 'left' : 'right' , fallback = type == 'next' ? 'first' : 'last' , that = this - , e = $.Event('slide', { - relatedTarget: $next[0] - }) + , e this.sliding = true @@ -347,6 +362,10 @@ $next = $next.length ? $next : this.$element.find('.item')[fallback]() + e = $.Event('slide', { + relatedTarget: $next[0] + }) + if ($next.hasClass('active')) return if ($.support.transition && this.$element.hasClass('slide')) { @@ -382,6 +401,8 @@ /* CAROUSEL PLUGIN DEFINITION * ========================== */ + var old = $.fn.carousel + $.fn.carousel = function (option) { return this.each(function () { var $this = $(this) @@ -403,21 +424,27 @@ $.fn.carousel.Constructor = Carousel + /* CAROUSEL NO CONFLICT + * ==================== */ + + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } + /* CAROUSEL DATA-API * ================= */ - $(function () { - $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) { - var $this = $(this), href - , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 - , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data()) - $target.carousel(options) - e.preventDefault() - }) + $(document).on('click.carousel.data-api', '[data-slide]', function (e) { + var $this = $(this), href + , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7 + , options = $.extend({}, $target.data(), $this.data()) + $target.carousel(options) + e.preventDefault() }) }(window.jQuery);/* ============================================================= - * bootstrap-collapse.js v2.1.0 + * bootstrap-collapse.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#collapse * ============================================================= * Copyright 2012 Twitter, Inc. @@ -538,8 +565,10 @@ } - /* COLLAPSIBLE PLUGIN DEFINITION - * ============================== */ + /* COLLAPSE PLUGIN DEFINITION + * ========================== */ + + var old = $.fn.collapse $.fn.collapse = function (option) { return this.each(function () { @@ -558,23 +587,30 @@ $.fn.collapse.Constructor = Collapse - /* COLLAPSIBLE DATA-API + /* COLLAPSE NO CONFLICT * ==================== */ - $(function () { - $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function (e) { - var $this = $(this), href - , target = $this.attr('data-target') - || e.preventDefault() - || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 - , option = $(target).data('collapse') ? 'toggle' : $this.data() - $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed') - $(target).collapse(option) - }) + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } + + + /* COLLAPSE DATA-API + * ================= */ + + $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) { + var $this = $(this), href + , target = $this.attr('data-target') + || e.preventDefault() + || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7 + , option = $(target).data('collapse') ? 'toggle' : $this.data() + $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed') + $(target).collapse(option) }) }(window.jQuery);/* ============================================================ - * bootstrap-dropdown.js v2.1.0 + * bootstrap-dropdown.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#dropdowns * ============================================================ * Copyright 2012 Twitter, Inc. @@ -628,9 +664,10 @@ if (!isActive) { $parent.toggleClass('open') - $this.focus() } + $this.focus() + return false } @@ -657,7 +694,7 @@ if (!isActive || (isActive && e.keyCode == 27)) return $this.click() - $items = $('[role=menu] li:not(.divider) a', $parent) + $items = $('[role=menu] li:not(.divider):visible a', $parent) if (!$items.length) return @@ -675,8 +712,9 @@ } function clearMenus() { - getParent($(toggle)) - .removeClass('open') + $(toggle).each(function () { + getParent($(this)).removeClass('open') + }) } function getParent($this) { @@ -685,7 +723,7 @@ if (!selector) { selector = $this.attr('href') - selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 + selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7 } $parent = $(selector) @@ -698,6 +736,8 @@ /* DROPDOWN PLUGIN DEFINITION * ========================== */ + var old = $.fn.dropdown + $.fn.dropdown = function (option) { return this.each(function () { var $this = $(this) @@ -710,20 +750,27 @@ $.fn.dropdown.Constructor = Dropdown + /* DROPDOWN NO CONFLICT + * ==================== */ + + $.fn.dropdown.noConflict = function () { + $.fn.dropdown = old + return this + } + + /* APPLY TO STANDARD DROPDOWN ELEMENTS * =================================== */ - $(function () { - $('html') - .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus) - $('body') - .on('click.dropdown touchstart.dropdown.data-api', '.dropdown', function (e) { e.stopPropagation() }) - .on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle) - .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) - }) + $(document) + .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus) + .on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() }) + .on('touchstart.dropdown.data-api', '.dropdown-menu', function (e) { e.stopPropagation() }) + .on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle) + .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown) }(window.jQuery);/* ========================================================= - * bootstrap-modal.js v2.1.0 + * bootstrap-modal.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#modals * ========================================================= * Copyright 2012 Twitter, Inc. @@ -773,8 +820,6 @@ if (this.isShown || e.isDefaultPrevented()) return - $('body').addClass('modal-open') - this.isShown = true this.escape() @@ -796,13 +841,12 @@ that.$element .addClass('in') .attr('aria-hidden', false) - .focus() that.enforceFocus() transition ? - that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) : - that.$element.trigger('shown') + that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown') }) : + that.$element.focus().trigger('shown') }) } @@ -820,8 +864,6 @@ this.isShown = false - $('body').removeClass('modal-open') - this.escape() $(document).off('focusin.modal') @@ -891,9 +933,11 @@ this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />') .appendTo(document.body) - if (this.options.backdrop != 'static') { - this.$backdrop.click($.proxy(this.hide, this)) - } + this.$backdrop.click( + this.options.backdrop == 'static' ? + $.proxy(this.$element[0].focus, this.$element[0]) + : $.proxy(this.hide, this) + ) if (doAnimate) this.$backdrop[0].offsetWidth // force reflow @@ -920,6 +964,8 @@ /* MODAL PLUGIN DEFINITION * ======================= */ + var old = $.fn.modal + $.fn.modal = function (option) { return this.each(function () { var $this = $(this) @@ -940,28 +986,36 @@ $.fn.modal.Constructor = Modal + /* MODAL NO CONFLICT + * ================= */ + + $.fn.modal.noConflict = function () { + $.fn.modal = old + return this + } + + /* MODAL DATA-API * ============== */ - $(function () { - $('body').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) { - var $this = $(this) - , href = $this.attr('href') - , $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7 - , option = $target.data('modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) + $(document).on('click.modal.data-api', '[data-toggle="modal"]', function (e) { + var $this = $(this) + , href = $this.attr('href') + , $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7 + , option = $target.data('modal') ? 'toggle' : $.extend({ remote:!/#/.test(href) && href }, $target.data(), $this.data()) - e.preventDefault() + e.preventDefault() - $target - .modal(option) - .one('hide', function () { - $this.focus() - }) - }) + $target + .modal(option) + .one('hide', function () { + $this.focus() + }) }) -}(window.jQuery);/* =========================================================== - * bootstrap-tooltip.js v2.1.0 +}(window.jQuery); +/* =========================================================== + * bootstrap-tooltip.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#tooltips * Inspired by the original jQuery.tipsy by Jason Frame * =========================================================== @@ -1081,9 +1135,9 @@ inside = /in/.test(placement) $tip - .remove() + .detach() .css({ top: 0, left: 0, display: 'block' }) - .appendTo(inside ? this.$element : document.body) + .insertAfter(this.$element) pos = this.getPosition(inside) @@ -1106,7 +1160,7 @@ } $tip - .css(tp) + .offset(tp) .addClass(placement) .addClass('in') } @@ -1128,18 +1182,18 @@ function removeWithAnimation() { var timeout = setTimeout(function () { - $tip.off($.support.transition.end).remove() + $tip.off($.support.transition.end).detach() }, 500) $tip.one($.support.transition.end, function () { clearTimeout(timeout) - $tip.remove() + $tip.detach() }) } $.support.transition && this.$tip.hasClass('fade') ? removeWithAnimation() : - $tip.remove() + $tip.detach() return this } @@ -1197,8 +1251,9 @@ this.enabled = !this.enabled } - , toggle: function () { - this[this.tip().hasClass('in') ? 'hide' : 'show']() + , toggle: function (e) { + var self = $(e.currentTarget)[this.type](this._options).data(this.type) + self[self.tip().hasClass('in') ? 'hide' : 'show']() } , destroy: function () { @@ -1211,6 +1266,8 @@ /* TOOLTIP PLUGIN DEFINITION * ========================= */ + var old = $.fn.tooltip + $.fn.tooltip = function ( option ) { return this.each(function () { var $this = $(this) @@ -1231,12 +1288,20 @@ , trigger: 'hover' , title: '' , delay: 0 - , html: true + , html: false } -}(window.jQuery); -/* =========================================================== - * bootstrap-popover.js v2.1.0 + + /* TOOLTIP NO CONFLICT + * =================== */ + + $.fn.tooltip.noConflict = function () { + $.fn.tooltip = old + return this + } + +}(window.jQuery);/* =========================================================== + * bootstrap-popover.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#popovers * =========================================================== * Copyright 2012 Twitter, Inc. @@ -1281,7 +1346,7 @@ , content = this.getContent() $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title) - $tip.find('.popover-content > *')[this.options.html ? 'html' : 'text'](content) + $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content) $tip.removeClass('fade top bottom left right in') } @@ -1318,6 +1383,8 @@ /* POPOVER PLUGIN DEFINITION * ======================= */ + var old = $.fn.popover + $.fn.popover = function (option) { return this.each(function () { var $this = $(this) @@ -1334,11 +1401,20 @@ placement: 'right' , trigger: 'click' , content: '' - , template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>' + , template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"></div></div></div>' }) + + /* POPOVER NO CONFLICT + * =================== */ + + $.fn.popover.noConflict = function () { + $.fn.popover = old + return this + } + }(window.jQuery);/* ============================================================= - * bootstrap-scrollspy.js v2.1.0 + * bootstrap-scrollspy.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#scrollspy * ============================================================= * Copyright 2012 Twitter, Inc. @@ -1398,7 +1474,7 @@ , $href = /^#\w/.test(href) && $(href) return ( $href && $href.length - && [[ $href.position().top, href ]] ) || null + && [[ $href.position().top + self.$scrollElement.scrollTop(), href ]] ) || null }) .sort(function (a, b) { return a[0] - b[0] }) .each(function () { @@ -1460,6 +1536,8 @@ /* SCROLLSPY PLUGIN DEFINITION * =========================== */ + var old = $.fn.scrollspy + $.fn.scrollspy = function (option) { return this.each(function () { var $this = $(this) @@ -1477,6 +1555,15 @@ } + /* SCROLLSPY NO CONFLICT + * ===================== */ + + $.fn.scrollspy.noConflict = function () { + $.fn.scrollspy = old + return this + } + + /* SCROLLSPY DATA-API * ================== */ @@ -1488,7 +1575,7 @@ }) }(window.jQuery);/* ======================================================== - * bootstrap-tab.js v2.1.0 + * bootstrap-tab.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#tabs * ======================================================== * Copyright 2012 Twitter, Inc. @@ -1538,7 +1625,7 @@ if ( $this.parent('li').hasClass('active') ) return - previous = $ul.find('.active a').last()[0] + previous = $ul.find('.active:last a')[0] e = $.Event('show', { relatedTarget: previous @@ -1599,6 +1686,8 @@ /* TAB PLUGIN DEFINITION * ===================== */ + var old = $.fn.tab + $.fn.tab = function ( option ) { return this.each(function () { var $this = $(this) @@ -1611,18 +1700,25 @@ $.fn.tab.Constructor = Tab + /* TAB NO CONFLICT + * =============== */ + + $.fn.tab.noConflict = function () { + $.fn.tab = old + return this + } + + /* TAB DATA-API * ============ */ - $(function () { - $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) { - e.preventDefault() - $(this).tab('show') - }) + $(document).on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) { + e.preventDefault() + $(this).tab('show') }) }(window.jQuery);/* ============================================================= - * bootstrap-typeahead.js v2.1.0 + * bootstrap-typeahead.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#typeahead * ============================================================= * Copyright 2012 Twitter, Inc. @@ -1656,8 +1752,8 @@ this.sorter = this.options.sorter || this.sorter this.highlighter = this.options.highlighter || this.highlighter this.updater = this.options.updater || this.updater - this.$menu = $(this.options.menu).appendTo('body') this.source = this.options.source + this.$menu = $(this.options.menu) this.shown = false this.listen() } @@ -1679,16 +1775,18 @@ } , show: function () { - var pos = $.extend({}, this.$element.offset(), { + var pos = $.extend({}, this.$element.position(), { height: this.$element[0].offsetHeight }) - this.$menu.css({ - top: pos.top + pos.height - , left: pos.left - }) + this.$menu + .insertAfter(this.$element) + .css({ + top: pos.top + pos.height + , left: pos.left + }) + .show() - this.$menu.show() this.shown = true return this } @@ -1797,7 +1895,7 @@ .on('keypress', $.proxy(this.keypress, this)) .on('keyup', $.proxy(this.keyup, this)) - if ($.browser.webkit || $.browser.msie) { + if (this.eventSupported('keydown')) { this.$element.on('keydown', $.proxy(this.keydown, this)) } @@ -1806,6 +1904,15 @@ .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) } + , eventSupported: function(eventName) { + var isSupported = eventName in this.$element + if (!isSupported) { + this.$element.setAttribute(eventName, 'return;') + isSupported = typeof this.$element[eventName] === 'function' + } + return isSupported + } + , move: function (e) { if (!this.shown) return @@ -1831,7 +1938,7 @@ } , keydown: function (e) { - this.suppressKeyPressRepeat = !~$.inArray(e.keyCode, [40,38,9,13,27]) + this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27]) this.move(e) } @@ -1844,6 +1951,9 @@ switch(e.keyCode) { case 40: // down arrow case 38: // up arrow + case 16: // shift + case 17: // ctrl + case 18: // alt break case 9: // tab @@ -1887,6 +1997,8 @@ /* TYPEAHEAD PLUGIN DEFINITION * =========================== */ + var old = $.fn.typeahead + $.fn.typeahead = function (option) { return this.each(function () { var $this = $(this) @@ -1908,21 +2020,28 @@ $.fn.typeahead.Constructor = Typeahead - /* TYPEAHEAD DATA-API + /* TYPEAHEAD NO CONFLICT + * =================== */ + + $.fn.typeahead.noConflict = function () { + $.fn.typeahead = old + return this + } + + + /* TYPEAHEAD DATA-API * ================== */ - $(function () { - $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { - var $this = $(this) - if ($this.data('typeahead')) return - e.preventDefault() - $this.typeahead($this.data()) - }) + $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { + var $this = $(this) + if ($this.data('typeahead')) return + e.preventDefault() + $this.typeahead($this.data()) }) }(window.jQuery); /* ========================================================== - * bootstrap-affix.js v2.1.0 + * bootstrap-affix.js v2.2.2 * http://twitter.github.com/bootstrap/javascript.html#affix * ========================================================== * Copyright 2012 Twitter, Inc. @@ -1951,7 +2070,9 @@ var Affix = function (element, options) { this.options = $.extend({}, $.fn.affix.defaults, options) - this.$window = $(window).on('scroll.affix.data-api', $.proxy(this.checkPosition, this)) + this.$window = $(window) + .on('scroll.affix.data-api', $.proxy(this.checkPosition, this)) + .on('click.affix.data-api', $.proxy(function () { setTimeout($.proxy(this.checkPosition, this), 1) }, this)) this.$element = $(element) this.checkPosition() } @@ -1989,6 +2110,8 @@ /* AFFIX PLUGIN DEFINITION * ======================= */ + var old = $.fn.affix + $.fn.affix = function (option) { return this.each(function () { var $this = $(this) @@ -2006,6 +2129,15 @@ } + /* AFFIX NO CONFLICT + * ================= */ + + $.fn.affix.noConflict = function () { + $.fn.affix = old + return this + } + + /* AFFIX DATA-API * ============== */ diff --git a/nikola/data/themes/default/assets/js/slides.jquery.js b/nikola/data/themes/default/assets/js/slides.jquery.js new file mode 100755 index 0000000..f2e09c8 --- /dev/null +++ b/nikola/data/themes/default/assets/js/slides.jquery.js @@ -0,0 +1,555 @@ +/* +* Slides, A Slideshow Plugin for jQuery +* Intructions: http://slidesjs.com +* By: Nathan Searles, http://nathansearles.com +* Version: 1.1.9 +* Updated: September 5th, 2011 +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +(function($){ + $.fn.slides = function( option ) { + // override defaults with specified option + option = $.extend( {}, $.fn.slides.option, option ); + + return this.each(function(){ + // wrap slides in control container, make sure slides are block level + $('.' + option.container, $(this)).children().wrapAll('<div class="slides_control"/>'); + + var elem = $(this), + control = $('.slides_control',elem), + total = control.children().size(), + width = control.children().outerWidth(), + height = control.children().outerHeight(), + start = option.start - 1, + effect = option.effect.indexOf(',') < 0 ? option.effect : option.effect.replace(' ', '').split(',')[0], + paginationEffect = option.effect.indexOf(',') < 0 ? effect : option.effect.replace(' ', '').split(',')[1], + next = 0, prev = 0, number = 0, current = 0, loaded, active, clicked, position, direction, imageParent, pauseTimeout, playInterval; + + // is there only one slide? + if (total < 2) { + // Fade in .slides_container + $('.' + option.container, $(this)).fadeIn(option.fadeSpeed, option.fadeEasing, function(){ + // let the script know everything is loaded + loaded = true; + // call the loaded funciton + option.slidesLoaded(); + }); + // Hide the next/previous buttons + $('.' + option.next + ', .' + option.prev).fadeOut(0); + return false; + } + + // animate slides + function animate(direction, effect, clicked) { + if (!active && loaded) { + active = true; + // start of animation + option.animationStart(current + 1); + switch(direction) { + case 'next': + // change current slide to previous + prev = current; + // get next from current + 1 + next = current + 1; + // if last slide, set next to first slide + next = total === next ? 0 : next; + // set position of next slide to right of previous + position = width*2; + // distance to slide based on width of slides + direction = -width*2; + // store new current slide + current = next; + break; + case 'prev': + // change current slide to previous + prev = current; + // get next from current - 1 + next = current - 1; + // if first slide, set next to last slide + next = next === -1 ? total-1 : next; + // set position of next slide to left of previous + position = 0; + // distance to slide based on width of slides + direction = 0; + // store new current slide + current = next; + break; + case 'pagination': + // get next from pagination item clicked, convert to number + next = parseInt(clicked,10); + // get previous from pagination item with class of current + prev = $('.' + option.paginationClass + ' li.'+ option.currentClass +' a', elem).attr('href').match('[^#/]+$'); + // if next is greater then previous set position of next slide to right of previous + if (next > prev) { + position = width*2; + direction = -width*2; + } else { + // if next is less then previous set position of next slide to left of previous + position = 0; + direction = 0; + } + // store new current slide + current = next; + break; + } + + // fade animation + if (effect === 'fade') { + // fade animation with crossfade + if (option.crossfade) { + // put hidden next above current + control.children(':eq('+ next +')', elem).css({ + zIndex: 10 + // fade in next + }).fadeIn(option.fadeSpeed, option.fadeEasing, function(){ + if (option.autoHeight) { + // animate container to height of next + control.animate({ + height: control.children(':eq('+ next +')', elem).outerHeight() + }, option.autoHeightSpeed, function(){ + // hide previous + control.children(':eq('+ prev +')', elem).css({ + display: 'none', + zIndex: 0 + }); + // reset z index + control.children(':eq('+ next +')', elem).css({ + zIndex: 0 + }); + // end of animation + option.animationComplete(next + 1); + active = false; + }); + } else { + // hide previous + control.children(':eq('+ prev +')', elem).css({ + display: 'none', + zIndex: 0 + }); + // reset zindex + control.children(':eq('+ next +')', elem).css({ + zIndex: 0 + }); + // end of animation + option.animationComplete(next + 1); + active = false; + } + }); + } else { + // fade animation with no crossfade + control.children(':eq('+ prev +')', elem).fadeOut(option.fadeSpeed, option.fadeEasing, function(){ + // animate to new height + if (option.autoHeight) { + control.animate({ + // animate container to height of next + height: control.children(':eq('+ next +')', elem).outerHeight() + }, option.autoHeightSpeed, + // fade in next slide + function(){ + control.children(':eq('+ next +')', elem).fadeIn(option.fadeSpeed, option.fadeEasing); + }); + } else { + // if fixed height + control.children(':eq('+ next +')', elem).fadeIn(option.fadeSpeed, option.fadeEasing, function(){ + // fix font rendering in ie, lame + if($.browser.msie) { + $(this).get(0).style.removeAttribute('filter'); + } + }); + } + // end of animation + option.animationComplete(next + 1); + active = false; + }); + } + // slide animation + } else { + // move next slide to right of previous + control.children(':eq('+ next +')').css({ + left: position, + display: 'block' + }); + // animate to new height + if (option.autoHeight) { + control.animate({ + left: direction, + height: control.children(':eq('+ next +')').outerHeight() + },option.slideSpeed, option.slideEasing, function(){ + control.css({ + left: -width + }); + control.children(':eq('+ next +')').css({ + left: width, + zIndex: 5 + }); + // reset previous slide + control.children(':eq('+ prev +')').css({ + left: width, + display: 'none', + zIndex: 0 + }); + // end of animation + option.animationComplete(next + 1); + active = false; + }); + // if fixed height + } else { + // animate control + control.animate({ + left: direction + },option.slideSpeed, option.slideEasing, function(){ + // after animation reset control position + control.css({ + left: -width + }); + // reset and show next + control.children(':eq('+ next +')').css({ + left: width, + zIndex: 5 + }); + // reset previous slide + control.children(':eq('+ prev +')').css({ + left: width, + display: 'none', + zIndex: 0 + }); + // end of animation + option.animationComplete(next + 1); + active = false; + }); + } + } + // set current state for pagination + if (option.pagination) { + // remove current class from all + $('.'+ option.paginationClass +' li.' + option.currentClass, elem).removeClass(option.currentClass); + // add current class to next + $('.' + option.paginationClass + ' li:eq('+ next +')', elem).addClass(option.currentClass); + } + } + } // end animate function + + function stop() { + // clear interval from stored id + clearInterval(elem.data('interval')); + } + + function pause() { + if (option.pause) { + // clear timeout and interval + clearTimeout(elem.data('pause')); + clearInterval(elem.data('interval')); + // pause slide show for option.pause amount + pauseTimeout = setTimeout(function() { + // clear pause timeout + clearTimeout(elem.data('pause')); + // start play interval after pause + playInterval = setInterval( function(){ + animate("next", effect); + },option.play); + // store play interval + elem.data('interval',playInterval); + },option.pause); + // store pause interval + elem.data('pause',pauseTimeout); + } else { + // if no pause, just stop + stop(); + } + } + + // 2 or more slides required + if (total < 2) { + return; + } + + // error corection for start slide + if (start < 0) { + start = 0; + } + + if (start > total) { + start = total - 1; + } + + // change current based on start option number + if (option.start) { + current = start; + } + + // randomizes slide order + if (option.randomize) { + control.randomize(); + } + + // make sure overflow is hidden, width is set + $('.' + option.container, elem).css({ + overflow: 'hidden', + // fix for ie + position: 'relative' + }); + + // set css for slides + control.children().css({ + position: 'absolute', + top: 0, + left: control.children().outerWidth(), + zIndex: 0, + display: 'none' + }); + + // set css for control div + control.css({ + position: 'relative', + // size of control 3 x slide width + width: (width * 3), + // set height to slide height + height: height, + // center control to slide + left: -width + }); + + // show slides + $('.' + option.container, elem).css({ + display: 'block' + }); + + // if autoHeight true, get and set height of first slide + if (option.autoHeight) { + control.children().css({ + height: 'auto' + }); + control.animate({ + height: control.children(':eq('+ start +')').outerHeight() + },option.autoHeightSpeed); + } + + // checks if image is loaded + if (option.preload && control.find('img:eq(' + start + ')').length) { + // adds preload image + $('.' + option.container, elem).css({ + background: 'url(' + option.preloadImage + ') no-repeat 50% 50%' + }); + + // gets image src, with cache buster + var img = control.find('img:eq(' + start + ')').attr('src') + '?' + (new Date()).getTime(); + + // check if the image has a parent + if ($('img', elem).parent().attr('class') != 'slides_control') { + // If image has parent, get tag name + imageParent = control.children(':eq(0)')[0].tagName.toLowerCase(); + } else { + // Image doesn't have parent, use image tag name + imageParent = control.find('img:eq(' + start + ')'); + } + + // checks if image is loaded + control.find('img:eq(' + start + ')').attr('src', img).load(function() { + // once image is fully loaded, fade in + control.find(imageParent + ':eq(' + start + ')').fadeIn(option.fadeSpeed, option.fadeEasing, function(){ + $(this).css({ + zIndex: 5 + }); + // removes preload image + $('.' + option.container, elem).css({ + background: '' + }); + // let the script know everything is loaded + loaded = true; + // call the loaded funciton + option.slidesLoaded(); + }); + }); + } else { + // if no preloader fade in start slide + control.children(':eq(' + start + ')').fadeIn(option.fadeSpeed, option.fadeEasing, function(){ + // let the script know everything is loaded + loaded = true; + // call the loaded funciton + option.slidesLoaded(); + }); + } + + // click slide for next + if (option.bigTarget) { + // set cursor to pointer + control.children().css({ + cursor: 'pointer' + }); + // click handler + control.children().click(function(){ + // animate to next on slide click + animate('next', effect); + return false; + }); + } + + // pause on mouseover + if (option.hoverPause && option.play) { + control.bind('mouseover',function(){ + // on mouse over stop + stop(); + }); + control.bind('mouseleave',function(){ + // on mouse leave start pause timeout + pause(); + }); + } + + // generate next/prev buttons + if (option.generateNextPrev) { + $('.' + option.container, elem).after('<a href="#" class="'+ option.prev +'">Prev</a>'); + $('.' + option.prev, elem).after('<a href="#" class="'+ option.next +'">Next</a>'); + } + + // next button + $('.' + option.next ,elem).click(function(e){ + e.preventDefault(); + if (option.play) { + pause(); + } + animate('next', effect); + }); + + // previous button + $('.' + option.prev, elem).click(function(e){ + e.preventDefault(); + if (option.play) { + pause(); + } + animate('prev', effect); + }); + + // generate pagination + if (option.generatePagination) { + // create unordered list + if (option.prependPagination) { + elem.prepend('<ul class='+ option.paginationClass +'></ul>'); + } else { + elem.append('<ul class='+ option.paginationClass +'></ul>'); + } + // for each slide create a list item and link + control.children().each(function(){ + $('.' + option.paginationClass, elem).append('<li><a href="#'+ number +'">'+ (number+1) +'</a></li>'); + number++; + }); + } else { + // if pagination exists, add href w/ value of item number to links + $('.' + option.paginationClass + ' li a', elem).each(function(){ + $(this).attr('href', '#' + number); + number++; + }); + } + + // add current class to start slide pagination + $('.' + option.paginationClass + ' li:eq('+ start +')', elem).addClass(option.currentClass); + + // click handling + $('.' + option.paginationClass + ' li a', elem ).click(function(){ + // pause slideshow + if (option.play) { + pause(); + } + // get clicked, pass to animate function + clicked = $(this).attr('href').match('[^#/]+$'); + // if current slide equals clicked, don't do anything + if (current != clicked) { + animate('pagination', paginationEffect, clicked); + } + return false; + }); + + // click handling + $('a.link', elem).click(function(){ + // pause slideshow + if (option.play) { + pause(); + } + // get clicked, pass to animate function + clicked = $(this).attr('href').match('[^#/]+$') - 1; + // if current slide equals clicked, don't do anything + if (current != clicked) { + animate('pagination', paginationEffect, clicked); + } + return false; + }); + + if (option.play) { + // set interval + playInterval = setInterval(function() { + animate('next', effect); + }, option.play); + // store interval id + elem.data('interval',playInterval); + } + }); + }; + + // default options + $.fn.slides.option = { + preload: false, // boolean, Set true to preload images in an image based slideshow + preloadImage: '/img/loading.gif', // string, Name and location of loading image for preloader. Default is "/img/loading.gif" + container: 'slides_container', // string, Class name for slides container. Default is "slides_container" + generateNextPrev: false, // boolean, Auto generate next/prev buttons + next: 'next', // string, Class name for next button + prev: 'prev', // string, Class name for previous button + pagination: true, // boolean, If you're not using pagination you can set to false, but don't have to + generatePagination: true, // boolean, Auto generate pagination + prependPagination: false, // boolean, prepend pagination + paginationClass: 'pagination', // string, Class name for pagination + currentClass: 'current', // string, Class name for current class + fadeSpeed: 350, // number, Set the speed of the fading animation in milliseconds + fadeEasing: '', // string, must load jQuery's easing plugin before http://gsgd.co.uk/sandbox/jquery/easing/ + slideSpeed: 350, // number, Set the speed of the sliding animation in milliseconds + slideEasing: '', // string, must load jQuery's easing plugin before http://gsgd.co.uk/sandbox/jquery/easing/ + start: 1, // number, Set the speed of the sliding animation in milliseconds + effect: 'slide', // string, '[next/prev], [pagination]', e.g. 'slide, fade' or simply 'fade' for both + crossfade: false, // boolean, Crossfade images in a image based slideshow + randomize: false, // boolean, Set to true to randomize slides + play: 0, // number, Autoplay slideshow, a positive number will set to true and be the time between slide animation in milliseconds + pause: 0, // number, Pause slideshow on click of next/prev or pagination. A positive number will set to true and be the time of pause in milliseconds + hoverPause: false, // boolean, Set to true and hovering over slideshow will pause it + autoHeight: false, // boolean, Set to true to auto adjust height + autoHeightSpeed: 350, // number, Set auto height animation time in milliseconds + bigTarget: false, // boolean, Set to true and the whole slide will link to next slide on click + animationStart: function(){}, // Function called at the start of animation + animationComplete: function(){}, // Function called at the completion of animation + slidesLoaded: function() {} // Function is called when slides is fully loaded + }; + + // Randomize slide order on load + $.fn.randomize = function(callback) { + function randomizeOrder() { return(Math.round(Math.random())-0.5); } + return($(this).each(function() { + var $this = $(this); + var $children = $this.children(); + var childCount = $children.length; + if (childCount > 1) { + $children.hide(); + var indices = []; + for (i=0;i<childCount;i++) { indices[indices.length] = i; } + indices = indices.sort(randomizeOrder); + $.each(indices,function(j,k) { + var $child = $children.eq(k); + var $clone = $child.clone(true); + $clone.show().appendTo($this); + if (callback !== undefined) { + callback($child, $clone); + } + $child.remove(); + }); + } + })); + }; +})(jQuery);
\ No newline at end of file |
