5
|
1 |
/* global deleteUserSetting, setUserSetting, switchEditors, tinymce, tinyMCEPreInit */ |
0
|
2 |
/** |
5
|
3 |
* Distraction-Free Writing |
0
|
4 |
* (wp-fullscreen) |
|
5 |
* |
5
|
6 |
* Access the API globally using the window.wp.editor.fullscreen variable. |
0
|
7 |
*/ |
5
|
8 |
( function( $, window ) { |
|
9 |
var api, ps, s, toggleUI, uiTimer, PubSub, |
|
10 |
uiScrollTop = 0, |
|
11 |
transitionend = 'transitionend webkitTransitionEnd', |
|
12 |
$body = $( document.body ), |
|
13 |
$document = $( document ); |
|
14 |
|
|
15 |
/** |
|
16 |
* PubSub |
|
17 |
* |
|
18 |
* A lightweight publish/subscribe implementation. |
|
19 |
* |
|
20 |
* @access private |
|
21 |
*/ |
|
22 |
PubSub = function() { |
|
23 |
this.topics = {}; |
|
24 |
|
|
25 |
this.subscribe = function( topic, callback ) { |
|
26 |
if ( ! this.topics[ topic ] ) |
|
27 |
this.topics[ topic ] = []; |
|
28 |
|
|
29 |
this.topics[ topic ].push( callback ); |
|
30 |
return callback; |
|
31 |
}; |
|
32 |
|
|
33 |
this.unsubscribe = function( topic, callback ) { |
|
34 |
var i, l, |
|
35 |
topics = this.topics[ topic ]; |
0
|
36 |
|
5
|
37 |
if ( ! topics ) |
|
38 |
return callback || []; |
|
39 |
|
|
40 |
// Clear matching callbacks |
|
41 |
if ( callback ) { |
|
42 |
for ( i = 0, l = topics.length; i < l; i++ ) { |
|
43 |
if ( callback == topics[i] ) |
|
44 |
topics.splice( i, 1 ); |
|
45 |
} |
|
46 |
return callback; |
|
47 |
|
|
48 |
// Clear all callbacks |
|
49 |
} else { |
|
50 |
this.topics[ topic ] = []; |
|
51 |
return topics; |
|
52 |
} |
|
53 |
}; |
|
54 |
|
|
55 |
this.publish = function( topic, args ) { |
|
56 |
var i, l, broken, |
|
57 |
topics = this.topics[ topic ]; |
|
58 |
|
|
59 |
if ( ! topics ) |
|
60 |
return; |
|
61 |
|
|
62 |
args = args || []; |
|
63 |
|
|
64 |
for ( i = 0, l = topics.length; i < l; i++ ) { |
|
65 |
broken = ( topics[i].apply( null, args ) === false || broken ); |
|
66 |
} |
|
67 |
return ! broken; |
|
68 |
}; |
|
69 |
}; |
0
|
70 |
|
|
71 |
// Initialize the fullscreen/api object |
5
|
72 |
api = {}; |
0
|
73 |
|
|
74 |
// Create the PubSub (publish/subscribe) interface. |
|
75 |
ps = api.pubsub = new PubSub(); |
|
76 |
|
|
77 |
s = api.settings = { // Settings |
5
|
78 |
visible: false, |
|
79 |
mode: 'tinymce', |
|
80 |
id: '', |
|
81 |
title_id: '', |
|
82 |
timer: 0, |
|
83 |
toolbar_shown: false |
|
84 |
}; |
|
85 |
|
|
86 |
function _hideUI() { |
|
87 |
$body.removeClass('wp-dfw-show-ui'); |
0
|
88 |
} |
|
89 |
|
|
90 |
/** |
5
|
91 |
* toggleUI |
0
|
92 |
* |
5
|
93 |
* Toggle the CSS class to show/hide the toolbar, borders and statusbar. |
0
|
94 |
*/ |
5
|
95 |
toggleUI = api.toggleUI = function( show ) { |
|
96 |
clearTimeout( uiTimer ); |
0
|
97 |
|
5
|
98 |
if ( ! $body.hasClass('wp-dfw-show-ui') || show === 'show' ) { |
|
99 |
$body.addClass('wp-dfw-show-ui'); |
|
100 |
} else if ( show !== 'autohide' ) { |
|
101 |
$body.removeClass('wp-dfw-show-ui'); |
0
|
102 |
} |
|
103 |
|
5
|
104 |
if ( show === 'autohide' ) { |
|
105 |
uiTimer = setTimeout( _hideUI, 2000 ); |
|
106 |
} |
|
107 |
}; |
0
|
108 |
|
5
|
109 |
function resetCssPosition( add ) { |
|
110 |
s.$dfwWrap.parents().each( function( i, parent ) { |
|
111 |
var cssPosition, $parent = $(parent); |
0
|
112 |
|
5
|
113 |
if ( add ) { |
|
114 |
if ( parent.style.position ) { |
|
115 |
$parent.data( 'wp-dfw-css-position', parent.style.position ); |
|
116 |
} |
0
|
117 |
|
5
|
118 |
$parent.css( 'position', 'static' ); |
|
119 |
} else { |
|
120 |
cssPosition = $parent.data( 'wp-dfw-css-position' ); |
|
121 |
cssPosition = cssPosition || ''; |
|
122 |
$parent.css( 'position', cssPosition ); |
|
123 |
} |
0
|
124 |
|
5
|
125 |
if ( parent.nodeName === 'BODY' ) { |
|
126 |
return false; |
|
127 |
} |
|
128 |
}); |
|
129 |
} |
0
|
130 |
|
|
131 |
/** |
|
132 |
* on() |
|
133 |
* |
|
134 |
* Turns fullscreen on. |
|
135 |
* |
|
136 |
* @param string mode Optional. Switch to the given mode before opening. |
|
137 |
*/ |
|
138 |
api.on = function() { |
5
|
139 |
var id, $dfwWrap, titleId; |
|
140 |
|
|
141 |
if ( s.visible ) { |
0
|
142 |
return; |
5
|
143 |
} |
|
144 |
|
|
145 |
if ( ! s.$fullscreenFader ) { |
|
146 |
api.ui.init(); |
|
147 |
} |
0
|
148 |
|
|
149 |
// Settings can be added or changed by defining "wp_fullscreen_settings" JS object. |
5
|
150 |
if ( typeof window.wp_fullscreen_settings === 'object' ) |
|
151 |
$.extend( s, window.wp_fullscreen_settings ); |
|
152 |
|
|
153 |
id = s.id || window.wpActiveEditor; |
0
|
154 |
|
5
|
155 |
if ( ! id ) { |
|
156 |
if ( s.hasTinymce ) { |
|
157 |
id = tinymce.activeEditor.id; |
|
158 |
} else { |
|
159 |
return; |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
s.id = id; |
|
164 |
$dfwWrap = s.$dfwWrap = $( '#wp-' + id + '-wrap' ); |
|
165 |
|
|
166 |
if ( ! $dfwWrap.length ) { |
|
167 |
return; |
|
168 |
} |
|
169 |
|
|
170 |
s.$dfwTextarea = $( '#' + id ); |
|
171 |
s.$editorContainer = $dfwWrap.find( '.wp-editor-container' ); |
|
172 |
uiScrollTop = $document.scrollTop(); |
0
|
173 |
|
5
|
174 |
if ( s.hasTinymce ) { |
|
175 |
s.editor = tinymce.get( id ); |
|
176 |
} |
|
177 |
|
|
178 |
if ( s.editor && ! s.editor.isHidden() ) { |
|
179 |
s.origHeight = $( '#' + id + '_ifr' ).height(); |
|
180 |
s.mode = 'tinymce'; |
|
181 |
} else { |
|
182 |
s.origHeight = s.$dfwTextarea.height(); |
|
183 |
s.mode = 'html'; |
|
184 |
} |
0
|
185 |
|
5
|
186 |
// Try to find title field |
|
187 |
if ( typeof window.adminpage !== 'undefined' && |
|
188 |
( window.adminpage === 'post-php' || window.adminpage === 'post-new-php' ) ) { |
0
|
189 |
|
5
|
190 |
titleId = 'title'; |
|
191 |
} else { |
|
192 |
titleId = id + '-title'; |
|
193 |
} |
0
|
194 |
|
5
|
195 |
s.$dfwTitle = $( '#' + titleId ); |
|
196 |
|
|
197 |
if ( ! s.$dfwTitle.length ) { |
|
198 |
s.$dfwTitle = null; |
|
199 |
} |
0
|
200 |
|
|
201 |
api.ui.fade( 'show', 'showing', 'shown' ); |
|
202 |
}; |
|
203 |
|
|
204 |
/** |
|
205 |
* off() |
|
206 |
* |
|
207 |
* Turns fullscreen off. |
|
208 |
*/ |
|
209 |
api.off = function() { |
|
210 |
if ( ! s.visible ) |
|
211 |
return; |
|
212 |
|
|
213 |
api.ui.fade( 'hide', 'hiding', 'hidden' ); |
|
214 |
}; |
|
215 |
|
|
216 |
/** |
|
217 |
* switchmode() |
|
218 |
* |
|
219 |
* @return string - The current mode. |
|
220 |
* |
|
221 |
* @param string to - The fullscreen mode to switch to. |
|
222 |
* @event switchMode |
|
223 |
* @eventparam string to - The new mode. |
|
224 |
* @eventparam string from - The old mode. |
|
225 |
*/ |
|
226 |
api.switchmode = function( to ) { |
|
227 |
var from = s.mode; |
|
228 |
|
5
|
229 |
if ( ! to || ! s.visible || ! s.hasTinymce || typeof switchEditors === 'undefined' ) { |
0
|
230 |
return from; |
5
|
231 |
} |
0
|
232 |
|
|
233 |
// Don't switch if the mode is the same. |
|
234 |
if ( from == to ) |
|
235 |
return from; |
|
236 |
|
5
|
237 |
if ( to === 'tinymce' && ! s.editor ) { |
|
238 |
s.editor = tinymce.get( s.id ); |
|
239 |
|
|
240 |
if ( ! s.editor && typeof tinyMCEPreInit !== 'undefined' && |
|
241 |
tinyMCEPreInit.mceInit && tinyMCEPreInit.mceInit[ s.id ] ) { |
|
242 |
|
|
243 |
// If the TinyMCE instance hasn't been created, set the "wp_fulscreen" flag on creating it |
|
244 |
tinyMCEPreInit.mceInit[ s.id ].wp_fullscreen = true; |
|
245 |
} |
|
246 |
} |
|
247 |
|
0
|
248 |
s.mode = to; |
5
|
249 |
switchEditors.go( s.id, to ); |
|
250 |
api.refreshButtons( true ); |
|
251 |
|
|
252 |
if ( to === 'html' ) { |
|
253 |
setTimeout( api.resizeTextarea, 200 ); |
|
254 |
} |
0
|
255 |
|
|
256 |
return to; |
|
257 |
}; |
|
258 |
|
|
259 |
/** |
|
260 |
* General |
|
261 |
*/ |
|
262 |
|
|
263 |
api.save = function() { |
5
|
264 |
var $hidden = $('#hiddenaction'), |
|
265 |
oldVal = $hidden.val(), |
|
266 |
$spinner = $('#wp-fullscreen-save .spinner'), |
|
267 |
$saveMessage = $('#wp-fullscreen-save .wp-fullscreen-saved-message'), |
|
268 |
$errorMessage = $('#wp-fullscreen-save .wp-fullscreen-error-message'); |
0
|
269 |
|
5
|
270 |
$spinner.addClass( 'is-active' ); |
|
271 |
$errorMessage.hide(); |
|
272 |
$saveMessage.hide(); |
|
273 |
$hidden.val('wp-fullscreen-save-post'); |
0
|
274 |
|
5
|
275 |
if ( s.editor && ! s.editor.isHidden() ) { |
|
276 |
s.editor.save(); |
0
|
277 |
} |
|
278 |
|
5
|
279 |
$.ajax({ |
|
280 |
url: window.ajaxurl, |
|
281 |
type: 'post', |
|
282 |
data: $('form#post').serialize(), |
|
283 |
dataType: 'json' |
|
284 |
}).done( function( response ) { |
|
285 |
$spinner.removeClass( 'is-active' ); |
|
286 |
|
|
287 |
if ( response && response.success ) { |
|
288 |
$saveMessage.show(); |
|
289 |
|
|
290 |
setTimeout( function() { |
|
291 |
$saveMessage.fadeOut(300); |
|
292 |
}, 3000 ); |
|
293 |
|
|
294 |
if ( response.data && response.data.last_edited ) { |
|
295 |
$('#wp-fullscreen-save input').attr( 'title', response.data.last_edited ); |
|
296 |
} |
|
297 |
} else { |
|
298 |
$errorMessage.show(); |
|
299 |
} |
|
300 |
}).fail( function() { |
|
301 |
$spinner.removeClass( 'is-active' ); |
|
302 |
$errorMessage.show(); |
|
303 |
}); |
0
|
304 |
|
5
|
305 |
$hidden.val( oldVal ); |
|
306 |
}; |
|
307 |
|
|
308 |
api.dfwWidth = function( pixels, total ) { |
|
309 |
var width; |
|
310 |
|
|
311 |
if ( pixels && pixels.toString().indexOf('%') !== -1 ) { |
|
312 |
s.$editorContainer.css( 'width', pixels ); |
|
313 |
s.$statusbar.css( 'width', pixels ); |
0
|
314 |
|
5
|
315 |
if ( s.$dfwTitle ) { |
|
316 |
s.$dfwTitle.css( 'width', pixels ); |
|
317 |
} |
|
318 |
return; |
|
319 |
} |
0
|
320 |
|
5
|
321 |
if ( ! pixels ) { |
|
322 |
// Reset to theme width |
|
323 |
width = $('#wp-fullscreen-body').data('theme-width') || 800; |
|
324 |
s.$editorContainer.width( width ); |
|
325 |
s.$statusbar.width( width ); |
|
326 |
|
|
327 |
if ( s.$dfwTitle ) { |
|
328 |
s.$dfwTitle.width( width - 16 ); |
|
329 |
} |
|
330 |
|
0
|
331 |
deleteUserSetting('dfw_width'); |
|
332 |
return; |
|
333 |
} |
|
334 |
|
5
|
335 |
if ( total ) { |
|
336 |
width = pixels; |
|
337 |
} else { |
|
338 |
width = s.$editorContainer.width(); |
|
339 |
width += pixels; |
|
340 |
} |
0
|
341 |
|
5
|
342 |
if ( width < 200 || width > 1200 ) { |
|
343 |
// sanity check |
0
|
344 |
return; |
5
|
345 |
} |
0
|
346 |
|
5
|
347 |
s.$editorContainer.width( width ); |
|
348 |
s.$statusbar.width( width ); |
0
|
349 |
|
5
|
350 |
if ( s.$dfwTitle ) { |
|
351 |
s.$dfwTitle.width( width - 16 ); |
|
352 |
} |
|
353 |
|
|
354 |
setUserSetting( 'dfw_width', width ); |
|
355 |
}; |
0
|
356 |
|
5
|
357 |
// This event occurs before the overlay blocks the UI. |
|
358 |
ps.subscribe( 'show', function() { |
|
359 |
var title = $('#last-edit').text(); |
0
|
360 |
|
5
|
361 |
if ( title ) { |
|
362 |
$('#wp-fullscreen-save input').attr( 'title', title ); |
|
363 |
} |
0
|
364 |
}); |
|
365 |
|
5
|
366 |
// This event occurs while the overlay blocks the UI. |
|
367 |
ps.subscribe( 'showing', function() { |
|
368 |
$body.addClass( 'wp-fullscreen-active' ); |
|
369 |
s.$dfwWrap.addClass( 'wp-fullscreen-wrap' ); |
0
|
370 |
|
5
|
371 |
if ( s.$dfwTitle ) { |
|
372 |
s.$dfwTitle.after( '<span id="wp-fullscreen-title-placeholder">' ); |
|
373 |
s.$dfwWrap.prepend( s.$dfwTitle.addClass('wp-fullscreen-title') ); |
0
|
374 |
} |
|
375 |
|
5
|
376 |
api.refreshButtons(); |
|
377 |
resetCssPosition( true ); |
|
378 |
$('#wpadminbar').hide(); |
0
|
379 |
|
5
|
380 |
// Show the UI for 2 sec. when opening |
|
381 |
toggleUI('autohide'); |
0
|
382 |
|
|
383 |
api.bind_resize(); |
5
|
384 |
|
|
385 |
if ( s.editor ) { |
|
386 |
s.editor.execCommand( 'wpFullScreenOn' ); |
|
387 |
} |
|
388 |
|
|
389 |
if ( 'ontouchstart' in window ) { |
|
390 |
api.dfwWidth( '90%' ); |
|
391 |
} else { |
|
392 |
api.dfwWidth( $( '#wp-fullscreen-body' ).data('dfw-width') || 800, true ); |
|
393 |
} |
0
|
394 |
|
|
395 |
// scroll to top so the user is not disoriented |
|
396 |
scrollTo(0, 0); |
|
397 |
}); |
|
398 |
|
5
|
399 |
// This event occurs after the overlay unblocks the UI |
|
400 |
ps.subscribe( 'shown', function() { |
0
|
401 |
s.visible = true; |
|
402 |
|
5
|
403 |
if ( s.editor && ! s.editor.isHidden() ) { |
|
404 |
s.editor.execCommand( 'wpAutoResize' ); |
|
405 |
} else { |
|
406 |
api.resizeTextarea( 'force' ); |
0
|
407 |
} |
|
408 |
}); |
|
409 |
|
|
410 |
ps.subscribe( 'hide', function() { // This event occurs before the overlay blocks DFW. |
5
|
411 |
$document.unbind( '.fullscreen' ); |
|
412 |
s.$dfwTextarea.unbind('.wp-dfw-resize'); |
0
|
413 |
}); |
|
414 |
|
|
415 |
ps.subscribe( 'hiding', function() { // This event occurs while the overlay blocks the DFW UI. |
5
|
416 |
$body.removeClass( 'wp-fullscreen-active' ); |
0
|
417 |
|
5
|
418 |
if ( s.$dfwTitle ) { |
|
419 |
$( '#wp-fullscreen-title-placeholder' ).before( s.$dfwTitle.removeClass('wp-fullscreen-title').css( 'width', '' ) ).remove(); |
|
420 |
} |
|
421 |
|
|
422 |
s.$dfwWrap.removeClass( 'wp-fullscreen-wrap' ); |
|
423 |
s.$editorContainer.css( 'width', '' ); |
|
424 |
s.$dfwTextarea.add( '#' + s.id + '_ifr' ).height( s.origHeight ); |
|
425 |
|
|
426 |
if ( s.editor ) { |
|
427 |
s.editor.execCommand( 'wpFullScreenOff' ); |
|
428 |
} |
|
429 |
|
|
430 |
resetCssPosition( false ); |
|
431 |
|
|
432 |
window.scrollTo( 0, uiScrollTop ); |
0
|
433 |
$('#wpadminbar').show(); |
|
434 |
}); |
|
435 |
|
5
|
436 |
// This event occurs after DFW is removed. |
|
437 |
ps.subscribe( 'hidden', function() { |
0
|
438 |
s.visible = false; |
|
439 |
}); |
|
440 |
|
5
|
441 |
api.refreshButtons = function( fade ) { |
|
442 |
if ( s.mode === 'html' ) { |
|
443 |
$('#wp-fullscreen-mode-bar').removeClass('wp-tmce-mode').addClass('wp-html-mode') |
|
444 |
.find('a').removeClass( 'active' ).filter('.wp-fullscreen-mode-html').addClass( 'active' ); |
0
|
445 |
|
5
|
446 |
if ( fade ) { |
0
|
447 |
$('#wp-fullscreen-button-bar').fadeOut( 150, function(){ |
|
448 |
$(this).addClass('wp-html-mode').fadeIn( 150 ); |
|
449 |
}); |
5
|
450 |
} else { |
0
|
451 |
$('#wp-fullscreen-button-bar').addClass('wp-html-mode'); |
5
|
452 |
} |
0
|
453 |
} else if ( s.mode === 'tinymce' ) { |
5
|
454 |
$('#wp-fullscreen-mode-bar').removeClass('wp-html-mode').addClass('wp-tmce-mode') |
|
455 |
.find('a').removeClass( 'active' ).filter('.wp-fullscreen-mode-tinymce').addClass( 'active' ); |
0
|
456 |
|
5
|
457 |
if ( fade ) { |
0
|
458 |
$('#wp-fullscreen-button-bar').fadeOut( 150, function(){ |
|
459 |
$(this).removeClass('wp-html-mode').fadeIn( 150 ); |
|
460 |
}); |
5
|
461 |
} else { |
0
|
462 |
$('#wp-fullscreen-button-bar').removeClass('wp-html-mode'); |
5
|
463 |
} |
0
|
464 |
} |
5
|
465 |
}; |
0
|
466 |
|
|
467 |
/** |
|
468 |
* UI Elements |
|
469 |
* |
|
470 |
* Used for transitioning between states. |
|
471 |
*/ |
|
472 |
api.ui = { |
|
473 |
init: function() { |
5
|
474 |
var toolbar; |
0
|
475 |
|
5
|
476 |
s.toolbar = toolbar = $('#fullscreen-topbar'); |
|
477 |
s.$fullscreenFader = $('#fullscreen-fader'); |
|
478 |
s.$statusbar = $('#wp-fullscreen-status'); |
|
479 |
s.hasTinymce = typeof tinymce !== 'undefined'; |
0
|
480 |
|
5
|
481 |
if ( ! s.hasTinymce ) |
0
|
482 |
$('#wp-fullscreen-mode-bar').hide(); |
|
483 |
|
5
|
484 |
$document.keyup( function(e) { |
|
485 |
var c = e.keyCode || e.charCode, modKey; |
0
|
486 |
|
5
|
487 |
if ( ! s.visible ) { |
|
488 |
return; |
|
489 |
} |
0
|
490 |
|
5
|
491 |
if ( navigator.platform && navigator.platform.indexOf('Mac') !== -1 ) { |
|
492 |
modKey = e.ctrlKey; // Ctrl key for Mac |
|
493 |
} else { |
|
494 |
modKey = e.altKey; // Alt key for Win & Linux |
|
495 |
} |
0
|
496 |
|
5
|
497 |
if ( modKey && ( 61 === c || 107 === c || 187 === c ) ) { // + |
|
498 |
api.dfwWidth( 25 ); |
|
499 |
e.preventDefault(); |
|
500 |
} |
|
501 |
|
|
502 |
if ( modKey && ( 45 === c || 109 === c || 189 === c ) ) { // - |
|
503 |
api.dfwWidth( -25 ); |
|
504 |
e.preventDefault(); |
0
|
505 |
} |
|
506 |
|
5
|
507 |
if ( modKey && 48 === c ) { // 0 |
|
508 |
api.dfwWidth( 0 ); |
|
509 |
e.preventDefault(); |
|
510 |
} |
|
511 |
}); |
0
|
512 |
|
5
|
513 |
$( window ).on( 'keydown.wp-fullscreen', function( event ) { |
|
514 |
// Turn fullscreen off when Esc is pressed. |
|
515 |
if ( 27 === event.keyCode && s.visible ) { |
|
516 |
api.off(); |
|
517 |
event.stopImmediatePropagation(); |
|
518 |
} |
|
519 |
}); |
0
|
520 |
|
5
|
521 |
if ( 'ontouchstart' in window ) { |
|
522 |
$body.addClass('wp-dfw-touch'); |
|
523 |
} |
0
|
524 |
|
5
|
525 |
toolbar.on( 'mouseenter', function() { |
|
526 |
toggleUI('show'); |
|
527 |
}).on( 'mouseleave', function() { |
|
528 |
toggleUI('autohide'); |
0
|
529 |
}); |
|
530 |
|
5
|
531 |
// Bind buttons |
|
532 |
$('#wp-fullscreen-buttons').on( 'click.wp-fullscreen', 'button', function( event ) { |
|
533 |
var command = event.currentTarget.id ? event.currentTarget.id.substr(6) : null; |
0
|
534 |
|
5
|
535 |
if ( s.editor && 'tinymce' === s.mode ) { |
|
536 |
switch( command ) { |
|
537 |
case 'bold': |
|
538 |
s.editor.execCommand('Bold'); |
|
539 |
break; |
|
540 |
case 'italic': |
|
541 |
s.editor.execCommand('Italic'); |
|
542 |
break; |
|
543 |
case 'bullist': |
|
544 |
s.editor.execCommand('InsertUnorderedList'); |
|
545 |
break; |
|
546 |
case 'numlist': |
|
547 |
s.editor.execCommand('InsertOrderedList'); |
|
548 |
break; |
|
549 |
case 'link': |
|
550 |
s.editor.execCommand('WP_Link'); |
|
551 |
break; |
|
552 |
case 'unlink': |
|
553 |
s.editor.execCommand('unlink'); |
|
554 |
break; |
|
555 |
case 'help': |
|
556 |
s.editor.execCommand('WP_Help'); |
|
557 |
break; |
|
558 |
case 'blockquote': |
|
559 |
s.editor.execCommand('mceBlockQuote'); |
|
560 |
break; |
|
561 |
} |
|
562 |
} else if ( command === 'link' && window.wpLink ) { |
|
563 |
window.wpLink.open(); |
|
564 |
} |
0
|
565 |
|
5
|
566 |
if ( command === 'wp-media-library' && typeof wp !== 'undefined' && wp.media && wp.media.editor ) { |
|
567 |
wp.media.editor.open( s.id ); |
|
568 |
} |
0
|
569 |
}); |
|
570 |
}, |
|
571 |
|
|
572 |
fade: function( before, during, after ) { |
5
|
573 |
if ( ! s.$fullscreenFader ) { |
0
|
574 |
api.ui.init(); |
5
|
575 |
} |
0
|
576 |
|
|
577 |
// If any callback bound to before returns false, bail. |
5
|
578 |
if ( before && ! ps.publish( before ) ) { |
0
|
579 |
return; |
5
|
580 |
} |
0
|
581 |
|
5
|
582 |
api.fade.In( s.$fullscreenFader, 200, function() { |
|
583 |
if ( during ) { |
0
|
584 |
ps.publish( during ); |
5
|
585 |
} |
0
|
586 |
|
5
|
587 |
api.fade.Out( s.$fullscreenFader, 200, function() { |
|
588 |
if ( after ) { |
0
|
589 |
ps.publish( after ); |
5
|
590 |
} |
|
591 |
}); |
0
|
592 |
}); |
|
593 |
} |
|
594 |
}; |
|
595 |
|
|
596 |
api.fade = { |
|
597 |
// Sensitivity to allow browsers to render the blank element before animating. |
|
598 |
sensitivity: 100, |
|
599 |
|
|
600 |
In: function( element, speed, callback, stop ) { |
|
601 |
|
|
602 |
callback = callback || $.noop; |
|
603 |
speed = speed || 400; |
|
604 |
stop = stop || false; |
|
605 |
|
|
606 |
if ( api.fade.transitions ) { |
|
607 |
if ( element.is(':visible') ) { |
|
608 |
element.addClass( 'fade-trigger' ); |
|
609 |
return element; |
|
610 |
} |
|
611 |
|
|
612 |
element.show(); |
5
|
613 |
element.first().one( transitionend, function() { |
0
|
614 |
callback(); |
|
615 |
}); |
5
|
616 |
|
0
|
617 |
setTimeout( function() { element.addClass( 'fade-trigger' ); }, this.sensitivity ); |
|
618 |
} else { |
5
|
619 |
if ( stop ) { |
0
|
620 |
element.stop(); |
5
|
621 |
} |
0
|
622 |
|
|
623 |
element.css( 'opacity', 1 ); |
|
624 |
element.first().fadeIn( speed, callback ); |
|
625 |
|
5
|
626 |
if ( element.length > 1 ) { |
0
|
627 |
element.not(':first').fadeIn( speed ); |
5
|
628 |
} |
0
|
629 |
} |
|
630 |
|
|
631 |
return element; |
|
632 |
}, |
|
633 |
|
|
634 |
Out: function( element, speed, callback, stop ) { |
|
635 |
|
|
636 |
callback = callback || $.noop; |
|
637 |
speed = speed || 400; |
|
638 |
stop = stop || false; |
|
639 |
|
5
|
640 |
if ( ! element.is(':visible') ) { |
0
|
641 |
return element; |
5
|
642 |
} |
0
|
643 |
|
|
644 |
if ( api.fade.transitions ) { |
5
|
645 |
element.first().one( transitionend, function() { |
|
646 |
if ( element.hasClass('fade-trigger') ) { |
0
|
647 |
return; |
5
|
648 |
} |
0
|
649 |
|
|
650 |
element.hide(); |
|
651 |
callback(); |
|
652 |
}); |
|
653 |
setTimeout( function() { element.removeClass( 'fade-trigger' ); }, this.sensitivity ); |
|
654 |
} else { |
5
|
655 |
if ( stop ) { |
0
|
656 |
element.stop(); |
5
|
657 |
} |
0
|
658 |
|
|
659 |
element.first().fadeOut( speed, callback ); |
|
660 |
|
5
|
661 |
if ( element.length > 1 ) { |
0
|
662 |
element.not(':first').fadeOut( speed ); |
5
|
663 |
} |
0
|
664 |
} |
|
665 |
|
|
666 |
return element; |
|
667 |
}, |
|
668 |
|
5
|
669 |
// Check if the browser supports CSS 3.0 transitions |
|
670 |
transitions: ( function() { |
|
671 |
var style = document.documentElement.style; |
0
|
672 |
|
5
|
673 |
return ( typeof style.WebkitTransition === 'string' || |
|
674 |
typeof style.MozTransition === 'string' || |
|
675 |
typeof style.OTransition === 'string' || |
|
676 |
typeof style.transition === 'string' ); |
0
|
677 |
})() |
|
678 |
}; |
|
679 |
|
|
680 |
/** |
|
681 |
* Resize API |
|
682 |
* |
|
683 |
* Automatically updates textarea height. |
|
684 |
*/ |
|
685 |
api.bind_resize = function() { |
5
|
686 |
s.$dfwTextarea.on( 'keydown.wp-dfw-resize click.wp-dfw-resize paste.wp-dfw-resize', function() { |
|
687 |
api.resizeTextarea(); |
0
|
688 |
}); |
5
|
689 |
}; |
0
|
690 |
|
5
|
691 |
api.resizeTextarea = function() { |
|
692 |
var node = s.$dfwTextarea[0]; |
0
|
693 |
|
5
|
694 |
if ( node.scrollHeight > node.clientHeight ) { |
|
695 |
node.style.height = node.scrollHeight + 50 + 'px'; |
0
|
696 |
} |
|
697 |
}; |
|
698 |
|
5
|
699 |
// Export |
|
700 |
window.wp = window.wp || {}; |
|
701 |
window.wp.editor = window.wp.editor || {}; |
|
702 |
window.wp.editor.fullscreen = api; |
|
703 |
|
|
704 |
})( jQuery, window ); |