(function (window, factory){ if (typeof define === 'function' && define.amd) { define(['jquery'] , function (){ return factory.apply(window, arguments); } ); } else if (typeof module === 'object' && module.exports) { module.exports = factory.call(window, require('jquery')); } else { factory.call(window, window.jQuery); } } (typeof global === 'object'? global: this, function (jQuery){ var originalAnimateMethod = jQuery.fn.animate, originalStopMethod = jQuery.fn.stop; var cssTransitionProperties = ['top', 'right', 'bottom', 'left', 'opacity', 'height', 'width'] , directions = ['top', 'right', 'bottom', 'left'] , cssPrefixes = ['-webkit-', '-moz-', '-o-', ''] , pluginOptions = ['avoidTransforms', 'useTranslate3d', 'leaveTransforms'] , rfxnum = /^([+-]=)?([\d+-.]+)(.*)$/, rupper = /([A-Z])/g, defaultEnhanceData = { secondary: { } , meta: { top: 0, right: 0, bottom: 0, left: 0} } , valUnit = 'px', DATA_KEY = 'jQe', CUBIC_BEZIER_OPEN = 'cubic-bezier(', CUBIC_BEZIER_CLOSE = ')', originalAnimatedFilter = null , pluginDisabledDefault = false ; var thisBody = document.body || document.documentElement, thisStyle = thisBody.style, transitionEndEvent = 'webkitTransitionEnd oTransitionEnd transitionend', cssTransitionsSupported = thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.OTransition !== undefined || thisStyle.transition !== undefined, has3D = ('WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix()), use3DByDefault = has3D; if (jQuery.expr && jQuery.expr.filters) { originalAnimatedFilter = jQuery.expr.filters.animated; jQuery.expr.filters.animated = function (elem){ return jQuery(elem).data('events') && jQuery(elem).data('events')[transitionEndEvent]? true : originalAnimatedFilter.call(this, elem); } ; } function _getUnit(val){ return val.match(/\D+$/); } function _interpretValue(e, val, prop, isTransform){ if (prop == "d") return ; if (!_isValidElement(e)) return ; var parts = rfxnum.exec(val), start = e.css(prop) === 'auto'? 0: e.css(prop), cleanCSSStart = typeof start == 'string'? _cleanValue(start): start, cleanTarget = typeof val == 'string'? _cleanValue(val): val, cleanStart = isTransform === true ? 0: cleanCSSStart, hidden = e.is(':hidden'), translation = e.translation(); if (prop == 'left') cleanStart = parseInt(cleanCSSStart, 10) + translation.x; if (prop == 'right') cleanStart = parseInt(cleanCSSStart, 10) + translation.x; if (prop == 'top') cleanStart = parseInt(cleanCSSStart, 10) + translation.y; if (prop == 'bottom') cleanStart = parseInt(cleanCSSStart, 10) + translation.y; if (!parts && val == 'show') { cleanStart = 1; if (hidden) { elem = e[0]; if (elem.style) { display = elem.style.display; if (!jQuery._data(elem, 'olddisplay') && display === 'none') { display = elem.style.display = ''; } if (display === '' && jQuery.css(elem, 'display') === 'none') { jQuery._data(elem, 'olddisplay', _domElementVisibleDisplayValue(elem.tagName)); } if (display === '' || display === 'none') { elem.style.display = jQuery._data(elem, 'olddisplay') || ''; } } e.css('opacity', 0); } } else if (!parts && val == 'hide') { cleanStart = 0; } if (parts) { var end = parseFloat(parts[2]); if (parts[1]) end = ((parts[1] === '-='? -1: 1) * end) + parseInt(cleanStart, 10); if (parts[3] && parts[3] != 'px') end = end + parts[3]; return end; } else { return cleanStart; } } function _getTranslation(x, y, use3D){ return ((use3D === true || ((use3DByDefault === true && use3D !== false )) && has3D))? 'translate3d(' + x + 'px, ' + y + 'px, 0)': 'translate(' + x + 'px,' + y + 'px)'; } function _applyCSSTransition(e, property, duration, easing, value, isTransform, isTranslatable, use3D){ var eCSSData = e.data(DATA_KEY), enhanceData = eCSSData && !_isEmptyObject(eCSSData)? eCSSData: jQuery.extend(true , { } , defaultEnhanceData), offsetPosition = value, isDirection = jQuery.inArray(property, directions) > -1; if (isDirection) { var meta = enhanceData.meta, cleanPropertyValue = _cleanValue(e.css(property)) || 0, stashedProperty = property + '_o'; offsetPosition = value - cleanPropertyValue; meta[property] = offsetPosition; meta[stashedProperty] = e.css(property) == 'auto'? 0 + offsetPosition: cleanPropertyValue + offsetPosition || 0; enhanceData.meta = meta; if (isTranslatable && offsetPosition === 0) { offsetPosition = 0 - meta[stashedProperty]; meta[property] = offsetPosition; meta[stashedProperty] = 0; } } return e.data(DATA_KEY, _applyCSSWithPrefix(e, enhanceData, property, duration, easing, offsetPosition, isTransform, isTranslatable, use3D)); } function _applyCSSWithPrefix(e, cssProperties, property, duration, easing, value, isTransform, isTranslatable, use3D){ var saveOriginal = false , transform = isTransform === true && isTranslatable === true ; cssProperties = cssProperties || { } ; if (!cssProperties.original) { cssProperties.original = { } ; saveOriginal = true ; } cssProperties.properties = cssProperties.properties || { } ; cssProperties.secondary = cssProperties.secondary || { } ; var meta = cssProperties.meta, original = cssProperties.original, properties = cssProperties.properties, secondary = cssProperties.secondary; for (var i = _AN_Read_length('length', cssPrefixes) - 1; i >= 0; i-- ){ var tp = cssPrefixes[i] + 'transition-property', td = cssPrefixes[i] + 'transition-duration', tf = cssPrefixes[i] + 'transition-timing-function'; property = (transform? cssPrefixes[i] + 'transform': property); if (saveOriginal) { original[tp] = e.css(tp) || ''; original[td] = e.css(td) || ''; original[tf] = e.css(tf) || ''; } secondary[property] = transform? _getTranslation(meta.left, meta.top, use3D): value; properties[tp] = (properties[tp]? properties[tp] + ',': '') + property; properties[td] = (properties[td]? properties[td] + ',': '') + duration + 'ms'; properties[tf] = (properties[tf]? properties[tf] + ',': '') + easing; } return cssProperties; } function _isBoxShortcut(prop){ for (var property in prop){ if ((property == 'width' || property == 'height') && (prop[property] == 'show' || prop[property] == 'hide' || prop[property] == 'toggle')) { return true ; } } return false ; } function _isEmptyObject(obj){ for (var i in obj){ return false ; } return true ; } function _domElementVisibleDisplayValue(tagName){ tagName = tagName.toUpperCase(); var displayValues = { 'LI': 'list-item', 'TR': 'table-row', 'TD': 'table-cell', 'TH': 'table-cell', 'CAPTION': 'table-caption', 'COL': 'table-column', 'COLGROUP': 'table-column-group', 'TFOOT': 'table-footer-group', 'THEAD': 'table-header-group', 'TBODY': 'table-row-group'} ; return typeof displayValues[tagName] == 'string'? displayValues[tagName]: 'block'; } function _cleanValue(val){ return parseFloat(_AN_Call_replace('replace', val, _getUnit(val), '')); } function _isValidElement(element){ var allValid = true ; element.each(function (index, el){ allValid = allValid && el.ownerDocument; return allValid; } ); return allValid; } function _appropriateProperty(prop, value, element){ if (!_isValidElement(element)) { return false ; } var is = jQuery.inArray(prop, cssTransitionProperties) > -1; if ((prop == 'width' || prop == 'height' || prop == 'opacity' || prop == 'left' || prop == 'top') && (parseFloat(value) === parseFloat(element.css(prop)))) is = false ; return is; } jQuery.extend({ toggle3DByDefault: function (){ return use3DByDefault = !use3DByDefault; } , toggleDisabledByDefault: function (){ return pluginDisabledDefault = !pluginDisabledDefault; } , setDisabledByDefault: function (newValue){ return pluginDisabledDefault = newValue; } } ); jQuery.fn.translation = function (){ if (!this[0]) { return null ; } var elem = this[0], cStyle = window.getComputedStyle(elem, null ), translation = { x: 0, y: 0} ; if (cStyle) { for (var i = _AN_Read_length('length', cssPrefixes) - 1; i >= 0; i-- ){ var transform = cStyle.getPropertyValue(cssPrefixes[i] + 'transform'); if (transform && (/matrix/i).test(transform)) { var explodedMatrix = _AN_Call_replace('replace', transform, /^matrix\(/i, '').split(/, |\)$/g); translation = { x: parseInt(explodedMatrix[4], 10), y: parseInt(explodedMatrix[5], 10)} ; break ; } } } return translation; } ; jQuery.fn.animate = function (prop, speed, easing, callback){ prop = prop || { } ; var isTranslatable = !(typeof prop.bottom !== 'undefined' || typeof prop.right !== 'undefined'), optall = jQuery.speed(speed, easing, callback), callbackQueue = 0, propertyCallback = function (){ callbackQueue-- ; if (callbackQueue === 0) { if (typeof optall.complete === 'function') { optall.complete.apply(this, arguments); } } } , bypassPlugin = (typeof prop.avoidCSSTransitions !== 'undefined')? prop.avoidCSSTransitions: pluginDisabledDefault; if (bypassPlugin === true || !cssTransitionsSupported || _isEmptyObject(prop) || _isBoxShortcut(prop) || optall.duration <= 0 || optall.step) { return originalAnimateMethod.apply(this, arguments); } return this[optall.queue === true ? 'queue': 'each'](function (){ var self = jQuery(this), opt = jQuery.extend({ } , optall), cssCallback = function (e){ var selfCSSData = self.data(DATA_KEY) || { original: { } } , restore = { } ; if (e.eventPhase != 2) return ; if (prop.leaveTransforms !== true ) { for (var i = _AN_Read_length('length', cssPrefixes) - 1; i >= 0; i-- ){ restore[cssPrefixes[i] + 'transform'] = ''; } if (isTranslatable && typeof selfCSSData.meta !== 'undefined') { for (var j = 0, dir; (dir = directions[j]); ++j){ var stashedProperty = selfCSSData.meta[dir + '_o']; if (typeof stashedProperty !== 'undefined') { restore[dir] = stashedProperty + valUnit; jQuery(this).css(dir, restore[dir]); } } } } self.unbind(transitionEndEvent).css(selfCSSData.original).css(restore).data(DATA_KEY, null ); if (prop.opacity === 'hide') { elem = self[0]; if (elem.style) { display = jQuery.css(elem, 'display'); if (display !== 'none' && !jQuery._data(elem, 'olddisplay')) { jQuery._data(elem, 'olddisplay', display); } elem.style.display = 'none'; } self.css('opacity', ''); } propertyCallback.call(this); } , easings = { bounce: CUBIC_BEZIER_OPEN + '0.0, 0.35, .5, 1.3' + CUBIC_BEZIER_CLOSE, linear: 'linear', swing: 'ease-in-out', easeInQuad: CUBIC_BEZIER_OPEN + '0.550, 0.085, 0.680, 0.530' + CUBIC_BEZIER_CLOSE, easeInCubic: CUBIC_BEZIER_OPEN + '0.550, 0.055, 0.675, 0.190' + CUBIC_BEZIER_CLOSE, easeInQuart: CUBIC_BEZIER_OPEN + '0.895, 0.030, 0.685, 0.220' + CUBIC_BEZIER_CLOSE, easeInQuint: CUBIC_BEZIER_OPEN + '0.755, 0.050, 0.855, 0.060' + CUBIC_BEZIER_CLOSE, easeInSine: CUBIC_BEZIER_OPEN + '0.470, 0.000, 0.745, 0.715' + CUBIC_BEZIER_CLOSE, easeInExpo: CUBIC_BEZIER_OPEN + '0.950, 0.050, 0.795, 0.035' + CUBIC_BEZIER_CLOSE, easeInCirc: CUBIC_BEZIER_OPEN + '0.600, 0.040, 0.980, 0.335' + CUBIC_BEZIER_CLOSE, easeInBack: CUBIC_BEZIER_OPEN + '0.600, -0.280, 0.735, 0.045' + CUBIC_BEZIER_CLOSE, easeOutQuad: CUBIC_BEZIER_OPEN + '0.250, 0.460, 0.450, 0.940' + CUBIC_BEZIER_CLOSE, easeOutCubic: CUBIC_BEZIER_OPEN + '0.215, 0.610, 0.355, 1.000' + CUBIC_BEZIER_CLOSE, easeOutQuart: CUBIC_BEZIER_OPEN + '0.165, 0.840, 0.440, 1.000' + CUBIC_BEZIER_CLOSE, easeOutQuint: CUBIC_BEZIER_OPEN + '0.230, 1.000, 0.320, 1.000' + CUBIC_BEZIER_CLOSE, easeOutSine: CUBIC_BEZIER_OPEN + '0.390, 0.575, 0.565, 1.000' + CUBIC_BEZIER_CLOSE, easeOutExpo: CUBIC_BEZIER_OPEN + '0.190, 1.000, 0.220, 1.000' + CUBIC_BEZIER_CLOSE, easeOutCirc: CUBIC_BEZIER_OPEN + '0.075, 0.820, 0.165, 1.000' + CUBIC_BEZIER_CLOSE, easeOutBack: CUBIC_BEZIER_OPEN + '0.175, 0.885, 0.320, 1.275' + CUBIC_BEZIER_CLOSE, easeInOutQuad: CUBIC_BEZIER_OPEN + '0.455, 0.030, 0.515, 0.955' + CUBIC_BEZIER_CLOSE, easeInOutCubic: CUBIC_BEZIER_OPEN + '0.645, 0.045, 0.355, 1.000' + CUBIC_BEZIER_CLOSE, easeInOutQuart: CUBIC_BEZIER_OPEN + '0.770, 0.000, 0.175, 1.000' + CUBIC_BEZIER_CLOSE, easeInOutQuint: CUBIC_BEZIER_OPEN + '0.860, 0.000, 0.070, 1.000' + CUBIC_BEZIER_CLOSE, easeInOutSine: CUBIC_BEZIER_OPEN + '0.445, 0.050, 0.550, 0.950' + CUBIC_BEZIER_CLOSE, easeInOutExpo: CUBIC_BEZIER_OPEN + '1.000, 0.000, 0.000, 1.000' + CUBIC_BEZIER_CLOSE, easeInOutCirc: CUBIC_BEZIER_OPEN + '0.785, 0.135, 0.150, 0.860' + CUBIC_BEZIER_CLOSE, easeInOutBack: CUBIC_BEZIER_OPEN + '0.680, -0.550, 0.265, 1.550' + CUBIC_BEZIER_CLOSE} , domProperties = { } , cssEasing = easings[opt.easing || 'swing']? easings[opt.easing || 'swing']: opt.easing || 'swing'; for (var p in prop){ if (jQuery.inArray(p, pluginOptions) === -1) { var isDirection = jQuery.inArray(p, directions) > -1, cleanVal = _interpretValue(self, prop[p], p, (isDirection && prop.avoidTransforms !== true )); if (_appropriateProperty(p, cleanVal, self)) { _applyCSSTransition(self, p, opt.duration, cssEasing, cleanVal, isDirection && prop.avoidTransforms !== true , isTranslatable, prop.useTranslate3d); } else { domProperties[p] = prop[p]; } } } self.unbind(transitionEndEvent); var selfCSSData = self.data(DATA_KEY); if (selfCSSData && !_isEmptyObject(selfCSSData) && !_isEmptyObject(selfCSSData.secondary)) { callbackQueue++ ; self.css(selfCSSData.properties); var secondary = selfCSSData.secondary; _AN_Call_settimeout('setTimeout', window, function (){ self.bind(transitionEndEvent, cssCallback).css(secondary); } ); } else { opt.queue = false ; } if (!_isEmptyObject(domProperties)) { callbackQueue++ ; originalAnimateMethod.apply(self, [domProperties, { duration: opt.duration, easing: jQuery.easing[opt.easing]? opt.easing: (jQuery.easing.swing? 'swing': 'linear'), complete: propertyCallback, queue: opt.queue} ] ); } return true ; } ); } ; jQuery.fn.animate.defaults = { } ; jQuery.fn.stop = function (clearQueue, gotoEnd, leaveTransforms){ if (!cssTransitionsSupported) return originalStopMethod.apply(this, [clearQueue, gotoEnd] ); if (clearQueue) this.queue([] ); this.each(function (){ var self = jQuery(this), selfCSSData = self.data(DATA_KEY); if (selfCSSData && !_isEmptyObject(selfCSSData)) { var i, restore = { } ; if (gotoEnd) { restore = selfCSSData.secondary; if (!leaveTransforms && typeof selfCSSData.meta.left_o !== undefined || typeof selfCSSData.meta.top_o !== undefined) { restore.left = typeof selfCSSData.meta.left_o !== undefined? selfCSSData.meta.left_o: 'auto'; restore.top = typeof selfCSSData.meta.top_o !== undefined? selfCSSData.meta.top_o: 'auto'; for (i = _AN_Read_length('length', cssPrefixes) - 1; i >= 0; i-- ){ restore[cssPrefixes[i] + 'transform'] = ''; } } } else if (!_isEmptyObject(selfCSSData.secondary)) { var cStyle = window.getComputedStyle(self[0], null ); if (cStyle) { for (var prop in selfCSSData.secondary){ if (selfCSSData.secondary.hasOwnProperty(prop)) { prop = _AN_Call_replace('replace', prop, rupper, '-$1').toLowerCase(); restore[prop] = cStyle.getPropertyValue(prop); if (!leaveTransforms && (/matrix/i).test(restore[prop])) { var explodedMatrix = _AN_Call_replace('replace', restore[prop], /^matrix\(/i, '').split(/, |\)$/g); restore.left = (parseFloat(explodedMatrix[4]) + parseFloat(self.css('left')) + valUnit) || 'auto'; restore.top = (parseFloat(explodedMatrix[5]) + parseFloat(self.css('top')) + valUnit) || 'auto'; for (i = _AN_Read_length('length', cssPrefixes) - 1; i >= 0; i-- ){ restore[cssPrefixes[i] + 'transform'] = ''; } } } } } } self.unbind(transitionEndEvent); self.css(selfCSSData.original).css(restore).data(DATA_KEY, null ); } else { originalStopMethod.apply(self, [clearQueue, gotoEnd] ); } } ); return this; } ; } ));