Make WordPress Core

Changeset 31380


Ignore:
Timestamp:
02/09/2015 04:44:39 AM (8 years ago)
Author:
wonderboymusic
Message:

Bind this at calltime instead of letting self spill down into closures.

See #28510.

Location:
trunk/src/wp-includes/js/media
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media/audio-video.js

    r31379 r31380  
    131131
    132132        shortcode : function( model ) {
    133             var self = this, content;
     133            var content;
    134134
    135135            _.each( this.defaults, function( value, key ) {
     
    139139                    delete model[ key ];
    140140                }
    141             });
     141            }, this );
    142142
    143143            content = model.content;
     
    192192
    193193        shortcode : function( model ) {
    194             var self = this, content;
     194            var content;
    195195
    196196            _.each( this.defaults, function( value, key ) {
    197                 model[ key ] = self.coerce( model, key );
     197                model[ key ] = this.coerce( model, key );
    198198
    199199                if ( value === model[ key ] ) {
    200200                    delete model[ key ];
    201201                }
    202             });
     202            }, this );
    203203
    204204            content = model.content;
     
    11901190
    11911191    changeAttachment: function( attachment ) {
    1192         var self = this;
    1193 
    11941192        this.setSource( attachment );
    11951193
    11961194        this.unset( 'src' );
    11971195        _.each( _.without( wp.media.view.settings.embedExts, this.extension ), function( ext ) {
    1198             self.unset( ext );
    1199         } );
     1196            this.unset( ext );
     1197        }, this );
    12001198    }
    12011199});
     
    28322830                priority: -60,
    28332831                click: function() {
    2834                     var changed = [], removed = [], self = this,
     2832                    var changed = [], removed = [],
    28352833                        selection = this.controller.state().get( 'selection' ),
    28362834                        library = this.controller.state().get( 'library' );
     
    28732871                        selection.remove( removed );
    28742872
    2875                         $.when.apply( null, changed ).then( function() {
     2873                        $.when.apply( null, changed ).then( _.bind( function() {
    28762874                            library._requery( true );
    2877                             self.controller.trigger( 'selection:action:done' );
    2878                         } );
     2875                            this.controller.trigger( 'selection:action:done' );
     2876                        }, this ) );
    28792877                    } else {
    28802878                        this.controller.trigger( 'selection:action:done' );
     
    41464144     */
    41474145    render: function() {
    4148         var self = this;
    4149 
    41504146        AttachmentDisplay.prototype.render.apply( this, arguments );
    4151         setTimeout( function() { self.resetFocus(); }, 10 );
     4147       
     4148        setTimeout( _.bind( function() {
     4149            this.resetFocus();
     4150        }, this ), 10 );
    41524151
    41534152        this.settings = _.defaults( {
  • trunk/src/wp-includes/js/media/audio-video.manifest.js

    r31373 r31380  
    130130
    131131        shortcode : function( model ) {
    132             var self = this, content;
     132            var content;
    133133
    134134            _.each( this.defaults, function( value, key ) {
     
    138138                    delete model[ key ];
    139139                }
    140             });
     140            }, this );
    141141
    142142            content = model.content;
     
    191191
    192192        shortcode : function( model ) {
    193             var self = this, content;
     193            var content;
    194194
    195195            _.each( this.defaults, function( value, key ) {
    196                 model[ key ] = self.coerce( model, key );
     196                model[ key ] = this.coerce( model, key );
    197197
    198198                if ( value === model[ key ] ) {
    199199                    delete model[ key ];
    200200                }
    201             });
     201            }, this );
    202202
    203203            content = model.content;
  • trunk/src/wp-includes/js/media/controllers/cropper.js

    r31373 r31380  
    6868
    6969                    click: function() {
    70                         var self = this,
    71                             selection = this.controller.state().get('selection').first();
     70                        var controller = this.controller,
     71                            selection;
    7272
    73                         selection.set({cropDetails: this.controller.state().imgSelect.getSelection()});
     73                        selection = controller.state().get('selection').first();
     74                        selection.set({cropDetails: controller.state().imgSelect.getSelection()});
    7475
    7576                        this.$el.text(l10n.cropping);
    7677                        this.$el.attr('disabled', true);
    77                         this.controller.state().doCrop( selection ).done( function( croppedImage ) {
    78                             self.controller.trigger('cropped', croppedImage );
    79                             self.controller.close();
     78                       
     79                        controller.state().doCrop( selection ).done( function( croppedImage ) {
     80                            controller.trigger('cropped', croppedImage );
     81                            controller.close();
    8082                        }).fail( function() {
    81                             self.controller.trigger('content:error:crop');
     83                            controller.trigger('content:error:crop');
    8284                        });
    8385                    }
  • trunk/src/wp-includes/js/media/grid.js

    r31379 r31380  
    26642664                priority: -60,
    26652665                click: function() {
    2666                     var changed = [], removed = [], self = this,
     2666                    var changed = [], removed = [],
    26672667                        selection = this.controller.state().get( 'selection' ),
    26682668                        library = this.controller.state().get( 'library' );
     
    27052705                        selection.remove( removed );
    27062706
    2707                         $.when.apply( null, changed ).then( function() {
     2707                        $.when.apply( null, changed ).then( _.bind( function() {
    27082708                            library._requery( true );
    2709                             self.controller.trigger( 'selection:action:done' );
    2710                         } );
     2709                            this.controller.trigger( 'selection:action:done' );
     2710                        }, this ) );
    27112711                    } else {
    27122712                        this.controller.trigger( 'selection:action:done' );
     
    31993199
    32003200    save: function() {
    3201         var self = this;
    3202 
    3203         this.model.fetch().done( function() {
    3204             self.frame.content.mode( 'edit-metadata' );
    3205         });
     3201        this.model.fetch().done( _.bind( function() {
     3202            this.frame.content.mode( 'edit-metadata' );
     3203        }, this ) );
    32063204    }
    32073205});
     
    32523250
    32533251    save: function() {
    3254         var self = this,
    3255             lastState = this.controller.lastState();
    3256 
    3257         this.model.fetch().done( function() {
    3258             self.controller.setState( lastState );
    3259         });
     3252        var lastState = this.controller.lastState();
     3253
     3254        this.model.fetch().done( _.bind( function() {
     3255            this.controller.setState( lastState );
     3256        }, this ) );
    32603257    }
    32613258
     
    35613558
    35623559    createModal: function() {
    3563         var self = this;
    3564 
    35653560        // Initialize modal container view.
    35663561        if ( this.options.modal ) {
     
    35703565            });
    35713566
    3572             this.modal.on( 'open', function () {
    3573                 $( 'body' ).on( 'keydown.media-modal', _.bind( self.keyEvent, self ) );
    3574             } );
     3567            this.modal.on( 'open', _.bind( function () {
     3568                $( 'body' ).on( 'keydown.media-modal', _.bind( this.keyEvent, this ) );
     3569            }, this ) );
    35753570
    35763571            // Completely destroy the modal DOM element when closing it.
    3577             this.modal.on( 'close', function() {
    3578                 self.modal.remove();
     3572            this.modal.on( 'close', _.bind( function() {
     3573                this.modal.remove();
    35793574                $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
    35803575                // Restore the original focus item if possible
    3581                 $( 'li.attachment[data-id="' + self.model.get( 'id' ) +'"]' ).focus();
    3582                 self.resetRoute();
    3583             } );
     3576                $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus();
     3577                this.resetRoute();
     3578            }, this ) );
    35843579
    35853580            // Set this frame as the modal's content.
     
    41464141     */
    41474142    render: function() {
    4148         var self = this;
    4149 
    41504143        AttachmentDisplay.prototype.render.apply( this, arguments );
    4151         setTimeout( function() { self.resetFocus(); }, 10 );
     4144       
     4145        setTimeout( _.bind( function() {
     4146            this.resetFocus();
     4147        }, this ), 10 );
    41524148
    41534149        this.settings = _.defaults( {
  • trunk/src/wp-includes/js/media/models/post-media.js

    r31373 r31380  
    2929
    3030    changeAttachment: function( attachment ) {
    31         var self = this;
    32 
    3331        this.setSource( attachment );
    3432
    3533        this.unset( 'src' );
    3634        _.each( _.without( wp.media.view.settings.embedExts, this.extension ), function( ext ) {
    37             self.unset( ext );
    38         } );
     35            this.unset( ext );
     36        }, this );
    3937    }
    4038});
  • trunk/src/wp-includes/js/media/views.js

    r31379 r31380  
    334334
    335335                    click: function() {
    336                         var self = this,
    337                             selection = this.controller.state().get('selection').first();
    338 
    339                         selection.set({cropDetails: this.controller.state().imgSelect.getSelection()});
     336                        var controller = this.controller,
     337                            selection;
     338
     339                        selection = controller.state().get('selection').first();
     340                        selection.set({cropDetails: controller.state().imgSelect.getSelection()});
    340341
    341342                        this.$el.text(l10n.cropping);
    342343                        this.$el.attr('disabled', true);
    343                         this.controller.state().doCrop( selection ).done( function( croppedImage ) {
    344                             self.controller.trigger('cropped', croppedImage );
    345                             self.controller.close();
     344                       
     345                        controller.state().doCrop( selection ).done( function( croppedImage ) {
     346                            controller.trigger('cropped', croppedImage );
     347                            controller.close();
    346348                        }).fail( function() {
    347                             self.controller.trigger('content:error:crop');
     349                            controller.trigger('content:error:crop');
    348350                        });
    349351                    }
     
    38373839                priority: -60,
    38383840                click: function() {
    3839                     var changed = [], removed = [], self = this,
     3841                    var changed = [], removed = [],
    38403842                        selection = this.controller.state().get( 'selection' ),
    38413843                        library = this.controller.state().get( 'library' );
     
    38783880                        selection.remove( removed );
    38793881
    3880                         $.when.apply( null, changed ).then( function() {
     3882                        $.when.apply( null, changed ).then( _.bind( function() {
    38813883                            library._requery( true );
    3882                             self.controller.trigger( 'selection:action:done' );
    3883                         } );
     3884                            this.controller.trigger( 'selection:action:done' );
     3885                        }, this ) );
    38843886                    } else {
    38853887                        this.controller.trigger( 'selection:action:done' );
     
    43964398
    43974399    save: function() {
    4398         var self = this,
    4399             lastState = this.controller.lastState();
    4400 
    4401         this.model.fetch().done( function() {
    4402             self.controller.setState( lastState );
    4403         });
     4400        var lastState = this.controller.lastState();
     4401
     4402        this.model.fetch().done( _.bind( function() {
     4403            this.controller.setState( lastState );
     4404        }, this ) );
    44044405    }
    44054406
     
    46044605
    46054606    initialize: function() {
    4606         var self = this;
    4607 
    46084607        this.$input = $('<input id="embed-url-field" type="url" />').val( this.model.get('url') );
    46094608        this.input = this.$input[0];
     
    46154614
    46164615        if ( this.model.get( 'url' ) ) {
    4617             _.delay( function () {
    4618                 self.model.trigger( 'change:url' );
    4619             }, 500 );
     4616            _.delay( _.bind( function () {
     4617                this.model.trigger( 'change:url' );
     4618            }, this ), 500 );
    46204619        }
    46214620    },
     
    60706069
    60716070    render: function() {
    6072         var self = this,
    6073             args = arguments;
     6071        var args = arguments;
    60746072
    60756073        if ( this.model.attachment && 'pending' === this.model.dfd.state() ) {
    6076             this.model.dfd.done( function() {
    6077                 AttachmentDisplay.prototype.render.apply( self, args );
    6078                 self.postRender();
    6079             } ).fail( function() {
    6080                 self.model.attachment = false;
    6081                 AttachmentDisplay.prototype.render.apply( self, args );
    6082                 self.postRender();
    6083             } );
     6074            this.model.dfd
     6075                .done( _.bind( function() {
     6076                    AttachmentDisplay.prototype.render.apply( this, args );
     6077                    this.postRender();
     6078                }, this ) )
     6079                .fail( _.bind( function() {
     6080                    this.model.attachment = false;
     6081                    AttachmentDisplay.prototype.render.apply( this, args );
     6082                    this.postRender();
     6083                }, this ) );
    60846084        } else {
    60856085            AttachmentDisplay.prototype.render.apply( this, arguments );
     
    77947794     */
    77957795    initialize: function() {
    7796         var self = this;
    7797 
    77987796        this.initialized = false;
    77997797
     
    78157813        this.$document.on( 'dragleave', _.bind( this.containerDragleave, this ) );
    78167814
    7817         this.$document.on( 'dragstart dragend drop', function( event ) {
    7818             self.localDrag = event.type === 'dragstart';
    7819         });
     7815        this.$document.on( 'dragstart dragend drop', _.bind( function( event ) {
     7816            this.localDrag = event.type === 'dragstart';
     7817        }, this ) );
    78207818
    78217819        this.initialized = true;
  • trunk/src/wp-includes/js/media/views/attachments/browser.js

    r31373 r31380  
    183183                priority: -60,
    184184                click: function() {
    185                     var changed = [], removed = [], self = this,
     185                    var changed = [], removed = [],
    186186                        selection = this.controller.state().get( 'selection' ),
    187187                        library = this.controller.state().get( 'library' );
     
    224224                        selection.remove( removed );
    225225
    226                         $.when.apply( null, changed ).then( function() {
     226                        $.when.apply( null, changed ).then( _.bind( function() {
    227227                            library._requery( true );
    228                             self.controller.trigger( 'selection:action:done' );
    229                         } );
     228                            this.controller.trigger( 'selection:action:done' );
     229                        }, this ) );
    230230                    } else {
    231231                        this.controller.trigger( 'selection:action:done' );
  • trunk/src/wp-includes/js/media/views/edit-image-details.js

    r31373 r31380  
    1616
    1717    save: function() {
    18         var self = this;
    19 
    20         this.model.fetch().done( function() {
    21             self.frame.content.mode( 'edit-metadata' );
    22         });
     18        this.model.fetch().done( _.bind( function() {
     19            this.frame.content.mode( 'edit-metadata' );
     20        }, this ) );
    2321    }
    2422});
  • trunk/src/wp-includes/js/media/views/edit-image.js

    r31373 r31380  
    4242
    4343    save: function() {
    44         var self = this,
    45             lastState = this.controller.lastState();
     44        var lastState = this.controller.lastState();
    4645
    47         this.model.fetch().done( function() {
    48             self.controller.setState( lastState );
    49         });
     46        this.model.fetch().done( _.bind( function() {
     47            this.controller.setState( lastState );
     48        }, this ) );
    5049    }
    5150
  • trunk/src/wp-includes/js/media/views/embed/url.js

    r31373 r31380  
    2424
    2525    initialize: function() {
    26         var self = this;
    27 
    2826        this.$input = $('<input id="embed-url-field" type="url" />').val( this.model.get('url') );
    2927        this.input = this.$input[0];
     
    3533
    3634        if ( this.model.get( 'url' ) ) {
    37             _.delay( function () {
    38                 self.model.trigger( 'change:url' );
    39             }, 500 );
     35            _.delay( _.bind( function () {
     36                this.model.trigger( 'change:url' );
     37            }, this ), 500 );
    4038        }
    4139    },
  • trunk/src/wp-includes/js/media/views/frame/edit-attachments.js

    r31373 r31380  
    7575
    7676    createModal: function() {
    77         var self = this;
    78 
    7977        // Initialize modal container view.
    8078        if ( this.options.modal ) {
     
    8482            });
    8583
    86             this.modal.on( 'open', function () {
    87                 $( 'body' ).on( 'keydown.media-modal', _.bind( self.keyEvent, self ) );
    88             } );
     84            this.modal.on( 'open', _.bind( function () {
     85                $( 'body' ).on( 'keydown.media-modal', _.bind( this.keyEvent, this ) );
     86            }, this ) );
    8987
    9088            // Completely destroy the modal DOM element when closing it.
    91             this.modal.on( 'close', function() {
    92                 self.modal.remove();
     89            this.modal.on( 'close', _.bind( function() {
     90                this.modal.remove();
    9391                $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
    9492                // Restore the original focus item if possible
    95                 $( 'li.attachment[data-id="' + self.model.get( 'id' ) +'"]' ).focus();
    96                 self.resetRoute();
    97             } );
     93                $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus();
     94                this.resetRoute();
     95            }, this ) );
    9896
    9997            // Set this frame as the modal's content.
  • trunk/src/wp-includes/js/media/views/image-details.js

    r31373 r31380  
    5050
    5151    render: function() {
    52         var self = this,
    53             args = arguments;
     52        var args = arguments;
    5453
    5554        if ( this.model.attachment && 'pending' === this.model.dfd.state() ) {
    56             this.model.dfd.done( function() {
    57                 AttachmentDisplay.prototype.render.apply( self, args );
    58                 self.postRender();
    59             } ).fail( function() {
    60                 self.model.attachment = false;
    61                 AttachmentDisplay.prototype.render.apply( self, args );
    62                 self.postRender();
    63             } );
     55            this.model.dfd
     56                .done( _.bind( function() {
     57                    AttachmentDisplay.prototype.render.apply( this, args );
     58                    this.postRender();
     59                }, this ) )
     60                .fail( _.bind( function() {
     61                    this.model.attachment = false;
     62                    AttachmentDisplay.prototype.render.apply( this, args );
     63                    this.postRender();
     64                }, this ) );
    6465        } else {
    6566            AttachmentDisplay.prototype.render.apply( this, arguments );
  • trunk/src/wp-includes/js/media/views/media-details.js

    r31373 r31380  
    111111     */
    112112    render: function() {
    113         var self = this;
    114 
    115113        AttachmentDisplay.prototype.render.apply( this, arguments );
    116         setTimeout( function() { self.resetFocus(); }, 10 );
     114       
     115        setTimeout( _.bind( function() {
     116            this.resetFocus();
     117        }, this ), 10 );
    117118
    118119        this.settings = _.defaults( {
  • trunk/src/wp-includes/js/media/views/uploader/editor.js

    r31373 r31380  
    3131     */
    3232    initialize: function() {
    33         var self = this;
    34 
    3533        this.initialized = false;
    3634
     
    5250        this.$document.on( 'dragleave', _.bind( this.containerDragleave, this ) );
    5351
    54         this.$document.on( 'dragstart dragend drop', function( event ) {
    55             self.localDrag = event.type === 'dragstart';
    56         });
     52        this.$document.on( 'dragstart dragend drop', _.bind( function( event ) {
     53            this.localDrag = event.type === 'dragstart';
     54        }, this ) );
    5755
    5856        this.initialized = true;
Note: See TracChangeset for help on using the changeset viewer.