Make WordPress Core

source: trunk/src/js/media/views/embed/url.js

Last change on this file was 54228, checked in by joedolson, 3 years ago

Media: Set https as placeholder for embedding media from URL.

Change the "Insert from URL" field in the media library to use a placeholder suggesting the https:// protocol instead of a value attribute with http://.

Props Presskopp, adamsilverstein, joyously, thijso, joedolson, costdev.
Fixes #53404.

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1var View = wp.media.View,
2        $ = jQuery,
3        l10n = wp.media.view.l10n,
4        EmbedUrl;
5
6/**
7 * wp.media.view.EmbedUrl
8 *
9 * @memberOf wp.media.view
10 *
11 * @class
12 * @augments wp.media.View
13 * @augments wp.Backbone.View
14 * @augments Backbone.View
15 */
16EmbedUrl = View.extend(/** @lends wp.media.view.EmbedUrl.prototype */{
17        tagName:   'span',
18        className: 'embed-url',
19
20        events: {
21                'input': 'url'
22        },
23
24        initialize: function() {
25                this.$input = $( '<input id="embed-url-field" type="url" />' )
26                        .attr( 'aria-label', l10n.insertFromUrlTitle )
27                        .val( this.model.get('url') );
28                this.input = this.$input[0];
29
30                this.spinner = $('<span class="spinner" />')[0];
31                this.$el.append([ this.input, this.spinner ]);
32
33                this.listenTo( this.model, 'change:url', this.render );
34
35                if ( this.model.get( 'url' ) ) {
36                        _.delay( _.bind( function () {
37                                this.model.trigger( 'change:url' );
38                        }, this ), 500 );
39                }
40        },
41        /**
42         * @return {wp.media.view.EmbedUrl} Returns itself to allow chaining.
43         */
44        render: function() {
45                var $input = this.$input;
46
47                if ( $input.is(':focus') ) {
48                        return;
49                }
50
51                if ( this.model.get( 'url' ) ) {
52                        this.input.value = this.model.get('url');
53                } else {
54                        this.input.setAttribute( 'placeholder', 'https://' );
55                }
56
57                /**
58                 * Call `render` directly on parent class with passed arguments
59                 */
60                View.prototype.render.apply( this, arguments );
61                return this;
62        },
63
64        url: function( event ) {
65                var url = event.target.value || '';
66                this.model.set( 'url', url.trim() );
67        }
68});
69
70module.exports = EmbedUrl;
Note: See TracBrowser for help on using the repository browser.