2011-04-24 21:01:34 -04:00
|
|
|
/**
|
2011-05-02 04:10:23 -04:00
|
|
|
* PubSub
|
|
|
|
*
|
|
|
|
* A lightweight publish/subscribe implementation.
|
|
|
|
* Private use only!
|
2011-04-24 21:01:34 -04:00
|
|
|
*/
|
2011-04-25 21:19:26 -04:00
|
|
|
var PubSub, fullscreen, wptitlehint;
|
|
|
|
|
|
|
|
PubSub = function() {
|
2011-04-24 21:01:34 -04:00
|
|
|
this.topics = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
PubSub.prototype.subscribe = function( topic, callback ) {
|
|
|
|
if ( ! this.topics[ topic ] )
|
|
|
|
this.topics[ topic ] = [];
|
|
|
|
|
|
|
|
this.topics[ topic ].push( callback );
|
|
|
|
return callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
PubSub.prototype.unsubscribe = function( topic, callback ) {
|
|
|
|
var i, l,
|
|
|
|
topics = this.topics[ topic ];
|
|
|
|
|
|
|
|
if ( ! topics )
|
|
|
|
return callback || [];
|
|
|
|
|
|
|
|
// Clear matching callbacks
|
|
|
|
if ( callback ) {
|
|
|
|
for ( i = 0, l = topics.length; i < l; i++ ) {
|
|
|
|
if ( callback == topics[i] )
|
|
|
|
topics.splice( i, 1 );
|
|
|
|
}
|
|
|
|
return callback;
|
|
|
|
|
|
|
|
// Clear all callbacks
|
|
|
|
} else {
|
|
|
|
this.topics[ topic ] = [];
|
|
|
|
return topics;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
PubSub.prototype.publish = function( topic, args ) {
|
2011-05-02 04:10:23 -04:00
|
|
|
var i, l, broken,
|
2011-04-24 21:01:34 -04:00
|
|
|
topics = this.topics[ topic ];
|
|
|
|
|
|
|
|
if ( ! topics )
|
|
|
|
return;
|
|
|
|
|
|
|
|
args = args || [];
|
|
|
|
|
|
|
|
for ( i = 0, l = topics.length; i < l; i++ ) {
|
2011-05-02 04:10:23 -04:00
|
|
|
broken = ( topics[i].apply( null, args ) === false || broken );
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
2011-05-02 04:10:23 -04:00
|
|
|
return ! broken;
|
2011-04-24 21:01:34 -04:00
|
|
|
};
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
/**
|
|
|
|
* Distraction Free Writing
|
|
|
|
* (wp-fullscreen)
|
|
|
|
*
|
|
|
|
* Access the API globally using the fullscreen variable.
|
|
|
|
*/
|
|
|
|
|
2011-04-24 21:01:34 -04:00
|
|
|
(function($){
|
2011-05-02 04:10:23 -04:00
|
|
|
var api, ps, bounder, s;
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
// Initialize the fullscreen/api object
|
|
|
|
fullscreen = api = {};
|
|
|
|
|
|
|
|
// Create the PubSub (publish/subscribe) interface.
|
|
|
|
ps = api.pubsub = new PubSub();
|
2011-05-02 04:10:23 -04:00
|
|
|
timer = 0;
|
|
|
|
block = false;
|
|
|
|
|
|
|
|
s = api.settings = { // Settings
|
|
|
|
visible : false,
|
|
|
|
mode : 'tinymce',
|
|
|
|
editor_id : 'content',
|
2011-08-03 06:19:00 -04:00
|
|
|
title_id : '',
|
2011-06-03 20:46:47 -04:00
|
|
|
timer : 0,
|
|
|
|
toolbar_shown : false
|
2011-05-02 04:10:23 -04:00
|
|
|
}
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
/**
|
2011-05-02 04:10:23 -04:00
|
|
|
* Bounder
|
2011-04-24 21:01:34 -04:00
|
|
|
*
|
|
|
|
* Creates a function that publishes start/stop topics.
|
2011-05-02 04:10:23 -04:00
|
|
|
* Used to throttle events.
|
2011-04-24 21:01:34 -04:00
|
|
|
*/
|
2011-06-10 17:08:49 -04:00
|
|
|
bounder = api.bounder = function( start, stop, delay, e ) {
|
|
|
|
var y, top;
|
|
|
|
|
2011-04-24 21:01:34 -04:00
|
|
|
delay = delay || 1250;
|
|
|
|
|
2011-06-10 17:08:49 -04:00
|
|
|
if ( e ) {
|
|
|
|
y = e.pageY || e.clientY || e.offsetY;
|
|
|
|
top = $(document).scrollTop();
|
|
|
|
|
|
|
|
if ( !e.isDefaultPrevented ) // test if e ic jQuery normalized
|
|
|
|
y = 135 + y;
|
|
|
|
|
|
|
|
if ( y - top > 120 )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( block )
|
2011-04-24 21:01:34 -04:00
|
|
|
return;
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
block = true;
|
2011-04-25 21:19:26 -04:00
|
|
|
|
2011-04-24 21:01:34 -04:00
|
|
|
setTimeout( function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
block = false;
|
2011-04-26 03:20:56 -04:00
|
|
|
}, 400 );
|
2011-04-24 21:01:34 -04:00
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.timer )
|
|
|
|
clearTimeout( s.timer );
|
2011-04-24 21:01:34 -04:00
|
|
|
else
|
|
|
|
ps.publish( start );
|
|
|
|
|
|
|
|
function timed() {
|
|
|
|
ps.publish( stop );
|
2011-05-02 04:10:23 -04:00
|
|
|
s.timer = 0;
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
s.timer = setTimeout( timed, delay );
|
2011-04-24 21:01:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-05-02 04:10:23 -04:00
|
|
|
* on()
|
|
|
|
*
|
|
|
|
* Turns fullscreen on.
|
|
|
|
*
|
|
|
|
* @param string mode Optional. Switch to the given mode before opening.
|
2011-04-24 21:01:34 -04:00
|
|
|
*/
|
|
|
|
api.on = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.visible )
|
|
|
|
return;
|
|
|
|
|
2011-08-03 06:19:00 -04:00
|
|
|
// Settings can be added or changed by defining "wp_fullscreen_settings" JS object.
|
2011-09-29 18:59:49 -04:00
|
|
|
if ( typeof(wp_fullscreen_settings) == 'object' )
|
2011-08-03 06:19:00 -04:00
|
|
|
$.extend( s, wp_fullscreen_settings );
|
|
|
|
|
|
|
|
s.editor_id = wpActiveEditor || 'content';
|
|
|
|
|
2012-03-09 18:23:10 -05:00
|
|
|
if ( $('input#title').length && s.editor_id == 'content' )
|
|
|
|
s.title_id = 'title';
|
|
|
|
else if ( $('input#' + s.editor_id + '-title').length ) // the title input field should have [editor_id]-title HTML ID to be auto detected
|
|
|
|
s.title_id = s.editor_id + '-title';
|
|
|
|
else
|
|
|
|
$('#wp-fullscreen-title, #wp-fullscreen-title-prompt-text').hide();
|
2011-08-03 06:19:00 -04:00
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
s.mode = $('#' + s.editor_id).is(':hidden') ? 'tinymce' : 'html';
|
2011-08-03 06:19:00 -04:00
|
|
|
s.qt_canvas = $('#' + s.editor_id).get(0);
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
if ( ! s.element )
|
2011-04-24 21:01:34 -04:00
|
|
|
api.ui.init();
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
s.is_mce_on = s.has_tinymce && typeof( tinyMCE.get(s.editor_id) ) != 'undefined';
|
|
|
|
|
|
|
|
api.ui.fade( 'show', 'showing', 'shown' );
|
2011-04-24 21:01:34 -04:00
|
|
|
};
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
/**
|
|
|
|
* off()
|
|
|
|
*
|
|
|
|
* Turns fullscreen off.
|
|
|
|
*/
|
2011-04-24 21:01:34 -04:00
|
|
|
api.off = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( ! s.visible )
|
|
|
|
return;
|
|
|
|
|
|
|
|
api.ui.fade( 'hide', 'hiding', 'hidden' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* switchmode()
|
|
|
|
*
|
|
|
|
* @return string - The current mode.
|
|
|
|
*
|
|
|
|
* @param string to - The fullscreen mode to switch to.
|
|
|
|
* @event switchMode
|
|
|
|
* @eventparam string to - The new mode.
|
|
|
|
* @eventparam string from - The old mode.
|
|
|
|
*/
|
|
|
|
api.switchmode = function( to ) {
|
|
|
|
var from = s.mode;
|
|
|
|
|
|
|
|
if ( ! to || ! s.visible || ! s.has_tinymce )
|
|
|
|
return from;
|
|
|
|
|
|
|
|
// Don't switch if the mode is the same.
|
|
|
|
if ( from == to )
|
|
|
|
return from;
|
|
|
|
|
|
|
|
ps.publish( 'switchMode', [ from, to ] );
|
|
|
|
s.mode = to;
|
|
|
|
ps.publish( 'switchedMode', [ from, to ] );
|
|
|
|
|
|
|
|
return to;
|
2011-04-24 21:01:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-05-02 04:10:23 -04:00
|
|
|
* General
|
2011-04-24 21:01:34 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
api.save = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
var hidden = $('#hiddenaction'), old = hidden.val(), spinner = $('#wp-fullscreen-save img'),
|
|
|
|
message = $('#wp-fullscreen-save span');
|
|
|
|
|
|
|
|
spinner.show();
|
|
|
|
api.savecontent();
|
|
|
|
|
|
|
|
hidden.val('wp-fullscreen-save-post');
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
$.post( ajaxurl, $('form#post').serialize(), function(r){
|
2011-05-02 04:10:23 -04:00
|
|
|
spinner.hide();
|
|
|
|
message.show();
|
2011-04-24 21:01:34 -04:00
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
setTimeout( function(){
|
2011-05-07 22:01:53 -04:00
|
|
|
message.fadeOut(1000);
|
2011-05-02 04:10:23 -04:00
|
|
|
}, 3000 );
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
if ( r.last_edited )
|
2011-05-02 04:10:23 -04:00
|
|
|
$('#wp-fullscreen-save input').attr( 'title', r.last_edited );
|
|
|
|
|
2011-04-24 21:01:34 -04:00
|
|
|
}, 'json');
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
hidden.val(old);
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
api.savecontent = function() {
|
|
|
|
var ed, content;
|
|
|
|
|
2011-08-03 06:19:00 -04:00
|
|
|
if ( s.title_id )
|
|
|
|
$('#' + s.title_id).val( $('#wp-fullscreen-title').val() );
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
if ( s.mode === 'tinymce' && (ed = tinyMCE.get('wp_mce_fullscreen')) ) {
|
|
|
|
content = ed.save();
|
|
|
|
} else {
|
|
|
|
content = $('#wp_mce_fullscreen').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#' + s.editor_id).val( content );
|
2011-05-16 02:17:44 -04:00
|
|
|
$(document).triggerHandler('wpcountwords', [ content ]);
|
2011-05-02 04:10:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
set_title_hint = function( title ) {
|
|
|
|
if ( ! title.val().length )
|
2011-04-24 21:01:34 -04:00
|
|
|
title.siblings('label').css( 'visibility', '' );
|
|
|
|
else
|
|
|
|
title.siblings('label').css( 'visibility', 'hidden' );
|
|
|
|
}
|
|
|
|
|
2011-05-07 22:01:53 -04:00
|
|
|
api.dfw_width = function(n) {
|
|
|
|
var el = $('#wp-fullscreen-wrap'), w = el.width();
|
|
|
|
|
|
|
|
if ( !n ) { // reset to theme width
|
|
|
|
el.width( $('#wp-fullscreen-central-toolbar').width() );
|
|
|
|
deleteUserSetting('dfw_width');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-05 03:03:26 -04:00
|
|
|
w = n + w;
|
|
|
|
|
2011-05-07 22:01:53 -04:00
|
|
|
if ( w < 200 || w > 1200 ) // sanity check
|
|
|
|
return;
|
|
|
|
|
2011-07-05 03:03:26 -04:00
|
|
|
el.width( w );
|
|
|
|
setUserSetting('dfw_width', w);
|
2011-05-07 22:01:53 -04:00
|
|
|
}
|
|
|
|
|
2011-04-24 21:01:34 -04:00
|
|
|
ps.subscribe( 'showToolbar', function() {
|
2011-05-11 05:18:32 -04:00
|
|
|
s.toolbars.removeClass('fade-1000').addClass('fade-300');
|
|
|
|
api.fade.In( s.toolbars, 300, function(){ ps.publish('toolbarShown'); }, true );
|
2011-04-24 21:01:34 -04:00
|
|
|
$('#wp-fullscreen-body').addClass('wp-fullscreen-focus');
|
2011-06-03 20:46:47 -04:00
|
|
|
s.toolbar_shown = true;
|
2011-04-24 21:01:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
ps.subscribe( 'hideToolbar', function() {
|
2011-05-11 05:18:32 -04:00
|
|
|
s.toolbars.removeClass('fade-300').addClass('fade-1000');
|
|
|
|
api.fade.Out( s.toolbars, 1000, function(){ ps.publish('toolbarHidden'); }, true );
|
2011-04-24 21:01:34 -04:00
|
|
|
$('#wp-fullscreen-body').removeClass('wp-fullscreen-focus');
|
2011-04-26 03:20:56 -04:00
|
|
|
});
|
|
|
|
|
2011-05-07 22:01:53 -04:00
|
|
|
ps.subscribe( 'toolbarShown', function() {
|
2011-05-11 05:18:32 -04:00
|
|
|
s.toolbars.removeClass('fade-300');
|
2011-05-07 22:01:53 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
ps.subscribe( 'toolbarHidden', function() {
|
2011-05-11 05:18:32 -04:00
|
|
|
s.toolbars.removeClass('fade-1000');
|
2011-06-03 20:46:47 -04:00
|
|
|
s.toolbar_shown = false;
|
2011-05-07 22:01:53 -04:00
|
|
|
});
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
ps.subscribe( 'show', function() { // This event occurs before the overlay blocks the UI.
|
2011-08-03 06:19:00 -04:00
|
|
|
var title;
|
|
|
|
|
|
|
|
if ( s.title_id ) {
|
|
|
|
title = $('#wp-fullscreen-title').val( $('#' + s.title_id).val() );
|
|
|
|
set_title_hint( title );
|
|
|
|
}
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
$('#wp-fullscreen-save input').attr( 'title', $('#last-edit').text() );
|
|
|
|
|
2011-08-03 06:19:00 -04:00
|
|
|
s.textarea_obj.value = s.qt_canvas.value;
|
2011-04-26 03:20:56 -04:00
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.has_tinymce && s.mode === 'tinymce' )
|
|
|
|
tinyMCE.execCommand('wpFullScreenInit');
|
|
|
|
|
|
|
|
s.orig_y = $(window).scrollTop();
|
2011-04-24 21:01:34 -04:00
|
|
|
});
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
ps.subscribe( 'showing', function() { // This event occurs while the DFW overlay blocks the UI.
|
|
|
|
$( document.body ).addClass( 'fullscreen-active' );
|
|
|
|
api.refresh_buttons();
|
|
|
|
|
2011-06-10 17:08:49 -04:00
|
|
|
$( document ).bind( 'mousemove.fullscreen', function(e) { bounder( 'showToolbar', 'hideToolbar', 2000, e ); } );
|
2011-05-07 22:01:53 -04:00
|
|
|
bounder( 'showToolbar', 'hideToolbar', 2000 );
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
api.bind_resize();
|
|
|
|
setTimeout( api.resize_textarea, 200 );
|
|
|
|
|
2011-05-13 02:27:49 -04:00
|
|
|
// scroll to top so the user is not disoriented
|
|
|
|
scrollTo(0, 0);
|
2011-05-30 15:22:09 -04:00
|
|
|
|
|
|
|
// needed it for IE7 and compat mode
|
2011-06-08 16:55:33 -04:00
|
|
|
$('#wpadminbar').hide();
|
2011-04-24 21:01:34 -04:00
|
|
|
});
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
ps.subscribe( 'shown', function() { // This event occurs after the DFW overlay is shown
|
2011-08-26 15:33:14 -04:00
|
|
|
var interim_init;
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
s.visible = true;
|
|
|
|
|
|
|
|
// init the standard TinyMCE instance if missing
|
|
|
|
if ( s.has_tinymce && ! s.is_mce_on ) {
|
|
|
|
|
2011-08-26 15:33:14 -04:00
|
|
|
interim_init = function(mce, ed) {
|
|
|
|
var el = ed.getElement(), old_val = el.value, settings = tinyMCEPreInit.mceInit[s.editor_id];
|
|
|
|
|
|
|
|
if ( settings && settings.wpautop && typeof(switchEditors) != 'undefined' )
|
|
|
|
el.value = switchEditors.wpautop( el.value );
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
ed.onInit.add(function(ed) {
|
|
|
|
ed.hide();
|
|
|
|
ed.getElement().value = old_val;
|
2011-08-26 15:33:14 -04:00
|
|
|
tinymce.onAddEditor.remove(interim_init);
|
2011-05-02 04:10:23 -04:00
|
|
|
});
|
2011-08-26 15:33:14 -04:00
|
|
|
};
|
2011-05-02 04:10:23 -04:00
|
|
|
|
2011-08-26 15:33:14 -04:00
|
|
|
tinymce.onAddEditor.add(interim_init);
|
2011-08-03 06:19:00 -04:00
|
|
|
tinyMCE.init(tinyMCEPreInit.mceInit[s.editor_id]);
|
2011-08-26 15:33:14 -04:00
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
s.is_mce_on = true;
|
|
|
|
}
|
2011-09-18 20:47:23 -04:00
|
|
|
|
|
|
|
wpActiveEditor = 'wp_mce_fullscreen';
|
2011-04-24 21:01:34 -04:00
|
|
|
});
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
ps.subscribe( 'hide', function() { // This event occurs before the overlay blocks DFW.
|
2011-08-26 15:33:14 -04:00
|
|
|
var htmled_is_hidden = $('#' + s.editor_id).is(':hidden');
|
2011-06-08 16:55:33 -04:00
|
|
|
// Make sure the correct editor is displaying.
|
2011-08-26 15:33:14 -04:00
|
|
|
if ( s.has_tinymce && s.mode === 'tinymce' && !htmled_is_hidden ) {
|
2011-11-16 21:44:28 -05:00
|
|
|
switchEditors.go(s.editor_id, 'tmce');
|
2011-08-26 15:33:14 -04:00
|
|
|
} else if ( s.mode === 'html' && htmled_is_hidden ) {
|
2011-11-16 21:44:28 -05:00
|
|
|
switchEditors.go(s.editor_id, 'html');
|
2011-06-08 16:55:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save content must be after switchEditors or content will be overwritten. See #17229.
|
2011-05-02 04:10:23 -04:00
|
|
|
api.savecontent();
|
2011-06-08 16:55:33 -04:00
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
$( document ).unbind( '.fullscreen' );
|
|
|
|
$(s.textarea_obj).unbind('.grow');
|
|
|
|
|
|
|
|
if ( s.has_tinymce && s.mode === 'tinymce' )
|
|
|
|
tinyMCE.execCommand('wpFullScreenSave');
|
|
|
|
|
2011-08-03 06:19:00 -04:00
|
|
|
if ( s.title_id )
|
|
|
|
set_title_hint( $('#' + s.title_id) );
|
2011-05-02 04:10:23 -04:00
|
|
|
|
2011-08-03 06:19:00 -04:00
|
|
|
s.qt_canvas.value = s.textarea_obj.value;
|
2011-04-24 21:01:34 -04:00
|
|
|
});
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
ps.subscribe( 'hiding', function() { // This event occurs while the overlay blocks the DFW UI.
|
|
|
|
|
2011-04-24 21:01:34 -04:00
|
|
|
$( document.body ).removeClass( 'fullscreen-active' );
|
2011-05-02 04:10:23 -04:00
|
|
|
scrollTo(0, s.orig_y);
|
2011-05-30 15:22:09 -04:00
|
|
|
$('#wpadminbar').show();
|
2011-04-24 21:01:34 -04:00
|
|
|
});
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
ps.subscribe( 'hidden', function() { // This event occurs after DFW is removed.
|
|
|
|
s.visible = false;
|
2011-08-03 06:19:00 -04:00
|
|
|
$('#wp_mce_fullscreen, #wp-fullscreen-title').removeAttr('style');
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
if ( s.has_tinymce && s.is_mce_on )
|
|
|
|
tinyMCE.execCommand('wpFullScreenClose');
|
|
|
|
|
|
|
|
s.textarea_obj.value = '';
|
|
|
|
api.oldheight = 0;
|
2011-09-18 20:47:23 -04:00
|
|
|
wpActiveEditor = s.editor_id;
|
2011-04-24 21:01:34 -04:00
|
|
|
});
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
ps.subscribe( 'switchMode', function( from, to ) {
|
|
|
|
var ed;
|
|
|
|
|
|
|
|
if ( !s.has_tinymce || !s.is_mce_on )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ed = tinyMCE.get('wp_mce_fullscreen');
|
|
|
|
|
|
|
|
if ( from === 'html' && to === 'tinymce' ) {
|
2011-08-26 15:33:14 -04:00
|
|
|
|
|
|
|
if ( tinyMCE.get(s.editor_id).getParam('wpautop') && typeof(switchEditors) != 'undefined' )
|
|
|
|
s.textarea_obj.value = switchEditors.wpautop( s.textarea_obj.value );
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
if ( 'undefined' == typeof(ed) )
|
|
|
|
tinyMCE.execCommand('wpFullScreenInit');
|
|
|
|
else
|
|
|
|
ed.show();
|
|
|
|
|
|
|
|
} else if ( from === 'tinymce' && to === 'html' ) {
|
|
|
|
if ( ed )
|
|
|
|
ed.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ps.subscribe( 'switchedMode', function( from, to ) {
|
2011-05-07 22:01:53 -04:00
|
|
|
api.refresh_buttons(true);
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
if ( to === 'html' )
|
|
|
|
setTimeout( api.resize_textarea, 200 );
|
2011-04-24 21:01:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Buttons
|
|
|
|
*/
|
|
|
|
api.b = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('Bold');
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
api.i = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('Italic');
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
api.ul = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('InsertUnorderedList');
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
api.ol = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('InsertOrderedList');
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
api.link = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('WP_Link');
|
|
|
|
else
|
|
|
|
wpLink.open();
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
api.unlink = function() {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('unlink');
|
|
|
|
}
|
|
|
|
|
2011-05-10 19:21:34 -04:00
|
|
|
api.atd = function() {
|
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('mceWritingImprovementTool');
|
|
|
|
}
|
|
|
|
|
|
|
|
api.help = function() {
|
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('WP_Help');
|
|
|
|
}
|
|
|
|
|
|
|
|
api.blockquote = function() {
|
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode )
|
|
|
|
tinyMCE.execCommand('mceBlockQuote');
|
|
|
|
}
|
|
|
|
|
2011-09-18 20:47:23 -04:00
|
|
|
api.medialib = function() {
|
2011-09-26 15:23:43 -04:00
|
|
|
if ( s.has_tinymce && 'tinymce' === s.mode ) {
|
2011-09-18 20:47:23 -04:00
|
|
|
tinyMCE.execCommand('WP_Medialib');
|
2011-09-26 15:23:43 -04:00
|
|
|
} else {
|
|
|
|
var href = $('#wp-' + s.editor_id + '-media-buttons a.thickbox').attr('href') || '';
|
|
|
|
|
|
|
|
if ( href )
|
|
|
|
tb_show('', href);
|
|
|
|
}
|
2011-09-18 20:47:23 -04:00
|
|
|
}
|
|
|
|
|
2011-05-07 22:01:53 -04:00
|
|
|
api.refresh_buttons = function( fade ) {
|
|
|
|
fade = fade || false;
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
if ( s.mode === 'html' ) {
|
|
|
|
$('#wp-fullscreen-mode-bar').removeClass('wp-tmce-mode').addClass('wp-html-mode');
|
2011-05-07 22:01:53 -04:00
|
|
|
|
|
|
|
if ( fade )
|
|
|
|
$('#wp-fullscreen-button-bar').fadeOut( 150, function(){
|
|
|
|
$(this).addClass('wp-html-mode').fadeIn( 150 );
|
|
|
|
});
|
|
|
|
else
|
|
|
|
$('#wp-fullscreen-button-bar').addClass('wp-html-mode');
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
} else if ( s.mode === 'tinymce' ) {
|
|
|
|
$('#wp-fullscreen-mode-bar').removeClass('wp-html-mode').addClass('wp-tmce-mode');
|
2011-05-07 22:01:53 -04:00
|
|
|
|
|
|
|
if ( fade )
|
|
|
|
$('#wp-fullscreen-button-bar').fadeOut( 150, function(){
|
|
|
|
$(this).removeClass('wp-html-mode').fadeIn( 150 );
|
|
|
|
});
|
|
|
|
else
|
|
|
|
$('#wp-fullscreen-button-bar').removeClass('wp-html-mode');
|
2011-05-02 04:10:23 -04:00
|
|
|
}
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-02 04:10:23 -04:00
|
|
|
* UI Elements
|
|
|
|
*
|
|
|
|
* Used for transitioning between states.
|
2011-04-24 21:01:34 -04:00
|
|
|
*/
|
|
|
|
api.ui = {
|
|
|
|
init: function() {
|
2011-05-16 02:17:44 -04:00
|
|
|
var topbar = $('#fullscreen-topbar'), txtarea = $('#wp_mce_fullscreen'), last = 0;
|
2011-08-03 06:19:00 -04:00
|
|
|
|
2011-05-11 05:18:32 -04:00
|
|
|
s.toolbars = topbar.add( $('#wp-fullscreen-status') );
|
2011-05-02 04:10:23 -04:00
|
|
|
s.element = $('#fullscreen-fader');
|
2011-05-16 02:17:44 -04:00
|
|
|
s.textarea_obj = txtarea[0];
|
2011-08-03 06:19:00 -04:00
|
|
|
s.has_tinymce = typeof(tinymce) != 'undefined';
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
if ( !s.has_tinymce )
|
|
|
|
$('#wp-fullscreen-mode-bar').hide();
|
2011-04-24 21:01:34 -04:00
|
|
|
|
2011-09-29 18:59:49 -04:00
|
|
|
if ( wptitlehint && $('#wp-fullscreen-title').length )
|
2011-04-24 21:01:34 -04:00
|
|
|
wptitlehint('wp-fullscreen-title');
|
2011-04-26 03:20:56 -04:00
|
|
|
|
2011-05-08 02:32:44 -04:00
|
|
|
$(document).keyup(function(e){
|
2011-06-03 20:46:47 -04:00
|
|
|
var c = e.keyCode || e.charCode, a, data;
|
2011-05-08 02:32:44 -04:00
|
|
|
|
|
|
|
if ( !fullscreen.settings.visible )
|
2011-05-07 22:01:53 -04:00
|
|
|
return true;
|
|
|
|
|
2011-06-03 20:46:47 -04:00
|
|
|
if ( navigator.platform && navigator.platform.indexOf('Mac') != -1 )
|
|
|
|
a = e.ctrlKey; // Ctrl key for Mac
|
|
|
|
else
|
|
|
|
a = e.altKey; // Alt key for Win & Linux
|
|
|
|
|
2011-05-28 22:04:52 -04:00
|
|
|
if ( 27 == c ) { // Esc
|
|
|
|
data = {
|
|
|
|
event: e,
|
|
|
|
what: 'dfw',
|
|
|
|
cb: fullscreen.off,
|
|
|
|
condition: function(){
|
|
|
|
if ( $('#TB_window').is(':visible') || $('.wp-dialog').is(':visible') )
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-29 01:07:32 -04:00
|
|
|
if ( ! jQuery(document).triggerHandler( 'wp_CloseOnEscape', [data] ) )
|
2011-05-28 22:04:52 -04:00
|
|
|
fullscreen.off();
|
|
|
|
}
|
2011-05-07 22:01:53 -04:00
|
|
|
|
2011-06-03 20:46:47 -04:00
|
|
|
if ( a && (61 == c || 107 == c || 187 == c) ) // +
|
|
|
|
api.dfw_width(25);
|
|
|
|
|
|
|
|
if ( a && (45 == c || 109 == c || 189 == c) ) // -
|
|
|
|
api.dfw_width(-25);
|
|
|
|
|
|
|
|
if ( a && 48 == c ) // 0
|
|
|
|
api.dfw_width(0);
|
|
|
|
|
2011-05-28 22:04:52 -04:00
|
|
|
return false;
|
2011-05-07 22:01:53 -04:00
|
|
|
});
|
|
|
|
|
2012-07-05 11:28:13 -04:00
|
|
|
// word count in Text mode
|
2011-05-16 02:17:44 -04:00
|
|
|
if ( typeof(wpWordCount) != 'undefined' ) {
|
|
|
|
|
|
|
|
txtarea.keyup( function(e) {
|
|
|
|
var k = e.keyCode || e.charCode;
|
|
|
|
|
|
|
|
if ( k == last )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( 13 == k || 8 == last || 46 == last )
|
|
|
|
$(document).triggerHandler('wpcountwords', [ txtarea.val() ]);
|
|
|
|
|
|
|
|
last = k;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-04-26 03:20:56 -04:00
|
|
|
topbar.mouseenter(function(e){
|
2011-05-11 05:18:32 -04:00
|
|
|
s.toolbars.addClass('fullscreen-make-sticky');
|
2011-05-02 04:10:23 -04:00
|
|
|
$( document ).unbind( '.fullscreen' );
|
|
|
|
clearTimeout( s.timer );
|
|
|
|
s.timer = 0;
|
2011-04-26 03:20:56 -04:00
|
|
|
}).mouseleave(function(e){
|
2011-05-11 05:18:32 -04:00
|
|
|
s.toolbars.removeClass('fullscreen-make-sticky');
|
2011-05-19 01:35:08 -04:00
|
|
|
|
|
|
|
if ( s.visible )
|
2011-06-10 17:08:49 -04:00
|
|
|
$( document ).bind( 'mousemove.fullscreen', function(e) { bounder( 'showToolbar', 'hideToolbar', 2000, e ); } );
|
2011-04-26 03:20:56 -04:00
|
|
|
});
|
2011-04-24 21:01:34 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
fade: function( before, during, after ) {
|
2011-05-02 04:10:23 -04:00
|
|
|
if ( ! s.element )
|
|
|
|
api.ui.init();
|
|
|
|
|
|
|
|
// If any callback bound to before returns false, bail.
|
|
|
|
if ( before && ! ps.publish( before ) )
|
|
|
|
return;
|
2011-04-24 21:01:34 -04:00
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
api.fade.In( s.element, 600, function() {
|
2011-04-24 21:01:34 -04:00
|
|
|
if ( during )
|
|
|
|
ps.publish( during );
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
api.fade.Out( s.element, 600, function() {
|
2011-04-24 21:01:34 -04:00
|
|
|
if ( after )
|
|
|
|
ps.publish( after );
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
api.fade = {
|
2011-04-24 21:28:23 -04:00
|
|
|
transitionend: 'transitionend webkitTransitionEnd oTransitionEnd',
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
// Sensitivity to allow browsers to render the blank element before animating.
|
|
|
|
sensitivity: 100,
|
|
|
|
|
2011-05-07 22:01:53 -04:00
|
|
|
In: function( element, speed, callback, stop ) {
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
callback = callback || $.noop;
|
|
|
|
speed = speed || 400;
|
2011-05-07 22:01:53 -04:00
|
|
|
stop = stop || false;
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
if ( api.fade.transitions ) {
|
|
|
|
if ( element.is(':visible') ) {
|
|
|
|
element.addClass( 'fade-trigger' );
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
element.show();
|
2011-05-11 05:18:32 -04:00
|
|
|
element.first().one( this.transitionend, function() {
|
2011-04-24 21:01:34 -04:00
|
|
|
callback();
|
|
|
|
});
|
2011-04-25 21:19:26 -04:00
|
|
|
setTimeout( function() { element.addClass( 'fade-trigger' ); }, this.sensitivity );
|
2011-04-24 21:01:34 -04:00
|
|
|
} else {
|
2011-05-07 22:01:53 -04:00
|
|
|
if ( stop )
|
|
|
|
element.stop();
|
|
|
|
|
2011-05-11 05:18:32 -04:00
|
|
|
element.css( 'opacity', 1 );
|
|
|
|
element.first().fadeIn( speed, callback );
|
|
|
|
|
|
|
|
if ( element.length > 1 )
|
|
|
|
element.not(':first').fadeIn( speed );
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2011-05-07 22:01:53 -04:00
|
|
|
Out: function( element, speed, callback, stop ) {
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
callback = callback || $.noop;
|
|
|
|
speed = speed || 400;
|
2011-05-07 22:01:53 -04:00
|
|
|
stop = stop || false;
|
2011-04-24 21:01:34 -04:00
|
|
|
|
|
|
|
if ( ! element.is(':visible') )
|
|
|
|
return element;
|
|
|
|
|
|
|
|
if ( api.fade.transitions ) {
|
2011-05-11 05:18:32 -04:00
|
|
|
element.first().one( api.fade.transitionend, function() {
|
2011-04-24 21:01:34 -04:00
|
|
|
if ( element.hasClass('fade-trigger') )
|
|
|
|
return;
|
|
|
|
|
|
|
|
element.hide();
|
|
|
|
callback();
|
|
|
|
});
|
2011-04-25 21:19:26 -04:00
|
|
|
setTimeout( function() { element.removeClass( 'fade-trigger' ); }, this.sensitivity );
|
2011-04-24 21:01:34 -04:00
|
|
|
} else {
|
2011-05-07 22:01:53 -04:00
|
|
|
if ( stop )
|
|
|
|
element.stop();
|
|
|
|
|
2011-05-11 05:18:32 -04:00
|
|
|
element.first().fadeOut( speed, callback );
|
|
|
|
|
|
|
|
if ( element.length > 1 )
|
|
|
|
element.not(':first').fadeOut( speed );
|
2011-04-24 21:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
transitions: (function() { // Check if the browser supports CSS 3.0 transitions
|
2011-04-24 21:01:34 -04:00
|
|
|
var s = document.documentElement.style;
|
|
|
|
|
|
|
|
return ( typeof ( s.WebkitTransition ) == 'string' ||
|
|
|
|
typeof ( s.MozTransition ) == 'string' ||
|
|
|
|
typeof ( s.OTransition ) == 'string' ||
|
|
|
|
typeof ( s.transition ) == 'string' );
|
|
|
|
})()
|
|
|
|
};
|
|
|
|
|
2011-05-02 04:10:23 -04:00
|
|
|
/**
|
|
|
|
* Resize API
|
|
|
|
*
|
|
|
|
* Automatically updates textarea height.
|
|
|
|
*/
|
|
|
|
|
|
|
|
api.bind_resize = function() {
|
|
|
|
$(s.textarea_obj).bind('keypress.grow click.grow paste.grow', function(){
|
|
|
|
setTimeout( api.resize_textarea, 200 );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
api.oldheight = 0;
|
|
|
|
api.resize_textarea = function() {
|
2011-05-07 22:01:53 -04:00
|
|
|
var txt = s.textarea_obj, newheight;
|
2011-05-02 04:10:23 -04:00
|
|
|
|
|
|
|
newheight = txt.scrollHeight > 300 ? txt.scrollHeight : 300;
|
|
|
|
|
|
|
|
if ( newheight != api.oldheight ) {
|
|
|
|
txt.style.height = newheight + 'px';
|
|
|
|
api.oldheight = newheight;
|
|
|
|
}
|
2011-04-24 21:01:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery);
|