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