1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
var PubSub,fullscreen,wptitlehint;PubSub=function(){this.topics={}},PubSub.prototype.subscribe=function(a,b){return this.topics[a]||(this.topics[a]=[]),this.topics[a].push(b),b},PubSub.prototype.unsubscribe=function(a,b){var c,d,e=this.topics[a];if(!e)return b||[];if(b){for(c=0,d=e.length;d>c;c++)b==e[c]&&e.splice(c,1);return b}return this.topics[a]=[],e},PubSub.prototype.publish=function(a,b){var c,d,e,f=this.topics[a];if(f){for(b=b||[],c=0,d=f.length;d>c;c++)e=f[c].apply(null,b)===!1||e;return!e}},function(a){var b,c,d,e;fullscreen=b={},c=b.pubsub=new PubSub,timer=0,block=!1,e=b.settings={visible:!1,mode:"tinymce",editor_id:"content",title_id:"",timer:0,toolbar_shown:!1},d=b.bounder=function(b,d,f,g){function h(){c.publish(d),e.timer=0}var i,j;f=f||1250,g&&(i=g.pageY||g.clientY||g.offsetY,j=a(document).scrollTop(),g.isDefaultPrevented||(i=135+i),i-j>120)||block||(block=!0,setTimeout(function(){block=!1},400),e.timer?clearTimeout(e.timer):c.publish(b),e.timer=setTimeout(h,f))},b.on=function(){e.visible||("object"==typeof wp_fullscreen_settings&&a.extend(e,wp_fullscreen_settings),e.editor_id=wpActiveEditor||"content",a("input#title").length&&"content"==e.editor_id?e.title_id="title":a("input#"+e.editor_id+"-title").length?e.title_id=e.editor_id+"-title":a("#wp-fullscreen-title, #wp-fullscreen-title-prompt-text").hide(),e.mode=a("#"+e.editor_id).is(":hidden")?"tinymce":"html",e.qt_canvas=a("#"+e.editor_id).get(0),e.element||b.ui.init(),e.is_mce_on=e.has_tinymce&&"undefined"!=typeof tinyMCE.get(e.editor_id),b.ui.fade("show","showing","shown"))},b.off=function(){e.visible&&b.ui.fade("hide","hiding","hidden")},b.switchmode=function(a){var b=e.mode;return a&&e.visible&&e.has_tinymce?b==a?b:(c.publish("switchMode",[b,a]),e.mode=a,c.publish("switchedMode",[b,a]),a):b},b.save=function(){var c=a("#hiddenaction"),d=c.val(),e=a("#wp-fullscreen-save .spinner"),f=a("#wp-fullscreen-save span");e.show(),b.savecontent(),c.val("wp-fullscreen-save-post"),a.post(ajaxurl,a("form#post").serialize(),function(b){e.hide(),f.show(),setTimeout(function(){f.fadeOut(1e3)},3e3),b.last_edited&&a("#wp-fullscreen-save input").attr("title",b.last_edited)},"json"),c.val(d)},b.savecontent=function(){var b,c;e.title_id&&a("#"+e.title_id).val(a("#wp-fullscreen-title").val()),c="tinymce"===e.mode&&(b=tinyMCE.get("wp_mce_fullscreen"))?b.save():a("#wp_mce_fullscreen").val(),a("#"+e.editor_id).val(c),a(document).triggerHandler("wpcountwords",[c])},set_title_hint=function(a){a.val().length?a.siblings("label").css("visibility","hidden"):a.siblings("label").css("visibility","")},b.dfw_width=function(b){var c=a("#wp-fullscreen-wrap"),d=c.width();return b?(d=b+d,200>d||d>1200||(c.width(d),setUserSetting("dfw_width",d)),void 0):(c.width(a("#wp-fullscreen-central-toolbar").width()),deleteUserSetting("dfw_width"),void 0)},c.subscribe("showToolbar",function(){e.toolbars.removeClass("fade-1000").addClass("fade-300"),b.fade.In(e.toolbars,300,function(){c.publish("toolbarShown")},!0),a("#wp-fullscreen-body").addClass("wp-fullscreen-focus"),e.toolbar_shown=!0}),c.subscribe("hideToolbar",function(){e.toolbars.removeClass("fade-300").addClass("fade-1000"),b.fade.Out(e.toolbars,1e3,function(){c.publish("toolbarHidden")},!0),a("#wp-fullscreen-body").removeClass("wp-fullscreen-focus")}),c.subscribe("toolbarShown",function(){e.toolbars.removeClass("fade-300")}),c.subscribe("toolbarHidden",function(){e.toolbars.removeClass("fade-1000"),e.toolbar_shown=!1}),c.subscribe("show",function(){var b;e.title_id&&(b=a("#wp-fullscreen-title").val(a("#"+e.title_id).val()),set_title_hint(b)),a("#wp-fullscreen-save input").attr("title",a("#last-edit").text()),e.textarea_obj.value=e.qt_canvas.value,e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("wpFullScreenInit"),e.orig_y=a(window).scrollTop()}),c.subscribe("showing",function(){a(document.body).addClass("fullscreen-active"),b.refresh_buttons(),a(document).bind("mousemove.fullscreen",function(a){d("showToolbar","hideToolbar",2e3,a)}),d("showToolbar","hideToolbar",2e3),b.bind_resize(),setTimeout(b.resize_textarea,200),scrollTo(0,0),a("#wpadminbar").hide()}),c.subscribe("shown",function(){var a;e.visible=!0,e.has_tinymce&&!e.is_mce_on&&(a=function(b,c){var d=c.getElement(),f=d.value,g=tinyMCEPreInit.mceInit[e.editor_id];g&&g.wpautop&&"undefined"!=typeof switchEditors&&(d.value=switchEditors.wpautop(d.value)),c.onInit.add(function(b){b.hide(),b.getElement().value=f,tinymce.onAddEditor.remove(a)})},tinymce.onAddEditor.add(a),tinyMCE.init(tinyMCEPreInit.mceInit[e.editor_id]),e.is_mce_on=!0),wpActiveEditor="wp_mce_fullscreen"}),c.subscribe("hide",function(){var c=a("#"+e.editor_id).is(":hidden");e.has_tinymce&&"tinymce"===e.mode&&!c?switchEditors.go(e.editor_id,"tmce"):"html"===e.mode&&c&&switchEditors.go(e.editor_id,"html"),b.savecontent(),a(document).unbind(".fullscreen"),a(e.textarea_obj).unbind(".grow"),e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("wpFullScreenSave"),e.title_id&&set_title_hint(a("#"+e.title_id)),e.qt_canvas.value=e.textarea_obj.value}),c.subscribe("hiding",function(){a(document.body).removeClass("fullscreen-active"),scrollTo(0,e.orig_y),a("#wpadminbar").show()}),c.subscribe("hidden",function(){e.visible=!1,a("#wp_mce_fullscreen, #wp-fullscreen-title").removeAttr("style"),e.has_tinymce&&e.is_mce_on&&tinyMCE.execCommand("wpFullScreenClose"),e.textarea_obj.value="",b.oldheight=0,wpActiveEditor=e.editor_id}),c.subscribe("switchMode",function(a,b){var c;e.has_tinymce&&e.is_mce_on&&(c=tinyMCE.get("wp_mce_fullscreen"),"html"===a&&"tinymce"===b?(tinyMCE.get(e.editor_id).getParam("wpautop")&&"undefined"!=typeof switchEditors&&(e.textarea_obj.value=switchEditors.wpautop(e.textarea_obj.value)),"undefined"==typeof c?tinyMCE.execCommand("wpFullScreenInit"):c.show()):"tinymce"===a&&"html"===b&&c&&c.hide())}),c.subscribe("switchedMode",function(a,c){b.refresh_buttons(!0),"html"===c&&setTimeout(b.resize_textarea,200)}),b.b=function(){e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("Bold")},b.i=function(){e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("Italic")},b.ul=function(){e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("InsertUnorderedList")},b.ol=function(){e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("InsertOrderedList")},b.link=function(){e.has_tinymce&&"tinymce"===e.mode?tinyMCE.execCommand("WP_Link"):wpLink.open()},b.unlink=function(){e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("unlink")},b.atd=function(){e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("mceWritingImprovementTool")},b.help=function(){e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("WP_Help")},b.blockquote=function(){e.has_tinymce&&"tinymce"===e.mode&&tinyMCE.execCommand("mceBlockQuote")},b.medialib=function(){"undefined"!=typeof wp&&wp.media&&wp.media.editor&&wp.media.editor.open(e.editor_id)},b.refresh_buttons=function(b){b=b||!1,"html"===e.mode?(a("#wp-fullscreen-mode-bar").removeClass("wp-tmce-mode").addClass("wp-html-mode"),b?a("#wp-fullscreen-button-bar").fadeOut(150,function(){a(this).addClass("wp-html-mode").fadeIn(150)}):a("#wp-fullscreen-button-bar").addClass("wp-html-mode")):"tinymce"===e.mode&&(a("#wp-fullscreen-mode-bar").removeClass("wp-html-mode").addClass("wp-tmce-mode"),b?a("#wp-fullscreen-button-bar").fadeOut(150,function(){a(this).removeClass("wp-html-mode").fadeIn(150)}):a("#wp-fullscreen-button-bar").removeClass("wp-html-mode"))},b.ui={init:function(){var c=a("#fullscreen-topbar"),f=a("#wp_mce_fullscreen"),g=0;e.toolbars=c.add(a("#wp-fullscreen-status")),e.element=a("#fullscreen-fader"),e.textarea_obj=f[0],e.has_tinymce="undefined"!=typeof tinymce,e.has_tinymce||a("#wp-fullscreen-mode-bar").hide(),wptitlehint&&a("#wp-fullscreen-title").length&&wptitlehint("wp-fullscreen-title"),a(document).keyup(function(c){var d,e,f=c.keyCode||c.charCode;return fullscreen.settings.visible?(d=navigator.platform&&-1!=navigator.platform.indexOf("Mac")?c.ctrlKey:c.altKey,27==f&&(e={event:c,what:"dfw",cb:fullscreen.off,condition:function(){return a("#TB_window").is(":visible")||a(".wp-dialog").is(":visible")?!1:!0}},jQuery(document).triggerHandler("wp_CloseOnEscape",[e])||fullscreen.off()),!d||61!=f&&107!=f&&187!=f||(b.dfw_width(25),c.preventDefault()),!d||45!=f&&109!=f&&189!=f||(b.dfw_width(-25),c.preventDefault()),d&&48==f&&(b.dfw_width(0),c.preventDefault()),void 0):!0}),"undefined"!=typeof wpWordCount&&f.keyup(function(b){var c=b.keyCode||b.charCode;return c==g?!0:((13==c||8==g||46==g)&&a(document).triggerHandler("wpcountwords",[f.val()]),g=c,!0)}),c.mouseenter(function(){e.toolbars.addClass("fullscreen-make-sticky"),a(document).unbind(".fullscreen"),clearTimeout(e.timer),e.timer=0}).mouseleave(function(){e.toolbars.removeClass("fullscreen-make-sticky"),e.visible&&a(document).bind("mousemove.fullscreen",function(a){d("showToolbar","hideToolbar",2e3,a)})})},fade:function(a,d,f){e.element||b.ui.init(),(!a||c.publish(a))&&b.fade.In(e.element,600,function(){d&&c.publish(d),b.fade.Out(e.element,600,function(){f&&c.publish(f)})})}},b.fade={transitionend:"transitionend webkitTransitionEnd oTransitionEnd",sensitivity:100,In:function(c,d,e,f){if(e=e||a.noop,d=d||400,f=f||!1,b.fade.transitions){if(c.is(":visible"))return c.addClass("fade-trigger"),c;c.show(),c.first().one(this.transitionend,function(){e()}),setTimeout(function(){c.addClass("fade-trigger")},this.sensitivity)}else f&&c.stop(),c.css("opacity",1),c.first().fadeIn(d,e),c.length>1&&c.not(":first").fadeIn(d);return c},Out:function(c,d,e,f){return e=e||a.noop,d=d||400,f=f||!1,c.is(":visible")?(b.fade.transitions?(c.first().one(b.fade.transitionend,function(){c.hasClass("fade-trigger")||(c.hide(),e())}),setTimeout(function(){c.removeClass("fade-trigger")},this.sensitivity)):(f&&c.stop(),c.first().fadeOut(d,e),c.length>1&&c.not(":first").fadeOut(d)),c):c},transitions:function(){var a=document.documentElement.style;return"string"==typeof a.WebkitTransition||"string"==typeof a.MozTransition||"string"==typeof a.OTransition||"string"==typeof a.transition}()},b.bind_resize=function(){a(e.textarea_obj).bind("keypress.grow click.grow paste.grow",function(){setTimeout(b.resize_textarea,200)})},b.oldheight=0,b.resize_textarea=function(){var a,c=e.textarea_obj;a=c.scrollHeight>300?c.scrollHeight:300,a!=b.oldheight&&(c.style.height=a+"px",b.oldheight=a)}}(jQuery); |