wp/wp-includes/js/media-editor.js
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 18:28:13 +0200
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
permissions -rw-r--r--
upgrade wordpress to 5.2.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     1
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     2
 * @output wp-includes/js/media-editor.js
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     3
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     4
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     5
/* global getUserSetting, tinymce, QTags */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     6
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
// WordPress, TinyMCE, and Media
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
// -----------------------------
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
(function($, _){
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
	 * Stores the editors' `wp.media.controller.Frame` instances.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
	 * @static
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
	var workflows = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	 * A helper mixin function to avoid truthy and falsey values being
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
	 *   passed as an input that expects booleans. If key is undefined in the map,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
	 *   but has a default value, set it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
	 * @param {object} attrs Map of props from a shortcode or settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
	 * @param {string} key The key within the passed map to check for a value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	 * @returns {mixed|undefined} The original or coerced value of key within attrs
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
	wp.media.coerce = function ( attrs, key ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
		if ( _.isUndefined( attrs[ key ] ) && ! _.isUndefined( this.defaults[ key ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
			attrs[ key ] = this.defaults[ key ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
		} else if ( 'true' === attrs[ key ] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
			attrs[ key ] = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
		} else if ( 'false' === attrs[ key ] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
			attrs[ key ] = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
		return attrs[ key ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
	};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    37
	/** @namespace wp.media.string */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	wp.media.string = {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
		 * Joins the `props` and `attachment` objects,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
		 * outputting the proper object format based on the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
		 * attachment's type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
		 * @param {Object} [props={}] Attachment details (align, link, size, etc).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
		 * @param {Object} attachment The attachment object, media version of Post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
		 * @returns {Object} Joined props
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		props: function( props, attachment ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    49
			var link, linkUrl, size, sizes,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
				defaultProps = wp.media.view.settings.defaultProps;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			props = props ? _.clone( props ) : {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
			if ( attachment && attachment.type ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
				props.type = attachment.type;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
			if ( 'image' === props.type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
				props = _.defaults( props || {}, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
					align:   defaultProps.align || getUserSetting( 'align', 'none' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
					size:    defaultProps.size  || getUserSetting( 'imgsize', 'medium' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
					url:     '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
					classes: []
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
			// All attachment-specific settings follow.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
			if ( ! attachment ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    69
				return props;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
			props.title = props.title || attachment.title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
			link = props.link || defaultProps.link || getUserSetting( 'urlbutton', 'file' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
			if ( 'file' === link || 'embed' === link ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
				linkUrl = attachment.url;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
			} else if ( 'post' === link ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
				linkUrl = attachment.link;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
			} else if ( 'custom' === link ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
				linkUrl = props.linkUrl;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
			props.linkUrl = linkUrl || '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
			// Format properties for images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
			if ( 'image' === attachment.type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
				props.classes.push( 'wp-image-' + attachment.id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
				sizes = attachment.sizes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
				size = sizes && sizes[ props.size ] ? sizes[ props.size ] : attachment;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
				_.extend( props, _.pick( attachment, 'align', 'caption', 'alt' ), {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
					width:     size.width,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
					height:    size.height,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
					src:       size.url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
					captionId: 'attachment_' + attachment.id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
			} else if ( 'video' === attachment.type || 'audio' === attachment.type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
				_.extend( props, _.pick( attachment, 'title', 'type', 'icon', 'mime' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
			// Format properties for non-images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
				props.title = props.title || attachment.filename;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
				props.rel = props.rel || 'attachment wp-att-' + attachment.id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
			return props;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
		 * Create link markup that is suitable for passing to the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
		 * @param {Object} props Attachment details (align, link, size, etc).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
		 * @param {Object} attachment The attachment object, media version of Post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
		 * @returns {string} The link markup
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		link: function( props, attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
			var options;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
			props = wp.media.string.props( props, attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
			options = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
				tag:     'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
				content: props.title,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
				attrs:   {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
					href: props.linkUrl
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
			if ( props.rel ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
				options.attrs.rel = props.rel;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
			return wp.html.string( options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
		 * Create an Audio shortcode string that is suitable for passing to the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
		 * @param {Object} props Attachment details (align, link, size, etc).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
		 * @param {Object} attachment The attachment object, media version of Post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
		 * @returns {string} The audio shortcode
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		audio: function( props, attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
			return wp.media.string._audioVideo( 'audio', props, attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
		 * Create a Video shortcode string that is suitable for passing to the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
		 * @param {Object} props Attachment details (align, link, size, etc).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
		 * @param {Object} attachment The attachment object, media version of Post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
		 * @returns {string} The video shortcode
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
		video: function( props, attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
			return wp.media.string._audioVideo( 'video', props, attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
		 * Helper function to create a media shortcode string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
		 * @access private
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
		 * @param {string} type The shortcode tag name: 'audio' or 'video'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
		 * @param {Object} props Attachment details (align, link, size, etc).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
		 * @param {Object} attachment The attachment object, media version of Post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
		 * @returns {string} The media shortcode
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
		_audioVideo: function( type, props, attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
			var shortcode, html, extension;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
			props = wp.media.string.props( props, attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
			if ( props.link !== 'embed' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
				return wp.media.string.link( props );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
			shortcode = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
			if ( 'video' === type ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
				if ( attachment.image && -1 === attachment.image.src.indexOf( attachment.icon ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
					shortcode.poster = attachment.image.src;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
				if ( attachment.width ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
					shortcode.width = attachment.width;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
				if ( attachment.height ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
					shortcode.height = attachment.height;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			extension = attachment.filename.split('.').pop();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
			if ( _.contains( wp.media.view.settings.embedExts, extension ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
				shortcode[extension] = attachment.url;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
				// Render unsupported audio and video files as links.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
				return wp.media.string.link( props );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
			html = wp.shortcode.string({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
				tag:     type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
				attrs:   shortcode
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
			return html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
		 * Create image markup, optionally with a link and/or wrapped in a caption shortcode,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
		 *  that is suitable for passing to the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
		 * @param {Object} props Attachment details (align, link, size, etc).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
		 * @param {Object} attachment The attachment object, media version of Post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
		 * @returns {string}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		image: function( props, attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
			var img = {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
				options, classes, shortcode, html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   214
			props.type = 'image';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
			props = wp.media.string.props( props, attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
			classes = props.classes || [];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
			img.src = ! _.isUndefined( attachment ) ? attachment.url : props.url;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
			_.extend( img, _.pick( props, 'width', 'height', 'alt' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			// Only assign the align class to the image if we're not printing
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
			// a caption, since the alignment is sent to the shortcode.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
			if ( props.align && ! props.caption ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
				classes.push( 'align' + props.align );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
			if ( props.size ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
				classes.push( 'size-' + props.size );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
			img['class'] = _.compact( classes ).join(' ');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			// Generate `img` tag options.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			options = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
				tag:    'img',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
				attrs:  img,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
				single: true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
			// Generate the `a` element options, if they exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
			if ( props.linkUrl ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
				options = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
					tag:   'a',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
					attrs: {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
						href: props.linkUrl
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
					},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
					content: options
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
			html = wp.html.string( options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
			// Generate the caption shortcode.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
			if ( props.caption ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
				shortcode = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
				if ( img.width ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
					shortcode.width = img.width;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
				if ( props.captionId ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
					shortcode.id = props.captionId;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
				if ( props.align ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
					shortcode.align = 'align' + props.align;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
				html = wp.shortcode.string({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
					tag:     'caption',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
					attrs:   shortcode,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
					content: html + ' ' + props.caption
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
			return html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
	wp.media.embed = {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
		coerce : wp.media.coerce,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
		defaults : {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
			url : '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
			width: '',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
			height: ''
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
		},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
		edit : function( data, isURL ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
			var frame, props = {}, shortcode;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
			if ( isURL ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
				props.url = data.replace(/<[^>]+>/g, '');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
				shortcode = wp.shortcode.next( 'embed', data ).shortcode;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
				props = _.defaults( shortcode.attrs.named, this.defaults );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
				if ( shortcode.content ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
					props.url = shortcode.content;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
			frame = wp.media({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
				frame: 'post',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
				state: 'embed',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
				metadata: props
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
			});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
			return frame;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
		},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
		shortcode : function( model ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
			var self = this, content;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
			_.each( this.defaults, function( value, key ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
				model[ key ] = self.coerce( model, key );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
				if ( value === model[ key ] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
					delete model[ key ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
			});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
			content = model.url;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
			delete model.url;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
			return new wp.shortcode({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
				tag: 'embed',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
				attrs: model,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
				content: content
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
			});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   334
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   335
	 * @class wp.media.collection
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   336
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   337
	 * @param {Object} attributes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   338
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
	wp.media.collection = function(attributes) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
		var collections = {};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
		return _.extend(/** @lends wp.media.collection.prototype */{
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
			coerce : wp.media.coerce,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
			 * Retrieve attachments based on the properties of the passed shortcode
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   347
			 * @param {wp.shortcode} shortcode An instance of wp.shortcode().
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
			 * @returns {wp.media.model.Attachments} A Backbone.Collection containing
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
			 *      the media items belonging to a collection.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
			 *      The query[ this.tag ] property is a Backbone.Model
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
			 *          containing the 'props' for the collection.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
			attachments: function( shortcode ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
				var shortcodeString = shortcode.string(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
					result = collections[ shortcodeString ],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   356
					attrs, args, query, others, self = this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
				delete collections[ shortcodeString ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
				if ( result ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
					return result;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
				// Fill the default shortcode attributes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
				attrs = _.defaults( shortcode.attrs.named, this.defaults );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
				args  = _.pick( attrs, 'orderby', 'order' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
				args.type    = this.type;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
				args.perPage = -1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
				// Mark the `orderby` override attribute.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
				if ( undefined !== attrs.orderby ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
					attrs._orderByField = attrs.orderby;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
				if ( 'rand' === attrs.orderby ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
					attrs._orderbyRandom = true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
				// Map the `orderby` attribute to the corresponding model property.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
				if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
					args.orderby = 'menuOrder';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
				// Map the `ids` param to the correct query args.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
				if ( attrs.ids ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
					args.post__in = attrs.ids.split(',');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
					args.orderby  = 'post__in';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
				} else if ( attrs.include ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
					args.post__in = attrs.include.split(',');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
				if ( attrs.exclude ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
					args.post__not_in = attrs.exclude.split(',');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
				if ( ! args.post__in ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
					args.uploadedTo = attrs.id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
				// Collect the attributes that were not included in `args`.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
				others = _.omit( attrs, 'id', 'ids', 'include', 'exclude', 'orderby', 'order' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
				_.each( this.defaults, function( value, key ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
					others[ key ] = self.coerce( others, key );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
				});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
				query = wp.media.query( args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
				query[ this.tag ] = new Backbone.Model( others );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
				return query;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
			},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
			 * Triggered when clicking 'Insert {label}' or 'Update {label}'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
			 * @param {wp.media.model.Attachments} attachments A Backbone.Collection containing
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
			 *      the media items belonging to a collection.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
			 *      The query[ this.tag ] property is a Backbone.Model
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
			 *          containing the 'props' for the collection.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
			 * @returns {wp.shortcode}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
			shortcode: function( attachments ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
				var props = attachments.props.toJSON(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
					attrs = _.pick( props, 'orderby', 'order' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
					shortcode, clone;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
				if ( attachments.type ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
					attrs.type = attachments.type;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
					delete attachments.type;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
				if ( attachments[this.tag] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
					_.extend( attrs, attachments[this.tag].toJSON() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
				// Convert all gallery shortcodes to use the `ids` property.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
				// Ignore `post__in` and `post__not_in`; the attachments in
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
				// the collection will already reflect those properties.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
				attrs.ids = attachments.pluck('id');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
				// Copy the `uploadedTo` post ID.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
				if ( props.uploadedTo ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
					attrs.id = props.uploadedTo;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
				// Check if the gallery is randomly ordered.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
				delete attrs.orderby;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
				if ( attrs._orderbyRandom ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
					attrs.orderby = 'rand';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
				} else if ( attrs._orderByField && attrs._orderByField != 'rand' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
					attrs.orderby = attrs._orderByField;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
				delete attrs._orderbyRandom;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
				delete attrs._orderByField;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
				// If the `ids` attribute is set and `orderby` attribute
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
				// is the default value, clear it for cleaner output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
				if ( attrs.ids && 'post__in' === attrs.orderby ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
					delete attrs.orderby;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
				attrs = this.setDefaults( attrs );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
				shortcode = new wp.shortcode({
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
					tag:    this.tag,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
					attrs:  attrs,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
					type:   'single'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
				// Use a cloned version of the gallery.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
				clone = new wp.media.model.Attachments( attachments.models, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
					props: props
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
				});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
				clone[ this.tag ] = attachments[ this.tag ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
				collections[ shortcode.string() ] = clone;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
				return shortcode;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
			},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
			 * Triggered when double-clicking a collection shortcode placeholder
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
			 *   in the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
			 * @param {string} content Content that is searched for possible
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
			 *    shortcode markup matching the passed tag name,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
			 * @this wp.media.{prop}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
			 * @returns {wp.media.view.MediaFrame.Select} A media workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
			edit: function( content ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
				var shortcode = wp.shortcode.next( this.tag, content ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
					defaultPostId = this.defaults.id,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
					attachments, selection, state;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
				// Bail if we didn't match the shortcode or all of the content.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
				if ( ! shortcode || shortcode.content !== content ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
					return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
				// Ignore the rest of the match object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
				shortcode = shortcode.shortcode;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
				if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
					shortcode.set( 'id', defaultPostId );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
				attachments = this.attachments( shortcode );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
				selection = new wp.media.model.Selection( attachments.models, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
					props:    attachments.props.toJSON(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
					multiple: true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
				selection[ this.tag ] = attachments[ this.tag ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
				// Fetch the query's attachments, and then break ties from the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
				// query to allow for sorting.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
				selection.more().done( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
					// Break ties with the query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
					selection.props.set({ query: false });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
					selection.unmirror();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
					selection.props.unset('orderby');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
				// Destroy the previous gallery frame.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
				if ( this.frame ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
					this.frame.dispose();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
				if ( shortcode.attrs.named.type && 'video' === shortcode.attrs.named.type ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
					state = 'video-' + this.tag + '-edit';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
				} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
					state = this.tag + '-edit';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
				// Store the current frame.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
				this.frame = wp.media({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
					frame:     'post',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
					state:     state,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
					title:     this.editTitle,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
					editing:   true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
					multiple:  true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
					selection: selection
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
				}).open();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
				return this.frame;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
			},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
			setDefaults: function( attrs ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
				var self = this;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
				// Remove default attributes from the shortcode.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
				_.each( this.defaults, function( value, key ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
					attrs[ key ] = self.coerce( attrs, key );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
					if ( value === attrs[ key ] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
						delete attrs[ key ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
				});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
				return attrs;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
		}, attributes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
	};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   562
	wp.media._galleryDefaults = {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
		itemtag: 'dl',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   564
		icontag: 'dt',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   565
		captiontag: 'dd',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   566
		columns: '3',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
		link: 'post',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   568
		size: 'thumbnail',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   569
		order: 'ASC',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   570
		id: wp.media.view.settings.post && wp.media.view.settings.post.id,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
		orderby : 'menu_order ID'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   572
	};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
	if ( wp.media.view.settings.galleryDefaults ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
		wp.media.galleryDefaults = _.extend( {}, wp.media._galleryDefaults, wp.media.view.settings.galleryDefaults );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
		wp.media.galleryDefaults = wp.media._galleryDefaults;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   580
	wp.media.gallery = new wp.media.collection({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   581
		tag: 'gallery',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   582
		type : 'image',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
		editTitle : wp.media.view.l10n.editGalleryTitle,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
		defaults : wp.media.galleryDefaults,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
		setDefaults: function( attrs ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
			var self = this, changed = ! _.isEqual( wp.media.galleryDefaults, wp.media._galleryDefaults );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
			_.each( this.defaults, function( value, key ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
				attrs[ key ] = self.coerce( attrs, key );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
				if ( value === attrs[ key ] && ( ! changed || value === wp.media._galleryDefaults[ key ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
					delete attrs[ key ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   592
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
			return attrs;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
	});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   599
	 * @namespace wp.media.featuredImage
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   600
	 * @memberOf wp.media
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	wp.media.featuredImage = {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
		 * Get the featured image post ID
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   606
		 * @returns {wp.media.view.settings.post.featuredImageId|number}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
		get: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
			return wp.media.view.settings.post.featuredImageId;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   611
		/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   612
		 * Sets the featured image ID property and sets the HTML in the post meta box to the new featured image.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   613
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   614
		 * @param {number} id The post ID of the featured image, or -1 to unset it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   615
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
		set: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
			var settings = wp.media.view.settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
			settings.post.featuredImageId = id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   621
			wp.media.post( 'get-post-thumbnail-html', {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
				post_id:      settings.post.id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
				thumbnail_id: settings.post.featuredImageId,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
				_wpnonce:     settings.post.nonce
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
			}).done( function( html ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   626
				if ( html == '0' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   627
					window.alert( window.setPostThumbnailL10n.error );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   628
					return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   629
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
				$( '.inside', '#postimagediv' ).html( html );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   633
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   634
		 * Remove the featured image id, save the post thumbnail data and
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   635
		 * set the HTML in the post meta box to no featured image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   636
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   637
		remove: function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   638
			wp.media.featuredImage.set( -1 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   639
		},
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   640
		/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   641
		 * The Featured Image workflow
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   643
		 * @this wp.media.featuredImage
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   644
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   645
		 * @returns {wp.media.view.MediaFrame.Select} A media workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   646
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
		frame: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   648
			if ( this._frame ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   649
				wp.media.frame = this._frame;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
				return this._frame;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
			this._frame = wp.media({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
				state: 'featured-image',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   655
				states: [ new wp.media.controller.FeaturedImage() , new wp.media.controller.EditImage() ]
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
			this._frame.on( 'toolbar:create:featured-image', function( toolbar ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   659
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   660
				 * @this wp.media.view.MediaFrame.Select
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   661
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
				this.createSelectToolbar( toolbar, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
					text: wp.media.view.l10n.setFeaturedImage
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
			}, this._frame );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   667
			this._frame.on( 'content:render:edit-image', function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   668
				var selection = this.state('featured-image').get('selection'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   669
					view = new wp.media.view.EditImage( { model: selection.single(), controller: this } ).render();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   670
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   671
				this.content.set( view );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   672
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   673
				// after bringing in the frame, load the actual editor via an ajax call
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   674
				view.loadEditor();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   675
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
			}, this._frame );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
			this._frame.state('featured-image').on( 'select', this.select );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
			return this._frame;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
		 * 'select' callback for Featured Image workflow, triggered when
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
		 *  the 'Set Featured Image' button is clicked in the media modal.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   684
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
		 * @this wp.media.controller.FeaturedImage
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   686
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		select: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   688
			var selection = this.get('selection').single();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   690
			if ( ! wp.media.view.settings.post.featuredImageId ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
				return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   692
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
			wp.media.featuredImage.set( selection ? selection.id : -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   696
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   697
		 * Open the content media manager to the 'featured image' tab when
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   698
		 * the post thumbnail is clicked.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   699
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   700
		 * Update the featured image id when the 'remove' link is clicked.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   701
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
		init: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
			$('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
				event.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
				// Stop propagation to prevent thickbox from activating.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
				event.stopPropagation();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
				wp.media.featuredImage.frame().open();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
			}).on( 'click', '#remove-post-thumbnail', function() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   710
				wp.media.featuredImage.remove();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   711
				return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	$( wp.media.featuredImage.init );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   718
	/** @namespace wp.media.editor */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
	wp.media.editor = {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   720
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
		 * Send content to the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
		 * @param {string} html Content to send to the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
		insert: function( html ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
			var editor, wpActiveEditor,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
				hasTinymce = ! _.isUndefined( window.tinymce ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
				hasQuicktags = ! _.isUndefined( window.QTags );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
			if ( this.activeEditor ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   731
				wpActiveEditor = window.wpActiveEditor = this.activeEditor;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   732
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   733
				wpActiveEditor = window.wpActiveEditor;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   734
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
			// Delegate to the global `send_to_editor` if it exists.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
			// This attempts to play nice with any themes/plugins that have
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
			// overridden the insert functionality.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   739
			if ( window.send_to_editor ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
				return window.send_to_editor.apply( this, arguments );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   743
			if ( ! wpActiveEditor ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   744
				if ( hasTinymce && tinymce.activeEditor ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
					editor = tinymce.activeEditor;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   746
					wpActiveEditor = window.wpActiveEditor = editor.id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   747
				} else if ( ! hasQuicktags ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   748
					return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   749
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   750
			} else if ( hasTinymce ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
				editor = tinymce.get( wpActiveEditor );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   752
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   754
			if ( editor && ! editor.isHidden() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   755
				editor.execCommand( 'mceInsertContent', false, html );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   756
			} else if ( hasQuicktags ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   757
				QTags.insertContent( html );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
			} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   759
				document.getElementById( wpActiveEditor ).value += html;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
			// If the old thickbox remove function exists, call it in case
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
			// a theme/plugin overloaded it.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   764
			if ( window.tb_remove ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
				try { window.tb_remove(); } catch( e ) {}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   766
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   769
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   770
		 * Setup 'workflow' and add to the 'workflows' cache. 'open' can
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   771
		 *  subsequently be called upon it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   772
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   773
		 * @param {string} id A slug used to identify the workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   774
		 * @param {Object} [options={}]
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   776
		 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
		 * @returns {wp.media.view.MediaFrame.Select} A media workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
		add: function( id, options ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
			var workflow = this.get( id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   783
			// only add once: if exists return existing
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
			if ( workflow ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
				return workflow;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   786
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
			workflow = workflows[ id ] = wp.media( _.defaults( options || {}, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
				frame:    'post',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
				state:    'insert',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
				title:    wp.media.view.l10n.addMedia,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
				multiple: true
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
			} ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
			workflow.on( 'insert', function( selection ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
				var state = workflow.state();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
				selection = selection || state.get('selection');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
				if ( ! selection )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
					return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
				$.when.apply( $, selection.map( function( attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
					var display = state.display( attachment ).toJSON();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   805
					/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   806
					 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
					 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
					return this.send.attachment( display, attachment.toJSON() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
				}, this ) ).done( function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   810
					wp.media.editor.insert( _.toArray( arguments ).join('\n\n') );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
			}, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
			workflow.state('gallery-edit').on( 'update', function( selection ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   815
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   816
				 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   817
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
				this.insert( wp.media.gallery.shortcode( selection ).string() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
			}, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
			workflow.state('playlist-edit').on( 'update', function( selection ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   823
				 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   824
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
				this.insert( wp.media.playlist.shortcode( selection ).string() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
			}, this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   827
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   828
			workflow.state('video-playlist-edit').on( 'update', function( selection ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
				 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
				 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
				this.insert( wp.media.playlist.shortcode( selection ).string() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
			}, this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
			workflow.state('embed').on( 'select', function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
				/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
				 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
				 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
				var state = workflow.state(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
					type = state.get('type'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
					embed = state.props.toJSON();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
				embed.url = embed.url || '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
				if ( 'link' === type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
					_.defaults( embed, {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   847
						linkText: embed.url,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
						linkUrl: embed.url
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
					this.send.link( embed ).done( function( resp ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
						wp.media.editor.insert( resp );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
				} else if ( 'image' === type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
					_.defaults( embed, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
						title:   embed.url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
						linkUrl: '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
						align:   'none',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
						link:    'none'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   863
					if ( 'none' === embed.link ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
						embed.linkUrl = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
					} else if ( 'file' === embed.link ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
						embed.linkUrl = embed.url;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   867
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
					this.insert( wp.media.string.image( embed ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
			}, this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
			workflow.state('featured-image').on( 'select', wp.media.featuredImage.select );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
			workflow.setState( workflow.options.state );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
			return workflow;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
		 * Determines the proper current workflow id
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
		 * @param {string} [id=''] A slug used to identify the workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
		 * @returns {wpActiveEditor|string|tinymce.activeEditor.id}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   883
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
		id: function( id ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   885
			if ( id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
				return id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   887
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
			// If an empty `id` is provided, default to `wpActiveEditor`.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   890
			id = window.wpActiveEditor;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
			// If that doesn't work, fall back to `tinymce.activeEditor.id`.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   893
			if ( ! id && ! _.isUndefined( window.tinymce ) && tinymce.activeEditor ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
				id = tinymce.activeEditor.id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   895
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
			// Last but not least, fall back to the empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
			id = id || '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
			return id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   901
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   902
		 * Return the workflow specified by id
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   904
		 * @param {string} id A slug used to identify the workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   906
		 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   907
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   908
		 * @returns {wp.media.view.MediaFrame} A media workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
		get: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
			id = this.id( id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
			return workflows[ id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   914
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   915
		 * Remove the workflow represented by id from the workflow cache
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   917
		 * @param {string} id A slug used to identify the workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   919
		 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
		remove: function( id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
			id = this.id( id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
			delete workflows[ id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
		},
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   925
		/** @namespace wp.media.editor.send */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
		send: {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   927
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   928
			 * Called when sending an attachment to the editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   929
			 *   from the medial modal.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   930
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   931
			 * @param {Object} props Attachment details (align, link, size, etc).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   932
			 * @param {Object} attachment The attachment object, media version of Post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   933
			 * @returns {Promise}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   934
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
			attachment: function( props, attachment ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
				var caption = attachment.caption,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
					options, html;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
				// If captions are disabled, clear the caption.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   940
				if ( ! wp.media.view.settings.captions ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
					delete attachment.caption;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   942
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
				props = wp.media.string.props( props, attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
				options = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
					id:           attachment.id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
					post_content: attachment.description,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
					post_excerpt: caption
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   952
				if ( props.linkUrl ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
					options.url = props.linkUrl;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   954
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
				if ( 'image' === attachment.type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
					html = wp.media.string.image( props );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
					_.each({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
						align: 'align',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
						size:  'image-size',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
						alt:   'image_alt'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
					}, function( option, prop ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
						if ( props[ prop ] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
							options[ option ] = props[ prop ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
				} else if ( 'video' === attachment.type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
					html = wp.media.string.video( props, attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
				} else if ( 'audio' === attachment.type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
					html = wp.media.string.audio( props, attachment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
					html = wp.media.string.link( props );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
					options.post_title = props.title;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
				return wp.media.post( 'send-attachment-to-editor', {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
					nonce:      wp.media.view.settings.nonce.sendToEditor,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
					attachment: options,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
					html:       html,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
					post_id:    wp.media.view.settings.post.id
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
			},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   983
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   984
			 * Called when 'Insert From URL' source is not an image. Example: YouTube url.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   985
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   986
			 * @param {Object} embed
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
			 * @returns {Promise}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   988
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
			link: function( embed ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
				return wp.media.post( 'send-link-to-editor', {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   991
					nonce:     wp.media.view.settings.nonce.sendToEditor,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   992
					src:       embed.linkUrl,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   993
					link_text: embed.linkText,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   994
					html:      wp.media.string.link( embed ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   995
					post_id:   wp.media.view.settings.post.id
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
		},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   999
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1000
		 * Open a workflow
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1001
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1002
		 * @param {string} [id=undefined] Optional. A slug used to identify the workflow.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1003
		 * @param {Object} [options={}]
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1004
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1005
		 * @this wp.media.editor
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1007
		 * @returns {wp.media.view.MediaFrame}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1008
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
		open: function( id, options ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1010
			var workflow;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
			options = options || {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
			id = this.id( id );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1015
			this.activeEditor = id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
			workflow = this.get( id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
			// Redo workflow if state has changed
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1020
			if ( ! workflow || ( workflow.options && options.state !== workflow.options.state ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
				workflow = this.add( id, options );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1022
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1024
			wp.media.frame = workflow;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1025
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
			return workflow.open();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1029
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1030
		 * Bind click event for .insert-media using event delegation
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1031
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
		init: function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1033
			$(document.body)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1034
				.on( 'click.add-media-button', '.insert-media', function( event ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1035
					var elem = $( event.currentTarget ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
						editor = elem.data('editor'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1037
						options = {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
							frame:    'post',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
							state:    'insert',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
							title:    wp.media.view.l10n.addMedia,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
							multiple: true
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
						};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
					event.preventDefault();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1045
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
					if ( elem.hasClass( 'gallery' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1047
						options.state = 'gallery';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1048
						options.title = wp.media.view.l10n.createGalleryTitle;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
					wp.media.editor.open( editor, options );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1052
				});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1053
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1054
			// Initialize and render the Editor drag-and-drop uploader.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
			new wp.media.view.EditorUploader().render();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
	_.bindAll( wp.media.editor, 'open' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
	$( wp.media.editor.init );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
}(jQuery, _));