Changeset 22758
- Timestamp:
- 11/21/2012 01:53:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/media-upload.js
r22715 r22758 95 95 linkToUrl; 96 96 97 linkToUrl = function( attachment, props) {98 var link = props.link ,97 linkToUrl = function( props, attachment ) { 98 var link = props.link || getUserSetting( 'urlbutton', 'post' ), 99 99 url; 100 100 101 101 if ( 'file' === link ) 102 url = attachment. get('url');102 url = attachment.url; 103 103 else if ( 'post' === link ) 104 url = attachment. get('link');104 url = attachment.link; 105 105 else if ( 'custom' === link ) 106 106 url = props.linkUrl; … … 110 110 111 111 wp.media.string = { 112 link: function( attachment, props ) { 113 var linkTo = getUserSetting( 'urlbutton', 'post' ), 114 options = { 115 tag: 'a', 116 content: attachment.get('title') || attachment.get('filename'), 117 attrs: { 118 rel: 'attachment wp-att-' + attachment.id 119 } 120 }; 121 122 options.attrs.href = linkToUrl( attachment, props ); 112 link: function( props, attachment ) { 113 var options; 114 115 props = _.defaults( props || {}, { 116 title: '', 117 linkUrl: '' 118 }); 119 120 if ( attachment ) { 121 attachment = attachment.toJSON(); 122 123 _.extend( props, { 124 title: attachment.title || attachment.filename, 125 linkUrl: linkToUrl( props, attachment ), 126 rel: 'attachment wp-att-' + attachment.id 127 }); 128 } 129 130 options = { 131 tag: 'a', 132 content: props.title, 133 attrs: { 134 href: props.linkUrl 135 } 136 }; 137 138 if ( props.rel ) 139 options.attrs.rel = props.rel; 123 140 124 141 return wp.html.string( options ); 125 142 }, 126 143 127 image: function( attachment, props ) { 128 var classes, img, options, size, shortcode, html; 144 image: function( props, attachment ) { 145 var classes = [], 146 img = {}, 147 options, sizes, size, shortcode, html; 129 148 130 149 props = _.defaults( props || {}, { 131 img: {},132 150 align: getUserSetting( 'align', 'none' ), 133 size: getUserSetting( 'imgsize', 'medium' ), 134 link: getUserSetting( 'urlbutton', 'post' ) 151 size: getUserSetting( 'imgsize', 'medium' ) 135 152 }); 136 153 137 props.linkUrl = linkToUrl( attachment, props ); 138 139 attachment = attachment.toJSON(); 140 141 img = _.clone( props.img ); 142 classes = img['class'] ? img['class'].split(/\s+/) : []; 143 size = attachment.sizes ? attachment.sizes[ props.size ] : {}; 144 145 if ( ! size ) { 146 delete props.size; 147 size = attachment; 154 if ( attachment ) { 155 attachment = attachment.toJSON(); 156 157 classes.push( 'wp-image-' + attachment.id ); 158 159 sizes = attachment.sizes; 160 size = sizes && sizes[ props.size ] ? sizes[ props.size ] : attachment; 161 162 _.extend( props, _.pick( attachment, 'align', 'caption' ), { 163 width: size.width, 164 height: size.height, 165 src: size.url, 166 linkUrl: linkToUrl( props, attachment ), 167 captionId: 'attachment_' + attachment.id 168 }); 148 169 } 149 170 … … 154 175 // Only assign the align class to the image if we're not printing 155 176 // a caption, since the alignment is sent to the shortcode. 156 if ( props.align && ! attachment.caption )177 if ( props.align && ! props.caption ) 157 178 classes.push( 'align' + props.align ); 158 179 159 180 if ( props.size ) 160 181 classes.push( 'size-' + props.size ); 161 162 classes.push( 'wp-image-' + attachment.id );163 182 164 183 img['class'] = _.compact( classes ).join(' '); … … 171 190 }; 172 191 173 // Generate the ` href` based on the `link` property.192 // Generate the `a` element options, if they exist. 174 193 if ( props.linkUrl ) { 175 props.anchor = props.anchor || {};176 props.anchor.href = props.linkUrl;177 }178 179 // Generate the `a` element options, if they exist.180 if ( props.anchor ) {181 194 options = { 182 tag: 'a', 183 attrs: props.anchor, 195 tag: 'a', 196 attrs: { 197 href: props.linkUrl 198 }, 184 199 content: options 185 200 }; … … 189 204 190 205 // Generate the caption shortcode. 191 if ( attachment.caption ) {206 if ( props.caption ) { 192 207 shortcode = { 193 id: 'attachment_' + attachment.id,194 208 width: img.width 195 209 }; 210 211 if ( props.captionId ) 212 shortcode.id = props.captionId; 196 213 197 214 if ( props.align ) … … 201 218 tag: 'caption', 202 219 attrs: shortcode, 203 content: html + ' ' + attachment.caption220 content: html + ' ' + props.caption 204 221 }); 205 222 } … … 381 398 382 399 if ( 'image' === attachment.get('type') ) 383 this.insert( wp.media.string.image( attachment, detail) + ' ' );400 this.insert( wp.media.string.image( detail, attachment ) + ' ' ); 384 401 else 385 this.insert( wp.media.string.link( attachment, detail) + ' ' );402 this.insert( wp.media.string.link( detail, attachment ) + ' ' ); 386 403 }, this ); 387 404 }, this );
Note: See TracChangeset
for help on using the changeset viewer.