diff --git a/.gitignore b/.gitignore index ffc79a9b..5e9ee2c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.jscsrc .DS_Store /node_modules jquery.bxslider.zip \ No newline at end of file diff --git a/Gulpfile.js b/Gulpfile.js index bbff9157..4525d6b6 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -1,43 +1,82 @@ -var gulp = require( 'gulp' ) - , uglify = require( 'gulp-uglify' ) - , umd = require( 'gulp-wrap-umd' ) - , rename = require( 'gulp-rename' ) - , less = require( 'gulp-less' ) - , path = require( 'path' ) - , lessCleanCSS = require( 'less-plugin-clean-css' ) - , jshint = require( 'gulp-jshint' ) - , livereload = require( 'gulp-livereload' ) - , gutil = require('gulp-util'); - -var cleancss = new lessCleanCSS( {advanced: true} ); - -gulp.task( 'copyAssets', function() { - - gulp.src( 'src/images/*' ) - .pipe( gulp.dest( 'dist/images' ) ) -}) - -gulp.task( 'buildJS', function() { - - gulp.src( 'src/jquery.bxslider.js') - .pipe( jshint() ) - .pipe( jshint.reporter('jshint-stylish') ) - .pipe( uglify().on('error', gutil.log) ) - .pipe( rename( 'jquery.bxslider.min.js' ) ) - .pipe( gulp.dest( 'dist' ) ); +// ## Globals +/*global $:true*/ +var $ = require('gulp-load-plugins')(); +var gulp = require('gulp'); + +// ### Styles +// `gulp styles` - compiles and optimizes css. +gulp.task('styles', function() { + return gulp.src('./src/less/*.less') + .pipe($.less()) + .pipe($.pleeease({ + autoprefixer: { + browsers: [ + 'last 2 versions', 'ie 8', 'ie 9', 'android 2.3', 'android 4', + 'opera 12' + ] + }, + minifier: false + })) + .pipe(gulp.dest('./dist/')); +}); + +// ### Scripts +// `gulp scripts` - runs jshint and uglify +gulp.task('scripts', ['jshint'], function() { + return gulp.src('./src/js/*.js') + .pipe(gulp.dest('./dist/')) + .pipe($.uglify({ + preserveComments: function (node, comment) { + if (/^\*\*/.test(comment.value) && /\*\*$/.test(comment.value)) { + + console.log('Found tri-star comment. Preserving.'); + return true; + } + } + })) + .pipe($.rename({extname: '.min.js'})) + .pipe(gulp.dest('./dist/')); }); -gulp.task( 'buildCSS', function () { +// ### Vendor Scripts +// `gulp vendor` - runs uglify on 3rd party plugins +gulp.task('vendor', function() { + return gulp.src('./src/vendor/*.js') + .pipe(gulp.dest('./dist/vendor')); +}); + +// ### Images +// `gulp images` - run lossless compression on all the images. +gulp.task('images', function() { + return gulp.src('./src/images/*') + .pipe($.imagemin({ + progressive: true, + interlaced: true + })) + .pipe(gulp.dest('./dist/images')); +}); - gulp.src( 'src/less/*.less') - .pipe( less() ) - .pipe( gulp.dest('dist') ); +// ### JsHint +// `gulp jshint` - lints configuration JSON and project javascript +gulp.task('jshint', function() { + return gulp.src([ 'bower.json', 'gulpfile.js', './src/*.js' ]) + .pipe($.jshint()) + .pipe($.jshint.reporter('jshint-stylish')) + .pipe($.jshint.reporter('fail')); }); -gulp.task( 'default', function() { +// ### Clean +// `gulp clean` - deletes the build folder entirely +gulp.task('clean', require('del').bind(null, ['dist/'])); + +// ### Build +// `gulp build` - Run all the build tasks but don't clean up beforehand. +// Generally you should be running `gulp` instead of `gulp build`. +gulp.task('build', ['styles', 'scripts', 'images', 'vendor']); - livereload.listen() - gulp.watch( [ 'docs/*.html', 'docs/examples/*.html', 'src/*.js' ] ).on( 'change', livereload.changed ) -}) -gulp.task( 'build', [ 'buildJS', 'buildCSS', 'copyAssets' ] ) \ No newline at end of file +// ### Gulp +// `gulp` - Run a complete build. To compile for production run `gulp --production`. +gulp.task('default', ['clean'], function() { + gulp.start('build'); +}); \ No newline at end of file diff --git a/bower.json b/bower.json index 729606fe..09bbc517 100644 --- a/bower.json +++ b/bower.json @@ -1,13 +1,13 @@ { "name": "bxslider-4", - "version": "4.1.2", + "version": "4.2.0", "homepage": "http://bxslider.com", "license": "MIT", "main": [ - "jquery.bxslider.js", - "jquery.bxslider.css", - "images/bx_loader.gif", - "images/controls.png" + "dist/jquery.bxslider.js", + "dist/jquery.bxslider.css", + "dist/images/bx_loader.gif", + "dist/images/controls.png" ], "keywords": [ "bxslider", @@ -16,7 +16,8 @@ "library" ], "ignore": [ - "**/.*", + "src/**/*.*", + "docs/**/.*", "*.md" ], "dependencies": { diff --git a/dist/jquery.bxslider.css b/dist/jquery.bxslider.css index 04536c0c..11087836 100644 --- a/dist/jquery.bxslider.css +++ b/dist/jquery.bxslider.css @@ -1,5 +1,5 @@ -/** - * BxSlider v4.1.3 - Fully loaded, responsive content slider +/*** + * BxSlider v4.2.0 - Fully loaded, responsive content slider * http://bxslider.com * * Written by: Steven Wanderski, 2014 @@ -8,7 +8,7 @@ * * CEO and founder of bxCreative, LTD * http://bxcreative.com - */ + ***/ /** RESET AND LAYOUT ===================================*/ .bx-wrapper { @@ -32,7 +32,6 @@ /** THEME ===================================*/ .bx-wrapper { - -moz-box-shadow: 0 0 5px #ccc; -webkit-box-shadow: 0 0 5px #ccc; box-shadow: 0 0 5px #ccc; border: 5px solid #fff; @@ -72,8 +71,6 @@ height: 10px; margin: 0 5px; outline: 0; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; border-radius: 5px; } .bx-wrapper .bx-pager.bx-default-pager a:hover, diff --git a/dist/jquery.bxslider.js b/dist/jquery.bxslider.js new file mode 100644 index 00000000..be529fbf --- /dev/null +++ b/dist/jquery.bxslider.js @@ -0,0 +1,1369 @@ +/*** + * BxSlider v4.2.0 - Fully loaded, responsive content slider + * http://bxslider.com + * + * Copyright 2014, Steven Wanderski - http://stevenwanderski.com - http://bxcreative.com + * Written while drinking Belgian ales and listening to jazz + * + * Released under the MIT license - http://opensource.org/licenses/MIT + ***/ + +;(function($){ + + var plugin = {}; + + var defaults = { + + // GENERAL + mode: 'horizontal', + slideSelector: '', + infiniteLoop: true, + hideControlOnEnd: false, + speed: 500, + easing: null, + slideMargin: 0, + startSlide: 0, + randomStart: false, + captions: false, + ticker: false, + tickerHover: false, + adaptiveHeight: false, + adaptiveHeightSpeed: 500, + video: false, + useCSS: true, + preloadImages: 'visible', + responsive: true, + slideZIndex: 50, + wrapperClass: 'bx-wrapper', + + // TOUCH + touchEnabled: true, + swipeThreshold: 50, + oneToOneTouch: true, + preventDefaultSwipeX: true, + preventDefaultSwipeY: false, + + // PAGER + pager: true, + pagerType: 'full', + pagerShortSeparator: ' / ', + pagerSelector: null, + buildPager: null, + pagerCustom: null, + + // CONTROLS + controls: true, + nextText: 'Next', + prevText: 'Prev', + nextSelector: null, + prevSelector: null, + autoControls: false, + startText: 'Start', + stopText: 'Stop', + autoControlsCombine: false, + autoControlsSelector: null, + + // AUTO + auto: false, + pause: 4000, + autoStart: true, + autoDirection: 'next', + autoHover: false, + autoDelay: 0, + autoSlideForOnePage: false, + + // CAROUSEL + minSlides: 1, + maxSlides: 1, + moveSlides: 0, + slideWidth: 0, + + // CALLBACKS + onSliderLoad: function(){}, + onSlideBefore: function(){}, + onSlideAfter: function(){}, + onSlideNext: function(){}, + onSlidePrev: function(){}, + onSliderResize: function(){} + }; + + $.fn.bxSlider = function(options){ + + if(this.length === 0){ + return this; + } + + // support multiple elements + if(this.length > 1){ + this.each(function(){ + $(this).bxSlider(options); + }); + return this; + } + + // create a namespace to be used throughout the plugin + var slider = {}; + // set a reference to our slider element + var el = this; + plugin.el = this; + + /** + * Makes slideshow responsive + */ + // first get the original window dimens (thanks a lot IE) + var windowWidth = $(window).width(); + var windowHeight = $(window).height(); + + + + /** + * =================================================================================== + * = PRIVATE FUNCTIONS + * =================================================================================== + */ + + /** + * Initializes namespace settings to be used throughout plugin + */ + var init = function(){ + // merge user-supplied options with the defaults + slider.settings = $.extend({}, defaults, options); + // parse slideWidth setting + slider.settings.slideWidth = parseInt(slider.settings.slideWidth); + // store the original children + slider.children = el.children(slider.settings.slideSelector); + // check if actual number of slides is less than minSlides / maxSlides + if(slider.children.length < slider.settings.minSlides){ slider.settings.minSlides = slider.children.length; } + if(slider.children.length < slider.settings.maxSlides){ slider.settings.maxSlides = slider.children.length; } + // if random start, set the startSlide setting to random number + if(slider.settings.randomStart){ slider.settings.startSlide = Math.floor(Math.random() * slider.children.length); } + // store active slide information + slider.active = { index: slider.settings.startSlide }; + // store if the slider is in carousel mode (displaying / moving multiple slides) + slider.carousel = slider.settings.minSlides > 1 || slider.settings.maxSlides > 1 ? false : true; + // if carousel, force preloadImages = 'all' + if(slider.carousel){ slider.settings.preloadImages = 'all'; } + // calculate the min / max width thresholds based on min / max number of slides + // used to setup and update carousel slides dimensions + slider.minThreshold = (slider.settings.minSlides * slider.settings.slideWidth) + ((slider.settings.minSlides - 1) * slider.settings.slideMargin); + slider.maxThreshold = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); + // store the current state of the slider (if currently animating, working is true) + slider.working = false; + // initialize the controls object + slider.controls = {}; + // initialize an auto interval + slider.interval = null; + // determine which property to use for transitions + slider.animProp = slider.settings.mode === 'vertical' ? 'top' : 'left'; + // determine if hardware acceleration can be used + slider.usingCSS = slider.settings.useCSS && slider.settings.mode !== 'fade' && (function(){ + // create our test div element + var div = document.createElement('div'); + // css transition properties + var props = ['WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective']; + // test for each property + for(var i in props){ + if(div.style[props[i]] !== undefined){ + slider.cssPrefix = props[i].replace('Perspective', '').toLowerCase(); + slider.animProp = '-' + slider.cssPrefix + '-transform'; + return true; + } + } + return false; + }()); + // if vertical mode always make maxSlides and minSlides equal + if(slider.settings.mode === 'vertical'){ slider.settings.maxSlides = slider.settings.minSlides; } + // save original style data + el.data("origStyle", el.attr("style")); + el.children(slider.settings.slideSelector).each(function(){ + $(this).data("origStyle", $(this).attr("style")); + }); + // perform all DOM / CSS modifications + setup(); + }; + + /** + * Performs all DOM and CSS modifications + */ + var setup = function(){ + // wrap el in a wrapper + el.wrap('
'); + // store a namespace reference to .bx-viewport + slider.viewport = el.parent(); + // add a loading div to display while images are loading + slider.loader = $('
'); + slider.viewport.prepend(slider.loader); + // set el to a massive width, to hold any needed slides + // also strip any margin and padding from el + el.css({ + width: slider.settings.mode === 'horizontal' ? (slider.children.length * 1000 + 215) + '%' : 'auto', + position: 'relative' + }); + // if using CSS, add the easing property + if(slider.usingCSS && slider.settings.easing){ + el.css('-' + slider.cssPrefix + '-transition-timing-function', slider.settings.easing); + // if not using CSS and no easing value was supplied, use the default JS animation easing (swing) + }else if(!slider.settings.easing){ + slider.settings.easing = 'swing'; + } + var slidesShowing = getNumberSlidesShowing(); + // make modifications to the viewport (.bx-viewport) + slider.viewport.css({ + width: '100%', + overflow: 'hidden', + position: 'relative' + }); + slider.viewport.parent().css({ + maxWidth: getViewportMaxWidth() + }); + // make modification to the wrapper (.bx-wrapper) + if(!slider.settings.pager){ + slider.viewport.parent().css({ + margin: '0 auto 0px' + }); + } + // apply css to all slider children + slider.children.css({ + 'float': slider.settings.mode === 'horizontal' ? 'left' : 'none', + listStyle: 'none', + position: 'relative' + }); + // apply the calculated width after the float is applied to prevent scrollbar interference + slider.children.css('width', getSlideWidth()); + // if slideMargin is supplied, add the css + if(slider.settings.mode === 'horizontal' && slider.settings.slideMargin > 0){ slider.children.css('marginRight', slider.settings.slideMargin); } + if(slider.settings.mode === 'vertical' && slider.settings.slideMargin > 0){ slider.children.css('marginBottom', slider.settings.slideMargin); } + // if "fade" mode, add positioning and z-index CSS + if(slider.settings.mode === 'fade'){ + slider.children.css({ + position: 'absolute', + zIndex: 0, + display: 'none' + }); + // prepare the z-index on the showing element + slider.children.eq(slider.settings.startSlide).css({zIndex: slider.settings.slideZIndex, display: 'block'}); + } + // create an element to contain all slider controls (pager, start / stop, etc) + slider.controls.el = $('
'); + // if captions are requested, add them + if(slider.settings.captions){ appendCaptions(); } + // check if startSlide is last slide + slider.active.last = slider.settings.startSlide === getPagerQty() - 1; + // if video is true, set up the fitVids plugin + if(slider.settings.video){ el.fitVids(); } + // set the default preload selector (visible) + var preloadSelector = slider.children.eq(slider.settings.startSlide); + if(slider.settings.preloadImages === "all"){ preloadSelector = slider.children; } + // only check for control addition if not in "ticker" mode + if(!slider.settings.ticker){ + // if controls are requested, add them + if(slider.settings.controls){ appendControls(); } + // if auto is true, and auto controls are requested, add them + if(slider.settings.auto && slider.settings.autoControls){ appendControlsAuto(); } + // if pager is requested, add it + if(slider.settings.pager){ appendPager(); } + // if any control option is requested, add the controls wrapper + if(slider.settings.controls || slider.settings.autoControls || slider.settings.pager){ slider.viewport.after(slider.controls.el); } + // if ticker mode, do not allow a pager + } else { + slider.settings.pager = false; + } + // preload all images, then perform final DOM / CSS modifications that depend on images being loaded + loadElements(preloadSelector, start); + }; + + var loadElements = function(selector, callback){ + var total = selector.find('img, iframe').length; + if(total === 0){ + callback(); + return; + } + var count = 0; + selector.find('img, iframe').each(function(){ + $(this).one('load', function(){ + if(++count === total){ callback(); } + }).each(function(){ + if(this.complete){ $(this).load(); } + }); + }); + }; + + /** + * Start the slider + */ + var start = function(){ + // if infinite loop, prepare additional slides + if(slider.settings.infiniteLoop && slider.settings.mode !== 'fade' && !slider.settings.ticker){ + var slice = slider.settings.mode === 'vertical' ? slider.settings.minSlides : slider.settings.maxSlides; + var sliceAppend = slider.children.slice(0, slice).clone(true).addClass('bx-clone'); + var slicePrepend = slider.children.slice(-slice).clone(true).addClass('bx-clone'); + el.append(sliceAppend).prepend(slicePrepend); + } + // remove the loading DOM element + slider.loader.remove(); + // set the left / top position of "el" + setSlidePosition(); + // if "vertical" mode, always use adaptiveHeight to prevent odd behavior + if(slider.settings.mode === 'vertical'){ slider.settings.adaptiveHeight = true; } + // set the viewport height + slider.viewport.height(getViewportHeight()); + // make sure everything is positioned just right (same as a window resize) + el.redrawSlider(); + // onSliderLoad callback + slider.settings.onSliderLoad(slider.active.index); + // slider has been fully initialized + slider.initialized = true; + // bind the resize call to the window + if(slider.settings.responsive){ $(window).bind('resize', resizeWindow); } + // if auto is true and has more than 1 page, start the show + if(slider.settings.auto && slider.settings.autoStart && (getPagerQty() > 1 || slider.settings.autoSlideForOnePage)){ initAuto(); } + // if ticker is true, start the ticker + if(slider.settings.ticker){ initTicker(); } + // if pager is requested, make the appropriate pager link active + if(slider.settings.pager){ updatePagerActive(slider.settings.startSlide); } + // check for any updates to the controls (like hideControlOnEnd updates) + if(slider.settings.controls){ updateDirectionControls(); } + // if touchEnabled is true, setup the touch events + if(slider.settings.touchEnabled && !slider.settings.ticker){ initTouch(); } + }; + + /** + * Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value + */ + var getViewportHeight = function(){ + var height = 0; + // first determine which children (slides) should be used in our height calculation + var children = $(); + // if mode is not "vertical" and adaptiveHeight is false, include all children + if(slider.settings.mode !== 'vertical' && !slider.settings.adaptiveHeight){ + children = slider.children; + }else{ + // if not carousel, return the single active child + if(!slider.carousel){ + children = slider.children.eq(slider.active.index); + // if carousel, return a slice of children + }else{ + // get the individual slide index + var currentIndex = slider.settings.moveSlides === 1 ? slider.active.index : slider.active.index * getMoveBy(); + // add the current slide to the children + children = slider.children.eq(currentIndex); + // cycle through the remaining "showing" slides + for (i = 1; i <= slider.settings.maxSlides - 1; i++){ + // if looped back to the start + if(currentIndex + i >= slider.children.length){ + children = children.add(slider.children.eq(i - 1)); + }else{ + children = children.add(slider.children.eq(currentIndex + i)); + } + } + } + } + // if "vertical" mode, calculate the sum of the heights of the children + if(slider.settings.mode === 'vertical'){ + children.each(function(index){ + height += $(this).outerHeight(); + }); + // add user-supplied margins + if(slider.settings.slideMargin > 0){ + height += slider.settings.slideMargin * (slider.settings.minSlides - 1); + } + // if not "vertical" mode, calculate the max height of the children + }else{ + height = Math.max.apply(Math, children.map(function(){ + return $(this).outerHeight(false); + }).get()); + } + + if(slider.viewport.css('box-sizing') === 'border-box'){ + height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')) + + parseFloat(slider.viewport.css('border-top-width')) + parseFloat(slider.viewport.css('border-bottom-width')); + }else if(slider.viewport.css('box-sizing') === 'padding-box'){ + height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')); + } + + return height; + }; + + /** + * Returns the calculated width to be used for the outer wrapper / viewport + */ + var getViewportMaxWidth = function(){ + var width = '100%'; + if(slider.settings.slideWidth > 0){ + if(slider.settings.mode === 'horizontal'){ + width = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); + }else{ + width = slider.settings.slideWidth; + } + } + return width; + }; + + /** + * Returns the calculated width to be applied to each slide + */ + var getSlideWidth = function(){ + // start with any user-supplied slide width + var newElWidth = slider.settings.slideWidth; + // get the current viewport width + var wrapWidth = slider.viewport.width(); + // if slide width was not supplied, or is larger than the viewport use the viewport width + if(slider.settings.slideWidth === 0 || + (slider.settings.slideWidth > wrapWidth && !slider.carousel) || + slider.settings.mode === 'vertical'){ + newElWidth = wrapWidth; + // if carousel, use the thresholds to determine the width + }else if(slider.settings.maxSlides > 1 && slider.settings.mode === 'horizontal'){ + if(wrapWidth > slider.maxThreshold){ + // newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.maxSlides - 1))) / slider.settings.maxSlides; + }else if(wrapWidth < slider.minThreshold){ + newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.minSlides - 1))) / slider.settings.minSlides; + } + } + return newElWidth; + }; + + /** + * Returns the number of slides currently visible in the viewport (includes partially visible slides) + */ + var getNumberSlidesShowing = function(){ + var slidesShowing = 1; + if(slider.settings.mode === 'horizontal' && slider.settings.slideWidth > 0){ + // if viewport is smaller than minThreshold, return minSlides + if(slider.viewport.width() < slider.minThreshold){ + slidesShowing = slider.settings.minSlides; + // if viewport is larger than minThreshold, return maxSlides + }else if(slider.viewport.width() > slider.maxThreshold){ + slidesShowing = slider.settings.maxSlides; + // if viewport is between min / max thresholds, divide viewport width by first child width + }else{ + var childWidth = slider.children.first().width() + slider.settings.slideMargin; + slidesShowing = Math.floor((slider.viewport.width() + + slider.settings.slideMargin) / childWidth); + } + // if "vertical" mode, slides showing will always be minSlides + }else if(slider.settings.mode === 'vertical'){ + slidesShowing = slider.settings.minSlides; + } + return slidesShowing; + }; + + /** + * Returns the number of pages (one full viewport of slides is one "page") + */ + var getPagerQty = function(){ + var pagerQty = 0; + // if moveSlides is specified by the user + if(slider.settings.moveSlides > 0){ + if(slider.settings.infiniteLoop){ + pagerQty = Math.ceil(slider.children.length / getMoveBy()); + }else{ + // use a while loop to determine pages + var breakPoint = 0; + var counter = 0; + // when breakpoint goes above children length, counter is the number of pages + while (breakPoint < slider.children.length){ + ++pagerQty; + breakPoint = counter + getNumberSlidesShowing(); + counter += slider.settings.moveSlides <= getNumberSlidesShowing() ? slider.settings.moveSlides : getNumberSlidesShowing(); + } + } + // if moveSlides is 0 (auto) divide children length by sides showing, then round up + }else{ + pagerQty = Math.ceil(slider.children.length / getNumberSlidesShowing()); + } + return pagerQty; + }; + + /** + * Returns the number of individual slides by which to shift the slider + */ + var getMoveBy = function(){ + // if moveSlides was set by the user and moveSlides is less than number of slides showing + if(slider.settings.moveSlides > 0 && slider.settings.moveSlides <= getNumberSlidesShowing()){ + return slider.settings.moveSlides; + } + // if moveSlides is 0 (auto) + return getNumberSlidesShowing(); + }; + + /** + * Sets the slider's (el) left or top position + */ + var setSlidePosition = function(){ + var position; + // if last slide, not infinite loop, and number of children is larger than specified maxSlides + if(slider.children.length > slider.settings.maxSlides && slider.active.last && !slider.settings.infiniteLoop){ + if(slider.settings.mode === 'horizontal'){ + // get the last child's position + var lastChild = slider.children.last(); + position = lastChild.position(); + // set the left position + setPositionProperty(-(position.left - (slider.viewport.width() - lastChild.outerWidth())), 'reset', 0); + }else if(slider.settings.mode === 'vertical'){ + // get the last showing index's position + var lastShowingIndex = slider.children.length - slider.settings.minSlides; + position = slider.children.eq(lastShowingIndex).position(); + // set the top position + setPositionProperty(-position.top, 'reset', 0); + } + // if not last slide + }else{ + // get the position of the first showing slide + position = slider.children.eq(slider.active.index * getMoveBy()).position(); + // check for last slide + if(slider.active.index === getPagerQty() - 1){ slider.active.last = true; } + // set the respective position + if(position !== undefined){ + if(slider.settings.mode === 'horizontal'){ setPositionProperty(-position.left, 'reset', 0); } + else if(slider.settings.mode === 'vertical'){ setPositionProperty(-position.top, 'reset', 0); } + } + } + }; + + /** + * Sets the el's animating property position (which in turn will sometimes animate el). + * If using CSS, sets the transform property. If not using CSS, sets the top / left property. + * + * @param value (int) + * - the animating property's value + * + * @param type (string) 'slider', 'reset', 'ticker' + * - the type of instance for which the function is being + * + * @param duration (int) + * - the amount of time (in ms) the transition should occupy + * + * @param params (array) optional + * - an optional parameter containing any variables that need to be passed in + */ + var setPositionProperty = function(value, type, duration, params){ + // use CSS transform + if(slider.usingCSS){ + // determine the translate3d value + var propValue = slider.settings.mode === 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)'; + // add the CSS transition-duration + el.css('-' + slider.cssPrefix + '-transition-duration', duration / 1000 + 's'); + if(type === 'slide'){ + // set the property value + el.css(slider.animProp, propValue); + // bind a callback method - executes when CSS transition completes + el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){ + // unbind the callback + el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); + updateAfterSlideTransition(); + }); + }else if(type === 'reset'){ + el.css(slider.animProp, propValue); + }else if(type === 'ticker'){ + // make the transition use 'linear' + el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear'); + el.css(slider.animProp, propValue); + // bind a callback method - executes when CSS transition completes + el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){ + // unbind the callback + el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); + // reset the position + setPositionProperty(params.resetValue, 'reset', 0); + // start the loop again + tickerLoop(); + }); + } + // use JS animate + }else{ + var animateObj = {}; + animateObj[slider.animProp] = value; + if(type === 'slide'){ + el.animate(animateObj, duration, slider.settings.easing, function(){ + updateAfterSlideTransition(); + }); + }else if(type === 'reset'){ + el.css(slider.animProp, value); + }else if(type === 'ticker'){ + el.animate(animateObj, speed, 'linear', function(){ + setPositionProperty(params.resetValue, 'reset', 0); + // run the recursive loop after animation + tickerLoop(); + }); + } + } + }; + + /** + * Populates the pager with proper amount of pages + */ + var populatePager = function(){ + var pagerHtml = ''; + var pagerQty = getPagerQty(); + // loop through each pager item + for(var i=0; i < pagerQty; i++){ + var linkContent = ''; + // if a buildPager function is supplied, use it to get pager link value, else use index + 1 + if(slider.settings.buildPager && $.isFunction(slider.settings.buildPager) || slider.settings.pagerCustom){ + linkContent = slider.settings.buildPager(i); + slider.pagerEl.addClass('bx-custom-pager'); + }else{ + linkContent = i + 1; + slider.pagerEl.addClass('bx-default-pager'); + } + // var linkContent = slider.settings.buildPager && $.isFunction(slider.settings.buildPager) ? slider.settings.buildPager(i) : i + 1; + // add the markup to the string + pagerHtml += ''; + } + // populate the pager element with pager links + slider.pagerEl.html(pagerHtml); + }; + + /** + * Appends the pager to the controls element + */ + var appendPager = function(){ + if(!slider.settings.pagerCustom){ + // create the pager DOM element + slider.pagerEl = $('
'); + // if a pager selector was supplied, populate it with the pager + if(slider.settings.pagerSelector){ + $(slider.settings.pagerSelector).html(slider.pagerEl); + // if no pager selector was supplied, add it after the wrapper + }else{ + slider.controls.el.addClass('bx-has-pager').append(slider.pagerEl); + } + // populate the pager + populatePager(); + }else{ + slider.pagerEl = $(slider.settings.pagerCustom); + } + // assign the pager click binding + slider.pagerEl.on('click', 'a', clickPagerBind); + }; + + /** + * Appends prev / next controls to the controls element + */ + var appendControls = function(){ + slider.controls.next = $('' + slider.settings.nextText + ''); + slider.controls.prev = $('' + slider.settings.prevText + ''); + // bind click actions to the controls + slider.controls.next.bind('click', clickNextBind); + slider.controls.prev.bind('click', clickPrevBind); + // if nextSelector was supplied, populate it + if(slider.settings.nextSelector){ + $(slider.settings.nextSelector).append(slider.controls.next); + } + // if prevSelector was supplied, populate it + if(slider.settings.prevSelector){ + $(slider.settings.prevSelector).append(slider.controls.prev); + } + // if no custom selectors were supplied + if(!slider.settings.nextSelector && !slider.settings.prevSelector){ + // add the controls to the DOM + slider.controls.directionEl = $('
'); + // add the control elements to the directionEl + slider.controls.directionEl.append(slider.controls.prev).append(slider.controls.next); + // slider.viewport.append(slider.controls.directionEl); + slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl); + } + }; + + /** + * Appends start / stop auto controls to the controls element + */ + var appendControlsAuto = function(){ + slider.controls.start = $(''); + slider.controls.stop = $(''); + // add the controls to the DOM + slider.controls.autoEl = $('
'); + // bind click actions to the controls + slider.controls.autoEl.on('click', '.bx-start', clickStartBind); + slider.controls.autoEl.on('click', '.bx-stop', clickStopBind); + // if autoControlsCombine, insert only the "start" control + if(slider.settings.autoControlsCombine){ + slider.controls.autoEl.append(slider.controls.start); + // if autoControlsCombine is false, insert both controls + }else{ + slider.controls.autoEl.append(slider.controls.start).append(slider.controls.stop); + } + // if auto controls selector was supplied, populate it with the controls + if(slider.settings.autoControlsSelector){ + $(slider.settings.autoControlsSelector).html(slider.controls.autoEl); + // if auto controls selector was not supplied, add it after the wrapper + }else{ + slider.controls.el.addClass('bx-has-controls-auto').append(slider.controls.autoEl); + } + // update the auto controls + updateAutoControls(slider.settings.autoStart ? 'stop' : 'start'); + }; + + /** + * Appends image captions to the DOM + */ + var appendCaptions = function(){ + // cycle through each child + slider.children.each(function(index){ + // get the image title attribute + var title = $(this).find('img:first').attr('title'); + // append the caption + if(title !== undefined && ('' + title).length){ + $(this).append('
' + title + '
'); + } + }); + }; + + /** + * Click next binding + * + * @param e (event) + * - DOM event object + */ + var clickNextBind = function(e){ + // if auto show is running, stop it + if(slider.settings.auto){ el.stopAuto(); } + el.goToNextSlide(); + e.preventDefault(); + }; + + /** + * Click prev binding + * + * @param e (event) + * - DOM event object + */ + var clickPrevBind = function(e){ + // if auto show is running, stop it + if(slider.settings.auto){ el.stopAuto(); } + el.goToPrevSlide(); + e.preventDefault(); + }; + + /** + * Click start binding + * + * @param e (event) + * - DOM event object + */ + var clickStartBind = function(e){ + el.startAuto(); + e.preventDefault(); + }; + + /** + * Click stop binding + * + * @param e (event) + * - DOM event object + */ + var clickStopBind = function(e){ + el.stopAuto(); + e.preventDefault(); + }; + + /** + * Click pager binding + * + * @param e (event) + * - DOM event object + */ + var clickPagerBind = function(e){ + // if auto show is running, stop it + if(slider.settings.auto){ el.stopAuto(); } + var pagerLink = $(e.currentTarget); + if(pagerLink.attr('data-slide-index') !== undefined){ + var pagerIndex = parseInt(pagerLink.attr('data-slide-index')); + // if clicked pager link is not active, continue with the goToSlide call + if(pagerIndex !== slider.active.index){ el.goToSlide(pagerIndex); } + e.preventDefault(); + } + }; + + /** + * Updates the pager links with an active class + * + * @param slideIndex (int) + * - index of slide to make active + */ + var updatePagerActive = function(slideIndex){ + // if "short" pager type + var len = slider.children.length; // nb of children + if(slider.settings.pagerType === 'short'){ + if(slider.settings.maxSlides > 1){ + len = Math.ceil(slider.children.length/slider.settings.maxSlides); + } + slider.pagerEl.html( (slideIndex + 1) + slider.settings.pagerShortSeparator + len); + return; + } + // remove all pager active classes + slider.pagerEl.find('a').removeClass('active'); + // apply the active class for all pagers + slider.pagerEl.each(function(i, el){ $(el).find('a').eq(slideIndex).addClass('active'); }); + }; + + /** + * Performs needed actions after a slide transition + */ + var updateAfterSlideTransition = function(){ + // if infinite loop is true + if(slider.settings.infiniteLoop){ + var position = ''; + // first slide + if(slider.active.index === 0){ + // set the new position + position = slider.children.eq(0).position(); + // carousel, last slide + }else if(slider.active.index === getPagerQty() - 1 && slider.carousel){ + position = slider.children.eq((getPagerQty() - 1) * getMoveBy()).position(); + // last slide + }else if(slider.active.index === slider.children.length - 1){ + position = slider.children.eq(slider.children.length - 1).position(); + } + if(position){ + if(slider.settings.mode === 'horizontal'){ setPositionProperty(-position.left, 'reset', 0); } + else if(slider.settings.mode === 'vertical'){ setPositionProperty(-position.top, 'reset', 0); } + } + } + // declare that the transition is complete + slider.working = false; + // onSlideAfter callback + slider.settings.onSlideAfter(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); + }; + + /** + * Updates the auto controls state (either active, or combined switch) + * + * @param state (string) "start", "stop" + * - the new state of the auto show + */ + var updateAutoControls = function(state){ + // if autoControlsCombine is true, replace the current control with the new state + if(slider.settings.autoControlsCombine){ + slider.controls.autoEl.html(slider.controls[state]); + // if autoControlsCombine is false, apply the "active" class to the appropriate control + }else{ + slider.controls.autoEl.find('a').removeClass('active'); + slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active'); + } + }; + + /** + * Updates the direction controls (checks if either should be hidden) + */ + var updateDirectionControls = function(){ + if(getPagerQty() === 1){ + slider.controls.prev.addClass('disabled'); + slider.controls.next.addClass('disabled'); + }else if(!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd){ + // if first slide + if(slider.active.index === 0){ + slider.controls.prev.addClass('disabled'); + slider.controls.next.removeClass('disabled'); + // if last slide + }else if(slider.active.index === getPagerQty() - 1){ + slider.controls.next.addClass('disabled'); + slider.controls.prev.removeClass('disabled'); + // if any slide in the middle + }else{ + slider.controls.prev.removeClass('disabled'); + slider.controls.next.removeClass('disabled'); + } + } + }; + + /** + * Initializes the auto process + */ + var initAuto = function(){ + // if autoDelay was supplied, launch the auto show using a setTimeout() call + if(slider.settings.autoDelay > 0){ + var timeout = setTimeout(el.startAuto, slider.settings.autoDelay); + // if autoDelay was not supplied, start the auto show normally + }else{ + el.startAuto(); + } + // if autoHover is requested + if(slider.settings.autoHover){ + // on el hover + el.hover(function(){ + // if the auto show is currently playing (has an active interval) + if(slider.interval){ + // stop the auto show and pass true argument which will prevent control update + el.stopAuto(true); + // create a new autoPaused value which will be used by the relative "mouseout" event + slider.autoPaused = true; + } + }, function(){ + // if the autoPaused value was created be the prior "mouseover" event + if(slider.autoPaused){ + // start the auto show and pass true argument which will prevent control update + el.startAuto(true); + // reset the autoPaused value + slider.autoPaused = null; + } + }); + } + }; + + /** + * Initializes the ticker process + */ + var initTicker = function(){ + var startPosition = 0; + // if autoDirection is "next", append a clone of the entire slider + if(slider.settings.autoDirection === 'next'){ + el.append(slider.children.clone().addClass('bx-clone')); + // if autoDirection is "prev", prepend a clone of the entire slider, and set the left position + }else{ + el.prepend(slider.children.clone().addClass('bx-clone')); + var position = slider.children.first().position(); + startPosition = slider.settings.mode === 'horizontal' ? -position.left : -position.top; + } + setPositionProperty(startPosition, 'reset', 0); + // do not allow controls in ticker mode + slider.settings.pager = false; + slider.settings.controls = false; + slider.settings.autoControls = false; + // if autoHover is requested + if(slider.settings.tickerHover && !slider.usingCSS){ + // on el hover + slider.viewport.hover(function(){ + el.stop(); + }, function(){ + // calculate the total width of children (used to calculate the speed ratio) + var totalDimens = 0; + slider.children.each(function(index){ + totalDimens += slider.settings.mode === 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); + }); + // calculate the speed ratio (used to determine the new speed to finish the paused animation) + var ratio = slider.settings.speed / totalDimens; + // determine which property to use + var property = slider.settings.mode === 'horizontal' ? 'left' : 'top'; + // calculate the new speed + var newSpeed = ratio * (totalDimens - (Math.abs(parseInt(el.css(property))))); + tickerLoop(newSpeed); + }); + } + // start the ticker loop + tickerLoop(); + }; + + /** + * Runs a continuous loop, news ticker-style + */ + var tickerLoop = function(resumeSpeed){ + speed = resumeSpeed ? resumeSpeed : slider.settings.speed; + var position = {left: 0, top: 0}; + var reset = {left: 0, top: 0}; + // if "next" animate left position to last child, then reset left to 0 + if(slider.settings.autoDirection === 'next'){ + position = el.find('.bx-clone').first().position(); + // if "prev" animate left position to 0, then reset left to first non-clone child + }else{ + reset = slider.children.first().position(); + } + var animateProperty = slider.settings.mode === 'horizontal' ? -position.left : -position.top; + var resetValue = slider.settings.mode === 'horizontal' ? -reset.left : -reset.top; + var params = {resetValue: resetValue}; + setPositionProperty(animateProperty, 'ticker', speed, params); + }; + + /** + * Initializes touch events + */ + var initTouch = function(){ + // initialize object to contain all touch values + slider.touch = { + start: {x: 0, y: 0}, + end: {x: 0, y: 0} + }; + slider.viewport.bind('touchstart', onTouchStart); + }; + + /** + * Event handler for "touchstart" + * + * @param e (event) + * - DOM event object + */ + var onTouchStart = function(e){ + if(slider.working){ + e.preventDefault(); + }else{ + // record the original position when touch starts + slider.touch.originalPos = el.position(); + var orig = e.originalEvent; + // record the starting touch x, y coordinates + slider.touch.start.x = orig.changedTouches[0].pageX; + slider.touch.start.y = orig.changedTouches[0].pageY; + // bind a "touchmove" event to the viewport + slider.viewport.bind('touchmove', onTouchMove); + // bind a "touchend" event to the viewport + slider.viewport.bind('touchend', onTouchEnd); + } + }; + + /** + * Event handler for "touchmove" + * + * @param e (event) + * - DOM event object + */ + var onTouchMove = function(e){ + var orig = e.originalEvent; + // if scrolling on y axis, do not prevent default + var xMovement = Math.abs(orig.changedTouches[0].pageX - slider.touch.start.x); + var yMovement = Math.abs(orig.changedTouches[0].pageY - slider.touch.start.y); + // x axis swipe + if((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX){ + e.preventDefault(); + // y axis swipe + }else if((yMovement * 3) > xMovement && slider.settings.preventDefaultSwipeY){ + e.preventDefault(); + } + if(slider.settings.mode !== 'fade' && slider.settings.oneToOneTouch){ + var value = 0, change = 0; + // if horizontal, drag along x axis + if(slider.settings.mode === 'horizontal'){ + change = orig.changedTouches[0].pageX - slider.touch.start.x; + value = slider.touch.originalPos.left + change; + // if vertical, drag along y axis + }else{ + change = orig.changedTouches[0].pageY - slider.touch.start.y; + value = slider.touch.originalPos.top + change; + } + setPositionProperty(value, 'reset', 0); + } + }; + + /** + * Event handler for "touchend" + * + * @param e (event) + * - DOM event object + */ + var onTouchEnd = function(e){ + slider.viewport.unbind('touchmove', onTouchMove); + var orig = e.originalEvent; + var value = 0; + var distance = 0; + // record end x, y positions + slider.touch.end.x = orig.changedTouches[0].pageX; + slider.touch.end.y = orig.changedTouches[0].pageY; + // if fade mode, check if absolute x distance clears the threshold + if(slider.settings.mode === 'fade'){ + distance = Math.abs(slider.touch.start.x - slider.touch.end.x); + if(distance >= slider.settings.swipeThreshold){ + if(slider.touch.start.x > slider.touch.end.x){ + el.goToNextSlide(); + } else { + el.goToPrevSlide(); + } + el.stopAuto(); + } + // not fade mode + }else{ + // calculate distance and el's animate property + if(slider.settings.mode === 'horizontal'){ + distance = slider.touch.end.x - slider.touch.start.x; + value = slider.touch.originalPos.left; + }else{ + distance = slider.touch.end.y - slider.touch.start.y; + value = slider.touch.originalPos.top; + } + // if not infinite loop and first / last slide, do not attempt a slide transition + if(!slider.settings.infiniteLoop && ((slider.active.index === 0 && distance > 0) || (slider.active.last && distance < 0))){ + setPositionProperty(value, 'reset', 200); + }else{ + // check if distance clears threshold + if(Math.abs(distance) >= slider.settings.swipeThreshold){ + if(distance < 0){ + el.goToNextSlide(); + } else { + el.goToPrevSlide(); + } + el.stopAuto(); + }else{ + // el.animate(property, 200); + setPositionProperty(value, 'reset', 200); + } + } + } + slider.viewport.unbind('touchend', onTouchEnd); + }; + + /** + * Window resize event callback + */ + var resizeWindow = function(e){ + // don't do anything if slider isn't initialized. + if(!slider.initialized){ return; } + // get the new window dimens (again, thank you IE) + var windowWidthNew = $(window).width(); + var windowHeightNew = $(window).height(); + // make sure that it is a true window resize + // *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements + // are resized. Can you just die already?* + if(windowWidth !== windowWidthNew || windowHeight !== windowHeightNew){ + // set the new window dimens + windowWidth = windowWidthNew; + windowHeight = windowHeightNew; + // update all dynamic elements + el.redrawSlider(); + // Call user resize handler + slider.settings.onSliderResize.call(el, slider.active.index); + } + }; + + /** + * =================================================================================== + * = PUBLIC FUNCTIONS + * =================================================================================== + */ + + /** + * Performs slide transition to the specified slide + * + * @param slideIndex (int) + * - the destination slide's index (zero-based) + * + * @param direction (string) + * - INTERNAL USE ONLY - the direction of travel ("prev" / "next") + */ + el.goToSlide = function(slideIndex, direction){ + // if plugin is currently in motion, ignore request + if(slider.working || slider.active.index === slideIndex){ return; } + // declare that plugin is in motion + slider.working = true; + // store the old index + slider.oldIndex = slider.active.index; + // if slideIndex is less than zero, set active index to last child (this happens during infinite loop) + if(slideIndex < 0){ + slider.active.index = getPagerQty() - 1; + // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) + }else if(slideIndex >= getPagerQty()){ + slider.active.index = 0; + // set active index to requested slide + }else{ + slider.active.index = slideIndex; + } + // onSlideBefore, onSlideNext, onSlidePrev callbacks + slider.settings.onSlideBefore(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); + if(direction === 'next'){ + slider.settings.onSlideNext(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); + }else if(direction === 'prev'){ + slider.settings.onSlidePrev(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); + } + // check if last slide + slider.active.last = slider.active.index >= getPagerQty() - 1; + // update the pager with active class + if(slider.settings.pager || slider.settings.pagerCustom){ updatePagerActive(slider.active.index); } + // // check for direction control update + if(slider.settings.controls){ updateDirectionControls(); } + // if slider is set to mode: "fade" + if(slider.settings.mode === 'fade'){ + // if adaptiveHeight is true and next height is different from current height, animate to the new height + if(slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()){ + slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); + } + // fade out the visible child and reset its z-index value + slider.children.filter(':visible').fadeOut(slider.settings.speed).css({zIndex: 0}); + // fade in the newly requested slide + slider.children.eq(slider.active.index).css('zIndex', slider.settings.slideZIndex+1).fadeIn(slider.settings.speed, function(){ + $(this).css('zIndex', slider.settings.slideZIndex); + updateAfterSlideTransition(); + }); + // slider mode is not "fade" + }else{ + // if adaptiveHeight is true and next height is different from current height, animate to the new height + if(slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()){ + slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); + } + var moveBy = 0; + var position = {left: 0, top: 0}; + var lastChild = null; + // if carousel and not infinite loop + if(!slider.settings.infiniteLoop && slider.carousel && slider.active.last){ + if(slider.settings.mode === 'horizontal'){ + // get the last child position + lastChild = slider.children.eq(slider.children.length - 1); + position = lastChild.position(); + // calculate the position of the last slide + moveBy = slider.viewport.width() - lastChild.outerWidth(); + }else{ + // get last showing index position + var lastShowingIndex = slider.children.length - slider.settings.minSlides; + position = slider.children.eq(lastShowingIndex).position(); + } + // horizontal carousel, going previous while on first slide (infiniteLoop mode) + }else if(slider.carousel && slider.active.last && direction === 'prev'){ + // get the last child position + var eq = slider.settings.moveSlides === 1 ? slider.settings.maxSlides - getMoveBy() : ((getPagerQty() - 1) * getMoveBy()) - (slider.children.length - slider.settings.maxSlides); + lastChild = el.children('.bx-clone').eq(eq); + position = lastChild.position(); + // if infinite loop and "Next" is clicked on the last slide + }else if(direction === 'next' && slider.active.index === 0){ + // get the last clone position + position = el.find('> .bx-clone').eq(slider.settings.maxSlides).position(); + slider.active.last = false; + // normal non-zero requests + }else if(slideIndex >= 0){ + var requestEl = slideIndex * getMoveBy(); + position = slider.children.eq(requestEl).position(); + } + + /* If the position doesn't exist + * (e.g. if you destroy the slider on a next click), + * it doesn't throw an error. + */ + if("undefined" !== typeof(position)){ + var value = slider.settings.mode === 'horizontal' ? -(position.left - moveBy) : -position.top; + // plugin values to be animated + setPositionProperty(value, 'slide', slider.settings.speed); + } + } + }; + + /** + * Transitions to the next slide in the show + */ + el.goToNextSlide = function(){ + // if infiniteLoop is false and last page is showing, disregard call + if(!slider.settings.infiniteLoop && slider.active.last){ return; } + var pagerIndex = parseInt(slider.active.index) + 1; + el.goToSlide(pagerIndex, 'next'); + }; + + /** + * Transitions to the prev slide in the show + */ + el.goToPrevSlide = function(){ + // if infiniteLoop is false and last page is showing, disregard call + if(!slider.settings.infiniteLoop && slider.active.index === 0){ return; } + var pagerIndex = parseInt(slider.active.index) - 1; + el.goToSlide(pagerIndex, 'prev'); + }; + + /** + * Starts the auto show + * + * @param preventControlUpdate (boolean) + * - if true, auto controls state will not be updated + */ + el.startAuto = function(preventControlUpdate){ + // if an interval already exists, disregard call + if(slider.interval){ return; } + // create an interval + slider.interval = setInterval(function(){ + if(slider.settings.autoDirection === 'next'){ + el.goToNextSlide(); + }else{ + el.goToPrevSlide(); + } + }, slider.settings.pause); + // if auto controls are displayed and preventControlUpdate is not true + if(slider.settings.autoControls && preventControlUpdate !== true){ updateAutoControls('stop'); } + }; + + /** + * Stops the auto show + * + * @param preventControlUpdate (boolean) + * - if true, auto controls state will not be updated + */ + el.stopAuto = function(preventControlUpdate){ + // if no interval exists, disregard call + if(!slider.interval){ return; } + // clear the interval + clearInterval(slider.interval); + slider.interval = null; + // if auto controls are displayed and preventControlUpdate is not true + if(slider.settings.autoControls && preventControlUpdate !== true){ updateAutoControls('start'); } + }; + + /** + * Returns current slide index (zero-based) + */ + el.getCurrentSlide = function(){ + return slider.active.index; + }; + + /** + * Returns current slide element + */ + el.getCurrentSlideElement = function(){ + return slider.children.eq(slider.active.index); + }; + + /** + * Returns number of slides in show + */ + el.getSlideCount = function(){ + return slider.children.length; + }; + + /** + * Update all dynamic slider elements + */ + el.redrawSlider = function(){ + // resize all children in ratio to new screen size + slider.children.add(el.find('.bx-clone')).outerWidth(getSlideWidth()); + // adjust the height + slider.viewport.css('height', getViewportHeight()); + // update the slide position + if(!slider.settings.ticker) { setSlidePosition(); } + // if active.last was true before the screen resize, we want + // to keep it last no matter what screen size we end on + if (slider.active.last) { slider.active.index = getPagerQty() - 1; } + // if the active index (page) no longer exists due to the resize, simply set the index as last + if (slider.active.index >= getPagerQty()) { slider.active.last = true; } + // if a pager is being displayed and a custom pager is not being used, update it + if(slider.settings.pager && !slider.settings.pagerCustom){ + populatePager(); + updatePagerActive(slider.active.index); + } + }; + + /** + * Destroy the current instance of the slider (revert everything back to original state) + */ + el.destroySlider = function(){ + // don't do anything if slider has already been destroyed + if(!slider.initialized){ return; } + slider.initialized = false; + $('.bx-clone', this).remove(); + slider.children.each(function(){ + if($(this).data("origStyle") !== undefined){ + $(this).attr("style", $(this).data("origStyle")); + } else { + $(this).removeAttr('style'); + } + }); + if($(this).data("origStyle") !== undefined){ + this.attr("style", $(this).data("origStyle")); + } else { + $(this).removeAttr('style'); + } + $(this).unwrap().unwrap(); + if(slider.controls.el){ slider.controls.el.remove(); } + if(slider.controls.next){ slider.controls.next.remove(); } + if(slider.controls.prev){ slider.controls.prev.remove(); } + if(slider.pagerEl && slider.settings.controls && !slider.settings.pagerCustom){ slider.pagerEl.remove(); } + $('.bx-caption', this).remove(); + if(slider.controls.autoEl){ slider.controls.autoEl.remove(); } + clearInterval(slider.interval); + if(slider.settings.responsive){ $(window).unbind('resize', resizeWindow); } + }; + + /** + * Reload the slider (revert all DOM changes, and re-initialize) + */ + el.reloadSlider = function(settings){ + if(settings !== undefined){ options = settings; } + el.destroySlider(); + init(); + }; + + init(); + + // returns the current jQuery object + return this; + }; + +})(jQuery); diff --git a/dist/jquery.bxslider.min.js b/dist/jquery.bxslider.min.js index fd8af7b9..9c97e535 100644 --- a/dist/jquery.bxslider.min.js +++ b/dist/jquery.bxslider.min.js @@ -1 +1,10 @@ -!function(t){var e={},s={mode:"horizontal",slideSelector:"",infiniteLoop:!0,hideControlOnEnd:!1,speed:500,easing:null,slideMargin:0,startSlide:0,randomStart:!1,captions:!1,ticker:!1,tickerHover:!1,adaptiveHeight:!1,adaptiveHeightSpeed:500,video:!1,useCSS:!0,preloadImages:"visible",responsive:!0,slideZIndex:50,wrapperClass:"bx-wrapper",touchEnabled:!0,swipeThreshold:50,oneToOneTouch:!0,preventDefaultSwipeX:!0,preventDefaultSwipeY:!1,pager:!0,pagerType:"full",pagerShortSeparator:" / ",pagerSelector:null,buildPager:null,pagerCustom:null,controls:!0,nextText:"Next",prevText:"Prev",nextSelector:null,prevSelector:null,autoControls:!1,startText:"Start",stopText:"Stop",autoControlsCombine:!1,autoControlsSelector:null,auto:!1,pause:4e3,autoStart:!0,autoDirection:"next",autoHover:!1,autoDelay:0,autoSlideForOnePage:!1,minSlides:1,maxSlides:1,moveSlides:0,slideWidth:0,onSliderLoad:function(){},onSlideBefore:function(){},onSlideAfter:function(){},onSlideNext:function(){},onSlidePrev:function(){},onSliderResize:function(){}};t.fn.bxSlider=function(n){if(0===this.length)return this;if(this.length>1)return this.each(function(){t(this).bxSlider(n)}),this;var o={},r=this;e.el=this;var a=t(window).width(),l=t(window).height(),d=function(){o.settings=t.extend({},s,n),o.settings.slideWidth=parseInt(o.settings.slideWidth),o.children=r.children(o.settings.slideSelector),o.children.length1||o.settings.maxSlides>1?!1:!0,o.carousel&&(o.settings.preloadImages="all"),o.minThreshold=o.settings.minSlides*o.settings.slideWidth+(o.settings.minSlides-1)*o.settings.slideMargin,o.maxThreshold=o.settings.maxSlides*o.settings.slideWidth+(o.settings.maxSlides-1)*o.settings.slideMargin,o.working=!1,o.controls={},o.interval=null,o.animProp="vertical"===o.settings.mode?"top":"left",o.usingCSS=o.settings.useCSS&&"fade"!==o.settings.mode&&function(){var t=document.createElement("div"),e=["WebkitPerspective","MozPerspective","OPerspective","msPerspective"];for(var i in e)if(void 0!==t.style[e[i]])return o.cssPrefix=e[i].replace("Perspective","").toLowerCase(),o.animProp="-"+o.cssPrefix+"-transform",!0;return!1}(),"vertical"===o.settings.mode&&(o.settings.maxSlides=o.settings.minSlides),r.data("origStyle",r.attr("style")),r.children(o.settings.slideSelector).each(function(){t(this).data("origStyle",t(this).attr("style"))}),c()},c=function(){r.wrap('
'),o.viewport=r.parent(),o.loader=t('
'),o.viewport.prepend(o.loader),r.css({width:"horizontal"===o.settings.mode?1e3*o.children.length+215+"%":"auto",position:"absolute"}),o.usingCSS&&o.settings.easing?r.css("-"+o.cssPrefix+"-transition-timing-function",o.settings.easing):o.settings.easing||(o.settings.easing="swing");f();o.viewport.css({width:"100%",overflow:"hidden",position:"relative"}),o.viewport.parent().css({maxWidth:u()}),o.settings.pager||o.viewport.parent().css({margin:"0 auto 0px"}),o.children.css({"float":"horizontal"===o.settings.mode?"left":"none",listStyle:"none",position:"relative"}),o.children.css("width",v()),"horizontal"===o.settings.mode&&o.settings.slideMargin>0&&o.children.css("marginRight",o.settings.slideMargin),"vertical"===o.settings.mode&&o.settings.slideMargin>0&&o.children.css("marginBottom",o.settings.slideMargin),"fade"===o.settings.mode&&(o.children.css({position:"absolute",zIndex:0,display:"none"}),o.children.eq(o.settings.startSlide).css({zIndex:o.settings.slideZIndex,display:"block"})),o.controls.el=t('
'),o.settings.captions&&P(),o.active.last=o.settings.startSlide===x()-1,o.settings.video&&r.fitVids();var e=o.children.eq(o.settings.startSlide);"all"===o.settings.preloadImages&&(e=o.children),o.settings.ticker?o.settings.pager=!1:(o.settings.controls&&C(),o.settings.auto&&o.settings.autoControls&&E(),o.settings.pager&&T(),(o.settings.controls||o.settings.autoControls||o.settings.pager)&&o.viewport.after(o.controls.el)),g(e,p)},g=function(e,i){var s=e.find("img, iframe").length;if(0===s)return void i();var n=0;e.find("img, iframe").each(function(){t(this).one("load",function(){++n===s&&i()}).each(function(){this.complete&&t(this).load()})})},p=function(){if(o.settings.infiniteLoop&&"fade"!==o.settings.mode&&!o.settings.ticker){var e="vertical"===o.settings.mode?o.settings.minSlides:o.settings.maxSlides,i=o.children.slice(0,e).clone(!0).addClass("bx-clone"),s=o.children.slice(-e).clone(!0).addClass("bx-clone");r.append(i).prepend(s)}o.loader.remove(),S(),"vertical"===o.settings.mode&&(o.settings.adaptiveHeight=!0),o.viewport.height(h()),r.redrawSlider(),o.settings.onSliderLoad(o.active.index),o.initialized=!0,o.settings.responsive&&t(window).bind("resize",V),o.settings.auto&&o.settings.autoStart&&(x()>1||o.settings.autoSlideForOnePage)&&H(),o.settings.ticker&&L(),o.settings.pager&&q(o.settings.startSlide),o.settings.controls&&A(),o.settings.touchEnabled&&!o.settings.ticker&&N()},h=function(){var e=0,s=t();if("vertical"===o.settings.mode||o.settings.adaptiveHeight)if(o.carousel){var n=1===o.settings.moveSlides?o.active.index:o.active.index*m();for(s=o.children.eq(n),i=1;i<=o.settings.maxSlides-1;i++)s=s.add(n+i>=o.children.length?o.children.eq(i-1):o.children.eq(n+i))}else s=o.children.eq(o.active.index);else s=o.children;return"vertical"===o.settings.mode?(s.each(function(){e+=t(this).outerHeight()}),o.settings.slideMargin>0&&(e+=o.settings.slideMargin*(o.settings.minSlides-1))):e=Math.max.apply(Math,s.map(function(){return t(this).outerHeight(!1)}).get()),"border-box"===o.viewport.css("box-sizing")?e+=parseFloat(o.viewport.css("padding-top"))+parseFloat(o.viewport.css("padding-bottom"))+parseFloat(o.viewport.css("border-top-width"))+parseFloat(o.viewport.css("border-bottom-width")):"padding-box"===o.viewport.css("box-sizing")&&(e+=parseFloat(o.viewport.css("padding-top"))+parseFloat(o.viewport.css("padding-bottom"))),e},u=function(){var t="100%";return o.settings.slideWidth>0&&(t="horizontal"===o.settings.mode?o.settings.maxSlides*o.settings.slideWidth+(o.settings.maxSlides-1)*o.settings.slideMargin:o.settings.slideWidth),t},v=function(){var t=o.settings.slideWidth,e=o.viewport.width();return 0===o.settings.slideWidth||o.settings.slideWidth>e&&!o.carousel||"vertical"===o.settings.mode?t=e:o.settings.maxSlides>1&&"horizontal"===o.settings.mode&&(e>o.maxThreshold||e0)if(o.viewport.width()o.maxThreshold)t=o.settings.maxSlides;else{var e=o.children.first().width()+o.settings.slideMargin;t=Math.floor((o.viewport.width()+o.settings.slideMargin)/e)}else"vertical"===o.settings.mode&&(t=o.settings.minSlides);return t},x=function(){var t=0;if(o.settings.moveSlides>0)if(o.settings.infiniteLoop)t=Math.ceil(o.children.length/m());else for(var e=0,i=0;e0&&o.settings.moveSlides<=f()?o.settings.moveSlides:f()},S=function(){var t;if(o.children.length>o.settings.maxSlides&&o.active.last&&!o.settings.infiniteLoop){if("horizontal"===o.settings.mode){var e=o.children.last();t=e.position(),b(-(t.left-(o.viewport.width()-e.outerWidth())),"reset",0)}else if("vertical"===o.settings.mode){var i=o.children.length-o.settings.minSlides;t=o.children.eq(i).position(),b(-t.top,"reset",0)}}else t=o.children.eq(o.active.index*m()).position(),o.active.index===x()-1&&(o.active.last=!0),void 0!==t&&("horizontal"===o.settings.mode?b(-t.left,"reset",0):"vertical"===o.settings.mode&&b(-t.top,"reset",0))},b=function(t,e,i,s){if(o.usingCSS){var n="vertical"===o.settings.mode?"translate3d(0, "+t+"px, 0)":"translate3d("+t+"px, 0, 0)";r.css("-"+o.cssPrefix+"-transition-duration",i/1e3+"s"),"slide"===e?(r.css(o.animProp,n),r.bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){r.unbind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd"),D()})):"reset"===e?r.css(o.animProp,n):"ticker"===e&&(r.css("-"+o.cssPrefix+"-transition-timing-function","linear"),r.css(o.animProp,n),r.bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){r.unbind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd"),b(s.resetValue,"reset",0),F()}))}else{var a={};a[o.animProp]=t,"slide"===e?r.animate(a,i,o.settings.easing,function(){D()}):"reset"===e?r.css(o.animProp,t):"ticker"===e&&r.animate(a,speed,"linear",function(){b(s.resetValue,"reset",0),F()})}},w=function(){for(var e="",i=x(),s=0;i>s;s++){var n="";o.settings.buildPager&&t.isFunction(o.settings.buildPager)||o.settings.pagerCustom?(n=o.settings.buildPager(s),o.pagerEl.addClass("bx-custom-pager")):(n=s+1,o.pagerEl.addClass("bx-default-pager")),e+='"}o.pagerEl.html(e)},T=function(){o.settings.pagerCustom?o.pagerEl=t(o.settings.pagerCustom):(o.pagerEl=t('
'),o.settings.pagerSelector?t(o.settings.pagerSelector).html(o.pagerEl):o.controls.el.addClass("bx-has-pager").append(o.pagerEl),w()),o.pagerEl.on("click","a",I)},C=function(){o.controls.next=t(''+o.settings.nextText+""),o.controls.prev=t(''+o.settings.prevText+""),o.controls.next.bind("click",z),o.controls.prev.bind("click",y),o.settings.nextSelector&&t(o.settings.nextSelector).append(o.controls.next),o.settings.prevSelector&&t(o.settings.prevSelector).append(o.controls.prev),o.settings.nextSelector||o.settings.prevSelector||(o.controls.directionEl=t('
'),o.controls.directionEl.append(o.controls.prev).append(o.controls.next),o.controls.el.addClass("bx-has-controls-direction").append(o.controls.directionEl))},E=function(){o.controls.start=t('"),o.controls.stop=t('"),o.controls.autoEl=t('
'),o.controls.autoEl.on("click",".bx-start",M),o.controls.autoEl.on("click",".bx-stop",k),o.settings.autoControlsCombine?o.controls.autoEl.append(o.controls.start):o.controls.autoEl.append(o.controls.start).append(o.controls.stop),o.settings.autoControlsSelector?t(o.settings.autoControlsSelector).html(o.controls.autoEl):o.controls.el.addClass("bx-has-controls-auto").append(o.controls.autoEl),W(o.settings.autoStart?"stop":"start")},P=function(){o.children.each(function(){var e=t(this).find("img:first").attr("title");void 0!==e&&(""+e).length&&t(this).append('
'+e+"
")})},z=function(t){o.settings.auto&&r.stopAuto(),r.goToNextSlide(),t.preventDefault()},y=function(t){o.settings.auto&&r.stopAuto(),r.goToPrevSlide(),t.preventDefault()},M=function(t){r.startAuto(),t.preventDefault()},k=function(t){r.stopAuto(),t.preventDefault()},I=function(e){o.settings.auto&&r.stopAuto();var i=t(e.currentTarget);if(void 0!==i.attr("data-slide-index")){var s=parseInt(i.attr("data-slide-index"));s!==o.active.index&&r.goToSlide(s),e.preventDefault()}},q=function(e){var i=o.children.length;return"short"===o.settings.pagerType?(o.settings.maxSlides>1&&(i=Math.ceil(o.children.length/o.settings.maxSlides)),void o.pagerEl.html(e+1+o.settings.pagerShortSeparator+i)):(o.pagerEl.find("a").removeClass("active"),void o.pagerEl.each(function(i,s){t(s).find("a").eq(e).addClass("active")}))},D=function(){if(o.settings.infiniteLoop){var t="";0===o.active.index?t=o.children.eq(0).position():o.active.index===x()-1&&o.carousel?t=o.children.eq((x()-1)*m()).position():o.active.index===o.children.length-1&&(t=o.children.eq(o.children.length-1).position()),t&&("horizontal"===o.settings.mode?b(-t.left,"reset",0):"vertical"===o.settings.mode&&b(-t.top,"reset",0))}o.working=!1,o.settings.onSlideAfter(o.children.eq(o.active.index),o.oldIndex,o.active.index)},W=function(t){o.settings.autoControlsCombine?o.controls.autoEl.html(o.controls[t]):(o.controls.autoEl.find("a").removeClass("active"),o.controls.autoEl.find("a:not(.bx-"+t+")").addClass("active"))},A=function(){1===x()?(o.controls.prev.addClass("disabled"),o.controls.next.addClass("disabled")):!o.settings.infiniteLoop&&o.settings.hideControlOnEnd&&(0===o.active.index?(o.controls.prev.addClass("disabled"),o.controls.next.removeClass("disabled")):o.active.index===x()-1?(o.controls.next.addClass("disabled"),o.controls.prev.removeClass("disabled")):(o.controls.prev.removeClass("disabled"),o.controls.next.removeClass("disabled")))},H=function(){if(o.settings.autoDelay>0){setTimeout(r.startAuto,o.settings.autoDelay)}else r.startAuto();o.settings.autoHover&&r.hover(function(){o.interval&&(r.stopAuto(!0),o.autoPaused=!0)},function(){o.autoPaused&&(r.startAuto(!0),o.autoPaused=null)})},L=function(){var e=0;if("next"===o.settings.autoDirection)r.append(o.children.clone().addClass("bx-clone"));else{r.prepend(o.children.clone().addClass("bx-clone"));var i=o.children.first().position();e="horizontal"===o.settings.mode?-i.left:-i.top}b(e,"reset",0),o.settings.pager=!1,o.settings.controls=!1,o.settings.autoControls=!1,o.settings.tickerHover&&!o.usingCSS&&o.viewport.hover(function(){r.stop()},function(){var e=0;o.children.each(function(){e+="horizontal"===o.settings.mode?t(this).outerWidth(!0):t(this).outerHeight(!0)});var i=o.settings.speed/e,s="horizontal"===o.settings.mode?"left":"top",n=i*(e-Math.abs(parseInt(r.css(s))));F(n)}),F()},F=function(t){speed=t?t:o.settings.speed;var e={left:0,top:0},i={left:0,top:0};"next"===o.settings.autoDirection?e=r.find(".bx-clone").first().position():i=o.children.first().position();var s="horizontal"===o.settings.mode?-e.left:-e.top,n="horizontal"===o.settings.mode?-i.left:-i.top,a={resetValue:n};b(s,"ticker",speed,a)},N=function(){o.touch={start:{x:0,y:0},end:{x:0,y:0}},o.viewport.bind("touchstart",O)},O=function(t){if(o.working)t.preventDefault();else{o.touch.originalPos=r.position();var e=t.originalEvent;o.touch.start.x=e.changedTouches[0].pageX,o.touch.start.y=e.changedTouches[0].pageY,o.viewport.bind("touchmove",X),o.viewport.bind("touchend",Y)}},X=function(t){var e=t.originalEvent,i=Math.abs(e.changedTouches[0].pageX-o.touch.start.x),s=Math.abs(e.changedTouches[0].pageY-o.touch.start.y);if(3*i>s&&o.settings.preventDefaultSwipeX?t.preventDefault():3*s>i&&o.settings.preventDefaultSwipeY&&t.preventDefault(),"fade"!==o.settings.mode&&o.settings.oneToOneTouch){var n=0,r=0;"horizontal"===o.settings.mode?(r=e.changedTouches[0].pageX-o.touch.start.x,n=o.touch.originalPos.left+r):(r=e.changedTouches[0].pageY-o.touch.start.y,n=o.touch.originalPos.top+r),b(n,"reset",0)}},Y=function(t){o.viewport.unbind("touchmove",X);var e=t.originalEvent,i=0,s=0;o.touch.end.x=e.changedTouches[0].pageX,o.touch.end.y=e.changedTouches[0].pageY,"fade"===o.settings.mode?(s=Math.abs(o.touch.start.x-o.touch.end.x),s>=o.settings.swipeThreshold&&(o.touch.start.x>o.touch.end.x?r.goToNextSlide():r.goToPrevSlide(),r.stopAuto())):("horizontal"===o.settings.mode?(s=o.touch.end.x-o.touch.start.x,i=o.touch.originalPos.left):(s=o.touch.end.y-o.touch.start.y,i=o.touch.originalPos.top),!o.settings.infiniteLoop&&(0===o.active.index&&s>0||o.active.last&&0>s)?b(i,"reset",200):Math.abs(s)>=o.settings.swipeThreshold?(0>s?r.goToNextSlide():r.goToPrevSlide(),r.stopAuto()):b(i,"reset",200)),o.viewport.unbind("touchend",Y)},V=function(){if(o.initialized){var e=t(window).width(),i=t(window).height();(a!==e||l!==i)&&(a=e,l=i,r.redrawSlider(),o.settings.onSliderResize.call(r,o.active.index))}};return r.goToSlide=function(e,i){if(!o.working&&o.active.index!==e)if(o.working=!0,o.oldIndex=o.active.index,o.active.index=0>e?x()-1:e>=x()?0:e,o.settings.onSlideBefore(o.children.eq(o.active.index),o.oldIndex,o.active.index),"next"===i?o.settings.onSlideNext(o.children.eq(o.active.index),o.oldIndex,o.active.index):"prev"===i&&o.settings.onSlidePrev(o.children.eq(o.active.index),o.oldIndex,o.active.index),o.active.last=o.active.index>=x()-1,(o.settings.pager||o.settings.pagerCustom)&&q(o.active.index),o.settings.controls&&A(),"fade"===o.settings.mode)o.settings.adaptiveHeight&&o.viewport.height()!==h()&&o.viewport.animate({height:h()},o.settings.adaptiveHeightSpeed),o.children.filter(":visible").fadeOut(o.settings.speed).css({zIndex:0}),o.children.eq(o.active.index).css("zIndex",o.settings.slideZIndex+1).fadeIn(o.settings.speed,function(){t(this).css("zIndex",o.settings.slideZIndex),D()});else{o.settings.adaptiveHeight&&o.viewport.height()!==h()&&o.viewport.animate({height:h()},o.settings.adaptiveHeightSpeed);var s=0,n={left:0,top:0},a=null;if(!o.settings.infiniteLoop&&o.carousel&&o.active.last)if("horizontal"===o.settings.mode)a=o.children.eq(o.children.length-1),n=a.position(),s=o.viewport.width()-a.outerWidth();else{var l=o.children.length-o.settings.minSlides;n=o.children.eq(l).position()}else if(o.carousel&&o.active.last&&"prev"===i){var d=1===o.settings.moveSlides?o.settings.maxSlides-m():(x()-1)*m()-(o.children.length-o.settings.maxSlides);a=r.children(".bx-clone").eq(d),n=a.position()}else if("next"===i&&0===o.active.index)n=r.find("> .bx-clone").eq(o.settings.maxSlides).position(),o.active.last=!1;else if(e>=0){var c=e*m();n=o.children.eq(c).position()}if("undefined"!=typeof n){var g="horizontal"===o.settings.mode?-(n.left-s):-n.top;b(g,"slide",o.settings.speed)}}},r.goToNextSlide=function(){if(o.settings.infiniteLoop||!o.active.last){var t=parseInt(o.active.index)+1;r.goToSlide(t,"next")}},r.goToPrevSlide=function(){if(o.settings.infiniteLoop||0!==o.active.index){var t=parseInt(o.active.index)-1;r.goToSlide(t,"prev")}},r.startAuto=function(t){o.interval||(o.interval=setInterval(function(){"next"===o.settings.autoDirection?r.goToNextSlide():r.goToPrevSlide()},o.settings.pause),o.settings.autoControls&&t!==!0&&W("stop"))},r.stopAuto=function(t){o.interval&&(clearInterval(o.interval),o.interval=null,o.settings.autoControls&&t!==!0&&W("start"))},r.getCurrentSlide=function(){return o.active.index},r.getCurrentSlideElement=function(){return o.children.eq(o.active.index)},r.getSlideCount=function(){return o.children.length},r.redrawSlider=function(){o.children.add(r.find(".bx-clone")).outerWidth(v()),o.viewport.css("height",h()),o.settings.ticker||S(),o.active.last&&(o.active.index=x()-1),o.active.index>=x()&&(o.active.last=!0),o.settings.pager&&!o.settings.pagerCustom&&(w(),q(o.active.index))},r.destroySlider=function(){o.initialized&&(o.initialized=!1,t(".bx-clone",this).remove(),o.children.each(function(){void 0!==t(this).data("origStyle")?t(this).attr("style",t(this).data("origStyle")):t(this).removeAttr("style")}),void 0!==t(this).data("origStyle")?this.attr("style",t(this).data("origStyle")):t(this).removeAttr("style"),t(this).unwrap().unwrap(),o.controls.el&&o.controls.el.remove(),o.controls.next&&o.controls.next.remove(),o.controls.prev&&o.controls.prev.remove(),o.pagerEl&&o.settings.controls&&!o.settings.pagerCustom&&o.pagerEl.remove(),t(".bx-caption",this).remove(),o.controls.autoEl&&o.controls.autoEl.remove(),clearInterval(o.interval),o.settings.responsive&&t(window).unbind("resize",V))},r.reloadSlider=function(t){void 0!==t&&(n=t),r.destroySlider(),d()},d(),this}}(jQuery); \ No newline at end of file +/*** + * BxSlider v4.2.0 - Fully loaded, responsive content slider + * http://bxslider.com + * + * Copyright 2014, Steven Wanderski - http://stevenwanderski.com - http://bxcreative.com + * Written while drinking Belgian ales and listening to jazz + * + * Released under the MIT license - http://opensource.org/licenses/MIT + ***/ +!function(t){var e={},s={mode:"horizontal",slideSelector:"",infiniteLoop:!0,hideControlOnEnd:!1,speed:500,easing:null,slideMargin:0,startSlide:0,randomStart:!1,captions:!1,ticker:!1,tickerHover:!1,adaptiveHeight:!1,adaptiveHeightSpeed:500,video:!1,useCSS:!0,preloadImages:"visible",responsive:!0,slideZIndex:50,wrapperClass:"bx-wrapper",touchEnabled:!0,swipeThreshold:50,oneToOneTouch:!0,preventDefaultSwipeX:!0,preventDefaultSwipeY:!1,pager:!0,pagerType:"full",pagerShortSeparator:" / ",pagerSelector:null,buildPager:null,pagerCustom:null,controls:!0,nextText:"Next",prevText:"Prev",nextSelector:null,prevSelector:null,autoControls:!1,startText:"Start",stopText:"Stop",autoControlsCombine:!1,autoControlsSelector:null,auto:!1,pause:4e3,autoStart:!0,autoDirection:"next",autoHover:!1,autoDelay:0,autoSlideForOnePage:!1,minSlides:1,maxSlides:1,moveSlides:0,slideWidth:0,onSliderLoad:function(){},onSlideBefore:function(){},onSlideAfter:function(){},onSlideNext:function(){},onSlidePrev:function(){},onSliderResize:function(){}};t.fn.bxSlider=function(n){if(0===this.length)return this;if(this.length>1)return this.each(function(){t(this).bxSlider(n)}),this;var o={},r=this;e.el=this;var a=t(window).width(),l=t(window).height(),d=function(){o.settings=t.extend({},s,n),o.settings.slideWidth=parseInt(o.settings.slideWidth),o.children=r.children(o.settings.slideSelector),o.children.length1||o.settings.maxSlides>1?!1:!0,o.carousel&&(o.settings.preloadImages="all"),o.minThreshold=o.settings.minSlides*o.settings.slideWidth+(o.settings.minSlides-1)*o.settings.slideMargin,o.maxThreshold=o.settings.maxSlides*o.settings.slideWidth+(o.settings.maxSlides-1)*o.settings.slideMargin,o.working=!1,o.controls={},o.interval=null,o.animProp="vertical"===o.settings.mode?"top":"left",o.usingCSS=o.settings.useCSS&&"fade"!==o.settings.mode&&function(){var t=document.createElement("div"),e=["WebkitPerspective","MozPerspective","OPerspective","msPerspective"];for(var i in e)if(void 0!==t.style[e[i]])return o.cssPrefix=e[i].replace("Perspective","").toLowerCase(),o.animProp="-"+o.cssPrefix+"-transform",!0;return!1}(),"vertical"===o.settings.mode&&(o.settings.maxSlides=o.settings.minSlides),r.data("origStyle",r.attr("style")),r.children(o.settings.slideSelector).each(function(){t(this).data("origStyle",t(this).attr("style"))}),c()},c=function(){r.wrap('
'),o.viewport=r.parent(),o.loader=t('
'),o.viewport.prepend(o.loader),r.css({width:"horizontal"===o.settings.mode?1e3*o.children.length+215+"%":"auto",position:"relative"}),o.usingCSS&&o.settings.easing?r.css("-"+o.cssPrefix+"-transition-timing-function",o.settings.easing):o.settings.easing||(o.settings.easing="swing");f();o.viewport.css({width:"100%",overflow:"hidden",position:"relative"}),o.viewport.parent().css({maxWidth:v()}),o.settings.pager||o.viewport.parent().css({margin:"0 auto 0px"}),o.children.css({"float":"horizontal"===o.settings.mode?"left":"none",listStyle:"none",position:"relative"}),o.children.css("width",u()),"horizontal"===o.settings.mode&&o.settings.slideMargin>0&&o.children.css("marginRight",o.settings.slideMargin),"vertical"===o.settings.mode&&o.settings.slideMargin>0&&o.children.css("marginBottom",o.settings.slideMargin),"fade"===o.settings.mode&&(o.children.css({position:"absolute",zIndex:0,display:"none"}),o.children.eq(o.settings.startSlide).css({zIndex:o.settings.slideZIndex,display:"block"})),o.controls.el=t('
'),o.settings.captions&&P(),o.active.last=o.settings.startSlide===x()-1,o.settings.video&&r.fitVids();var e=o.children.eq(o.settings.startSlide);"all"===o.settings.preloadImages&&(e=o.children),o.settings.ticker?o.settings.pager=!1:(o.settings.controls&&C(),o.settings.auto&&o.settings.autoControls&&E(),o.settings.pager&&T(),(o.settings.controls||o.settings.autoControls||o.settings.pager)&&o.viewport.after(o.controls.el)),g(e,p)},g=function(e,i){var s=e.find("img, iframe").length;if(0===s)return void i();var n=0;e.find("img, iframe").each(function(){t(this).one("load",function(){++n===s&&i()}).each(function(){this.complete&&t(this).load()})})},p=function(){if(o.settings.infiniteLoop&&"fade"!==o.settings.mode&&!o.settings.ticker){var e="vertical"===o.settings.mode?o.settings.minSlides:o.settings.maxSlides,i=o.children.slice(0,e).clone(!0).addClass("bx-clone"),s=o.children.slice(-e).clone(!0).addClass("bx-clone");r.append(i).prepend(s)}o.loader.remove(),S(),"vertical"===o.settings.mode&&(o.settings.adaptiveHeight=!0),o.viewport.height(h()),r.redrawSlider(),o.settings.onSliderLoad(o.active.index),o.initialized=!0,o.settings.responsive&&t(window).bind("resize",V),o.settings.auto&&o.settings.autoStart&&(x()>1||o.settings.autoSlideForOnePage)&&H(),o.settings.ticker&&L(),o.settings.pager&&q(o.settings.startSlide),o.settings.controls&&A(),o.settings.touchEnabled&&!o.settings.ticker&&N()},h=function(){var e=0,s=t();if("vertical"===o.settings.mode||o.settings.adaptiveHeight)if(o.carousel){var n=1===o.settings.moveSlides?o.active.index:o.active.index*m();for(s=o.children.eq(n),i=1;i<=o.settings.maxSlides-1;i++)s=s.add(n+i>=o.children.length?o.children.eq(i-1):o.children.eq(n+i))}else s=o.children.eq(o.active.index);else s=o.children;return"vertical"===o.settings.mode?(s.each(function(){e+=t(this).outerHeight()}),o.settings.slideMargin>0&&(e+=o.settings.slideMargin*(o.settings.minSlides-1))):e=Math.max.apply(Math,s.map(function(){return t(this).outerHeight(!1)}).get()),"border-box"===o.viewport.css("box-sizing")?e+=parseFloat(o.viewport.css("padding-top"))+parseFloat(o.viewport.css("padding-bottom"))+parseFloat(o.viewport.css("border-top-width"))+parseFloat(o.viewport.css("border-bottom-width")):"padding-box"===o.viewport.css("box-sizing")&&(e+=parseFloat(o.viewport.css("padding-top"))+parseFloat(o.viewport.css("padding-bottom"))),e},v=function(){var t="100%";return o.settings.slideWidth>0&&(t="horizontal"===o.settings.mode?o.settings.maxSlides*o.settings.slideWidth+(o.settings.maxSlides-1)*o.settings.slideMargin:o.settings.slideWidth),t},u=function(){var t=o.settings.slideWidth,e=o.viewport.width();return 0===o.settings.slideWidth||o.settings.slideWidth>e&&!o.carousel||"vertical"===o.settings.mode?t=e:o.settings.maxSlides>1&&"horizontal"===o.settings.mode&&(e>o.maxThreshold||e0)if(o.viewport.width()o.maxThreshold)t=o.settings.maxSlides;else{var e=o.children.first().width()+o.settings.slideMargin;t=Math.floor((o.viewport.width()+o.settings.slideMargin)/e)}else"vertical"===o.settings.mode&&(t=o.settings.minSlides);return t},x=function(){var t=0;if(o.settings.moveSlides>0)if(o.settings.infiniteLoop)t=Math.ceil(o.children.length/m());else for(var e=0,i=0;e0&&o.settings.moveSlides<=f()?o.settings.moveSlides:f()},S=function(){var t;if(o.children.length>o.settings.maxSlides&&o.active.last&&!o.settings.infiniteLoop){if("horizontal"===o.settings.mode){var e=o.children.last();t=e.position(),b(-(t.left-(o.viewport.width()-e.outerWidth())),"reset",0)}else if("vertical"===o.settings.mode){var i=o.children.length-o.settings.minSlides;t=o.children.eq(i).position(),b(-t.top,"reset",0)}}else t=o.children.eq(o.active.index*m()).position(),o.active.index===x()-1&&(o.active.last=!0),void 0!==t&&("horizontal"===o.settings.mode?b(-t.left,"reset",0):"vertical"===o.settings.mode&&b(-t.top,"reset",0))},b=function(t,e,i,s){if(o.usingCSS){var n="vertical"===o.settings.mode?"translate3d(0, "+t+"px, 0)":"translate3d("+t+"px, 0, 0)";r.css("-"+o.cssPrefix+"-transition-duration",i/1e3+"s"),"slide"===e?(r.css(o.animProp,n),r.bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){r.unbind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd"),D()})):"reset"===e?r.css(o.animProp,n):"ticker"===e&&(r.css("-"+o.cssPrefix+"-transition-timing-function","linear"),r.css(o.animProp,n),r.bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",function(){r.unbind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd"),b(s.resetValue,"reset",0),F()}))}else{var a={};a[o.animProp]=t,"slide"===e?r.animate(a,i,o.settings.easing,function(){D()}):"reset"===e?r.css(o.animProp,t):"ticker"===e&&r.animate(a,speed,"linear",function(){b(s.resetValue,"reset",0),F()})}},w=function(){for(var e="",i=x(),s=0;i>s;s++){var n="";o.settings.buildPager&&t.isFunction(o.settings.buildPager)||o.settings.pagerCustom?(n=o.settings.buildPager(s),o.pagerEl.addClass("bx-custom-pager")):(n=s+1,o.pagerEl.addClass("bx-default-pager")),e+='"}o.pagerEl.html(e)},T=function(){o.settings.pagerCustom?o.pagerEl=t(o.settings.pagerCustom):(o.pagerEl=t('
'),o.settings.pagerSelector?t(o.settings.pagerSelector).html(o.pagerEl):o.controls.el.addClass("bx-has-pager").append(o.pagerEl),w()),o.pagerEl.on("click","a",I)},C=function(){o.controls.next=t(''+o.settings.nextText+""),o.controls.prev=t(''+o.settings.prevText+""),o.controls.next.bind("click",z),o.controls.prev.bind("click",y),o.settings.nextSelector&&t(o.settings.nextSelector).append(o.controls.next),o.settings.prevSelector&&t(o.settings.prevSelector).append(o.controls.prev),o.settings.nextSelector||o.settings.prevSelector||(o.controls.directionEl=t('
'),o.controls.directionEl.append(o.controls.prev).append(o.controls.next),o.controls.el.addClass("bx-has-controls-direction").append(o.controls.directionEl))},E=function(){o.controls.start=t('"),o.controls.stop=t('"),o.controls.autoEl=t('
'),o.controls.autoEl.on("click",".bx-start",M),o.controls.autoEl.on("click",".bx-stop",k),o.settings.autoControlsCombine?o.controls.autoEl.append(o.controls.start):o.controls.autoEl.append(o.controls.start).append(o.controls.stop),o.settings.autoControlsSelector?t(o.settings.autoControlsSelector).html(o.controls.autoEl):o.controls.el.addClass("bx-has-controls-auto").append(o.controls.autoEl),W(o.settings.autoStart?"stop":"start")},P=function(){o.children.each(function(){var e=t(this).find("img:first").attr("title");void 0!==e&&(""+e).length&&t(this).append('
'+e+"
")})},z=function(t){o.settings.auto&&r.stopAuto(),r.goToNextSlide(),t.preventDefault()},y=function(t){o.settings.auto&&r.stopAuto(),r.goToPrevSlide(),t.preventDefault()},M=function(t){r.startAuto(),t.preventDefault()},k=function(t){r.stopAuto(),t.preventDefault()},I=function(e){o.settings.auto&&r.stopAuto();var i=t(e.currentTarget);if(void 0!==i.attr("data-slide-index")){var s=parseInt(i.attr("data-slide-index"));s!==o.active.index&&r.goToSlide(s),e.preventDefault()}},q=function(e){var i=o.children.length;return"short"===o.settings.pagerType?(o.settings.maxSlides>1&&(i=Math.ceil(o.children.length/o.settings.maxSlides)),void o.pagerEl.html(e+1+o.settings.pagerShortSeparator+i)):(o.pagerEl.find("a").removeClass("active"),void o.pagerEl.each(function(i,s){t(s).find("a").eq(e).addClass("active")}))},D=function(){if(o.settings.infiniteLoop){var t="";0===o.active.index?t=o.children.eq(0).position():o.active.index===x()-1&&o.carousel?t=o.children.eq((x()-1)*m()).position():o.active.index===o.children.length-1&&(t=o.children.eq(o.children.length-1).position()),t&&("horizontal"===o.settings.mode?b(-t.left,"reset",0):"vertical"===o.settings.mode&&b(-t.top,"reset",0))}o.working=!1,o.settings.onSlideAfter(o.children.eq(o.active.index),o.oldIndex,o.active.index)},W=function(t){o.settings.autoControlsCombine?o.controls.autoEl.html(o.controls[t]):(o.controls.autoEl.find("a").removeClass("active"),o.controls.autoEl.find("a:not(.bx-"+t+")").addClass("active"))},A=function(){1===x()?(o.controls.prev.addClass("disabled"),o.controls.next.addClass("disabled")):!o.settings.infiniteLoop&&o.settings.hideControlOnEnd&&(0===o.active.index?(o.controls.prev.addClass("disabled"),o.controls.next.removeClass("disabled")):o.active.index===x()-1?(o.controls.next.addClass("disabled"),o.controls.prev.removeClass("disabled")):(o.controls.prev.removeClass("disabled"),o.controls.next.removeClass("disabled")))},H=function(){if(o.settings.autoDelay>0){setTimeout(r.startAuto,o.settings.autoDelay)}else r.startAuto();o.settings.autoHover&&r.hover(function(){o.interval&&(r.stopAuto(!0),o.autoPaused=!0)},function(){o.autoPaused&&(r.startAuto(!0),o.autoPaused=null)})},L=function(){var e=0;if("next"===o.settings.autoDirection)r.append(o.children.clone().addClass("bx-clone"));else{r.prepend(o.children.clone().addClass("bx-clone"));var i=o.children.first().position();e="horizontal"===o.settings.mode?-i.left:-i.top}b(e,"reset",0),o.settings.pager=!1,o.settings.controls=!1,o.settings.autoControls=!1,o.settings.tickerHover&&!o.usingCSS&&o.viewport.hover(function(){r.stop()},function(){var e=0;o.children.each(function(){e+="horizontal"===o.settings.mode?t(this).outerWidth(!0):t(this).outerHeight(!0)});var i=o.settings.speed/e,s="horizontal"===o.settings.mode?"left":"top",n=i*(e-Math.abs(parseInt(r.css(s))));F(n)}),F()},F=function(t){speed=t?t:o.settings.speed;var e={left:0,top:0},i={left:0,top:0};"next"===o.settings.autoDirection?e=r.find(".bx-clone").first().position():i=o.children.first().position();var s="horizontal"===o.settings.mode?-e.left:-e.top,n="horizontal"===o.settings.mode?-i.left:-i.top,a={resetValue:n};b(s,"ticker",speed,a)},N=function(){o.touch={start:{x:0,y:0},end:{x:0,y:0}},o.viewport.bind("touchstart",O)},O=function(t){if(o.working)t.preventDefault();else{o.touch.originalPos=r.position();var e=t.originalEvent;o.touch.start.x=e.changedTouches[0].pageX,o.touch.start.y=e.changedTouches[0].pageY,o.viewport.bind("touchmove",X),o.viewport.bind("touchend",Y)}},X=function(t){var e=t.originalEvent,i=Math.abs(e.changedTouches[0].pageX-o.touch.start.x),s=Math.abs(e.changedTouches[0].pageY-o.touch.start.y);if(3*i>s&&o.settings.preventDefaultSwipeX?t.preventDefault():3*s>i&&o.settings.preventDefaultSwipeY&&t.preventDefault(),"fade"!==o.settings.mode&&o.settings.oneToOneTouch){var n=0,r=0;"horizontal"===o.settings.mode?(r=e.changedTouches[0].pageX-o.touch.start.x,n=o.touch.originalPos.left+r):(r=e.changedTouches[0].pageY-o.touch.start.y,n=o.touch.originalPos.top+r),b(n,"reset",0)}},Y=function(t){o.viewport.unbind("touchmove",X);var e=t.originalEvent,i=0,s=0;o.touch.end.x=e.changedTouches[0].pageX,o.touch.end.y=e.changedTouches[0].pageY,"fade"===o.settings.mode?(s=Math.abs(o.touch.start.x-o.touch.end.x),s>=o.settings.swipeThreshold&&(o.touch.start.x>o.touch.end.x?r.goToNextSlide():r.goToPrevSlide(),r.stopAuto())):("horizontal"===o.settings.mode?(s=o.touch.end.x-o.touch.start.x,i=o.touch.originalPos.left):(s=o.touch.end.y-o.touch.start.y,i=o.touch.originalPos.top),!o.settings.infiniteLoop&&(0===o.active.index&&s>0||o.active.last&&0>s)?b(i,"reset",200):Math.abs(s)>=o.settings.swipeThreshold?(0>s?r.goToNextSlide():r.goToPrevSlide(),r.stopAuto()):b(i,"reset",200)),o.viewport.unbind("touchend",Y)},V=function(){if(o.initialized){var e=t(window).width(),i=t(window).height();(a!==e||l!==i)&&(a=e,l=i,r.redrawSlider(),o.settings.onSliderResize.call(r,o.active.index))}};return r.goToSlide=function(e,i){if(!o.working&&o.active.index!==e)if(o.working=!0,o.oldIndex=o.active.index,o.active.index=0>e?x()-1:e>=x()?0:e,o.settings.onSlideBefore(o.children.eq(o.active.index),o.oldIndex,o.active.index),"next"===i?o.settings.onSlideNext(o.children.eq(o.active.index),o.oldIndex,o.active.index):"prev"===i&&o.settings.onSlidePrev(o.children.eq(o.active.index),o.oldIndex,o.active.index),o.active.last=o.active.index>=x()-1,(o.settings.pager||o.settings.pagerCustom)&&q(o.active.index),o.settings.controls&&A(),"fade"===o.settings.mode)o.settings.adaptiveHeight&&o.viewport.height()!==h()&&o.viewport.animate({height:h()},o.settings.adaptiveHeightSpeed),o.children.filter(":visible").fadeOut(o.settings.speed).css({zIndex:0}),o.children.eq(o.active.index).css("zIndex",o.settings.slideZIndex+1).fadeIn(o.settings.speed,function(){t(this).css("zIndex",o.settings.slideZIndex),D()});else{o.settings.adaptiveHeight&&o.viewport.height()!==h()&&o.viewport.animate({height:h()},o.settings.adaptiveHeightSpeed);var s=0,n={left:0,top:0},a=null;if(!o.settings.infiniteLoop&&o.carousel&&o.active.last)if("horizontal"===o.settings.mode)a=o.children.eq(o.children.length-1),n=a.position(),s=o.viewport.width()-a.outerWidth();else{var l=o.children.length-o.settings.minSlides;n=o.children.eq(l).position()}else if(o.carousel&&o.active.last&&"prev"===i){var d=1===o.settings.moveSlides?o.settings.maxSlides-m():(x()-1)*m()-(o.children.length-o.settings.maxSlides);a=r.children(".bx-clone").eq(d),n=a.position()}else if("next"===i&&0===o.active.index)n=r.find("> .bx-clone").eq(o.settings.maxSlides).position(),o.active.last=!1;else if(e>=0){var c=e*m();n=o.children.eq(c).position()}if("undefined"!=typeof n){var g="horizontal"===o.settings.mode?-(n.left-s):-n.top;b(g,"slide",o.settings.speed)}}},r.goToNextSlide=function(){if(o.settings.infiniteLoop||!o.active.last){var t=parseInt(o.active.index)+1;r.goToSlide(t,"next")}},r.goToPrevSlide=function(){if(o.settings.infiniteLoop||0!==o.active.index){var t=parseInt(o.active.index)-1;r.goToSlide(t,"prev")}},r.startAuto=function(t){o.interval||(o.interval=setInterval(function(){"next"===o.settings.autoDirection?r.goToNextSlide():r.goToPrevSlide()},o.settings.pause),o.settings.autoControls&&t!==!0&&W("stop"))},r.stopAuto=function(t){o.interval&&(clearInterval(o.interval),o.interval=null,o.settings.autoControls&&t!==!0&&W("start"))},r.getCurrentSlide=function(){return o.active.index},r.getCurrentSlideElement=function(){return o.children.eq(o.active.index)},r.getSlideCount=function(){return o.children.length},r.redrawSlider=function(){o.children.add(r.find(".bx-clone")).outerWidth(u()),o.viewport.css("height",h()),o.settings.ticker||S(),o.active.last&&(o.active.index=x()-1),o.active.index>=x()&&(o.active.last=!0),o.settings.pager&&!o.settings.pagerCustom&&(w(),q(o.active.index))},r.destroySlider=function(){o.initialized&&(o.initialized=!1,t(".bx-clone",this).remove(),o.children.each(function(){void 0!==t(this).data("origStyle")?t(this).attr("style",t(this).data("origStyle")):t(this).removeAttr("style")}),void 0!==t(this).data("origStyle")?this.attr("style",t(this).data("origStyle")):t(this).removeAttr("style"),t(this).unwrap().unwrap(),o.controls.el&&o.controls.el.remove(),o.controls.next&&o.controls.next.remove(),o.controls.prev&&o.controls.prev.remove(),o.pagerEl&&o.settings.controls&&!o.settings.pagerCustom&&o.pagerEl.remove(),t(".bx-caption",this).remove(),o.controls.autoEl&&o.controls.autoEl.remove(),clearInterval(o.interval),o.settings.responsive&&t(window).unbind("resize",V))},r.reloadSlider=function(t){void 0!==t&&(n=t),r.destroySlider(),d()},d(),this}}(jQuery); \ No newline at end of file diff --git a/dist/vendor/jquery.easing.1.3.js b/dist/vendor/jquery.easing.1.3.js new file mode 100644 index 00000000..ef743210 --- /dev/null +++ b/dist/vendor/jquery.easing.1.3.js @@ -0,0 +1,205 @@ +/* + * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ + * + * Uses the built in easing capabilities added In jQuery 1.1 + * to offer multiple easing options + * + * TERMS OF USE - jQuery Easing + * + * Open source under the BSD License. + * + * Copyright © 2008 George McGinley Smith + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the author nor the names of contributors may be used to endorse + * or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +// t: current time, b: begInnIng value, c: change In value, d: duration +jQuery.easing['jswing'] = jQuery.easing['swing']; + +jQuery.extend( jQuery.easing, +{ + def: 'easeOutQuad', + swing: function (x, t, b, c, d) { + //alert(jQuery.easing.default); + return jQuery.easing[jQuery.easing.def](x, t, b, c, d); + }, + easeInQuad: function (x, t, b, c, d) { + return c*(t/=d)*t + b; + }, + easeOutQuad: function (x, t, b, c, d) { + return -c *(t/=d)*(t-2) + b; + }, + easeInOutQuad: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t + b; + return -c/2 * ((--t)*(t-2) - 1) + b; + }, + easeInCubic: function (x, t, b, c, d) { + return c*(t/=d)*t*t + b; + }, + easeOutCubic: function (x, t, b, c, d) { + return c*((t=t/d-1)*t*t + 1) + b; + }, + easeInOutCubic: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t + b; + return c/2*((t-=2)*t*t + 2) + b; + }, + easeInQuart: function (x, t, b, c, d) { + return c*(t/=d)*t*t*t + b; + }, + easeOutQuart: function (x, t, b, c, d) { + return -c * ((t=t/d-1)*t*t*t - 1) + b; + }, + easeInOutQuart: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t*t + b; + return -c/2 * ((t-=2)*t*t*t - 2) + b; + }, + easeInQuint: function (x, t, b, c, d) { + return c*(t/=d)*t*t*t*t + b; + }, + easeOutQuint: function (x, t, b, c, d) { + return c*((t=t/d-1)*t*t*t*t + 1) + b; + }, + easeInOutQuint: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; + return c/2*((t-=2)*t*t*t*t + 2) + b; + }, + easeInSine: function (x, t, b, c, d) { + return -c * Math.cos(t/d * (Math.PI/2)) + c + b; + }, + easeOutSine: function (x, t, b, c, d) { + return c * Math.sin(t/d * (Math.PI/2)) + b; + }, + easeInOutSine: function (x, t, b, c, d) { + return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; + }, + easeInExpo: function (x, t, b, c, d) { + return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; + }, + easeOutExpo: function (x, t, b, c, d) { + return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; + }, + easeInOutExpo: function (x, t, b, c, d) { + if (t==0) return b; + if (t==d) return b+c; + if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; + return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; + }, + easeInCirc: function (x, t, b, c, d) { + return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; + }, + easeOutCirc: function (x, t, b, c, d) { + return c * Math.sqrt(1 - (t=t/d-1)*t) + b; + }, + easeInOutCirc: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; + return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; + }, + easeInElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + }, + easeOutElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; + }, + easeInOutElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; + }, + easeInBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + return c*(t/=d)*t*((s+1)*t - s) + b; + }, + easeOutBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; + }, + easeInOutBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; + return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; + }, + easeInBounce: function (x, t, b, c, d) { + return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b; + }, + easeOutBounce: function (x, t, b, c, d) { + if ((t/=d) < (1/2.75)) { + return c*(7.5625*t*t) + b; + } else if (t < (2/2.75)) { + return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; + } else if (t < (2.5/2.75)) { + return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; + } else { + return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; + } + }, + easeInOutBounce: function (x, t, b, c, d) { + if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b; + return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b; + } +}); + +/* + * + * TERMS OF USE - EASING EQUATIONS + * + * Open source under the BSD License. + * + * Copyright © 2001 Robert Penner + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the author nor the names of contributors may be used to endorse + * or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ \ No newline at end of file diff --git a/dist/vendor/jquery.fitvids.js b/dist/vendor/jquery.fitvids.js new file mode 100644 index 00000000..d464f93f --- /dev/null +++ b/dist/vendor/jquery.fitvids.js @@ -0,0 +1,80 @@ +/*global jQuery */ +/*jshint multistr:true browser:true */ +/*! +* FitVids 1.0 +* +* Copyright 2011, Chris Coyier - http://css-tricks.com + Dave Rupert - http://daverupert.com +* Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/ +* Released under the WTFPL license - http://sam.zoy.org/wtfpl/ +* +* Date: Thu Sept 01 18:00:00 2011 -0500 +*/ + +(function( $ ){ + + "use strict"; + + $.fn.fitVids = function( options ) { + var settings = { + customSelector: null + }; + + var div = document.createElement('div'), + ref = document.getElementsByTagName('base')[0] || document.getElementsByTagName('script')[0]; + + div.className = 'fit-vids-style'; + div.innerHTML = '­'; + + ref.parentNode.insertBefore(div,ref); + + if ( options ) { + $.extend( settings, options ); + } + + return this.each(function(){ + var selectors = [ + "iframe[src*='player.vimeo.com']", + "iframe[src*='www.youtube.com']", + "iframe[src*='www.kickstarter.com']", + "object", + "embed" + ]; + + if (settings.customSelector) { + selectors.push(settings.customSelector); + } + + var $allVideos = $(this).find(selectors.join(',')); + + $allVideos.each(function(){ + var $this = $(this); + if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; } + var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(), + width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(), + aspectRatio = height / width; + if(!$this.attr('id')){ + var videoID = 'fitvid' + Math.floor(Math.random()*999999); + $this.attr('id', videoID); + } + $this.wrap('
').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+"%"); + $this.removeAttr('height').removeAttr('width'); + }); + }); + }; +})( jQuery ); diff --git a/package.json b/package.json new file mode 100644 index 00000000..0b7afcdf --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "bxslider", + "version": "4.2.0", + "author": "Steven Wanderski ", + "homepage": "http://bxslider.com", + "private": true, + "repository": { + "type": "git", + "url": "git://github.com/stevenwanderski/bxslider-4.git" + }, + "bugs": { + "url": "https://github.com/stevenwanderski/bxslider-4/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "http://opensource.org/licenses/MIT" + } + ], + "devDependencies": { + "del": "^1.1.1", + "gulp": "^3.8.10", + "gulp-imagemin": "^2.1.0", + "gulp-jshint": "^1.9.0", + "gulp-less": "^2.0.1", + "gulp-load-plugins": "^0.8.0", + "gulp-pleeease": "^1.1.0", + "gulp-rename": "^1.2.0", + "gulp-uglify": "^1.1.0", + "imagemin-pngcrush": "^4.0.0", + "jshint-stylish": "^1.0.0" + } +} diff --git a/readme.md b/readme.md index 4533d112..29f41146 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -#bxSlider 4.1.3 +#bxSlider 4.2.0 ##The fully-loaded, responsive jQuery content slider ###Why should I use this slider? @@ -561,6 +561,31 @@ slider.destroySlider(); ## Changelog +### Version 4.2.0 +* Fix: Reverse #714, fixes #722. +* Fix: Repo Tag #729 +* Fix: #720 pagerCustom issues + +4.2.0 Introduces a streamlined build process using [gulp](www.gulpjs.com). Along with this new build process the projects folder structure has been changed. You will find a `dist` folder with all assets ready to use, including both minified and unminified versions of the javascript. These assets should be ready to go. In `src` you will find the uncompiled assets, including a new less version of the css for bxslider. This is an important step for bxslider. It will help speed development up and keep work clean. It also paves the way for a big revamp we have planned in the future. + +**Unfamiliar with npm? Don't have node installed?** [Download and install node.js](http://nodejs.org/download/) before proceeding. + +From the command line: + +1. Install [gulp](http://gulpjs.com) globally with `npm install -g gulp` +2. Navigate to the project directory, then run `npm install` + +You now have all the necessary dependencies to run the build process. + +### Available gulp commands + +* `gulp` — Compile and optimize all files to `dist` +* `gulp styles` — Compile css assets only to `dist` +* `gulp scripts` — Compile js assets only to `dist` +* `gulp images` - Run lossless compression on all the images and copy to `dist` +* `gulp jshint` — Checks JS and JSON code for errors based on our .jshintrc settings + + ### Version 4.1.3 * Fix: responsive issue for horizontal mode for issue #611, #714 * Fix: extra space on the left when using fade mode. #715 diff --git a/src/js/jquery.bxslider.js b/src/js/jquery.bxslider.js new file mode 100644 index 00000000..be529fbf --- /dev/null +++ b/src/js/jquery.bxslider.js @@ -0,0 +1,1369 @@ +/*** + * BxSlider v4.2.0 - Fully loaded, responsive content slider + * http://bxslider.com + * + * Copyright 2014, Steven Wanderski - http://stevenwanderski.com - http://bxcreative.com + * Written while drinking Belgian ales and listening to jazz + * + * Released under the MIT license - http://opensource.org/licenses/MIT + ***/ + +;(function($){ + + var plugin = {}; + + var defaults = { + + // GENERAL + mode: 'horizontal', + slideSelector: '', + infiniteLoop: true, + hideControlOnEnd: false, + speed: 500, + easing: null, + slideMargin: 0, + startSlide: 0, + randomStart: false, + captions: false, + ticker: false, + tickerHover: false, + adaptiveHeight: false, + adaptiveHeightSpeed: 500, + video: false, + useCSS: true, + preloadImages: 'visible', + responsive: true, + slideZIndex: 50, + wrapperClass: 'bx-wrapper', + + // TOUCH + touchEnabled: true, + swipeThreshold: 50, + oneToOneTouch: true, + preventDefaultSwipeX: true, + preventDefaultSwipeY: false, + + // PAGER + pager: true, + pagerType: 'full', + pagerShortSeparator: ' / ', + pagerSelector: null, + buildPager: null, + pagerCustom: null, + + // CONTROLS + controls: true, + nextText: 'Next', + prevText: 'Prev', + nextSelector: null, + prevSelector: null, + autoControls: false, + startText: 'Start', + stopText: 'Stop', + autoControlsCombine: false, + autoControlsSelector: null, + + // AUTO + auto: false, + pause: 4000, + autoStart: true, + autoDirection: 'next', + autoHover: false, + autoDelay: 0, + autoSlideForOnePage: false, + + // CAROUSEL + minSlides: 1, + maxSlides: 1, + moveSlides: 0, + slideWidth: 0, + + // CALLBACKS + onSliderLoad: function(){}, + onSlideBefore: function(){}, + onSlideAfter: function(){}, + onSlideNext: function(){}, + onSlidePrev: function(){}, + onSliderResize: function(){} + }; + + $.fn.bxSlider = function(options){ + + if(this.length === 0){ + return this; + } + + // support multiple elements + if(this.length > 1){ + this.each(function(){ + $(this).bxSlider(options); + }); + return this; + } + + // create a namespace to be used throughout the plugin + var slider = {}; + // set a reference to our slider element + var el = this; + plugin.el = this; + + /** + * Makes slideshow responsive + */ + // first get the original window dimens (thanks a lot IE) + var windowWidth = $(window).width(); + var windowHeight = $(window).height(); + + + + /** + * =================================================================================== + * = PRIVATE FUNCTIONS + * =================================================================================== + */ + + /** + * Initializes namespace settings to be used throughout plugin + */ + var init = function(){ + // merge user-supplied options with the defaults + slider.settings = $.extend({}, defaults, options); + // parse slideWidth setting + slider.settings.slideWidth = parseInt(slider.settings.slideWidth); + // store the original children + slider.children = el.children(slider.settings.slideSelector); + // check if actual number of slides is less than minSlides / maxSlides + if(slider.children.length < slider.settings.minSlides){ slider.settings.minSlides = slider.children.length; } + if(slider.children.length < slider.settings.maxSlides){ slider.settings.maxSlides = slider.children.length; } + // if random start, set the startSlide setting to random number + if(slider.settings.randomStart){ slider.settings.startSlide = Math.floor(Math.random() * slider.children.length); } + // store active slide information + slider.active = { index: slider.settings.startSlide }; + // store if the slider is in carousel mode (displaying / moving multiple slides) + slider.carousel = slider.settings.minSlides > 1 || slider.settings.maxSlides > 1 ? false : true; + // if carousel, force preloadImages = 'all' + if(slider.carousel){ slider.settings.preloadImages = 'all'; } + // calculate the min / max width thresholds based on min / max number of slides + // used to setup and update carousel slides dimensions + slider.minThreshold = (slider.settings.minSlides * slider.settings.slideWidth) + ((slider.settings.minSlides - 1) * slider.settings.slideMargin); + slider.maxThreshold = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); + // store the current state of the slider (if currently animating, working is true) + slider.working = false; + // initialize the controls object + slider.controls = {}; + // initialize an auto interval + slider.interval = null; + // determine which property to use for transitions + slider.animProp = slider.settings.mode === 'vertical' ? 'top' : 'left'; + // determine if hardware acceleration can be used + slider.usingCSS = slider.settings.useCSS && slider.settings.mode !== 'fade' && (function(){ + // create our test div element + var div = document.createElement('div'); + // css transition properties + var props = ['WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective']; + // test for each property + for(var i in props){ + if(div.style[props[i]] !== undefined){ + slider.cssPrefix = props[i].replace('Perspective', '').toLowerCase(); + slider.animProp = '-' + slider.cssPrefix + '-transform'; + return true; + } + } + return false; + }()); + // if vertical mode always make maxSlides and minSlides equal + if(slider.settings.mode === 'vertical'){ slider.settings.maxSlides = slider.settings.minSlides; } + // save original style data + el.data("origStyle", el.attr("style")); + el.children(slider.settings.slideSelector).each(function(){ + $(this).data("origStyle", $(this).attr("style")); + }); + // perform all DOM / CSS modifications + setup(); + }; + + /** + * Performs all DOM and CSS modifications + */ + var setup = function(){ + // wrap el in a wrapper + el.wrap('
'); + // store a namespace reference to .bx-viewport + slider.viewport = el.parent(); + // add a loading div to display while images are loading + slider.loader = $('
'); + slider.viewport.prepend(slider.loader); + // set el to a massive width, to hold any needed slides + // also strip any margin and padding from el + el.css({ + width: slider.settings.mode === 'horizontal' ? (slider.children.length * 1000 + 215) + '%' : 'auto', + position: 'relative' + }); + // if using CSS, add the easing property + if(slider.usingCSS && slider.settings.easing){ + el.css('-' + slider.cssPrefix + '-transition-timing-function', slider.settings.easing); + // if not using CSS and no easing value was supplied, use the default JS animation easing (swing) + }else if(!slider.settings.easing){ + slider.settings.easing = 'swing'; + } + var slidesShowing = getNumberSlidesShowing(); + // make modifications to the viewport (.bx-viewport) + slider.viewport.css({ + width: '100%', + overflow: 'hidden', + position: 'relative' + }); + slider.viewport.parent().css({ + maxWidth: getViewportMaxWidth() + }); + // make modification to the wrapper (.bx-wrapper) + if(!slider.settings.pager){ + slider.viewport.parent().css({ + margin: '0 auto 0px' + }); + } + // apply css to all slider children + slider.children.css({ + 'float': slider.settings.mode === 'horizontal' ? 'left' : 'none', + listStyle: 'none', + position: 'relative' + }); + // apply the calculated width after the float is applied to prevent scrollbar interference + slider.children.css('width', getSlideWidth()); + // if slideMargin is supplied, add the css + if(slider.settings.mode === 'horizontal' && slider.settings.slideMargin > 0){ slider.children.css('marginRight', slider.settings.slideMargin); } + if(slider.settings.mode === 'vertical' && slider.settings.slideMargin > 0){ slider.children.css('marginBottom', slider.settings.slideMargin); } + // if "fade" mode, add positioning and z-index CSS + if(slider.settings.mode === 'fade'){ + slider.children.css({ + position: 'absolute', + zIndex: 0, + display: 'none' + }); + // prepare the z-index on the showing element + slider.children.eq(slider.settings.startSlide).css({zIndex: slider.settings.slideZIndex, display: 'block'}); + } + // create an element to contain all slider controls (pager, start / stop, etc) + slider.controls.el = $('
'); + // if captions are requested, add them + if(slider.settings.captions){ appendCaptions(); } + // check if startSlide is last slide + slider.active.last = slider.settings.startSlide === getPagerQty() - 1; + // if video is true, set up the fitVids plugin + if(slider.settings.video){ el.fitVids(); } + // set the default preload selector (visible) + var preloadSelector = slider.children.eq(slider.settings.startSlide); + if(slider.settings.preloadImages === "all"){ preloadSelector = slider.children; } + // only check for control addition if not in "ticker" mode + if(!slider.settings.ticker){ + // if controls are requested, add them + if(slider.settings.controls){ appendControls(); } + // if auto is true, and auto controls are requested, add them + if(slider.settings.auto && slider.settings.autoControls){ appendControlsAuto(); } + // if pager is requested, add it + if(slider.settings.pager){ appendPager(); } + // if any control option is requested, add the controls wrapper + if(slider.settings.controls || slider.settings.autoControls || slider.settings.pager){ slider.viewport.after(slider.controls.el); } + // if ticker mode, do not allow a pager + } else { + slider.settings.pager = false; + } + // preload all images, then perform final DOM / CSS modifications that depend on images being loaded + loadElements(preloadSelector, start); + }; + + var loadElements = function(selector, callback){ + var total = selector.find('img, iframe').length; + if(total === 0){ + callback(); + return; + } + var count = 0; + selector.find('img, iframe').each(function(){ + $(this).one('load', function(){ + if(++count === total){ callback(); } + }).each(function(){ + if(this.complete){ $(this).load(); } + }); + }); + }; + + /** + * Start the slider + */ + var start = function(){ + // if infinite loop, prepare additional slides + if(slider.settings.infiniteLoop && slider.settings.mode !== 'fade' && !slider.settings.ticker){ + var slice = slider.settings.mode === 'vertical' ? slider.settings.minSlides : slider.settings.maxSlides; + var sliceAppend = slider.children.slice(0, slice).clone(true).addClass('bx-clone'); + var slicePrepend = slider.children.slice(-slice).clone(true).addClass('bx-clone'); + el.append(sliceAppend).prepend(slicePrepend); + } + // remove the loading DOM element + slider.loader.remove(); + // set the left / top position of "el" + setSlidePosition(); + // if "vertical" mode, always use adaptiveHeight to prevent odd behavior + if(slider.settings.mode === 'vertical'){ slider.settings.adaptiveHeight = true; } + // set the viewport height + slider.viewport.height(getViewportHeight()); + // make sure everything is positioned just right (same as a window resize) + el.redrawSlider(); + // onSliderLoad callback + slider.settings.onSliderLoad(slider.active.index); + // slider has been fully initialized + slider.initialized = true; + // bind the resize call to the window + if(slider.settings.responsive){ $(window).bind('resize', resizeWindow); } + // if auto is true and has more than 1 page, start the show + if(slider.settings.auto && slider.settings.autoStart && (getPagerQty() > 1 || slider.settings.autoSlideForOnePage)){ initAuto(); } + // if ticker is true, start the ticker + if(slider.settings.ticker){ initTicker(); } + // if pager is requested, make the appropriate pager link active + if(slider.settings.pager){ updatePagerActive(slider.settings.startSlide); } + // check for any updates to the controls (like hideControlOnEnd updates) + if(slider.settings.controls){ updateDirectionControls(); } + // if touchEnabled is true, setup the touch events + if(slider.settings.touchEnabled && !slider.settings.ticker){ initTouch(); } + }; + + /** + * Returns the calculated height of the viewport, used to determine either adaptiveHeight or the maxHeight value + */ + var getViewportHeight = function(){ + var height = 0; + // first determine which children (slides) should be used in our height calculation + var children = $(); + // if mode is not "vertical" and adaptiveHeight is false, include all children + if(slider.settings.mode !== 'vertical' && !slider.settings.adaptiveHeight){ + children = slider.children; + }else{ + // if not carousel, return the single active child + if(!slider.carousel){ + children = slider.children.eq(slider.active.index); + // if carousel, return a slice of children + }else{ + // get the individual slide index + var currentIndex = slider.settings.moveSlides === 1 ? slider.active.index : slider.active.index * getMoveBy(); + // add the current slide to the children + children = slider.children.eq(currentIndex); + // cycle through the remaining "showing" slides + for (i = 1; i <= slider.settings.maxSlides - 1; i++){ + // if looped back to the start + if(currentIndex + i >= slider.children.length){ + children = children.add(slider.children.eq(i - 1)); + }else{ + children = children.add(slider.children.eq(currentIndex + i)); + } + } + } + } + // if "vertical" mode, calculate the sum of the heights of the children + if(slider.settings.mode === 'vertical'){ + children.each(function(index){ + height += $(this).outerHeight(); + }); + // add user-supplied margins + if(slider.settings.slideMargin > 0){ + height += slider.settings.slideMargin * (slider.settings.minSlides - 1); + } + // if not "vertical" mode, calculate the max height of the children + }else{ + height = Math.max.apply(Math, children.map(function(){ + return $(this).outerHeight(false); + }).get()); + } + + if(slider.viewport.css('box-sizing') === 'border-box'){ + height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')) + + parseFloat(slider.viewport.css('border-top-width')) + parseFloat(slider.viewport.css('border-bottom-width')); + }else if(slider.viewport.css('box-sizing') === 'padding-box'){ + height += parseFloat(slider.viewport.css('padding-top')) + parseFloat(slider.viewport.css('padding-bottom')); + } + + return height; + }; + + /** + * Returns the calculated width to be used for the outer wrapper / viewport + */ + var getViewportMaxWidth = function(){ + var width = '100%'; + if(slider.settings.slideWidth > 0){ + if(slider.settings.mode === 'horizontal'){ + width = (slider.settings.maxSlides * slider.settings.slideWidth) + ((slider.settings.maxSlides - 1) * slider.settings.slideMargin); + }else{ + width = slider.settings.slideWidth; + } + } + return width; + }; + + /** + * Returns the calculated width to be applied to each slide + */ + var getSlideWidth = function(){ + // start with any user-supplied slide width + var newElWidth = slider.settings.slideWidth; + // get the current viewport width + var wrapWidth = slider.viewport.width(); + // if slide width was not supplied, or is larger than the viewport use the viewport width + if(slider.settings.slideWidth === 0 || + (slider.settings.slideWidth > wrapWidth && !slider.carousel) || + slider.settings.mode === 'vertical'){ + newElWidth = wrapWidth; + // if carousel, use the thresholds to determine the width + }else if(slider.settings.maxSlides > 1 && slider.settings.mode === 'horizontal'){ + if(wrapWidth > slider.maxThreshold){ + // newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.maxSlides - 1))) / slider.settings.maxSlides; + }else if(wrapWidth < slider.minThreshold){ + newElWidth = (wrapWidth - (slider.settings.slideMargin * (slider.settings.minSlides - 1))) / slider.settings.minSlides; + } + } + return newElWidth; + }; + + /** + * Returns the number of slides currently visible in the viewport (includes partially visible slides) + */ + var getNumberSlidesShowing = function(){ + var slidesShowing = 1; + if(slider.settings.mode === 'horizontal' && slider.settings.slideWidth > 0){ + // if viewport is smaller than minThreshold, return minSlides + if(slider.viewport.width() < slider.minThreshold){ + slidesShowing = slider.settings.minSlides; + // if viewport is larger than minThreshold, return maxSlides + }else if(slider.viewport.width() > slider.maxThreshold){ + slidesShowing = slider.settings.maxSlides; + // if viewport is between min / max thresholds, divide viewport width by first child width + }else{ + var childWidth = slider.children.first().width() + slider.settings.slideMargin; + slidesShowing = Math.floor((slider.viewport.width() + + slider.settings.slideMargin) / childWidth); + } + // if "vertical" mode, slides showing will always be minSlides + }else if(slider.settings.mode === 'vertical'){ + slidesShowing = slider.settings.minSlides; + } + return slidesShowing; + }; + + /** + * Returns the number of pages (one full viewport of slides is one "page") + */ + var getPagerQty = function(){ + var pagerQty = 0; + // if moveSlides is specified by the user + if(slider.settings.moveSlides > 0){ + if(slider.settings.infiniteLoop){ + pagerQty = Math.ceil(slider.children.length / getMoveBy()); + }else{ + // use a while loop to determine pages + var breakPoint = 0; + var counter = 0; + // when breakpoint goes above children length, counter is the number of pages + while (breakPoint < slider.children.length){ + ++pagerQty; + breakPoint = counter + getNumberSlidesShowing(); + counter += slider.settings.moveSlides <= getNumberSlidesShowing() ? slider.settings.moveSlides : getNumberSlidesShowing(); + } + } + // if moveSlides is 0 (auto) divide children length by sides showing, then round up + }else{ + pagerQty = Math.ceil(slider.children.length / getNumberSlidesShowing()); + } + return pagerQty; + }; + + /** + * Returns the number of individual slides by which to shift the slider + */ + var getMoveBy = function(){ + // if moveSlides was set by the user and moveSlides is less than number of slides showing + if(slider.settings.moveSlides > 0 && slider.settings.moveSlides <= getNumberSlidesShowing()){ + return slider.settings.moveSlides; + } + // if moveSlides is 0 (auto) + return getNumberSlidesShowing(); + }; + + /** + * Sets the slider's (el) left or top position + */ + var setSlidePosition = function(){ + var position; + // if last slide, not infinite loop, and number of children is larger than specified maxSlides + if(slider.children.length > slider.settings.maxSlides && slider.active.last && !slider.settings.infiniteLoop){ + if(slider.settings.mode === 'horizontal'){ + // get the last child's position + var lastChild = slider.children.last(); + position = lastChild.position(); + // set the left position + setPositionProperty(-(position.left - (slider.viewport.width() - lastChild.outerWidth())), 'reset', 0); + }else if(slider.settings.mode === 'vertical'){ + // get the last showing index's position + var lastShowingIndex = slider.children.length - slider.settings.minSlides; + position = slider.children.eq(lastShowingIndex).position(); + // set the top position + setPositionProperty(-position.top, 'reset', 0); + } + // if not last slide + }else{ + // get the position of the first showing slide + position = slider.children.eq(slider.active.index * getMoveBy()).position(); + // check for last slide + if(slider.active.index === getPagerQty() - 1){ slider.active.last = true; } + // set the respective position + if(position !== undefined){ + if(slider.settings.mode === 'horizontal'){ setPositionProperty(-position.left, 'reset', 0); } + else if(slider.settings.mode === 'vertical'){ setPositionProperty(-position.top, 'reset', 0); } + } + } + }; + + /** + * Sets the el's animating property position (which in turn will sometimes animate el). + * If using CSS, sets the transform property. If not using CSS, sets the top / left property. + * + * @param value (int) + * - the animating property's value + * + * @param type (string) 'slider', 'reset', 'ticker' + * - the type of instance for which the function is being + * + * @param duration (int) + * - the amount of time (in ms) the transition should occupy + * + * @param params (array) optional + * - an optional parameter containing any variables that need to be passed in + */ + var setPositionProperty = function(value, type, duration, params){ + // use CSS transform + if(slider.usingCSS){ + // determine the translate3d value + var propValue = slider.settings.mode === 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)'; + // add the CSS transition-duration + el.css('-' + slider.cssPrefix + '-transition-duration', duration / 1000 + 's'); + if(type === 'slide'){ + // set the property value + el.css(slider.animProp, propValue); + // bind a callback method - executes when CSS transition completes + el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){ + // unbind the callback + el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); + updateAfterSlideTransition(); + }); + }else if(type === 'reset'){ + el.css(slider.animProp, propValue); + }else if(type === 'ticker'){ + // make the transition use 'linear' + el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear'); + el.css(slider.animProp, propValue); + // bind a callback method - executes when CSS transition completes + el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){ + // unbind the callback + el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); + // reset the position + setPositionProperty(params.resetValue, 'reset', 0); + // start the loop again + tickerLoop(); + }); + } + // use JS animate + }else{ + var animateObj = {}; + animateObj[slider.animProp] = value; + if(type === 'slide'){ + el.animate(animateObj, duration, slider.settings.easing, function(){ + updateAfterSlideTransition(); + }); + }else if(type === 'reset'){ + el.css(slider.animProp, value); + }else if(type === 'ticker'){ + el.animate(animateObj, speed, 'linear', function(){ + setPositionProperty(params.resetValue, 'reset', 0); + // run the recursive loop after animation + tickerLoop(); + }); + } + } + }; + + /** + * Populates the pager with proper amount of pages + */ + var populatePager = function(){ + var pagerHtml = ''; + var pagerQty = getPagerQty(); + // loop through each pager item + for(var i=0; i < pagerQty; i++){ + var linkContent = ''; + // if a buildPager function is supplied, use it to get pager link value, else use index + 1 + if(slider.settings.buildPager && $.isFunction(slider.settings.buildPager) || slider.settings.pagerCustom){ + linkContent = slider.settings.buildPager(i); + slider.pagerEl.addClass('bx-custom-pager'); + }else{ + linkContent = i + 1; + slider.pagerEl.addClass('bx-default-pager'); + } + // var linkContent = slider.settings.buildPager && $.isFunction(slider.settings.buildPager) ? slider.settings.buildPager(i) : i + 1; + // add the markup to the string + pagerHtml += ''; + } + // populate the pager element with pager links + slider.pagerEl.html(pagerHtml); + }; + + /** + * Appends the pager to the controls element + */ + var appendPager = function(){ + if(!slider.settings.pagerCustom){ + // create the pager DOM element + slider.pagerEl = $('
'); + // if a pager selector was supplied, populate it with the pager + if(slider.settings.pagerSelector){ + $(slider.settings.pagerSelector).html(slider.pagerEl); + // if no pager selector was supplied, add it after the wrapper + }else{ + slider.controls.el.addClass('bx-has-pager').append(slider.pagerEl); + } + // populate the pager + populatePager(); + }else{ + slider.pagerEl = $(slider.settings.pagerCustom); + } + // assign the pager click binding + slider.pagerEl.on('click', 'a', clickPagerBind); + }; + + /** + * Appends prev / next controls to the controls element + */ + var appendControls = function(){ + slider.controls.next = $('' + slider.settings.nextText + ''); + slider.controls.prev = $('' + slider.settings.prevText + ''); + // bind click actions to the controls + slider.controls.next.bind('click', clickNextBind); + slider.controls.prev.bind('click', clickPrevBind); + // if nextSelector was supplied, populate it + if(slider.settings.nextSelector){ + $(slider.settings.nextSelector).append(slider.controls.next); + } + // if prevSelector was supplied, populate it + if(slider.settings.prevSelector){ + $(slider.settings.prevSelector).append(slider.controls.prev); + } + // if no custom selectors were supplied + if(!slider.settings.nextSelector && !slider.settings.prevSelector){ + // add the controls to the DOM + slider.controls.directionEl = $('
'); + // add the control elements to the directionEl + slider.controls.directionEl.append(slider.controls.prev).append(slider.controls.next); + // slider.viewport.append(slider.controls.directionEl); + slider.controls.el.addClass('bx-has-controls-direction').append(slider.controls.directionEl); + } + }; + + /** + * Appends start / stop auto controls to the controls element + */ + var appendControlsAuto = function(){ + slider.controls.start = $(''); + slider.controls.stop = $(''); + // add the controls to the DOM + slider.controls.autoEl = $('
'); + // bind click actions to the controls + slider.controls.autoEl.on('click', '.bx-start', clickStartBind); + slider.controls.autoEl.on('click', '.bx-stop', clickStopBind); + // if autoControlsCombine, insert only the "start" control + if(slider.settings.autoControlsCombine){ + slider.controls.autoEl.append(slider.controls.start); + // if autoControlsCombine is false, insert both controls + }else{ + slider.controls.autoEl.append(slider.controls.start).append(slider.controls.stop); + } + // if auto controls selector was supplied, populate it with the controls + if(slider.settings.autoControlsSelector){ + $(slider.settings.autoControlsSelector).html(slider.controls.autoEl); + // if auto controls selector was not supplied, add it after the wrapper + }else{ + slider.controls.el.addClass('bx-has-controls-auto').append(slider.controls.autoEl); + } + // update the auto controls + updateAutoControls(slider.settings.autoStart ? 'stop' : 'start'); + }; + + /** + * Appends image captions to the DOM + */ + var appendCaptions = function(){ + // cycle through each child + slider.children.each(function(index){ + // get the image title attribute + var title = $(this).find('img:first').attr('title'); + // append the caption + if(title !== undefined && ('' + title).length){ + $(this).append('
' + title + '
'); + } + }); + }; + + /** + * Click next binding + * + * @param e (event) + * - DOM event object + */ + var clickNextBind = function(e){ + // if auto show is running, stop it + if(slider.settings.auto){ el.stopAuto(); } + el.goToNextSlide(); + e.preventDefault(); + }; + + /** + * Click prev binding + * + * @param e (event) + * - DOM event object + */ + var clickPrevBind = function(e){ + // if auto show is running, stop it + if(slider.settings.auto){ el.stopAuto(); } + el.goToPrevSlide(); + e.preventDefault(); + }; + + /** + * Click start binding + * + * @param e (event) + * - DOM event object + */ + var clickStartBind = function(e){ + el.startAuto(); + e.preventDefault(); + }; + + /** + * Click stop binding + * + * @param e (event) + * - DOM event object + */ + var clickStopBind = function(e){ + el.stopAuto(); + e.preventDefault(); + }; + + /** + * Click pager binding + * + * @param e (event) + * - DOM event object + */ + var clickPagerBind = function(e){ + // if auto show is running, stop it + if(slider.settings.auto){ el.stopAuto(); } + var pagerLink = $(e.currentTarget); + if(pagerLink.attr('data-slide-index') !== undefined){ + var pagerIndex = parseInt(pagerLink.attr('data-slide-index')); + // if clicked pager link is not active, continue with the goToSlide call + if(pagerIndex !== slider.active.index){ el.goToSlide(pagerIndex); } + e.preventDefault(); + } + }; + + /** + * Updates the pager links with an active class + * + * @param slideIndex (int) + * - index of slide to make active + */ + var updatePagerActive = function(slideIndex){ + // if "short" pager type + var len = slider.children.length; // nb of children + if(slider.settings.pagerType === 'short'){ + if(slider.settings.maxSlides > 1){ + len = Math.ceil(slider.children.length/slider.settings.maxSlides); + } + slider.pagerEl.html( (slideIndex + 1) + slider.settings.pagerShortSeparator + len); + return; + } + // remove all pager active classes + slider.pagerEl.find('a').removeClass('active'); + // apply the active class for all pagers + slider.pagerEl.each(function(i, el){ $(el).find('a').eq(slideIndex).addClass('active'); }); + }; + + /** + * Performs needed actions after a slide transition + */ + var updateAfterSlideTransition = function(){ + // if infinite loop is true + if(slider.settings.infiniteLoop){ + var position = ''; + // first slide + if(slider.active.index === 0){ + // set the new position + position = slider.children.eq(0).position(); + // carousel, last slide + }else if(slider.active.index === getPagerQty() - 1 && slider.carousel){ + position = slider.children.eq((getPagerQty() - 1) * getMoveBy()).position(); + // last slide + }else if(slider.active.index === slider.children.length - 1){ + position = slider.children.eq(slider.children.length - 1).position(); + } + if(position){ + if(slider.settings.mode === 'horizontal'){ setPositionProperty(-position.left, 'reset', 0); } + else if(slider.settings.mode === 'vertical'){ setPositionProperty(-position.top, 'reset', 0); } + } + } + // declare that the transition is complete + slider.working = false; + // onSlideAfter callback + slider.settings.onSlideAfter(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); + }; + + /** + * Updates the auto controls state (either active, or combined switch) + * + * @param state (string) "start", "stop" + * - the new state of the auto show + */ + var updateAutoControls = function(state){ + // if autoControlsCombine is true, replace the current control with the new state + if(slider.settings.autoControlsCombine){ + slider.controls.autoEl.html(slider.controls[state]); + // if autoControlsCombine is false, apply the "active" class to the appropriate control + }else{ + slider.controls.autoEl.find('a').removeClass('active'); + slider.controls.autoEl.find('a:not(.bx-' + state + ')').addClass('active'); + } + }; + + /** + * Updates the direction controls (checks if either should be hidden) + */ + var updateDirectionControls = function(){ + if(getPagerQty() === 1){ + slider.controls.prev.addClass('disabled'); + slider.controls.next.addClass('disabled'); + }else if(!slider.settings.infiniteLoop && slider.settings.hideControlOnEnd){ + // if first slide + if(slider.active.index === 0){ + slider.controls.prev.addClass('disabled'); + slider.controls.next.removeClass('disabled'); + // if last slide + }else if(slider.active.index === getPagerQty() - 1){ + slider.controls.next.addClass('disabled'); + slider.controls.prev.removeClass('disabled'); + // if any slide in the middle + }else{ + slider.controls.prev.removeClass('disabled'); + slider.controls.next.removeClass('disabled'); + } + } + }; + + /** + * Initializes the auto process + */ + var initAuto = function(){ + // if autoDelay was supplied, launch the auto show using a setTimeout() call + if(slider.settings.autoDelay > 0){ + var timeout = setTimeout(el.startAuto, slider.settings.autoDelay); + // if autoDelay was not supplied, start the auto show normally + }else{ + el.startAuto(); + } + // if autoHover is requested + if(slider.settings.autoHover){ + // on el hover + el.hover(function(){ + // if the auto show is currently playing (has an active interval) + if(slider.interval){ + // stop the auto show and pass true argument which will prevent control update + el.stopAuto(true); + // create a new autoPaused value which will be used by the relative "mouseout" event + slider.autoPaused = true; + } + }, function(){ + // if the autoPaused value was created be the prior "mouseover" event + if(slider.autoPaused){ + // start the auto show and pass true argument which will prevent control update + el.startAuto(true); + // reset the autoPaused value + slider.autoPaused = null; + } + }); + } + }; + + /** + * Initializes the ticker process + */ + var initTicker = function(){ + var startPosition = 0; + // if autoDirection is "next", append a clone of the entire slider + if(slider.settings.autoDirection === 'next'){ + el.append(slider.children.clone().addClass('bx-clone')); + // if autoDirection is "prev", prepend a clone of the entire slider, and set the left position + }else{ + el.prepend(slider.children.clone().addClass('bx-clone')); + var position = slider.children.first().position(); + startPosition = slider.settings.mode === 'horizontal' ? -position.left : -position.top; + } + setPositionProperty(startPosition, 'reset', 0); + // do not allow controls in ticker mode + slider.settings.pager = false; + slider.settings.controls = false; + slider.settings.autoControls = false; + // if autoHover is requested + if(slider.settings.tickerHover && !slider.usingCSS){ + // on el hover + slider.viewport.hover(function(){ + el.stop(); + }, function(){ + // calculate the total width of children (used to calculate the speed ratio) + var totalDimens = 0; + slider.children.each(function(index){ + totalDimens += slider.settings.mode === 'horizontal' ? $(this).outerWidth(true) : $(this).outerHeight(true); + }); + // calculate the speed ratio (used to determine the new speed to finish the paused animation) + var ratio = slider.settings.speed / totalDimens; + // determine which property to use + var property = slider.settings.mode === 'horizontal' ? 'left' : 'top'; + // calculate the new speed + var newSpeed = ratio * (totalDimens - (Math.abs(parseInt(el.css(property))))); + tickerLoop(newSpeed); + }); + } + // start the ticker loop + tickerLoop(); + }; + + /** + * Runs a continuous loop, news ticker-style + */ + var tickerLoop = function(resumeSpeed){ + speed = resumeSpeed ? resumeSpeed : slider.settings.speed; + var position = {left: 0, top: 0}; + var reset = {left: 0, top: 0}; + // if "next" animate left position to last child, then reset left to 0 + if(slider.settings.autoDirection === 'next'){ + position = el.find('.bx-clone').first().position(); + // if "prev" animate left position to 0, then reset left to first non-clone child + }else{ + reset = slider.children.first().position(); + } + var animateProperty = slider.settings.mode === 'horizontal' ? -position.left : -position.top; + var resetValue = slider.settings.mode === 'horizontal' ? -reset.left : -reset.top; + var params = {resetValue: resetValue}; + setPositionProperty(animateProperty, 'ticker', speed, params); + }; + + /** + * Initializes touch events + */ + var initTouch = function(){ + // initialize object to contain all touch values + slider.touch = { + start: {x: 0, y: 0}, + end: {x: 0, y: 0} + }; + slider.viewport.bind('touchstart', onTouchStart); + }; + + /** + * Event handler for "touchstart" + * + * @param e (event) + * - DOM event object + */ + var onTouchStart = function(e){ + if(slider.working){ + e.preventDefault(); + }else{ + // record the original position when touch starts + slider.touch.originalPos = el.position(); + var orig = e.originalEvent; + // record the starting touch x, y coordinates + slider.touch.start.x = orig.changedTouches[0].pageX; + slider.touch.start.y = orig.changedTouches[0].pageY; + // bind a "touchmove" event to the viewport + slider.viewport.bind('touchmove', onTouchMove); + // bind a "touchend" event to the viewport + slider.viewport.bind('touchend', onTouchEnd); + } + }; + + /** + * Event handler for "touchmove" + * + * @param e (event) + * - DOM event object + */ + var onTouchMove = function(e){ + var orig = e.originalEvent; + // if scrolling on y axis, do not prevent default + var xMovement = Math.abs(orig.changedTouches[0].pageX - slider.touch.start.x); + var yMovement = Math.abs(orig.changedTouches[0].pageY - slider.touch.start.y); + // x axis swipe + if((xMovement * 3) > yMovement && slider.settings.preventDefaultSwipeX){ + e.preventDefault(); + // y axis swipe + }else if((yMovement * 3) > xMovement && slider.settings.preventDefaultSwipeY){ + e.preventDefault(); + } + if(slider.settings.mode !== 'fade' && slider.settings.oneToOneTouch){ + var value = 0, change = 0; + // if horizontal, drag along x axis + if(slider.settings.mode === 'horizontal'){ + change = orig.changedTouches[0].pageX - slider.touch.start.x; + value = slider.touch.originalPos.left + change; + // if vertical, drag along y axis + }else{ + change = orig.changedTouches[0].pageY - slider.touch.start.y; + value = slider.touch.originalPos.top + change; + } + setPositionProperty(value, 'reset', 0); + } + }; + + /** + * Event handler for "touchend" + * + * @param e (event) + * - DOM event object + */ + var onTouchEnd = function(e){ + slider.viewport.unbind('touchmove', onTouchMove); + var orig = e.originalEvent; + var value = 0; + var distance = 0; + // record end x, y positions + slider.touch.end.x = orig.changedTouches[0].pageX; + slider.touch.end.y = orig.changedTouches[0].pageY; + // if fade mode, check if absolute x distance clears the threshold + if(slider.settings.mode === 'fade'){ + distance = Math.abs(slider.touch.start.x - slider.touch.end.x); + if(distance >= slider.settings.swipeThreshold){ + if(slider.touch.start.x > slider.touch.end.x){ + el.goToNextSlide(); + } else { + el.goToPrevSlide(); + } + el.stopAuto(); + } + // not fade mode + }else{ + // calculate distance and el's animate property + if(slider.settings.mode === 'horizontal'){ + distance = slider.touch.end.x - slider.touch.start.x; + value = slider.touch.originalPos.left; + }else{ + distance = slider.touch.end.y - slider.touch.start.y; + value = slider.touch.originalPos.top; + } + // if not infinite loop and first / last slide, do not attempt a slide transition + if(!slider.settings.infiniteLoop && ((slider.active.index === 0 && distance > 0) || (slider.active.last && distance < 0))){ + setPositionProperty(value, 'reset', 200); + }else{ + // check if distance clears threshold + if(Math.abs(distance) >= slider.settings.swipeThreshold){ + if(distance < 0){ + el.goToNextSlide(); + } else { + el.goToPrevSlide(); + } + el.stopAuto(); + }else{ + // el.animate(property, 200); + setPositionProperty(value, 'reset', 200); + } + } + } + slider.viewport.unbind('touchend', onTouchEnd); + }; + + /** + * Window resize event callback + */ + var resizeWindow = function(e){ + // don't do anything if slider isn't initialized. + if(!slider.initialized){ return; } + // get the new window dimens (again, thank you IE) + var windowWidthNew = $(window).width(); + var windowHeightNew = $(window).height(); + // make sure that it is a true window resize + // *we must check this because our dinosaur friend IE fires a window resize event when certain DOM elements + // are resized. Can you just die already?* + if(windowWidth !== windowWidthNew || windowHeight !== windowHeightNew){ + // set the new window dimens + windowWidth = windowWidthNew; + windowHeight = windowHeightNew; + // update all dynamic elements + el.redrawSlider(); + // Call user resize handler + slider.settings.onSliderResize.call(el, slider.active.index); + } + }; + + /** + * =================================================================================== + * = PUBLIC FUNCTIONS + * =================================================================================== + */ + + /** + * Performs slide transition to the specified slide + * + * @param slideIndex (int) + * - the destination slide's index (zero-based) + * + * @param direction (string) + * - INTERNAL USE ONLY - the direction of travel ("prev" / "next") + */ + el.goToSlide = function(slideIndex, direction){ + // if plugin is currently in motion, ignore request + if(slider.working || slider.active.index === slideIndex){ return; } + // declare that plugin is in motion + slider.working = true; + // store the old index + slider.oldIndex = slider.active.index; + // if slideIndex is less than zero, set active index to last child (this happens during infinite loop) + if(slideIndex < 0){ + slider.active.index = getPagerQty() - 1; + // if slideIndex is greater than children length, set active index to 0 (this happens during infinite loop) + }else if(slideIndex >= getPagerQty()){ + slider.active.index = 0; + // set active index to requested slide + }else{ + slider.active.index = slideIndex; + } + // onSlideBefore, onSlideNext, onSlidePrev callbacks + slider.settings.onSlideBefore(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); + if(direction === 'next'){ + slider.settings.onSlideNext(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); + }else if(direction === 'prev'){ + slider.settings.onSlidePrev(slider.children.eq(slider.active.index), slider.oldIndex, slider.active.index); + } + // check if last slide + slider.active.last = slider.active.index >= getPagerQty() - 1; + // update the pager with active class + if(slider.settings.pager || slider.settings.pagerCustom){ updatePagerActive(slider.active.index); } + // // check for direction control update + if(slider.settings.controls){ updateDirectionControls(); } + // if slider is set to mode: "fade" + if(slider.settings.mode === 'fade'){ + // if adaptiveHeight is true and next height is different from current height, animate to the new height + if(slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()){ + slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); + } + // fade out the visible child and reset its z-index value + slider.children.filter(':visible').fadeOut(slider.settings.speed).css({zIndex: 0}); + // fade in the newly requested slide + slider.children.eq(slider.active.index).css('zIndex', slider.settings.slideZIndex+1).fadeIn(slider.settings.speed, function(){ + $(this).css('zIndex', slider.settings.slideZIndex); + updateAfterSlideTransition(); + }); + // slider mode is not "fade" + }else{ + // if adaptiveHeight is true and next height is different from current height, animate to the new height + if(slider.settings.adaptiveHeight && slider.viewport.height() !== getViewportHeight()){ + slider.viewport.animate({height: getViewportHeight()}, slider.settings.adaptiveHeightSpeed); + } + var moveBy = 0; + var position = {left: 0, top: 0}; + var lastChild = null; + // if carousel and not infinite loop + if(!slider.settings.infiniteLoop && slider.carousel && slider.active.last){ + if(slider.settings.mode === 'horizontal'){ + // get the last child position + lastChild = slider.children.eq(slider.children.length - 1); + position = lastChild.position(); + // calculate the position of the last slide + moveBy = slider.viewport.width() - lastChild.outerWidth(); + }else{ + // get last showing index position + var lastShowingIndex = slider.children.length - slider.settings.minSlides; + position = slider.children.eq(lastShowingIndex).position(); + } + // horizontal carousel, going previous while on first slide (infiniteLoop mode) + }else if(slider.carousel && slider.active.last && direction === 'prev'){ + // get the last child position + var eq = slider.settings.moveSlides === 1 ? slider.settings.maxSlides - getMoveBy() : ((getPagerQty() - 1) * getMoveBy()) - (slider.children.length - slider.settings.maxSlides); + lastChild = el.children('.bx-clone').eq(eq); + position = lastChild.position(); + // if infinite loop and "Next" is clicked on the last slide + }else if(direction === 'next' && slider.active.index === 0){ + // get the last clone position + position = el.find('> .bx-clone').eq(slider.settings.maxSlides).position(); + slider.active.last = false; + // normal non-zero requests + }else if(slideIndex >= 0){ + var requestEl = slideIndex * getMoveBy(); + position = slider.children.eq(requestEl).position(); + } + + /* If the position doesn't exist + * (e.g. if you destroy the slider on a next click), + * it doesn't throw an error. + */ + if("undefined" !== typeof(position)){ + var value = slider.settings.mode === 'horizontal' ? -(position.left - moveBy) : -position.top; + // plugin values to be animated + setPositionProperty(value, 'slide', slider.settings.speed); + } + } + }; + + /** + * Transitions to the next slide in the show + */ + el.goToNextSlide = function(){ + // if infiniteLoop is false and last page is showing, disregard call + if(!slider.settings.infiniteLoop && slider.active.last){ return; } + var pagerIndex = parseInt(slider.active.index) + 1; + el.goToSlide(pagerIndex, 'next'); + }; + + /** + * Transitions to the prev slide in the show + */ + el.goToPrevSlide = function(){ + // if infiniteLoop is false and last page is showing, disregard call + if(!slider.settings.infiniteLoop && slider.active.index === 0){ return; } + var pagerIndex = parseInt(slider.active.index) - 1; + el.goToSlide(pagerIndex, 'prev'); + }; + + /** + * Starts the auto show + * + * @param preventControlUpdate (boolean) + * - if true, auto controls state will not be updated + */ + el.startAuto = function(preventControlUpdate){ + // if an interval already exists, disregard call + if(slider.interval){ return; } + // create an interval + slider.interval = setInterval(function(){ + if(slider.settings.autoDirection === 'next'){ + el.goToNextSlide(); + }else{ + el.goToPrevSlide(); + } + }, slider.settings.pause); + // if auto controls are displayed and preventControlUpdate is not true + if(slider.settings.autoControls && preventControlUpdate !== true){ updateAutoControls('stop'); } + }; + + /** + * Stops the auto show + * + * @param preventControlUpdate (boolean) + * - if true, auto controls state will not be updated + */ + el.stopAuto = function(preventControlUpdate){ + // if no interval exists, disregard call + if(!slider.interval){ return; } + // clear the interval + clearInterval(slider.interval); + slider.interval = null; + // if auto controls are displayed and preventControlUpdate is not true + if(slider.settings.autoControls && preventControlUpdate !== true){ updateAutoControls('start'); } + }; + + /** + * Returns current slide index (zero-based) + */ + el.getCurrentSlide = function(){ + return slider.active.index; + }; + + /** + * Returns current slide element + */ + el.getCurrentSlideElement = function(){ + return slider.children.eq(slider.active.index); + }; + + /** + * Returns number of slides in show + */ + el.getSlideCount = function(){ + return slider.children.length; + }; + + /** + * Update all dynamic slider elements + */ + el.redrawSlider = function(){ + // resize all children in ratio to new screen size + slider.children.add(el.find('.bx-clone')).outerWidth(getSlideWidth()); + // adjust the height + slider.viewport.css('height', getViewportHeight()); + // update the slide position + if(!slider.settings.ticker) { setSlidePosition(); } + // if active.last was true before the screen resize, we want + // to keep it last no matter what screen size we end on + if (slider.active.last) { slider.active.index = getPagerQty() - 1; } + // if the active index (page) no longer exists due to the resize, simply set the index as last + if (slider.active.index >= getPagerQty()) { slider.active.last = true; } + // if a pager is being displayed and a custom pager is not being used, update it + if(slider.settings.pager && !slider.settings.pagerCustom){ + populatePager(); + updatePagerActive(slider.active.index); + } + }; + + /** + * Destroy the current instance of the slider (revert everything back to original state) + */ + el.destroySlider = function(){ + // don't do anything if slider has already been destroyed + if(!slider.initialized){ return; } + slider.initialized = false; + $('.bx-clone', this).remove(); + slider.children.each(function(){ + if($(this).data("origStyle") !== undefined){ + $(this).attr("style", $(this).data("origStyle")); + } else { + $(this).removeAttr('style'); + } + }); + if($(this).data("origStyle") !== undefined){ + this.attr("style", $(this).data("origStyle")); + } else { + $(this).removeAttr('style'); + } + $(this).unwrap().unwrap(); + if(slider.controls.el){ slider.controls.el.remove(); } + if(slider.controls.next){ slider.controls.next.remove(); } + if(slider.controls.prev){ slider.controls.prev.remove(); } + if(slider.pagerEl && slider.settings.controls && !slider.settings.pagerCustom){ slider.pagerEl.remove(); } + $('.bx-caption', this).remove(); + if(slider.controls.autoEl){ slider.controls.autoEl.remove(); } + clearInterval(slider.interval); + if(slider.settings.responsive){ $(window).unbind('resize', resizeWindow); } + }; + + /** + * Reload the slider (revert all DOM changes, and re-initialize) + */ + el.reloadSlider = function(settings){ + if(settings !== undefined){ options = settings; } + el.destroySlider(); + init(); + }; + + init(); + + // returns the current jQuery object + return this; + }; + +})(jQuery); diff --git a/src/less/jquery.bxslider.less b/src/less/jquery.bxslider.less index 2620bae5..00352b9a 100644 --- a/src/less/jquery.bxslider.less +++ b/src/less/jquery.bxslider.less @@ -1,5 +1,5 @@ -/** - * BxSlider v4.1.3 - Fully loaded, responsive content slider +/*** + * BxSlider v4.2.0 - Fully loaded, responsive content slider * http://bxslider.com * * Written by: Steven Wanderski, 2014 @@ -8,7 +8,7 @@ * * CEO and founder of bxCreative, LTD * http://bxcreative.com - */ + ***/ /** RESET AND LAYOUT diff --git a/src/vendor/jquery.easing.1.3.js b/src/vendor/jquery.easing.1.3.js new file mode 100644 index 00000000..ef743210 --- /dev/null +++ b/src/vendor/jquery.easing.1.3.js @@ -0,0 +1,205 @@ +/* + * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ + * + * Uses the built in easing capabilities added In jQuery 1.1 + * to offer multiple easing options + * + * TERMS OF USE - jQuery Easing + * + * Open source under the BSD License. + * + * Copyright © 2008 George McGinley Smith + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the author nor the names of contributors may be used to endorse + * or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ + +// t: current time, b: begInnIng value, c: change In value, d: duration +jQuery.easing['jswing'] = jQuery.easing['swing']; + +jQuery.extend( jQuery.easing, +{ + def: 'easeOutQuad', + swing: function (x, t, b, c, d) { + //alert(jQuery.easing.default); + return jQuery.easing[jQuery.easing.def](x, t, b, c, d); + }, + easeInQuad: function (x, t, b, c, d) { + return c*(t/=d)*t + b; + }, + easeOutQuad: function (x, t, b, c, d) { + return -c *(t/=d)*(t-2) + b; + }, + easeInOutQuad: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t + b; + return -c/2 * ((--t)*(t-2) - 1) + b; + }, + easeInCubic: function (x, t, b, c, d) { + return c*(t/=d)*t*t + b; + }, + easeOutCubic: function (x, t, b, c, d) { + return c*((t=t/d-1)*t*t + 1) + b; + }, + easeInOutCubic: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t + b; + return c/2*((t-=2)*t*t + 2) + b; + }, + easeInQuart: function (x, t, b, c, d) { + return c*(t/=d)*t*t*t + b; + }, + easeOutQuart: function (x, t, b, c, d) { + return -c * ((t=t/d-1)*t*t*t - 1) + b; + }, + easeInOutQuart: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t*t + b; + return -c/2 * ((t-=2)*t*t*t - 2) + b; + }, + easeInQuint: function (x, t, b, c, d) { + return c*(t/=d)*t*t*t*t + b; + }, + easeOutQuint: function (x, t, b, c, d) { + return c*((t=t/d-1)*t*t*t*t + 1) + b; + }, + easeInOutQuint: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; + return c/2*((t-=2)*t*t*t*t + 2) + b; + }, + easeInSine: function (x, t, b, c, d) { + return -c * Math.cos(t/d * (Math.PI/2)) + c + b; + }, + easeOutSine: function (x, t, b, c, d) { + return c * Math.sin(t/d * (Math.PI/2)) + b; + }, + easeInOutSine: function (x, t, b, c, d) { + return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; + }, + easeInExpo: function (x, t, b, c, d) { + return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; + }, + easeOutExpo: function (x, t, b, c, d) { + return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; + }, + easeInOutExpo: function (x, t, b, c, d) { + if (t==0) return b; + if (t==d) return b+c; + if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; + return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; + }, + easeInCirc: function (x, t, b, c, d) { + return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; + }, + easeOutCirc: function (x, t, b, c, d) { + return c * Math.sqrt(1 - (t=t/d-1)*t) + b; + }, + easeInOutCirc: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; + return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; + }, + easeInElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + }, + easeOutElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; + }, + easeInOutElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; + }, + easeInBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + return c*(t/=d)*t*((s+1)*t - s) + b; + }, + easeOutBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; + }, + easeInOutBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; + return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; + }, + easeInBounce: function (x, t, b, c, d) { + return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b; + }, + easeOutBounce: function (x, t, b, c, d) { + if ((t/=d) < (1/2.75)) { + return c*(7.5625*t*t) + b; + } else if (t < (2/2.75)) { + return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; + } else if (t < (2.5/2.75)) { + return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; + } else { + return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; + } + }, + easeInOutBounce: function (x, t, b, c, d) { + if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b; + return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b; + } +}); + +/* + * + * TERMS OF USE - EASING EQUATIONS + * + * Open source under the BSD License. + * + * Copyright © 2001 Robert Penner + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * Neither the name of the author nor the names of contributors may be used to endorse + * or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ \ No newline at end of file diff --git a/src/vendor/jquery.fitvids.js b/src/vendor/jquery.fitvids.js new file mode 100644 index 00000000..d464f93f --- /dev/null +++ b/src/vendor/jquery.fitvids.js @@ -0,0 +1,80 @@ +/*global jQuery */ +/*jshint multistr:true browser:true */ +/*! +* FitVids 1.0 +* +* Copyright 2011, Chris Coyier - http://css-tricks.com + Dave Rupert - http://daverupert.com +* Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/ +* Released under the WTFPL license - http://sam.zoy.org/wtfpl/ +* +* Date: Thu Sept 01 18:00:00 2011 -0500 +*/ + +(function( $ ){ + + "use strict"; + + $.fn.fitVids = function( options ) { + var settings = { + customSelector: null + }; + + var div = document.createElement('div'), + ref = document.getElementsByTagName('base')[0] || document.getElementsByTagName('script')[0]; + + div.className = 'fit-vids-style'; + div.innerHTML = '­'; + + ref.parentNode.insertBefore(div,ref); + + if ( options ) { + $.extend( settings, options ); + } + + return this.each(function(){ + var selectors = [ + "iframe[src*='player.vimeo.com']", + "iframe[src*='www.youtube.com']", + "iframe[src*='www.kickstarter.com']", + "object", + "embed" + ]; + + if (settings.customSelector) { + selectors.push(settings.customSelector); + } + + var $allVideos = $(this).find(selectors.join(',')); + + $allVideos.each(function(){ + var $this = $(this); + if (this.tagName.toLowerCase() === 'embed' && $this.parent('object').length || $this.parent('.fluid-width-video-wrapper').length) { return; } + var height = ( this.tagName.toLowerCase() === 'object' || ($this.attr('height') && !isNaN(parseInt($this.attr('height'), 10))) ) ? parseInt($this.attr('height'), 10) : $this.height(), + width = !isNaN(parseInt($this.attr('width'), 10)) ? parseInt($this.attr('width'), 10) : $this.width(), + aspectRatio = height / width; + if(!$this.attr('id')){ + var videoID = 'fitvid' + Math.floor(Math.random()*999999); + $this.attr('id', videoID); + } + $this.wrap('
').parent('.fluid-width-video-wrapper').css('padding-top', (aspectRatio * 100)+"%"); + $this.removeAttr('height').removeAttr('width'); + }); + }); + }; +})( jQuery );