X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/00dbffaf1593b0ac719d98f00839221a9ca52133..refs/tags/wordpress-3.8:/wp-includes/js/media-editor.js diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index 15eff8da..75b1c570 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -1,3 +1,5 @@ +/* global getUserSetting, tinymce, QTags, wpActiveEditor */ + // WordPress, TinyMCE, and Media // ----------------------------- (function($){ @@ -45,7 +47,7 @@ props.title = props.title || attachment.title; link = props.link || defaultProps.link || getUserSetting( 'urlbutton', 'file' ); - if ( 'file' === link ) + if ( 'file' === link || 'embed' === link ) linkUrl = attachment.url; else if ( 'post' === link ) linkUrl = attachment.link; @@ -66,7 +68,8 @@ src: size.url, captionId: 'attachment_' + attachment.id }); - + } else if ( 'video' === attachment.type || 'audio' === attachment.type ) { + _.extend( props, _.pick( attachment, 'title', 'type', 'icon', 'mime' ) ); // Format properties for non-images. } else { props.title = props.title || attachment.filename; @@ -95,6 +98,48 @@ return wp.html.string( options ); }, + audio: function( props, attachment ) { + return wp.media.string._audioVideo( 'audio', props, attachment ); + }, + + video: function( props, attachment ) { + return wp.media.string._audioVideo( 'video', props, attachment ); + }, + + _audioVideo: function( type, props, attachment ) { + var shortcode, html, extension; + + props = wp.media.string.props( props, attachment ); + if ( props.link !== 'embed' ) + return wp.media.string.link( props ); + + shortcode = {}; + + if ( 'video' === type ) { + if ( attachment.width ) + shortcode.width = attachment.width; + + if ( attachment.height ) + shortcode.height = attachment.height; + } + + extension = attachment.filename.split('.').pop(); + + if ( _.contains( wp.media.view.settings.embedExts, extension ) ) { + shortcode[extension] = attachment.url; + } else { + // Render unsupported audio and video files as links. + return wp.media.string.link( props ); + } + + html = wp.shortcode.string({ + tag: type, + attrs: shortcode + }); + + return html; + }, + image: function( props, attachment ) { var img = {}, options, classes, shortcode, html; @@ -102,7 +147,7 @@ props = wp.media.string.props( props, attachment ); classes = props.classes || []; - img.src = props.url; + img.src = typeof attachment !== 'undefined' ? attachment.url : props.url; _.extend( img, _.pick( props, 'width', 'height', 'alt' ) ); // Only assign the align class to the image if we're not printing @@ -170,6 +215,7 @@ icontag: 'dt', captiontag: 'dd', columns: '3', + link: 'post', size: 'thumbnail', orderby: 'menu_order ID' }, @@ -192,6 +238,9 @@ args.perPage = -1; // Mark the `orderby` override attribute. + if( undefined !== attrs.orderby ) + attrs._orderByField = attrs.orderby; + if ( 'rand' === attrs.orderby ) attrs._orderbyRandom = true; @@ -239,9 +288,15 @@ attrs.id = props.uploadedTo; // Check if the gallery is randomly ordered. + delete attrs.orderby; + if ( attrs._orderbyRandom ) attrs.orderby = 'rand'; + else if ( attrs._orderByField && attrs._orderByField != 'rand' ) + attrs.orderby = attrs._orderByField; + delete attrs._orderbyRandom; + delete attrs._orderByField; // If the `ids` attribute is set and `orderby` attribute // is the default value, clear it for cleaner output. @@ -449,7 +504,7 @@ add: function( id, options ) { var workflow = this.get( id ); - if ( workflow ) + if ( workflow ) // only add once: if exists return existing return workflow; workflow = workflows[ id ] = wp.media( _.defaults( options || {}, { @@ -471,7 +526,7 @@ var display = state.display( attachment ).toJSON(); return this.send.attachment( display, attachment.toJSON() ); }, this ) ).done( function() { - wp.media.editor.insert( _.toArray( arguments ).join("\n\n") ); + wp.media.editor.insert( _.toArray( arguments ).join('\n\n') ); }); }, this ); @@ -575,7 +630,10 @@ if ( props[ prop ] ) options[ option ] = props[ prop ]; }); - + } else if ( 'video' === attachment.type ) { + html = wp.media.string.video( props, attachment ); + } else if ( 'audio' === attachment.type ) { + html = wp.media.string.audio( props, attachment ); } else { html = wp.media.string.link( props ); options.post_title = props.title; @@ -600,9 +658,11 @@ } }, - open: function( id ) { + open: function( id, options ) { var workflow, editor; + options = options || {}; + id = this.id( id ); // Save a bookmark of the caret position in IE. @@ -617,9 +677,9 @@ workflow = this.get( id ); - // Initialize the editor's workflow if we haven't yet. - if ( ! workflow ) - workflow = this.add( id ); + // Redo workflow if state has changed + if ( ! workflow || ( workflow.options && options.state !== workflow.options.state ) ) + workflow = this.add( id, options ); return workflow.open(); }, @@ -627,7 +687,13 @@ init: function() { $(document.body).on( 'click', '.insert-media', function( event ) { var $this = $(this), - editor = $this.data('editor'); + editor = $this.data('editor'), + options = { + frame: 'post', + state: 'insert', + title: wp.media.view.l10n.addMedia, + multiple: true + }; event.preventDefault(); @@ -638,7 +704,12 @@ // See: http://core.trac.wordpress.org/ticket/22445 $this.blur(); - wp.media.editor.open( editor ); + if ( $this.hasClass( 'gallery' ) ) { + options.state = 'gallery'; + options.title = wp.media.view.l10n.createGalleryTitle; + } + + wp.media.editor.open( editor, options ); }); } };