WordPress.org

Make WordPress Core

Changeset 27271


Ignore:
Timestamp:
02/25/2014 07:52:57 PM (8 years ago)
Author:
nacin
Message:

Update the Masonry JavaScript library to version 3.

The new script handle is 'masonry'. The old 'jquery-masonry' handle is the official shiv that sits on top of the v3 library. While v3 no longer depends on jQuery, a theme or plugin may have bee
n implicitly loading jQuery though Masonry, rather than additionally declaring it as a dependency for themselves. Thus, the shiv is separate.

Themes should switch to 'masonry' and declare jQuery as a dependency on their own if they need it. Upgrade guide: http://masonry.desandro.com/appendix.html#upgrading-from-v2. imagesLoaded remai
ns included with Masonry here.

props shelob9.
fixes #25351.

Location:
trunk/src/wp-includes
Files:
1 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/jquery/jquery.masonry.js

    r27264 r27271  
    1 /**
    2  * jQuery Masonry v2.1.05
    3  * A dynamic layout plugin for jQuery
    4  * The flip-side of CSS Floats
     1/*!
     2 * Masonry v2 shim
     3 * to maintain backwards compatibility
     4 * as of Masonry v3.1.2
     5 *
     6 * Cascading grid layout library
    57 * http://masonry.desandro.com
    6  *
    7  * Licensed under the MIT license.
    8  * Copyright 2012 David DeSandro
     8 * MIT License
     9 * by David DeSandro
    910 */
    10 (function(a,b,c){"use strict";var d=b.event,e;d.special.smartresize={setup:function(){b(this).bind("resize",d.special.smartresize.handler)},teardown:function(){b(this).unbind("resize",d.special.smartresize.handler)},handler:function(a,c){var d=this,f=arguments;a.type="smartresize",e&&clearTimeout(e),e=setTimeout(function(){b.event.handle.apply(d,f)},c==="execAsap"?0:100)}},b.fn.smartresize=function(a){return a?this.bind("smartresize",a):this.trigger("smartresize",["execAsap"])},b.Mason=function(a,c){this.element=b(c),this._create(a),this._init()},b.Mason.settings={isResizable:!0,isAnimated:!1,animationOptions:{queue:!1,duration:500},gutterWidth:0,isRTL:!1,isFitWidth:!1,containerStyle:{position:"relative"}},b.Mason.prototype={_filterFindBricks:function(a){var b=this.options.itemSelector;return b?a.filter(b).add(a.find(b)):a},_getBricks:function(a){var b=this._filterFindBricks(a).css({position:"absolute"}).addClass("masonry-brick");return b},_create:function(c){this.options=b.extend(!0,{},b.Mason.settings,c),this.styleQueue=[];var d=this.element[0].style;this.originalStyle={height:d.height||""};var e=this.options.containerStyle;for(var f in e)this.originalStyle[f]=d[f]||"";this.element.css(e),this.horizontalDirection=this.options.isRTL?"right":"left",this.offset={x:parseInt(this.element.css("padding-"+this.horizontalDirection),10),y:parseInt(this.element.css("padding-top"),10)},this.isFluid=this.options.columnWidth&&typeof this.options.columnWidth=="function";var g=this;setTimeout(function(){g.element.addClass("masonry")},0),this.options.isResizable&&b(a).bind("smartresize.masonry",function(){g.resize()}),this.reloadItems()},_init:function(a){this._getColumns(),this._reLayout(a)},option:function(a,c){b.isPlainObject(a)&&(this.options=b.extend(!0,this.options,a))},layout:function(a,b){for(var c=0,d=a.length;c<d;c++)this._placeBrick(a[c]);var e={};e.height=Math.max.apply(Math,this.colYs);if(this.options.isFitWidth){var f=0;c=this.cols;while(--c){if(this.colYs[c]!==0)break;f++}e.width=(this.cols-f)*this.columnWidth-this.options.gutterWidth}this.styleQueue.push({$el:this.element,style:e});var g=this.isLaidOut?this.options.isAnimated?"animate":"css":"css",h=this.options.animationOptions,i;for(c=0,d=this.styleQueue.length;c<d;c++)i=this.styleQueue[c],i.$el[g](i.style,h);this.styleQueue=[],b&&b.call(a),this.isLaidOut=!0},_getColumns:function(){var a=this.options.isFitWidth?this.element.parent():this.element,b=a.width();this.columnWidth=this.isFluid?this.options.columnWidth(b):this.options.columnWidth||this.$bricks.outerWidth(!0)||b,this.columnWidth+=this.options.gutterWidth,this.cols=Math.floor((b+this.options.gutterWidth)/this.columnWidth),this.cols=Math.max(this.cols,1)},_placeBrick:function(a){var c=b(a),d,e,f,g,h;d=Math.ceil(c.outerWidth(!0)/this.columnWidth),d=Math.min(d,this.cols);if(d===1)f=this.colYs;else{e=this.cols+1-d,f=[];for(h=0;h<e;h++)g=this.colYs.slice(h,h+d),f[h]=Math.max.apply(Math,g)}var i=Math.min.apply(Math,f),j=0;for(var k=0,l=f.length;k<l;k++)if(f[k]===i){j=k;break}var m={top:i+this.offset.y};m[this.horizontalDirection]=this.columnWidth*j+this.offset.x,this.styleQueue.push({$el:c,style:m});var n=i+c.outerHeight(!0),o=this.cols+1-l;for(k=0;k<o;k++)this.colYs[j+k]=n},resize:function(){var a=this.cols;this._getColumns(),(this.isFluid||this.cols!==a)&&this._reLayout()},_reLayout:function(a){var b=this.cols;this.colYs=[];while(b--)this.colYs.push(0);this.layout(this.$bricks,a)},reloadItems:function(){this.$bricks=this._getBricks(this.element.children())},reload:function(a){this.reloadItems(),this._init(a)},appended:function(a,b,c){if(b){this._filterFindBricks(a).css({top:this.element.height()});var d=this;setTimeout(function(){d._appended(a,c)},1)}else this._appended(a,c)},_appended:function(a,b){var c=this._getBricks(a);this.$bricks=this.$bricks.add(c),this.layout(c,b)},remove:function(a){this.$bricks=this.$bricks.not(a),a.remove()},destroy:function(){this.$bricks.removeClass("masonry-brick").each(function(){this.style.position="",this.style.top="",this.style.left=""});var c=this.element[0].style;for(var d in this.originalStyle)c[d]=this.originalStyle[d];this.element.unbind(".masonry").removeClass("masonry").removeData("masonry"),b(a).unbind(".masonry")}},b.fn.imagesLoaded=function(a){function h(){a.call(c,d)}function i(a){var c=a.target;c.src!==f&&b.inArray(c,g)===-1&&(g.push(c),--e<=0&&(setTimeout(h),d.unbind(".imagesLoaded",i)))}var c=this,d=c.find("img").add(c.filter("img")),e=d.length,f="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==",g=[];return e||h(),d.bind("load.imagesLoaded error.imagesLoaded",i).each(function(){var a=this.src;this.src=f,this.src=a}),c};var f=function(b){a.console&&a.console.error(b)};b.fn.masonry=function(a){if(typeof a=="string"){var c=Array.prototype.slice.call(arguments,1);this.each(function(){var d=b.data(this,"masonry");if(!d){f("cannot call methods on masonry prior to initialization; attempted to call method '"+a+"'");return}if(!b.isFunction(d[a])||a.charAt(0)==="_"){f("no such method '"+a+"' for masonry instance");return}d[a].apply(d,c)})}else this.each(function(){var c=b.data(this,"masonry");c?(c.option(a||{}),c._init()):b.data(this,"masonry",new b.Mason(a,this))});return this}})(window,jQuery);
     11( function( window ) {
     12
     13  var Masonry = window.Masonry;
     14
     15  Masonry.prototype._remapV2Options = function() {
     16    // map v2 options to v3 equivalents
     17    this._remapOption( 'gutterWidth', 'gutter' );
     18    this._remapOption( 'isResizable', 'isResizeBound' );
     19    this._remapOption( 'isRTL', 'isOriginLeft', function( opt ) {
     20      return !opt;
     21    });
     22
     23    // override transitionDuration with isAnimated
     24    var isAniOption = this.options.isAnimated;
     25    if ( isAniOption !== undefined ) {
     26      this.options.transitionDuration = isAniOption ?
     27        Masonry.prototype.options.transitionDuration : 0;
     28    }
     29
     30    if ( isAniOption === undefined || isAniOption ) {
     31      // use animation Duration option in place of transitionDuration
     32      var aniOptions = this.options.animationOptions;
     33      var aniDuration = aniOptions && aniOptions.duration;
     34      if ( aniDuration ) {
     35        this.options.transitionDuration = typeof aniDuration === 'string' ?
     36          aniDuration : aniDuration + 'ms';
     37      }
     38    }
     39  };
     40
     41  Masonry.prototype._remapOption = function( from, to, munge ) {
     42    var fromOption = this.options[ from ];
     43    if ( fromOption !== undefined ) {
     44      this.options[ to ] = munge ? munge( fromOption ) : fromOption;
     45    }
     46  };
     47
     48  // remap v2 options for necessary methods
     49
     50  var __create = Masonry.prototype._create;
     51  Masonry.prototype._create = function() {
     52    this._remapV2Options();
     53    __create.apply( this, arguments );
     54  };
     55
     56  var _layout = Masonry.prototype.layout;
     57  Masonry.prototype.layout = function() {
     58    this._remapV2Options();
     59    _layout.apply( this, arguments );
     60  };
     61
     62  var _option = Masonry.prototype.option;
     63  Masonry.prototype.option = function() {
     64    _option.apply( this, arguments );
     65    this._remapV2Options();
     66  };
     67
     68  // re-enable using function for columnWidth
     69  var _measureColumns = Masonry.prototype.measureColumns;
     70  Masonry.prototype.measureColumns = function() {
     71    var colWOpt = this.options.columnWidth;
     72    if ( colWOpt && typeof colWOpt === 'function' ) {
     73      this.getContainerWidth();
     74      this.columnWidth = colWOpt( this.containerWidth );
     75    }
     76    _measureColumns.apply( this, arguments );
     77  };
     78
     79})( window );
  • trunk/src/wp-includes/script-loader.php

    r27239 r27271  
    198198    $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), false, 1 );
    199199    $scripts->add( 'jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1 );
    200     $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry.min.js", array('jquery'), '2.1.05', 1 );
     200
     201    // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
     202    // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
     203    $scripts->add( 'masonry', "/wp-includes/js/masonry.min.js", array(), '3.1.2', 1 );
     204    $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry$suffix.js", array( 'jquery', 'masonry' ), '3.1.2', 1 );
    201205
    202206    $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20121105', 1 );
Note: See TracChangeset for help on using the changeset viewer.