Changeset 22567
- Timestamp:
- 11/14/2012 07:17:22 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/media-upload.js
r22547 r22567 91 91 // ----------------------------- 92 92 (function($){ 93 // Stores the editors' `wp.media.controller.Workflow` instances. 94 var workflows = {}; 95 96 wp.mce.media = { 93 // Stores the editors' `wp.media.controller.Frame` instances. 94 var workflows = {}, 95 linkToUrl; 96 97 linkToUrl = function( attachment, props ) { 98 var link = props.link, 99 url; 100 101 if ( 'file' === link ) 102 url = attachment.get('url'); 103 else if ( 'post' === link ) 104 url = attachment.get('link'); 105 else if ( 'custom' === link ) 106 url = props.linkUrl; 107 108 return url || ''; 109 }; 110 111 wp.media.string = {}; 112 113 wp.media.string.link = function( attachment, props ) { 114 var linkTo = getUserSetting( 'urlbutton', 'post' ), 115 options = { 116 tag: 'a', 117 content: attachment.get('title') || attachment.get('filename'), 118 attrs: { 119 rel: 'attachment wp-att-' + attachment.id 120 } 121 }; 122 123 options.attrs.href = linkToUrl( attachment, props ); 124 125 return wp.html.string( options ); 126 }; 127 128 wp.media.string.image = function( attachment, props ) { 129 var classes, img, options, size, shortcode, html; 130 131 props = _.defaults( props || {}, { 132 img: {}, 133 align: getUserSetting( 'align', 'none' ), 134 size: getUserSetting( 'imgsize', 'medium' ), 135 link: getUserSetting( 'urlbutton', 'post' ) 136 }); 137 138 props.linkUrl = linkToUrl( attachment, props ); 139 140 attachment = attachment.toJSON(); 141 142 img = _.clone( props.img ); 143 classes = img['class'] ? img['class'].split(/\s+/) : []; 144 size = attachment.sizes ? attachment.sizes[ props.size ] : {}; 145 146 if ( ! size ) { 147 delete props.size; 148 size = attachment; 149 } 150 151 img.width = size.width; 152 img.height = size.height; 153 img.src = size.url; 154 155 // Only assign the align class to the image if we're not printing 156 // a caption, since the alignment is sent to the shortcode. 157 if ( props.align && ! attachment.caption ) 158 classes.push( 'align' + props.align ); 159 160 if ( props.size ) 161 classes.push( 'size-' + props.size ); 162 163 classes.push( 'wp-image-' + attachment.id ); 164 165 img['class'] = _.compact( classes ).join(' '); 166 167 // Generate `img` tag options. 168 options = { 169 tag: 'img', 170 attrs: img, 171 single: true 172 }; 173 174 // Generate the `href` based on the `link` property. 175 if ( props.linkUrl ) { 176 props.anchor = props.anchor || {}; 177 props.anchor.href = props.linkUrl; 178 } 179 180 // Generate the `a` element options, if they exist. 181 if ( props.anchor ) { 182 options = { 183 tag: 'a', 184 attrs: props.anchor, 185 content: options 186 }; 187 } 188 189 html = wp.html.string( options ); 190 191 // Generate the caption shortcode. 192 if ( attachment.caption ) { 193 shortcode = { 194 id: 'attachment_' + attachment.id, 195 width: img.width 196 }; 197 198 if ( props.align ) 199 shortcode.align = 'align' + props.align; 200 201 html = wp.shortcode.string({ 202 tag: 'caption', 203 attrs: shortcode, 204 content: html + ' ' + attachment.caption 205 }); 206 } 207 208 return html; 209 }; 210 211 wp.media.gallery = (function() { 212 var galleries = {}; 213 214 return { 215 attachments: function( shortcode, parent ) { 216 var shortcodeString = shortcode.string(), 217 result = galleries[ shortcodeString ], 218 attrs, args, query, others; 219 220 delete galleries[ shortcodeString ]; 221 222 if ( result ) 223 return result; 224 225 attrs = shortcode.attrs.named; 226 args = _.pick( attrs, 'orderby', 'order' ); 227 228 args.type = 'image'; 229 args.perPage = -1; 230 231 // Map the `ids` param to the correct query args. 232 if ( attrs.ids ) { 233 args.post__in = attrs.ids.split(','); 234 args.orderby = 'post__in'; 235 } else if ( attrs.include ) { 236 args.post__in = attrs.include.split(','); 237 } 238 239 if ( attrs.exclude ) 240 args.post__not_in = attrs.exclude.split(','); 241 242 if ( ! args.post__in ) 243 args.parent = attrs.id || parent; 244 245 // Collect the attributes that were not included in `args`. 246 others = {}; 247 _.filter( attrs, function( value, key ) { 248 if ( _.isUndefined( args[ key ] ) ) 249 others[ key ] = value; 250 }); 251 252 query = media.query( args ); 253 query.gallery = new Backbone.Model( others ); 254 return query; 255 }, 256 257 shortcode: function( attachments ) { 258 var props = attachments.props.toJSON(), 259 attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order' ), 260 shortcode, clone; 261 262 if ( attachments.gallery ) 263 _.extend( attrs, attachments.gallery.toJSON() ); 264 265 attrs.ids = attachments.pluck('id'); 266 267 // If the `ids` attribute is set and `orderby` attribute 268 // is the default value, clear it for cleaner output. 269 if ( attrs.ids && 'post__in' === attrs.orderby ) 270 delete attrs.orderby; 271 272 shortcode = new wp.shortcode({ 273 tag: 'gallery', 274 attrs: attrs, 275 type: 'single' 276 }); 277 278 // Use a cloned version of the gallery. 279 clone = new wp.media.model.Attachments( attachments.models, { 280 props: props 281 }); 282 clone.gallery = attachments.gallery; 283 galleries[ shortcode.string() ] = clone; 284 285 return shortcode; 286 } 287 }; 288 }()); 289 290 wp.media.editor = { 97 291 insert: send_to_editor, 98 292 … … 135 329 136 330 workflow.get('gallery-edit').on( 'update', function( selection ) { 137 var view = wp.mce.view.get('gallery'), 138 shortcode; 139 140 if ( ! view ) 141 return; 142 143 shortcode = view.gallery.shortcode( selection ); 144 this.insert( shortcode.string() ); 331 this.insert( wp.media.gallery.shortcode( selection ).string() ); 145 332 }, this ); 146 333 … … 212 399 return; 213 400 214 workflow = wp.m ce.media.get( editor );401 workflow = wp.media.editor.get( editor ); 215 402 216 403 // If the workflow exists, just open it. … … 221 408 222 409 // Initialize the editor's workflow if we haven't yet. 223 wp.m ce.media.add( editor );410 wp.media.editor.add( editor ); 224 411 }); 225 412 } 226 413 }; 227 414 228 $( wp.m ce.media.init );415 $( wp.media.editor.init ); 229 416 }(jQuery)); -
trunk/wp-includes/class-wp-editor.php
r22416 r22567 192 192 self::$mce_locale = $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1 193 193 $no_captions = (bool) apply_filters( 'disable_captions', '' ); 194 $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wp link', 'wpdialogs', 'wpview' );194 $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' ); 195 195 $first_run = true; 196 196 $ext_plugins = ''; 197 197 198 198 if ( $set['teeny'] ) { 199 self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs' , 'wpview'), $editor_id );199 self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs' ), $editor_id ); 200 200 } else { 201 201 /* -
trunk/wp-includes/js/mce-view.js
r22554 r22567 1 1 // Ensure the global `wp` object exists. 2 2 window.wp = window.wp || {}; 3 4 // HTML utility functions5 // ----------------------6 (function(){7 wp.html = _.extend( wp.html || {}, {8 // ### Parse HTML attributes.9 //10 // Converts `content` to a set of parsed HTML attributes.11 // Utilizes `wp.shortcode.attrs( content )`, which is a valid superset of12 // the HTML attribute specification. Reformats the attributes into an13 // object that contains the `attrs` with `key:value` mapping, and a record14 // of the attributes that were entered using `empty` attribute syntax (i.e.15 // with no value).16 attrs: function( content ) {17 var result, attrs;18 19 // If `content` ends in a slash, strip it.20 if ( '/' === content[ content.length - 1 ] )21 content = content.slice( 0, -1 );22 23 result = wp.shortcode.attrs( content );24 attrs = result.named;25 26 _.each( result.numeric, function( key ) {27 if ( /\s/.test( key ) )28 return;29 30 attrs[ key ] = '';31 });32 33 return attrs;34 },35 36 // ### Convert an HTML-representation of an object to a string.37 string: function( options ) {38 var text = '<' + options.tag,39 content = options.content || '';40 41 _.each( options.attrs, function( value, attr ) {42 text += ' ' + attr;43 44 // Use empty attribute notation where possible.45 if ( '' === value )46 return;47 48 // Convert boolean values to strings.49 if ( _.isBoolean( value ) )50 value = value ? 'true' : 'false';51 52 text += '="' + value + '"';53 });54 55 // Return the result if it is a self-closing tag.56 if ( options.single )57 return text + ' />';58 59 // Complete the opening tag.60 text += '>';61 62 // If `content` is an object, recursively call this function.63 text += _.isObject( content ) ? wp.html.string( content ) : content;64 65 return text + '</' + options.tag + '>';66 }67 });68 }());69 3 70 4 (function($){ … … 410 344 $node.removeClass('selected'); 411 345 $( node.firstChild ).trigger('deselect'); 412 }, 413 414 // Link any localized strings. 415 l10n: _.isUndefined( _wpMceViewL10n ) ? {} : _wpMceViewL10n 346 } 416 347 }; 417 348 418 349 }(jQuery)); 419 420 // Default TinyMCE Views421 // ---------------------422 (function($){423 var mceview = wp.mce.view,424 linkToUrl;425 426 linkToUrl = function( attachment, props ) {427 var link = props.link,428 url;429 430 if ( 'file' === link )431 url = attachment.get('url');432 else if ( 'post' === link )433 url = attachment.get('link');434 else if ( 'custom' === link )435 url = props.linkUrl;436 437 return url || '';438 };439 440 wp.media.string = {};441 442 wp.media.string.link = function( attachment, props ) {443 var linkTo = getUserSetting( 'urlbutton', 'post' ),444 options = {445 tag: 'a',446 content: attachment.get('title') || attachment.get('filename'),447 attrs: {448 rel: 'attachment wp-att-' + attachment.id449 }450 };451 452 options.attrs.href = linkToUrl( attachment, props );453 454 return wp.html.string( options );455 };456 457 wp.media.string.image = function( attachment, props ) {458 var classes, img, options, size, shortcode, html;459 460 props = _.defaults( props || {}, {461 img: {},462 align: getUserSetting( 'align', 'none' ),463 size: getUserSetting( 'imgsize', 'medium' ),464 link: getUserSetting( 'urlbutton', 'post' )465 });466 467 props.linkUrl = linkToUrl( attachment, props );468 469 attachment = attachment.toJSON();470 471 img = _.clone( props.img );472 classes = img['class'] ? img['class'].split(/\s+/) : [];473 size = attachment.sizes ? attachment.sizes[ props.size ] : {};474 475 if ( ! size ) {476 delete props.size;477 size = attachment;478 }479 480 img.width = size.width;481 img.height = size.height;482 img.src = size.url;483 484 // Only assign the align class to the image if we're not printing485 // a caption, since the alignment is sent to the shortcode.486 if ( props.align && ! attachment.caption )487 classes.push( 'align' + props.align );488 489 if ( props.size )490 classes.push( 'size-' + props.size );491 492 classes.push( 'wp-image-' + attachment.id );493 494 img['class'] = _.compact( classes ).join(' ');495 496 // Generate `img` tag options.497 options = {498 tag: 'img',499 attrs: img,500 single: true501 };502 503 // Generate the `href` based on the `link` property.504 if ( props.linkUrl ) {505 props.anchor = props.anchor || {};506 props.anchor.href = props.linkUrl;507 }508 509 // Generate the `a` element options, if they exist.510 if ( props.anchor ) {511 options = {512 tag: 'a',513 attrs: props.anchor,514 content: options515 };516 }517 518 html = wp.html.string( options );519 520 // Generate the caption shortcode.521 if ( attachment.caption ) {522 shortcode = {523 id: 'attachment_' + attachment.id,524 width: img.width525 };526 527 if ( props.align )528 shortcode.align = 'align' + props.align;529 530 html = wp.shortcode.string({531 tag: 'caption',532 attrs: shortcode,533 content: html + ' ' + attachment.caption534 });535 }536 537 return html;538 };539 540 mceview.add( 'attachment', {541 pattern: new RegExp( '(?:<a([^>]*)>)?<img([^>]*class=(?:"[^"]*|\'[^\']*)\\bwp-image-(\\d+)[^>]*)>(?:</a>)?' ),542 543 text: function( instance ) {544 var props = _.pick( instance, 'align', 'size', 'link', 'img', 'anchor' );545 return wp.media.string.image( instance.model, props );546 },547 548 view: {549 className: 'editor-attachment',550 template: media.template('editor-attachment'),551 552 events: {553 'click .close': 'remove'554 },555 556 initialize: function() {557 var view = this,558 results = this.options.results,559 id = results[3],560 className;561 562 this.model = wp.media.model.Attachment.get( id );563 564 if ( results[1] )565 this.anchor = mceview.attrs( results[1] );566 567 this.img = mceview.attrs( results[2] );568 className = this.img['class'];569 570 // Strip ID class.571 className = className.replace( /(?:^|\s)wp-image-\d+/, '' );572 573 // Calculate thumbnail `size` and remove class.574 className = className.replace( /(?:^|\s)size-(\S+)/, function( match, size ) {575 view.size = size;576 return '';577 });578 579 // Calculate `align` and remove class.580 className = className.replace( /(?:^|\s)align(left|center|right|none)(?:\s|$)/, function( match, align ) {581 view.align = align;582 return '';583 });584 585 this.img['class'] = className;586 587 this.$el.addClass('spinner');588 this.model.fetch().done( _.bind( this.render, this ) );589 },590 591 render: function() {592 var attachment = this.model.toJSON(),593 options;594 595 // If we don't have the attachment data, bail.596 if ( ! attachment.url )597 return;598 599 // Align the wrapper.600 if ( this.align )601 this.$wrapper.addClass( 'align' + this.align );602 603 // Generate the template options.604 options = {605 url: 'image' === attachment.type ? attachment.url : attachment.icon,606 uploading: attachment.uploading607 };608 609 _.extend( options, wp.media.fit({610 width: attachment.width,611 height: attachment.height,612 maxWidth: mceview.l10n.contentWidth613 }) );614 615 // Use the specified size if it exists.616 if ( this.size && attachment.sizes && attachment.sizes[ this.size ] )617 _.extend( options, _.pick( attachment.sizes[ this.size ], 'url', 'width', 'height' ) );618 619 this.$el.html( this.template( options ) );620 }621 }622 });623 624 mceview.add( 'gallery', {625 shortcode: 'gallery',626 627 gallery: (function() {628 var galleries = {};629 630 return {631 attachments: function( shortcode, parent ) {632 var shortcodeString = shortcode.string(),633 result = galleries[ shortcodeString ],634 attrs, args, query, others;635 636 delete galleries[ shortcodeString ];637 638 if ( result )639 return result;640 641 attrs = shortcode.attrs.named;642 args = _.pick( attrs, 'orderby', 'order' );643 644 args.type = 'image';645 args.perPage = -1;646 647 // Map the `ids` param to the correct query args.648 if ( attrs.ids ) {649 args.post__in = attrs.ids.split(',');650 args.orderby = 'post__in';651 } else if ( attrs.include ) {652 args.post__in = attrs.include.split(',');653 }654 655 if ( attrs.exclude )656 args.post__not_in = attrs.exclude.split(',');657 658 if ( ! args.post__in )659 args.parent = attrs.id || parent;660 661 // Collect the attributes that were not included in `args`.662 others = {};663 _.filter( attrs, function( value, key ) {664 if ( _.isUndefined( args[ key ] ) )665 others[ key ] = value;666 });667 668 query = media.query( args );669 query.gallery = new Backbone.Model( others );670 return query;671 },672 673 shortcode: function( attachments ) {674 var props = attachments.props.toJSON(),675 attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order' ),676 shortcode, clone;677 678 if ( attachments.gallery )679 _.extend( attrs, attachments.gallery.toJSON() );680 681 attrs.ids = attachments.pluck('id');682 683 // If the `ids` attribute is set and `orderby` attribute684 // is the default value, clear it for cleaner output.685 if ( attrs.ids && 'post__in' === attrs.orderby )686 delete attrs.orderby;687 688 shortcode = new wp.shortcode({689 tag: 'gallery',690 attrs: attrs,691 type: 'single'692 });693 694 // Use a cloned version of the gallery.695 clone = new wp.media.model.Attachments( attachments.models, {696 props: props697 });698 clone.gallery = attachments.gallery;699 galleries[ shortcode.string() ] = clone;700 701 return shortcode;702 }703 };704 }()),705 706 view: {707 className: 'editor-gallery',708 template: media.template('editor-gallery'),709 710 // The fallback post ID to use as a parent for galleries that don't711 // specify the `ids` or `include` parameters.712 //713 // Uses the hidden input on the edit posts page by default.714 parent: $('#post_ID').val(),715 716 events: {717 'click .close': 'remove',718 'click .edit': 'edit'719 },720 721 initialize: function() {722 this.update();723 },724 725 update: function() {726 var view = mceview.get('gallery');727 728 this.attachments = view.gallery.attachments( this.options.shortcode, this.parent );729 this.attachments.more().done( _.bind( this.render, this ) );730 },731 732 render: function() {733 var options, thumbnail, size;734 735 if ( ! this.attachments.length )736 return;737 738 thumbnail = this.attachments.first().toJSON();739 size = thumbnail.sizes && thumbnail.sizes.thumbnail ? thumbnail.sizes.thumbnail : thumbnail;740 741 options = {742 url: size.url,743 orientation: size.orientation,744 count: this.attachments.length745 };746 747 this.$el.html( this.template( options ) );748 },749 750 edit: function() {751 var selection;752 753 if ( ! wp.media.view || this.frame )754 return;755 756 selection = new wp.media.model.Selection( this.attachments.models, {757 props: this.attachments.props.toJSON(),758 multiple: true759 });760 selection.gallery = this.attachments.gallery;761 762 this.frame = wp.media({763 frame: 'post',764 state: 'gallery-edit',765 title: mceview.l10n.editGallery,766 editing: true,767 multiple: true,768 selection: selection769 });770 771 // Create a single-use frame. If the frame is closed,772 // then detach it from the DOM and remove the reference.773 this.frame.on( 'close', function() {774 if ( this.frame )775 this.frame.detach();776 delete this.frame;777 }, this );778 779 // Update the `shortcode` and `attachments`.780 this.frame.get('gallery-edit').on( 'update', function( selection ) {781 var view = mceview.get('gallery');782 783 this.options.shortcode = view.gallery.shortcode( selection );784 this.update();785 }, this );786 }787 }788 });789 }(jQuery)); -
trunk/wp-includes/js/shortcode.js
r22522 r22567 273 273 }); 274 274 }()); 275 276 // HTML utility functions 277 // ---------------------- 278 // 279 // Experimental. These functions may change or be removed in the future. 280 (function(){ 281 wp.html = _.extend( wp.html || {}, { 282 // ### Parse HTML attributes. 283 // 284 // Converts `content` to a set of parsed HTML attributes. 285 // Utilizes `wp.shortcode.attrs( content )`, which is a valid superset of 286 // the HTML attribute specification. Reformats the attributes into an 287 // object that contains the `attrs` with `key:value` mapping, and a record 288 // of the attributes that were entered using `empty` attribute syntax (i.e. 289 // with no value). 290 attrs: function( content ) { 291 var result, attrs; 292 293 // If `content` ends in a slash, strip it. 294 if ( '/' === content[ content.length - 1 ] ) 295 content = content.slice( 0, -1 ); 296 297 result = wp.shortcode.attrs( content ); 298 attrs = result.named; 299 300 _.each( result.numeric, function( key ) { 301 if ( /\s/.test( key ) ) 302 return; 303 304 attrs[ key ] = ''; 305 }); 306 307 return attrs; 308 }, 309 310 // ### Convert an HTML-representation of an object to a string. 311 string: function( options ) { 312 var text = '<' + options.tag, 313 content = options.content || ''; 314 315 _.each( options.attrs, function( value, attr ) { 316 text += ' ' + attr; 317 318 // Use empty attribute notation where possible. 319 if ( '' === value ) 320 return; 321 322 // Convert boolean values to strings. 323 if ( _.isBoolean( value ) ) 324 value = value ? 'true' : 'false'; 325 326 text += '="' + value + '"'; 327 }); 328 329 // Return the result if it is a self-closing tag. 330 if ( options.single ) 331 return text + ' />'; 332 333 // Complete the opening tag. 334 text += '>'; 335 336 // If `content` is an object, recursively call this function. 337 text += _.isObject( content ) ? wp.html.string( content ) : content; 338 339 return text + '</' + options.tag + '>'; 340 } 341 }); 342 }()); -
trunk/wp-includes/script-loader.php
r22516 r22567 299 299 ) ); 300 300 301 $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', ' mce-view', 'media-views' ), false, 1 );301 $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', 'shortcode', 'media-views' ), false, 1 ); 302 302 303 303 $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), 'r6', 1 ); … … 327 327 $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 ); 328 328 $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); 329 did_action( 'init' ) && $scripts->localize( 'mce-view', '_wpMceViewL10n', array(330 'contentWidth' => isset( $GLOBALS['content_width'] ) ? $GLOBALS['content_width'] : 800,331 'editGallery' => __( 'Edit Gallery' ),332 ) );333 329 334 330 if ( is_admin() ) {
Note: See TracChangeset
for help on using the changeset viewer.