]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/media-editor.js
Wordpress 3.6
[autoinstalls/wordpress.git] / wp-includes / js / media-editor.js
index 5a77d50a5a94da8243f293629e29c7435f68304e..fc497cd84dabc40d98e1fe633570859338c6508f 100644 (file)
@@ -45,7 +45,7 @@
                        props.title = props.title || attachment.title;
 
                        link = props.link || defaultProps.link || getUserSetting( 'urlbutton', 'file' );
                        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;
                                linkUrl = attachment.url;
                        else if ( 'post' === link )
                                linkUrl = attachment.link;
@@ -66,7 +66,8 @@
                                        src:       size.url,
                                        captionId: 'attachment_' + attachment.id
                                });
                                        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;
                        // Format properties for non-images.
                        } else {
                                props.title = props.title || attachment.filename;
                        return wp.html.string( options );
                },
 
                        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;
                image: function( props, attachment ) {
                        var img = {},
                                options, classes, shortcode, html;
                        props = wp.media.string.props( props, attachment );
                        classes = props.classes || [];
 
                        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
                        _.extend( img, _.pick( props, 'width', 'height', 'alt' ) );
 
                        // Only assign the align class to the image if we're not printing
                add: function( id, options ) {
                        var workflow = this.get( id );
 
                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 || {}, {
                                return workflow;
 
                        workflow = workflows[ id ] = wp.media( _.defaults( options || {}, {
                                                if ( props[ prop ] )
                                                        options[ option ] = props[ prop ];
                                        });
                                                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;
                                } else {
                                        html = wp.media.string.link( props );
                                        options.post_title = props.title;
                        }
                },
 
                        }
                },
 
-               open: function( id ) {
+               open: function( id, options ) {
                        var workflow, editor;
 
                        var workflow, editor;
 
+                       options = options || {};
+
                        id = this.id( id );
 
                        // Save a bookmark of the caret position in IE.
                        id = this.id( id );
 
                        // Save a bookmark of the caret position in IE.
 
                        workflow = this.get( id );
 
 
                        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();
                },
 
                        return workflow.open();
                },
                init: function() {
                        $(document.body).on( 'click', '.insert-media', function( event ) {
                                var $this = $(this),
                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();
 
 
                                event.preventDefault();
 
                                // See: http://core.trac.wordpress.org/ticket/22445
                                $this.blur();
 
                                // 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 );
                        });
                }
        };
                        });
                }
        };