1 var tagBox, commentsBox, editPermalink, makeSlugeditClickable, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint; |
1 /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */ |
2 |
2 /* global theList:true, theExtraList:true, getUserSetting, setUserSetting */ |
3 // return an array with any duplicate, whitespace or values removed |
3 |
4 function array_unique_noempty(a) { |
4 var commentsBox, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint, makeSlugeditClickable, editPermalink; |
5 var out = []; |
5 // Back-compat: prevent fatal errors |
6 jQuery.each( a, function(key, val) { |
6 makeSlugeditClickable = editPermalink = function(){}; |
7 val = jQuery.trim(val); |
7 |
8 if ( val && jQuery.inArray(val, out) == -1 ) |
8 window.wp = window.wp || {}; |
9 out.push(val); |
9 |
10 } ); |
10 ( function( $ ) { |
11 return out; |
11 var titleHasFocus = false; |
12 } |
|
13 |
|
14 (function($){ |
|
15 |
|
16 tagBox = { |
|
17 clean : function(tags) { |
|
18 var comma = postL10n.comma; |
|
19 if ( ',' !== comma ) |
|
20 tags = tags.replace(new RegExp(comma, 'g'), ','); |
|
21 tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, ''); |
|
22 if ( ',' !== comma ) |
|
23 tags = tags.replace(/,/g, comma); |
|
24 return tags; |
|
25 }, |
|
26 |
|
27 parseTags : function(el) { |
|
28 var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'), |
|
29 thetags = taxbox.find('.the-tags'), comma = postL10n.comma, |
|
30 current_tags = thetags.val().split(comma), new_tags = []; |
|
31 delete current_tags[num]; |
|
32 |
|
33 $.each( current_tags, function(key, val) { |
|
34 val = $.trim(val); |
|
35 if ( val ) { |
|
36 new_tags.push(val); |
|
37 } |
|
38 }); |
|
39 |
|
40 thetags.val( this.clean( new_tags.join(comma) ) ); |
|
41 |
|
42 this.quickClicks(taxbox); |
|
43 return false; |
|
44 }, |
|
45 |
|
46 quickClicks : function(el) { |
|
47 var thetags = $('.the-tags', el), |
|
48 tagchecklist = $('.tagchecklist', el), |
|
49 id = $(el).attr('id'), |
|
50 current_tags, disabled; |
|
51 |
|
52 if ( !thetags.length ) |
|
53 return; |
|
54 |
|
55 disabled = thetags.prop('disabled'); |
|
56 |
|
57 current_tags = thetags.val().split(postL10n.comma); |
|
58 tagchecklist.empty(); |
|
59 |
|
60 $.each( current_tags, function( key, val ) { |
|
61 var span, xbutton; |
|
62 |
|
63 val = $.trim( val ); |
|
64 |
|
65 if ( ! val ) |
|
66 return; |
|
67 |
|
68 // Create a new span, and ensure the text is properly escaped. |
|
69 span = $('<span />').text( val ); |
|
70 |
|
71 // If tags editing isn't disabled, create the X button. |
|
72 if ( ! disabled ) { |
|
73 xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' ); |
|
74 xbutton.click( function(){ tagBox.parseTags(this); }); |
|
75 span.prepend(' ').prepend( xbutton ); |
|
76 } |
|
77 |
|
78 // Append the span to the tag list. |
|
79 tagchecklist.append( span ); |
|
80 }); |
|
81 }, |
|
82 |
|
83 flushTags : function(el, a, f) { |
|
84 a = a || false; |
|
85 var tags = $('.the-tags', el), |
|
86 newtag = $('input.newtag', el), |
|
87 comma = postL10n.comma, |
|
88 newtags, text; |
|
89 |
|
90 text = a ? $(a).text() : newtag.val(); |
|
91 tagsval = tags.val(); |
|
92 newtags = tagsval ? tagsval + comma + text : text; |
|
93 |
|
94 newtags = this.clean( newtags ); |
|
95 newtags = array_unique_noempty( newtags.split(comma) ).join(comma); |
|
96 tags.val(newtags); |
|
97 this.quickClicks(el); |
|
98 |
|
99 if ( !a ) |
|
100 newtag.val(''); |
|
101 if ( 'undefined' == typeof(f) ) |
|
102 newtag.focus(); |
|
103 |
|
104 return false; |
|
105 }, |
|
106 |
|
107 get : function(id) { |
|
108 var tax = id.substr(id.indexOf('-')+1); |
|
109 |
|
110 $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) { |
|
111 if ( 0 == r || 'success' != stat ) |
|
112 r = wpAjax.broken; |
|
113 |
|
114 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>'); |
|
115 $('a', r).click(function(){ |
|
116 tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this); |
|
117 return false; |
|
118 }); |
|
119 |
|
120 $('#'+id).after(r); |
|
121 }); |
|
122 }, |
|
123 |
|
124 init : function() { |
|
125 var t = this, ajaxtag = $('div.ajaxtag'); |
|
126 |
|
127 $('.tagsdiv').each( function() { |
|
128 tagBox.quickClicks(this); |
|
129 }); |
|
130 |
|
131 $('input.tagadd', ajaxtag).click(function(){ |
|
132 t.flushTags( $(this).closest('.tagsdiv') ); |
|
133 }); |
|
134 |
|
135 $('div.taghint', ajaxtag).click(function(){ |
|
136 $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus(); |
|
137 }); |
|
138 |
|
139 $('input.newtag', ajaxtag).blur(function() { |
|
140 if ( this.value == '' ) |
|
141 $(this).parent().siblings('.taghint').css('visibility', ''); |
|
142 }).focus(function(){ |
|
143 $(this).parent().siblings('.taghint').css('visibility', 'hidden'); |
|
144 }).keyup(function(e){ |
|
145 if ( 13 == e.which ) { |
|
146 tagBox.flushTags( $(this).closest('.tagsdiv') ); |
|
147 return false; |
|
148 } |
|
149 }).keypress(function(e){ |
|
150 if ( 13 == e.which ) { |
|
151 e.preventDefault(); |
|
152 return false; |
|
153 } |
|
154 }).each(function(){ |
|
155 var tax = $(this).closest('div.tagsdiv').attr('id'); |
|
156 $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } ); |
|
157 }); |
|
158 |
|
159 // save tags on post save/publish |
|
160 $('#post').submit(function(){ |
|
161 $('div.tagsdiv').each( function() { |
|
162 tagBox.flushTags(this, false, 1); |
|
163 }); |
|
164 }); |
|
165 |
|
166 // tag cloud |
|
167 $('a.tagcloud-link').click(function(){ |
|
168 tagBox.get( $(this).attr('id') ); |
|
169 $(this).unbind().click(function(){ |
|
170 $(this).siblings('.the-tagcloud').toggle(); |
|
171 return false; |
|
172 }); |
|
173 return false; |
|
174 }); |
|
175 } |
|
176 }; |
|
177 |
12 |
178 commentsBox = { |
13 commentsBox = { |
179 st : 0, |
14 st : 0, |
180 |
15 |
181 get : function(total, num) { |
16 get : function(total, num) { |
257 send = {}; |
92 send = {}; |
258 |
93 |
259 if ( ! post_id || ! $('#post-lock-dialog').length ) |
94 if ( ! post_id || ! $('#post-lock-dialog').length ) |
260 return; |
95 return; |
261 |
96 |
262 send['post_id'] = post_id; |
97 send.post_id = post_id; |
263 |
98 |
264 if ( lock ) |
99 if ( lock ) |
265 send['lock'] = lock; |
100 send.lock = lock; |
266 |
101 |
267 data['wp-refresh-post-lock'] = send; |
102 data['wp-refresh-post-lock'] = send; |
268 }); |
103 |
269 |
104 }).on( 'heartbeat-tick.refresh-lock', function( e, data ) { |
270 // Post locks: update the lock string or show the dialog if somebody has taken over editing |
105 // Post locks: update the lock string or show the dialog if somebody has taken over editing |
271 $(document).on( 'heartbeat-tick.refresh-lock', function( e, data ) { |
|
272 var received, wrap, avatar; |
106 var received, wrap, avatar; |
273 |
107 |
274 if ( data['wp-refresh-post-lock'] ) { |
108 if ( data['wp-refresh-post-lock'] ) { |
275 received = data['wp-refresh-post-lock']; |
109 received = data['wp-refresh-post-lock']; |
276 |
110 |
277 if ( received.lock_error ) { |
111 if ( received.lock_error ) { |
278 // show "editing taken over" message |
112 // show "editing taken over" message |
279 wrap = $('#post-lock-dialog'); |
113 wrap = $('#post-lock-dialog'); |
280 |
114 |
281 if ( wrap.length && ! wrap.is(':visible') ) { |
115 if ( wrap.length && ! wrap.is(':visible') ) { |
282 if ( typeof autosave == 'function' ) { |
116 if ( wp.autosave ) { |
283 $(document).on('autosave-disable-buttons.post-lock', function() { |
117 // Save the latest changes and disable |
284 wrap.addClass('saving'); |
118 $(document).one( 'heartbeat-tick', function() { |
285 }).on('autosave-enable-buttons.post-lock', function() { |
119 wp.autosave.server.suspend(); |
286 wrap.removeClass('saving').addClass('saved'); |
120 wrap.removeClass('saving').addClass('saved'); |
287 window.onbeforeunload = null; |
121 $(window).off( 'beforeunload.edit-post' ); |
288 }); |
122 }); |
289 |
123 |
290 // Save the latest changes and disable |
124 wrap.addClass('saving'); |
291 if ( ! autosave() ) |
125 wp.autosave.server.triggerSave(); |
292 window.onbeforeunload = null; |
|
293 |
|
294 autosave = function(){}; |
|
295 } |
126 } |
296 |
127 |
297 if ( received.lock_error.avatar_src ) { |
128 if ( received.lock_error.avatar_src ) { |
298 avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&/g, '&') ); |
129 avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&/g, '&') ); |
299 wrap.find('div.post-locked-avatar').empty().append( avatar ); |
130 wrap.find('div.post-locked-avatar').empty().append( avatar ); |
369 $(this).find('.wp-tab-first').focus(); |
234 $(this).find('.wp-tab-first').focus(); |
370 e.preventDefault(); |
235 e.preventDefault(); |
371 } |
236 } |
372 }).filter(':visible').find('.wp-tab-first').focus(); |
237 }).filter(':visible').find('.wp-tab-first').focus(); |
373 |
238 |
|
239 // Set the heartbeat interval to 15 sec. if post lock dialogs are enabled |
|
240 if ( wp.heartbeat && $('#post-lock-dialog').length ) { |
|
241 wp.heartbeat.interval( 15 ); |
|
242 } |
|
243 |
|
244 // The form is being submitted by the user |
|
245 $submitButtons = $submitpost.find( ':submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) { |
|
246 var $button = $(this); |
|
247 |
|
248 if ( $button.hasClass('disabled') ) { |
|
249 event.preventDefault(); |
|
250 return; |
|
251 } |
|
252 |
|
253 if ( $button.hasClass('submitdelete') || $button.is( '#post-preview' ) ) { |
|
254 return; |
|
255 } |
|
256 |
|
257 // The form submission can be blocked from JS or by using HTML 5.0 validation on some fields. |
|
258 // Run this only on an actual 'submit'. |
|
259 $('form#post').off( 'submit.edit-post' ).on( 'submit.edit-post', function( event ) { |
|
260 if ( event.isDefaultPrevented() ) { |
|
261 return; |
|
262 } |
|
263 |
|
264 // Stop autosave |
|
265 if ( wp.autosave ) { |
|
266 wp.autosave.server.suspend(); |
|
267 } |
|
268 |
|
269 releaseLock = false; |
|
270 $(window).off( 'beforeunload.edit-post' ); |
|
271 |
|
272 $submitButtons.addClass( 'disabled' ); |
|
273 |
|
274 if ( $button.attr('id') === 'publish' ) { |
|
275 $submitpost.find( '#major-publishing-actions .spinner' ).addClass( 'is-active' ); |
|
276 } else { |
|
277 $submitpost.find( '#minor-publishing .spinner' ).addClass( 'is-active' ); |
|
278 } |
|
279 }); |
|
280 }); |
|
281 |
|
282 // Submit the form saving a draft or an autosave, and show a preview in a new tab |
|
283 $('#post-preview').on( 'click.post-preview', function( event ) { |
|
284 var $this = $(this), |
|
285 $form = $('form#post'), |
|
286 $previewField = $('input#wp-preview'), |
|
287 target = $this.attr('target') || 'wp-preview', |
|
288 ua = navigator.userAgent.toLowerCase(); |
|
289 |
|
290 event.preventDefault(); |
|
291 |
|
292 if ( $this.hasClass('disabled') ) { |
|
293 return; |
|
294 } |
|
295 |
|
296 if ( wp.autosave ) { |
|
297 wp.autosave.server.tempBlockSave(); |
|
298 } |
|
299 |
|
300 $previewField.val('dopreview'); |
|
301 $form.attr( 'target', target ).submit().attr( 'target', '' ); |
|
302 |
|
303 // Workaround for WebKit bug preventing a form submitting twice to the same action. |
|
304 // https://bugs.webkit.org/show_bug.cgi?id=28633 |
|
305 if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) { |
|
306 $form.attr( 'action', function( index, value ) { |
|
307 return value + '?t=' + ( new Date() ).getTime(); |
|
308 }); |
|
309 } |
|
310 |
|
311 $previewField.val(''); |
|
312 }); |
|
313 |
|
314 // This code is meant to allow tabbing from Title to Post content. |
|
315 $('#title').on( 'keydown.editor-focus', function( event ) { |
|
316 var editor, $textarea; |
|
317 |
|
318 if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) { |
|
319 editor = typeof tinymce != 'undefined' && tinymce.get('content'); |
|
320 $textarea = $('#content'); |
|
321 |
|
322 if ( editor && ! editor.isHidden() ) { |
|
323 editor.focus(); |
|
324 } else if ( $textarea.length ) { |
|
325 $textarea.focus(); |
|
326 } else { |
|
327 return; |
|
328 } |
|
329 |
|
330 event.preventDefault(); |
|
331 } |
|
332 }); |
|
333 |
|
334 // Autosave new posts after a title is typed |
|
335 if ( $( '#auto_draft' ).val() ) { |
|
336 $( '#title' ).blur( function() { |
|
337 var cancel; |
|
338 |
|
339 if ( ! this.value || $('#edit-slug-box > *').length ) { |
|
340 return; |
|
341 } |
|
342 |
|
343 // Cancel the autosave when the blur was triggered by the user submitting the form |
|
344 $('form#post').one( 'submit', function() { |
|
345 cancel = true; |
|
346 }); |
|
347 |
|
348 window.setTimeout( function() { |
|
349 if ( ! cancel && wp.autosave ) { |
|
350 wp.autosave.server.triggerSave(); |
|
351 } |
|
352 }, 200 ); |
|
353 }); |
|
354 } |
|
355 |
|
356 $document.on( 'autosave-disable-buttons.edit-post', function() { |
|
357 $submitButtons.addClass( 'disabled' ); |
|
358 }).on( 'autosave-enable-buttons.edit-post', function() { |
|
359 if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) { |
|
360 $submitButtons.removeClass( 'disabled' ); |
|
361 } |
|
362 }).on( 'before-autosave.edit-post', function() { |
|
363 $( '.autosave-message' ).text( postL10n.savingText ); |
|
364 }).on( 'after-autosave.edit-post', function( event, data ) { |
|
365 $( '.autosave-message' ).text( data.message ); |
|
366 }); |
|
367 |
|
368 $(window).on( 'beforeunload.edit-post', function() { |
|
369 var editor = typeof tinymce !== 'undefined' && tinymce.get('content'); |
|
370 |
|
371 if ( ( editor && ! editor.isHidden() && editor.isDirty() ) || |
|
372 ( wp.autosave && wp.autosave.server.postChanged() ) ) { |
|
373 |
|
374 return postL10n.saveAlert; |
|
375 } |
|
376 }).on( 'unload.edit-post', function( event ) { |
|
377 if ( ! releaseLock ) { |
|
378 return; |
|
379 } |
|
380 |
|
381 // Unload is triggered (by hand) on removing the Thickbox iframe. |
|
382 // Make sure we process only the main document unload. |
|
383 if ( event.target && event.target.nodeName != '#document' ) { |
|
384 return; |
|
385 } |
|
386 |
|
387 $.ajax({ |
|
388 type: 'POST', |
|
389 url: ajaxurl, |
|
390 async: false, |
|
391 data: { |
|
392 action: 'wp-remove-post-lock', |
|
393 _wpnonce: $('#_wpnonce').val(), |
|
394 post_ID: $('#post_ID').val(), |
|
395 active_post_lock: $('#active_post_lock').val() |
|
396 } |
|
397 }); |
|
398 }); |
|
399 |
374 // multi-taxonomies |
400 // multi-taxonomies |
375 if ( $('#tagsdiv-post_tag').length ) { |
401 if ( $('#tagsdiv-post_tag').length ) { |
376 tagBox.init(); |
402 window.tagBox && window.tagBox.init(); |
377 } else { |
403 } else { |
378 $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){ |
404 $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){ |
379 if ( this.id.indexOf('tagsdiv-') === 0 ) { |
405 if ( this.id.indexOf('tagsdiv-') === 0 ) { |
380 tagBox.init(); |
406 window.tagBox && window.tagBox.init(); |
381 return false; |
407 return false; |
382 } |
408 } |
383 }); |
409 }); |
384 } |
410 } |
385 |
411 |
475 // submitdiv |
501 // submitdiv |
476 if ( $('#submitdiv').length ) { |
502 if ( $('#submitdiv').length ) { |
477 stamp = $('#timestamp').html(); |
503 stamp = $('#timestamp').html(); |
478 visibility = $('#post-visibility-display').html(); |
504 visibility = $('#post-visibility-display').html(); |
479 |
505 |
480 function updateVisibility() { |
506 updateVisibility = function() { |
481 var pvSelect = $('#post-visibility-select'); |
507 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) { |
482 if ( $('input:radio:checked', pvSelect).val() != 'public' ) { |
|
483 $('#sticky').prop('checked', false); |
508 $('#sticky').prop('checked', false); |
484 $('#sticky-span').hide(); |
509 $('#sticky-span').hide(); |
485 } else { |
510 } else { |
486 $('#sticky-span').show(); |
511 $('#sticky-span').show(); |
487 } |
512 } |
488 if ( $('input:radio:checked', pvSelect).val() != 'password' ) { |
513 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) { |
489 $('#password-span').hide(); |
514 $('#password-span').hide(); |
490 } else { |
515 } else { |
491 $('#password-span').show(); |
516 $('#password-span').show(); |
492 } |
517 } |
493 } |
518 }; |
494 |
519 |
495 function updateText() { |
520 updateText = function() { |
496 |
521 |
497 if ( ! $('#timestampdiv').length ) |
522 if ( ! $timestampdiv.length ) |
498 return true; |
523 return true; |
499 |
524 |
500 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'), |
525 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'), |
501 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(), |
526 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(), |
502 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(); |
527 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(); |
529 publishOn + ' <b>' + |
554 publishOn + ' <b>' + |
530 postL10n.dateFormat.replace( '%1$s', $('option[value="' + $('#mm').val() + '"]', '#mm').text() ) |
555 postL10n.dateFormat.replace( '%1$s', $('option[value="' + $('#mm').val() + '"]', '#mm').text() ) |
531 .replace( '%2$s', jj ) |
556 .replace( '%2$s', jj ) |
532 .replace( '%3$s', aa ) |
557 .replace( '%3$s', aa ) |
533 .replace( '%4$s', hh ) |
558 .replace( '%4$s', hh ) |
534 .replace( '%5$s', mn ) |
559 .replace( '%5$s', mn ) + |
535 + '</b> ' |
560 '</b> ' |
536 ); |
561 ); |
537 } |
562 } |
538 |
563 |
539 if ( $('input:radio:checked', '#post-visibility-select').val() == 'private' ) { |
564 if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) { |
540 $('#publish').val( postL10n.update ); |
565 $('#publish').val( postL10n.update ); |
541 if ( optPublish.length == 0 ) { |
566 if ( 0 === optPublish.length ) { |
542 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>'); |
567 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>'); |
543 } else { |
568 } else { |
544 optPublish.html( postL10n.privatelyPublished ); |
569 optPublish.html( postL10n.privatelyPublished ); |
545 } |
570 } |
546 $('option[value="publish"]', postStatus).prop('selected', true); |
571 $('option[value="publish"]', postStatus).prop('selected', true); |
547 $('.edit-post-status', '#misc-publishing-actions').hide(); |
572 $('#misc-publishing-actions .edit-post-status').hide(); |
548 } else { |
573 } else { |
549 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) { |
574 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) { |
550 if ( optPublish.length ) { |
575 if ( optPublish.length ) { |
551 optPublish.remove(); |
576 optPublish.remove(); |
552 postStatus.val($('#hidden_post_status').val()); |
577 postStatus.val($('#hidden_post_status').val()); |
553 } |
578 } |
554 } else { |
579 } else { |
555 optPublish.html( postL10n.published ); |
580 optPublish.html( postL10n.published ); |
556 } |
581 } |
557 if ( postStatus.is(':hidden') ) |
582 if ( postStatus.is(':hidden') ) |
558 $('.edit-post-status', '#misc-publishing-actions').show(); |
583 $('#misc-publishing-actions .edit-post-status').show(); |
559 } |
584 } |
560 $('#post-status-display').html($('option:selected', postStatus).text()); |
585 $('#post-status-display').html($('option:selected', postStatus).text()); |
561 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) { |
586 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) { |
562 $('#save-post').hide(); |
587 $('#save-post').hide(); |
563 } else { |
588 } else { |
567 } else { |
592 } else { |
568 $('#save-post').show().val( postL10n.saveDraft ); |
593 $('#save-post').show().val( postL10n.saveDraft ); |
569 } |
594 } |
570 } |
595 } |
571 return true; |
596 return true; |
572 } |
597 }; |
573 |
598 |
574 $('.edit-visibility', '#visibility').click(function () { |
599 $( '#visibility .edit-visibility').click( function () { |
575 if ($('#post-visibility-select').is(":hidden")) { |
600 if ( $postVisibilitySelect.is(':hidden') ) { |
576 updateVisibility(); |
601 updateVisibility(); |
577 $('#post-visibility-select').slideDown('fast'); |
602 $postVisibilitySelect.slideDown('fast').find('input[type="radio"]').first().focus(); |
578 $(this).hide(); |
603 $(this).hide(); |
579 } |
604 } |
580 return false; |
605 return false; |
581 }); |
606 }); |
582 |
607 |
583 $('.cancel-post-visibility', '#post-visibility-select').click(function () { |
608 $postVisibilitySelect.find('.cancel-post-visibility').click( function( event ) { |
584 $('#post-visibility-select').slideUp('fast'); |
609 $postVisibilitySelect.slideUp('fast'); |
585 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true); |
610 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true); |
586 $('#post_password').val($('#hidden-post-password').val()); |
611 $('#post_password').val($('#hidden-post-password').val()); |
587 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked')); |
612 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked')); |
588 $('#post-visibility-display').html(visibility); |
613 $('#post-visibility-display').html(visibility); |
589 $('.edit-visibility', '#visibility').show(); |
614 $('#visibility .edit-visibility').show().focus(); |
590 updateText(); |
615 updateText(); |
591 return false; |
616 event.preventDefault(); |
592 }); |
617 }); |
593 |
618 |
594 $('.save-post-visibility', '#post-visibility-select').click(function () { // crazyhorse - multiple ok cancels |
619 $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // crazyhorse - multiple ok cancels |
595 var pvSelect = $('#post-visibility-select'); |
620 $postVisibilitySelect.slideUp('fast'); |
596 |
621 $('#visibility .edit-visibility').show(); |
597 pvSelect.slideUp('fast'); |
|
598 $('.edit-visibility', '#visibility').show(); |
|
599 updateText(); |
622 updateText(); |
600 |
623 |
601 if ( $('input:radio:checked', pvSelect).val() != 'public' ) { |
624 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) { |
602 $('#sticky').prop('checked', false); |
625 $('#sticky').prop('checked', false); |
603 } // WEAPON LOCKED |
626 } // WEAPON LOCKED |
604 |
627 |
605 if ( true == $('#sticky').prop('checked') ) { |
628 if ( $('#sticky').prop('checked') ) { |
606 sticky = 'Sticky'; |
629 sticky = 'Sticky'; |
607 } else { |
630 } else { |
608 sticky = ''; |
631 sticky = ''; |
609 } |
632 } |
610 |
633 |
611 $('#post-visibility-display').html( postL10n[$('input:radio:checked', pvSelect).val() + sticky] ); |
634 $('#post-visibility-display').html( postL10n[ $postVisibilitySelect.find('input:radio:checked').val() + sticky ] ); |
612 return false; |
635 event.preventDefault(); |
613 }); |
636 }); |
614 |
637 |
615 $('input:radio', '#post-visibility-select').change(function() { |
638 $postVisibilitySelect.find('input:radio').change( function() { |
616 updateVisibility(); |
639 updateVisibility(); |
617 }); |
640 }); |
618 |
641 |
619 $('#timestampdiv').siblings('a.edit-timestamp').click(function() { |
642 $timestampdiv.siblings('a.edit-timestamp').click( function( event ) { |
620 if ($('#timestampdiv').is(":hidden")) { |
643 if ( $timestampdiv.is( ':hidden' ) ) { |
621 $('#timestampdiv').slideDown('fast'); |
644 $timestampdiv.slideDown('fast'); |
622 $('#mm').focus(); |
645 $('#mm').focus(); |
623 $(this).hide(); |
646 $(this).hide(); |
624 } |
647 } |
625 return false; |
648 event.preventDefault(); |
626 }); |
649 }); |
627 |
650 |
628 $('.cancel-timestamp', '#timestampdiv').click(function() { |
651 $timestampdiv.find('.cancel-timestamp').click( function( event ) { |
629 $('#timestampdiv').slideUp('fast'); |
652 $timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().focus(); |
630 $('#mm').val($('#hidden_mm').val()); |
653 $('#mm').val($('#hidden_mm').val()); |
631 $('#jj').val($('#hidden_jj').val()); |
654 $('#jj').val($('#hidden_jj').val()); |
632 $('#aa').val($('#hidden_aa').val()); |
655 $('#aa').val($('#hidden_aa').val()); |
633 $('#hh').val($('#hidden_hh').val()); |
656 $('#hh').val($('#hidden_hh').val()); |
634 $('#mn').val($('#hidden_mn').val()); |
657 $('#mn').val($('#hidden_mn').val()); |
635 $('#timestampdiv').siblings('a.edit-timestamp').show(); |
|
636 updateText(); |
658 updateText(); |
|
659 event.preventDefault(); |
|
660 }); |
|
661 |
|
662 $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels |
|
663 if ( updateText() ) { |
|
664 $timestampdiv.slideUp('fast'); |
|
665 $timestampdiv.siblings('a.edit-timestamp').show(); |
|
666 } |
|
667 event.preventDefault(); |
|
668 }); |
|
669 |
|
670 $('#post').on( 'submit', function( event ) { |
|
671 if ( ! updateText() ) { |
|
672 event.preventDefault(); |
|
673 $timestampdiv.show(); |
|
674 |
|
675 if ( wp.autosave ) { |
|
676 wp.autosave.enableButtons(); |
|
677 } |
|
678 |
|
679 $( '#publishing-action .spinner' ).removeClass( 'is-active' ); |
|
680 } |
|
681 }); |
|
682 |
|
683 $postStatusSelect.siblings('a.edit-post-status').click( function( event ) { |
|
684 if ( $postStatusSelect.is( ':hidden' ) ) { |
|
685 $postStatusSelect.slideDown('fast').find('select').focus(); |
|
686 $(this).hide(); |
|
687 } |
|
688 event.preventDefault(); |
|
689 }); |
|
690 |
|
691 $postStatusSelect.find('.save-post-status').click( function( event ) { |
|
692 $postStatusSelect.slideUp('fast').siblings('a.edit-post-status').show(); |
|
693 updateText(); |
|
694 event.preventDefault(); |
|
695 }); |
|
696 |
|
697 $postStatusSelect.find('.cancel-post-status').click( function( event ) { |
|
698 $('#post-status-select').slideUp('fast').siblings( 'a.edit-post-status' ).show().focus(); |
|
699 $('#post_status').val( $('#hidden_post_status').val() ); |
|
700 updateText(); |
|
701 event.preventDefault(); |
|
702 }); |
|
703 } // end submitdiv |
|
704 |
|
705 // permalink |
|
706 function editPermalink() { |
|
707 var i, slug_value, |
|
708 c = 0, |
|
709 e = $('#editable-post-name'), |
|
710 revert_e = e.html(), |
|
711 real_slug = $('#post_name'), |
|
712 revert_slug = real_slug.val(), |
|
713 b = $('#edit-slug-buttons'), |
|
714 revert_b = b.html(), |
|
715 full = $('#editable-post-name-full'); |
|
716 |
|
717 // Deal with Twemoji in the post-name |
|
718 full.find( 'img' ).replaceWith( function() { return this.alt; } ); |
|
719 full = full.html(); |
|
720 |
|
721 $('#view-post-btn').hide(); |
|
722 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>'); |
|
723 b.children('.save').click(function() { |
|
724 var new_slug = e.children('input').val(); |
|
725 if ( new_slug == $('#editable-post-name-full').text() ) { |
|
726 b.children('.cancel').click(); |
|
727 return false; |
|
728 } |
|
729 $.post(ajaxurl, { |
|
730 action: 'sample-permalink', |
|
731 post_id: postId, |
|
732 new_slug: new_slug, |
|
733 new_title: $('#title').val(), |
|
734 samplepermalinknonce: $('#samplepermalinknonce').val() |
|
735 }, function(data) { |
|
736 var box = $('#edit-slug-box'); |
|
737 box.html(data); |
|
738 if (box.hasClass('hidden')) { |
|
739 box.fadeIn('fast', function () { |
|
740 box.removeClass('hidden'); |
|
741 }); |
|
742 } |
|
743 |
|
744 b.html(revert_b); |
|
745 real_slug.val(new_slug); |
|
746 $('#view-post-btn').show(); |
|
747 }); |
637 return false; |
748 return false; |
638 }); |
749 }); |
639 |
750 |
640 $('.save-timestamp', '#timestampdiv').click(function () { // crazyhorse - multiple ok cancels |
751 b.children('.cancel').click(function() { |
641 if ( updateText() ) { |
752 $('#view-post-btn').show(); |
642 $('#timestampdiv').slideUp('fast'); |
753 e.html(revert_e); |
643 $('#timestampdiv').siblings('a.edit-timestamp').show(); |
754 b.html(revert_b); |
644 } |
755 real_slug.val(revert_slug); |
645 return false; |
756 return false; |
646 }); |
757 }); |
647 |
758 |
648 $('#post').on( 'submit', function(e){ |
759 for ( i = 0; i < full.length; ++i ) { |
649 if ( ! updateText() ) { |
760 if ( '%' == full.charAt(i) ) |
650 e.preventDefault(); |
761 c++; |
651 $('#timestampdiv').show(); |
762 } |
652 $('#publishing-action .spinner').hide(); |
763 |
653 $('#publish').prop('disabled', false).removeClass('button-primary-disabled'); |
764 slug_value = ( c > full.length / 4 ) ? '' : full; |
|
765 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e) { |
|
766 var key = e.keyCode || 0; |
|
767 // on enter, just save the new slug, don't save the post |
|
768 if ( 13 == key ) { |
|
769 b.children('.save').click(); |
654 return false; |
770 return false; |
655 } |
771 } |
656 }); |
772 if ( 27 == key ) { |
657 |
773 b.children('.cancel').click(); |
658 $('#post-status-select').siblings('a.edit-post-status').click(function() { |
|
659 if ($('#post-status-select').is(":hidden")) { |
|
660 $('#post-status-select').slideDown('fast'); |
|
661 $(this).hide(); |
|
662 } |
|
663 return false; |
|
664 }); |
|
665 |
|
666 $('.save-post-status', '#post-status-select').click(function() { |
|
667 $('#post-status-select').slideUp('fast'); |
|
668 $('#post-status-select').siblings('a.edit-post-status').show(); |
|
669 updateText(); |
|
670 return false; |
|
671 }); |
|
672 |
|
673 $('.cancel-post-status', '#post-status-select').click(function() { |
|
674 $('#post-status-select').slideUp('fast'); |
|
675 $('#post_status').val($('#hidden_post_status').val()); |
|
676 $('#post-status-select').siblings('a.edit-post-status').show(); |
|
677 updateText(); |
|
678 return false; |
|
679 }); |
|
680 } // end submitdiv |
|
681 |
|
682 // permalink |
|
683 if ( $('#edit-slug-box').length ) { |
|
684 editPermalink = function(post_id) { |
|
685 var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.val(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html(); |
|
686 |
|
687 $('#view-post-btn').hide(); |
|
688 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>'); |
|
689 b.children('.save').click(function() { |
|
690 var new_slug = e.children('input').val(); |
|
691 if ( new_slug == $('#editable-post-name-full').text() ) { |
|
692 return $('.cancel', '#edit-slug-buttons').click(); |
|
693 } |
|
694 $.post(ajaxurl, { |
|
695 action: 'sample-permalink', |
|
696 post_id: post_id, |
|
697 new_slug: new_slug, |
|
698 new_title: $('#title').val(), |
|
699 samplepermalinknonce: $('#samplepermalinknonce').val() |
|
700 }, function(data) { |
|
701 var box = $('#edit-slug-box'); |
|
702 box.html(data); |
|
703 if (box.hasClass('hidden')) { |
|
704 box.fadeIn('fast', function () { |
|
705 box.removeClass('hidden'); |
|
706 }); |
|
707 } |
|
708 b.html(revert_b); |
|
709 real_slug.val(new_slug); |
|
710 makeSlugeditClickable(); |
|
711 $('#view-post-btn').show(); |
|
712 }); |
|
713 return false; |
774 return false; |
714 }); |
775 } |
715 |
776 } ).keyup( function() { |
716 $('.cancel', '#edit-slug-buttons').click(function() { |
777 real_slug.val(this.value); |
717 $('#view-post-btn').show(); |
778 }).focus(); |
718 e.html(revert_e); |
779 } |
719 b.html(revert_b); |
780 |
720 real_slug.val(revert_slug); |
781 if ( $editSlugWrap.length ) { |
721 return false; |
782 $editSlugWrap.on( 'click', function( event ) { |
722 }); |
783 var $target = $( event.target ); |
723 |
784 |
724 for ( i = 0; i < full.length; ++i ) { |
785 if ( $target.is('#editable-post-name') || $target.hasClass('edit-slug') ) { |
725 if ( '%' == full.charAt(i) ) |
786 editPermalink(); |
726 c++; |
787 } |
727 } |
788 }); |
728 |
|
729 slug_value = ( c > full.length / 4 ) ? '' : full; |
|
730 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e) { |
|
731 var key = e.keyCode || 0; |
|
732 // on enter, just save the new slug, don't save the post |
|
733 if ( 13 == key ) { |
|
734 b.children('.save').click(); |
|
735 return false; |
|
736 } |
|
737 if ( 27 == key ) { |
|
738 b.children('.cancel').click(); |
|
739 return false; |
|
740 } |
|
741 }).keyup(function(e) { |
|
742 real_slug.val(this.value); |
|
743 }).focus(); |
|
744 } |
|
745 |
|
746 makeSlugeditClickable = function() { |
|
747 $('#editable-post-name').click(function() { |
|
748 $('#edit-slug-buttons').children('.edit-slug').click(); |
|
749 }); |
|
750 } |
|
751 makeSlugeditClickable(); |
|
752 } |
789 } |
753 |
790 |
754 // word count |
791 // word count |
755 if ( typeof(wpWordCount) != 'undefined' ) { |
792 if ( typeof(wpWordCount) != 'undefined' ) { |
756 $(document).triggerHandler('wpcountwords', [ co.val() ]); |
793 $document.triggerHandler('wpcountwords', [ co.val() ]); |
757 |
794 |
758 co.keyup( function(e) { |
795 co.keyup( function(e) { |
759 var k = e.keyCode || e.charCode; |
796 var k = e.keyCode || e.charCode; |
760 |
797 |
761 if ( k == last ) |
798 if ( k == last ) |
762 return true; |
799 return true; |
763 |
800 |
764 if ( 13 == k || 8 == last || 46 == last ) |
801 if ( 13 == k || 8 == last || 46 == last ) |
765 $(document).triggerHandler('wpcountwords', [ co.val() ]); |
802 $document.triggerHandler('wpcountwords', [ co.val() ]); |
766 |
803 |
767 last = k; |
804 last = k; |
768 return true; |
805 return true; |
769 }); |
806 }); |
770 } |
807 } |
772 wptitlehint = function(id) { |
809 wptitlehint = function(id) { |
773 id = id || 'title'; |
810 id = id || 'title'; |
774 |
811 |
775 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text'); |
812 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text'); |
776 |
813 |
777 if ( title.val() == '' ) |
814 if ( '' === title.val() ) |
778 titleprompt.removeClass('screen-reader-text'); |
815 titleprompt.removeClass('screen-reader-text'); |
779 |
816 |
780 titleprompt.click(function(){ |
817 titleprompt.click(function(){ |
781 $(this).addClass('screen-reader-text'); |
818 $(this).addClass('screen-reader-text'); |
782 title.focus(); |
819 title.focus(); |
783 }); |
820 }); |
784 |
821 |
785 title.blur(function(){ |
822 title.blur(function(){ |
786 if ( this.value == '' ) |
823 if ( '' === this.value ) |
787 titleprompt.removeClass('screen-reader-text'); |
824 titleprompt.removeClass('screen-reader-text'); |
788 }).focus(function(){ |
825 }).focus(function(){ |
789 titleprompt.addClass('screen-reader-text'); |
826 titleprompt.addClass('screen-reader-text'); |
790 }).keydown(function(e){ |
827 }).keydown(function(e){ |
791 titleprompt.addClass('screen-reader-text'); |
828 titleprompt.addClass('screen-reader-text'); |
792 $(this).unbind(e); |
829 $(this).unbind(e); |
793 }); |
830 }); |
794 } |
831 }; |
795 |
832 |
796 wptitlehint(); |
833 wptitlehint(); |
797 |
834 |
798 // resizable textarea#content |
835 // Resize the visual and text editors |
799 (function() { |
836 ( function() { |
800 var textarea = $('textarea#content'), offset = null, el; |
837 var editor, offset, mce, |
|
838 $textarea = $('textarea#content'), |
|
839 $handle = $('#post-status-info'), |
|
840 $postdivrich = $('#postdivrich'); |
|
841 |
801 // No point for touch devices |
842 // No point for touch devices |
802 if ( !textarea.length || 'ontouchstart' in window ) |
843 if ( ! $textarea.length || 'ontouchstart' in window ) { |
|
844 // Hide the resize handle |
|
845 $('#content-resize-handle').hide(); |
803 return; |
846 return; |
804 |
847 } |
805 function dragging(e) { |
848 |
806 textarea.height( Math.max(50, offset + e.pageY) + 'px' ); |
849 function dragging( event ) { |
807 return false; |
850 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) { |
808 } |
851 return; |
809 |
852 } |
810 function endDrag(e) { |
853 |
811 var height; |
854 if ( mce ) { |
812 |
855 editor.theme.resizeTo( null, offset + event.pageY ); |
813 textarea.focus(); |
856 } else { |
814 $(document).unbind('mousemove', dragging).unbind('mouseup', endDrag); |
857 $textarea.height( Math.max( 50, offset + event.pageY ) ); |
815 |
858 } |
816 height = parseInt( textarea.css('height'), 10 ); |
859 |
|
860 event.preventDefault(); |
|
861 } |
|
862 |
|
863 function endDrag() { |
|
864 var height, toolbarHeight; |
|
865 |
|
866 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) { |
|
867 return; |
|
868 } |
|
869 |
|
870 if ( mce ) { |
|
871 editor.focus(); |
|
872 toolbarHeight = parseInt( $( '#wp-content-editor-container .mce-toolbar-grp' ).height(), 10 ); |
|
873 |
|
874 if ( toolbarHeight < 10 || toolbarHeight > 200 ) { |
|
875 toolbarHeight = 30; |
|
876 } |
|
877 |
|
878 height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28; |
|
879 } else { |
|
880 $textarea.focus(); |
|
881 height = parseInt( $textarea.css('height'), 10 ); |
|
882 } |
|
883 |
|
884 $document.off( '.wp-editor-resize' ); |
817 |
885 |
818 // sanity check |
886 // sanity check |
819 if ( height && height > 50 && height < 5000 ) |
887 if ( height && height > 50 && height < 5000 ) { |
820 setUserSetting( 'ed_size', height ); |
888 setUserSetting( 'ed_size', height ); |
821 } |
889 } |
822 |
890 } |
823 textarea.css('resize', 'none'); |
891 |
824 el = $('<div id="content-resize-handle"><br></div>'); |
892 $handle.on( 'mousedown.wp-editor-resize', function( event ) { |
825 $('#wp-content-wrap').append(el); |
893 if ( typeof tinymce !== 'undefined' ) { |
826 el.on('mousedown', function(e) { |
894 editor = tinymce.get('content'); |
827 offset = textarea.height() - e.pageY; |
895 } |
828 textarea.blur(); |
896 |
829 $(document).mousemove(dragging).mouseup(endDrag); |
897 if ( editor && ! editor.isHidden() ) { |
830 return false; |
898 mce = true; |
831 }); |
899 offset = $('#content_ifr').height() - event.pageY; |
|
900 } else { |
|
901 mce = false; |
|
902 offset = $textarea.height() - event.pageY; |
|
903 $textarea.blur(); |
|
904 } |
|
905 |
|
906 $document.on( 'mousemove.wp-editor-resize', dragging ) |
|
907 .on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag ); |
|
908 |
|
909 event.preventDefault(); |
|
910 }).on( 'mouseup.wp-editor-resize', endDrag ); |
832 })(); |
911 })(); |
833 |
912 |
834 if ( typeof(tinymce) != 'undefined' ) { |
913 if ( typeof tinymce !== 'undefined' ) { |
835 tinymce.onAddEditor.add(function(mce, ed){ |
|
836 // iOS expands the iframe to full height and the user cannot adjust it. |
|
837 if ( ed.id != 'content' || tinymce.isIOS5 ) |
|
838 return; |
|
839 |
|
840 function getHeight() { |
|
841 var height, node = document.getElementById('content_ifr'), |
|
842 ifr_height = node ? parseInt( node.style.height, 10 ) : 0, |
|
843 tb_height = $('#content_tbl tr.mceFirst').height(); |
|
844 |
|
845 if ( !ifr_height || !tb_height ) |
|
846 return false; |
|
847 |
|
848 // total height including toolbar and statusbar |
|
849 height = ifr_height + tb_height + 21; |
|
850 // textarea height = total height - 33px toolbar |
|
851 height -= 33; |
|
852 |
|
853 return height; |
|
854 } |
|
855 |
|
856 // resize TinyMCE to match the textarea height when switching Text -> Visual |
|
857 ed.onLoadContent.add( function(ed, o) { |
|
858 var ifr_height, node = document.getElementById('content'), |
|
859 height = node ? parseInt( node.style.height, 10 ) : 0, |
|
860 tb_height = $('#content_tbl tr.mceFirst').height() || 33; |
|
861 |
|
862 // height cannot be under 50 or over 5000 |
|
863 if ( !height || height < 50 || height > 5000 ) |
|
864 height = 360; // default height for the main editor |
|
865 |
|
866 if ( getUserSetting( 'ed_size' ) > 5000 ) |
|
867 setUserSetting( 'ed_size', 360 ); |
|
868 |
|
869 // compensate for padding and toolbars |
|
870 ifr_height = ( height - tb_height ) + 12; |
|
871 |
|
872 // sanity check |
|
873 if ( ifr_height > 50 && ifr_height < 5000 ) { |
|
874 $('#content_tbl').css('height', '' ); |
|
875 $('#content_ifr').css('height', ifr_height + 'px' ); |
|
876 } |
|
877 }); |
|
878 |
|
879 // resize the textarea to match TinyMCE's height when switching Visual -> Text |
|
880 ed.onSaveContent.add( function(ed, o) { |
|
881 var height = getHeight(); |
|
882 |
|
883 if ( !height || height < 50 || height > 5000 ) |
|
884 return; |
|
885 |
|
886 $('textarea#content').css( 'height', height + 'px' ); |
|
887 }); |
|
888 |
|
889 // save on resizing TinyMCE |
|
890 ed.onPostRender.add(function() { |
|
891 $('#content_resize').on('mousedown.wp-mce-resize', function(e){ |
|
892 $(document).on('mouseup.wp-mce-resize', function(e){ |
|
893 var height; |
|
894 |
|
895 $(document).off('mouseup.wp-mce-resize'); |
|
896 |
|
897 height = getHeight(); |
|
898 // sanity check |
|
899 if ( height && height > 50 && height < 5000 ) |
|
900 setUserSetting( 'ed_size', height ); |
|
901 }); |
|
902 }); |
|
903 }); |
|
904 }); |
|
905 |
|
906 // When changing post formats, change the editor body class |
914 // When changing post formats, change the editor body class |
907 $('#post-formats-select input.post-format').on( 'change.set-editor-class', function( event ) { |
915 $( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() { |
908 var editor, body, format = this.id; |
916 var editor, body, format = this.id; |
909 |
917 |
910 if ( format && $( this ).prop('checked') ) { |
918 if ( format && $( this ).prop( 'checked' ) && ( editor = tinymce.get( 'content' ) ) ) { |
911 editor = tinymce.get( 'content' ); |
919 body = editor.getBody(); |
912 |
920 body.className = body.className.replace( /\bpost-format-[^ ]+/, '' ); |
913 if ( editor ) { |
921 editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format ); |
914 body = editor.getBody(); |
922 $( document ).trigger( 'editor-classchange' ); |
915 body.className = body.className.replace( /\bpost-format-[^ ]+/, '' ); |
|
916 editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format ); |
|
917 } |
|
918 } |
923 } |
919 }); |
924 }); |
920 } |
925 } |
921 }); |
926 }); |