diff --git wp-admin/css/colors-classic.css wp-admin/css/colors-classic.css
index 74a1060..c8963fc 100644
|
|
textarea.disabled { |
164 | 164 | color: #fff; |
165 | 165 | } |
166 | 166 | |
| 167 | .post-format-options, |
167 | 168 | .widget .widget-top, |
168 | 169 | .postbox h3, |
169 | 170 | .stuffbox h3, |
… |
… |
table.widefat span.spam a, |
688 | 689 | background-image: linear-gradient(to top, #eff8ff, #f7fcfe); |
689 | 690 | } |
690 | 691 | |
| 692 | .post-format-options, |
691 | 693 | .postbox h3 { |
692 | 694 | color: #174f69; |
693 | 695 | } |
diff --git wp-admin/css/colors-fresh.css wp-admin/css/colors-fresh.css
index 5aa5fa8..1941f51 100644
|
|
textarea.disabled { |
164 | 164 | color: #fff; |
165 | 165 | } |
166 | 166 | |
| 167 | .post-format-options, |
167 | 168 | .widget .widget-top, |
168 | 169 | .postbox h3, |
169 | 170 | .stuffbox h3, |
… |
… |
table.widefat span.spam a, |
690 | 691 | background-image: linear-gradient(to top, #f5f5f5, #f9f9f9); |
691 | 692 | } |
692 | 693 | |
| 694 | .post-format-options, |
693 | 695 | .postbox h3 { |
694 | 696 | color: #464646; |
695 | 697 | } |
diff --git wp-admin/css/wp-admin.css wp-admin/css/wp-admin.css
index 1b07b3e..883e7d0 100644
|
|
body .ui-tooltip { |
4000 | 4000 | } |
4001 | 4001 | |
4002 | 4002 | .wp-format-status #titlewrap, |
| 4003 | .wp-format-image .wp-media-buttons .insert-media, |
| 4004 | .wp-format-audio .wp-media-buttons .insert-media, |
| 4005 | .wp-format-video .wp-media-buttons .insert-media, |
4003 | 4006 | .wp-format-aside .wp-media-buttons .insert-media, |
4004 | 4007 | .wp-format-status .wp-media-buttons .insert-media { |
4005 | 4008 | display: none; |
… |
… |
body .ui-tooltip { |
4101 | 4104 | } |
4102 | 4105 | |
4103 | 4106 | .post-format-options { |
4104 | | height: 50px; |
| 4107 | border-width: 1px; |
| 4108 | border-style: solid; |
| 4109 | -webkit-border-radius: 3px; |
| 4110 | border-radius: 3px; |
| 4111 | border-color: #CCC; |
4105 | 4112 | margin: 13px 0 10px; |
4106 | | padding: 0; |
| 4113 | padding: 5px; |
4107 | 4114 | } |
4108 | 4115 | |
4109 | 4116 | .post-format-options a { |
4110 | 4117 | display: inline-block; |
4111 | | height: 34px; |
4112 | | margin-right: 33px; |
| 4118 | min-width: 62px; |
| 4119 | padding:5px; |
| 4120 | border:1px solid transparent; |
| 4121 | margin-right: 10px; |
4113 | 4122 | position: relative; |
4114 | 4123 | text-decoration: none; |
4115 | 4124 | text-align: center; |
| 4125 | transition: opacity 0.1s linear; |
| 4126 | opacity: 0.6; |
| 4127 | } |
| 4128 | |
| 4129 | .post-format-options:hover a { |
| 4130 | opacity: 1.0; |
| 4131 | } |
| 4132 | .post-format-options a:hover, |
| 4133 | .post-format-options a.active { |
| 4134 | opacity: 1.0; |
| 4135 | background-color: #fff; |
| 4136 | border-color: #ccc; |
4116 | 4137 | } |
4117 | 4138 | |
4118 | 4139 | .post-format-options a div { |
… |
… |
body .ui-tooltip { |
4127 | 4148 | margin-top: 4px; |
4128 | 4149 | } |
4129 | 4150 | |
4130 | | .post-format-change, .post-format-set .post-format-options { |
| 4151 | .post-format-set .post-format-options { |
4131 | 4152 | display: none; |
4132 | 4153 | } |
4133 | 4154 | |
… |
… |
body .ui-tooltip { |
4150 | 4171 | width: 16px; |
4151 | 4172 | } |
4152 | 4173 | |
4153 | | .post-format-change span.icon.standard { |
| 4174 | .post-format-change span.icon.wp-format-standard { |
4154 | 4175 | background: url(../images/post-formats.png) no-repeat -8px -8px; |
4155 | 4176 | } |
4156 | 4177 | |
4157 | | .post-format-change span.icon.image { |
| 4178 | .post-format-change span.icon.wp-format-image { |
4158 | 4179 | background: url(../images/post-formats.png) no-repeat -40px -8px; |
4159 | 4180 | } |
4160 | 4181 | |
4161 | | .post-format-change span.icon.gallery { |
| 4182 | .post-format-change span.icon.wp-format-gallery { |
4162 | 4183 | background: url(../images/post-formats.png) no-repeat -72px -8px; |
4163 | 4184 | } |
4164 | 4185 | |
4165 | | .post-format-change span.icon.audio { |
| 4186 | .post-format-change span.icon.wp-format-audio { |
4166 | 4187 | background: url(../images/post-formats.png) no-repeat -104px -8px; |
4167 | 4188 | } |
4168 | 4189 | |
4169 | | .post-format-change span.icon.video { |
| 4190 | .post-format-change span.icon.wp-format-video { |
4170 | 4191 | background: url(../images/post-formats.png) no-repeat -136px -8px; |
4171 | 4192 | } |
4172 | 4193 | |
4173 | | .post-format-change span.icon.chat { |
| 4194 | .post-format-change span.icon.wp-format-chat { |
4174 | 4195 | background: url(../images/post-formats.png) no-repeat -168px -8px; |
4175 | 4196 | } |
4176 | 4197 | |
4177 | | .post-format-change span.icon.status { |
| 4198 | .post-format-change span.icon.wp-format-status { |
4178 | 4199 | background: url(../images/post-formats.png) no-repeat -200px -8px; |
4179 | 4200 | } |
4180 | 4201 | |
4181 | | .post-format-change span.icon.aside { |
| 4202 | .post-format-change span.icon.wp-format-aside { |
4182 | 4203 | background: url(../images/post-formats.png) no-repeat -232px -8px; |
4183 | 4204 | } |
4184 | 4205 | |
4185 | | .post-format-change span.icon.quote { |
| 4206 | .post-format-change span.icon.wp-format-quote { |
4186 | 4207 | background: url(../images/post-formats.png) no-repeat -264px -8px; |
4187 | 4208 | } |
4188 | 4209 | |
4189 | | .post-format-change span.icon.link { |
| 4210 | .post-format-change span.icon.wp-format-link { |
4190 | 4211 | background: url(../images/post-formats.png) no-repeat -296px -8px; |
4191 | 4212 | } |
4192 | 4213 | |
diff --git wp-admin/edit-form-advanced.php wp-admin/edit-form-advanced.php
index d92e8c4..454e1da 100644
|
|
if ( post_type_supports( $post_type, 'post-formats' ) && apply_filters( 'enable_ |
135 | 135 | wp_enqueue_script( 'wp-mediaelement' ); |
136 | 136 | wp_enqueue_style( 'wp-mediaelement' ); |
137 | 137 | $post_format = get_post_format(); |
138 | | $post_format_set_class = 'post-format-set'; |
139 | 138 | |
140 | 139 | if ( ! $post_format ) { |
141 | 140 | $post_format = 'standard'; |
142 | 141 | |
143 | 142 | if ( ! empty( $_REQUEST['format'] ) && in_array( $_REQUEST['format'], get_post_format_slugs() ) ) |
144 | 143 | $post_format = $_REQUEST['format']; |
145 | | elseif ( 'auto-draft' == $post->post_status ) |
146 | | $post_format_set_class = ''; |
147 | 144 | } |
148 | 145 | |
149 | 146 | $user_wants = get_user_option( 'post_formats_' . $post_type ); |
… |
… |
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); |
424 | 421 | <div id="poststuff"> |
425 | 422 | <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> |
426 | 423 | <div id="post-body-content"<?php echo $format_class; ?>> |
| 424 | <div class="wp-post-format-ui<?php if ( ! $show_post_format_ui ) echo ' no-ui' ?>"> |
| 425 | <div class="post-format-change"><span class="icon <?php echo esc_attr( 'wp-format-' . $post_format ); ?>"></span> <span class="post-format-description"><?php echo $all_post_formats[$post_format]['description']; ?></span></div> |
| 426 | </div> |
427 | 427 | <?php if ( post_type_supports($post_type, 'title') ) { ?> |
428 | 428 | <div id="titlediv"> |
429 | 429 | <div id="titlewrap"> |
diff --git wp-admin/includes/post-formats.php wp-admin/includes/post-formats.php
index 9571e55..e06d09c 100644
|
|
wp_nonce_field( 'show-post-format-ui_' . $post_type, 'show_post_format_ui_nonce' |
10 | 10 | |
11 | 11 | ?> |
12 | 12 | <div class="wp-post-format-ui<?php if ( ! $show_post_format_ui ) echo ' no-ui' ?>"> |
13 | | <div class="post-format-change"><span class="icon <?php echo esc_attr( $post_format ); ?>"></span> <span class="post-format-description"><?php echo $all_post_formats[$post_format]['description']; ?></span> <a href="#"><?php _e('Change format'); ?></a></div> |
14 | 13 | <div class="post-formats-fields"> |
15 | 14 | |
16 | 15 | <input type="hidden" name="post_format" id="post_format" value="<?php echo esc_attr( $post_format ); ?>" /> |
… |
… |
wp_nonce_field( 'show-post-format-ui_' . $post_type, 'show_post_format_ui_nonce' |
144 | 143 | </div> |
145 | 144 | </div> |
146 | 145 | </div> |
147 | | </div> |
148 | | No newline at end of file |
| 146 | </div> |
diff --git wp-admin/js/post-formats.js wp-admin/js/post-formats.js
index 9344df0..02bf9c5 100644
|
|
|
| 1 | /*globals window, $, jQuery, document, _, postFormats, tinymce, ajaxurl, wp, getUserSetting */ |
| 2 | |
1 | 3 | window.wp = window.wp || {}; |
2 | 4 | |
3 | | (function($) { |
4 | | var container, $container, mediaFrame, lastMimeType, mediaPreview, lastHeight = 360, content, insertMediaButton, |
| 5 | (function ($) { |
| 6 | "use strict"; |
| 7 | |
| 8 | var mediaFrame, insertMediaButton, container, icon, formatField, |
| 9 | lastMimeType, |
| 10 | classRegex = /\s?\bwp-format-[^ ]+/g, |
| 11 | shortHeight = 120, |
| 12 | lastHeight = 360, |
5 | 13 | initialFormat = 'standard', |
6 | 14 | shortClass = 'short-format', |
| 15 | noTitleFormats = ['status'], |
| 16 | noMediaFormats = ['status', 'aside', 'image', 'audio', 'video'], |
7 | 17 | shortContentFormats = ['status', 'aside'], |
8 | | noUIFormats = ['standard', 'chat', 'status', 'aside', 'gallery'], |
9 | | $screenIcon = $( '.icon32' ); |
10 | | |
| 18 | noUIFormats = ['standard', 'chat', 'status', 'aside', 'gallery']; |
11 | 19 | |
12 | 20 | function switchFormatClass( format ) { |
13 | | container.get(0).className = container.get(0).className.replace( /\s?\bwp-format-[^ ]+/g, '' ); |
14 | | container.addClass('wp-format-' + format); |
15 | | $screenIcon.get(0).className = $screenIcon.get(0).className.replace( /\s?\bwp-format-[^ ]+/g, '' ); |
16 | | $screenIcon.addClass('wp-format-' + format); |
| 21 | formatField.val( format ); |
| 22 | |
| 23 | container |
| 24 | .prop( 'className', container.prop( 'className' ).replace( classRegex, '' ) ) |
| 25 | .addClass( 'wp-format-' + format ); |
| 26 | |
| 27 | icon |
| 28 | .prop( 'className', icon.prop( 'className' ).replace( classRegex, '' ) ) |
| 29 | .addClass( 'wp-format-' + format ); |
17 | 30 | } |
18 | 31 | |
19 | 32 | function resizeContent( format, noAnimate ) { |
20 | | var height; |
21 | | |
22 | | content = $('#content, #content_ifr'); |
| 33 | var height, content = $( '#content, #content_ifr' ); |
23 | 34 | |
24 | | height = content.height(); |
25 | | if ( 120 < height ) { |
| 35 | height = content.outerHeight(); |
| 36 | if ( shortHeight < height ) { |
26 | 37 | lastHeight = height; |
27 | 38 | } |
28 | 39 | |
29 | 40 | if ( -1 < $.inArray( format, shortContentFormats ) ) { |
30 | | if ( ! content.hasClass(shortClass) ) { |
31 | | content.addClass(shortClass); |
32 | | if ( noAnimate ) { |
33 | | content.each(function () { |
34 | | $(this).css({ height : 120 }); |
35 | | }); |
36 | | } else { |
37 | | content.each(function () { |
38 | | $(this).animate({ height : 120 }); |
39 | | }); |
40 | | } |
| 41 | if ( ! content.hasClass( shortClass ) ) { |
| 42 | content.addClass( shortClass ); |
| 43 | _(content).each(function (elem) { |
| 44 | $(elem)[noAnimate ? 'css' : 'animate']( { height : shortHeight } ); |
| 45 | }); |
41 | 46 | } |
42 | 47 | } else { |
43 | | content.removeClass(shortClass).animate({ height : lastHeight }); |
| 48 | content.removeClass( shortClass ).animate( { height : lastHeight } ); |
44 | 49 | } |
45 | 50 | } |
46 | 51 | |
47 | | function switchFormat($this) { |
48 | | var editor, body, |
49 | | parent = $this.parent(), |
50 | | format = $this.data('wp-format'), |
51 | | description = $('.post-format-description'), |
52 | | postTitle = $('#title'); |
| 52 | function switchFormat(elem) { |
| 53 | var editor, body, formatTo, formatFrom, |
| 54 | format = elem.data( 'wp-format' ), |
| 55 | titlePrompt = $( '#title-prompt-text' ), |
| 56 | description = $( '.post-format-description' ), |
| 57 | postTitle = $( '#title'), |
| 58 | fields = $( '.post-formats-fields' ), |
| 59 | tinyIcon = $( '.post-format-change span.icon' ); |
| 60 | |
| 61 | if ( format === postFormats.currentPostFormat ) { |
| 62 | return; |
| 63 | } |
53 | 64 | |
54 | | if ( typeof container === 'undefined' ) |
55 | | container = $('#post-body-content'); |
| 65 | elem.addClass( 'active' ).siblings().removeClass( 'active' ); |
56 | 66 | |
57 | | parent.slideUp().find('a.active').removeClass('active'); |
58 | | $this.addClass('active'); |
59 | | $('#post_format').val(format); |
60 | | $('.post-format-change').show().find('span.icon').removeClass(postFormats.currentPostFormat).addClass(format); |
| 67 | // Animate the media button going away or coming back |
| 68 | formatTo = -1 < $.inArray( format, noMediaFormats ); |
| 69 | formatFrom = -1 < $.inArray( postFormats.currentPostFormat, noMediaFormats ); |
| 70 | if ( formatFrom ? !formatTo : formatTo ) { // XOR |
| 71 | insertMediaButton.fadeToggle( 200 ).css( 'display', 'inline-block' ); |
| 72 | } |
| 73 | // Animate the title going away or coming back |
| 74 | formatTo = -1 < $.inArray( format, noTitleFormats ); |
| 75 | formatFrom = -1 < $.inArray( postFormats.currentPostFormat, noTitleFormats ); |
| 76 | if ( formatFrom ? !formatTo : formatTo ) { // XOR |
| 77 | $( '#titlewrap' ).fadeToggle( 200 ); |
| 78 | } |
61 | 79 | |
62 | | if ( -1 < $.inArray( format, noUIFormats ) ) { |
| 80 | if ( -1 < $.inArray( format, noUIFormats ) && -1 < $.inArray( postFormats.currentPostFormat, noUIFormats ) ) { |
63 | 81 | switchFormatClass( format ); // No slide |
64 | | $container.hide(); |
| 82 | fields.slideUp(); |
65 | 83 | } else { |
66 | | $container.slideUp( 200, function(){ |
| 84 | fields.slideUp( 400, function () { |
67 | 85 | switchFormatClass( format ); |
68 | | $container.slideDown( 400 ); |
| 86 | if ( -1 === $.inArray( format, noUIFormats ) ) { |
| 87 | fields.slideDown( 400 ); |
| 88 | } |
69 | 89 | }); |
70 | 90 | } |
71 | 91 | |
72 | 92 | resizeContent( format ); |
73 | | |
74 | 93 | postTitle.focus(); |
75 | 94 | |
76 | | if ( '' === postTitle.val() ) |
77 | | $('#title-prompt-text').removeClass('screen-reader-text'); |
| 95 | if ( '' === postTitle.val() ) { |
| 96 | titlePrompt.removeClass( 'screen-reader-text' ); |
78 | 97 | |
79 | | // Update description line |
80 | | description.html($this.data('description')); |
| 98 | postTitle.keydown( function (e) { |
| 99 | titlePrompt.addClass( 'screen-reader-text' ); |
| 100 | $( e.currentTarget ).unbind( e ); |
| 101 | } ); |
| 102 | } |
81 | 103 | |
82 | | if (description.not(':visible')) |
83 | | description.slideDown('fast'); |
| 104 | // Update description line |
| 105 | description.html( elem.data( 'description' ) ); |
| 106 | tinyIcon |
| 107 | .show() |
| 108 | .prop( 'className', tinyIcon.prop( 'className' ).replace( classRegex, '' ) ) |
| 109 | .addClass( 'wp-format-' + format ); |
| 110 | |
| 111 | if ( description.not( ':visible' ) ) { |
| 112 | description.slideDown( 'fast' ); |
| 113 | } |
84 | 114 | |
85 | | if ( typeof tinymce != 'undefined' ) { |
86 | | editor = tinymce.get('content'); |
| 115 | if ( tinymce ) { |
| 116 | editor = tinymce.get( 'content' ); |
87 | 117 | |
88 | 118 | if ( editor ) { |
89 | 119 | body = editor.getBody(); |
… |
… |
window.wp = window.wp || {}; |
94 | 124 | |
95 | 125 | // If gallery, force it to open to gallery state |
96 | 126 | insertMediaButton.toggleClass( 'gallery', 'gallery' === format ); |
97 | | |
98 | 127 | postFormats.currentPostFormat = format; |
99 | 128 | } |
100 | 129 | |
101 | | |
102 | | |
103 | | $(function() { |
| 130 | $(function () { |
| 131 | container = $( '#post-body-content' ); |
| 132 | icon = $( '.icon32' ); |
| 133 | formatField = $( '#post_format' ); |
104 | 134 | insertMediaButton = $( '#insert-media-button' ).toggleClass( 'gallery', 'gallery' === postFormats.currentPostFormat ); |
105 | | $container = $( '.post-formats-fields' ); |
106 | | |
107 | 135 | initialFormat = $( '.post-format-options .active' ).data( 'wp-format' ); |
| 136 | |
108 | 137 | if ( -1 < $.inArray( initialFormat, shortContentFormats ) ) { |
109 | 138 | resizeContent( initialFormat, true ); |
110 | 139 | } |
111 | 140 | |
112 | | $('#show_post_format_ui').on('change', function() { |
113 | | $('.wp-post-format-ui').toggleClass('no-ui', ! this.checked ); |
| 141 | $( '#show_post_format_ui' ).on( 'change', function () { |
| 142 | $( '.wp-post-format-ui' ).toggleClass( 'no-ui', ! this.checked ); |
114 | 143 | $.post( ajaxurl, { |
115 | 144 | action: 'show-post-format-ui', |
116 | | post_type: $('#post_type').val(), |
| 145 | post_type: $( '#post_type' ).val(), |
117 | 146 | show: this.checked ? 1 : 0, |
118 | | nonce: $('#show_post_format_ui_nonce').val() |
119 | | }); |
120 | | }); |
121 | | |
122 | | $('.post-format-change a').click(function() { |
123 | | $('.post-formats-fields, .post-format-change').slideUp(); |
124 | | $('.post-format-options').slideDown(); |
125 | | return false; |
126 | | }); |
| 147 | nonce: $( '#show_post_format_ui_nonce' ).val() |
| 148 | } ); |
| 149 | } ); |
127 | 150 | |
128 | 151 | // Post formats selection |
129 | | $('.post-format-options').on( 'click', 'a', function (e) { |
| 152 | $( '.post-format-options' ).on( 'click', 'a', function (e) { |
130 | 153 | e.preventDefault(); |
131 | | switchFormat($(this)); |
132 | | }); |
| 154 | switchFormat( $( e.currentTarget ) ); |
| 155 | } ); |
133 | 156 | |
134 | 157 | // Media selection |
135 | | $('.wp-format-media-select').click(function(event) { |
136 | | event.preventDefault(); |
137 | | var $el = $(this), mime = 'image', |
138 | | $holder = $el.closest('.wp-format-media-holder'), |
139 | | $field = $( '#wp_format_' + $holder.data('format') ); |
| 158 | $( '.wp-format-media-select' ).click( function (e) { |
| 159 | e.preventDefault(); |
140 | 160 | |
141 | | mime = $holder.data('format'); |
| 161 | var $el = $(e.currentTarget), mediaPreview, mime = 'image', $holder, $field; |
| 162 | |
| 163 | $holder = $el.closest( '.wp-format-media-holder' ); |
| 164 | $field = $( '#wp_format_' + $holder.data( 'format' ) ); |
| 165 | mime = $holder.data( 'format' ); |
142 | 166 | |
143 | 167 | // If the media frame already exists, reopen it. |
144 | 168 | if ( mediaFrame && lastMimeType === mime ) { |
… |
… |
window.wp = window.wp || {}; |
150 | 174 | |
151 | 175 | mediaFrame = wp.media.frames.formatMedia = wp.media( { |
152 | 176 | button: { |
153 | | text: $el.data('update') |
| 177 | text: $el.data( 'update' ) |
154 | 178 | }, |
155 | 179 | states: [ |
156 | 180 | new wp.media.controller.Library({ |
157 | 181 | library: wp.media.query( { type: mime } ), |
158 | | title: $el.data('choose'), |
| 182 | title: $el.data( 'choose' ), |
159 | 183 | displaySettings: 'image' === mime |
160 | 184 | }) |
161 | 185 | ] |
162 | 186 | } ); |
163 | 187 | |
164 | | mediaPreview = function(attachment) { |
| 188 | mediaPreview = function (attachment) { |
165 | 189 | var w, h, dimensions = '', url = attachment.url, mime = attachment.mime, format = attachment.type; |
166 | 190 | |
167 | 191 | if ( 'video' === format ) { |
168 | 192 | if ( attachment.width ) { |
169 | 193 | w = attachment.width; |
170 | | if ( w > 600 ) |
| 194 | if ( w > 600 ) { |
171 | 195 | w = 600; |
| 196 | } |
172 | 197 | dimensions += ' width="' + w + '"'; |
173 | 198 | } |
174 | 199 | |
175 | 200 | if ( attachment.height ) { |
176 | 201 | h = attachment.height; |
177 | | if ( attachment.width && w < attachment.width ) |
| 202 | if ( attachment.width && w < attachment.width ) { |
178 | 203 | h = Math.round( ( h * w ) / attachment.width ); |
| 204 | } |
179 | 205 | dimensions += ' height="' + h + '"'; |
180 | 206 | } |
181 | 207 | } |
182 | 208 | |
183 | | $('#' + format + '-preview').remove(); |
| 209 | $( '#' + format + '-preview' ).remove(); |
184 | 210 | $holder.parent().prepend( '<div id="' + format + '-preview" class="wp-format-media-preview">' + |
185 | 211 | '<' + format + dimensions + ' class="wp-' + format + '-shortcode" controls="controls" preload="none">' + |
186 | 212 | '<source type="' + mime + '" src="' + url + '" />' + |
187 | 213 | '</' + format + '></div>' ); |
188 | | $('.wp-' + format + '-shortcode').mediaelementplayer(); |
| 214 | $( '.wp-' + format + '-shortcode' ).mediaelementplayer(); |
189 | 215 | }; |
190 | 216 | |
191 | 217 | // When an image is selected, run a callback. |
192 | | mediaFrame.on( 'select', function() { |
| 218 | mediaFrame.on( 'select', function () { |
193 | 219 | // Grab the selected attachment. |
194 | | var w = 0, h = 0, html, attachment = mediaFrame.state().get('selection').first().toJSON(); |
| 220 | var w = 0, h = 0, html, attachment = mediaFrame.state().get( 'selection' ).first().toJSON(); |
195 | 221 | |
196 | | if ( 0 === attachment.mime.indexOf('audio') ) { |
197 | | $field.val(attachment.url); |
| 222 | if ( 0 === attachment.mime.indexOf( 'audio' ) ) { |
| 223 | $field.val( attachment.url ); |
198 | 224 | // show one preview at a time |
199 | | mediaPreview(attachment); |
200 | | } else if ( 0 === attachment.mime.indexOf('video') ) { |
| 225 | mediaPreview( attachment ); |
| 226 | } else if ( 0 === attachment.mime.indexOf( 'video' ) ) { |
201 | 227 | attachment.src = attachment.url; |
202 | | $field.val(wp.shortcode.string({ |
| 228 | $field.val( wp.shortcode.string( { |
203 | 229 | tag: 'video', |
204 | 230 | attrs: _.pick( attachment, 'src', 'width', 'height' ) |
205 | | })); |
| 231 | } ) ); |
206 | 232 | // show one preview at a time |
207 | | mediaPreview(attachment); |
| 233 | mediaPreview( attachment ); |
208 | 234 | } else { |
209 | 235 | html = wp.media.string.image({ |
210 | | align : getUserSetting('align'), |
211 | | size : getUserSetting('imgsize'), |
212 | | link : getUserSetting('urlbutton') |
| 236 | align : getUserSetting( 'align' ), |
| 237 | size : getUserSetting( 'imgsize' ), |
| 238 | link : getUserSetting( 'urlbutton' ) |
213 | 239 | }, attachment); |
| 240 | |
214 | 241 | // set the hidden input's value |
215 | | $field.val(html); |
216 | | $('#image-preview').remove(); |
217 | | if ( attachment.width ) |
| 242 | $field.val( html ); |
| 243 | |
| 244 | $( '#image-preview' ).remove(); |
| 245 | |
| 246 | if ( attachment.width ) { |
218 | 247 | w = attachment.width > 600 ? 600 : attachment.width; |
219 | | if ( attachment.height ) |
| 248 | } |
| 249 | |
| 250 | if ( attachment.height ) { |
220 | 251 | h = attachment.height; |
221 | | if ( w < attachment.width ) |
| 252 | } |
| 253 | |
| 254 | if ( w < attachment.width ) { |
222 | 255 | h = Math.round( ( h * w ) / attachment.width ); |
| 256 | } |
| 257 | |
223 | 258 | $holder.parent().prepend( ['<div id="image-preview" class="wp-format-media-preview">', |
224 | 259 | '<img src="', attachment.url, '"', |
225 | 260 | w ? ' width="' + w + '"' : '', |
226 | 261 | h ? ' height="' + h + '"' : '', |
227 | 262 | ' />', |
228 | | '</div>'].join('') ); |
| 263 | '</div>'].join( '' ) ); |
229 | 264 | } |
230 | 265 | }); |
231 | 266 | |
232 | 267 | mediaFrame.open(); |
233 | 268 | }); |
234 | 269 | }); |
235 | | })(jQuery); |
| 270 | }( jQuery ) ); |