define(["./core", "./var/document", "./var/rcssNum", "./var/rnotwhite", "./css/var/cssExpand", "./css/var/isHidden", "./css/var/swap", "./css/adjustCSS", "./data/var/dataPriv", "./css/showHide", "./core/init", "./queue", "./deferred", "./traversing", "./manipulation", "./css", "./effects/Tween"] , function (jQuery, document, rcssNum, rnotwhite, cssExpand, isHidden, swap, adjustCSS, dataPriv, showHide){ var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, rrun = /queueHooks$/; function raf(){ if (timerId) { window.requestAnimationFrame(raf); jQuery.fx.tick(); } } function createFxNow(){ _AN_Call_settimeout("setTimeout", window, function (){ fxNow = undefined; } ); return (fxNow = jQuery.now()); } function genFx(type, includeWidth){ var which, i = 0, attrs = { height: type} ; includeWidth = includeWidth? 1: 0; for (; i < 4; i += 2 - includeWidth){ which = cssExpand[i]; attrs["margin" + which] = attrs["padding" + which] = type; } if (includeWidth) { attrs.opacity = attrs.width = type; } return attrs; } function createTween(value, prop, animation){ var tween, collection = (Animation.tweeners[prop] || [] ).concat(Animation.tweeners["*"] ), index = 0, length = _AN_Read_length("length", collection); for (; index < length; index++ ){ if ((tween = collection[index].call(animation, prop, value))) { return tween; } } } function defaultPrefilter(elem, props, opts){ var prop, value, toggle, hooks, oldfire, propTween, restoreDisplay, display, isBox = "width" in props || "height" in props, anim = this, orig = { } , style = elem.style, hidden = elem.nodeType && isHidden(elem), dataShow = dataPriv.get(elem, "fxshow"); if (!opts.queue) { hooks = jQuery._queueHooks(elem, "fx"); if (hooks.unqueued == null ) { hooks.unqueued = 0; oldfire = hooks.empty.fire; hooks.empty.fire = function (){ if (!hooks.unqueued) { oldfire(); } } ; } hooks.unqueued++ ; anim.always(function (){ anim.always(function (){ hooks.unqueued-- ; if (!_AN_Read_length("length", jQuery.queue(elem, "fx"))) { hooks.empty.fire(); } } ); } ); } for (prop in props){ value = props[prop]; if (rfxtypes.test(value)) { delete props[prop]; toggle = toggle || value === "toggle"; if (value === (hidden? "hide": "show")) { if (value === "show" && dataShow && dataShow[prop] !== undefined) { hidden = true ; } else { continue ; } } orig[prop] = dataShow && dataShow[prop] || jQuery.style(elem, prop); } } propTween = !jQuery.isEmptyObject(props); if (!propTween && jQuery.isEmptyObject(orig)) { return ; } if (isBox && elem.nodeType === 1) { opts.overflow = [style.overflow, style.overflowX, style.overflowY] ; restoreDisplay = dataShow && dataShow.display; if (restoreDisplay == null ) { restoreDisplay = dataPriv.get(elem, "display"); } display = jQuery.css(elem, "display"); if (display === "none") { display = restoreDisplay || swap(elem, { "display": ""} , function (){ return jQuery.css(elem, "display"); } ); } if (display === "inline" || display === "inline-block" && restoreDisplay != null ) { if (jQuery.css(elem, "float") === "none") { if (!propTween) { anim.done(function (){ style.display = restoreDisplay; } ); if (restoreDisplay == null ) { display = style.display; restoreDisplay = display === "none"? "": display; } } style.display = "inline-block"; } } } if (opts.overflow) { style.overflow = "hidden"; anim.always(function (){ style.overflow = opts.overflow[0]; style.overflowX = opts.overflow[1]; style.overflowY = opts.overflow[2]; } ); } propTween = false ; for (prop in orig){ if (!propTween) { if (dataShow) { if ("hidden" in dataShow) { hidden = dataShow.hidden; } } else { dataShow = dataPriv.access(elem, "fxshow", { display: restoreDisplay} ); } if (toggle) { dataShow.hidden = !hidden; } if (hidden) { showHide([elem] , true ); } anim.done(function (){ if (!hidden) { showHide([elem] ); } dataPriv.remove(elem, "fxshow"); for (prop in orig){ jQuery.style(elem, prop, orig[prop]); } } ); } propTween = createTween(hidden? dataShow[prop]: 0, prop, anim); if (!(prop in dataShow)) { dataShow[prop] = propTween.start; if (hidden) { propTween.end = propTween.start; propTween.start = prop === "width" || prop === "height"? 1: 0; } } } } function propFilter(props, specialEasing){ var index, name, easing, value, hooks; for (index in props){ name = jQuery.camelCase(index); easing = specialEasing[name]; value = props[index]; if (jQuery.isArray(value)) { easing = value[1]; value = props[index] = value[0]; } if (index !== name) { props[name] = value; delete props[index]; } hooks = jQuery.cssHooks[name]; if (hooks && "expand" in hooks) { value = hooks.expand(value); delete props[name]; for (index in value){ if (!(index in props)) { props[index] = value[index]; specialEasing[index] = easing; } } } else { specialEasing[name] = easing; } } } function Animation(elem, properties, options){ var result, stopped, index = 0, length = _AN_Read_length("length", Animation.prefilters), deferred = jQuery.Deferred().always(function (){ delete tick.elem; } ), tick = function (){ if (stopped) { return false ; } var currentTime = fxNow || createFxNow(), remaining = Math.max(0, animation.startTime + animation.duration - currentTime), temp = remaining / animation.duration || 0, percent = 1 - temp, index = 0, length = _AN_Read_length("length", animation.tweens); for (; index < length; index++ ){ animation.tweens[index].run(percent); } deferred.notifyWith(elem, [animation, percent, remaining] ); if (percent < 1 && length) { return remaining; } else { deferred.resolveWith(elem, [animation] ); return false ; } } , animation = deferred.promise({ elem: elem, props: jQuery.extend({ } , properties), opts: jQuery.extend(true , { specialEasing: { } , easing: jQuery.easing._default} , options), originalProperties: properties, originalOptions: options, startTime: fxNow || createFxNow(), duration: options.duration, tweens: [] , createTween: function (prop, end){ var tween = jQuery.Tween(elem, animation.opts, prop, end, animation.opts.specialEasing[prop] || animation.opts.easing); animation.tweens.push(tween); return tween; } , stop: function (gotoEnd){ var index = 0, length = gotoEnd? _AN_Read_length("length", animation.tweens): 0; if (stopped) { return this; } stopped = true ; for (; index < length; index++ ){ animation.tweens[index].run(1); } if (gotoEnd) { deferred.notifyWith(elem, [animation, 1, 0] ); deferred.resolveWith(elem, [animation, gotoEnd] ); } else { deferred.rejectWith(elem, [animation, gotoEnd] ); } return this; } } ), props = animation.props; propFilter(props, animation.opts.specialEasing); for (; index < length; index++ ){ result = Animation.prefilters[index].call(animation, elem, props, animation.opts); if (result) { if (jQuery.isFunction(result.stop)) { jQuery._queueHooks(animation.elem, animation.opts.queue).stop = jQuery.proxy(result.stop, result); } return result; } } jQuery.map(props, createTween, animation); if (jQuery.isFunction(animation.opts.start)) { animation.opts.start.call(elem, animation); } jQuery.fx.timer(jQuery.extend(tick, { elem: elem, anim: animation, queue: animation.opts.queue} )); return animation.progress(animation.opts.progress).done(animation.opts.done, animation.opts.complete).fail(animation.opts.fail).always(animation.opts.always); } jQuery.Animation = jQuery.extend(Animation, { tweeners: { "*": [function (prop, value){ var tween = this.createTween(prop, value); adjustCSS(tween.elem, prop, rcssNum.exec(value), tween); return tween; } ] } , tweener: function (props, callback){ if (jQuery.isFunction(props)) { callback = props; props = ["*"] ; } else { props = props.match(rnotwhite); } var prop, index = 0, length = _AN_Read_length("length", props); for (; index < length; index++ ){ prop = props[index]; Animation.tweeners[prop] = Animation.tweeners[prop] || [] ; Animation.tweeners[prop].unshift(callback); } } , prefilters: [defaultPrefilter] , prefilter: function (callback, prepend){ if (prepend) { Animation.prefilters.unshift(callback); } else { Animation.prefilters.push(callback); } } } ); jQuery.speed = function (speed, easing, fn){ var opt = speed && typeof speed === "object"? jQuery.extend({ } , speed): { complete: fn || !fn && easing || jQuery.isFunction(speed) && speed, duration: speed, easing: fn && easing || easing && !jQuery.isFunction(easing) && easing} ; if (jQuery.fx.off || document.hidden) { opt.duration = 0; } else { opt.duration = typeof opt.duration === "number"? opt.duration: opt.duration in jQuery.fx.speeds? jQuery.fx.speeds[opt.duration]: jQuery.fx.speeds._default; } if (opt.queue == null || opt.queue === true ) { opt.queue = "fx"; } opt.old = opt.complete; opt.complete = function (){ if (jQuery.isFunction(opt.old)) { opt.old.call(this); } if (opt.queue) { jQuery.dequeue(this, opt.queue); } } ; return opt; } ; jQuery.fn.extend({ fadeTo: function (speed, to, easing, callback){ return _AN_Call_show("show", this.filter(isHidden).css("opacity", 0)).end().animate({ opacity: to} , speed, easing, callback); } , animate: function (prop, speed, easing, callback){ var empty = jQuery.isEmptyObject(prop), optall = jQuery.speed(speed, easing, callback), doAnimation = function (){ var anim = Animation(this, jQuery.extend({ } , prop), optall); if (empty || dataPriv.get(this, "finish")) { anim.stop(true ); } } ; doAnimation.finish = doAnimation; return empty || optall.queue === false ? this.each(doAnimation): this.queue(optall.queue, doAnimation); } , stop: function (type, clearQueue, gotoEnd){ var stopQueue = function (hooks){ var stop = hooks.stop; delete hooks.stop; stop(gotoEnd); } ; if (typeof type !== "string") { gotoEnd = clearQueue; clearQueue = type; type = undefined; } if (clearQueue && type !== false ) { this.queue(type || "fx", [] ); } return this.each(function (){ var dequeue = true , index = type != null && type + "queueHooks", timers = jQuery.timers, data = dataPriv.get(this); if (index) { if (data[index] && data[index].stop) { stopQueue(data[index]); } } else { for (index in data){ if (data[index] && data[index].stop && rrun.test(index)) { stopQueue(data[index]); } } } for (index = _AN_Read_length("length", timers); index-- ; ){ if (timers[index].elem === this && (type == null || timers[index].queue === type)) { timers[index].anim.stop(gotoEnd); dequeue = false ; timers.splice(index, 1); } } if (dequeue || !gotoEnd) { jQuery.dequeue(this, type); } } ); } , finish: function (type){ if (type !== false ) { type = type || "fx"; } return this.each(function (){ var index, data = dataPriv.get(this), queue = data[type + "queue"], hooks = data[type + "queueHooks"], timers = jQuery.timers, length = queue? _AN_Read_length("length", queue): 0; data.finish = true ; jQuery.queue(this, type, [] ); if (hooks && hooks.stop) { hooks.stop.call(this, true ); } for (index = _AN_Read_length("length", timers); index-- ; ){ if (timers[index].elem === this && timers[index].queue === type) { timers[index].anim.stop(true ); timers.splice(index, 1); } } for (index = 0; index < length; index++ ){ if (queue[index] && queue[index].finish) { queue[index].finish.call(this); } } delete data.finish; } ); } } ); jQuery.each(["toggle", "show", "hide"] , function (i, name){ var cssFn = jQuery.fn[name]; jQuery.fn[name] = function (speed, easing, callback){ return speed == null || typeof speed === "boolean"? cssFn.apply(this, arguments): this.animate(genFx(name, true ), speed, easing, callback); } ; } ); jQuery.each({ slideDown: genFx("show"), slideUp: genFx("hide"), slideToggle: genFx("toggle"), fadeIn: { opacity: "show"} , fadeOut: { opacity: "hide"} , fadeToggle: { opacity: "toggle"} } , function (name, props){ jQuery.fn[name] = function (speed, easing, callback){ return this.animate(props, speed, easing, callback); } ; } ); jQuery.timers = [] ; jQuery.fx.tick = function (){ var timer, i = 0, timers = jQuery.timers; fxNow = jQuery.now(); for (; i < _AN_Read_length("length", timers); i++ ){ timer = timers[i]; if (!timer() && timers[i] === timer) { timers.splice(i-- , 1); } } if (!_AN_Read_length("length", timers)) { jQuery.fx.stop(); } fxNow = undefined; } ; jQuery.fx.timer = function (timer){ jQuery.timers.push(timer); if (timer()) { jQuery.fx.start(); } else { jQuery.timers.pop(); } } ; jQuery.fx.interval = 13; jQuery.fx.start = function (){ if (!timerId) { timerId = window.requestAnimationFrame? window.requestAnimationFrame(raf): _AN_Call_setinterval("setInterval", window, jQuery.fx.tick, jQuery.fx.interval); } } ; jQuery.fx.stop = function (){ if (window.cancelAnimationFrame) { window.cancelAnimationFrame(timerId); } else { window.clearInterval(timerId); } timerId = null ; } ; jQuery.fx.speeds = { slow: 600, fast: 200, _default: 400} ; return jQuery; } );