X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7f1521bf193b382565eb753043c161f4cb3fcda7..b22765f41bf0b2021b9beb9120ee0ac91fa89292:/wp-includes/js/media-views.js diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 605459f4..e8a8202d 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1,6 +1,4 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o'); - this.$el.append( this.spinner[0] ); this.listenTo( this.model, 'change:url', this.updateoEmbed ); }, @@ -4545,36 +4582,56 @@ EmbedLink = wp.media.view.Settings.extend({ this.$('.embed-container').hide().find('.embed-preview').empty(); this.$( '.setting' ).hide(); - // only proceed with embed if the field contains more than 6 characters - if ( url && url.length < 6 ) { + // only proceed with embed if the field contains more than 11 characters + // Example: http://a.io is 11 chars + if ( url && ( url.length < 11 || ! url.match(/^http(s)?:\/\//) ) ) { return; } this.fetch(); - }, 600 ), + }, wp.media.controller.Embed.sensitivity ), fetch: function() { + var embed; + // check if they haven't typed in 500 ms if ( $('#embed-url-field').val() !== this.model.get('url') ) { return; } - wp.ajax.send( 'parse-embed', { - data : { + if ( this.dfd && 'pending' === this.dfd.state() ) { + this.dfd.abort(); + } + + embed = new wp.shortcode({ + tag: 'embed', + attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ), + content: this.model.get('url') + }); + + this.dfd = $.ajax({ + type: 'POST', + url: wp.ajax.settings.url, + context: this, + data: { + action: 'parse-embed', post_ID: wp.media.view.settings.post.id, - shortcode: '[embed]' + this.model.get('url') + '[/embed]' + shortcode: embed.string() } - } ) - .done( _.bind( this.renderoEmbed, this ) ) - .fail( _.bind( this.renderFail, this ) ); + }) + .done( this.renderoEmbed ) + .fail( this.renderFail ); }, - renderFail: function () { + renderFail: function ( response, status ) { + if ( 'abort' === status ) { + return; + } this.$( '.link-text' ).show(); }, renderoEmbed: function( response ) { - var html = ( response && response.body ) || ''; + var html = ( response && response.data && response.data.body ) || ''; if ( html ) { this.$('.embed-container').show().find('.embed-preview').html( html ); @@ -4586,9 +4643,7 @@ EmbedLink = wp.media.view.Settings.extend({ module.exports = EmbedLink; -},{}],39:[function(require,module,exports){ -/*globals wp, _, jQuery */ - +},{}],41:[function(require,module,exports){ /** * wp.media.view.EmbedUrl * @@ -4667,7 +4722,7 @@ EmbedUrl = View.extend({ module.exports = EmbedUrl; -},{}],40:[function(require,module,exports){ +},{}],42:[function(require,module,exports){ /** * wp.media.view.FocusManager * @@ -4713,9 +4768,7 @@ var FocusManager = wp.media.View.extend({ module.exports = FocusManager; -},{}],41:[function(require,module,exports){ -/*globals _, Backbone */ - +},{}],43:[function(require,module,exports){ /** * wp.media.view.Frame * @@ -4881,9 +4934,7 @@ _.extend( Frame.prototype, wp.media.controller.StateMachine.prototype ); module.exports = Frame; -},{}],42:[function(require,module,exports){ -/*globals wp */ - +},{}],44:[function(require,module,exports){ /** * wp.media.view.MediaFrame.ImageDetails * @@ -5060,9 +5111,7 @@ ImageDetails = Select.extend({ module.exports = ImageDetails; -},{}],43:[function(require,module,exports){ -/*globals wp, _ */ - +},{}],45:[function(require,module,exports){ /** * wp.media.view.MediaFrame.Post * @@ -5797,9 +5846,7 @@ Post = Select.extend({ module.exports = Post; -},{}],44:[function(require,module,exports){ -/*globals wp, _ */ - +},{}],46:[function(require,module,exports){ /** * wp.media.view.MediaFrame.Select * @@ -5970,7 +6017,7 @@ Select = MediaFrame.extend({ module.exports = Select; -},{}],45:[function(require,module,exports){ +},{}],47:[function(require,module,exports){ /** * wp.media.view.Iframe * @@ -5994,9 +6041,7 @@ var Iframe = wp.media.View.extend({ module.exports = Iframe; -},{}],46:[function(require,module,exports){ -/*globals wp, _, jQuery */ - +},{}],48:[function(require,module,exports){ /** * wp.media.view.ImageDetails * @@ -6164,7 +6209,7 @@ ImageDetails = AttachmentDisplay.extend({ module.exports = ImageDetails; -},{}],47:[function(require,module,exports){ +},{}],49:[function(require,module,exports){ /** * wp.media.view.Label * @@ -6190,9 +6235,7 @@ var Label = wp.media.View.extend({ module.exports = Label; -},{}],48:[function(require,module,exports){ -/*globals wp, _, jQuery */ - +},{}],50:[function(require,module,exports){ /** * wp.media.view.MediaFrame * @@ -6439,9 +6482,7 @@ _.each(['open','close','attach','detach','escape'], function( method ) { module.exports = MediaFrame; -},{}],49:[function(require,module,exports){ -/*globals jQuery */ - +},{}],51:[function(require,module,exports){ /** * wp.media.view.MenuItem * @@ -6513,7 +6554,7 @@ MenuItem = wp.media.View.extend({ module.exports = MenuItem; -},{}],50:[function(require,module,exports){ +},{}],52:[function(require,module,exports){ /** * wp.media.view.Menu * @@ -6630,9 +6671,7 @@ Menu = PriorityList.extend({ module.exports = Menu; -},{}],51:[function(require,module,exports){ -/*globals wp, _, jQuery */ - +},{}],53:[function(require,module,exports){ /** * wp.media.view.Modal * @@ -6845,9 +6884,7 @@ Modal = wp.media.View.extend({ module.exports = Modal; -},{}],52:[function(require,module,exports){ -/*globals _, Backbone */ - +},{}],54:[function(require,module,exports){ /** * wp.media.view.PriorityList * @@ -6944,7 +6981,7 @@ var PriorityList = wp.media.View.extend({ module.exports = PriorityList; -},{}],53:[function(require,module,exports){ +},{}],55:[function(require,module,exports){ /** * wp.media.view.RouterItem * @@ -6968,9 +7005,7 @@ var RouterItem = wp.media.view.MenuItem.extend({ module.exports = RouterItem; -},{}],54:[function(require,module,exports){ -/*globals wp */ - +},{}],56:[function(require,module,exports){ /** * wp.media.view.Router * @@ -7007,9 +7042,7 @@ Router = Menu.extend({ module.exports = Router; -},{}],55:[function(require,module,exports){ -/*globals wp */ - +},{}],57:[function(require,module,exports){ /** * wp.media.view.Search * @@ -7057,9 +7090,7 @@ Search = wp.media.View.extend({ module.exports = Search; -},{}],56:[function(require,module,exports){ -/*globals wp, _, Backbone */ - +},{}],58:[function(require,module,exports){ /** * wp.media.view.Selection * @@ -7142,9 +7173,7 @@ Selection = wp.media.View.extend({ module.exports = Selection; -},{}],57:[function(require,module,exports){ -/*globals _, Backbone */ - +},{}],59:[function(require,module,exports){ /** * wp.media.view.Settings * @@ -7265,9 +7294,7 @@ Settings = View.extend({ module.exports = Settings; -},{}],58:[function(require,module,exports){ -/*globals wp, _ */ - +},{}],60:[function(require,module,exports){ /** * wp.media.view.Settings.AttachmentDisplay * @@ -7361,9 +7388,7 @@ AttachmentDisplay = Settings.extend({ module.exports = AttachmentDisplay; -},{}],59:[function(require,module,exports){ -/*globals wp */ - +},{}],61:[function(require,module,exports){ /** * wp.media.view.Settings.Gallery * @@ -7380,9 +7405,7 @@ var Gallery = wp.media.view.Settings.extend({ module.exports = Gallery; -},{}],60:[function(require,module,exports){ -/*globals wp */ - +},{}],62:[function(require,module,exports){ /** * wp.media.view.Settings.Playlist * @@ -7399,7 +7422,7 @@ var Playlist = wp.media.view.Settings.extend({ module.exports = Playlist; -},{}],61:[function(require,module,exports){ +},{}],63:[function(require,module,exports){ /** * wp.media.view.Sidebar * @@ -7415,9 +7438,106 @@ var Sidebar = wp.media.view.PriorityList.extend({ module.exports = Sidebar; -},{}],62:[function(require,module,exports){ -/*globals _ */ +},{}],64:[function(require,module,exports){ +/** + * wp.media.view.SiteIconCropper + * + * Uses the imgAreaSelect plugin to allow a user to crop a Site Icon. + * + * Takes imgAreaSelect options from + * wp.customize.SiteIconControl.calculateImageSelectOptions. + * + * @class + * @augments wp.media.view.Cropper + * @augments wp.media.View + * @augments wp.Backbone.View + * @augments Backbone.View + */ +var View = wp.media.view, + SiteIconCropper; + +SiteIconCropper = View.Cropper.extend({ + className: 'crop-content site-icon', + + ready: function () { + View.Cropper.prototype.ready.apply( this, arguments ); + + this.$( '.crop-image' ).on( 'load', _.bind( this.addSidebar, this ) ); + }, + + addSidebar: function() { + this.sidebar = new wp.media.view.Sidebar({ + controller: this.controller + }); + + this.sidebar.set( 'preview', new wp.media.view.SiteIconPreview({ + controller: this.controller, + attachment: this.options.attachment + }) ); + this.controller.cropperView.views.add( this.sidebar ); + } +}); + +module.exports = SiteIconCropper; + +},{}],65:[function(require,module,exports){ +/** + * wp.media.view.SiteIconPreview + * + * Shows a preview of the Site Icon as a favicon and app icon while cropping. + * + * @class + * @augments wp.media.View + * @augments wp.Backbone.View + * @augments Backbone.View + */ +var View = wp.media.View, + $ = jQuery, + SiteIconPreview; + +SiteIconPreview = View.extend({ + className: 'site-icon-preview', + template: wp.template( 'site-icon-preview' ), + + ready: function() { + this.controller.imgSelect.setOptions({ + onInit: this.updatePreview, + onSelectChange: this.updatePreview + }); + }, + + prepare: function() { + return { + url: this.options.attachment.get( 'url' ) + }; + }, + + updatePreview: function( img, coords ) { + var rx = 64 / coords.width, + ry = 64 / coords.height, + preview_rx = 16 / coords.width, + preview_ry = 16 / coords.height; + + $( '#preview-app-icon' ).css({ + width: Math.round(rx * this.imageWidth ) + 'px', + height: Math.round(ry * this.imageHeight ) + 'px', + marginLeft: '-' + Math.round(rx * coords.x1) + 'px', + marginTop: '-' + Math.round(ry * coords.y1) + 'px' + }); + + $( '#preview-favicon' ).css({ + width: Math.round( preview_rx * this.imageWidth ) + 'px', + height: Math.round( preview_ry * this.imageHeight ) + 'px', + marginLeft: '-' + Math.round( preview_rx * coords.x1 ) + 'px', + marginTop: '-' + Math.floor( preview_ry* coords.y1 ) + 'px' + }); + } +}); + +module.exports = SiteIconPreview; + +},{}],66:[function(require,module,exports){ /** * wp.media.view.Spinner * @@ -7452,9 +7572,7 @@ var Spinner = wp.media.View.extend({ module.exports = Spinner; -},{}],63:[function(require,module,exports){ -/*globals _, Backbone */ - +},{}],67:[function(require,module,exports){ /** * wp.media.view.Toolbar * @@ -7614,9 +7732,7 @@ Toolbar = View.extend({ module.exports = Toolbar; -},{}],64:[function(require,module,exports){ -/*globals wp, _ */ - +},{}],68:[function(require,module,exports){ /** * wp.media.view.Toolbar.Embed * @@ -7653,9 +7769,7 @@ Embed = Select.extend({ module.exports = Embed; -},{}],65:[function(require,module,exports){ -/*globals wp, _ */ - +},{}],69:[function(require,module,exports){ /** * wp.media.view.Toolbar.Select * @@ -7725,12 +7839,10 @@ Select = Toolbar.extend({ module.exports = Select; -},{}],66:[function(require,module,exports){ -/*globals wp, _, jQuery */ - +},{}],70:[function(require,module,exports){ /** - * Creates a dropzone on WP editor instances (elements with .wp-editor-wrap - * or #wp-fullscreen-body) and relays drag'n'dropped files to a media workflow. + * Creates a dropzone on WP editor instances (elements with .wp-editor-wrap) + * and relays drag'n'dropped files to a media workflow. * * wp.media.view.EditorUploader * @@ -7779,6 +7891,10 @@ EditorUploader = View.extend({ this.$document.on( 'dragstart dragend drop', _.bind( function( event ) { this.localDrag = event.type === 'dragstart'; + + if ( event.type === 'drop' ) { + this.containerDragleave(); + } }, this ) ); this.initialized = true; @@ -7837,7 +7953,7 @@ EditorUploader = View.extend({ } View.prototype.render.apply( this, arguments ); - $( '.wp-editor-wrap, #wp-fullscreen-body' ).each( _.bind( this.attach, this ) ); + $( '.wp-editor-wrap' ).each( _.bind( this.attach, this ) ); return this; }, @@ -7856,7 +7972,7 @@ EditorUploader = View.extend({ * @param {jQuery.Event} event The 'drop' event. */ drop: function( event ) { - var $wrap = null, uploadView; + var $wrap, uploadView; this.containerDragleave( event ); this.dropzoneDragleave( event ); @@ -7873,13 +7989,15 @@ EditorUploader = View.extend({ } if ( ! this.workflow ) { - this.workflow = wp.media.editor.open( 'content', { + this.workflow = wp.media.editor.open( window.wpActiveEditor, { frame: 'post', state: 'insert', title: l10n.addMedia, multiple: true }); + uploadView = this.workflow.uploader; + if ( uploadView.uploader && uploadView.uploader.ready ) { this.addFiles.apply( this ); } else { @@ -7946,9 +8064,7 @@ EditorUploader = View.extend({ module.exports = EditorUploader; -},{}],67:[function(require,module,exports){ -/*globals wp, _ */ - +},{}],71:[function(require,module,exports){ /** * wp.media.view.UploaderInline * @@ -8079,9 +8195,7 @@ UploaderInline = View.extend({ module.exports = UploaderInline; -},{}],68:[function(require,module,exports){ -/*globals wp */ - +},{}],72:[function(require,module,exports){ /** * wp.media.view.UploaderStatusError * @@ -8097,9 +8211,7 @@ var UploaderStatusError = wp.media.View.extend({ module.exports = UploaderStatusError; -},{}],69:[function(require,module,exports){ -/*globals wp, _ */ - +},{}],73:[function(require,module,exports){ /** * wp.media.view.UploaderStatus * @@ -8206,7 +8318,7 @@ UploaderStatus = View.extend({ * @returns {string} */ filename: function( filename ) { - return wp.media.truncate( _.escape( filename ), 24 ); + return _.escape( filename ); }, /** * @param {Backbone.Model} error @@ -8237,9 +8349,7 @@ UploaderStatus = View.extend({ module.exports = UploaderStatus; -},{}],70:[function(require,module,exports){ -/*globals wp, _, jQuery */ - +},{}],74:[function(require,module,exports){ /** * wp.media.view.UploaderWindow * @@ -8350,9 +8460,7 @@ UploaderWindow = wp.media.View.extend({ module.exports = UploaderWindow; -},{}],71:[function(require,module,exports){ -/*globals wp */ - +},{}],75:[function(require,module,exports){ /** * wp.media.View * @@ -8418,4 +8526,4 @@ var View = wp.Backbone.View.extend({ module.exports = View; -},{}]},{},[17]); +},{}]},{},[19]);