Redmine/public/javascripts/jstoolbar/jstoolbar-textile.min.js

2 lines
9.4 KiB
JavaScript
Raw Normal View History

function jsToolBar(a){if(!document.createElement){return}if(!a){return}if(typeof document["selection"]=="undefined"&&typeof a["setSelectionRange"]=="undefined"){return}this.textarea=a;this.editor=document.createElement("div");this.editor.className="jstEditor";this.textarea.parentNode.insertBefore(this.editor,this.textarea);this.editor.appendChild(this.textarea);this.toolbar=document.createElement("div");this.toolbar.className="jstElements";this.editor.parentNode.insertBefore(this.toolbar,this.editor);if(this.editor.addEventListener){this.handle=document.createElement("div");this.handle.className="jstHandle";var b=this.resizeDragStart;var c=this;this.handle.addEventListener("mousedown",function(a){b.call(c,a)},false);window.addEventListener("unload",function(){var a=c.handle.parentNode.removeChild(c.handle);delete c.handle},false);this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling)}this.context=null;this.toolNodes={}}function jsButton(a,b,c,d){if(typeof jsToolBar.strings=="undefined"){this.title=a||null}else{this.title=jsToolBar.strings[a]||a||null}this.fn=b||function(){};this.scope=c||null;this.className=d||null}function jsSpace(a){this.id=a||null;this.width=null}function jsCombo(a,b,c,d,e){this.title=a||null;this.options=b||null;this.scope=c||null;this.fn=d||function(){};this.className=e||null}jsButton.prototype.draw=function(){if(!this.scope)return null;var a=document.createElement("button");a.setAttribute("type","button");a.tabIndex=200;if(this.className)a.className=this.className;a.title=this.title;var b=document.createElement("span");b.appendChild(document.createTextNode(this.title));a.appendChild(b);if(this.icon!=undefined){a.style.backgroundImage="url("+this.icon+")"}if(typeof this.fn=="function"){var c=this;a.onclick=function(){try{c.fn.apply(c.scope,arguments)}catch(a){}return false}}return a};jsSpace.prototype.draw=function(){var a=document.createElement("span");if(this.id)a.id=this.id;a.appendChild(document.createTextNode(String.fromCharCode(160)));a.className="jstSpacer";if(this.width)a.style.marginRight=this.width+"px";return a};jsCombo.prototype.draw=function(){if(!this.scope||!this.options)return null;var a=document.createElement("select");if(this.className)a.className=className;a.title=this.title;for(var b in this.options){var c=document.createElement("option");c.value=b;c.appendChild(document.createTextNode(this.options[b]));a.appendChild(c)}var d=this;a.onchange=function(){try{d.fn.call(d.scope,this.value)}catch(a){alert(a)}return false};return a};jsToolBar.prototype={base_url:"",mode:"wiki",elements:{},help_link:"",getMode:function(){return this.mode},setMode:function(a){this.mode=a||"wiki"},switchMode:function(a){a=a||"wiki";this.draw(a)},setHelpLink:function(a){this.help_link=a},button:function(a){var b=this.elements[a];if(typeof b.fn[this.mode]!="function")return null;var c=new jsButton(b.title,b.fn[this.mode],this,"jstb_"+a);if(b.icon!=undefined)c.icon=b.icon;return c},space:function(a){var b=new jsSpace(a);if(this.elements[a].width!==undefined)b.width=this.elements[a].width;return b},combo:function(a){var b=this.elements[a];var c=b[this.mode].list.length;if(typeof b[this.mode].fn!="function"||c==0){return null}else{var d={};for(var e=0;e<c;e++){var f=b[this.mode].list[e];d[f]=b.options[f]}return new jsCombo(b.title,d,this,b[this.mode].fn)}},draw:function(a){this.setMode(a);while(this.toolbar.hasChildNodes()){this.toolbar.removeChild(this.toolbar.firstChild)}this.toolNodes={};var b=document.createElement("div");b.className="help";b.innerHTML=this.help_link;"<a href=\"/help/wiki_syntax.html\" onclick=\"window.open('/help/wiki_syntax.html', '', 'resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes'); return false;\">Aide</a>";this.toolbar.appendChild(b);var c,d,e;for(var f in this.elements){c=this.elements[f];var g=c.type==undefined||c.type==""||c.disabled!=undefined&&c.disabled||c.context!=undefined&&c.context!=null&&c.context!=this.context;if(!g&&typeof this[c.type]=="function"){d=this[c.type](f);if(d)e=d.draw();if(e){this.toolNodes[f]=e;thi