Make WordPress Core

Changeset 54374


Ignore:
Timestamp:
10/04/2022 01:41:59 AM (4 years ago)
Author:
desrosj
Message:

Twenty Seventeen: Update the scrollTo jQuery plugin.

This updates the scrollTo jQuery plugin included in Twenty Seventeen to the latest version, 2.1.3.

For a full list of changes in this update, see GitHub: https://github.com/flesler/jquery.scrollTo/compare/2.1.2...v2.1.3.

Props sarahricker, mukesh27, desrosj.
Fixes #56702.

Location:
trunk/src/wp-content/themes/twentyseventeen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js

    r46586 r54374  
    11/*!
    22 * jQuery.scrollTo
    3  * Copyright (c) 2007-2015 Ariel Flesler - aflesler<a>gmail<d>com | http://flesler.blogspot.com
     3 * Copyright (c) 2007 Ariel Flesler - aflesler ○ gmail • com | https://github.com/flesler
    44 * Licensed under MIT
    5  * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
     5 * https://github.com/flesler/jquery.scrollTo
    66 * @projectDescription Lightweight, cross-browser and highly customizable animated scrolling with jQuery
    77 * @author Ariel Flesler
    8  * @version 2.1.2
     8 * @version 2.1.3
    99 */
    1010;(function(factory) {
     
    1212        if (typeof define === 'function' && define.amd) {
    1313                // AMD
    14                 define( ['jquery'], factory );
     14                define(['jquery'], factory);
    1515        } else if (typeof module !== 'undefined' && module.exports) {
    1616                // CommonJS
    17                 module.exports = factory( require( 'jquery' ) );
     17                module.exports = factory(require('jquery'));
    1818        } else {
    1919                // Global
    20                 factory( jQuery );
     20                factory(jQuery);
    2121        }
    2222})(function($) {
     
    2424
    2525        var $scrollTo = $.scrollTo = function(target, duration, settings) {
    26                 return $( window ).scrollTo( target, duration, settings );
     26                return $(window).scrollTo(target, duration, settings);
    2727        };
    2828
     
    3434
    3535        function isWin(elem) {
    36                 return ! elem.nodeName ||
    37                         $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) !== -1;
     36                return !elem.nodeName ||
     37                        $.inArray(elem.nodeName.toLowerCase(), ['iframe','#document','html','body']) !== -1;
     38        }
     39
     40        function isFunction(obj) {
     41                // Brought from jQuery since it's deprecated
     42                return typeof obj === 'function'
    3843        }
    3944
     
    5055                }
    5156
    52                 settings = $.extend( {}, $scrollTo.defaults, settings );
     57                settings = $.extend({}, $scrollTo.defaults, settings);
    5358                // Speed is still recognized for backwards compatibility
    5459                duration = duration || settings.duration;
     
    5964                        duration /= 2;
    6065                }
    61                 settings.offset = both( settings.offset );
    62                 settings.over = both( settings.over );
     66                settings.offset = both(settings.offset);
     67                settings.over = both(settings.over);
    6368
    6469                return this.each(function() {
    6570                        // Null target yields nothing, just like jQuery does
    66                         if (target === null) { return; }
    67 
    68                         var win = isWin( this ),
     71                        if (target === null) return;
     72
     73                        var win = isWin(this),
    6974                                elem = win ? this.contentWindow || window : this,
    70                                 $elem = $( elem ),
     75                                $elem = $(elem),
    7176                                targ = target,
    7277                                attr = {},
     
    7782                                case 'number':
    7883                                case 'string':
    79                                         if (/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test( targ )) {
    80                                                 targ = both( targ );
     84                                        if (/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(targ)) {
     85                                                targ = both(targ);
    8186                                                // We are done
    8287                                                break;
    8388                                        }
    8489                                        // Relative/Absolute selector
    85                                         targ = win ? $( targ ) : $( targ, elem );
     90                                        targ = win ? $(targ) : $(targ, elem);
    8691                                        /* falls through */
    8792                                case 'object':
    88                                         if (targ.length === 0) { return; }
     93                                        if (targ.length === 0) return;
    8994                                        // DOMElement / jQuery
    9095                                        if (targ.is || targ.style) {
    9196                                                // Get the real position of the target
    92                                                 toff = (targ = $( targ )).offset();
    93                                         }
    94                         }
    95 
    96                         var offset = $.isFunction( settings.offset ) && settings.offset( elem, targ ) || settings.offset;
    97 
    98                         $.each(settings.axis.split( '' ), function(i, axis) {
     97                                                toff = (targ = $(targ)).offset();
     98                                        }
     99                        }
     100
     101                        var offset = isFunction(settings.offset) && settings.offset(elem, targ) || settings.offset;
     102
     103                        $.each(settings.axis.split(''), function(i, axis) {
    99104                                var Pos = axis === 'x' ? 'Left' : 'Top',
    100105                                        pos = Pos.toLowerCase(),
    101106                                        key = 'scroll' + Pos,
    102107                                        prev = $elem[key](),
    103                                         max = $scrollTo.max( elem, axis );
     108                                        max = $scrollTo.max(elem, axis);
    104109
    105110                                if (toff) {// jQuery / DOMElement
     
    108113                                        // If it's a dom element, reduce the margin
    109114                                        if (settings.margin) {
    110                                                 attr[key] -= parseInt( targ.css( 'margin' + Pos ), 10 ) || 0;
    111                                                 attr[key] -= parseInt( targ.css( 'border' + Pos + 'Width' ), 10 ) || 0;
     115                                                attr[key] -= parseInt(targ.css('margin'+Pos), 10) || 0;
     116                                                attr[key] -= parseInt(targ.css('border'+Pos+'Width'), 10) || 0;
    112117                                        }
    113118
     
    121126                                        var val = targ[pos];
    122127                                        // Handle percentage values
    123                                         attr[key] = val.slice && val.slice( -1 ) === '%' ?
    124                                                 parseFloat( val ) / 100 * max
     128                                        attr[key] = val.slice && val.slice(-1) === '%' ?
     129                                                parseFloat(val) / 100 * max
    125130                                                : val;
    126131                                }
    127132
    128133                                // Number or 'number'
    129                                 if (settings.limit && /^\d+$/.test( attr[key] )) {
     134                                if (settings.limit && /^\d+$/.test(attr[key])) {
    130135                                        // Check the limits
    131                                         attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );
     136                                        attr[key] = attr[key] <= 0 ? 0 : Math.min(attr[key], max);
    132137                                }
    133138
    134139                                // Don't waste time animating, if there's no need.
    135                                 if ( ! i && settings.axis.length > 1) {
     140                                if (!i && settings.axis.length > 1) {
    136141                                        if (prev === attr[key]) {
    137142                                                // No animation needed
     
    139144                                        } else if (queue) {
    140145                                                // Intermediate animation
    141                                                 animate( settings.onAfterFirst );
     146                                                animate(settings.onAfterFirst);
    142147                                                // Don't animate this axis again in the next iteration.
    143148                                                attr = {};
     
    146151                        });
    147152
    148                         animate( settings.onAfter );
     153                        animate(settings.onAfter);
    149154
    150155                        function animate(callback) {
     
    155160                                        duration: duration,
    156161                                        complete: callback && function() {
    157                                                 callback.call( elem, targ, settings );
     162                                                callback.call(elem, targ, settings);
    158163                                        }
    159164                                });
    160                                 $elem.animate( attr, opts );
     165                                $elem.animate(attr, opts);
    161166                        }
    162167                });
     
    167172        $scrollTo.max = function(elem, axis) {
    168173                var Dim = axis === 'x' ? 'Width' : 'Height',
    169                         scroll = 'scroll' + Dim;
    170 
    171                 if ( ! isWin( elem )) {
    172                         return elem[scroll] - $( elem )[Dim.toLowerCase()](); }
     174                        scroll = 'scroll'+Dim;
     175
     176                if (!isWin(elem))
     177                        return elem[scroll] - $(elem)[Dim.toLowerCase()]();
    173178
    174179                var size = 'client' + Dim,
     
    177182                        body = doc.body;
    178183
    179                 return Math.max( html[scroll], body[scroll] ) - Math.min( html[size], body[size] );
     184                return Math.max(html[scroll], body[scroll]) - Math.min(html[size], body[size]);
    180185        };
    181186
    182187        function both(val) {
    183                 return $.isFunction( val ) || $.isPlainObject( val ) ? val : { top:val, left:val };
     188                return isFunction(val) || $.isPlainObject(val) ? val : { top:val, left:val };
    184189        }
    185190
    186191        // Add special hooks so that window scroll properties can be animated
    187         $.Tween.propHooks.scrollLeft = $.Tween.propHooks.scrollTop = {
     192        $.Tween.propHooks.scrollLeft =
     193        $.Tween.propHooks.scrollTop = {
    188194                get: function(t) {
    189                         return $( t.elem )[t.prop]();
     195                        return $(t.elem)[t.prop]();
    190196                },
    191197                set: function(t) {
    192                         var curr = this.get( t );
     198                        var curr = this.get(t);
    193199                        // If interrupt is true and user scrolled, stop animating
    194200                        if (t.options.interrupt && t._last && t._last !== curr) {
    195                                 return $( t.elem ).stop();
    196                         }
    197                         var next = Math.round( t.now );
     201                                return $(t.elem).stop();
     202                        }
     203                        var next = Math.round(t.now);
    198204                        // Don't waste CPU
    199205                        // Browsers don't render floating point scroll
    200206                        if (curr !== next) {
    201                                 $( t.elem )[t.prop](next);
    202                                 t._last = this.get( t );
     207                                $(t.elem)[t.prop](next);
     208                                t._last = this.get(t);
    203209                        }
    204210                }
  • trunk/src/wp-content/themes/twentyseventeen/functions.php

    r53418 r54374  
    499499        wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '20190121', true );
    500500
    501         wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true );
     501        wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.3', true );
    502502
    503503        wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n );
Note: See TracChangeset for help on using the changeset viewer.