From c0093b599fcd58b6ad122ab425c4cc1a4da4a520 Mon Sep 17 00:00:00 2001 From: Scott González Date: Sat, 11 Feb 2012 12:20:46 -0500 Subject: Easings: Rewrote all easings to only rely on state and reduce code size. Fixes #8115 - Easings: Simplify equations to only rely on state. --- ui/jquery.effects.core.js | 250 +++++++--------------------------------------- 1 file changed, 35 insertions(+), 215 deletions(-) (limited to 'ui/jquery.effects.core.js') diff --git a/ui/jquery.effects.core.js b/ui/jquery.effects.core.js index 233b4f96d..68ed637e1 100644 --- a/ui/jquery.effects.core.js +++ b/ui/jquery.effects.core.js @@ -662,229 +662,49 @@ $.fn.extend({ /*********************************** EASING ***********************************/ /******************************************************************************/ -/* - * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ - * - * Uses the built in easing capabilities added In jQuery 1.1 - * to offer multiple easing options - * - * TERMS OF USE - jQuery Easing - * - * Open source under the BSD License. - * - * Copyright 2008 George McGinley Smith - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * Neither the name of the author nor the names of contributors may be used to endorse - * or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * -*/ +// based on easing equations from Robert Penner (http://www.robertpenner.com/easing) -// t: current time, b: begInnIng value, c: change In value, d: duration -$.easing.jswing = $.easing.swing; +var baseEasings = {}; -$.extend( $.easing, { - def: "easeOutQuad", - swing: function ( x, t, b, c, d ) { - return $.easing[ $.easing.def ]( x, t, b, c, d ); - }, - easeInQuad: function ( x, t, b, c, d ) { - return c * ( t /= d ) * t + b; - }, - easeOutQuad: function ( x, t, b, c, d ) { - return -c * ( t /= d ) * ( t - 2 ) + b; - }, - easeInOutQuad: function ( x, t, b, c, d ) { - if ( ( t /= d / 2 ) < 1 ) return c / 2 * t * t + b; - return -c / 2 * ( ( --t ) * ( t-2 ) - 1) + b; - }, - easeInCubic: function ( x, t, b, c, d ) { - return c * ( t /= d ) * t * t + b; - }, - easeOutCubic: function ( x, t, b, c, d ) { - return c * ( ( t = t / d - 1 ) * t * t + 1 ) + b; - }, - easeInOutCubic: function ( x, t, b, c, d ) { - if ( ( t /= d / 2 ) < 1 ) return c / 2 * t * t * t + b; - return c / 2 * ( ( t -= 2 ) * t * t + 2) + b; - }, - easeInQuart: function ( x, t, b, c, d ) { - return c * ( t /= d ) * t * t * t + b; - }, - easeOutQuart: function ( x, t, b, c, d ) { - return -c * ( ( t = t / d - 1 ) * t * t * t - 1) + b; - }, - easeInOutQuart: function ( x, t, b, c, d ) { - if ( (t /= d / 2 ) < 1 ) return c / 2 * t * t * t * t + b; - return -c / 2 * ( ( t -= 2 ) * t * t * t - 2) + b; - }, - easeInQuint: function ( x, t, b, c, d ) { - return c * ( t /= d ) * t * t * t * t + b; - }, - easeOutQuint: function ( x, t, b, c, d ) { - return c * ( ( t = t / d - 1 ) * t * t * t * t + 1) + b; - }, - easeInOutQuint: function ( x, t, b, c, d ) { - if ( ( t /= d / 2 ) < 1 ) return c / 2 * t * t * t * t * t + b; - return c / 2 * ( ( t -= 2 ) * t * t * t * t + 2) + b; - }, - easeInSine: function ( x, t, b, c, d ) { - return -c * Math.cos( t / d * ( Math.PI / 2 ) ) + c + b; - }, - easeOutSine: function ( x, t, b, c, d ) { - return c * Math.sin( t / d * ( Math.PI /2 ) ) + b; - }, - easeInOutSine: function ( x, t, b, c, d ) { - return -c / 2 * ( Math.cos( Math.PI * t / d ) - 1 ) + b; - }, - easeInExpo: function ( x, t, b, c, d ) { - return ( t==0 ) ? b : c * Math.pow( 2, 10 * ( t / d - 1) ) + b; - }, - easeOutExpo: function ( x, t, b, c, d ) { - return ( t==d ) ? b + c : c * ( -Math.pow( 2, -10 * t / d) + 1) + b; - }, - easeInOutExpo: function ( x, t, b, c, d ) { - if ( t==0 ) return b; - if ( t==d ) return b + c; - if ( ( t /= d / 2) < 1) return c / 2 * Math.pow( 2, 10 * (t - 1) ) + b; - return c / 2 * ( -Math.pow( 2, -10 * --t ) + 2 ) + b; - }, - easeInCirc: function ( x, t, b, c, d ) { - return -c * ( Math.sqrt( 1 - ( t /= d ) * t ) - 1 ) + b; - }, - easeOutCirc: function ( x, t, b, c, d ) { - return c * Math.sqrt( 1 - ( t = t / d - 1 ) * t ) + b; - }, - easeInOutCirc: function ( x, t, b, c, d ) { - if ( ( t /= d / 2) < 1 ) return -c / 2 * ( Math.sqrt( 1 - t * t ) - 1 ) + b; - return c / 2 * ( Math.sqrt( 1 - ( t -= 2 ) * t ) + 1 ) + b; - }, - easeInElastic: function ( x, t, b, c, d ) { - var s = 1.70158, - p = d * 0.3, - a = c; - if ( t == 0 ) return b; - if ( ( t /= d ) == 1 ) return b+c; - if ( a < Math.abs( c ) ) { - a = c; - s = p / 4; - } else { - s = p / ( 2 * Math.PI ) * Math.asin( c / a ); - } - return - ( a * Math.pow( 2, 10 * ( t -= 1 ) ) * Math.sin( ( t * d - s) * ( 2 * Math.PI ) / p ) ) + b; - }, - easeOutElastic: function ( x, t, b, c, d ) { - var s = 1.70158, - p = d * 0.3, - a = c; - if ( t == 0 ) return b; - if ( ( t /= d ) == 1 ) return b+c; - if ( a < Math.abs( c ) ) { - a = c; - s = p / 4; - } else { - s = p / ( 2 * Math.PI ) * Math.asin( c / a ); - } - return a * Math.pow( 2, -10 * t ) * Math.sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) + c + b; - }, - easeInOutElastic: function ( x, t, b, c, d ) { - var s = 1.70158, - p = d * ( 0.3 * 1.5 ), - a = c; - if ( t == 0 ) return b; - if ( ( t /= d / 2 ) == 2 ) return b+c; - if ( a < Math.abs( c ) ) { - a = c; - s = p / 4; - } else { - s = p / ( 2 * Math.PI ) * Math.asin( c / a ); - } - if ( t < 1 ) return -.5 * ( a * Math.pow( 2, 10 * ( t -= 1 ) ) * Math.sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) ) + b; - return a * Math.pow( 2, -10 * ( t -= 1 ) ) * Math.sin( ( t * d - s ) * ( 2 * Math.PI ) / p ) *.5 + c + b; - }, - easeInBack: function ( x, t, b, c, d, s ) { - if ( s == undefined ) s = 1.70158; - return c * ( t /= d ) * t * ( ( s+1 ) * t - s ) + b; - }, - easeOutBack: function ( x, t, b, c, d, s ) { - if ( s == undefined ) s = 1.70158; - return c * ( ( t = t / d - 1 ) * t * ( ( s + 1 ) * t + s) + 1) + b; +$.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) { + baseEasings[ name ] = function( p ) { + return Math.pow( p, i + 2 ); + }; +}); + +$.extend( baseEasings, { + Sine: function ( p ) { + return 1 - Math.cos( p * Math.PI / 2 ); }, - easeInOutBack: function ( x, t, b, c, d, s ) { - if ( s == undefined ) s = 1.70158; - if ( ( t /= d / 2 ) < 1 ) return c / 2 * ( t * t * ( ( ( s *= 1.525 ) + 1 ) * t - s ) ) + b; - return c / 2 * ( ( t -= 2 ) * t * ( ( ( s *= 1.525 ) + 1 ) * t + s) + 2) + b; + Circ: function ( p ) { + return 1 - Math.sqrt( 1 - p * p ); }, - easeInBounce: function ( x, t, b, c, d ) { - return c - $.easing.easeOutBounce( x, d - t, 0, c, d ) + b; + Elastic: function( p ) { + return p === 0 || p === 1 ? p : + -Math.pow( 2, 8 * (p - 1) ) * Math.sin( ( (p - 1) * 80 - 7.5 ) * Math.PI / 15 ); }, - easeOutBounce: function ( x, t, b, c, d ) { - if ( ( t /= d ) < ( 1 / 2.75 ) ) { - return c * ( 7.5625 * t * t ) + b; - } else if ( t < ( 2 / 2.75 ) ) { - return c * ( 7.5625 * ( t -= ( 1.5 / 2.75 ) ) * t + .75 ) + b; - } else if ( t < ( 2.5 / 2.75 ) ) { - return c * ( 7.5625 * ( t -= ( 2.25/ 2.75 ) ) * t + .9375 ) + b; - } else { - return c * ( 7.5625 * ( t -= ( 2.625 / 2.75 ) ) * t + .984375 ) + b; - } + Back: function( p ) { + return p * p * ( 3 * p - 2 ); }, - easeInOutBounce: function ( x, t, b, c, d ) { - if ( t < d / 2 ) return $.easing.easeInBounce( x, t * 2, 0, c, d ) * .5 + b; - return $.easing.easeOutBounce( x, t * 2 - d, 0, c, d ) * .5 + c * .5 + b; + Bounce: function ( p ) { + var pow2, + bounce = 4; + + while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {} + return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 ); } }); -/* - * - * TERMS OF USE - EASING EQUATIONS - * - * Open source under the BSD License. - * - * Copyright 2001 Robert Penner - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * Neither the name of the author nor the names of contributors may be used to endorse - * or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ +$.each( baseEasings, function( name, easeIn ) { + $.easing[ "easeIn" + name ] = easeIn; + $.easing[ "easeOut" + name ] = function( p ) { + return 1 - easeIn( 1 - p ); + }; + $.easing[ "easeInOut" + name ] = function( p ) { + return p < .5 ? + easeIn( p * 2 ) / 2 : + easeIn( p * -2 + 2 ) / -2 + 1; + }; +}); })(jQuery); -- cgit v1.2.3 From 609243b21d2530ecd5e8e19e99951decc8587285 Mon Sep 17 00:00:00 2001 From: Scott González Date: Sun, 12 Feb 2012 09:01:06 -0500 Subject: Use jQuery.css() instead of deprecated jQuery.curCSS(). --- ui/jquery.effects.core.js | 2 +- ui/jquery.ui.core.js | 12 ++++++------ ui/jquery.ui.menu.js | 4 ++-- ui/jquery.ui.position.js | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'ui/jquery.effects.core.js') diff --git a/ui/jquery.effects.core.js b/ui/jquery.effects.core.js index 68ed637e1..b28e4c4ee 100644 --- a/ui/jquery.effects.core.js +++ b/ui/jquery.effects.core.js @@ -77,7 +77,7 @@ function getColor(elem, attr) { var color; do { - color = $.curCSS(elem, attr); + color = $.css(elem, attr); // Keep going until we find an element that has color, or we hit the body if ( color != "" && color !== "transparent" || $.nodeName(elem, "body") ) diff --git a/ui/jquery.ui.core.js b/ui/jquery.ui.core.js index d777d6d49..1c54c993c 100644 --- a/ui/jquery.ui.core.js +++ b/ui/jquery.ui.core.js @@ -77,11 +77,11 @@ $.fn.extend({ var scrollParent; if (($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) { scrollParent = this.parents().filter(function() { - return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1)); + return (/(relative|absolute|fixed)/).test($.css(this,'position')) && (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x')); }).eq(0); } else { scrollParent = this.parents().filter(function() { - return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1)); + return (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x')); }).eq(0); } @@ -141,12 +141,12 @@ $.each( [ "Width", "Height" ], function( i, name ) { function reduce( elem, size, border, margin ) { $.each( side, function() { - size -= parseFloat( $.curCSS( elem, "padding" + this, true ) ) || 0; + size -= parseFloat( $.css( elem, "padding" + this ) ) || 0; if ( border ) { - size -= parseFloat( $.curCSS( elem, "border" + this + "Width", true ) ) || 0; + size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0; } if ( margin ) { - size -= parseFloat( $.curCSS( elem, "margin" + this, true ) ) || 0; + size -= parseFloat( $.css( elem, "margin" + this ) ) || 0; } }); return size; @@ -197,7 +197,7 @@ function focusable( element, isTabIndexNotNaN ) { function visible( element ) { return !$( element ).parents().andSelf().filter(function() { - return $.curCSS( this, "visibility" ) === "hidden" || + return $.css( this, "visibility" ) === "hidden" || $.expr.filters.hidden( this ); }).length; } diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index 45be5edcf..42829c2a1 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -286,8 +286,8 @@ $.widget( "ui.menu", { this.blur( event ); if ( this._hasScroll() ) { - var borderTop = parseFloat( $.curCSS( this.activeMenu[0], "borderTopWidth", true ) ) || 0, - paddingTop = parseFloat( $.curCSS( this.activeMenu[0], "paddingTop", true ) ) || 0, + var borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0, + paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0, offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop, scroll = this.activeMenu.scrollTop(), elementHeight = this.activeMenu.height(), diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index 00976bf79..119847cec 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -152,13 +152,13 @@ $.fn.position = function( options ) { var elem = $( this ), elemWidth = elem.outerWidth(), elemHeight = elem.outerHeight(), - marginLeft = parseInt( $.curCSS( this, "marginLeft", true ) ) || 0, - marginTop = parseInt( $.curCSS( this, "marginTop", true ) ) || 0, + marginLeft = parseInt( $.css( this, "marginLeft" ) ) || 0, + marginTop = parseInt( $.css( this, "marginTop" ) ) || 0, scrollInfo = $.position.getScrollInfo( within ), collisionWidth = elemWidth + marginLeft + - ( parseInt( $.curCSS( this, "marginRight", true ) ) || 0 ) + scrollInfo.width, + ( parseInt( $.css( this, "marginRight" ) ) || 0 ) + scrollInfo.width, collisionHeight = elemHeight + marginTop + - ( parseInt( $.curCSS( this, "marginBottom", true ) ) || 0 ) + scrollInfo.height, + ( parseInt( $.css( this, "marginBottom" ) ) || 0 ) + scrollInfo.height, position = $.extend( {}, basePosition ), myOffset = [ parseInt( offsets.my[ 0 ], 10 ) * -- cgit v1.2.3