forked from extern/django-helpdesk
56 lines
29 KiB
JavaScript
56 lines
29 KiB
JavaScript
|
/* NicEdit - Micro Inline WYSIWYG
|
||
|
* Copyright 2007 Brian Kirchoff
|
||
|
*
|
||
|
* NicEdit is distributed under the terms of the MIT license
|
||
|
* For more information visit http://nicedit.com/
|
||
|
* Do not remove this copyright message
|
||
|
*/
|
||
|
|
||
|
var nicEditorConfig = {
|
||
|
buttons : {
|
||
|
'save' : {name : 'Click to Save', type : 'nicEditorSaveButton', tile : 1},
|
||
|
'undo' : {name : 'Undo', command : 'undo', noActive : true, tile : 23},
|
||
|
'redo' : {name : 'Redo', command : 'redo', noActive : true, tile : 24},
|
||
|
'bold' : {name : 'Click to Bold', command : 'Bold', tags : ['B','STRONG'], css : {'font-weight' : 'bold'}, tile : 2},
|
||
|
'italic' : {name : 'Click to Italic', command : 'Italic', tags : ['EM','I'], css : {'font-style' : 'italic'}, tile : 3},
|
||
|
'underline' : {name : 'Click to Underline', command : 'Underline', tags : ['U'], css : {'text-decoration' : 'underline'}, tile : 4},
|
||
|
'left' : {name : 'Left Align', command : 'justifyleft', noActive : true, tile : 8},
|
||
|
'center' : {name : 'Center Align', command : 'justifycenter', noActive : true, tile : 9},
|
||
|
'right' : {name : 'Right Align', command : 'justifyright', noActive : true, tile : 10},
|
||
|
'ol' : {name : 'Insert Ordered List', command : 'insertorderedlist', tags : ['OL'], tile : 12},
|
||
|
'ul' : {name : 'Insert Unordered List', command : 'insertunorderedlist', tags : ['UL'], tile : 13},
|
||
|
'fontSize' : {name : 'Select Font Size', type : 'nicEditorFontSizeSelect', command : 'fontsize'},
|
||
|
'fontFamily' : {name : 'Select Font Family', type : 'nicEditorFontFamilySelect', command : 'fontname'},
|
||
|
'fontFormat' : {name : 'Select Font Format', type : 'nicEditorFontFormatSelect', command : 'formatBlock'},
|
||
|
'subscript' : {name : 'Click to Subscript', command : 'subscript', tags : ['SUB'], tile : 6, disabled : true},
|
||
|
'superscript' : {name : 'Click to Superscript', command : 'superscript', tags : ['SUP'], tile : 5, disabled : true},
|
||
|
'strikeThrough' : {name : 'Click to Strike Through', command : 'strikeThrough', css : {'text-decoration' : 'line-through'}, tile : 7, disabled : true},
|
||
|
'indent' : {name : 'Indent Text', command : 'indent', noActive : true, tile : 20},
|
||
|
'unindent' : {name : 'Remove Indent', command : 'outdent', noActive : true, tile : 21},
|
||
|
'hr' : {name : 'Horizontal Rule', command : 'insertHorizontalRule', noActive : true, tile : 22},
|
||
|
'color' : {name : 'Change Color', type : 'nicEditorColorButton', tile : 25},
|
||
|
'image' : {name : 'Add Image', type : 'nicEditorImageButton', tile : 14},
|
||
|
'html' : {name : 'Edit HTML', type : 'nicEditorHTMLButton', tile : 16},
|
||
|
'link' : {name : 'Add Link', type : 'nicEditorLinkButton', tile : 17}
|
||
|
},
|
||
|
iconsPath : 'http://media.jutda.com.au/helpdesk/nicEditorIcons.gif',
|
||
|
fullPanel : false,
|
||
|
onSubmit : null,
|
||
|
buttonList : ['bold','italic','underline','left','center','right','ol','ul','indent','unindent','fontSize','fontFamily','image','link'],
|
||
|
toolTipOn : false,
|
||
|
toolTipText : 'Click to Edit'
|
||
|
};
|
||
|
|
||
|
function bkClass(){}bkClass.prototype.construct=function(){};bkClass.extend=function(E){var A=function(){if(arguments[0]!==bkClass){this.construct.apply(this,arguments)}};var D=new this(bkClass);var B=this.prototype;for(var F in E){var C=E[F];if(C instanceof Function){C.$=B}D[F]=C}A.prototype=D;A.extend=this.extend;return A};Function.prototype.closure=function(){var A=this,B=bkLib.toArray(arguments),C=B.shift();return function(){return A.apply(C,B.concat(bkLib.toArray(arguments)))}};Function.prototype.closureListener=function(){var A=this,C=bkLib.toArray(arguments),B=C.shift();return function(E){E=E||window.event;if(E.target){var D=E.target}else{var D=E.srcElement}return A.apply(B,[E,D].concat(C))}};function $N(A){return document.getElementById(A)}var bkLib={getStyle:function(B,A,D){var C=(!D)?document.defaultView:D;return(C&&C.getComputedStyle)?C.getComputedStyle(B,"").getPropertyValue(A):B.currentStyle[A]},setStyle:function(B,A){var C=B.style;for(itm in A){switch(itm){case"float":C["cssFloat"]=C["styleFloat"]=A[itm];break;case"opacity":C.opacity=A[itm];C.filter="alpha(opacity="+Math.round(A[itm]*100)+")";break;case"className":B.className=A[itm];break;default:if(document.compatMode||itm!="cursor"){C[itm]=A[itm]}}}},cancelEvent:function(A){A=A||window.event;if(A.preventDefault&&A.stopPropagation){A.preventDefault();A.stopPropagation()}return false},domLoad:[],domLoaded:function(){if(arguments.callee.done){return }arguments.callee.done=true;for(i=0;i<bkLib.domLoad.length;i++){bkLib.domLoad[i]()}},onDomLoaded:function(fireThis){this.domLoad.push(fireThis);if(document.addEventListener){document.addEventListener("DOMContentLoaded",bkLib.domLoaded,null);/*@cc_on @*//*@if (@_win32)
|
||
|
var proto = "src='javascript:void(0)'";
|
||
|
if (location.protocol == "https:") proto = "src=//0";
|
||
|
document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
|
||
|
var script = document.getElementById("__ie_onload");
|
||
|
script.onreadystatechange = function() {
|
||
|
if (this.readyState == "complete") {
|
||
|
bkLib.domLoaded();
|
||
|
}
|
||
|
};
|
||
|
/*@end @*/}window.onload=bkLib.domLoaded},addEvent:function(C,B,A){(C.addEventListener)?C.addEventListener(B,A,false):C.attachEvent("on"+B,A)},elmPos:function(B){var C=curtop=0;var A=B.offsetHeight;if(B.offsetParent){C=B.offsetLeft;curtop=B.offsetTop;while(B=B.offsetParent){C+=B.offsetLeft;curtop+=B.offsetTop}}return[C,curtop+A]},mousePos:function(A){return[A.pageX||A.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,A.pageY||A.clientY+document.body.scrollTop+document.documentElement.scrollTop]},getElementsByClassName:function(F){if(document.getElementsByClassName){return document.getElementsByClassName(F)}var A=[];var E=new RegExp("\\b"+F+"\\b");var D=document.getElementsByTagName("*");for(var C=0,B=D.length;C<B;C++){if(E.test(D[C].className)){A.push(D[C])}}return A},inArray:function(A,B){for(i=0;i<A.length;i++){if(A[i]===B){return true}}return false},toArray:function(C){var B=C.length,A=new Array(B);while(B--){A[B]=C[B]}return A},unselectAble:function(B){if(B.setAttribute&&B.contentEditable!=true&&B.nodeName!="input"&&B.nodeName!="textarea"){B.setAttribute("unselectable","on")}for(var A=0;A<B.childNodes.length;A++){bkLib.unselectAble(B.childNodes[A])}},ajaxRequest:function(D,C,A){var B=(window.XMLHttpRequest)?new window.XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");B.open((!D)?"GET":D,C,true);if(D=="POST"){B.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}B.send(A)}};var bkEvent={addEvent:function(A,B){if(B){this.eventList=this.eventList||{};this.eventList[A]=this.eventList[A]||[];this.eventList[A].push(B)}},fireEvent:function(C,B){if(this.eventList&&this.eventList[C]){for(var A=0;A<this.eventList[C].length;A++){this.eventList[C][A](B)}}}}
|
||
|
var nicEditors={allTextAreas:function(C){var A=document.getElementsByTagName("textarea");var D=new Array();for(var B=0;B<A.length;B++){D.push(new nicEditor(C).panelInstance(A[B]))}return D}};var nicEditor=bkClass.extend({nicInstances:[],nicPanel:null,selectedInstance:null,construct:function(B){var A=bkClass.extend(nicEditorConfig);A=(B)?A.extend(B):A;this.options=new A();bkLib.addEvent(document.body,"mousedown",this.selectCheck.closureListener(this))},selectCheck:function(C,A){var B=false;do{if(A.className&&A.className.indexOf("nicEdit")!=-1){return false}}while(A=A.parentNode);this.fireEvent("noInstanceSelect",A);this.selectedInstance=null;return false},panelInstance:function(B){if(typeof (B)=="string"){B=$N(B)}var A=document.createElement("DIV");B.parentNode.insertBefore(A,B);panelWidth=B.width||B.clientWidth;A.style.width=panelWidth+"px";this.setPanel(A);return this.addInstance(B)},findInstance:function(A){if(typeof (A)=="string"){A=$N(A)}for(i=0;i<this.nicInstances.length;i++){if(A==this.nicInstances[i].elm){return this.nicInstances[i]}}},addInstance:function(A,B){if(typeof (A)=="string"){A=$N(A)}if(A.contentEditable||!!window.opera){this.nicInstances.push(new nicEditorInstance(A,B,this))}else{this.nicInstances.push(new nicEditorIFrameInstance(A,B,this))}return this},instancesByClassName:function(B,E){var D=bkLib.getElementsByClassName(B);var C=new Array();for(var A=0;A<D.length;A++){this.addInstance(D[A],E)}},nicCommand:function(B,A){if(this.selectedInstance){this.selectedInstance.nicCommand(B,A)}},setPanel:function(A){if(typeof (A)=="string"){A=$N(A)}this.nicPanel=new nicEditorPanel(A,this.options,this);return this}});nicEditor=nicEditor.extend(bkEvent);var nicEditorInstance=bkClass.extend({nicEditor:null,elm:null,initalContent:null,isSelected:false,construct:function(G,D,C){this.nicEditor=C;this.elm=G;this.options=D||{};newX=G.width||G.clientWidth;newY=G.height||G.clientHeight;if(G.nodeName=="TEXTAREA"){G.style.display="none";var B=document.createElement("DIV");var A=document.createElement("DIV");A.innerHTML=G.value;bkLib.setStyle(B,{width:(newX)+"px",border:"1px solid #ccc",borderTop:0,overflow:"hidden"});bkLib.setStyle(A,{width:(newX-8)+"px",margin:"4px",minHeight:(newY-8)+"px"});var H=navigator.appVersion;if(H.indexOf("MSIE")!=-1&&!((typeof document.body.style.maxHeight!="undefined")&&document.compatMode=="CSS1Compat")){A.style.height=newY+"px"}B.appendChild(A);G.parentNode.insertBefore(B,G);this.elm=A;this.copyElm=G;var F=document.getElementsByTagName("FORM");for(var E=0;E<F.length;E++){bkLib.addEvent(F[E],"submit",this.saveContent.closure(this))}}this.initialHeight=newY-8;this.nicEditor.addEvent("noInstanceSelect",this.unselected.closure(this));this.init();this.unselected()},init:function(){this.elm.setAttribute("contentEditable","true");this.initialContent=this.getContent();if(this.initialContent==""){this.setContent("<br />")}this.elm.className="nicEdit";bkLib.addEvent(this.elm,"mousedown",this.mouseDown.closureListener(this))},getSel:function(){return(window.getSelection)?window.getSelection():document.selection},getRng:function(){var A=this.getSel();if(!A){return null}return(A.rangeCount>0)?A.getRangeAt(0):A.createRange()},selRng:function(A,B){if(window.getSelection){B.removeAllRanges();B.addRange(A)}else{A.select()}},saveRng:function(){this.savedRange=this.getRng();this.savedSel=this.getSel()},restoreRng:function(){if(this.savedRange){this.selRng(this.savedRange,this.savedSel)}},mouseDown:function(B,A){if(this.nicEditor.selectedInstance!=this){this.nicEditor.fireEvent("noInstanceSelect",A)}this.nicEditor.selectedInstance=this;this.nicEditor.fireEvent("instanceSelect",A);this.selected()},selected:function(){this.isSelected=true;bkLib.setStyle(this.elm,{className:"nicEdit nicEdit-instanceSelect"});if(this.toolTip){this.toolTip.remove();this.toolTip=null}},unselected:function(){this.isSelected=false;bkLib.setStyle(this.elm,{className:"nicEdit nicEdit-noInstanceSelect"});if(!this.toolTip&&(this.nicEditor.options.toolTipOn||this.options.toolTipOn)){this.addTooltip();this.toolTip.setContent((this.options.tool
|