Ticket #22714: 22714.embed.diff

File 22714.embed.diff, 2.7 KB (added by koopersmith, 6 months ago)
Line 
1Index: wp-includes/js/media-views.js
2===================================================================
3--- wp-includes/js/media-views.js       (revision 23026)
4+++ wp-includes/js/media-views.js       (working copy)
5@@ -744,6 +744,7 @@
6                        this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity );
7                        this.props = new Backbone.Model({ url: '' });
8                        this.props.on( 'change:url', this.debouncedScan, this );
9+                       this.props.on( 'change:url', this.refresh, this );
10                        this.on( 'scan', this.scanImage, this );
11                },
12 
13@@ -774,11 +775,15 @@
14                        image.src = url;
15                },
16 
17+               refresh: function() {
18+                       this.frame.toolbar.get().refresh();
19+               },
20+
21                reset: function() {
22                        this.props = new Backbone.Model({ url: '' });
23 
24-                       if ( this.id === this.frame.state().id )
25-                               this.frame.toolbar.get().refresh();
26+                       if ( this.active )
27+                               this.refresh();
28                }
29        });
30 
31@@ -2208,13 +2213,17 @@
32                        if ( ! this.options.silent )
33                                this.render();
34 
35-                       selection.on( 'add remove reset', this.refresh, this );
36-                       library.on( 'add remove reset', this.refresh, this );
37+                       if ( selection )
38+                               selection.on( 'add remove reset', this.refresh, this );
39+                       if ( library )
40+                               library.on( 'add remove reset', this.refresh, this );
41                },
42 
43                dispose: function() {
44-                       this.selection.off( null, null, this );
45-                       this.library.off( null, null, this );
46+                       if ( this.selection )
47+                               this.selection.off( null, null, this );
48+                       if ( this.library )
49+                               this.library.off( null, null, this );
50                        return media.View.prototype.dispose.apply( this, arguments );
51                },
52 
53@@ -2278,9 +2287,9 @@
54                                var requires = button.options.requires,
55                                        disabled = false;
56 
57-                               if ( requires.selection && ! selection.length )
58+                               if ( requires.selection && selection && ! selection.length )
59                                        disabled = true;
60-                               else if ( requires.library && ! library.length )
61+                               else if ( requires.library && library && ! library.length )
62                                        disabled = true;
63 
64                                button.model.set( 'disabled', disabled );
65@@ -2347,18 +2356,13 @@
66        media.view.Toolbar.Embed = media.view.Toolbar.Select.extend({
67                initialize: function() {
68                        _.defaults( this.options, {
69-                               text: l10n.insertIntoPost
70+                               text: l10n.insertIntoPost,
71+                               requires: false
72                        });
73 
74                        media.view.Toolbar.Select.prototype.initialize.apply( this, arguments );
75-                       this.controller.state().props.on( 'change:url', this.refresh, this );
76                },
77 
78-               dispose: function() {
79-                       this.controller.state().props.off( 'change:url', this.refresh, this );
80-                       media.view.Toolbar.Select.prototype.dispose.apply( this, arguments );
81-               },
82-
83                refresh: function() {
84                        var url = this.controller.state().props.get('url');
85                        this.get('select').model.set( 'disabled', ! url || /^https?:\/\/$/.test(url) );