-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
quicktags.min.js
1 lines (1 loc) · 9.29 KB
/
quicktags.min.js
1
var QTags,edCanvas,edButtons=[],edAddTag=function(){},edCheckOpenTags=function(){},edCloseAllTags=function(){},edInsertImage=function(){},edInsertLink=function(){},edInsertTag=function(){},edLink=function(){},edQuickLink=function(){},edRemoveTag=function(){},edShowButton=function(){},edShowLinks=function(){},edSpell=function(){},edToolbar=function(){};function quicktags(t){return new QTags(t)}function edInsertContent(t,n){return QTags.insertContent(n)}function edButton(t,n,e,o,i){return QTags.addButton(t,n,e,o,i,"",-1)}!function(){var t,u=function(t){var n,e,o,i;"undefined"!=typeof jQuery?jQuery(document).ready(t):((n=u).funcs=[],n.ready=function(){if(!n.isReady)for(n.isReady=!0,e=0;e<n.funcs.length;e++)n.funcs[e]()},n.isReady?t():n.funcs.push(t),n.eventAttached||(document.addEventListener?(o=function(){document.removeEventListener("DOMContentLoaded",o,!1),n.ready()},document.addEventListener("DOMContentLoaded",o,!1),window.addEventListener("load",n.ready,!1)):document.attachEvent&&(o=function(){"complete"===document.readyState&&(document.detachEvent("onreadystatechange",o),n.ready())},document.attachEvent("onreadystatechange",o),window.attachEvent("onload",n.ready),(i=function(){try{document.documentElement.doScroll("left")}catch(t){return void setTimeout(i,50)}n.ready()})()),n.eventAttached=!0))},n=(n=new Date,t=function(t){t=t.toString();return t=t.length<2?"0"+t:t},n.getUTCFullYear()+"-"+t(n.getUTCMonth()+1)+"-"+t(n.getUTCDate())+"T"+t(n.getUTCHours())+":"+t(n.getUTCMinutes())+":"+t(n.getUTCSeconds())+"+00:00"),d=QTags=function(t){if("string"==typeof t)t={id:t};else if("object"!=typeof t)return!1;var n,e=this,o=t.id,i=document.getElementById(o),a="qt_"+o;if(!o||!i)return!1;e.name=a,e.id=o,e.canvas=i,e.settings=t,n="content"!==o||"string"!=typeof adminpage||"post-new-php"!==adminpage&&"post-php"!==adminpage?a+"_toolbar":(edCanvas=i,"ed_toolbar"),(t=document.createElement("div")).id=n,t.className="quicktags-toolbar",t.onclick=function(){window.wpActiveEditor=o},i.parentNode.insertBefore(t,i),n=function(t){var n=(t=t||window.event).target||t.srcElement;(n.clientWidth||n.offsetWidth)&&/ ed_button /.test(" "+n.className+" ")&&(e.canvas=i=document.getElementById(o),t=n.id.replace(a+"_",""),e.theButtons[t]&&e.theButtons[t].callback.call(e.theButtons[t],n,i,e))},(e.toolbar=t).addEventListener?t.addEventListener("click",n,!1):t.attachEvent&&t.attachEvent("onclick",n),e.getButton=function(t){return e.theButtons[t]},e.getButtonElement=function(t){return document.getElementById(a+"_"+t)},d.instances[o]=e,d.instances[0]||(d.instances[0]=d.instances[o],u(function(){d._buttonsInit()}))};d.instances={},d.getInstance=function(t){return d.instances[t]},d._buttonsInit=function(){var t,n,e,o,i,a,u,s,c,l=this;for(i in l.instances)if("0"!==i){for(s in(a=l.instances[i]).canvas,t=a.name,e={},c=o="",(n=a.settings).buttons&&(c=","+n.buttons+","),edButtons)edButtons[s]&&(u=edButtons[s].id,c&&-1!==",strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,".indexOf(","+u+",")&&-1===c.indexOf(","+u+",")||edButtons[s].instance&&edButtons[s].instance!==i||(e[u]=edButtons[s],edButtons[s].html&&(o+=edButtons[s].html(t+"_"))));c&&-1!==c.indexOf(",fullscreen,")&&(e.fullscreen=new d.FullscreenButton,o+=e.fullscreen.html(t+"_")),c&&-1!==c.indexOf(",dfw,")&&(e.dfw=new d.DFWButton,o+=e.dfw.html(t+"_")),"rtl"===document.getElementsByTagName("html")[0].dir&&(e.textdirection=new d.TextDirectionButton,o+=e.textdirection.html(t+"_")),a.toolbar.innerHTML=o,a.theButtons=e,"undefined"!=typeof jQuery&&jQuery(document).triggerHandler("quicktags-init",[a])}l.buttonsInitDone=!0},d.addButton=function(t,n,e,o,i,a,u,s){var c;if(t&&n){if(u=u||0,o=o||"","function"==typeof e)(c=new d.Button(t,n,i,a,s)).callback=e;else{if("string"!=typeof e)return;c=new d.TagButton(t,n,e,o,i,a,s)}if(-1===u)return c;if(0<u){for(;void 0!==edButtons[u];)u++;edButtons[u]=c}else edButtons[edButtons.length]=c;this.buttonsInitDone&&this._buttonsInit()}},d.insertContent=function(t){var n,e,o,i,a=document.getElementById(wpActiveEditor);return!!a&&(document.selection?(a.focus(),document.selection.createRange().text=t):a.selectionStart||0===a.selectionStart?(i=a.value,n=a.selectionStart,e=a.selectionEnd,o=a.scrollTop,a.value=i.substring(0,n)+t+i.substring(e,i.length),a.selectionStart=n+t.length,a.selectionEnd=n+t.length,a.scrollTop=o):a.value+=t,a.focus(),!0)},d.Button=function(t,n,e,o,i){var a=this;a.id=t,a.display=n,a.access="",a.title=o||"",a.instance=i||""},d.Button.prototype.html=function(t){var n,e=this.title?' title="'+this.title+'"':"",o=(n=window.wp)&&n.editor&&n.editor.dfw;return"fullscreen"===this.id?'<button type="button" id="'+t+this.id+'" class="ed_button qt-dfw qt-fullscreen"'+e+"></button>":"dfw"===this.id?(n=o&&o.isActive()?"":' disabled="disabled"',o=o&&o.isOn()?" active":"",'<button type="button" id="'+t+this.id+'" class="ed_button qt-dfw'+o+'"'+e+n+"></button>"):'<input type="button" id="'+t+this.id+'" class="ed_button button button-small"'+e+' value="'+this.display+'" />'},d.Button.prototype.callback=function(){},d.TagButton=function(t,n,e,o,i,a,u){d.Button.call(this,t,n,i,a,u),this.tagStart=e,this.tagEnd=o},d.TagButton.prototype=new d.Button,d.TagButton.prototype.openTag=function(t,n){n.openTags||(n.openTags=[]),this.tagEnd&&(n.openTags.push(this.id),t.value="/"+t.value)},d.TagButton.prototype.closeTag=function(t,n){var e=this.isOpen(n);!1!==e&&n.openTags.splice(e,1),t.value=this.display},d.TagButton.prototype.isOpen=function(t){var n=0,e=!1;if(t.openTags)for(;!1===e&&n<t.openTags.length;)e=t.openTags[n]===this.id&&n,n++;else e=!1;return e},d.TagButton.prototype.callback=function(t,n,e){var o,i,a,u,s,c,l=this,d=n.value,r=d?l.tagEnd:"";document.selection?(n.focus(),0<(c=document.selection.createRange()).text.length?l.tagEnd?c.text=l.tagStart+c.text+r:c.text=c.text+l.tagStart:l.tagEnd?!1===l.isOpen(e)?(c.text=l.tagStart,l.openTag(t,e)):(c.text=r,l.closeTag(t,e)):c.text=l.tagStart):n.selectionStart||0===n.selectionStart?(o=n.selectionStart,a=i=n.selectionEnd,u=n.scrollTop,s=d.substring(0,o),c=d.substring(i,d.length),d=d.substring(o,i),o!==i?l.tagEnd?(n.value=s+l.tagStart+d+r+c,a+=l.tagStart.length+r.length):(n.value=s+d+l.tagStart+c,a+=l.tagStart.length):l.tagEnd?!1===l.isOpen(e)?(n.value=s+l.tagStart+c,l.openTag(t,e),a=o+l.tagStart.length):(n.value=s+r+c,a=o+r.length,l.closeTag(t,e)):(n.value=s+l.tagStart+c,a=o+l.tagStart.length),n.selectionStart=a,n.selectionEnd=a,n.scrollTop=u):r?!1!==l.isOpen(e)?(n.value+=l.tagStart,l.openTag(t,e)):(n.value+=r,l.closeTag(t,e)):n.value+=l.tagStart,n.focus()},d.SpellButton=function(){},d.CloseButton=function(){d.Button.call(this,"close",quicktagsL10n.closeTags,"",quicktagsL10n.closeAllOpenTags)},d.CloseButton.prototype=new d.Button,d._close=function(t,n,e){var o,i,a=e.openTags;if(a)for(;0<a.length;)o=e.getButton(a[a.length-1]),i=document.getElementById(e.name+"_"+o.id),t?o.callback.call(o,i,n,e):o.closeTag(i,e)},d.CloseButton.prototype.callback=d._close,d.closeAllTags=function(t){t=this.getInstance(t);d._close("",t.canvas,t)},d.LinkButton=function(){d.TagButton.call(this,"link","link","","</a>")},d.LinkButton.prototype=new d.TagButton,d.LinkButton.prototype.callback=function(t,n,e,o){"undefined"==typeof wpLink?(o=o||"http://",!1===this.isOpen(e)?(o=prompt(quicktagsL10n.enterURL,o))&&(this.tagStart='<a href="'+o+'">',d.TagButton.prototype.callback.call(this,t,n,e)):d.TagButton.prototype.callback.call(this,t,n,e)):wpLink.open(e.id)},d.ImgButton=function(){d.TagButton.call(this,"img","img","","")},d.ImgButton.prototype=new d.TagButton,d.ImgButton.prototype.callback=function(t,n,e,o){o=o||"http://";var i=prompt(quicktagsL10n.enterImageURL,o);i&&(o=prompt(quicktagsL10n.enterImageDescription,""),this.tagStart='<img src="'+i+'" alt="'+o+'" />',d.TagButton.prototype.callback.call(this,t,n,e))},d.FullscreenButton=function(){d.Button.call(this,"fullscreen",quicktagsL10n.fullscreen,"f",quicktagsL10n.toggleFullscreen)},d.FullscreenButton.prototype=new d.Button,d.FullscreenButton.prototype.callback=function(t,n){n.id&&"undefined"!=typeof wp&&wp.editor&&wp.editor.fullscreen&&wp.editor.fullscreen.on()},d.DFWButton=function(){d.Button.call(this,"dfw","","f",quicktagsL10n.dfw)},d.DFWButton.prototype=new d.Button,d.DFWButton.prototype.callback=function(){var t;(t=window.wp)&&t.editor&&t.editor.dfw&&window.wp.editor.dfw.toggle()},d.TextDirectionButton=function(){d.Button.call(this,"textdirection",quicktagsL10n.textdirection,"",quicktagsL10n.toggleTextdirection)},d.TextDirectionButton.prototype=new d.Button,d.TextDirectionButton.prototype.callback=function(t,n){var e="rtl"===document.getElementsByTagName("html")[0].dir,o=(o=n.style.direction)||(e?"rtl":"ltr");n.style.direction="rtl"===o?"ltr":"rtl",n.focus()},edButtons[10]=new d.TagButton("strong","b","<strong>","</strong>"),edButtons[20]=new d.TagButton("em","i","<em>","</em>"),edButtons[30]=new d.LinkButton,edButtons[40]=new d.TagButton("block","b-quote","\n\n<blockquote>","</blockquote>\n\n"),edButtons[50]=new d.TagButton("del","del",'<del datetime="'+n+'">',"</del>"),edButtons[60]=new d.TagButton("ins","ins",'<ins datetime="'+n+'">',"</ins>"),edButtons[70]=new d.ImgButton,edButtons[80]=new d.TagButton("ul","ul","<ul>\n","</ul>\n\n"),edButtons[90]=new d.TagButton("ol","ol","<ol>\n","</ol>\n\n"),edButtons[100]=new d.TagButton("li","li","\t<li>","</li>\n"),edButtons[110]=new d.TagButton("code","code","<code>","</code>"),edButtons[120]=new d.TagButton("more","more","\x3c!--more--\x3e\n\n",""),edButtons[140]=new d.CloseButton}();