diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..7bc01d9 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..f29c2c3 --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + MyActivity + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b080d2d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..ce30bc2 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/html/Lato400.woff b/assets/html/Lato400.woff new file mode 100644 index 0000000..ad1a467 Binary files /dev/null and b/assets/html/Lato400.woff differ diff --git a/assets/html/Lato700.woff b/assets/html/Lato700.woff new file mode 100644 index 0000000..35934a9 Binary files /dev/null and b/assets/html/Lato700.woff differ diff --git a/assets/html/app.appcache b/assets/html/app.appcache new file mode 100644 index 0000000..caa91e1 --- /dev/null +++ b/assets/html/app.appcache @@ -0,0 +1,10 @@ +CACHE MANIFEST +# v1.2 + +# Explicitly cached 'master entries'. +CACHE: +http://imgs.xkcd.com/ + +# Resources that require the user to be online. +NETWORK: +* \ No newline at end of file diff --git a/assets/html/idangerous.swiper.css b/assets/html/idangerous.swiper.css new file mode 100755 index 0000000..20d0b7c --- /dev/null +++ b/assets/html/idangerous.swiper.css @@ -0,0 +1,107 @@ +/* =============================================================== +Basic Swiper Styles +================================================================*/ +.swiper-container { + margin:0 auto; + position:relative; + overflow:hidden; + -webkit-backface-visibility:hidden; + -moz-backface-visibility:hidden; + -ms-backface-visibility:hidden; + -o-backface-visibility:hidden; + backface-visibility:hidden; + /* Fix of Webkit flickering */ + z-index:1; +} +.swiper-wrapper { + position:relative; + width:100%; + -webkit-transition-property:-webkit-transform, left, top; + -webkit-transition-duration:0s; + -webkit-transform:translate3d(0px,0,0); + -webkit-transition-timing-function:ease; + + -moz-transition-property:-moz-transform, left, top; + -moz-transition-duration:0s; + -moz-transform:translate3d(0px,0,0); + -moz-transition-timing-function:ease; + + -o-transition-property:-o-transform, left, top; + -o-transition-duration:0s; + -o-transform:translate3d(0px,0,0); + -o-transition-timing-function:ease; + -o-transform:translate(0px,0px); + + -ms-transition-property:-ms-transform, left, top; + -ms-transition-duration:0s; + -ms-transform:translate3d(0px,0,0); + -ms-transition-timing-function:ease; + + transition-property:transform, left, top; + transition-duration:0s; + transform:translate3d(0px,0,0); + transition-timing-function:ease; + + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; +} +.swiper-free-mode > .swiper-wrapper { + -webkit-transition-timing-function: ease-out; + -moz-transition-timing-function: ease-out; + -ms-transition-timing-function: ease-out; + -o-transition-timing-function: ease-out; + transition-timing-function: ease-out; + margin: 0 auto; +} +.swiper-slide { + float: left; +} + +/* IE10 Windows Phone 8 Fixes */ +.swiper-wp8-horizontal { + -ms-touch-action: pan-y; +} +.swiper-wp8-vertical { + -ms-touch-action: pan-x; +} + +/* =============================================================== +Your custom styles, here you need to specify container's and slide's +sizes, pagination, etc. +================================================================*/ +.swiper-container { + /* Specify Swiper's Size: */ + + /*width:200px; + height: 100px;*/ +} +.swiper-slide { + /* Specify Slides's Size: */ + + /*width: 100%; + height: 100%;*/ +} +.swiper-slide-active { + /* Specific active slide styling: */ + +} +.swiper-slide-visible { + /* Specific visible slide styling: */ + +} +/* =============================================================== +Pagination Styles +================================================================*/ +.swiper-pagination-switch { + /* Stylize pagination button: */ + +} +.swiper-active-switch { + /* Specific active button style: */ + +} +.swiper-visible-switch { + /* Specific visible button style: */ + +} diff --git a/assets/html/idangerous.swiper.js b/assets/html/idangerous.swiper.js new file mode 100755 index 0000000..c955821 --- /dev/null +++ b/assets/html/idangerous.swiper.js @@ -0,0 +1,2705 @@ +var Swiper = function (selector, params) { + 'use strict'; + + /*========================= + A little bit dirty but required part for IE8 and old FF support + ===========================*/ + if (document.body.__defineGetter__) { + if (HTMLElement) { + var element = HTMLElement.prototype; + if (element.__defineGetter__) { + element.__defineGetter__('outerHTML', function () { return new XMLSerializer().serializeToString(this); }); + } + } + } + + if (!window.getComputedStyle) { + window.getComputedStyle = function (el, pseudo) { + this.el = el; + this.getPropertyValue = function (prop) { + var re = /(\-([a-z]){1})/g; + if (prop === 'float') prop = 'styleFloat'; + if (re.test(prop)) { + prop = prop.replace(re, function () { + return arguments[2].toUpperCase(); + }); + } + return el.currentStyle[prop] ? el.currentStyle[prop] : null; + }; + return this; + }; + } + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (obj, start) { + for (var i = (start || 0), j = this.length; i < j; i++) { + if (this[i] === obj) { return i; } + } + return -1; + }; + } + if (!document.querySelectorAll) { + if (!window.jQuery) return; + } + function $$(selector, context) { + if (document.querySelectorAll) + return (context || document).querySelectorAll(selector); + else + return jQuery(selector, context); + } + + /*========================= + Check for correct selector + ===========================*/ + if (typeof selector === 'undefined') return; + + if (!(selector.nodeType)) { + if ($$(selector).length === 0) return; + } + + /*========================= + _this + ===========================*/ + var _this = this; + + /*========================= + Default Flags and vars + ===========================*/ + _this.touches = { + start: 0, + startX: 0, + startY: 0, + current: 0, + currentX: 0, + currentY: 0, + diff: 0, + abs: 0 + }; + _this.positions = { + start: 0, + abs: 0, + diff: 0, + current: 0 + }; + _this.times = { + start: 0, + end: 0 + }; + + _this.id = (new Date()).getTime(); + _this.container = (selector.nodeType) ? selector : $$(selector)[0]; + _this.isTouched = false; + _this.isMoved = false; + _this.activeIndex = 0; + _this.centerIndex = 0; + _this.activeLoaderIndex = 0; + _this.activeLoopIndex = 0; + _this.previousIndex = null; + _this.velocity = 0; + _this.snapGrid = []; + _this.slidesGrid = []; + _this.imagesToLoad = []; + _this.imagesLoaded = 0; + _this.wrapperLeft = 0; + _this.wrapperRight = 0; + _this.wrapperTop = 0; + _this.wrapperBottom = 0; + _this.isAndroid = navigator.userAgent.toLowerCase().indexOf('android') >= 0; + var wrapper, slideSize, wrapperSize, direction, isScrolling, containerSize; + + /*========================= + Default Parameters + ===========================*/ + var defaults = { + eventTarget: 'wrapper', // or 'container' + mode : 'horizontal', // or 'vertical' + touchRatio : 1, + speed : 300, + freeMode : false, + freeModeFluid : false, + momentumRatio: 1, + momentumBounce: true, + momentumBounceRatio: 1, + slidesPerView : 1, + slidesPerGroup : 1, + simulateTouch : true, + followFinger : true, + shortSwipes : true, + longSwipesRatio: 0.5, + moveStartThreshold: false, + onlyExternal : false, + createPagination : true, + pagination : false, + paginationElement: 'span', + paginationClickable: false, + paginationAsRange: true, + resistance : true, // or false or 100% + scrollContainer : false, + preventLinks : true, + preventLinksPropagation: false, + noSwiping : false, // or class + noSwipingClass : 'swiper-no-swiping', //:) + initialSlide: 0, + keyboardControl: false, + mousewheelControl : false, + mousewheelControlForceToAxis : false, + useCSS3Transforms : true, + // Autoplay + autoplay: false, + autoplayDisableOnInteraction: true, + autoplayStopOnLast: false, + //Loop mode + loop: false, + loopAdditionalSlides: 0, + //Auto Height + calculateHeight: false, + cssWidthAndHeight: false, + //Images Preloader + updateOnImagesReady : true, + //Form elements + releaseFormElements : true, + //Watch for active slide, useful when use effects on different slide states + watchActiveIndex: false, + //Slides Visibility Fit + visibilityFullFit : false, + //Slides Offset + offsetPxBefore : 0, + offsetPxAfter : 0, + offsetSlidesBefore : 0, + offsetSlidesAfter : 0, + centeredSlides: false, + //Queue callbacks + queueStartCallbacks : false, + queueEndCallbacks : false, + //Auto Resize + autoResize : true, + resizeReInit : false, + //DOMAnimation + DOMAnimation : true, + //Slides Loader + loader: { + slides: [], //array with slides + slidesHTMLType: 'inner', // or 'outer' + surroundGroups: 1, //keep preloaded slides groups around view + logic: 'reload', //or 'change' + loadAllSlides: false + }, + //Namespace + slideElement: 'div', + slideClass: 'swiper-slide', + slideActiveClass: 'swiper-slide-active', + slideVisibleClass: 'swiper-slide-visible', + slideDuplicateClass: 'swiper-slide-duplicate', + wrapperClass: 'swiper-wrapper', + paginationElementClass: 'swiper-pagination-switch', + paginationActiveClass: 'swiper-active-switch', + paginationVisibleClass: 'swiper-visible-switch' + }; + params = params || {}; + for (var prop in defaults) { + if (prop in params && typeof params[prop] === 'object') { + for (var subProp in defaults[prop]) { + if (! (subProp in params[prop])) { + params[prop][subProp] = defaults[prop][subProp]; + } + } + } + else if (! (prop in params)) { + params[prop] = defaults[prop]; + } + } + _this.params = params; + if (params.scrollContainer) { + params.freeMode = true; + params.freeModeFluid = true; + } + if (params.loop) { + params.resistance = '100%'; + } + var isH = params.mode === 'horizontal'; + + /*========================= + Define Touch Events + ===========================*/ + var desktopEvents = ['mousedown', 'mousemove', 'mouseup']; + if (_this.browser.ie10) desktopEvents = ['MSPointerDown', 'MSPointerMove', 'MSPointerUp']; + if (_this.browser.ie11) desktopEvents = ['pointerdown', 'pointermove', 'pointerup']; + + _this.touchEvents = { + touchStart : _this.support.touch || !params.simulateTouch ? 'touchstart' : desktopEvents[0], + touchMove : _this.support.touch || !params.simulateTouch ? 'touchmove' : desktopEvents[1], + touchEnd : _this.support.touch || !params.simulateTouch ? 'touchend' : desktopEvents[2] + }; + + /*========================= + Wrapper + ===========================*/ + for (var i = _this.container.childNodes.length - 1; i >= 0; i--) { + if (_this.container.childNodes[i].className) { + var _wrapperClasses = _this.container.childNodes[i].className.split(/\s+/); + for (var j = 0; j < _wrapperClasses.length; j++) { + if (_wrapperClasses[j] === params.wrapperClass) { + wrapper = _this.container.childNodes[i]; + } + } + } + } + + _this.wrapper = wrapper; + /*========================= + Slide API + ===========================*/ + _this._extendSwiperSlide = function (el) { + el.append = function () { + if (params.loop) { + el.insertAfter(_this.slides.length - _this.loopedSlides); + } + else { + _this.wrapper.appendChild(el); + _this.reInit(); + } + + return el; + }; + el.prepend = function () { + if (params.loop) { + _this.wrapper.insertBefore(el, _this.slides[_this.loopedSlides]); + _this.removeLoopedSlides(); + _this.calcSlides(); + _this.createLoop(); + } + else { + _this.wrapper.insertBefore(el, _this.wrapper.firstChild); + } + _this.reInit(); + return el; + }; + el.insertAfter = function (index) { + if (typeof index === 'undefined') return false; + var beforeSlide; + + if (params.loop) { + beforeSlide = _this.slides[index + 1 + _this.loopedSlides]; + if (beforeSlide) { + _this.wrapper.insertBefore(el, beforeSlide); + } + else { + _this.wrapper.appendChild(el); + } + _this.removeLoopedSlides(); + _this.calcSlides(); + _this.createLoop(); + } + else { + beforeSlide = _this.slides[index + 1]; + _this.wrapper.insertBefore(el, beforeSlide); + } + _this.reInit(); + return el; + }; + el.clone = function () { + return _this._extendSwiperSlide(el.cloneNode(true)); + }; + el.remove = function () { + _this.wrapper.removeChild(el); + _this.reInit(); + }; + el.html = function (html) { + if (typeof html === 'undefined') { + return el.innerHTML; + } + else { + el.innerHTML = html; + return el; + } + }; + el.index = function () { + var index; + for (var i = _this.slides.length - 1; i >= 0; i--) { + if (el === _this.slides[i]) index = i; + } + return index; + }; + el.isActive = function () { + if (el.index() === _this.activeIndex) return true; + else return false; + }; + if (!el.swiperSlideDataStorage) el.swiperSlideDataStorage = {}; + el.getData = function (name) { + return el.swiperSlideDataStorage[name]; + }; + el.setData = function (name, value) { + el.swiperSlideDataStorage[name] = value; + return el; + }; + el.data = function (name, value) { + if (typeof value === 'undefined') { + return el.getAttribute('data-' + name); + } + else { + el.setAttribute('data-' + name, value); + return el; + } + }; + el.getWidth = function (outer) { + return _this.h.getWidth(el, outer); + }; + el.getHeight = function (outer) { + return _this.h.getHeight(el, outer); + }; + el.getOffset = function () { + return _this.h.getOffset(el); + }; + return el; + }; + + //Calculate information about number of slides + _this.calcSlides = function (forceCalcSlides) { + var oldNumber = _this.slides ? _this.slides.length : false; + _this.slides = []; + _this.displaySlides = []; + for (var i = 0; i < _this.wrapper.childNodes.length; i++) { + if (_this.wrapper.childNodes[i].className) { + var _className = _this.wrapper.childNodes[i].className; + var _slideClasses = _className.split(/\s+/); + for (var j = 0; j < _slideClasses.length; j++) { + if (_slideClasses[j] === params.slideClass) { + _this.slides.push(_this.wrapper.childNodes[i]); + } + } + } + } + for (i = _this.slides.length - 1; i >= 0; i--) { + _this._extendSwiperSlide(_this.slides[i]); + } + if (oldNumber === false) return; + if (oldNumber !== _this.slides.length || forceCalcSlides) { + + // Number of slides has been changed + removeSlideEvents(); + addSlideEvents(); + _this.updateActiveSlide(); + if (_this.params.pagination) _this.createPagination(); + _this.callPlugins('numberOfSlidesChanged'); + } + }; + + //Create Slide + _this.createSlide = function (html, slideClassList, el) { + slideClassList = slideClassList || _this.params.slideClass; + el = el || params.slideElement; + var newSlide = document.createElement(el); + newSlide.innerHTML = html || ''; + newSlide.className = slideClassList; + return _this._extendSwiperSlide(newSlide); + }; + + //Append Slide + _this.appendSlide = function (html, slideClassList, el) { + if (!html) return; + if (html.nodeType) { + return _this._extendSwiperSlide(html).append(); + } + else { + return _this.createSlide(html, slideClassList, el).append(); + } + }; + _this.prependSlide = function (html, slideClassList, el) { + if (!html) return; + if (html.nodeType) { + return _this._extendSwiperSlide(html).prepend(); + } + else { + return _this.createSlide(html, slideClassList, el).prepend(); + } + }; + _this.insertSlideAfter = function (index, html, slideClassList, el) { + if (typeof index === 'undefined') return false; + if (html.nodeType) { + return _this._extendSwiperSlide(html).insertAfter(index); + } + else { + return _this.createSlide(html, slideClassList, el).insertAfter(index); + } + }; + _this.removeSlide = function (index) { + if (_this.slides[index]) { + if (params.loop) { + if (!_this.slides[index + _this.loopedSlides]) return false; + _this.slides[index + _this.loopedSlides].remove(); + _this.removeLoopedSlides(); + _this.calcSlides(); + _this.createLoop(); + } + else _this.slides[index].remove(); + return true; + } + else return false; + }; + _this.removeLastSlide = function () { + if (_this.slides.length > 0) { + if (params.loop) { + _this.slides[_this.slides.length - 1 - _this.loopedSlides].remove(); + _this.removeLoopedSlides(); + _this.calcSlides(); + _this.createLoop(); + } + else _this.slides[_this.slides.length - 1].remove(); + return true; + } + else { + return false; + } + }; + _this.removeAllSlides = function () { + for (var i = _this.slides.length - 1; i >= 0; i--) { + _this.slides[i].remove(); + } + }; + _this.getSlide = function (index) { + return _this.slides[index]; + }; + _this.getLastSlide = function () { + return _this.slides[_this.slides.length - 1]; + }; + _this.getFirstSlide = function () { + return _this.slides[0]; + }; + + //Currently Active Slide + _this.activeSlide = function () { + return _this.slides[_this.activeIndex]; + }; + + /*========================= + Wrapper for Callbacks : Allows additive callbacks via function arrays + ===========================*/ + _this.fireCallback = function () { + var callback = arguments[0]; + if (Object.prototype.toString.call(callback) === '[object Array]') { + for (var i = 0; i < callback.length; i++) { + if (typeof callback[i] === 'function') { + callback[i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); + } + } + } else if (Object.prototype.toString.call(callback) === '[object String]') { + if (params['on' + callback]) _this.fireCallback(params['on' + callback]); + } else { + callback(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); + } + }; + function isArray(obj) { + if (Object.prototype.toString.apply(obj) === '[object Array]') return true; + return false; + } + + /** + * Allows user to add callbacks, rather than replace them + * @param callback + * @param func + * @return {*} + */ + _this.addCallback = function (callback, func) { + var _this = this, tempFunc; + if (_this.params['on' + callback]) { + if (isArray(this.params['on' + callback])) { + return this.params['on' + callback].push(func); + } else if (typeof this.params['on' + callback] === 'function') { + tempFunc = this.params['on' + callback]; + this.params['on' + callback] = []; + this.params['on' + callback].push(tempFunc); + return this.params['on' + callback].push(func); + } + } else { + this.params['on' + callback] = []; + return this.params['on' + callback].push(func); + } + }; + _this.removeCallbacks = function (callback) { + if (_this.params['on' + callback]) { + _this.params['on' + callback] = null; + } + }; + + /*========================= + Plugins API + ===========================*/ + var _plugins = []; + for (var plugin in _this.plugins) { + if (params[plugin]) { + var p = _this.plugins[plugin](_this, params[plugin]); + if (p) _plugins.push(p); + } + } + _this.callPlugins = function (method, args) { + if (!args) args = {}; + for (var i = 0; i < _plugins.length; i++) { + if (method in _plugins[i]) { + _plugins[i][method](args); + } + } + }; + + /*========================= + Windows Phone 8 Fix + ===========================*/ + if ((_this.browser.ie10 || _this.browser.ie11) && !params.onlyExternal) { + _this.wrapper.classList.add('swiper-wp8-' + (isH ? 'horizontal' : 'vertical')); + } + + /*========================= + Free Mode Class + ===========================*/ + if (params.freeMode) { + _this.container.className += ' swiper-free-mode'; + } + + /*================================================== + Init/Re-init/Resize Fix + ====================================================*/ + _this.initialized = false; + _this.init = function (force, forceCalcSlides) { + var _width = _this.h.getWidth(_this.container); + var _height = _this.h.getHeight(_this.container); + if (_width === _this.width && _height === _this.height && !force) return; + _this.width = _width; + _this.height = _height; + + var slideWidth, slideHeight, slideMaxHeight, wrapperWidth, wrapperHeight, slideLeft; + var i; // loop index variable to avoid JSHint W004 / W038 + containerSize = isH ? _width : _height; + var wrapper = _this.wrapper; + + if (force) { + _this.calcSlides(forceCalcSlides); + } + + if (params.slidesPerView === 'auto') { + //Auto mode + var slidesWidth = 0; + var slidesHeight = 0; + + //Unset Styles + if (params.slidesOffset > 0) { + wrapper.style.paddingLeft = ''; + wrapper.style.paddingRight = ''; + wrapper.style.paddingTop = ''; + wrapper.style.paddingBottom = ''; + } + wrapper.style.width = ''; + wrapper.style.height = ''; + if (params.offsetPxBefore > 0) { + if (isH) _this.wrapperLeft = params.offsetPxBefore; + else _this.wrapperTop = params.offsetPxBefore; + } + if (params.offsetPxAfter > 0) { + if (isH) _this.wrapperRight = params.offsetPxAfter; + else _this.wrapperBottom = params.offsetPxAfter; + } + + if (params.centeredSlides) { + if (isH) { + _this.wrapperLeft = (containerSize - this.slides[0].getWidth(true)) / 2; + _this.wrapperRight = (containerSize - _this.slides[_this.slides.length - 1].getWidth(true)) / 2; + } + else { + _this.wrapperTop = (containerSize - _this.slides[0].getHeight(true)) / 2; + _this.wrapperBottom = (containerSize - _this.slides[_this.slides.length - 1].getHeight(true)) / 2; + } + } + + if (isH) { + if (_this.wrapperLeft >= 0) wrapper.style.paddingLeft = _this.wrapperLeft + 'px'; + if (_this.wrapperRight >= 0) wrapper.style.paddingRight = _this.wrapperRight + 'px'; + } + else { + if (_this.wrapperTop >= 0) wrapper.style.paddingTop = _this.wrapperTop + 'px'; + if (_this.wrapperBottom >= 0) wrapper.style.paddingBottom = _this.wrapperBottom + 'px'; + } + slideLeft = 0; + var centeredSlideLeft = 0; + _this.snapGrid = []; + _this.slidesGrid = []; + + slideMaxHeight = 0; + for (i = 0; i < _this.slides.length; i++) { + slideWidth = _this.slides[i].getWidth(true); + slideHeight = _this.slides[i].getHeight(true); + if (params.calculateHeight) { + slideMaxHeight = Math.max(slideMaxHeight, slideHeight); + } + var _slideSize = isH ? slideWidth : slideHeight; + if (params.centeredSlides) { + var nextSlideWidth = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getWidth(true); + var nextSlideHeight = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getHeight(true); + var nextSlideSize = isH ? nextSlideWidth : nextSlideHeight; + if (_slideSize > containerSize) { + for (var j = 0; j <= Math.floor(_slideSize / (containerSize + _this.wrapperLeft)); j++) { + if (j === 0) _this.snapGrid.push(slideLeft + _this.wrapperLeft); + else _this.snapGrid.push(slideLeft + _this.wrapperLeft + containerSize * j); + } + _this.slidesGrid.push(slideLeft + _this.wrapperLeft); + } + else { + _this.snapGrid.push(centeredSlideLeft); + _this.slidesGrid.push(centeredSlideLeft); + } + + centeredSlideLeft += _slideSize / 2 + nextSlideSize / 2; + + } + else { + if (_slideSize > containerSize) { + for (var k = 0; k <= Math.floor(_slideSize / containerSize); k++) { + _this.snapGrid.push(slideLeft + containerSize * k); + } + } + else { + _this.snapGrid.push(slideLeft); + } + _this.slidesGrid.push(slideLeft); + } + + slideLeft += _slideSize; + + slidesWidth += slideWidth; + slidesHeight += slideHeight; + } + if (params.calculateHeight) _this.height = slideMaxHeight; + if (isH) { + wrapperSize = slidesWidth + _this.wrapperRight + _this.wrapperLeft; + wrapper.style.width = (slidesWidth) + 'px'; + wrapper.style.height = (_this.height) + 'px'; + } + else { + wrapperSize = slidesHeight + _this.wrapperTop + _this.wrapperBottom; + wrapper.style.width = (_this.width) + 'px'; + wrapper.style.height = (slidesHeight) + 'px'; + } + + } + else if (params.scrollContainer) { + //Scroll Container + wrapper.style.width = ''; + wrapper.style.height = ''; + wrapperWidth = _this.slides[0].getWidth(true); + wrapperHeight = _this.slides[0].getHeight(true); + wrapperSize = isH ? wrapperWidth : wrapperHeight; + wrapper.style.width = wrapperWidth + 'px'; + wrapper.style.height = wrapperHeight + 'px'; + slideSize = isH ? wrapperWidth : wrapperHeight; + + } + else { + //For usual slides + if (params.calculateHeight) { + slideMaxHeight = 0; + wrapperHeight = 0; + //ResetWrapperSize + if (!isH) _this.container.style.height = ''; + wrapper.style.height = ''; + + for (i = 0; i < _this.slides.length; i++) { + //ResetSlideSize + _this.slides[i].style.height = ''; + slideMaxHeight = Math.max(_this.slides[i].getHeight(true), slideMaxHeight); + if (!isH) wrapperHeight += _this.slides[i].getHeight(true); + } + slideHeight = slideMaxHeight; + _this.height = slideHeight; + + if (isH) wrapperHeight = slideHeight; + else { + containerSize = slideHeight; + _this.container.style.height = containerSize + 'px'; + } + } + else { + slideHeight = isH ? _this.height : _this.height / params.slidesPerView; + wrapperHeight = isH ? _this.height : _this.slides.length * slideHeight; + } + slideWidth = isH ? _this.width / params.slidesPerView : _this.width; + wrapperWidth = isH ? _this.slides.length * slideWidth : _this.width; + slideSize = isH ? slideWidth : slideHeight; + + if (params.offsetSlidesBefore > 0) { + if (isH) _this.wrapperLeft = slideSize * params.offsetSlidesBefore; + else _this.wrapperTop = slideSize * params.offsetSlidesBefore; + } + if (params.offsetSlidesAfter > 0) { + if (isH) _this.wrapperRight = slideSize * params.offsetSlidesAfter; + else _this.wrapperBottom = slideSize * params.offsetSlidesAfter; + } + if (params.offsetPxBefore > 0) { + if (isH) _this.wrapperLeft = params.offsetPxBefore; + else _this.wrapperTop = params.offsetPxBefore; + } + if (params.offsetPxAfter > 0) { + if (isH) _this.wrapperRight = params.offsetPxAfter; + else _this.wrapperBottom = params.offsetPxAfter; + } + if (params.centeredSlides) { + if (isH) { + _this.wrapperLeft = (containerSize - slideSize) / 2; + _this.wrapperRight = (containerSize - slideSize) / 2; + } + else { + _this.wrapperTop = (containerSize - slideSize) / 2; + _this.wrapperBottom = (containerSize - slideSize) / 2; + } + } + if (isH) { + if (_this.wrapperLeft > 0) wrapper.style.paddingLeft = _this.wrapperLeft + 'px'; + if (_this.wrapperRight > 0) wrapper.style.paddingRight = _this.wrapperRight + 'px'; + } + else { + if (_this.wrapperTop > 0) wrapper.style.paddingTop = _this.wrapperTop + 'px'; + if (_this.wrapperBottom > 0) wrapper.style.paddingBottom = _this.wrapperBottom + 'px'; + } + + wrapperSize = isH ? wrapperWidth + _this.wrapperRight + _this.wrapperLeft : wrapperHeight + _this.wrapperTop + _this.wrapperBottom; + if (!params.cssWidthAndHeight) { + if (parseFloat(wrapperWidth) > 0) { + wrapper.style.width = wrapperWidth + 'px'; + } + if (parseFloat(wrapperHeight) > 0) { + wrapper.style.height = wrapperHeight + 'px'; + } + } + slideLeft = 0; + _this.snapGrid = []; + _this.slidesGrid = []; + for (i = 0; i < _this.slides.length; i++) { + _this.snapGrid.push(slideLeft); + _this.slidesGrid.push(slideLeft); + slideLeft += slideSize; + if (!params.cssWidthAndHeight) { + if (parseFloat(slideWidth) > 0) { + _this.slides[i].style.width = slideWidth + 'px'; + } + if (parseFloat(slideHeight) > 0) { + _this.slides[i].style.height = slideHeight + 'px'; + } + } + } + + } + + if (!_this.initialized) { + _this.callPlugins('onFirstInit'); + if (params.onFirstInit) _this.fireCallback(params.onFirstInit, _this); + } + else { + _this.callPlugins('onInit'); + if (params.onInit) _this.fireCallback(params.onInit, _this); + } + _this.initialized = true; + }; + + _this.reInit = function (forceCalcSlides) { + _this.init(true, forceCalcSlides); + }; + + _this.resizeFix = function (reInit) { + _this.callPlugins('beforeResizeFix'); + + _this.init(params.resizeReInit || reInit); + + // swipe to active slide in fixed mode + if (!params.freeMode) { + _this.swipeTo((params.loop ? _this.activeLoopIndex : _this.activeIndex), 0, false); + // Fix autoplay + if (params.autoplay) { + if (_this.support.transitions && typeof autoplayTimeoutId !== 'undefined') { + if (typeof autoplayTimeoutId !== 'undefined') { + clearTimeout(autoplayTimeoutId); + autoplayTimeoutId = undefined; + _this.startAutoplay(); + } + } + else { + if (typeof autoplayIntervalId !== 'undefined') { + clearInterval(autoplayIntervalId); + autoplayIntervalId = undefined; + _this.startAutoplay(); + } + } + } + } + // move wrapper to the beginning in free mode + else if (_this.getWrapperTranslate() < -maxWrapperPosition()) { + _this.setWrapperTransition(0); + _this.setWrapperTranslate(-maxWrapperPosition()); + } + + _this.callPlugins('afterResizeFix'); + }; + + /*========================================== + Max and Min Positions + ============================================*/ + function maxWrapperPosition() { + var a = (wrapperSize - containerSize); + if (params.freeMode) { + a = wrapperSize - containerSize; + } + // if (params.loop) a -= containerSize; + if (params.slidesPerView > _this.slides.length) a = 0; + if (a < 0) a = 0; + return a; + } + function minWrapperPosition() { + var a = 0; + // if (params.loop) a = containerSize; + return a; + } + + /*========================================== + Event Listeners + ============================================*/ + function initEvents() { + var bind = _this.h.addEventListener; + var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container; + //Touch Events + if (! (_this.browser.ie10 || _this.browser.ie11)) { + if (_this.support.touch) { + bind(eventTarget, 'touchstart', onTouchStart); + bind(eventTarget, 'touchmove', onTouchMove); + bind(eventTarget, 'touchend', onTouchEnd); + } + if (params.simulateTouch) { + bind(eventTarget, 'mousedown', onTouchStart); + bind(document, 'mousemove', onTouchMove); + bind(document, 'mouseup', onTouchEnd); + } + } + else { + bind(eventTarget, _this.touchEvents.touchStart, onTouchStart); + bind(document, _this.touchEvents.touchMove, onTouchMove); + bind(document, _this.touchEvents.touchEnd, onTouchEnd); + } + + //Resize Event + if (params.autoResize) { + bind(window, 'resize', _this.resizeFix); + } + //Slide Events + addSlideEvents(); + //Mousewheel + _this._wheelEvent = false; + if (params.mousewheelControl) { + if (document.onmousewheel !== undefined) { + _this._wheelEvent = 'mousewheel'; + } + try { + new WheelEvent('wheel'); + _this._wheelEvent = 'wheel'; + } catch (e) {} + if (!_this._wheelEvent) { + _this._wheelEvent = 'DOMMouseScroll'; + } + + if (_this._wheelEvent) { + bind(_this.container, _this._wheelEvent, handleMousewheel); + } + } + + //Keyboard + function _loadImage(src) { + var image = new Image(); + image.onload = function () { + _this.imagesLoaded++; + if (_this.imagesLoaded === _this.imagesToLoad.length) { + _this.reInit(); + if (params.onImagesReady) _this.fireCallback(params.onImagesReady, _this); + } + }; + image.src = src; + } + + if (params.keyboardControl) { + bind(document, 'keydown', handleKeyboardKeys); + } + if (params.updateOnImagesReady) { + _this.imagesToLoad = $$('img', _this.container); + + for (var i = 0; i < _this.imagesToLoad.length; i++) { + _loadImage(_this.imagesToLoad[i].getAttribute('src')); + } + } + } + + //Remove Event Listeners + _this.destroy = function () { + var unbind = _this.h.removeEventListener; + var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container; + //Touch Events + if (! (_this.browser.ie10 || _this.browser.ie11)) { + if (_this.support.touch) { + unbind(eventTarget, 'touchstart', onTouchStart); + unbind(eventTarget, 'touchmove', onTouchMove); + unbind(eventTarget, 'touchend', onTouchEnd); + } + if (params.simulateTouch) { + unbind(eventTarget, 'mousedown', onTouchStart); + unbind(document, 'mousemove', onTouchMove); + unbind(document, 'mouseup', onTouchEnd); + } + } + else { + unbind(eventTarget, _this.touchEvents.touchStart, onTouchStart); + unbind(document, _this.touchEvents.touchMove, onTouchMove); + unbind(document, _this.touchEvents.touchEnd, onTouchEnd); + } + + //Resize Event + if (params.autoResize) { + unbind(window, 'resize', _this.resizeFix); + } + + //Init Slide Events + removeSlideEvents(); + + //Pagination + if (params.paginationClickable) { + removePaginationEvents(); + } + + //Mousewheel + if (params.mousewheelControl && _this._wheelEvent) { + unbind(_this.container, _this._wheelEvent, handleMousewheel); + } + + //Keyboard + if (params.keyboardControl) { + unbind(document, 'keydown', handleKeyboardKeys); + } + + //Stop autoplay + if (params.autoplay) { + _this.stopAutoplay(); + } + _this.callPlugins('onDestroy'); + + //Destroy variable + _this = null; + }; + + function addSlideEvents() { + var bind = _this.h.addEventListener, + i; + + //Prevent Links Events + if (params.preventLinks) { + var links = $$('a', _this.container); + for (i = 0; i < links.length; i++) { + bind(links[i], 'click', preventClick); + } + } + //Release Form Elements + if (params.releaseFormElements) { + var formElements = $$('input, textarea, select', _this.container); + for (i = 0; i < formElements.length; i++) { + bind(formElements[i], _this.touchEvents.touchStart, releaseForms, true); + } + } + + //Slide Clicks & Touches + if (params.onSlideClick) { + for (i = 0; i < _this.slides.length; i++) { + bind(_this.slides[i], 'click', slideClick); + } + } + if (params.onSlideTouch) { + for (i = 0; i < _this.slides.length; i++) { + bind(_this.slides[i], _this.touchEvents.touchStart, slideTouch); + } + } + } + function removeSlideEvents() { + var unbind = _this.h.removeEventListener, + i; + + //Slide Clicks & Touches + if (params.onSlideClick) { + for (i = 0; i < _this.slides.length; i++) { + unbind(_this.slides[i], 'click', slideClick); + } + } + if (params.onSlideTouch) { + for (i = 0; i < _this.slides.length; i++) { + unbind(_this.slides[i], _this.touchEvents.touchStart, slideTouch); + } + } + //Release Form Elements + if (params.releaseFormElements) { + var formElements = $$('input, textarea, select', _this.container); + for (i = 0; i < formElements.length; i++) { + unbind(formElements[i], _this.touchEvents.touchStart, releaseForms, true); + } + } + //Prevent Links Events + if (params.preventLinks) { + var links = $$('a', _this.container); + for (i = 0; i < links.length; i++) { + unbind(links[i], 'click', preventClick); + } + } + } + /*========================================== + Keyboard Control + ============================================*/ + function handleKeyboardKeys(e) { + var kc = e.keyCode || e.charCode; + if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) return; + if (kc === 37 || kc === 39 || kc === 38 || kc === 40) { + var inView = false; + //Check that swiper should be inside of visible area of window + var swiperOffset = _this.h.getOffset(_this.container); + var scrollLeft = _this.h.windowScroll().left; + var scrollTop = _this.h.windowScroll().top; + var windowWidth = _this.h.windowWidth(); + var windowHeight = _this.h.windowHeight(); + var swiperCoord = [ + [swiperOffset.left, swiperOffset.top], + [swiperOffset.left + _this.width, swiperOffset.top], + [swiperOffset.left, swiperOffset.top + _this.height], + [swiperOffset.left + _this.width, swiperOffset.top + _this.height] + ]; + for (var i = 0; i < swiperCoord.length; i++) { + var point = swiperCoord[i]; + if ( + point[0] >= scrollLeft && point[0] <= scrollLeft + windowWidth && + point[1] >= scrollTop && point[1] <= scrollTop + windowHeight + ) { + inView = true; + } + + } + if (!inView) return; + } + if (isH) { + if (kc === 37 || kc === 39) { + if (e.preventDefault) e.preventDefault(); + else e.returnValue = false; + } + if (kc === 39) _this.swipeNext(); + if (kc === 37) _this.swipePrev(); + } + else { + if (kc === 38 || kc === 40) { + if (e.preventDefault) e.preventDefault(); + else e.returnValue = false; + } + if (kc === 40) _this.swipeNext(); + if (kc === 38) _this.swipePrev(); + } + } + + /*========================================== + Mousewheel Control + ============================================*/ + var lastScrollTime = (new Date()).getTime(); + function handleMousewheel(e) { + var we = _this._wheelEvent; + var delta = 0; + + //Opera & IE + if (e.detail) delta = -e.detail; + //WebKits + else if (we === 'mousewheel') { + if (params.mousewheelControlForceToAxis) { + if (isH) { + if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) delta = e.wheelDeltaX; + else return; + } + else { + if (Math.abs(e.wheelDeltaY) > Math.abs(e.wheelDeltaX)) delta = e.wheelDeltaY; + else return; + } + } + else { + delta = e.wheelDelta; + } + } + //Old FireFox + else if (we === 'DOMMouseScroll') delta = -e.detail; + //New FireFox + else if (we === 'wheel') { + if (params.mousewheelControlForceToAxis) { + if (isH) { + if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) delta = -e.deltaX; + else return; + } + else { + if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) delta = -e.deltaY; + else return; + } + } + else { + delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? - e.deltaX : - e.deltaY; + } + } + + if (!params.freeMode) { + if ((new Date()).getTime() - lastScrollTime > 60) { + if (delta < 0) _this.swipeNext(); + else _this.swipePrev(); + } + lastScrollTime = (new Date()).getTime(); + + } + else { + //Freemode or scrollContainer: + var position = _this.getWrapperTranslate() + delta; + + if (position > 0) position = 0; + if (position < -maxWrapperPosition()) position = -maxWrapperPosition(); + + _this.setWrapperTransition(0); + _this.setWrapperTranslate(position); + _this.updateActiveSlide(position); + + // Return page scroll on edge positions + if (position === 0 || position === -maxWrapperPosition()) return; + } + if (params.autoplay) _this.stopAutoplay(true); + + if (e.preventDefault) e.preventDefault(); + else e.returnValue = false; + return false; + } + + /*========================= + Grab Cursor + ===========================*/ + if (params.grabCursor) { + var containerStyle = _this.container.style; + containerStyle.cursor = 'move'; + containerStyle.cursor = 'grab'; + containerStyle.cursor = '-moz-grab'; + containerStyle.cursor = '-webkit-grab'; + } + + /*========================= + Slides Events Handlers + ===========================*/ + + _this.allowSlideClick = true; + function slideClick(event) { + if (_this.allowSlideClick) { + setClickedSlide(event); + _this.fireCallback(params.onSlideClick, _this, event); + } + } + + function slideTouch(event) { + setClickedSlide(event); + _this.fireCallback(params.onSlideTouch, _this, event); + } + + function setClickedSlide(event) { + + // IE 6-8 support + if (!event.currentTarget) { + var element = event.srcElement; + do { + if (element.className.indexOf(params.slideClass) > -1) { + break; + } + element = element.parentNode; + } while (element); + _this.clickedSlide = element; + } + else { + _this.clickedSlide = event.currentTarget; + } + + _this.clickedSlideIndex = _this.slides.indexOf(_this.clickedSlide); + _this.clickedSlideLoopIndex = _this.clickedSlideIndex - (_this.loopedSlides || 0); + } + + _this.allowLinks = true; + function preventClick(e) { + if (!_this.allowLinks) { + if (e.preventDefault) e.preventDefault(); + else e.returnValue = false; + if (params.preventLinksPropagation && 'stopPropagation' in e) { + e.stopPropagation(); + } + return false; + } + } + function releaseForms(e) { + if (e.stopPropagation) e.stopPropagation(); + else e.returnValue = false; + return false; + + } + + /*================================================== + Event Handlers + ====================================================*/ + var isTouchEvent = false; + var allowThresholdMove; + var allowMomentumBounce = true; + function onTouchStart(event) { + if (params.preventLinks) _this.allowLinks = true; + //Exit if slider is already was touched + if (_this.isTouched || params.onlyExternal) { + return false; + } + + if (params.noSwiping && (event.target || event.srcElement) && noSwipingSlide(event.target || event.srcElement)) return false; + allowMomentumBounce = false; + //Check For Nested Swipers + _this.isTouched = true; + isTouchEvent = event.type === 'touchstart'; + + if (!isTouchEvent || event.targetTouches.length === 1) { + _this.callPlugins('onTouchStartBegin'); + + if (!isTouchEvent && !_this.isAndroid) { + if (event.preventDefault) event.preventDefault(); + else event.returnValue = false; + } + + var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX); + var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY); + + //Start Touches to check the scrolling + _this.touches.startX = _this.touches.currentX = pageX; + _this.touches.startY = _this.touches.currentY = pageY; + + _this.touches.start = _this.touches.current = isH ? pageX : pageY; + + //Set Transition Time to 0 + _this.setWrapperTransition(0); + + //Get Start Translate Position + _this.positions.start = _this.positions.current = _this.getWrapperTranslate(); + + //Set Transform + _this.setWrapperTranslate(_this.positions.start); + + //TouchStartTime + _this.times.start = (new Date()).getTime(); + + //Unset Scrolling + isScrolling = undefined; + + //Set Treshold + if (params.moveStartThreshold > 0) { + allowThresholdMove = false; + } + + //CallBack + if (params.onTouchStart) _this.fireCallback(params.onTouchStart, _this); + _this.callPlugins('onTouchStartEnd'); + + } + } + var velocityPrevPosition, velocityPrevTime; + function onTouchMove(event) { + // If slider is not touched - exit + if (!_this.isTouched || params.onlyExternal) return; + if (isTouchEvent && event.type === 'mousemove') return; + + var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX); + var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY); + + //check for scrolling + if (typeof isScrolling === 'undefined' && isH) { + isScrolling = !!(isScrolling || Math.abs(pageY - _this.touches.startY) > Math.abs(pageX - _this.touches.startX)); + } + if (typeof isScrolling === 'undefined' && !isH) { + isScrolling = !!(isScrolling || Math.abs(pageY - _this.touches.startY) < Math.abs(pageX - _this.touches.startX)); + } + if (isScrolling) { + _this.isTouched = false; + return; + } + + //Check For Nested Swipers + if (event.assignedToSwiper) { + _this.isTouched = false; + return; + } + event.assignedToSwiper = true; + + //Block inner links + if (params.preventLinks) { + _this.allowLinks = false; + } + if (params.onSlideClick) { + _this.allowSlideClick = false; + } + + //Stop AutoPlay if exist + if (params.autoplay) { + _this.stopAutoplay(true); + } + if (!isTouchEvent || event.touches.length === 1) { + + //Moved Flag + if (!_this.isMoved) { + _this.callPlugins('onTouchMoveStart'); + + if (params.loop) { + _this.fixLoop(); + _this.positions.start = _this.getWrapperTranslate(); + } + if (params.onTouchMoveStart) _this.fireCallback(params.onTouchMoveStart, _this); + } + _this.isMoved = true; + + // cancel event + if (event.preventDefault) event.preventDefault(); + else event.returnValue = false; + + _this.touches.current = isH ? pageX : pageY; + + _this.positions.current = (_this.touches.current - _this.touches.start) * params.touchRatio + _this.positions.start; + + //Resistance Callbacks + if (_this.positions.current > 0 && params.onResistanceBefore) { + _this.fireCallback(params.onResistanceBefore, _this, _this.positions.current); + } + if (_this.positions.current < -maxWrapperPosition() && params.onResistanceAfter) { + _this.fireCallback(params.onResistanceAfter, _this, Math.abs(_this.positions.current + maxWrapperPosition())); + } + //Resistance + if (params.resistance && params.resistance !== '100%') { + var resistance; + //Resistance for Negative-Back sliding + if (_this.positions.current > 0) { + resistance = 1 - _this.positions.current / containerSize / 2; + if (resistance < 0.5) + _this.positions.current = (containerSize / 2); + else + _this.positions.current = _this.positions.current * resistance; + } + //Resistance for After-End Sliding + if (_this.positions.current < -maxWrapperPosition()) { + + var diff = (_this.touches.current - _this.touches.start) * params.touchRatio + (maxWrapperPosition() + _this.positions.start); + resistance = (containerSize + diff) / (containerSize); + var newPos = _this.positions.current - diff * (1 - resistance) / 2; + var stopPos = -maxWrapperPosition() - containerSize / 2; + + if (newPos < stopPos || resistance <= 0) + _this.positions.current = stopPos; + else + _this.positions.current = newPos; + } + } + if (params.resistance && params.resistance === '100%') { + //Resistance for Negative-Back sliding + if (_this.positions.current > 0 && !(params.freeMode && !params.freeModeFluid)) { + _this.positions.current = 0; + } + //Resistance for After-End Sliding + if (_this.positions.current < -maxWrapperPosition() && !(params.freeMode && !params.freeModeFluid)) { + _this.positions.current = -maxWrapperPosition(); + } + } + //Move Slides + if (!params.followFinger) return; + + if (!params.moveStartThreshold) { + _this.setWrapperTranslate(_this.positions.current); + } + else { + if (Math.abs(_this.touches.current - _this.touches.start) > params.moveStartThreshold || allowThresholdMove) { + if (!allowThresholdMove) { + allowThresholdMove = true; + _this.touches.start = _this.touches.current; + return; + } + _this.setWrapperTranslate(_this.positions.current); + } + else { + _this.positions.current = _this.positions.start; + } + } + + if (params.freeMode || params.watchActiveIndex) { + _this.updateActiveSlide(_this.positions.current); + } + + //Grab Cursor + if (params.grabCursor) { + _this.container.style.cursor = 'move'; + _this.container.style.cursor = 'grabbing'; + _this.container.style.cursor = '-moz-grabbin'; + _this.container.style.cursor = '-webkit-grabbing'; + } + //Velocity + if (!velocityPrevPosition) velocityPrevPosition = _this.touches.current; + if (!velocityPrevTime) velocityPrevTime = (new Date()).getTime(); + _this.velocity = (_this.touches.current - velocityPrevPosition) / ((new Date()).getTime() - velocityPrevTime) / 2; + if (Math.abs(_this.touches.current - velocityPrevPosition) < 2) _this.velocity = 0; + velocityPrevPosition = _this.touches.current; + velocityPrevTime = (new Date()).getTime(); + //Callbacks + _this.callPlugins('onTouchMoveEnd'); + if (params.onTouchMove) _this.fireCallback(params.onTouchMove, _this); + + return false; + } + } + function onTouchEnd(event) { + //Check For scrolling + if (isScrolling) { + _this.swipeReset(); + } + // If slider is not touched exit + if (params.onlyExternal || !_this.isTouched) return; + _this.isTouched = false; + + //Return Grab Cursor + if (params.grabCursor) { + _this.container.style.cursor = 'move'; + _this.container.style.cursor = 'grab'; + _this.container.style.cursor = '-moz-grab'; + _this.container.style.cursor = '-webkit-grab'; + } + + //Check for Current Position + if (!_this.positions.current && _this.positions.current !== 0) { + _this.positions.current = _this.positions.start; + } + + //For case if slider touched but not moved + if (params.followFinger) { + _this.setWrapperTranslate(_this.positions.current); + } + + // TouchEndTime + _this.times.end = (new Date()).getTime(); + + //Difference + _this.touches.diff = _this.touches.current - _this.touches.start; + _this.touches.abs = Math.abs(_this.touches.diff); + + _this.positions.diff = _this.positions.current - _this.positions.start; + _this.positions.abs = Math.abs(_this.positions.diff); + + var diff = _this.positions.diff; + var diffAbs = _this.positions.abs; + var timeDiff = _this.times.end - _this.times.start; + + if (diffAbs < 5 && (timeDiff) < 300 && _this.allowLinks === false) { + if (!params.freeMode && diffAbs !== 0) _this.swipeReset(); + //Release inner links + if (params.preventLinks) { + _this.allowLinks = true; + } + if (params.onSlideClick) { + _this.allowSlideClick = true; + } + } + + setTimeout(function () { + //Release inner links + if (params.preventLinks) { + _this.allowLinks = true; + } + if (params.onSlideClick) { + _this.allowSlideClick = true; + } + }, 100); + + var maxPosition = maxWrapperPosition(); + + //Not moved or Prevent Negative Back Sliding/After-End Sliding + if (!_this.isMoved && params.freeMode) { + _this.isMoved = false; + if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this); + _this.callPlugins('onTouchEnd'); + return; + } + if (!_this.isMoved || _this.positions.current > 0 || _this.positions.current < -maxPosition) { + _this.swipeReset(); + if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this); + _this.callPlugins('onTouchEnd'); + return; + } + + _this.isMoved = false; + + //Free Mode + if (params.freeMode) { + if (params.freeModeFluid) { + var momentumDuration = 1000 * params.momentumRatio; + var momentumDistance = _this.velocity * momentumDuration; + var newPosition = _this.positions.current + momentumDistance; + var doBounce = false; + var afterBouncePosition; + var bounceAmount = Math.abs(_this.velocity) * 20 * params.momentumBounceRatio; + if (newPosition < -maxPosition) { + if (params.momentumBounce && _this.support.transitions) { + if (newPosition + maxPosition < -bounceAmount) newPosition = -maxPosition - bounceAmount; + afterBouncePosition = -maxPosition; + doBounce = true; + allowMomentumBounce = true; + } + else newPosition = -maxPosition; + } + if (newPosition > 0) { + if (params.momentumBounce && _this.support.transitions) { + if (newPosition > bounceAmount) newPosition = bounceAmount; + afterBouncePosition = 0; + doBounce = true; + allowMomentumBounce = true; + } + else newPosition = 0; + } + //Fix duration + if (_this.velocity !== 0) momentumDuration = Math.abs((newPosition - _this.positions.current) / _this.velocity); + + _this.setWrapperTranslate(newPosition); + + _this.setWrapperTransition(momentumDuration); + + if (params.momentumBounce && doBounce) { + _this.wrapperTransitionEnd(function () { + if (!allowMomentumBounce) return; + if (params.onMomentumBounce) _this.fireCallback(params.onMomentumBounce, _this); + _this.callPlugins('onMomentumBounce'); + + _this.setWrapperTranslate(afterBouncePosition); + _this.setWrapperTransition(300); + }); + } + + _this.updateActiveSlide(newPosition); + } + if (!params.freeModeFluid || timeDiff >= 300) _this.updateActiveSlide(_this.positions.current); + + if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this); + _this.callPlugins('onTouchEnd'); + return; + } + + //Direction + direction = diff < 0 ? 'toNext' : 'toPrev'; + + //Short Touches + if (direction === 'toNext' && (timeDiff <= 300)) { + if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset(); + else _this.swipeNext(true); + } + + if (direction === 'toPrev' && (timeDiff <= 300)) { + if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset(); + else _this.swipePrev(true); + } + + //Long Touches + var targetSlideSize = 0; + if (params.slidesPerView === 'auto') { + //Define current slide's width + var currentPosition = Math.abs(_this.getWrapperTranslate()); + var slidesOffset = 0; + var _slideSize; + for (var i = 0; i < _this.slides.length; i++) { + _slideSize = isH ? _this.slides[i].getWidth(true) : _this.slides[i].getHeight(true); + slidesOffset += _slideSize; + if (slidesOffset > currentPosition) { + targetSlideSize = _slideSize; + break; + } + } + if (targetSlideSize > containerSize) targetSlideSize = containerSize; + } + else { + targetSlideSize = slideSize * params.slidesPerView; + } + if (direction === 'toNext' && (timeDiff > 300)) { + if (diffAbs >= targetSlideSize * params.longSwipesRatio) { + _this.swipeNext(true); + } + else { + _this.swipeReset(); + } + } + if (direction === 'toPrev' && (timeDiff > 300)) { + if (diffAbs >= targetSlideSize * params.longSwipesRatio) { + _this.swipePrev(true); + } + else { + _this.swipeReset(); + } + } + if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this); + _this.callPlugins('onTouchEnd'); + } + + + /*================================================== + noSwiping Bubble Check by Isaac Strack + ====================================================*/ + function noSwipingSlide(el) { + /*This function is specifically designed to check the parent elements for the noSwiping class, up to the wrapper. + We need to check parents because while onTouchStart bubbles, _this.isTouched is checked in onTouchStart, which stops the bubbling. + So, if a text box, for example, is the initial target, and the parent slide container has the noSwiping class, the _this.isTouched + check will never find it, and what was supposed to be noSwiping is able to be swiped. + This function will iterate up and check for the noSwiping class in parents, up through the wrapperClass.*/ + + // First we create a truthy variable, which is that swiping is allowd (noSwiping = false) + var noSwiping = false; + + // Now we iterate up (parentElements) until we reach the node with the wrapperClass. + do { + + // Each time, we check to see if there's a 'swiper-no-swiping' class (noSwipingClass). + if (el.className.indexOf(params.noSwipingClass) > -1) + { + noSwiping = true; // If there is, we set noSwiping = true; + } + + el = el.parentElement; // now we iterate up (parent node) + + } while (!noSwiping && el.parentElement && el.className.indexOf(params.wrapperClass) === -1); // also include el.parentElement truthy, just in case. + + // because we didn't check the wrapper itself, we do so now, if noSwiping is false: + if (!noSwiping && el.className.indexOf(params.wrapperClass) > -1 && el.className.indexOf(params.noSwipingClass) > -1) + noSwiping = true; // if the wrapper has the noSwipingClass, we set noSwiping = true; + + return noSwiping; + } + + function addClassToHtmlString(klass, outerHtml) { + var par = document.createElement('div'); + var child; + + par.innerHTML = outerHtml; + child = par.firstChild; + child.className += ' ' + klass; + + return child.outerHTML; + } + + + /*================================================== + Swipe Functions + ====================================================*/ + _this.swipeNext = function (internal) { + if (!internal && params.loop) _this.fixLoop(); + if (!internal && params.autoplay) _this.stopAutoplay(true); + _this.callPlugins('onSwipeNext'); + var currentPosition = _this.getWrapperTranslate(); + var newPosition = currentPosition; + if (params.slidesPerView === 'auto') { + for (var i = 0; i < _this.snapGrid.length; i++) { + if (-currentPosition >= _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) { + newPosition = -_this.snapGrid[i + 1]; + break; + } + } + } + else { + var groupSize = slideSize * params.slidesPerGroup; + newPosition = -(Math.floor(Math.abs(currentPosition) / Math.floor(groupSize)) * groupSize + groupSize); + } + if (newPosition < -maxWrapperPosition()) { + newPosition = -maxWrapperPosition(); + } + if (newPosition === currentPosition) return false; + swipeToPosition(newPosition, 'next'); + return true; + }; + _this.swipePrev = function (internal) { + if (!internal && params.loop) _this.fixLoop(); + if (!internal && params.autoplay) _this.stopAutoplay(true); + _this.callPlugins('onSwipePrev'); + + var currentPosition = Math.ceil(_this.getWrapperTranslate()); + var newPosition; + if (params.slidesPerView === 'auto') { + newPosition = 0; + for (var i = 1; i < _this.snapGrid.length; i++) { + if (-currentPosition === _this.snapGrid[i]) { + newPosition = -_this.snapGrid[i - 1]; + break; + } + if (-currentPosition > _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) { + newPosition = -_this.snapGrid[i]; + break; + } + } + } + else { + var groupSize = slideSize * params.slidesPerGroup; + newPosition = -(Math.ceil(-currentPosition / groupSize) - 1) * groupSize; + } + + if (newPosition > 0) newPosition = 0; + + if (newPosition === currentPosition) return false; + swipeToPosition(newPosition, 'prev'); + return true; + + }; + _this.swipeReset = function () { + _this.callPlugins('onSwipeReset'); + var currentPosition = _this.getWrapperTranslate(); + var groupSize = slideSize * params.slidesPerGroup; + var newPosition; + var maxPosition = -maxWrapperPosition(); + if (params.slidesPerView === 'auto') { + newPosition = 0; + for (var i = 0; i < _this.snapGrid.length; i++) { + if (-currentPosition === _this.snapGrid[i]) return; + if (-currentPosition >= _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) { + if (_this.positions.diff > 0) newPosition = -_this.snapGrid[i + 1]; + else newPosition = -_this.snapGrid[i]; + break; + } + } + if (-currentPosition >= _this.snapGrid[_this.snapGrid.length - 1]) newPosition = -_this.snapGrid[_this.snapGrid.length - 1]; + if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition(); + } + else { + newPosition = currentPosition < 0 ? Math.round(currentPosition / groupSize) * groupSize : 0; + } + if (params.scrollContainer) { + newPosition = currentPosition < 0 ? currentPosition : 0; + } + if (newPosition < -maxWrapperPosition()) { + newPosition = -maxWrapperPosition(); + } + if (params.scrollContainer && (containerSize > slideSize)) { + newPosition = 0; + } + + if (newPosition === currentPosition) return false; + + swipeToPosition(newPosition, 'reset'); + return true; + }; + + _this.swipeTo = function (index, speed, runCallbacks) { + index = parseInt(index, 10); + _this.callPlugins('onSwipeTo', {index: index, speed: speed}); + if (params.loop) index = index + _this.loopedSlides; + var currentPosition = _this.getWrapperTranslate(); + if (index > (_this.slides.length - 1) || index < 0) return; + var newPosition; + if (params.slidesPerView === 'auto') { + newPosition = -_this.slidesGrid[index]; + } + else { + newPosition = -index * slideSize; + } + if (newPosition < - maxWrapperPosition()) { + newPosition = - maxWrapperPosition(); + } + + if (newPosition === currentPosition) return false; + + runCallbacks = runCallbacks === false ? false : true; + swipeToPosition(newPosition, 'to', {index: index, speed: speed, runCallbacks: runCallbacks}); + return true; + }; + + function swipeToPosition(newPosition, action, toOptions) { + var speed = (action === 'to' && toOptions.speed >= 0) ? toOptions.speed : params.speed; + var timeOld = + new Date(); + + function anim() { + var timeNew = + new Date(); + var time = timeNew - timeOld; + currentPosition += animationStep * time / (1000 / 60); + condition = direction === 'toNext' ? currentPosition > newPosition : currentPosition < newPosition; + if (condition) { + _this.setWrapperTranslate(Math.round(currentPosition)); + _this._DOMAnimating = true; + window.setTimeout(function () { + anim(); + }, 1000 / 60); + } + else { + if (params.onSlideChangeEnd) _this.fireCallback(params.onSlideChangeEnd, _this); + _this.setWrapperTranslate(newPosition); + _this._DOMAnimating = false; + } + } + + if (_this.support.transitions || !params.DOMAnimation) { + _this.setWrapperTranslate(newPosition); + _this.setWrapperTransition(speed); + } + else { + //Try the DOM animation + var currentPosition = _this.getWrapperTranslate(); + var animationStep = Math.ceil((newPosition - currentPosition) / speed * (1000 / 60)); + var direction = currentPosition > newPosition ? 'toNext' : 'toPrev'; + var condition = direction === 'toNext' ? currentPosition > newPosition : currentPosition < newPosition; + if (_this._DOMAnimating) return; + + anim(); + } + + //Update Active Slide Index + _this.updateActiveSlide(newPosition); + + //Callbacks + if (params.onSlideNext && action === 'next') { + _this.fireCallback(params.onSlideNext, _this, newPosition); + } + if (params.onSlidePrev && action === 'prev') { + _this.fireCallback(params.onSlidePrev, _this, newPosition); + } + //'Reset' Callback + if (params.onSlideReset && action === 'reset') { + _this.fireCallback(params.onSlideReset, _this, newPosition); + } + + //'Next', 'Prev' and 'To' Callbacks + if (action === 'next' || action === 'prev' || (action === 'to' && toOptions.runCallbacks === true)) + slideChangeCallbacks(action); + } + /*================================================== + Transition Callbacks + ====================================================*/ + //Prevent Multiple Callbacks + _this._queueStartCallbacks = false; + _this._queueEndCallbacks = false; + function slideChangeCallbacks(direction) { + //Transition Start Callback + _this.callPlugins('onSlideChangeStart'); + if (params.onSlideChangeStart) { + if (params.queueStartCallbacks && _this.support.transitions) { + if (_this._queueStartCallbacks) return; + _this._queueStartCallbacks = true; + _this.fireCallback(params.onSlideChangeStart, _this, direction); + _this.wrapperTransitionEnd(function () { + _this._queueStartCallbacks = false; + }); + } + else _this.fireCallback(params.onSlideChangeStart, _this, direction); + } + //Transition End Callback + if (params.onSlideChangeEnd) { + if (_this.support.transitions) { + if (params.queueEndCallbacks) { + if (_this._queueEndCallbacks) return; + _this._queueEndCallbacks = true; + _this.wrapperTransitionEnd(function (swiper) { + _this.fireCallback(params.onSlideChangeEnd, swiper, direction); + }); + } + else { + _this.wrapperTransitionEnd(function (swiper) { + _this.fireCallback(params.onSlideChangeEnd, swiper, direction); + }); + } + } + else { + if (!params.DOMAnimation) { + setTimeout(function () { + _this.fireCallback(params.onSlideChangeEnd, _this, direction); + }, 10); + } + } + } + } + + /*================================================== + Update Active Slide Index + ====================================================*/ + _this.updateActiveSlide = function (position) { + if (!_this.initialized) return; + if (_this.slides.length === 0) return; + _this.previousIndex = _this.activeIndex; + if (typeof position === 'undefined') position = _this.getWrapperTranslate(); + if (position > 0) position = 0; + + if (params.slidesPerView === 'auto') { + var slidesOffset = 0; + _this.activeIndex = _this.slidesGrid.indexOf(-position); + if (_this.activeIndex < 0) { + for (var i = 0; i < _this.slidesGrid.length - 1; i++) { + if (-position > _this.slidesGrid[i] && -position < _this.slidesGrid[i + 1]) { + break; + } + } + var leftDistance = Math.abs(_this.slidesGrid[i] + position); + var rightDistance = Math.abs(_this.slidesGrid[i + 1] + position); + if (leftDistance <= rightDistance) _this.activeIndex = i; + else _this.activeIndex = i + 1; + } + } + else { + _this.activeIndex = Math[params.visibilityFullFit ? 'ceil' : 'round'](-position / slideSize); + } + + if (_this.activeIndex === _this.slides.length) _this.activeIndex = _this.slides.length - 1; + if (_this.activeIndex < 0) _this.activeIndex = 0; + + // Check for slide + if (!_this.slides[_this.activeIndex]) return; + + // Calc Visible slides + _this.calcVisibleSlides(position); + + // Mark visible and active slides with additonal classes + var activeClassRegexp = new RegExp('\\s*' + params.slideActiveClass); + var inViewClassRegexp = new RegExp('\\s*' + params.slideVisibleClass); + + for (var j = 0; j < _this.slides.length; j++) { + _this.slides[j].className = _this.slides[j].className.replace(activeClassRegexp, '').replace(inViewClassRegexp, ''); + if (_this.visibleSlides.indexOf(_this.slides[j]) >= 0) { + _this.slides[j].className += ' ' + params.slideVisibleClass; + } + + } + _this.slides[_this.activeIndex].className += ' ' + params.slideActiveClass; + + //Update loop index + if (params.loop) { + var ls = _this.loopedSlides; + _this.activeLoopIndex = _this.activeIndex - ls; + if (_this.activeLoopIndex >= _this.slides.length - ls * 2) { + _this.activeLoopIndex = _this.slides.length - ls * 2 - _this.activeLoopIndex; + } + if (_this.activeLoopIndex < 0) { + _this.activeLoopIndex = _this.slides.length - ls * 2 + _this.activeLoopIndex; + } + if (_this.activeLoopIndex < 0) _this.activeLoopIndex = 0; + } + else { + _this.activeLoopIndex = _this.activeIndex; + } + //Update Pagination + if (params.pagination) { + _this.updatePagination(position); + } + }; + /*================================================== + Pagination + ====================================================*/ + _this.createPagination = function (firstInit) { + if (params.paginationClickable && _this.paginationButtons) { + removePaginationEvents(); + } + _this.paginationContainer = params.pagination.nodeType ? params.pagination : $$(params.pagination)[0]; + if (params.createPagination) { + var paginationHTML = ''; + var numOfSlides = _this.slides.length; + var numOfButtons = numOfSlides; + if (params.loop) numOfButtons -= _this.loopedSlides * 2; + for (var i = 0; i < numOfButtons; i++) { + paginationHTML += '<' + params.paginationElement + ' class="' + params.paginationElementClass + '">'; + } + _this.paginationContainer.innerHTML = paginationHTML; + } + _this.paginationButtons = $$('.' + params.paginationElementClass, _this.paginationContainer); + if (!firstInit) _this.updatePagination(); + _this.callPlugins('onCreatePagination'); + if (params.paginationClickable) { + addPaginationEvents(); + } + }; + function removePaginationEvents() { + var pagers = _this.paginationButtons; + if (pagers) { + for (var i = 0; i < pagers.length; i++) { + _this.h.removeEventListener(pagers[i], 'click', paginationClick); + } + } + } + function addPaginationEvents() { + var pagers = _this.paginationButtons; + if (pagers) { + for (var i = 0; i < pagers.length; i++) { + _this.h.addEventListener(pagers[i], 'click', paginationClick); + } + } + } + function paginationClick(e) { + var index; + var target = e.target || e.srcElement; + var pagers = _this.paginationButtons; + for (var i = 0; i < pagers.length; i++) { + if (target === pagers[i]) index = i; + } + _this.swipeTo(index); + } + _this.updatePagination = function (position) { + if (!params.pagination) return; + if (_this.slides.length < 1) return; + var activePagers = $$('.' + params.paginationActiveClass, _this.paginationContainer); + if (!activePagers) return; + + //Reset all Buttons' class to not active + var pagers = _this.paginationButtons; + if (pagers.length === 0) return; + for (var i = 0; i < pagers.length; i++) { + pagers[i].className = params.paginationElementClass; + } + + var indexOffset = params.loop ? _this.loopedSlides : 0; + if (params.paginationAsRange) { + if (!_this.visibleSlides) _this.calcVisibleSlides(position); + //Get Visible Indexes + var visibleIndexes = []; + var j; // lopp index - avoid JSHint W004 / W038 + for (j = 0; j < _this.visibleSlides.length; j++) { + var visIndex = _this.slides.indexOf(_this.visibleSlides[j]) - indexOffset; + + if (params.loop && visIndex < 0) { + visIndex = _this.slides.length - _this.loopedSlides * 2 + visIndex; + } + if (params.loop && visIndex >= _this.slides.length - _this.loopedSlides * 2) { + visIndex = _this.slides.length - _this.loopedSlides * 2 - visIndex; + visIndex = Math.abs(visIndex); + } + visibleIndexes.push(visIndex); + } + + for (j = 0; j < visibleIndexes.length; j++) { + if (pagers[visibleIndexes[j]]) pagers[visibleIndexes[j]].className += ' ' + params.paginationVisibleClass; + } + + if (params.loop) { + if (pagers[_this.activeLoopIndex] !== undefined) { + pagers[_this.activeLoopIndex].className += ' ' + params.paginationActiveClass; + } + } + else { + pagers[_this.activeIndex].className += ' ' + params.paginationActiveClass; + } + } + else { + if (params.loop) { + if (pagers[_this.activeLoopIndex]) pagers[_this.activeLoopIndex].className += ' ' + params.paginationActiveClass + ' ' + params.paginationVisibleClass; + } + else { + pagers[_this.activeIndex].className += ' ' + params.paginationActiveClass + ' ' + params.paginationVisibleClass; + } + } + }; + _this.calcVisibleSlides = function (position) { + var visibleSlides = []; + var _slideLeft = 0, _slideSize = 0, _slideRight = 0; + if (isH && _this.wrapperLeft > 0) position = position + _this.wrapperLeft; + if (!isH && _this.wrapperTop > 0) position = position + _this.wrapperTop; + + for (var i = 0; i < _this.slides.length; i++) { + _slideLeft += _slideSize; + if (params.slidesPerView === 'auto') + _slideSize = isH ? _this.h.getWidth(_this.slides[i], true) : _this.h.getHeight(_this.slides[i], true); + else _slideSize = slideSize; + + _slideRight = _slideLeft + _slideSize; + var isVisibile = false; + if (params.visibilityFullFit) { + if (_slideLeft >= -position && _slideRight <= -position + containerSize) isVisibile = true; + if (_slideLeft <= -position && _slideRight >= -position + containerSize) isVisibile = true; + } + else { + if (_slideRight > -position && _slideRight <= ((-position + containerSize))) isVisibile = true; + if (_slideLeft >= -position && _slideLeft < ((-position + containerSize))) isVisibile = true; + if (_slideLeft < -position && _slideRight > ((-position + containerSize))) isVisibile = true; + } + + if (isVisibile) visibleSlides.push(_this.slides[i]); + + } + if (visibleSlides.length === 0) visibleSlides = [_this.slides[_this.activeIndex]]; + + _this.visibleSlides = visibleSlides; + }; + + /*========================================== + Autoplay + ============================================*/ + var autoplayTimeoutId, autoplayIntervalId; + _this.startAutoplay = function () { + if (_this.support.transitions) { + if (typeof autoplayTimeoutId !== 'undefined') return false; + if (!params.autoplay) return; + _this.callPlugins('onAutoplayStart'); + autoplay(); + } + else { + if (typeof autoplayIntervalId !== 'undefined') return false; + if (!params.autoplay) return; + _this.callPlugins('onAutoplayStart'); + autoplayIntervalId = setInterval(function () { + if (params.loop) { + _this.fixLoop(); + _this.swipeNext(true); + } + else if (!_this.swipeNext(true)) { + if (!params.autoplayStopOnLast) _this.swipeTo(0); + else { + clearInterval(autoplayIntervalId); + autoplayIntervalId = undefined; + } + } + }, params.autoplay); + } + }; + _this.stopAutoplay = function (internal) { + if (_this.support.transitions) { + if (!autoplayTimeoutId) return; + if (autoplayTimeoutId) clearTimeout(autoplayTimeoutId); + autoplayTimeoutId = undefined; + if (internal && !params.autoplayDisableOnInteraction) { + _this.wrapperTransitionEnd(function () { + autoplay(); + }); + } + _this.callPlugins('onAutoplayStop'); + } + else { + if (autoplayIntervalId) clearInterval(autoplayIntervalId); + autoplayIntervalId = undefined; + _this.callPlugins('onAutoplayStop'); + } + }; + function autoplay() { + autoplayTimeoutId = setTimeout(function () { + if (params.loop) { + _this.fixLoop(); + _this.swipeNext(true); + } + else if (!_this.swipeNext(true)) { + if (!params.autoplayStopOnLast) _this.swipeTo(0); + else { + clearTimeout(autoplayTimeoutId); + autoplayTimeoutId = undefined; + } + } + _this.wrapperTransitionEnd(function () { + if (typeof autoplayTimeoutId !== 'undefined') autoplay(); + }); + }, params.autoplay); + } + /*================================================== + Loop + ====================================================*/ + _this.loopCreated = false; + _this.removeLoopedSlides = function () { + if (_this.loopCreated) { + for (var i = 0; i < _this.slides.length; i++) { + if (_this.slides[i].getData('looped') === true) _this.wrapper.removeChild(_this.slides[i]); + } + } + }; + + _this.createLoop = function () { + if (_this.slides.length === 0) return; + if (params.slidesPerView === 'auto') { + _this.loopedSlides = params.loopedSlides || 1; + } + else { + _this.loopedSlides = params.slidesPerView + params.loopAdditionalSlides; + } + + if (_this.loopedSlides > _this.slides.length) { + _this.loopedSlides = _this.slides.length; + } + + var slideFirstHTML = '', + slideLastHTML = '', + i; + var slidesSetFullHTML = ''; + /** + loopedSlides is too large if loopAdditionalSlides are set. + Need to divide the slides by maximum number of slides existing. + + @author Tomaz Lovrec + */ + var numSlides = _this.slides.length; + var fullSlideSets = Math.floor(_this.loopedSlides / numSlides); + var remainderSlides = _this.loopedSlides % numSlides; + // assemble full sets of slides + for (i = 0; i < (fullSlideSets * numSlides); i++) { + var j = i; + if (i >= numSlides) { + var over = Math.floor(i / numSlides); + j = i - (numSlides * over); + } + slidesSetFullHTML += _this.slides[j].outerHTML; + } + // assemble remainder slides + // assemble remainder appended to existing slides + for (i = 0; i < remainderSlides;i++) { + slideLastHTML += addClassToHtmlString(params.slideDuplicateClass, _this.slides[i].outerHTML); + } + // assemble slides that get preppended to existing slides + for (i = numSlides - remainderSlides; i < numSlides;i++) { + slideFirstHTML += addClassToHtmlString(params.slideDuplicateClass, _this.slides[i].outerHTML); + } + // assemble all slides + var slides = slideFirstHTML + slidesSetFullHTML + wrapper.innerHTML + slidesSetFullHTML + slideLastHTML; + // set the slides + wrapper.innerHTML = slides; + + _this.loopCreated = true; + _this.calcSlides(); + + //Update Looped Slides with special class + for (i = 0; i < _this.slides.length; i++) { + if (i < _this.loopedSlides || i >= _this.slides.length - _this.loopedSlides) _this.slides[i].setData('looped', true); + } + _this.callPlugins('onCreateLoop'); + + }; + + _this.fixLoop = function () { + var newIndex; + //Fix For Negative Oversliding + if (_this.activeIndex < _this.loopedSlides) { + newIndex = _this.slides.length - _this.loopedSlides * 3 + _this.activeIndex; + _this.swipeTo(newIndex, 0, false); + } + //Fix For Positive Oversliding + else if ((params.slidesPerView === 'auto' && _this.activeIndex >= _this.loopedSlides * 2) || (_this.activeIndex > _this.slides.length - params.slidesPerView * 2)) { + newIndex = -_this.slides.length + _this.activeIndex + _this.loopedSlides; + _this.swipeTo(newIndex, 0, false); + } + }; + + /*================================================== + Slides Loader + ====================================================*/ + _this.loadSlides = function () { + var slidesHTML = ''; + _this.activeLoaderIndex = 0; + var slides = params.loader.slides; + var slidesToLoad = params.loader.loadAllSlides ? slides.length : params.slidesPerView * (1 + params.loader.surroundGroups); + for (var i = 0; i < slidesToLoad; i++) { + if (params.loader.slidesHTMLType === 'outer') slidesHTML += slides[i]; + else { + slidesHTML += '<' + params.slideElement + ' class="' + params.slideClass + '" data-swiperindex="' + i + '">' + slides[i] + ''; + } + } + _this.wrapper.innerHTML = slidesHTML; + _this.calcSlides(true); + //Add permanent transitionEnd callback + if (!params.loader.loadAllSlides) { + _this.wrapperTransitionEnd(_this.reloadSlides, true); + } + }; + + _this.reloadSlides = function () { + var slides = params.loader.slides; + var newActiveIndex = parseInt(_this.activeSlide().data('swiperindex'), 10); + if (newActiveIndex < 0 || newActiveIndex > slides.length - 1) return; //<-- Exit + _this.activeLoaderIndex = newActiveIndex; + var firstIndex = Math.max(0, newActiveIndex - params.slidesPerView * params.loader.surroundGroups); + var lastIndex = Math.min(newActiveIndex + params.slidesPerView * (1 + params.loader.surroundGroups) - 1, slides.length - 1); + //Update Transforms + if (newActiveIndex > 0) { + var newTransform = -slideSize * (newActiveIndex - firstIndex); + _this.setWrapperTranslate(newTransform); + _this.setWrapperTransition(0); + } + var i; // loop index + //New Slides + if (params.loader.logic === 'reload') { + _this.wrapper.innerHTML = ''; + var slidesHTML = ''; + for (i = firstIndex; i <= lastIndex; i++) { + slidesHTML += params.loader.slidesHTMLType === 'outer' ? slides[i] : '<' + params.slideElement + ' class="' + params.slideClass + '" data-swiperindex="' + i + '">' + slides[i] + ''; + } + _this.wrapper.innerHTML = slidesHTML; + } + else { + var minExistIndex = 1000; + var maxExistIndex = 0; + + for (i = 0; i < _this.slides.length; i++) { + var index = _this.slides[i].data('swiperindex'); + if (index < firstIndex || index > lastIndex) { + _this.wrapper.removeChild(_this.slides[i]); + } + else { + minExistIndex = Math.min(index, minExistIndex); + maxExistIndex = Math.max(index, maxExistIndex); + } + } + for (i = firstIndex; i <= lastIndex; i++) { + var newSlide; + if (i < minExistIndex) { + newSlide = document.createElement(params.slideElement); + newSlide.className = params.slideClass; + newSlide.setAttribute('data-swiperindex', i); + newSlide.innerHTML = slides[i]; + _this.wrapper.insertBefore(newSlide, _this.wrapper.firstChild); + } + if (i > maxExistIndex) { + newSlide = document.createElement(params.slideElement); + newSlide.className = params.slideClass; + newSlide.setAttribute('data-swiperindex', i); + newSlide.innerHTML = slides[i]; + _this.wrapper.appendChild(newSlide); + } + } + } + //reInit + _this.reInit(true); + }; + + /*================================================== + Make Swiper + ====================================================*/ + function makeSwiper() { + _this.calcSlides(); + if (params.loader.slides.length > 0 && _this.slides.length === 0) { + _this.loadSlides(); + } + if (params.loop) { + _this.createLoop(); + } + _this.init(); + initEvents(); + if (params.pagination) { + _this.createPagination(true); + } + + if (params.loop || params.initialSlide > 0) { + _this.swipeTo(params.initialSlide, 0, false); + } + else { + _this.updateActiveSlide(0); + } + if (params.autoplay) { + _this.startAutoplay(); + } + /** + * Set center slide index. + * + * @author Tomaz Lovrec + */ + _this.centerIndex = _this.activeIndex; + + // Callbacks + if (params.onSwiperCreated) _this.fireCallback(params.onSwiperCreated, _this); + _this.callPlugins('onSwiperCreated'); + } + + makeSwiper(); +}; + +Swiper.prototype = { + plugins : {}, + + /*================================================== + Wrapper Operations + ====================================================*/ + wrapperTransitionEnd : function (callback, permanent) { + 'use strict'; + var a = this, + el = a.wrapper, + events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'], + i; + + function fireCallBack() { + callback(a); + if (a.params.queueEndCallbacks) a._queueEndCallbacks = false; + if (!permanent) { + for (i = 0; i < events.length; i++) { + a.h.removeEventListener(el, events[i], fireCallBack); + } + } + } + + if (callback) { + for (i = 0; i < events.length; i++) { + a.h.addEventListener(el, events[i], fireCallBack); + } + } + }, + + getWrapperTranslate : function (axis) { + 'use strict'; + var el = this.wrapper, + matrix, curTransform, curStyle, transformMatrix; + + // automatic axis detection + if (typeof axis === 'undefined') { + axis = this.params.mode === 'horizontal' ? 'x' : 'y'; + } + + if (this.support.transforms && this.params.useCSS3Transforms) { + curStyle = window.getComputedStyle(el, null); + if (window.WebKitCSSMatrix) { + transformMatrix = new WebKitCSSMatrix(curStyle.webkitTransform); + } + else { + transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,'); + matrix = transformMatrix.toString().split(','); + } + + if (axis === 'x') { + //Latest Chrome and webkits Fix + if (window.WebKitCSSMatrix) + curTransform = transformMatrix.m41; + //Crazy IE10 Matrix + else if (matrix.length === 16) + curTransform = parseFloat(matrix[12]); + //Normal Browsers + else + curTransform = parseFloat(matrix[4]); + } + if (axis === 'y') { + //Latest Chrome and webkits Fix + if (window.WebKitCSSMatrix) + curTransform = transformMatrix.m42; + //Crazy IE10 Matrix + else if (matrix.length === 16) + curTransform = parseFloat(matrix[13]); + //Normal Browsers + else + curTransform = parseFloat(matrix[5]); + } + } + else { + if (axis === 'x') curTransform = parseFloat(el.style.left, 10) || 0; + if (axis === 'y') curTransform = parseFloat(el.style.top, 10) || 0; + } + return curTransform || 0; + }, + + setWrapperTranslate : function (x, y, z) { + 'use strict'; + var es = this.wrapper.style, + coords = {x: 0, y: 0, z: 0}, + translate; + + // passed all coordinates + if (arguments.length === 3) { + coords.x = x; + coords.y = y; + coords.z = z; + } + + // passed one coordinate and optional axis + else { + if (typeof y === 'undefined') { + y = this.params.mode === 'horizontal' ? 'x' : 'y'; + } + coords[y] = x; + } + + if (this.support.transforms && this.params.useCSS3Transforms) { + translate = this.support.transforms3d ? 'translate3d(' + coords.x + 'px, ' + coords.y + 'px, ' + coords.z + 'px)' : 'translate(' + coords.x + 'px, ' + coords.y + 'px)'; + es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = translate; + } + else { + es.left = coords.x + 'px'; + es.top = coords.y + 'px'; + } + this.callPlugins('onSetWrapperTransform', coords); + if (this.params.onSetWrapperTransform) this.fireCallback(this.params.onSetWrapperTransform, this, coords); + }, + + setWrapperTransition : function (duration) { + 'use strict'; + var es = this.wrapper.style; + es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = (duration / 1000) + 's'; + this.callPlugins('onSetWrapperTransition', {duration: duration}); + if (this.params.onSetWrapperTransition) this.fireCallback(this.params.onSetWrapperTransition, this, duration); + + }, + + /*================================================== + Helpers + ====================================================*/ + h : { + getWidth: function (el, outer) { + 'use strict'; + var width = window.getComputedStyle(el, null).getPropertyValue('width'); + var returnWidth = parseFloat(width); + //IE Fixes + if (isNaN(returnWidth) || width.indexOf('%') > 0) { + returnWidth = el.offsetWidth - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right')); + } + if (outer) returnWidth += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right')); + + return returnWidth; + }, + getHeight: function (el, outer) { + 'use strict'; + if (outer) return el.offsetHeight; + + var height = window.getComputedStyle(el, null).getPropertyValue('height'); + var returnHeight = parseFloat(height); + //IE Fixes + if (isNaN(returnHeight) || height.indexOf('%') > 0) { + returnHeight = el.offsetHeight - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom')); + } + if (outer) returnHeight += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom')); + return returnHeight; + }, + getOffset: function (el) { + 'use strict'; + var box = el.getBoundingClientRect(); + var body = document.body; + var clientTop = el.clientTop || body.clientTop || 0; + var clientLeft = el.clientLeft || body.clientLeft || 0; + var scrollTop = window.pageYOffset || el.scrollTop; + var scrollLeft = window.pageXOffset || el.scrollLeft; + if (document.documentElement && !window.pageYOffset) { + //IE7-8 + scrollTop = document.documentElement.scrollTop; + scrollLeft = document.documentElement.scrollLeft; + } + return { + top: box.top + scrollTop - clientTop, + left: box.left + scrollLeft - clientLeft + }; + }, + windowWidth : function () { + 'use strict'; + if (window.innerWidth) return window.innerWidth; + else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; + }, + windowHeight : function () { + 'use strict'; + if (window.innerHeight) return window.innerHeight; + else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; + }, + windowScroll : function () { + 'use strict'; + var left = 0, top = 0; + if (typeof pageYOffset !== 'undefined') { + return { + left: window.pageXOffset, + top: window.pageYOffset + }; + } + else if (document.documentElement) { + return { + left: document.documentElement.scrollLeft, + top: document.documentElement.scrollTop + }; + } + }, + + addEventListener : function (el, event, listener, useCapture) { + 'use strict'; + if (typeof useCapture === 'undefined') { + useCapture = false; + } + + if (el.addEventListener) { + el.addEventListener(event, listener, useCapture); + } + else if (el.attachEvent) { + el.attachEvent('on' + event, listener); + } + }, + + removeEventListener : function (el, event, listener, useCapture) { + 'use strict'; + if (typeof useCapture === 'undefined') { + useCapture = false; + } + + if (el.removeEventListener) { + el.removeEventListener(event, listener, useCapture); + } + else if (el.detachEvent) { + el.detachEvent('on' + event, listener); + } + } + }, + setTransform : function (el, transform) { + 'use strict'; + var es = el.style; + es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transform; + }, + setTranslate : function (el, translate) { + 'use strict'; + var es = el.style; + var pos = { + x : translate.x || 0, + y : translate.y || 0, + z : translate.z || 0 + }; + var transformString = this.support.transforms3d ? 'translate3d(' + (pos.x) + 'px,' + (pos.y) + 'px,' + (pos.z) + 'px)' : 'translate(' + (pos.x) + 'px,' + (pos.y) + 'px)'; + es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transformString; + if (!this.support.transforms) { + es.left = pos.x + 'px'; + es.top = pos.y + 'px'; + } + }, + setTransition : function (el, duration) { + 'use strict'; + var es = el.style; + es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = duration + 'ms'; + }, + /*================================================== + Feature Detection + ====================================================*/ + support: { + + touch : (window.Modernizr && Modernizr.touch === true) || (function () { + 'use strict'; + return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch); + })(), + + transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () { + 'use strict'; + var div = document.createElement('div').style; + return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div); + })(), + + transforms : (window.Modernizr && Modernizr.csstransforms === true) || (function () { + 'use strict'; + var div = document.createElement('div').style; + return ('transform' in div || 'WebkitTransform' in div || 'MozTransform' in div || 'msTransform' in div || 'MsTransform' in div || 'OTransform' in div); + })(), + + transitions : (window.Modernizr && Modernizr.csstransitions === true) || (function () { + 'use strict'; + var div = document.createElement('div').style; + return ('transition' in div || 'WebkitTransition' in div || 'MozTransition' in div || 'msTransition' in div || 'MsTransition' in div || 'OTransition' in div); + })() + }, + + browser : { + + ie8 : (function () { + 'use strict'; + var rv = -1; // Return value assumes failure. + if (navigator.appName === 'Microsoft Internet Explorer') { + var ua = navigator.userAgent; + var re = new RegExp(/MSIE ([0-9]{1,}[\.0-9]{0,})/); + if (re.exec(ua) != null) + rv = parseFloat(RegExp.$1); + } + return rv !== -1 && rv < 9; + })(), + + ie10 : window.navigator.msPointerEnabled, + ie11 : window.navigator.pointerEnabled + } +}; + +/*========================= + jQuery & Zepto Plugins + ===========================*/ +if (window.jQuery || window.Zepto) { + (function ($) { + 'use strict'; + $.fn.swiper = function (params) { + var s = new Swiper($(this)[0], params); + $(this).data('swiper', s); + return s; + }; + })(window.jQuery || window.Zepto); +} + +// component +if (typeof(module) !== 'undefined') +{ + module.exports = Swiper; +} diff --git a/assets/html/index.html b/assets/html/index.html new file mode 100644 index 0000000..615ea0c --- /dev/null +++ b/assets/html/index.html @@ -0,0 +1,57 @@ + + + + + XKCD Unofficial + + + + + +
+ +
+
+
    +
  • +
    +
    +
    +
  • +
  • +
    +
    +
    +
  • +
  • +
    +
    +
    +
  • +
+
+
+
+ +
+ Loading
+
+ + + + + + + \ No newline at end of file diff --git a/assets/html/iscroll-zoom.js b/assets/html/iscroll-zoom.js new file mode 100644 index 0000000..e9e5d40 --- /dev/null +++ b/assets/html/iscroll-zoom.js @@ -0,0 +1,2172 @@ +/*! iScroll v5.1.1 ~ (c) 2008-2014 Matteo Spinelli ~ http://cubiq.org/license */ +(function (window, document, Math) { +var rAF = window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function (callback) { window.setTimeout(callback, 1000 / 60); }; + +var utils = (function () { + var me = {}; + + var _elementStyle = document.createElement('div').style; + var _vendor = (function () { + var vendors = ['t', 'webkitT', 'MozT', 'msT', 'OT'], + transform, + i = 0, + l = vendors.length; + + for ( ; i < l; i++ ) { + transform = vendors[i] + 'ransform'; + if ( transform in _elementStyle ) return vendors[i].substr(0, vendors[i].length-1); + } + + return false; + })(); + + function _prefixStyle (style) { + if ( _vendor === false ) return false; + if ( _vendor === '' ) return style; + return _vendor + style.charAt(0).toUpperCase() + style.substr(1); + } + + me.getTime = Date.now || function getTime () { return new Date().getTime(); }; + + me.extend = function (target, obj) { + for ( var i in obj ) { + target[i] = obj[i]; + } + }; + + me.addEvent = function (el, type, fn, capture) { + el.addEventListener(type, fn, !!capture); + }; + + me.removeEvent = function (el, type, fn, capture) { + el.removeEventListener(type, fn, !!capture); + }; + + me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) { + var distance = current - start, + speed = Math.abs(distance) / time, + destination, + duration; + + deceleration = deceleration === undefined ? 0.0006 : deceleration; + + destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 ); + duration = speed / deceleration; + + if ( destination < lowerMargin ) { + destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin; + distance = Math.abs(destination - current); + duration = distance / speed; + } else if ( destination > 0 ) { + destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0; + distance = Math.abs(current) + destination; + duration = distance / speed; + } + + return { + destination: Math.round(destination), + duration: duration + }; + }; + + var _transform = _prefixStyle('transform'); + + me.extend(me, { + hasTransform: _transform !== false, + hasPerspective: _prefixStyle('perspective') in _elementStyle, + hasTouch: 'ontouchstart' in window, + hasPointer: navigator.msPointerEnabled, + hasTransition: _prefixStyle('transition') in _elementStyle + }); + + // This should find all Android browsers lower than build 535.19 (both stock browser and webview) + me.isBadAndroid = /Android /.test(window.navigator.appVersion) && !(/Chrome\/\d/.test(window.navigator.appVersion)); + + me.extend(me.style = {}, { + transform: _transform, + transitionTimingFunction: _prefixStyle('transitionTimingFunction'), + transitionDuration: _prefixStyle('transitionDuration'), + transitionDelay: _prefixStyle('transitionDelay'), + transformOrigin: _prefixStyle('transformOrigin') + }); + + me.hasClass = function (e, c) { + var re = new RegExp("(^|\\s)" + c + "(\\s|$)"); + return re.test(e.className); + }; + + me.addClass = function (e, c) { + if ( me.hasClass(e, c) ) { + return; + } + + var newclass = e.className.split(' '); + newclass.push(c); + e.className = newclass.join(' '); + }; + + me.removeClass = function (e, c) { + if ( !me.hasClass(e, c) ) { + return; + } + + var re = new RegExp("(^|\\s)" + c + "(\\s|$)", 'g'); + e.className = e.className.replace(re, ' '); + }; + + me.offset = function (el) { + var left = -el.offsetLeft, + top = -el.offsetTop; + + // jshint -W084 + while (el = el.offsetParent) { + left -= el.offsetLeft; + top -= el.offsetTop; + } + // jshint +W084 + + return { + left: left, + top: top + }; + }; + + me.preventDefaultException = function (el, exceptions) { + for ( var i in exceptions ) { + if ( exceptions[i].test(el[i]) ) { + return true; + } + } + + return false; + }; + + me.extend(me.eventType = {}, { + touchstart: 1, + touchmove: 1, + touchend: 1, + + mousedown: 2, + mousemove: 2, + mouseup: 2, + + MSPointerDown: 3, + MSPointerMove: 3, + MSPointerUp: 3 + }); + + me.extend(me.ease = {}, { + quadratic: { + style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)', + fn: function (k) { + return k * ( 2 - k ); + } + }, + circular: { + style: 'cubic-bezier(0.1, 0.57, 0.1, 1)', // Not properly "circular" but this looks better, it should be (0.075, 0.82, 0.165, 1) + fn: function (k) { + return Math.sqrt( 1 - ( --k * k ) ); + } + }, + back: { + style: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)', + fn: function (k) { + var b = 4; + return ( k = k - 1 ) * k * ( ( b + 1 ) * k + b ) + 1; + } + }, + bounce: { + style: '', + fn: function (k) { + if ( ( k /= 1 ) < ( 1 / 2.75 ) ) { + return 7.5625 * k * k; + } else if ( k < ( 2 / 2.75 ) ) { + return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75; + } else if ( k < ( 2.5 / 2.75 ) ) { + return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375; + } else { + return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375; + } + } + }, + elastic: { + style: '', + fn: function (k) { + var f = 0.22, + e = 0.4; + + if ( k === 0 ) { return 0; } + if ( k == 1 ) { return 1; } + + return ( e * Math.pow( 2, - 10 * k ) * Math.sin( ( k - f / 4 ) * ( 2 * Math.PI ) / f ) + 1 ); + } + } + }); + + me.tap = function (e, eventName) { + var ev = document.createEvent('Event'); + ev.initEvent(eventName, true, true); + ev.pageX = e.pageX; + ev.pageY = e.pageY; + e.target.dispatchEvent(ev); + }; + + me.click = function (e) { + var target = e.target, + ev; + + if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) { + ev = document.createEvent('MouseEvents'); + ev.initMouseEvent('click', true, true, e.view, 1, + target.screenX, target.screenY, target.clientX, target.clientY, + e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, + 0, null); + + ev._constructed = true; + target.dispatchEvent(ev); + } + }; + + return me; +})(); + +function IScroll (el, options) { + this.wrapper = typeof el == 'string' ? document.querySelector(el) : el; + this.scroller = this.wrapper.children[0]; + this.scrollerStyle = this.scroller.style; // cache style for better performance + + this.options = { + + zoomMin: 1, + zoomMax: 4, startZoom: 1, + + resizeScrollbars: true, + + mouseWheelSpeed: 20, + + snapThreshold: 0.334, + +// INSERT POINT: OPTIONS + + startX: 0, + startY: 0, + scrollY: true, + directionLockThreshold: 5, + momentum: true, + + bounce: true, + bounceTime: 600, + bounceEasing: '', + + preventDefault: true, + preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ }, + + HWCompositing: true, + useTransition: true, + useTransform: true + }; + + for ( var i in options ) { + this.options[i] = options[i]; + } + + // Normalize options + this.translateZ = this.options.HWCompositing && utils.hasPerspective ? ' translateZ(0)' : ''; + + this.options.useTransition = utils.hasTransition && this.options.useTransition; + this.options.useTransform = utils.hasTransform && this.options.useTransform; + + this.options.eventPassthrough = this.options.eventPassthrough === true ? 'vertical' : this.options.eventPassthrough; + this.options.preventDefault = !this.options.eventPassthrough && this.options.preventDefault; + + // If you want eventPassthrough I have to lock one of the axes + this.options.scrollY = this.options.eventPassthrough == 'vertical' ? false : this.options.scrollY; + this.options.scrollX = this.options.eventPassthrough == 'horizontal' ? false : this.options.scrollX; + + // With eventPassthrough we also need lockDirection mechanism + this.options.freeScroll = this.options.freeScroll && !this.options.eventPassthrough; + this.options.directionLockThreshold = this.options.eventPassthrough ? 0 : this.options.directionLockThreshold; + + this.options.bounceEasing = typeof this.options.bounceEasing == 'string' ? utils.ease[this.options.bounceEasing] || utils.ease.circular : this.options.bounceEasing; + + this.options.resizePolling = this.options.resizePolling === undefined ? 60 : this.options.resizePolling; + + if ( this.options.tap === true ) { + this.options.tap = 'tap'; + } + + if ( this.options.shrinkScrollbars == 'scale' ) { + this.options.useTransition = false; + } + + this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1; + +// INSERT POINT: NORMALIZATION + + // Some defaults + this.x = 0; + this.y = 0; + this.directionX = 0; + this.directionY = 0; + this._events = {}; + + this.scale = Math.min(Math.max(this.options.startZoom, this.options.zoomMin), this.options.zoomMax); + +// INSERT POINT: DEFAULTS + + this._init(); + this.refresh(); + + this.scrollTo(this.options.startX, this.options.startY); + this.enable(); +} + +IScroll.prototype = { + version: '5.1.1', + + _init: function () { + this._initEvents(); + + if ( this.options.zoom ) { + this._initZoom(); + } + + if ( this.options.scrollbars || this.options.indicators ) { + this._initIndicators(); + } + + if ( this.options.mouseWheel ) { + this._initWheel(); + } + + if ( this.options.snap ) { + this._initSnap(); + } + + if ( this.options.keyBindings ) { + this._initKeys(); + } + +// INSERT POINT: _init + + }, + + destroy: function () { + this._initEvents(true); + + this._execEvent('destroy'); + }, + + _transitionEnd: function (e) { + if ( e.target != this.scroller || !this.isInTransition ) { + return; + } + + this._transitionTime(); + if ( !this.resetPosition(this.options.bounceTime) ) { + this.isInTransition = false; + this._execEvent('scrollEnd'); + } + }, + + _start: function (e) { + // React to left mouse button only + if ( utils.eventType[e.type] != 1 ) { + if ( e.button !== 0 ) { + return; + } + } + + if ( !this.enabled || (this.initiated && utils.eventType[e.type] !== this.initiated) ) { + return; + } + + if ( this.options.preventDefault && !utils.isBadAndroid && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) { + e.preventDefault(); + } + + var point = e.touches ? e.touches[0] : e, + pos; + + this.initiated = utils.eventType[e.type]; + this.moved = false; + this.distX = 0; + this.distY = 0; + this.directionX = 0; + this.directionY = 0; + this.directionLocked = 0; + + this._transitionTime(); + + this.startTime = utils.getTime(); + + if ( this.options.useTransition && this.isInTransition ) { + this.isInTransition = false; + pos = this.getComputedPosition(); + this._translate(Math.round(pos.x), Math.round(pos.y)); + this._execEvent('scrollEnd'); + } else if ( !this.options.useTransition && this.isAnimating ) { + this.isAnimating = false; + this._execEvent('scrollEnd'); + } + + this.startX = this.x; + this.startY = this.y; + this.absStartX = this.x; + this.absStartY = this.y; + this.pointX = point.pageX; + this.pointY = point.pageY; + + this._execEvent('beforeScrollStart'); + }, + + _move: function (e) { + if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) { + return; + } + + if ( this.options.preventDefault ) { // increases performance on Android? TODO: check! + e.preventDefault(); + } + + var point = e.touches ? e.touches[0] : e, + deltaX = point.pageX - this.pointX, + deltaY = point.pageY - this.pointY, + timestamp = utils.getTime(), + newX, newY, + absDistX, absDistY; + + this.pointX = point.pageX; + this.pointY = point.pageY; + + this.distX += deltaX; + this.distY += deltaY; + absDistX = Math.abs(this.distX); + absDistY = Math.abs(this.distY); + + // We need to move at least 10 pixels for the scrolling to initiate + if ( timestamp - this.endTime > 300 && (absDistX < 10 && absDistY < 10) ) { + return; + } + + // If you are scrolling in one direction lock the other + if ( !this.directionLocked && !this.options.freeScroll ) { + if ( absDistX > absDistY + this.options.directionLockThreshold ) { + this.directionLocked = 'h'; // lock horizontally + } else if ( absDistY >= absDistX + this.options.directionLockThreshold ) { + this.directionLocked = 'v'; // lock vertically + } else { + this.directionLocked = 'n'; // no lock + } + } + + if ( this.directionLocked == 'h' ) { + if ( this.options.eventPassthrough == 'vertical' ) { + e.preventDefault(); + } else if ( this.options.eventPassthrough == 'horizontal' ) { + this.initiated = false; + return; + } + + deltaY = 0; + } else if ( this.directionLocked == 'v' ) { + if ( this.options.eventPassthrough == 'horizontal' ) { + e.preventDefault(); + } else if ( this.options.eventPassthrough == 'vertical' ) { + this.initiated = false; + return; + } + + deltaX = 0; + } + + deltaX = this.hasHorizontalScroll ? deltaX : 0; + deltaY = this.hasVerticalScroll ? deltaY : 0; + + newX = this.x + deltaX; + newY = this.y + deltaY; + + // Slow down if outside of the boundaries + if ( newX > 0 || newX < this.maxScrollX ) { + newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX; + } + if ( newY > 0 || newY < this.maxScrollY ) { + newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY; + } + + this.directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0; + this.directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0; + + if ( !this.moved ) { + this._execEvent('scrollStart'); + } + + this.moved = true; + + this._translate(newX, newY); + +/* REPLACE START: _move */ + + if ( timestamp - this.startTime > 300 ) { + this.startTime = timestamp; + this.startX = this.x; + this.startY = this.y; + } + +/* REPLACE END: _move */ + + }, + + _end: function (e) { + if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) { + return; + } + + if ( this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) { + e.preventDefault(); + } + + var point = e.changedTouches ? e.changedTouches[0] : e, + momentumX, + momentumY, + duration = utils.getTime() - this.startTime, + newX = Math.round(this.x), + newY = Math.round(this.y), + distanceX = Math.abs(newX - this.startX), + distanceY = Math.abs(newY - this.startY), + time = 0, + easing = ''; + + this.isInTransition = 0; + this.initiated = 0; + this.endTime = utils.getTime(); + + // reset if we are outside of the boundaries + if ( this.resetPosition(this.options.bounceTime) ) { + return; + } + + this.scrollTo(newX, newY); // ensures that the last position is rounded + + // we scrolled less than 10 pixels + if ( !this.moved ) { + if ( this.options.tap ) { + utils.tap(e, this.options.tap); + } + + if ( this.options.click ) { + utils.click(e); + } + + this._execEvent('scrollCancel'); + return; + } + + if ( this._events.flick && duration < 200 && distanceX < 100 && distanceY < 100 ) { + this._execEvent('flick'); + return; + } + + // start momentum animation if needed + if ( this.options.momentum && duration < 300 ) { + momentumX = this.hasHorizontalScroll ? utils.momentum(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : { destination: newX, duration: 0 }; + momentumY = this.hasVerticalScroll ? utils.momentum(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : { destination: newY, duration: 0 }; + newX = momentumX.destination; + newY = momentumY.destination; + time = Math.max(momentumX.duration, momentumY.duration); + this.isInTransition = 1; + } + + + if ( this.options.snap ) { + var snap = this._nearestSnap(newX, newY); + this.currentPage = snap; + time = this.options.snapSpeed || Math.max( + Math.max( + Math.min(Math.abs(newX - snap.x), 1000), + Math.min(Math.abs(newY - snap.y), 1000) + ), 300); + newX = snap.x; + newY = snap.y; + + this.directionX = 0; + this.directionY = 0; + easing = this.options.bounceEasing; + } + +// INSERT POINT: _end + + if ( newX != this.x || newY != this.y ) { + // change easing function when scroller goes out of the boundaries + if ( newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY ) { + easing = utils.ease.quadratic; + } + + this.scrollTo(newX, newY, time, easing); + return; + } + + this._execEvent('scrollEnd'); + }, + + _resize: function () { + var that = this; + + clearTimeout(this.resizeTimeout); + + this.resizeTimeout = setTimeout(function () { + that.refresh(); + }, this.options.resizePolling); + }, + + resetPosition: function (time) { + var x = this.x, + y = this.y; + + time = time || 0; + + if ( !this.hasHorizontalScroll || this.x > 0 ) { + x = 0; + } else if ( this.x < this.maxScrollX ) { + x = this.maxScrollX; + } + + if ( !this.hasVerticalScroll || this.y > 0 ) { + y = 0; + } else if ( this.y < this.maxScrollY ) { + y = this.maxScrollY; + } + + if ( x == this.x && y == this.y ) { + return false; + } + + this.scrollTo(x, y, time, this.options.bounceEasing); + + return true; + }, + + disable: function () { + this.enabled = false; + }, + + enable: function () { + this.enabled = true; + }, + + refresh: function () { + var rf = this.wrapper.offsetHeight; // Force reflow + + this.wrapperWidth = this.wrapper.clientWidth; + this.wrapperHeight = this.wrapper.clientHeight; + +/* REPLACE START: refresh */ + this.scrollerWidth = Math.round(this.scroller.offsetWidth * this.scale); + this.scrollerHeight = Math.round(this.scroller.offsetHeight * this.scale); + + this.maxScrollX = this.wrapperWidth - this.scrollerWidth; + this.maxScrollY = this.wrapperHeight - this.scrollerHeight; +/* REPLACE END: refresh */ + + this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0; + this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0; + + if ( !this.hasHorizontalScroll ) { + this.maxScrollX = 0; + this.scrollerWidth = this.wrapperWidth; + } + + if ( !this.hasVerticalScroll ) { + this.maxScrollY = 0; + this.scrollerHeight = this.wrapperHeight; + } + + this.endTime = 0; + this.directionX = 0; + this.directionY = 0; + + this.wrapperOffset = utils.offset(this.wrapper); + + this._execEvent('refresh'); + + this.resetPosition(); + +// INSERT POINT: _refresh + + }, + + on: function (type, fn) { + if ( !this._events[type] ) { + this._events[type] = []; + } + + this._events[type].push(fn); + }, + + off: function (type, fn) { + if ( !this._events[type] ) { + return; + } + + var index = this._events[type].indexOf(fn); + + if ( index > -1 ) { + this._events[type].splice(index, 1); + } + }, + + _execEvent: function (type) { + if ( !this._events[type] ) { + return; + } + + var i = 0, + l = this._events[type].length; + + if ( !l ) { + return; + } + + for ( ; i < l; i++ ) { + this._events[type][i].apply(this, [].slice.call(arguments, 1)); + } + }, + + scrollBy: function (x, y, time, easing) { + x = this.x + x; + y = this.y + y; + time = time || 0; + + this.scrollTo(x, y, time, easing); + }, + + scrollTo: function (x, y, time, easing) { + easing = easing || utils.ease.circular; + + this.isInTransition = this.options.useTransition && time > 0; + + if ( !time || (this.options.useTransition && easing.style) ) { + this._transitionTimingFunction(easing.style); + this._transitionTime(time); + this._translate(x, y); + } else { + this._animate(x, y, time, easing.fn); + } + }, + + scrollToElement: function (el, time, offsetX, offsetY, easing) { + el = el.nodeType ? el : this.scroller.querySelector(el); + + if ( !el ) { + return; + } + + var pos = utils.offset(el); + + pos.left -= this.wrapperOffset.left; + pos.top -= this.wrapperOffset.top; + + // if offsetX/Y are true we center the element to the screen + if ( offsetX === true ) { + offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2); + } + if ( offsetY === true ) { + offsetY = Math.round(el.offsetHeight / 2 - this.wrapper.offsetHeight / 2); + } + + pos.left -= offsetX || 0; + pos.top -= offsetY || 0; + + pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left; + pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top; + + time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x-pos.left), Math.abs(this.y-pos.top)) : time; + + this.scrollTo(pos.left, pos.top, time, easing); + }, + + _transitionTime: function (time) { + time = time || 0; + + this.scrollerStyle[utils.style.transitionDuration] = time + 'ms'; + + if ( !time && utils.isBadAndroid ) { + this.scrollerStyle[utils.style.transitionDuration] = '0.001s'; + } + + + if ( this.indicators ) { + for ( var i = this.indicators.length; i--; ) { + this.indicators[i].transitionTime(time); + } + } + + +// INSERT POINT: _transitionTime + + }, + + _transitionTimingFunction: function (easing) { + this.scrollerStyle[utils.style.transitionTimingFunction] = easing; + + + if ( this.indicators ) { + for ( var i = this.indicators.length; i--; ) { + this.indicators[i].transitionTimingFunction(easing); + } + } + + +// INSERT POINT: _transitionTimingFunction + + }, + + _translate: function (x, y) { + if ( this.options.useTransform ) { + +/* REPLACE START: _translate */ this.scrollerStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px) scale(' + this.scale + ') ' + this.translateZ;/* REPLACE END: _translate */ + + } else { + x = Math.round(x); + y = Math.round(y); + this.scrollerStyle.left = x + 'px'; + this.scrollerStyle.top = y + 'px'; + } + + this.x = x; + this.y = y; + + + if ( this.indicators ) { + for ( var i = this.indicators.length; i--; ) { + this.indicators[i].updatePosition(); + } + } + + +// INSERT POINT: _translate + + }, + + _initEvents: function (remove) { + var eventType = remove ? utils.removeEvent : utils.addEvent, + target = this.options.bindToWrapper ? this.wrapper : window; + + eventType(window, 'orientationchange', this); + eventType(window, 'resize', this); + + if ( this.options.click ) { + eventType(this.wrapper, 'click', this, true); + } + + if ( !this.options.disableMouse ) { + eventType(this.wrapper, 'mousedown', this); + eventType(target, 'mousemove', this); + eventType(target, 'mousecancel', this); + eventType(target, 'mouseup', this); + } + + if ( utils.hasPointer && !this.options.disablePointer ) { + eventType(this.wrapper, 'MSPointerDown', this); + eventType(target, 'MSPointerMove', this); + eventType(target, 'MSPointerCancel', this); + eventType(target, 'MSPointerUp', this); + } + + if ( utils.hasTouch && !this.options.disableTouch ) { + eventType(this.wrapper, 'touchstart', this); + eventType(target, 'touchmove', this); + eventType(target, 'touchcancel', this); + eventType(target, 'touchend', this); + } + + eventType(this.scroller, 'transitionend', this); + eventType(this.scroller, 'webkitTransitionEnd', this); + eventType(this.scroller, 'oTransitionEnd', this); + eventType(this.scroller, 'MSTransitionEnd', this); + }, + + getComputedPosition: function () { + var matrix = window.getComputedStyle(this.scroller, null), + x, y; + + if ( this.options.useTransform ) { + matrix = matrix[utils.style.transform].split(')')[0].split(', '); + x = +(matrix[12] || matrix[4]); + y = +(matrix[13] || matrix[5]); + } else { + x = +matrix.left.replace(/[^-\d.]/g, ''); + y = +matrix.top.replace(/[^-\d.]/g, ''); + } + + return { x: x, y: y }; + }, + + _initIndicators: function () { + var interactive = this.options.interactiveScrollbars, + customStyle = typeof this.options.scrollbars != 'string', + indicators = [], + indicator; + + var that = this; + + this.indicators = []; + + if ( this.options.scrollbars ) { + // Vertical scrollbar + if ( this.options.scrollY ) { + indicator = { + el: createDefaultScrollbar('v', interactive, this.options.scrollbars), + interactive: interactive, + defaultScrollbars: true, + customStyle: customStyle, + resize: this.options.resizeScrollbars, + shrink: this.options.shrinkScrollbars, + fade: this.options.fadeScrollbars, + listenX: false + }; + + this.wrapper.appendChild(indicator.el); + indicators.push(indicator); + } + + // Horizontal scrollbar + if ( this.options.scrollX ) { + indicator = { + el: createDefaultScrollbar('h', interactive, this.options.scrollbars), + interactive: interactive, + defaultScrollbars: true, + customStyle: customStyle, + resize: this.options.resizeScrollbars, + shrink: this.options.shrinkScrollbars, + fade: this.options.fadeScrollbars, + listenY: false + }; + + this.wrapper.appendChild(indicator.el); + indicators.push(indicator); + } + } + + if ( this.options.indicators ) { + // TODO: check concat compatibility + indicators = indicators.concat(this.options.indicators); + } + + for ( var i = indicators.length; i--; ) { + this.indicators.push( new Indicator(this, indicators[i]) ); + } + + // TODO: check if we can use array.map (wide compatibility and performance issues) + function _indicatorsMap (fn) { + for ( var i = that.indicators.length; i--; ) { + fn.call(that.indicators[i]); + } + } + + if ( this.options.fadeScrollbars ) { + this.on('scrollEnd', function () { + _indicatorsMap(function () { + this.fade(); + }); + }); + + this.on('scrollCancel', function () { + _indicatorsMap(function () { + this.fade(); + }); + }); + + this.on('scrollStart', function () { + _indicatorsMap(function () { + this.fade(1); + }); + }); + + this.on('beforeScrollStart', function () { + _indicatorsMap(function () { + this.fade(1, true); + }); + }); + } + + + this.on('refresh', function () { + _indicatorsMap(function () { + this.refresh(); + }); + }); + + this.on('destroy', function () { + _indicatorsMap(function () { + this.destroy(); + }); + + delete this.indicators; + }); + }, + + _initZoom: function () { + this.scrollerStyle[utils.style.transformOrigin] = '0 0'; + }, + + _zoomStart: function (e) { + var c1 = Math.abs( e.touches[0].pageX - e.touches[1].pageX ), + c2 = Math.abs( e.touches[0].pageY - e.touches[1].pageY ); + + this.touchesDistanceStart = Math.sqrt(c1 * c1 + c2 * c2); + this.startScale = this.scale; + + this.originX = Math.abs(e.touches[0].pageX + e.touches[1].pageX) / 2 + this.wrapperOffset.left - this.x; + this.originY = Math.abs(e.touches[0].pageY + e.touches[1].pageY) / 2 + this.wrapperOffset.top - this.y; + + this._execEvent('zoomStart'); + }, + + _zoom: function (e) { + if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) { + return; + } + + if ( this.options.preventDefault ) { + e.preventDefault(); + } + + var c1 = Math.abs( e.touches[0].pageX - e.touches[1].pageX ), + c2 = Math.abs( e.touches[0].pageY - e.touches[1].pageY ), + distance = Math.sqrt( c1 * c1 + c2 * c2 ), + scale = 1 / this.touchesDistanceStart * distance * this.startScale, + lastScale, + x, y; + + this.scaled = true; + + if ( scale < this.options.zoomMin ) { + scale = 0.5 * this.options.zoomMin * Math.pow(2.0, scale / this.options.zoomMin); + } else if ( scale > this.options.zoomMax ) { + scale = 2.0 * this.options.zoomMax * Math.pow(0.5, this.options.zoomMax / scale); + } + + lastScale = scale / this.startScale; + x = this.originX - this.originX * lastScale + this.startX; + y = this.originY - this.originY * lastScale + this.startY; + + this.scale = scale; + + this.scrollTo(x, y, 0); + }, + + _zoomEnd: function (e) { + if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) { + return; + } + + if ( this.options.preventDefault ) { + e.preventDefault(); + } + + var newX, newY, + lastScale; + + this.isInTransition = 0; + this.initiated = 0; + + if ( this.scale > this.options.zoomMax ) { + this.scale = this.options.zoomMax; + } else if ( this.scale < this.options.zoomMin ) { + this.scale = this.options.zoomMin; + } + + // Update boundaries + this.refresh(); + + lastScale = this.scale / this.startScale; + + newX = this.originX - this.originX * lastScale + this.startX; + newY = this.originY - this.originY * lastScale + this.startY; + + if ( newX > 0 ) { + newX = 0; + } else if ( newX < this.maxScrollX ) { + newX = this.maxScrollX; + } + + if ( newY > 0 ) { + newY = 0; + } else if ( newY < this.maxScrollY ) { + newY = this.maxScrollY; + } + + if ( this.x != newX || this.y != newY ) { + this.scrollTo(newX, newY, this.options.bounceTime); + } + + this.scaled = false; + + this._execEvent('zoomEnd'); + }, + + zoom: function (scale, x, y, time) { + if ( scale < this.options.zoomMin ) { + scale = this.options.zoomMin; + } else if ( scale > this.options.zoomMax ) { + scale = this.options.zoomMax; + } + + if ( scale == this.scale ) { + return; + } + + var relScale = scale / this.scale; + + x = x === undefined ? this.wrapperWidth / 2 : x; + y = y === undefined ? this.wrapperHeight / 2 : y; + time = time === undefined ? 300 : time; + + x = x + this.wrapperOffset.left - this.x; + y = y + this.wrapperOffset.top - this.y; + + x = x - x * relScale + this.x; + y = y - y * relScale + this.y; + + this.scale = scale; + + this.refresh(); // update boundaries + + if ( x > 0 ) { + x = 0; + } else if ( x < this.maxScrollX ) { + x = this.maxScrollX; + } + + if ( y > 0 ) { + y = 0; + } else if ( y < this.maxScrollY ) { + y = this.maxScrollY; + } + + this.scrollTo(x, y, time); + }, + + _wheelZoom: function (e) { + var wheelDeltaY, + deltaScale, + that = this; + + // Execute the zoomEnd event after 400ms the wheel stopped scrolling + clearTimeout(this.wheelTimeout); + this.wheelTimeout = setTimeout(function () { + that._execEvent('zoomEnd'); + }, 400); + + if ( 'deltaX' in e ) { + wheelDeltaY = -e.deltaY / Math.abs(e.deltaY); + } else if ('wheelDeltaX' in e) { + wheelDeltaY = e.wheelDeltaY / Math.abs(e.wheelDeltaY); + } else if('wheelDelta' in e) { + wheelDeltaY = e.wheelDelta / Math.abs(e.wheelDelta); + } else if ('detail' in e) { + wheelDeltaY = -e.detail / Math.abs(e.wheelDelta); + } else { + return; + } + + deltaScale = this.scale + wheelDeltaY / 5; + + this.zoom(deltaScale, e.pageX, e.pageY, 0); + }, + + _initWheel: function () { + utils.addEvent(this.wrapper, 'wheel', this); + utils.addEvent(this.wrapper, 'mousewheel', this); + utils.addEvent(this.wrapper, 'DOMMouseScroll', this); + + this.on('destroy', function () { + utils.removeEvent(this.wrapper, 'wheel', this); + utils.removeEvent(this.wrapper, 'mousewheel', this); + utils.removeEvent(this.wrapper, 'DOMMouseScroll', this); + }); + }, + + _wheel: function (e) { + if ( !this.enabled ) { + return; + } + + e.preventDefault(); + e.stopPropagation(); + + var wheelDeltaX, wheelDeltaY, + newX, newY, + that = this; + + if ( this.wheelTimeout === undefined ) { + that._execEvent('scrollStart'); + } + + // Execute the scrollEnd event after 400ms the wheel stopped scrolling + clearTimeout(this.wheelTimeout); + this.wheelTimeout = setTimeout(function () { + that._execEvent('scrollEnd'); + that.wheelTimeout = undefined; + }, 400); + + if ( 'deltaX' in e ) { + wheelDeltaX = -e.deltaX; + wheelDeltaY = -e.deltaY; + } else if ( 'wheelDeltaX' in e ) { + wheelDeltaX = e.wheelDeltaX / 120 * this.options.mouseWheelSpeed; + wheelDeltaY = e.wheelDeltaY / 120 * this.options.mouseWheelSpeed; + } else if ( 'wheelDelta' in e ) { + wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * this.options.mouseWheelSpeed; + } else if ( 'detail' in e ) { + wheelDeltaX = wheelDeltaY = -e.detail / 3 * this.options.mouseWheelSpeed; + } else { + return; + } + + wheelDeltaX *= this.options.invertWheelDirection; + wheelDeltaY *= this.options.invertWheelDirection; + + if ( !this.hasVerticalScroll ) { + wheelDeltaX = wheelDeltaY; + wheelDeltaY = 0; + } + + if ( this.options.snap ) { + newX = this.currentPage.pageX; + newY = this.currentPage.pageY; + + if ( wheelDeltaX > 0 ) { + newX--; + } else if ( wheelDeltaX < 0 ) { + newX++; + } + + if ( wheelDeltaY > 0 ) { + newY--; + } else if ( wheelDeltaY < 0 ) { + newY++; + } + + this.goToPage(newX, newY); + + return; + } + + newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0); + newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0); + + if ( newX > 0 ) { + newX = 0; + } else if ( newX < this.maxScrollX ) { + newX = this.maxScrollX; + } + + if ( newY > 0 ) { + newY = 0; + } else if ( newY < this.maxScrollY ) { + newY = this.maxScrollY; + } + + this.scrollTo(newX, newY, 0); + +// INSERT POINT: _wheel + }, + + _initSnap: function () { + this.currentPage = {}; + + if ( typeof this.options.snap == 'string' ) { + this.options.snap = this.scroller.querySelectorAll(this.options.snap); + } + + this.on('refresh', function () { + var i = 0, l, + m = 0, n, + cx, cy, + x = 0, y, + stepX = this.options.snapStepX || this.wrapperWidth, + stepY = this.options.snapStepY || this.wrapperHeight, + el; + + this.pages = []; + + if ( !this.wrapperWidth || !this.wrapperHeight || !this.scrollerWidth || !this.scrollerHeight ) { + return; + } + + if ( this.options.snap === true ) { + cx = Math.round( stepX / 2 ); + cy = Math.round( stepY / 2 ); + + while ( x > -this.scrollerWidth ) { + this.pages[i] = []; + l = 0; + y = 0; + + while ( y > -this.scrollerHeight ) { + this.pages[i][l] = { + x: Math.max(x, this.maxScrollX), + y: Math.max(y, this.maxScrollY), + width: stepX, + height: stepY, + cx: x - cx, + cy: y - cy + }; + + y -= stepY; + l++; + } + + x -= stepX; + i++; + } + } else { + el = this.options.snap; + l = el.length; + n = -1; + + for ( ; i < l; i++ ) { + if ( i === 0 || el[i].offsetLeft <= el[i-1].offsetLeft ) { + m = 0; + n++; + } + + if ( !this.pages[m] ) { + this.pages[m] = []; + } + + x = Math.max(-el[i].offsetLeft, this.maxScrollX); + y = Math.max(-el[i].offsetTop, this.maxScrollY); + cx = x - Math.round(el[i].offsetWidth / 2); + cy = y - Math.round(el[i].offsetHeight / 2); + + this.pages[m][n] = { + x: x, + y: y, + width: el[i].offsetWidth, + height: el[i].offsetHeight, + cx: cx, + cy: cy + }; + + if ( x > this.maxScrollX ) { + m++; + } + } + } + + this.goToPage(this.currentPage.pageX || 0, this.currentPage.pageY || 0, 0); + + // Update snap threshold if needed + if ( this.options.snapThreshold % 1 === 0 ) { + this.snapThresholdX = this.options.snapThreshold; + this.snapThresholdY = this.options.snapThreshold; + } else { + this.snapThresholdX = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].width * this.options.snapThreshold); + this.snapThresholdY = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].height * this.options.snapThreshold); + } + }); + + this.on('flick', function () { + var time = this.options.snapSpeed || Math.max( + Math.max( + Math.min(Math.abs(this.x - this.startX), 1000), + Math.min(Math.abs(this.y - this.startY), 1000) + ), 300); + + this.goToPage( + this.currentPage.pageX + this.directionX, + this.currentPage.pageY + this.directionY, + time + ); + }); + }, + + _nearestSnap: function (x, y) { + if ( !this.pages.length ) { + return { x: 0, y: 0, pageX: 0, pageY: 0 }; + } + + var i = 0, + l = this.pages.length, + m = 0; + + // Check if we exceeded the snap threshold + if ( Math.abs(x - this.absStartX) < this.snapThresholdX && + Math.abs(y - this.absStartY) < this.snapThresholdY ) { + return this.currentPage; + } + + if ( x > 0 ) { + x = 0; + } else if ( x < this.maxScrollX ) { + x = this.maxScrollX; + } + + if ( y > 0 ) { + y = 0; + } else if ( y < this.maxScrollY ) { + y = this.maxScrollY; + } + + for ( ; i < l; i++ ) { + if ( x >= this.pages[i][0].cx ) { + x = this.pages[i][0].x; + break; + } + } + + l = this.pages[i].length; + + for ( ; m < l; m++ ) { + if ( y >= this.pages[0][m].cy ) { + y = this.pages[0][m].y; + break; + } + } + + if ( i == this.currentPage.pageX ) { + i += this.directionX; + + if ( i < 0 ) { + i = 0; + } else if ( i >= this.pages.length ) { + i = this.pages.length - 1; + } + + x = this.pages[i][0].x; + } + + if ( m == this.currentPage.pageY ) { + m += this.directionY; + + if ( m < 0 ) { + m = 0; + } else if ( m >= this.pages[0].length ) { + m = this.pages[0].length - 1; + } + + y = this.pages[0][m].y; + } + + return { + x: x, + y: y, + pageX: i, + pageY: m + }; + }, + + goToPage: function (x, y, time, easing) { + easing = easing || this.options.bounceEasing; + + if ( x >= this.pages.length ) { + x = this.pages.length - 1; + } else if ( x < 0 ) { + x = 0; + } + + if ( y >= this.pages[x].length ) { + y = this.pages[x].length - 1; + } else if ( y < 0 ) { + y = 0; + } + + var posX = this.pages[x][y].x, + posY = this.pages[x][y].y; + + time = time === undefined ? this.options.snapSpeed || Math.max( + Math.max( + Math.min(Math.abs(posX - this.x), 1000), + Math.min(Math.abs(posY - this.y), 1000) + ), 300) : time; + + this.currentPage = { + x: posX, + y: posY, + pageX: x, + pageY: y + }; + + this.scrollTo(posX, posY, time, easing); + }, + + next: function (time, easing) { + var x = this.currentPage.pageX, + y = this.currentPage.pageY; + + x++; + + if ( x >= this.pages.length && this.hasVerticalScroll ) { + x = 0; + y++; + } + + this.goToPage(x, y, time, easing); + }, + + prev: function (time, easing) { + var x = this.currentPage.pageX, + y = this.currentPage.pageY; + + x--; + + if ( x < 0 && this.hasVerticalScroll ) { + x = 0; + y--; + } + + this.goToPage(x, y, time, easing); + }, + + _initKeys: function (e) { + // default key bindings + var keys = { + pageUp: 33, + pageDown: 34, + end: 35, + home: 36, + left: 37, + up: 38, + right: 39, + down: 40 + }; + var i; + + // if you give me characters I give you keycode + if ( typeof this.options.keyBindings == 'object' ) { + for ( i in this.options.keyBindings ) { + if ( typeof this.options.keyBindings[i] == 'string' ) { + this.options.keyBindings[i] = this.options.keyBindings[i].toUpperCase().charCodeAt(0); + } + } + } else { + this.options.keyBindings = {}; + } + + for ( i in keys ) { + this.options.keyBindings[i] = this.options.keyBindings[i] || keys[i]; + } + + utils.addEvent(window, 'keydown', this); + + this.on('destroy', function () { + utils.removeEvent(window, 'keydown', this); + }); + }, + + _key: function (e) { + if ( !this.enabled ) { + return; + } + + var snap = this.options.snap, // we are using this alot, better to cache it + newX = snap ? this.currentPage.pageX : this.x, + newY = snap ? this.currentPage.pageY : this.y, + now = utils.getTime(), + prevTime = this.keyTime || 0, + acceleration = 0.250, + pos; + + if ( this.options.useTransition && this.isInTransition ) { + pos = this.getComputedPosition(); + + this._translate(Math.round(pos.x), Math.round(pos.y)); + this.isInTransition = false; + } + + this.keyAcceleration = now - prevTime < 200 ? Math.min(this.keyAcceleration + acceleration, 50) : 0; + + switch ( e.keyCode ) { + case this.options.keyBindings.pageUp: + if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) { + newX += snap ? 1 : this.wrapperWidth; + } else { + newY += snap ? 1 : this.wrapperHeight; + } + break; + case this.options.keyBindings.pageDown: + if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) { + newX -= snap ? 1 : this.wrapperWidth; + } else { + newY -= snap ? 1 : this.wrapperHeight; + } + break; + case this.options.keyBindings.end: + newX = snap ? this.pages.length-1 : this.maxScrollX; + newY = snap ? this.pages[0].length-1 : this.maxScrollY; + break; + case this.options.keyBindings.home: + newX = 0; + newY = 0; + break; + case this.options.keyBindings.left: + newX += snap ? -1 : 5 + this.keyAcceleration>>0; + break; + case this.options.keyBindings.up: + newY += snap ? 1 : 5 + this.keyAcceleration>>0; + break; + case this.options.keyBindings.right: + newX -= snap ? -1 : 5 + this.keyAcceleration>>0; + break; + case this.options.keyBindings.down: + newY -= snap ? 1 : 5 + this.keyAcceleration>>0; + break; + default: + return; + } + + if ( snap ) { + this.goToPage(newX, newY); + return; + } + + if ( newX > 0 ) { + newX = 0; + this.keyAcceleration = 0; + } else if ( newX < this.maxScrollX ) { + newX = this.maxScrollX; + this.keyAcceleration = 0; + } + + if ( newY > 0 ) { + newY = 0; + this.keyAcceleration = 0; + } else if ( newY < this.maxScrollY ) { + newY = this.maxScrollY; + this.keyAcceleration = 0; + } + + this.scrollTo(newX, newY, 0); + + this.keyTime = now; + }, + + _animate: function (destX, destY, duration, easingFn) { + var that = this, + startX = this.x, + startY = this.y, + startTime = utils.getTime(), + destTime = startTime + duration; + + function step () { + var now = utils.getTime(), + newX, newY, + easing; + + if ( now >= destTime ) { + that.isAnimating = false; + that._translate(destX, destY); + + if ( !that.resetPosition(that.options.bounceTime) ) { + that._execEvent('scrollEnd'); + } + + return; + } + + now = ( now - startTime ) / duration; + easing = easingFn(now); + newX = ( destX - startX ) * easing + startX; + newY = ( destY - startY ) * easing + startY; + that._translate(newX, newY); + + if ( that.isAnimating ) { + rAF(step); + } + } + + this.isAnimating = true; + step(); + }, + handleEvent: function (e) { + switch ( e.type ) { + case 'touchstart': + case 'MSPointerDown': + case 'mousedown': + this._start(e); + + if ( this.options.zoom && e.touches && e.touches.length > 1 ) { + this._zoomStart(e); + } + break; + case 'touchmove': + case 'MSPointerMove': + case 'mousemove': + if ( this.options.zoom && e.touches && e.touches[1] ) { + this._zoom(e); + return; + } + this._move(e); + break; + case 'touchend': + case 'MSPointerUp': + case 'mouseup': + case 'touchcancel': + case 'MSPointerCancel': + case 'mousecancel': + if ( this.scaled ) { + this._zoomEnd(e); + return; + } + this._end(e); + break; + case 'orientationchange': + case 'resize': + this._resize(); + break; + case 'transitionend': + case 'webkitTransitionEnd': + case 'oTransitionEnd': + case 'MSTransitionEnd': + this._transitionEnd(e); + break; + case 'wheel': + case 'DOMMouseScroll': + case 'mousewheel': + if ( this.options.wheelAction == 'zoom' ) { + this._wheelZoom(e); + return; + } + this._wheel(e); + break; + case 'keydown': + this._key(e); + break; + } + } + +}; +function createDefaultScrollbar (direction, interactive, type) { + var scrollbar = document.createElement('div'), + indicator = document.createElement('div'); + + if ( type === true ) { + scrollbar.style.cssText = 'position:absolute;z-index:9999'; + indicator.style.cssText = '-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px'; + } + + indicator.className = 'iScrollIndicator'; + + if ( direction == 'h' ) { + if ( type === true ) { + scrollbar.style.cssText += ';height:7px;left:2px;right:2px;bottom:0'; + indicator.style.height = '100%'; + } + scrollbar.className = 'iScrollHorizontalScrollbar'; + } else { + if ( type === true ) { + scrollbar.style.cssText += ';width:7px;bottom:2px;top:2px;right:1px'; + indicator.style.width = '100%'; + } + scrollbar.className = 'iScrollVerticalScrollbar'; + } + + scrollbar.style.cssText += ';overflow:hidden'; + + if ( !interactive ) { + scrollbar.style.pointerEvents = 'none'; + } + + scrollbar.appendChild(indicator); + + return scrollbar; +} + +function Indicator (scroller, options) { + this.wrapper = typeof options.el == 'string' ? document.querySelector(options.el) : options.el; + this.wrapperStyle = this.wrapper.style; + this.indicator = this.wrapper.children[0]; + this.indicatorStyle = this.indicator.style; + this.scroller = scroller; + + this.options = { + listenX: true, + listenY: true, + interactive: false, + resize: true, + defaultScrollbars: false, + shrink: false, + fade: false, + speedRatioX: 0, + speedRatioY: 0 + }; + + for ( var i in options ) { + this.options[i] = options[i]; + } + + this.sizeRatioX = 1; + this.sizeRatioY = 1; + this.maxPosX = 0; + this.maxPosY = 0; + + if ( this.options.interactive ) { + if ( !this.options.disableTouch ) { + utils.addEvent(this.indicator, 'touchstart', this); + utils.addEvent(window, 'touchend', this); + } + if ( !this.options.disablePointer ) { + utils.addEvent(this.indicator, 'MSPointerDown', this); + utils.addEvent(window, 'MSPointerUp', this); + } + if ( !this.options.disableMouse ) { + utils.addEvent(this.indicator, 'mousedown', this); + utils.addEvent(window, 'mouseup', this); + } + } + + if ( this.options.fade ) { + this.wrapperStyle[utils.style.transform] = this.scroller.translateZ; + this.wrapperStyle[utils.style.transitionDuration] = utils.isBadAndroid ? '0.001s' : '0ms'; + this.wrapperStyle.opacity = '0'; + } +} + +Indicator.prototype = { + handleEvent: function (e) { + switch ( e.type ) { + case 'touchstart': + case 'MSPointerDown': + case 'mousedown': + this._start(e); + break; + case 'touchmove': + case 'MSPointerMove': + case 'mousemove': + this._move(e); + break; + case 'touchend': + case 'MSPointerUp': + case 'mouseup': + case 'touchcancel': + case 'MSPointerCancel': + case 'mousecancel': + this._end(e); + break; + } + }, + + destroy: function () { + if ( this.options.interactive ) { + utils.removeEvent(this.indicator, 'touchstart', this); + utils.removeEvent(this.indicator, 'MSPointerDown', this); + utils.removeEvent(this.indicator, 'mousedown', this); + + utils.removeEvent(window, 'touchmove', this); + utils.removeEvent(window, 'MSPointerMove', this); + utils.removeEvent(window, 'mousemove', this); + + utils.removeEvent(window, 'touchend', this); + utils.removeEvent(window, 'MSPointerUp', this); + utils.removeEvent(window, 'mouseup', this); + } + + if ( this.options.defaultScrollbars ) { + this.wrapper.parentNode.removeChild(this.wrapper); + } + }, + + _start: function (e) { + var point = e.touches ? e.touches[0] : e; + + e.preventDefault(); + e.stopPropagation(); + + this.transitionTime(); + + this.initiated = true; + this.moved = false; + this.lastPointX = point.pageX; + this.lastPointY = point.pageY; + + this.startTime = utils.getTime(); + + if ( !this.options.disableTouch ) { + utils.addEvent(window, 'touchmove', this); + } + if ( !this.options.disablePointer ) { + utils.addEvent(window, 'MSPointerMove', this); + } + if ( !this.options.disableMouse ) { + utils.addEvent(window, 'mousemove', this); + } + + this.scroller._execEvent('beforeScrollStart'); + }, + + _move: function (e) { + var point = e.touches ? e.touches[0] : e, + deltaX, deltaY, + newX, newY, + timestamp = utils.getTime(); + + if ( !this.moved ) { + this.scroller._execEvent('scrollStart'); + } + + this.moved = true; + + deltaX = point.pageX - this.lastPointX; + this.lastPointX = point.pageX; + + deltaY = point.pageY - this.lastPointY; + this.lastPointY = point.pageY; + + newX = this.x + deltaX; + newY = this.y + deltaY; + + this._pos(newX, newY); + +// INSERT POINT: indicator._move + + e.preventDefault(); + e.stopPropagation(); + }, + + _end: function (e) { + if ( !this.initiated ) { + return; + } + + this.initiated = false; + + e.preventDefault(); + e.stopPropagation(); + + utils.removeEvent(window, 'touchmove', this); + utils.removeEvent(window, 'MSPointerMove', this); + utils.removeEvent(window, 'mousemove', this); + + if ( this.scroller.options.snap ) { + var snap = this.scroller._nearestSnap(this.scroller.x, this.scroller.y); + + var time = this.options.snapSpeed || Math.max( + Math.max( + Math.min(Math.abs(this.scroller.x - snap.x), 1000), + Math.min(Math.abs(this.scroller.y - snap.y), 1000) + ), 300); + + if ( this.scroller.x != snap.x || this.scroller.y != snap.y ) { + this.scroller.directionX = 0; + this.scroller.directionY = 0; + this.scroller.currentPage = snap; + this.scroller.scrollTo(snap.x, snap.y, time, this.scroller.options.bounceEasing); + } + } + + if ( this.moved ) { + this.scroller._execEvent('scrollEnd'); + } + }, + + transitionTime: function (time) { + time = time || 0; + this.indicatorStyle[utils.style.transitionDuration] = time + 'ms'; + + if ( !time && utils.isBadAndroid ) { + this.indicatorStyle[utils.style.transitionDuration] = '0.001s'; + } + }, + + transitionTimingFunction: function (easing) { + this.indicatorStyle[utils.style.transitionTimingFunction] = easing; + }, + + refresh: function () { + this.transitionTime(); + + if ( this.options.listenX && !this.options.listenY ) { + this.indicatorStyle.display = this.scroller.hasHorizontalScroll ? 'block' : 'none'; + } else if ( this.options.listenY && !this.options.listenX ) { + this.indicatorStyle.display = this.scroller.hasVerticalScroll ? 'block' : 'none'; + } else { + this.indicatorStyle.display = this.scroller.hasHorizontalScroll || this.scroller.hasVerticalScroll ? 'block' : 'none'; + } + + if ( this.scroller.hasHorizontalScroll && this.scroller.hasVerticalScroll ) { + utils.addClass(this.wrapper, 'iScrollBothScrollbars'); + utils.removeClass(this.wrapper, 'iScrollLoneScrollbar'); + + if ( this.options.defaultScrollbars && this.options.customStyle ) { + if ( this.options.listenX ) { + this.wrapper.style.right = '8px'; + } else { + this.wrapper.style.bottom = '8px'; + } + } + } else { + utils.removeClass(this.wrapper, 'iScrollBothScrollbars'); + utils.addClass(this.wrapper, 'iScrollLoneScrollbar'); + + if ( this.options.defaultScrollbars && this.options.customStyle ) { + if ( this.options.listenX ) { + this.wrapper.style.right = '2px'; + } else { + this.wrapper.style.bottom = '2px'; + } + } + } + + var r = this.wrapper.offsetHeight; // force refresh + + if ( this.options.listenX ) { + this.wrapperWidth = this.wrapper.clientWidth; + if ( this.options.resize ) { + this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8); + this.indicatorStyle.width = this.indicatorWidth + 'px'; + } else { + this.indicatorWidth = this.indicator.clientWidth; + } + + this.maxPosX = this.wrapperWidth - this.indicatorWidth; + + if ( this.options.shrink == 'clip' ) { + this.minBoundaryX = -this.indicatorWidth + 8; + this.maxBoundaryX = this.wrapperWidth - 8; + } else { + this.minBoundaryX = 0; + this.maxBoundaryX = this.maxPosX; + } + + this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX)); + } + + if ( this.options.listenY ) { + this.wrapperHeight = this.wrapper.clientHeight; + if ( this.options.resize ) { + this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8); + this.indicatorStyle.height = this.indicatorHeight + 'px'; + } else { + this.indicatorHeight = this.indicator.clientHeight; + } + + this.maxPosY = this.wrapperHeight - this.indicatorHeight; + + if ( this.options.shrink == 'clip' ) { + this.minBoundaryY = -this.indicatorHeight + 8; + this.maxBoundaryY = this.wrapperHeight - 8; + } else { + this.minBoundaryY = 0; + this.maxBoundaryY = this.maxPosY; + } + + this.maxPosY = this.wrapperHeight - this.indicatorHeight; + this.sizeRatioY = this.options.speedRatioY || (this.scroller.maxScrollY && (this.maxPosY / this.scroller.maxScrollY)); + } + + this.updatePosition(); + }, + + updatePosition: function () { + var x = this.options.listenX && Math.round(this.sizeRatioX * this.scroller.x) || 0, + y = this.options.listenY && Math.round(this.sizeRatioY * this.scroller.y) || 0; + + if ( !this.options.ignoreBoundaries ) { + if ( x < this.minBoundaryX ) { + if ( this.options.shrink == 'scale' ) { + this.width = Math.max(this.indicatorWidth + x, 8); + this.indicatorStyle.width = this.width + 'px'; + } + x = this.minBoundaryX; + } else if ( x > this.maxBoundaryX ) { + if ( this.options.shrink == 'scale' ) { + this.width = Math.max(this.indicatorWidth - (x - this.maxPosX), 8); + this.indicatorStyle.width = this.width + 'px'; + x = this.maxPosX + this.indicatorWidth - this.width; + } else { + x = this.maxBoundaryX; + } + } else if ( this.options.shrink == 'scale' && this.width != this.indicatorWidth ) { + this.width = this.indicatorWidth; + this.indicatorStyle.width = this.width + 'px'; + } + + if ( y < this.minBoundaryY ) { + if ( this.options.shrink == 'scale' ) { + this.height = Math.max(this.indicatorHeight + y * 3, 8); + this.indicatorStyle.height = this.height + 'px'; + } + y = this.minBoundaryY; + } else if ( y > this.maxBoundaryY ) { + if ( this.options.shrink == 'scale' ) { + this.height = Math.max(this.indicatorHeight - (y - this.maxPosY) * 3, 8); + this.indicatorStyle.height = this.height + 'px'; + y = this.maxPosY + this.indicatorHeight - this.height; + } else { + y = this.maxBoundaryY; + } + } else if ( this.options.shrink == 'scale' && this.height != this.indicatorHeight ) { + this.height = this.indicatorHeight; + this.indicatorStyle.height = this.height + 'px'; + } + } + + this.x = x; + this.y = y; + + if ( this.scroller.options.useTransform ) { + this.indicatorStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.scroller.translateZ; + } else { + this.indicatorStyle.left = x + 'px'; + this.indicatorStyle.top = y + 'px'; + } + }, + + _pos: function (x, y) { + if ( x < 0 ) { + x = 0; + } else if ( x > this.maxPosX ) { + x = this.maxPosX; + } + + if ( y < 0 ) { + y = 0; + } else if ( y > this.maxPosY ) { + y = this.maxPosY; + } + + x = this.options.listenX ? Math.round(x / this.sizeRatioX) : this.scroller.x; + y = this.options.listenY ? Math.round(y / this.sizeRatioY) : this.scroller.y; + + this.scroller.scrollTo(x, y); + }, + + fade: function (val, hold) { + if ( hold && !this.visible ) { + return; + } + + clearTimeout(this.fadeTimeout); + this.fadeTimeout = null; + + var time = val ? 250 : 500, + delay = val ? 0 : 300; + + val = val ? '1' : '0'; + + this.wrapperStyle[utils.style.transitionDuration] = time + 'ms'; + + this.fadeTimeout = setTimeout((function (val) { + this.wrapperStyle.opacity = val; + this.visible = +val; + }).bind(this, val), delay); + } +}; + +IScroll.utils = utils; + +if ( typeof module != 'undefined' && module.exports ) { + module.exports = IScroll; +} else { + window.IScroll = IScroll; +} + +})(window, document, Math); \ No newline at end of file diff --git a/assets/html/iscroll.js b/assets/html/iscroll.js new file mode 100644 index 0000000..0db50c6 --- /dev/null +++ b/assets/html/iscroll.js @@ -0,0 +1,1988 @@ +/*! iScroll v5.1.1 ~ (c) 2008-2014 Matteo Spinelli ~ http://cubiq.org/license */ +(function (window, document, Math) { +var rAF = window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function (callback) { window.setTimeout(callback, 1000 / 60); }; + +var utils = (function () { + var me = {}; + + var _elementStyle = document.createElement('div').style; + var _vendor = (function () { + var vendors = ['t', 'webkitT', 'MozT', 'msT', 'OT'], + transform, + i = 0, + l = vendors.length; + + for ( ; i < l; i++ ) { + transform = vendors[i] + 'ransform'; + if ( transform in _elementStyle ) return vendors[i].substr(0, vendors[i].length-1); + } + + return false; + })(); + + function _prefixStyle (style) { + if ( _vendor === false ) return false; + if ( _vendor === '' ) return style; + return _vendor + style.charAt(0).toUpperCase() + style.substr(1); + } + + me.getTime = Date.now || function getTime () { return new Date().getTime(); }; + + me.extend = function (target, obj) { + for ( var i in obj ) { + target[i] = obj[i]; + } + }; + + me.addEvent = function (el, type, fn, capture) { + el.addEventListener(type, fn, !!capture); + }; + + me.removeEvent = function (el, type, fn, capture) { + el.removeEventListener(type, fn, !!capture); + }; + + me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) { + var distance = current - start, + speed = Math.abs(distance) / time, + destination, + duration; + + deceleration = deceleration === undefined ? 0.0006 : deceleration; + + destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 ); + duration = speed / deceleration; + + if ( destination < lowerMargin ) { + destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin; + distance = Math.abs(destination - current); + duration = distance / speed; + } else if ( destination > 0 ) { + destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0; + distance = Math.abs(current) + destination; + duration = distance / speed; + } + + return { + destination: Math.round(destination), + duration: duration + }; + }; + + var _transform = _prefixStyle('transform'); + + me.extend(me, { + hasTransform: _transform !== false, + hasPerspective: _prefixStyle('perspective') in _elementStyle, + hasTouch: 'ontouchstart' in window, + hasPointer: navigator.msPointerEnabled, + hasTransition: _prefixStyle('transition') in _elementStyle + }); + + // This should find all Android browsers lower than build 535.19 (both stock browser and webview) + me.isBadAndroid = /Android /.test(window.navigator.appVersion) && !(/Chrome\/\d/.test(window.navigator.appVersion)); + + me.extend(me.style = {}, { + transform: _transform, + transitionTimingFunction: _prefixStyle('transitionTimingFunction'), + transitionDuration: _prefixStyle('transitionDuration'), + transitionDelay: _prefixStyle('transitionDelay'), + transformOrigin: _prefixStyle('transformOrigin') + }); + + me.hasClass = function (e, c) { + var re = new RegExp("(^|\\s)" + c + "(\\s|$)"); + return re.test(e.className); + }; + + me.addClass = function (e, c) { + if ( me.hasClass(e, c) ) { + return; + } + + var newclass = e.className.split(' '); + newclass.push(c); + e.className = newclass.join(' '); + }; + + me.removeClass = function (e, c) { + if ( !me.hasClass(e, c) ) { + return; + } + + var re = new RegExp("(^|\\s)" + c + "(\\s|$)", 'g'); + e.className = e.className.replace(re, ' '); + }; + + me.offset = function (el) { + var left = -el.offsetLeft, + top = -el.offsetTop; + + // jshint -W084 + while (el = el.offsetParent) { + left -= el.offsetLeft; + top -= el.offsetTop; + } + // jshint +W084 + + return { + left: left, + top: top + }; + }; + + me.preventDefaultException = function (el, exceptions) { + for ( var i in exceptions ) { + if ( exceptions[i].test(el[i]) ) { + return true; + } + } + + return false; + }; + + me.extend(me.eventType = {}, { + touchstart: 1, + touchmove: 1, + touchend: 1, + + mousedown: 2, + mousemove: 2, + mouseup: 2, + + MSPointerDown: 3, + MSPointerMove: 3, + MSPointerUp: 3 + }); + + me.extend(me.ease = {}, { + quadratic: { + style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)', + fn: function (k) { + return k * ( 2 - k ); + } + }, + circular: { + style: 'cubic-bezier(0.1, 0.57, 0.1, 1)', // Not properly "circular" but this looks better, it should be (0.075, 0.82, 0.165, 1) + fn: function (k) { + return Math.sqrt( 1 - ( --k * k ) ); + } + }, + back: { + style: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)', + fn: function (k) { + var b = 4; + return ( k = k - 1 ) * k * ( ( b + 1 ) * k + b ) + 1; + } + }, + bounce: { + style: '', + fn: function (k) { + if ( ( k /= 1 ) < ( 1 / 2.75 ) ) { + return 7.5625 * k * k; + } else if ( k < ( 2 / 2.75 ) ) { + return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75; + } else if ( k < ( 2.5 / 2.75 ) ) { + return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375; + } else { + return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375; + } + } + }, + elastic: { + style: '', + fn: function (k) { + var f = 0.22, + e = 0.4; + + if ( k === 0 ) { return 0; } + if ( k == 1 ) { return 1; } + + return ( e * Math.pow( 2, - 10 * k ) * Math.sin( ( k - f / 4 ) * ( 2 * Math.PI ) / f ) + 1 ); + } + } + }); + + me.tap = function (e, eventName) { + var ev = document.createEvent('Event'); + ev.initEvent(eventName, true, true); + ev.pageX = e.pageX; + ev.pageY = e.pageY; + e.target.dispatchEvent(ev); + }; + + me.click = function (e) { + var target = e.target, + ev; + + if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) { + ev = document.createEvent('MouseEvents'); + ev.initMouseEvent('click', true, true, e.view, 1, + target.screenX, target.screenY, target.clientX, target.clientY, + e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, + 0, null); + + ev._constructed = true; + target.dispatchEvent(ev); + } + }; + + return me; +})(); + +function IScroll (el, options) { + this.wrapper = typeof el == 'string' ? document.querySelector(el) : el; + this.scroller = this.wrapper.children[0]; + this.scrollerStyle = this.scroller.style; // cache style for better performance + + this.options = { + + resizeScrollbars: true, + + mouseWheelSpeed: 20, + + snapThreshold: 0.334, + +// INSERT POINT: OPTIONS + + startX: 0, + startY: 0, + scrollY: true, + directionLockThreshold: 5, + momentum: true, + + bounce: true, + bounceTime: 600, + bounceEasing: '', + + preventDefault: true, + preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ }, + + HWCompositing: true, + useTransition: true, + useTransform: true + }; + + for ( var i in options ) { + this.options[i] = options[i]; + } + + // Normalize options + this.translateZ = this.options.HWCompositing && utils.hasPerspective ? ' translateZ(0)' : ''; + + this.options.useTransition = utils.hasTransition && this.options.useTransition; + this.options.useTransform = utils.hasTransform && this.options.useTransform; + + this.options.eventPassthrough = this.options.eventPassthrough === true ? 'vertical' : this.options.eventPassthrough; + this.options.preventDefault = !this.options.eventPassthrough && this.options.preventDefault; + + // If you want eventPassthrough I have to lock one of the axes + this.options.scrollY = this.options.eventPassthrough == 'vertical' ? false : this.options.scrollY; + this.options.scrollX = this.options.eventPassthrough == 'horizontal' ? false : this.options.scrollX; + + // With eventPassthrough we also need lockDirection mechanism + this.options.freeScroll = this.options.freeScroll && !this.options.eventPassthrough; + this.options.directionLockThreshold = this.options.eventPassthrough ? 0 : this.options.directionLockThreshold; + + this.options.bounceEasing = typeof this.options.bounceEasing == 'string' ? utils.ease[this.options.bounceEasing] || utils.ease.circular : this.options.bounceEasing; + + this.options.resizePolling = this.options.resizePolling === undefined ? 60 : this.options.resizePolling; + + if ( this.options.tap === true ) { + this.options.tap = 'tap'; + } + + if ( this.options.shrinkScrollbars == 'scale' ) { + this.options.useTransition = false; + } + + this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1; + +// INSERT POINT: NORMALIZATION + + // Some defaults + this.x = 0; + this.y = 0; + this.directionX = 0; + this.directionY = 0; + this._events = {}; + +// INSERT POINT: DEFAULTS + + this._init(); + this.refresh(); + + this.scrollTo(this.options.startX, this.options.startY); + this.enable(); +} + +IScroll.prototype = { + version: '5.1.1', + + _init: function () { + this._initEvents(); + + if ( this.options.scrollbars || this.options.indicators ) { + this._initIndicators(); + } + + if ( this.options.mouseWheel ) { + this._initWheel(); + } + + if ( this.options.snap ) { + this._initSnap(); + } + + if ( this.options.keyBindings ) { + this._initKeys(); + } + +// INSERT POINT: _init + + }, + + destroy: function () { + this._initEvents(true); + + this._execEvent('destroy'); + }, + + _transitionEnd: function (e) { + if ( e.target != this.scroller || !this.isInTransition ) { + return; + } + + this._transitionTime(); + if ( !this.resetPosition(this.options.bounceTime) ) { + this.isInTransition = false; + this._execEvent('scrollEnd'); + } + }, + + _start: function (e) { + // React to left mouse button only + if ( utils.eventType[e.type] != 1 ) { + if ( e.button !== 0 ) { + return; + } + } + + if ( !this.enabled || (this.initiated && utils.eventType[e.type] !== this.initiated) ) { + return; + } + + if ( this.options.preventDefault && !utils.isBadAndroid && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) { + e.preventDefault(); + } + + var point = e.touches ? e.touches[0] : e, + pos; + + this.initiated = utils.eventType[e.type]; + this.moved = false; + this.distX = 0; + this.distY = 0; + this.directionX = 0; + this.directionY = 0; + this.directionLocked = 0; + + this._transitionTime(); + + this.startTime = utils.getTime(); + + if ( this.options.useTransition && this.isInTransition ) { + this.isInTransition = false; + pos = this.getComputedPosition(); + this._translate(Math.round(pos.x), Math.round(pos.y)); + this._execEvent('scrollEnd'); + } else if ( !this.options.useTransition && this.isAnimating ) { + this.isAnimating = false; + this._execEvent('scrollEnd'); + } + + this.startX = this.x; + this.startY = this.y; + this.absStartX = this.x; + this.absStartY = this.y; + this.pointX = point.pageX; + this.pointY = point.pageY; + + this._execEvent('beforeScrollStart'); + }, + + _move: function (e) { + if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) { + return; + } + + if ( this.options.preventDefault ) { // increases performance on Android? TODO: check! + e.preventDefault(); + } + + var point = e.touches ? e.touches[0] : e, + deltaX = point.pageX - this.pointX, + deltaY = point.pageY - this.pointY, + timestamp = utils.getTime(), + newX, newY, + absDistX, absDistY; + + this.pointX = point.pageX; + this.pointY = point.pageY; + + this.distX += deltaX; + this.distY += deltaY; + absDistX = Math.abs(this.distX); + absDistY = Math.abs(this.distY); + + // We need to move at least 10 pixels for the scrolling to initiate + if ( timestamp - this.endTime > 300 && (absDistX < 10 && absDistY < 10) ) { + return; + } + + // If you are scrolling in one direction lock the other + if ( !this.directionLocked && !this.options.freeScroll ) { + if ( absDistX > absDistY + this.options.directionLockThreshold ) { + this.directionLocked = 'h'; // lock horizontally + } else if ( absDistY >= absDistX + this.options.directionLockThreshold ) { + this.directionLocked = 'v'; // lock vertically + } else { + this.directionLocked = 'n'; // no lock + } + } + + if ( this.directionLocked == 'h' ) { + if ( this.options.eventPassthrough == 'vertical' ) { + e.preventDefault(); + } else if ( this.options.eventPassthrough == 'horizontal' ) { + this.initiated = false; + return; + } + + deltaY = 0; + } else if ( this.directionLocked == 'v' ) { + if ( this.options.eventPassthrough == 'horizontal' ) { + e.preventDefault(); + } else if ( this.options.eventPassthrough == 'vertical' ) { + this.initiated = false; + return; + } + + deltaX = 0; + } + + deltaX = this.hasHorizontalScroll ? deltaX : 0; + deltaY = this.hasVerticalScroll ? deltaY : 0; + + newX = this.x + deltaX; + newY = this.y + deltaY; + + // Slow down if outside of the boundaries + if ( newX > 0 || newX < this.maxScrollX ) { + newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX; + } + if ( newY > 0 || newY < this.maxScrollY ) { + newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY; + } + + this.directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0; + this.directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0; + + if ( !this.moved ) { + this._execEvent('scrollStart'); + } + + this.moved = true; + + this._translate(newX, newY); + +/* REPLACE START: _move */ + + if ( timestamp - this.startTime > 300 ) { + this.startTime = timestamp; + this.startX = this.x; + this.startY = this.y; + } + +/* REPLACE END: _move */ + + }, + + _end: function (e) { + if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) { + return; + } + + if ( this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) { + e.preventDefault(); + } + + var point = e.changedTouches ? e.changedTouches[0] : e, + momentumX, + momentumY, + duration = utils.getTime() - this.startTime, + newX = Math.round(this.x), + newY = Math.round(this.y), + distanceX = Math.abs(newX - this.startX), + distanceY = Math.abs(newY - this.startY), + time = 0, + easing = ''; + + this.isInTransition = 0; + this.initiated = 0; + this.endTime = utils.getTime(); + + // reset if we are outside of the boundaries + if ( this.resetPosition(this.options.bounceTime) ) { + return; + } + + this.scrollTo(newX, newY); // ensures that the last position is rounded + + // we scrolled less than 10 pixels + if ( !this.moved ) { + if ( this.options.tap ) { + utils.tap(e, this.options.tap); + } + + if ( this.options.click ) { + utils.click(e); + } + + this._execEvent('scrollCancel'); + return; + } + + if ( this._events.flick && duration < 200 && distanceX < 100 && distanceY < 100 ) { + this._execEvent('flick'); + return; + } + + // start momentum animation if needed + if ( this.options.momentum && duration < 300 ) { + momentumX = this.hasHorizontalScroll ? utils.momentum(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : { destination: newX, duration: 0 }; + momentumY = this.hasVerticalScroll ? utils.momentum(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : { destination: newY, duration: 0 }; + newX = momentumX.destination; + newY = momentumY.destination; + time = Math.max(momentumX.duration, momentumY.duration); + this.isInTransition = 1; + } + + + if ( this.options.snap ) { + var snap = this._nearestSnap(newX, newY); + this.currentPage = snap; + time = this.options.snapSpeed || Math.max( + Math.max( + Math.min(Math.abs(newX - snap.x), 1000), + Math.min(Math.abs(newY - snap.y), 1000) + ), 300); + newX = snap.x; + newY = snap.y; + + this.directionX = 0; + this.directionY = 0; + easing = this.options.bounceEasing; + } + +// INSERT POINT: _end + + if ( newX != this.x || newY != this.y ) { + // change easing function when scroller goes out of the boundaries + if ( newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY ) { + easing = utils.ease.quadratic; + } + + this.scrollTo(newX, newY, time, easing); + return; + } + + this._execEvent('scrollEnd'); + }, + + _resize: function () { + var that = this; + + clearTimeout(this.resizeTimeout); + + this.resizeTimeout = setTimeout(function () { + that.refresh(); + }, this.options.resizePolling); + }, + + resetPosition: function (time) { + var x = this.x, + y = this.y; + + time = time || 0; + + if ( !this.hasHorizontalScroll || this.x > 0 ) { + x = 0; + } else if ( this.x < this.maxScrollX ) { + x = this.maxScrollX; + } + + if ( !this.hasVerticalScroll || this.y > 0 ) { + y = 0; + } else if ( this.y < this.maxScrollY ) { + y = this.maxScrollY; + } + + if ( x == this.x && y == this.y ) { + return false; + } + + this.scrollTo(x, y, time, this.options.bounceEasing); + + return true; + }, + + disable: function () { + this.enabled = false; + }, + + enable: function () { + this.enabled = true; + }, + + refresh: function () { + var rf = this.wrapper.offsetHeight; // Force reflow + + this.wrapperWidth = this.wrapper.clientWidth; + this.wrapperHeight = this.wrapper.clientHeight; + +/* REPLACE START: refresh */ + + this.scrollerWidth = this.scroller.offsetWidth; + this.scrollerHeight = this.scroller.offsetHeight; + + this.maxScrollX = this.wrapperWidth - this.scrollerWidth; + this.maxScrollY = this.wrapperHeight - this.scrollerHeight; + +/* REPLACE END: refresh */ + + this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0; + this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0; + + if ( !this.hasHorizontalScroll ) { + this.maxScrollX = 0; + this.scrollerWidth = this.wrapperWidth; + } + + if ( !this.hasVerticalScroll ) { + this.maxScrollY = 0; + this.scrollerHeight = this.wrapperHeight; + } + + this.endTime = 0; + this.directionX = 0; + this.directionY = 0; + + this.wrapperOffset = utils.offset(this.wrapper); + + this._execEvent('refresh'); + + this.resetPosition(); + +// INSERT POINT: _refresh + + }, + + on: function (type, fn) { + if ( !this._events[type] ) { + this._events[type] = []; + } + + this._events[type].push(fn); + }, + + off: function (type, fn) { + if ( !this._events[type] ) { + return; + } + + var index = this._events[type].indexOf(fn); + + if ( index > -1 ) { + this._events[type].splice(index, 1); + } + }, + + _execEvent: function (type) { + if ( !this._events[type] ) { + return; + } + + var i = 0, + l = this._events[type].length; + + if ( !l ) { + return; + } + + for ( ; i < l; i++ ) { + this._events[type][i].apply(this, [].slice.call(arguments, 1)); + } + }, + + scrollBy: function (x, y, time, easing) { + x = this.x + x; + y = this.y + y; + time = time || 0; + + this.scrollTo(x, y, time, easing); + }, + + scrollTo: function (x, y, time, easing) { + easing = easing || utils.ease.circular; + + this.isInTransition = this.options.useTransition && time > 0; + + if ( !time || (this.options.useTransition && easing.style) ) { + this._transitionTimingFunction(easing.style); + this._transitionTime(time); + this._translate(x, y); + } else { + this._animate(x, y, time, easing.fn); + } + }, + + scrollToElement: function (el, time, offsetX, offsetY, easing) { + el = el.nodeType ? el : this.scroller.querySelector(el); + + if ( !el ) { + return; + } + + var pos = utils.offset(el); + + pos.left -= this.wrapperOffset.left; + pos.top -= this.wrapperOffset.top; + + // if offsetX/Y are true we center the element to the screen + if ( offsetX === true ) { + offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2); + } + if ( offsetY === true ) { + offsetY = Math.round(el.offsetHeight / 2 - this.wrapper.offsetHeight / 2); + } + + pos.left -= offsetX || 0; + pos.top -= offsetY || 0; + + pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left; + pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top; + + time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x-pos.left), Math.abs(this.y-pos.top)) : time; + + this.scrollTo(pos.left, pos.top, time, easing); + }, + + _transitionTime: function (time) { + time = time || 0; + + this.scrollerStyle[utils.style.transitionDuration] = time + 'ms'; + + if ( !time && utils.isBadAndroid ) { + this.scrollerStyle[utils.style.transitionDuration] = '0.001s'; + } + + + if ( this.indicators ) { + for ( var i = this.indicators.length; i--; ) { + this.indicators[i].transitionTime(time); + } + } + + +// INSERT POINT: _transitionTime + + }, + + _transitionTimingFunction: function (easing) { + this.scrollerStyle[utils.style.transitionTimingFunction] = easing; + + + if ( this.indicators ) { + for ( var i = this.indicators.length; i--; ) { + this.indicators[i].transitionTimingFunction(easing); + } + } + + +// INSERT POINT: _transitionTimingFunction + + }, + + _translate: function (x, y) { + if ( this.options.useTransform ) { + +/* REPLACE START: _translate */ + + this.scrollerStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.translateZ; + +/* REPLACE END: _translate */ + + } else { + x = Math.round(x); + y = Math.round(y); + this.scrollerStyle.left = x + 'px'; + this.scrollerStyle.top = y + 'px'; + } + + this.x = x; + this.y = y; + + + if ( this.indicators ) { + for ( var i = this.indicators.length; i--; ) { + this.indicators[i].updatePosition(); + } + } + + +// INSERT POINT: _translate + + }, + + _initEvents: function (remove) { + var eventType = remove ? utils.removeEvent : utils.addEvent, + target = this.options.bindToWrapper ? this.wrapper : window; + + eventType(window, 'orientationchange', this); + eventType(window, 'resize', this); + + if ( this.options.click ) { + eventType(this.wrapper, 'click', this, true); + } + + if ( !this.options.disableMouse ) { + eventType(this.wrapper, 'mousedown', this); + eventType(target, 'mousemove', this); + eventType(target, 'mousecancel', this); + eventType(target, 'mouseup', this); + } + + if ( utils.hasPointer && !this.options.disablePointer ) { + eventType(this.wrapper, 'MSPointerDown', this); + eventType(target, 'MSPointerMove', this); + eventType(target, 'MSPointerCancel', this); + eventType(target, 'MSPointerUp', this); + } + + if ( utils.hasTouch && !this.options.disableTouch ) { + eventType(this.wrapper, 'touchstart', this); + eventType(target, 'touchmove', this); + eventType(target, 'touchcancel', this); + eventType(target, 'touchend', this); + } + + eventType(this.scroller, 'transitionend', this); + eventType(this.scroller, 'webkitTransitionEnd', this); + eventType(this.scroller, 'oTransitionEnd', this); + eventType(this.scroller, 'MSTransitionEnd', this); + }, + + getComputedPosition: function () { + var matrix = window.getComputedStyle(this.scroller, null), + x, y; + + if ( this.options.useTransform ) { + matrix = matrix[utils.style.transform].split(')')[0].split(', '); + x = +(matrix[12] || matrix[4]); + y = +(matrix[13] || matrix[5]); + } else { + x = +matrix.left.replace(/[^-\d.]/g, ''); + y = +matrix.top.replace(/[^-\d.]/g, ''); + } + + return { x: x, y: y }; + }, + + _initIndicators: function () { + var interactive = this.options.interactiveScrollbars, + customStyle = typeof this.options.scrollbars != 'string', + indicators = [], + indicator; + + var that = this; + + this.indicators = []; + + if ( this.options.scrollbars ) { + // Vertical scrollbar + if ( this.options.scrollY ) { + indicator = { + el: createDefaultScrollbar('v', interactive, this.options.scrollbars), + interactive: interactive, + defaultScrollbars: true, + customStyle: customStyle, + resize: this.options.resizeScrollbars, + shrink: this.options.shrinkScrollbars, + fade: this.options.fadeScrollbars, + listenX: false + }; + + this.wrapper.appendChild(indicator.el); + indicators.push(indicator); + } + + // Horizontal scrollbar + if ( this.options.scrollX ) { + indicator = { + el: createDefaultScrollbar('h', interactive, this.options.scrollbars), + interactive: interactive, + defaultScrollbars: true, + customStyle: customStyle, + resize: this.options.resizeScrollbars, + shrink: this.options.shrinkScrollbars, + fade: this.options.fadeScrollbars, + listenY: false + }; + + this.wrapper.appendChild(indicator.el); + indicators.push(indicator); + } + } + + if ( this.options.indicators ) { + // TODO: check concat compatibility + indicators = indicators.concat(this.options.indicators); + } + + for ( var i = indicators.length; i--; ) { + this.indicators.push( new Indicator(this, indicators[i]) ); + } + + // TODO: check if we can use array.map (wide compatibility and performance issues) + function _indicatorsMap (fn) { + for ( var i = that.indicators.length; i--; ) { + fn.call(that.indicators[i]); + } + } + + if ( this.options.fadeScrollbars ) { + this.on('scrollEnd', function () { + _indicatorsMap(function () { + this.fade(); + }); + }); + + this.on('scrollCancel', function () { + _indicatorsMap(function () { + this.fade(); + }); + }); + + this.on('scrollStart', function () { + _indicatorsMap(function () { + this.fade(1); + }); + }); + + this.on('beforeScrollStart', function () { + _indicatorsMap(function () { + this.fade(1, true); + }); + }); + } + + + this.on('refresh', function () { + _indicatorsMap(function () { + this.refresh(); + }); + }); + + this.on('destroy', function () { + _indicatorsMap(function () { + this.destroy(); + }); + + delete this.indicators; + }); + }, + + _initWheel: function () { + utils.addEvent(this.wrapper, 'wheel', this); + utils.addEvent(this.wrapper, 'mousewheel', this); + utils.addEvent(this.wrapper, 'DOMMouseScroll', this); + + this.on('destroy', function () { + utils.removeEvent(this.wrapper, 'wheel', this); + utils.removeEvent(this.wrapper, 'mousewheel', this); + utils.removeEvent(this.wrapper, 'DOMMouseScroll', this); + }); + }, + + _wheel: function (e) { + if ( !this.enabled ) { + return; + } + + e.preventDefault(); + e.stopPropagation(); + + var wheelDeltaX, wheelDeltaY, + newX, newY, + that = this; + + if ( this.wheelTimeout === undefined ) { + that._execEvent('scrollStart'); + } + + // Execute the scrollEnd event after 400ms the wheel stopped scrolling + clearTimeout(this.wheelTimeout); + this.wheelTimeout = setTimeout(function () { + that._execEvent('scrollEnd'); + that.wheelTimeout = undefined; + }, 400); + + if ( 'deltaX' in e ) { + wheelDeltaX = -e.deltaX; + wheelDeltaY = -e.deltaY; + } else if ( 'wheelDeltaX' in e ) { + wheelDeltaX = e.wheelDeltaX / 120 * this.options.mouseWheelSpeed; + wheelDeltaY = e.wheelDeltaY / 120 * this.options.mouseWheelSpeed; + } else if ( 'wheelDelta' in e ) { + wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * this.options.mouseWheelSpeed; + } else if ( 'detail' in e ) { + wheelDeltaX = wheelDeltaY = -e.detail / 3 * this.options.mouseWheelSpeed; + } else { + return; + } + + wheelDeltaX *= this.options.invertWheelDirection; + wheelDeltaY *= this.options.invertWheelDirection; + + if ( !this.hasVerticalScroll ) { + wheelDeltaX = wheelDeltaY; + wheelDeltaY = 0; + } + + if ( this.options.snap ) { + newX = this.currentPage.pageX; + newY = this.currentPage.pageY; + + if ( wheelDeltaX > 0 ) { + newX--; + } else if ( wheelDeltaX < 0 ) { + newX++; + } + + if ( wheelDeltaY > 0 ) { + newY--; + } else if ( wheelDeltaY < 0 ) { + newY++; + } + + this.goToPage(newX, newY); + + return; + } + + newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0); + newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0); + + if ( newX > 0 ) { + newX = 0; + } else if ( newX < this.maxScrollX ) { + newX = this.maxScrollX; + } + + if ( newY > 0 ) { + newY = 0; + } else if ( newY < this.maxScrollY ) { + newY = this.maxScrollY; + } + + this.scrollTo(newX, newY, 0); + +// INSERT POINT: _wheel + }, + + _initSnap: function () { + this.currentPage = {}; + + if ( typeof this.options.snap == 'string' ) { + this.options.snap = this.scroller.querySelectorAll(this.options.snap); + } + + this.on('refresh', function () { + var i = 0, l, + m = 0, n, + cx, cy, + x = 0, y, + stepX = this.options.snapStepX || this.wrapperWidth, + stepY = this.options.snapStepY || this.wrapperHeight, + el; + + this.pages = []; + + if ( !this.wrapperWidth || !this.wrapperHeight || !this.scrollerWidth || !this.scrollerHeight ) { + return; + } + + if ( this.options.snap === true ) { + cx = Math.round( stepX / 2 ); + cy = Math.round( stepY / 2 ); + + while ( x > -this.scrollerWidth ) { + this.pages[i] = []; + l = 0; + y = 0; + + while ( y > -this.scrollerHeight ) { + this.pages[i][l] = { + x: Math.max(x, this.maxScrollX), + y: Math.max(y, this.maxScrollY), + width: stepX, + height: stepY, + cx: x - cx, + cy: y - cy + }; + + y -= stepY; + l++; + } + + x -= stepX; + i++; + } + } else { + el = this.options.snap; + l = el.length; + n = -1; + + for ( ; i < l; i++ ) { + if ( i === 0 || el[i].offsetLeft <= el[i-1].offsetLeft ) { + m = 0; + n++; + } + + if ( !this.pages[m] ) { + this.pages[m] = []; + } + + x = Math.max(-el[i].offsetLeft, this.maxScrollX); + y = Math.max(-el[i].offsetTop, this.maxScrollY); + cx = x - Math.round(el[i].offsetWidth / 2); + cy = y - Math.round(el[i].offsetHeight / 2); + + this.pages[m][n] = { + x: x, + y: y, + width: el[i].offsetWidth, + height: el[i].offsetHeight, + cx: cx, + cy: cy + }; + + if ( x > this.maxScrollX ) { + m++; + } + } + } + + this.goToPage(this.currentPage.pageX || 0, this.currentPage.pageY || 0, 0); + + // Update snap threshold if needed + if ( this.options.snapThreshold % 1 === 0 ) { + this.snapThresholdX = this.options.snapThreshold; + this.snapThresholdY = this.options.snapThreshold; + } else { + this.snapThresholdX = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].width * this.options.snapThreshold); + this.snapThresholdY = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].height * this.options.snapThreshold); + } + }); + + this.on('flick', function () { + var time = this.options.snapSpeed || Math.max( + Math.max( + Math.min(Math.abs(this.x - this.startX), 1000), + Math.min(Math.abs(this.y - this.startY), 1000) + ), 300); + + this.goToPage( + this.currentPage.pageX + this.directionX, + this.currentPage.pageY + this.directionY, + time + ); + }); + }, + + _nearestSnap: function (x, y) { + if ( !this.pages.length ) { + return { x: 0, y: 0, pageX: 0, pageY: 0 }; + } + + var i = 0, + l = this.pages.length, + m = 0; + + // Check if we exceeded the snap threshold + if ( Math.abs(x - this.absStartX) < this.snapThresholdX && + Math.abs(y - this.absStartY) < this.snapThresholdY ) { + return this.currentPage; + } + + if ( x > 0 ) { + x = 0; + } else if ( x < this.maxScrollX ) { + x = this.maxScrollX; + } + + if ( y > 0 ) { + y = 0; + } else if ( y < this.maxScrollY ) { + y = this.maxScrollY; + } + + for ( ; i < l; i++ ) { + if ( x >= this.pages[i][0].cx ) { + x = this.pages[i][0].x; + break; + } + } + + l = this.pages[i].length; + + for ( ; m < l; m++ ) { + if ( y >= this.pages[0][m].cy ) { + y = this.pages[0][m].y; + break; + } + } + + if ( i == this.currentPage.pageX ) { + i += this.directionX; + + if ( i < 0 ) { + i = 0; + } else if ( i >= this.pages.length ) { + i = this.pages.length - 1; + } + + x = this.pages[i][0].x; + } + + if ( m == this.currentPage.pageY ) { + m += this.directionY; + + if ( m < 0 ) { + m = 0; + } else if ( m >= this.pages[0].length ) { + m = this.pages[0].length - 1; + } + + y = this.pages[0][m].y; + } + + return { + x: x, + y: y, + pageX: i, + pageY: m + }; + }, + + goToPage: function (x, y, time, easing) { + easing = easing || this.options.bounceEasing; + + if ( x >= this.pages.length ) { + x = this.pages.length - 1; + } else if ( x < 0 ) { + x = 0; + } + + if ( y >= this.pages[x].length ) { + y = this.pages[x].length - 1; + } else if ( y < 0 ) { + y = 0; + } + + var posX = this.pages[x][y].x, + posY = this.pages[x][y].y; + + time = time === undefined ? this.options.snapSpeed || Math.max( + Math.max( + Math.min(Math.abs(posX - this.x), 1000), + Math.min(Math.abs(posY - this.y), 1000) + ), 300) : time; + + this.currentPage = { + x: posX, + y: posY, + pageX: x, + pageY: y + }; + + this.scrollTo(posX, posY, time, easing); + }, + + next: function (time, easing) { + var x = this.currentPage.pageX, + y = this.currentPage.pageY; + + x++; + + if ( x >= this.pages.length && this.hasVerticalScroll ) { + x = 0; + y++; + } + + this.goToPage(x, y, time, easing); + }, + + prev: function (time, easing) { + var x = this.currentPage.pageX, + y = this.currentPage.pageY; + + x--; + + if ( x < 0 && this.hasVerticalScroll ) { + x = 0; + y--; + } + + this.goToPage(x, y, time, easing); + }, + + _initKeys: function (e) { + // default key bindings + var keys = { + pageUp: 33, + pageDown: 34, + end: 35, + home: 36, + left: 37, + up: 38, + right: 39, + down: 40 + }; + var i; + + // if you give me characters I give you keycode + if ( typeof this.options.keyBindings == 'object' ) { + for ( i in this.options.keyBindings ) { + if ( typeof this.options.keyBindings[i] == 'string' ) { + this.options.keyBindings[i] = this.options.keyBindings[i].toUpperCase().charCodeAt(0); + } + } + } else { + this.options.keyBindings = {}; + } + + for ( i in keys ) { + this.options.keyBindings[i] = this.options.keyBindings[i] || keys[i]; + } + + utils.addEvent(window, 'keydown', this); + + this.on('destroy', function () { + utils.removeEvent(window, 'keydown', this); + }); + }, + + _key: function (e) { + if ( !this.enabled ) { + return; + } + + var snap = this.options.snap, // we are using this alot, better to cache it + newX = snap ? this.currentPage.pageX : this.x, + newY = snap ? this.currentPage.pageY : this.y, + now = utils.getTime(), + prevTime = this.keyTime || 0, + acceleration = 0.250, + pos; + + if ( this.options.useTransition && this.isInTransition ) { + pos = this.getComputedPosition(); + + this._translate(Math.round(pos.x), Math.round(pos.y)); + this.isInTransition = false; + } + + this.keyAcceleration = now - prevTime < 200 ? Math.min(this.keyAcceleration + acceleration, 50) : 0; + + switch ( e.keyCode ) { + case this.options.keyBindings.pageUp: + if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) { + newX += snap ? 1 : this.wrapperWidth; + } else { + newY += snap ? 1 : this.wrapperHeight; + } + break; + case this.options.keyBindings.pageDown: + if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) { + newX -= snap ? 1 : this.wrapperWidth; + } else { + newY -= snap ? 1 : this.wrapperHeight; + } + break; + case this.options.keyBindings.end: + newX = snap ? this.pages.length-1 : this.maxScrollX; + newY = snap ? this.pages[0].length-1 : this.maxScrollY; + break; + case this.options.keyBindings.home: + newX = 0; + newY = 0; + break; + case this.options.keyBindings.left: + newX += snap ? -1 : 5 + this.keyAcceleration>>0; + break; + case this.options.keyBindings.up: + newY += snap ? 1 : 5 + this.keyAcceleration>>0; + break; + case this.options.keyBindings.right: + newX -= snap ? -1 : 5 + this.keyAcceleration>>0; + break; + case this.options.keyBindings.down: + newY -= snap ? 1 : 5 + this.keyAcceleration>>0; + break; + default: + return; + } + + if ( snap ) { + this.goToPage(newX, newY); + return; + } + + if ( newX > 0 ) { + newX = 0; + this.keyAcceleration = 0; + } else if ( newX < this.maxScrollX ) { + newX = this.maxScrollX; + this.keyAcceleration = 0; + } + + if ( newY > 0 ) { + newY = 0; + this.keyAcceleration = 0; + } else if ( newY < this.maxScrollY ) { + newY = this.maxScrollY; + this.keyAcceleration = 0; + } + + this.scrollTo(newX, newY, 0); + + this.keyTime = now; + }, + + _animate: function (destX, destY, duration, easingFn) { + var that = this, + startX = this.x, + startY = this.y, + startTime = utils.getTime(), + destTime = startTime + duration; + + function step () { + var now = utils.getTime(), + newX, newY, + easing; + + if ( now >= destTime ) { + that.isAnimating = false; + that._translate(destX, destY); + + if ( !that.resetPosition(that.options.bounceTime) ) { + that._execEvent('scrollEnd'); + } + + return; + } + + now = ( now - startTime ) / duration; + easing = easingFn(now); + newX = ( destX - startX ) * easing + startX; + newY = ( destY - startY ) * easing + startY; + that._translate(newX, newY); + + if ( that.isAnimating ) { + rAF(step); + } + } + + this.isAnimating = true; + step(); + }, + handleEvent: function (e) { + switch ( e.type ) { + case 'touchstart': + case 'MSPointerDown': + case 'mousedown': + this._start(e); + break; + case 'touchmove': + case 'MSPointerMove': + case 'mousemove': + this._move(e); + break; + case 'touchend': + case 'MSPointerUp': + case 'mouseup': + case 'touchcancel': + case 'MSPointerCancel': + case 'mousecancel': + this._end(e); + break; + case 'orientationchange': + case 'resize': + this._resize(); + break; + case 'transitionend': + case 'webkitTransitionEnd': + case 'oTransitionEnd': + case 'MSTransitionEnd': + this._transitionEnd(e); + break; + case 'wheel': + case 'DOMMouseScroll': + case 'mousewheel': + this._wheel(e); + break; + case 'keydown': + this._key(e); + break; + case 'click': + if ( !e._constructed ) { + e.preventDefault(); + e.stopPropagation(); + } + break; + } + } +}; +function createDefaultScrollbar (direction, interactive, type) { + var scrollbar = document.createElement('div'), + indicator = document.createElement('div'); + + if ( type === true ) { + scrollbar.style.cssText = 'position:absolute;z-index:9999'; + indicator.style.cssText = '-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px'; + } + + indicator.className = 'iScrollIndicator'; + + if ( direction == 'h' ) { + if ( type === true ) { + scrollbar.style.cssText += ';height:7px;left:2px;right:2px;bottom:0'; + indicator.style.height = '100%'; + } + scrollbar.className = 'iScrollHorizontalScrollbar'; + } else { + if ( type === true ) { + scrollbar.style.cssText += ';width:7px;bottom:2px;top:2px;right:1px'; + indicator.style.width = '100%'; + } + scrollbar.className = 'iScrollVerticalScrollbar'; + } + + scrollbar.style.cssText += ';overflow:hidden'; + + if ( !interactive ) { + scrollbar.style.pointerEvents = 'none'; + } + + scrollbar.appendChild(indicator); + + return scrollbar; +} + +function Indicator (scroller, options) { + this.wrapper = typeof options.el == 'string' ? document.querySelector(options.el) : options.el; + this.wrapperStyle = this.wrapper.style; + this.indicator = this.wrapper.children[0]; + this.indicatorStyle = this.indicator.style; + this.scroller = scroller; + + this.options = { + listenX: true, + listenY: true, + interactive: false, + resize: true, + defaultScrollbars: false, + shrink: false, + fade: false, + speedRatioX: 0, + speedRatioY: 0 + }; + + for ( var i in options ) { + this.options[i] = options[i]; + } + + this.sizeRatioX = 1; + this.sizeRatioY = 1; + this.maxPosX = 0; + this.maxPosY = 0; + + if ( this.options.interactive ) { + if ( !this.options.disableTouch ) { + utils.addEvent(this.indicator, 'touchstart', this); + utils.addEvent(window, 'touchend', this); + } + if ( !this.options.disablePointer ) { + utils.addEvent(this.indicator, 'MSPointerDown', this); + utils.addEvent(window, 'MSPointerUp', this); + } + if ( !this.options.disableMouse ) { + utils.addEvent(this.indicator, 'mousedown', this); + utils.addEvent(window, 'mouseup', this); + } + } + + if ( this.options.fade ) { + this.wrapperStyle[utils.style.transform] = this.scroller.translateZ; + this.wrapperStyle[utils.style.transitionDuration] = utils.isBadAndroid ? '0.001s' : '0ms'; + this.wrapperStyle.opacity = '0'; + } +} + +Indicator.prototype = { + handleEvent: function (e) { + switch ( e.type ) { + case 'touchstart': + case 'MSPointerDown': + case 'mousedown': + this._start(e); + break; + case 'touchmove': + case 'MSPointerMove': + case 'mousemove': + this._move(e); + break; + case 'touchend': + case 'MSPointerUp': + case 'mouseup': + case 'touchcancel': + case 'MSPointerCancel': + case 'mousecancel': + this._end(e); + break; + } + }, + + destroy: function () { + if ( this.options.interactive ) { + utils.removeEvent(this.indicator, 'touchstart', this); + utils.removeEvent(this.indicator, 'MSPointerDown', this); + utils.removeEvent(this.indicator, 'mousedown', this); + + utils.removeEvent(window, 'touchmove', this); + utils.removeEvent(window, 'MSPointerMove', this); + utils.removeEvent(window, 'mousemove', this); + + utils.removeEvent(window, 'touchend', this); + utils.removeEvent(window, 'MSPointerUp', this); + utils.removeEvent(window, 'mouseup', this); + } + + if ( this.options.defaultScrollbars ) { + this.wrapper.parentNode.removeChild(this.wrapper); + } + }, + + _start: function (e) { + var point = e.touches ? e.touches[0] : e; + + e.preventDefault(); + e.stopPropagation(); + + this.transitionTime(); + + this.initiated = true; + this.moved = false; + this.lastPointX = point.pageX; + this.lastPointY = point.pageY; + + this.startTime = utils.getTime(); + + if ( !this.options.disableTouch ) { + utils.addEvent(window, 'touchmove', this); + } + if ( !this.options.disablePointer ) { + utils.addEvent(window, 'MSPointerMove', this); + } + if ( !this.options.disableMouse ) { + utils.addEvent(window, 'mousemove', this); + } + + this.scroller._execEvent('beforeScrollStart'); + }, + + _move: function (e) { + var point = e.touches ? e.touches[0] : e, + deltaX, deltaY, + newX, newY, + timestamp = utils.getTime(); + + if ( !this.moved ) { + this.scroller._execEvent('scrollStart'); + } + + this.moved = true; + + deltaX = point.pageX - this.lastPointX; + this.lastPointX = point.pageX; + + deltaY = point.pageY - this.lastPointY; + this.lastPointY = point.pageY; + + newX = this.x + deltaX; + newY = this.y + deltaY; + + this._pos(newX, newY); + +// INSERT POINT: indicator._move + + e.preventDefault(); + e.stopPropagation(); + }, + + _end: function (e) { + if ( !this.initiated ) { + return; + } + + this.initiated = false; + + e.preventDefault(); + e.stopPropagation(); + + utils.removeEvent(window, 'touchmove', this); + utils.removeEvent(window, 'MSPointerMove', this); + utils.removeEvent(window, 'mousemove', this); + + if ( this.scroller.options.snap ) { + var snap = this.scroller._nearestSnap(this.scroller.x, this.scroller.y); + + var time = this.options.snapSpeed || Math.max( + Math.max( + Math.min(Math.abs(this.scroller.x - snap.x), 1000), + Math.min(Math.abs(this.scroller.y - snap.y), 1000) + ), 300); + + if ( this.scroller.x != snap.x || this.scroller.y != snap.y ) { + this.scroller.directionX = 0; + this.scroller.directionY = 0; + this.scroller.currentPage = snap; + this.scroller.scrollTo(snap.x, snap.y, time, this.scroller.options.bounceEasing); + } + } + + if ( this.moved ) { + this.scroller._execEvent('scrollEnd'); + } + }, + + transitionTime: function (time) { + time = time || 0; + this.indicatorStyle[utils.style.transitionDuration] = time + 'ms'; + + if ( !time && utils.isBadAndroid ) { + this.indicatorStyle[utils.style.transitionDuration] = '0.001s'; + } + }, + + transitionTimingFunction: function (easing) { + this.indicatorStyle[utils.style.transitionTimingFunction] = easing; + }, + + refresh: function () { + this.transitionTime(); + + if ( this.options.listenX && !this.options.listenY ) { + this.indicatorStyle.display = this.scroller.hasHorizontalScroll ? 'block' : 'none'; + } else if ( this.options.listenY && !this.options.listenX ) { + this.indicatorStyle.display = this.scroller.hasVerticalScroll ? 'block' : 'none'; + } else { + this.indicatorStyle.display = this.scroller.hasHorizontalScroll || this.scroller.hasVerticalScroll ? 'block' : 'none'; + } + + if ( this.scroller.hasHorizontalScroll && this.scroller.hasVerticalScroll ) { + utils.addClass(this.wrapper, 'iScrollBothScrollbars'); + utils.removeClass(this.wrapper, 'iScrollLoneScrollbar'); + + if ( this.options.defaultScrollbars && this.options.customStyle ) { + if ( this.options.listenX ) { + this.wrapper.style.right = '8px'; + } else { + this.wrapper.style.bottom = '8px'; + } + } + } else { + utils.removeClass(this.wrapper, 'iScrollBothScrollbars'); + utils.addClass(this.wrapper, 'iScrollLoneScrollbar'); + + if ( this.options.defaultScrollbars && this.options.customStyle ) { + if ( this.options.listenX ) { + this.wrapper.style.right = '2px'; + } else { + this.wrapper.style.bottom = '2px'; + } + } + } + + var r = this.wrapper.offsetHeight; // force refresh + + if ( this.options.listenX ) { + this.wrapperWidth = this.wrapper.clientWidth; + if ( this.options.resize ) { + this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8); + this.indicatorStyle.width = this.indicatorWidth + 'px'; + } else { + this.indicatorWidth = this.indicator.clientWidth; + } + + this.maxPosX = this.wrapperWidth - this.indicatorWidth; + + if ( this.options.shrink == 'clip' ) { + this.minBoundaryX = -this.indicatorWidth + 8; + this.maxBoundaryX = this.wrapperWidth - 8; + } else { + this.minBoundaryX = 0; + this.maxBoundaryX = this.maxPosX; + } + + this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX)); + } + + if ( this.options.listenY ) { + this.wrapperHeight = this.wrapper.clientHeight; + if ( this.options.resize ) { + this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8); + this.indicatorStyle.height = this.indicatorHeight + 'px'; + } else { + this.indicatorHeight = this.indicator.clientHeight; + } + + this.maxPosY = this.wrapperHeight - this.indicatorHeight; + + if ( this.options.shrink == 'clip' ) { + this.minBoundaryY = -this.indicatorHeight + 8; + this.maxBoundaryY = this.wrapperHeight - 8; + } else { + this.minBoundaryY = 0; + this.maxBoundaryY = this.maxPosY; + } + + this.maxPosY = this.wrapperHeight - this.indicatorHeight; + this.sizeRatioY = this.options.speedRatioY || (this.scroller.maxScrollY && (this.maxPosY / this.scroller.maxScrollY)); + } + + this.updatePosition(); + }, + + updatePosition: function () { + var x = this.options.listenX && Math.round(this.sizeRatioX * this.scroller.x) || 0, + y = this.options.listenY && Math.round(this.sizeRatioY * this.scroller.y) || 0; + + if ( !this.options.ignoreBoundaries ) { + if ( x < this.minBoundaryX ) { + if ( this.options.shrink == 'scale' ) { + this.width = Math.max(this.indicatorWidth + x, 8); + this.indicatorStyle.width = this.width + 'px'; + } + x = this.minBoundaryX; + } else if ( x > this.maxBoundaryX ) { + if ( this.options.shrink == 'scale' ) { + this.width = Math.max(this.indicatorWidth - (x - this.maxPosX), 8); + this.indicatorStyle.width = this.width + 'px'; + x = this.maxPosX + this.indicatorWidth - this.width; + } else { + x = this.maxBoundaryX; + } + } else if ( this.options.shrink == 'scale' && this.width != this.indicatorWidth ) { + this.width = this.indicatorWidth; + this.indicatorStyle.width = this.width + 'px'; + } + + if ( y < this.minBoundaryY ) { + if ( this.options.shrink == 'scale' ) { + this.height = Math.max(this.indicatorHeight + y * 3, 8); + this.indicatorStyle.height = this.height + 'px'; + } + y = this.minBoundaryY; + } else if ( y > this.maxBoundaryY ) { + if ( this.options.shrink == 'scale' ) { + this.height = Math.max(this.indicatorHeight - (y - this.maxPosY) * 3, 8); + this.indicatorStyle.height = this.height + 'px'; + y = this.maxPosY + this.indicatorHeight - this.height; + } else { + y = this.maxBoundaryY; + } + } else if ( this.options.shrink == 'scale' && this.height != this.indicatorHeight ) { + this.height = this.indicatorHeight; + this.indicatorStyle.height = this.height + 'px'; + } + } + + this.x = x; + this.y = y; + + if ( this.scroller.options.useTransform ) { + this.indicatorStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.scroller.translateZ; + } else { + this.indicatorStyle.left = x + 'px'; + this.indicatorStyle.top = y + 'px'; + } + }, + + _pos: function (x, y) { + if ( x < 0 ) { + x = 0; + } else if ( x > this.maxPosX ) { + x = this.maxPosX; + } + + if ( y < 0 ) { + y = 0; + } else if ( y > this.maxPosY ) { + y = this.maxPosY; + } + + x = this.options.listenX ? Math.round(x / this.sizeRatioX) : this.scroller.x; + y = this.options.listenY ? Math.round(y / this.sizeRatioY) : this.scroller.y; + + this.scroller.scrollTo(x, y); + }, + + fade: function (val, hold) { + if ( hold && !this.visible ) { + return; + } + + clearTimeout(this.fadeTimeout); + this.fadeTimeout = null; + + var time = val ? 250 : 500, + delay = val ? 0 : 300; + + val = val ? '1' : '0'; + + this.wrapperStyle[utils.style.transitionDuration] = time + 'ms'; + + this.fadeTimeout = setTimeout((function (val) { + this.wrapperStyle.opacity = val; + this.visible = +val; + }).bind(this, val), delay); + } +}; + +IScroll.utils = utils; + +if ( typeof module != 'undefined' && module.exports ) { + module.exports = IScroll; +} else { + window.IScroll = IScroll; +} + +})(window, document, Math); \ No newline at end of file diff --git a/assets/html/jquery-2.1.0.min.js b/assets/html/jquery-2.1.0.min.js new file mode 100644 index 0000000..cbe6abe --- /dev/null +++ b/assets/html/jquery-2.1.0.min.js @@ -0,0 +1,4 @@ +/*! jQuery v2.1.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ +!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k="".trim,l={},m=a.document,n="2.1.0",o=function(a,b){return new o.fn.init(a,b)},p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};o.fn=o.prototype={jquery:n,constructor:o,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=o.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return o.each(this,a,b)},map:function(a){return this.pushStack(o.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},o.extend=o.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||o.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(o.isPlainObject(d)||(e=o.isArray(d)))?(e?(e=!1,f=c&&o.isArray(c)?c:[]):f=c&&o.isPlainObject(c)?c:{},g[b]=o.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},o.extend({expando:"jQuery"+(n+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===o.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return a-parseFloat(a)>=0},isPlainObject:function(a){if("object"!==o.type(a)||a.nodeType||o.isWindow(a))return!1;try{if(a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(b){return!1}return!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=o.trim(a),a&&(1===a.indexOf("use strict")?(b=m.createElement("script"),b.text=a,m.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":k.call(a)},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?o.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),o.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||o.guid++,f):void 0},now:Date.now,support:l}),o.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=o.type(a);return"function"===c||o.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s="sizzle"+-new Date,t=a.document,u=0,v=0,w=eb(),x=eb(),y=eb(),z=function(a,b){return a===b&&(j=!0),0},A="undefined",B=1<<31,C={}.hasOwnProperty,D=[],E=D.pop,F=D.push,G=D.push,H=D.slice,I=D.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},J="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",K="[\\x20\\t\\r\\n\\f]",L="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",M=L.replace("w","w#"),N="\\["+K+"*("+L+")"+K+"*(?:([*^$|!~]?=)"+K+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+M+")|)|)"+K+"*\\]",O=":("+L+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+N.replace(3,8)+")*)|.*)\\)|)",P=new RegExp("^"+K+"+|((?:^|[^\\\\])(?:\\\\.)*)"+K+"+$","g"),Q=new RegExp("^"+K+"*,"+K+"*"),R=new RegExp("^"+K+"*([>+~]|"+K+")"+K+"*"),S=new RegExp("="+K+"*([^\\]'\"]*?)"+K+"*\\]","g"),T=new RegExp(O),U=new RegExp("^"+M+"$"),V={ID:new RegExp("^#("+L+")"),CLASS:new RegExp("^\\.("+L+")"),TAG:new RegExp("^("+L.replace("w","w*")+")"),ATTR:new RegExp("^"+N),PSEUDO:new RegExp("^"+O),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+K+"*(even|odd|(([+-]|)(\\d*)n|)"+K+"*(?:([+-]|)"+K+"*(\\d+)|))"+K+"*\\)|)","i"),bool:new RegExp("^(?:"+J+")$","i"),needsContext:new RegExp("^"+K+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+K+"*((?:-\\d)?\\d*)"+K+"*\\)|)(?=[^-]|$)","i")},W=/^(?:input|select|textarea|button)$/i,X=/^h\d$/i,Y=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,$=/[+~]/,_=/'|\\/g,ab=new RegExp("\\\\([\\da-f]{1,6}"+K+"?|("+K+")|.)","ig"),bb=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{G.apply(D=H.call(t.childNodes),t.childNodes),D[t.childNodes.length].nodeType}catch(cb){G={apply:D.length?function(a,b){F.apply(a,H.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function db(a,b,d,e){var f,g,h,i,j,m,p,q,u,v;if((b?b.ownerDocument||b:t)!==l&&k(b),b=b||l,d=d||[],!a||"string"!=typeof a)return d;if(1!==(i=b.nodeType)&&9!==i)return[];if(n&&!e){if(f=Z.exec(a))if(h=f[1]){if(9===i){if(g=b.getElementById(h),!g||!g.parentNode)return d;if(g.id===h)return d.push(g),d}else if(b.ownerDocument&&(g=b.ownerDocument.getElementById(h))&&r(b,g)&&g.id===h)return d.push(g),d}else{if(f[2])return G.apply(d,b.getElementsByTagName(a)),d;if((h=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return G.apply(d,b.getElementsByClassName(h)),d}if(c.qsa&&(!o||!o.test(a))){if(q=p=s,u=b,v=9===i&&a,1===i&&"object"!==b.nodeName.toLowerCase()){m=ob(a),(p=b.getAttribute("id"))?q=p.replace(_,"\\$&"):b.setAttribute("id",q),q="[id='"+q+"'] ",j=m.length;while(j--)m[j]=q+pb(m[j]);u=$.test(a)&&mb(b.parentNode)||b,v=m.join(",")}if(v)try{return G.apply(d,u.querySelectorAll(v)),d}catch(w){}finally{p||b.removeAttribute("id")}}}return xb(a.replace(P,"$1"),b,d,e)}function eb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function fb(a){return a[s]=!0,a}function gb(a){var b=l.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function hb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function ib(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||B)-(~a.sourceIndex||B);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function jb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function kb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function lb(a){return fb(function(b){return b=+b,fb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function mb(a){return a&&typeof a.getElementsByTagName!==A&&a}c=db.support={},f=db.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},k=db.setDocument=function(a){var b,e=a?a.ownerDocument||a:t,g=e.defaultView;return e!==l&&9===e.nodeType&&e.documentElement?(l=e,m=e.documentElement,n=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){k()},!1):g.attachEvent&&g.attachEvent("onunload",function(){k()})),c.attributes=gb(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=gb(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=Y.test(e.getElementsByClassName)&&gb(function(a){return a.innerHTML="
",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=gb(function(a){return m.appendChild(a).id=s,!e.getElementsByName||!e.getElementsByName(s).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==A&&n){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(ab,bb);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(ab,bb);return function(a){var c=typeof a.getAttributeNode!==A&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==A?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==A&&n?b.getElementsByClassName(a):void 0},p=[],o=[],(c.qsa=Y.test(e.querySelectorAll))&&(gb(function(a){a.innerHTML="",a.querySelectorAll("[t^='']").length&&o.push("[*^$]="+K+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||o.push("\\["+K+"*(?:value|"+J+")"),a.querySelectorAll(":checked").length||o.push(":checked")}),gb(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&o.push("name"+K+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||o.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),o.push(",.*:")})),(c.matchesSelector=Y.test(q=m.webkitMatchesSelector||m.mozMatchesSelector||m.oMatchesSelector||m.msMatchesSelector))&&gb(function(a){c.disconnectedMatch=q.call(a,"div"),q.call(a,"[s!='']:x"),p.push("!=",O)}),o=o.length&&new RegExp(o.join("|")),p=p.length&&new RegExp(p.join("|")),b=Y.test(m.compareDocumentPosition),r=b||Y.test(m.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},z=b?function(a,b){if(a===b)return j=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===t&&r(t,a)?-1:b===e||b.ownerDocument===t&&r(t,b)?1:i?I.call(i,a)-I.call(i,b):0:4&d?-1:1)}:function(a,b){if(a===b)return j=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],k=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:i?I.call(i,a)-I.call(i,b):0;if(f===g)return ib(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)k.unshift(c);while(h[d]===k[d])d++;return d?ib(h[d],k[d]):h[d]===t?-1:k[d]===t?1:0},e):l},db.matches=function(a,b){return db(a,null,null,b)},db.matchesSelector=function(a,b){if((a.ownerDocument||a)!==l&&k(a),b=b.replace(S,"='$1']"),!(!c.matchesSelector||!n||p&&p.test(b)||o&&o.test(b)))try{var d=q.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return db(b,l,null,[a]).length>0},db.contains=function(a,b){return(a.ownerDocument||a)!==l&&k(a),r(a,b)},db.attr=function(a,b){(a.ownerDocument||a)!==l&&k(a);var e=d.attrHandle[b.toLowerCase()],f=e&&C.call(d.attrHandle,b.toLowerCase())?e(a,b,!n):void 0;return void 0!==f?f:c.attributes||!n?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},db.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},db.uniqueSort=function(a){var b,d=[],e=0,f=0;if(j=!c.detectDuplicates,i=!c.sortStable&&a.slice(0),a.sort(z),j){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return i=null,a},e=db.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=db.selectors={cacheLength:50,createPseudo:fb,match:V,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(ab,bb),a[3]=(a[4]||a[5]||"").replace(ab,bb),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||db.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&db.error(a[0]),a},PSEUDO:function(a){var b,c=!a[5]&&a[2];return V.CHILD.test(a[0])?null:(a[3]&&void 0!==a[4]?a[2]=a[4]:c&&T.test(c)&&(b=ob(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(ab,bb).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=w[a+" "];return b||(b=new RegExp("(^|"+K+")"+a+"("+K+"|$)"))&&w(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==A&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=db.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),t=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&t){k=q[s]||(q[s]={}),j=k[a]||[],n=j[0]===u&&j[1],m=j[0]===u&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[u,n,m];break}}else if(t&&(j=(b[s]||(b[s]={}))[a])&&j[0]===u)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(t&&((l[s]||(l[s]={}))[a]=[u,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||db.error("unsupported pseudo: "+a);return e[s]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?fb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=I.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:fb(function(a){var b=[],c=[],d=g(a.replace(P,"$1"));return d[s]?fb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:fb(function(a){return function(b){return db(a,b).length>0}}),contains:fb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:fb(function(a){return U.test(a||"")||db.error("unsupported lang: "+a),a=a.replace(ab,bb).toLowerCase(),function(b){var c;do if(c=n?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===m},focus:function(a){return a===l.activeElement&&(!l.hasFocus||l.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return X.test(a.nodeName)},input:function(a){return W.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:lb(function(){return[0]}),last:lb(function(a,b){return[b-1]}),eq:lb(function(a,b,c){return[0>c?c+b:c]}),even:lb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:lb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:lb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:lb(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function qb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=v++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[u,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[s]||(b[s]={}),(h=i[d])&&h[0]===u&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function rb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function sb(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function tb(a,b,c,d,e,f){return d&&!d[s]&&(d=tb(d)),e&&!e[s]&&(e=tb(e,f)),fb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||wb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:sb(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=sb(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?I.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=sb(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):G.apply(g,r)})}function ub(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],i=g||d.relative[" "],j=g?1:0,k=qb(function(a){return a===b},i,!0),l=qb(function(a){return I.call(b,a)>-1},i,!0),m=[function(a,c,d){return!g&&(d||c!==h)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>j;j++)if(c=d.relative[a[j].type])m=[qb(rb(m),c)];else{if(c=d.filter[a[j].type].apply(null,a[j].matches),c[s]){for(e=++j;f>e;e++)if(d.relative[a[e].type])break;return tb(j>1&&rb(m),j>1&&pb(a.slice(0,j-1).concat({value:" "===a[j-2].type?"*":""})).replace(P,"$1"),c,e>j&&ub(a.slice(j,e)),f>e&&ub(a=a.slice(e)),f>e&&pb(a))}m.push(c)}return rb(m)}function vb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,i,j,k){var m,n,o,p=0,q="0",r=f&&[],s=[],t=h,v=f||e&&d.find.TAG("*",k),w=u+=null==t?1:Math.random()||.1,x=v.length;for(k&&(h=g!==l&&g);q!==x&&null!=(m=v[q]);q++){if(e&&m){n=0;while(o=a[n++])if(o(m,g,i)){j.push(m);break}k&&(u=w)}c&&((m=!o&&m)&&p--,f&&r.push(m))}if(p+=q,c&&q!==p){n=0;while(o=b[n++])o(r,s,g,i);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=E.call(j));s=sb(s)}G.apply(j,s),k&&!f&&s.length>0&&p+b.length>1&&db.uniqueSort(j)}return k&&(u=w,h=t),r};return c?fb(f):f}g=db.compile=function(a,b){var c,d=[],e=[],f=y[a+" "];if(!f){b||(b=ob(a)),c=b.length;while(c--)f=ub(b[c]),f[s]?d.push(f):e.push(f);f=y(a,vb(e,d))}return f};function wb(a,b,c){for(var d=0,e=b.length;e>d;d++)db(a,b[d],c);return c}function xb(a,b,e,f){var h,i,j,k,l,m=ob(a);if(!f&&1===m.length){if(i=m[0]=m[0].slice(0),i.length>2&&"ID"===(j=i[0]).type&&c.getById&&9===b.nodeType&&n&&d.relative[i[1].type]){if(b=(d.find.ID(j.matches[0].replace(ab,bb),b)||[])[0],!b)return e;a=a.slice(i.shift().value.length)}h=V.needsContext.test(a)?0:i.length;while(h--){if(j=i[h],d.relative[k=j.type])break;if((l=d.find[k])&&(f=l(j.matches[0].replace(ab,bb),$.test(i[0].type)&&mb(b.parentNode)||b))){if(i.splice(h,1),a=f.length&&pb(i),!a)return G.apply(e,f),e;break}}}return g(a,m)(f,b,!n,e,$.test(a)&&mb(b.parentNode)||b),e}return c.sortStable=s.split("").sort(z).join("")===s,c.detectDuplicates=!!j,k(),c.sortDetached=gb(function(a){return 1&a.compareDocumentPosition(l.createElement("div"))}),gb(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||hb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&gb(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||hb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),gb(function(a){return null==a.getAttribute("disabled")})||hb(J,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),db}(a);o.find=t,o.expr=t.selectors,o.expr[":"]=o.expr.pseudos,o.unique=t.uniqueSort,o.text=t.getText,o.isXMLDoc=t.isXML,o.contains=t.contains;var u=o.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(o.isFunction(b))return o.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return o.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return o.filter(b,a,c);b=o.filter(b,a)}return o.grep(a,function(a){return g.call(b,a)>=0!==c})}o.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?o.find.matchesSelector(d,a)?[d]:[]:o.find.matches(a,o.grep(b,function(a){return 1===a.nodeType}))},o.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(o(a).filter(function(){for(b=0;c>b;b++)if(o.contains(e[b],this))return!0}));for(b=0;c>b;b++)o.find(a,e[b],d);return d=this.pushStack(c>1?o.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?o(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=o.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof o?b[0]:b,o.merge(this,o.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:m,!0)),v.test(c[1])&&o.isPlainObject(b))for(c in b)o.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=m.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=m,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):o.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(o):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),o.makeArray(a,this))};A.prototype=o.fn,y=o(m);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};o.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&o(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),o.fn.extend({has:function(a){var b=o(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(o.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?o(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&o.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?o.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(o(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(o.unique(o.merge(this.get(),o(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}o.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return o.dir(a,"parentNode")},parentsUntil:function(a,b,c){return o.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return o.dir(a,"nextSibling")},prevAll:function(a){return o.dir(a,"previousSibling")},nextUntil:function(a,b,c){return o.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return o.dir(a,"previousSibling",c)},siblings:function(a){return o.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return o.sibling(a.firstChild)},contents:function(a){return a.contentDocument||o.merge([],a.childNodes)}},function(a,b){o.fn[a]=function(c,d){var e=o.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=o.filter(d,e)),this.length>1&&(C[a]||o.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return o.each(a.match(E)||[],function(a,c){b[c]=!0}),b}o.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):o.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){o.each(b,function(b,c){var d=o.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&o.each(arguments,function(a,b){var c;while((c=o.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?o.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},o.extend({Deferred:function(a){var b=[["resolve","done",o.Callbacks("once memory"),"resolved"],["reject","fail",o.Callbacks("once memory"),"rejected"],["notify","progress",o.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return o.Deferred(function(c){o.each(b,function(b,f){var g=o.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&o.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?o.extend(a,d):d}},e={};return d.pipe=d.then,o.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&o.isFunction(a.promise)?e:0,g=1===f?a:o.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&o.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;o.fn.ready=function(a){return o.ready.promise().done(a),this},o.extend({isReady:!1,readyWait:1,holdReady:function(a){a?o.readyWait++:o.ready(!0)},ready:function(a){(a===!0?--o.readyWait:o.isReady)||(o.isReady=!0,a!==!0&&--o.readyWait>0||(H.resolveWith(m,[o]),o.fn.trigger&&o(m).trigger("ready").off("ready")))}});function I(){m.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),o.ready()}o.ready.promise=function(b){return H||(H=o.Deferred(),"complete"===m.readyState?setTimeout(o.ready):(m.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},o.ready.promise();var J=o.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===o.type(c)){e=!0;for(h in c)o.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,o.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(o(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};o.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=o.expando+Math.random()}K.uid=1,K.accepts=o.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,o.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(o.isEmptyObject(f))o.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,o.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{o.isArray(b)?d=b.concat(b.map(o.camelCase)):(e=o.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!o.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?o.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}o.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b)},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),o.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length; +while(c--)d=g[c].name,0===d.indexOf("data-")&&(d=o.camelCase(d.slice(5)),P(f,d,e[d]));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=o.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),o.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||o.isArray(c)?d=L.access(a,b,o.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=o.queue(a,b),d=c.length,e=c.shift(),f=o._queueHooks(a,b),g=function(){o.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:o.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),o.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length",l.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="",l.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";l.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return m.activeElement}catch(a){}}o.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=o.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof o!==U&&o.event.triggered!==b.type?o.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],n=q=h[1],p=(h[2]||"").split(".").sort(),n&&(l=o.event.special[n]||{},n=(e?l.delegateType:l.bindType)||n,l=o.event.special[n]||{},k=o.extend({type:n,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&o.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[n])||(m=i[n]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(n,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),o.event.global[n]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],n=q=h[1],p=(h[2]||"").split(".").sort(),n){l=o.event.special[n]||{},n=(d?l.delegateType:l.bindType)||n,m=i[n]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||o.removeEvent(a,n,r.handle),delete i[n])}else for(n in i)o.event.remove(a,n+b[j],c,d,!0);o.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,l,n,p=[d||m],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||m,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+o.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[o.expando]?b:new o.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:o.makeArray(c,[b]),n=o.event.special[q]||{},e||!n.trigger||n.trigger.apply(d,c)!==!1)){if(!e&&!n.noBubble&&!o.isWindow(d)){for(i=n.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||m)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:n.bindType||q,l=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),l&&l.apply(g,c),l=k&&g[k],l&&l.apply&&o.acceptData(g)&&(b.result=l.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||n._default&&n._default.apply(p.pop(),c)!==!1||!o.acceptData(d)||k&&o.isFunction(d[q])&&!o.isWindow(d)&&(h=d[k],h&&(d[k]=null),o.event.triggered=q,d[q](),o.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=o.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=o.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=o.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((o.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?o(e,this).index(i)>=0:o.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*\s*$/g,ib={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return o.nodeName(a,"table")&&o.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)o.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=o.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&o.nodeName(a,b)?o.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}o.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=o.contains(a.ownerDocument,a);if(!(l.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||o.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,n=a.length;n>m;m++)if(e=a[m],e||0===e)if("object"===o.type(e))o.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1>")+h[2],j=h[0];while(j--)f=f.lastChild;o.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===o.inArray(e,d))&&(i=o.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f,g,h=o.event.special,i=0;void 0!==(c=a[i]);i++){if(o.acceptData(c)&&(f=c[L.expando],f&&(b=L.cache[f]))){if(d=Object.keys(b.events||{}),d.length)for(g=0;void 0!==(e=d[g]);g++)h[e]?o.event.remove(c,e):o.removeEvent(c,e,b.handle);L.cache[f]&&delete L.cache[f]}delete M.cache[c[M.expando]]}}}),o.fn.extend({text:function(a){return J(this,function(a){return void 0===a?o.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?o.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||o.cleanData(ob(c)),c.parentNode&&(b&&o.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(o.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return o.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(o.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,o.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,k=this.length,m=this,n=k-1,p=a[0],q=o.isFunction(p);if(q||k>1&&"string"==typeof p&&!l.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(k&&(c=o.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=o.map(ob(c,"script"),kb),g=f.length;k>j;j++)h=c,j!==n&&(h=o.clone(h,!0,!0),g&&o.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,o.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&o.contains(i,h)&&(h.src?o._evalUrl&&o._evalUrl(h.src):o.globalEval(h.textContent.replace(hb,"")))}return this}}),o.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){o.fn[a]=function(a){for(var c,d=[],e=o(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),o(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d=o(c.createElement(b)).appendTo(c.body),e=a.getDefaultComputedStyle?a.getDefaultComputedStyle(d[0]).display:o.css(d[0],"display");return d.detach(),e}function tb(a){var b=m,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||o("