Make WordPress Core

Changeset 28992


Ignore:
Timestamp:
07/04/2014 02:17:22 AM (11 years ago)
Author:
wonderboymusic
Message:

Make a new file: media-grid.js. This will be way more useful in later commits and help reduce churn and bloat in media-views.js.

See #24716.

Location:
trunk/src
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/upload.php

    r28682 r28992  
    2323if ( 'grid' === $mode ) {
    2424    wp_enqueue_media();
     25    wp_enqueue_script( 'media-grid' );
    2526    wp_enqueue_script( 'media' );
     27   
    2628    require_once( ABSPATH . 'wp-admin/admin-header.php' );
    2729    ?><div class="view-switch media-grid-view-switch">
  • trunk/src/wp-includes/js/media-views.js

    r28989 r28992  
    19531953            return this;
    19541954        };
    1955     });
    1956 
    1957     /**
    1958      * wp.media.view.MediaFrame.Manage
    1959      *
    1960      * A generic management frame workflow.
    1961      *
    1962      * Used in the media grid view.
    1963      *
    1964      * @constructor
    1965      * @augments wp.media.view.MediaFrame
    1966      * @augments wp.media.view.Frame
    1967      * @augments wp.media.View
    1968      * @augments wp.Backbone.View
    1969      * @augments Backbone.View
    1970      * @mixes wp.media.controller.StateMachine
    1971      */
    1972     media.view.MediaFrame.Manage = media.view.MediaFrame.extend({
    1973         /**
    1974          * @global wp.Uploader
    1975          */
    1976         initialize: function() {
    1977             _.defaults( this.options, {
    1978                 title:     l10n.mediaLibraryTitle,
    1979                 modal:     false,
    1980                 selection: [],
    1981                 library:   {},
    1982                 multiple:  false,
    1983                 state:     'library',
    1984                 uploader:  true
    1985             });
    1986 
    1987             // Ensure core and media grid view UI is enabled.
    1988             this.$el.addClass('wp-core-ui media-grid-view');
    1989 
    1990             // Force the uploader off if the upload limit has been exceeded or
    1991             // if the browser isn't supported.
    1992             if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) {
    1993                 this.options.uploader = false;
    1994             }
    1995 
    1996             // Initialize a window-wide uploader.
    1997             if ( this.options.uploader ) {
    1998                 this.uploader = new media.view.UploaderWindow({
    1999                     controller: this,
    2000                     uploader: {
    2001                         dropzone:  $('body'),
    2002                         container: $('body')
    2003                     }
    2004                 }).render();
    2005                 this.uploader.ready();
    2006                 $('body').append( this.uploader.el );
    2007 
    2008                 this.options.uploader = false;
    2009             }
    2010 
    2011             /**
    2012              * call 'initialize' directly on the parent class
    2013              */
    2014             media.view.MediaFrame.prototype.initialize.apply( this, arguments );
    2015 
    2016             // Since we're not using the default modal built into
    2017             // a media frame, append our $element to the supplied container.
    2018             this.$el.appendTo( this.options.container );
    2019 
    2020             this.createSelection();
    2021             this.createStates();
    2022             this.bindHandlers();
    2023             this.render();
    2024         },
    2025 
    2026         createSelection: function() {
    2027             var selection = this.options.selection;
    2028 
    2029             if ( ! (selection instanceof media.model.Selection) ) {
    2030                 this.options.selection = new media.model.Selection( selection, {
    2031                     multiple: this.options.multiple
    2032                 });
    2033             }
    2034 
    2035             this._selection = {
    2036                 attachments: new media.model.Attachments(),
    2037                 difference: []
    2038             };
    2039         },
    2040 
    2041         createStates: function() {
    2042             var options = this.options;
    2043 
    2044             if ( this.options.states ) {
    2045                 return;
    2046             }
    2047 
    2048             // Add the default states.
    2049             this.states.add([
    2050                 new media.controller.Library({
    2051                     library:    media.query( options.library ),
    2052                     multiple:   options.multiple,
    2053                     title:      options.title,
    2054                     priority:   20,
    2055                     toolbar:    false,
    2056                     router:     false,
    2057                     content:    'browse',
    2058                     filterable: 'mime-types'
    2059                 }),
    2060 
    2061                 new media.controller.EditImage( { model: options.editImage } )
    2062             ]);
    2063         },
    2064 
    2065         bindHandlers: function() {
    2066             this.on( 'content:create:browse', this.browseContent, this );
    2067             this.on( 'content:render:edit-image', this.editImageContent, this );
    2068         },
    2069 
    2070         /**
    2071          * Content
    2072          *
    2073          * @param {Object} content
    2074          * @this wp.media.controller.Region
    2075          */
    2076         browseContent: function( content ) {
    2077             var state = this.state();
    2078 
    2079             // Browse our library of attachments.
    2080             content.view = new media.view.AttachmentsBrowser({
    2081                 controller: this,
    2082                 collection: state.get('library'),
    2083                 selection:  state.get('selection'),
    2084                 model:      state,
    2085                 sortable:   state.get('sortable'),
    2086                 search:     state.get('searchable'),
    2087                 filters:    state.get('filterable'),
    2088                 display:    state.get('displaySettings'),
    2089                 dragInfo:   state.get('dragInfo'),
    2090                 bulkEdit:   true,
    2091 
    2092                 suggestedWidth:  state.get('suggestedWidth'),
    2093                 suggestedHeight: state.get('suggestedHeight'),
    2094 
    2095                 AttachmentView: state.get('AttachmentView')
    2096             });
    2097         },
    2098 
    2099         editImageContent: function() {
    2100             var image = this.state().get('image'),
    2101                 view = new media.view.EditImage( { model: image, controller: this } ).render();
    2102 
    2103             this.content.set( view );
    2104 
    2105             // after creating the wrapper view, load the actual editor via an ajax call
    2106             view.loadEditor();
    2107 
    2108         }
    21091955    });
    21101956
  • trunk/src/wp-includes/script-loader.php

    r28914 r28992  
    507507
    508508        $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js" );
    509 
     509       
     510        $scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 );
    510511        $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery' ), false, 1 );
    511512        did_action( 'init' ) && $scripts->localize( 'media', 'attachMediaBoxL10n', array(
Note: See TracChangeset for help on using the changeset viewer.