/* NicEdit - Micro Inline WYSIWYG * Copyright 2007-2008 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 bkExtend = function(){ var args = arguments; if (args.length == 1) args = [this, args[0]]; for (var prop in args[1]) args[0][prop] = args[1][prop]; return args[0]; }; function bkClass() { } bkClass.prototype.construct = function() {}; bkClass.extend = function(def) { var classDef = function() { if (arguments[0] !== bkClass) { return this.construct.apply(this, arguments); } }; var proto = new this(bkClass); bkExtend(proto,def); classDef.prototype = proto; classDef.extend = this.extend; return classDef; }; var bkElement = bkClass.extend({ construct : function(elm,d) { if(typeof(elm) == "string") { elm = (d || document).createElement(elm); } elm = $BK(elm); return elm; }, appendTo : function(elm) { elm.appendChild(this); return this; }, appendBefore : function(elm) { elm.parentNode.insertBefore(this,elm); return this; }, addEvent : function(type, fn) { bkLib.addEvent(this,type,fn); return this; }, setContent : function(c) { this.innerHTML = c; return this; }, pos : function() { var curleft = curtop = 0; var o = obj = this; if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent); } var b = (!window.opera) ? parseInt(this.getStyle('border-width') || this.style.border) || 0 : 0; return [curleft+b,curtop+b+this.offsetHeight]; }, noSelect : function() { bkLib.noSelect(this); return this; }, parentTag : function(t) { var elm = this; do { if(elm && elm.nodeName && elm.nodeName.toUpperCase() == t) { return elm; } elm = elm.parentNode; } while(elm); return false; }, hasClass : function(cls) { return this.className.match(new RegExp('(\\s|^)nicEdit-'+cls+'(\\s|$)')); }, addClass : function(cls) { if (!this.hasClass(cls)) { this.className += " nicEdit-"+cls }; return this; }, removeClass : function(cls) { if (this.hasClass(cls)) { this.className = this.className.replace(new RegExp('(\\s|^)nicEdit-'+cls+'(\\s|$)'),' '); } return this; }, setStyle : function(st) { var elmStyle = this.style; for(var itm in st) { switch(itm) { case 'float': elmStyle['cssFloat'] = elmStyle['styleFloat'] = st[itm]; break; case 'opacity': elmStyle.opacity = st[itm]; elmStyle.filter = "alpha(opacity=" + Math.round(st[itm]*100) + ")"; break; case 'className': this.className = st[itm]; break; default: //if(document.compatMode || itm != "cursor") { // Nasty Workaround for IE 5.5 elmStyle[itm] = st[itm]; //} } } return this; }, getStyle : function( cssRule, d ) { var doc = (!d) ? document.defaultView : d; if(this.nodeType == 1) return (doc && doc.getComputedStyle) ? doc.getComputedStyle( this, null ).getPropertyValue(cssRule) : this.currentStyle[ bkLib.camelize(cssRule) ]; }, remove : function() { this.parentNode.removeChild(this); return this; }, setAttributes : function(at) { for(var itm in at) { this[itm] = at[itm]; } return this; } }); var bkLib = { isMSIE : (navigator.appVersion.indexOf("MSIE") != -1), addEvent : function(obj, type, fn) { (obj.addEventListener) ? obj.addEventListener( type, fn, false ) : obj.attachEvent("on"+type, fn); }, toArray : function(iterable) { var length = iterable.length, results = new Array(length); while (length--) { results[length] = iterable[length] }; return results; }, noSelect : function(element) { if(element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') { element.setAttribute('unselectable','on'); } for(var i=0;i.nicEdit-main p { margin: 0; }<\/scr"+"ipt>"); $BK("__ie_onload").onreadystatechange = function() { if (this.readyState == "complete"){bkLib.domLoaded();} }; } window.onload = bkLib.domLoaded; } }; function $BK(elm) { if(typeof(elm) == "string") { elm = document.getElementById(elm); } return (elm && !elm.appendTo) ? bkExtend(elm,bkElement.prototype) : elm; } var bkEvent = { addEvent : function(evType, evFunc) { if(evFunc) { this.eventList = this.eventList || {}; this.eventList[evType] = this.eventList[evType] || []; this.eventList[evType].push(evFunc); } return this; }, fireEvent : function() { var args = bkLib.toArray(arguments), evType = args.shift(); if(this.eventList && this.eventList[evType]) { for(var i=0;i'); } this.instanceDoc = document.defaultView; this.elm.addEvent('mousedown',this.selected.closureListener(this)).addEvent('keypress',this.keyDown.closureListener(this)).addEvent('focus',this.selected.closure(this)).addEvent('blur',this.blur.closure(this)).addEvent('keyup',this.selected.closure(this)); this.ne.fireEvent('add',this); }, remove : function() { this.saveContent(); if(this.copyElm || this.options.hasPanel) { this.editorContain.remove(); this.e.setStyle({'display' : 'block'}); this.ne.removePanel(); } this.disable(); this.ne.fireEvent('remove',this); }, disable : function() { this.elm.setAttribute('contentEditable','false'); }, getSel : function() { return (window.getSelection) ? window.getSelection() : document.selection; }, getRng : function() { var s = this.getSel(); if(!s) { return null; } return (s.rangeCount > 0) ? s.getRangeAt(0) : s.createRange(); }, selRng : function(rng,s) { if(window.getSelection) { s.removeAllRanges(); s.addRange(rng); } else { rng.select(); } }, selElm : function() { var r = this.getRng(); if(r.startContainer) { var contain = r.startContainer; if(r.cloneContents().childNodes.length == 1) { for(var i=0;i'+((css) ? '' : '')+''+this.initialContent+''); fd.close(); this.frameDoc = fd; this.frameWin = $BK(this.elmFrame.contentWindow); this.frameContent = $BK(this.frameWin.document.body).setStyle(this.savedStyles); this.instanceDoc = this.frameWin.document.defaultView; this.heightUpdate(); this.frameDoc.addEvent('mousedown', this.selected.closureListener(this)).addEvent('keyup',this.heightUpdate.closureListener(this)).addEvent('keydown',this.keyDown.closureListener(this)).addEvent('keyup',this.selected.closure(this)); this.ne.fireEvent('add',this); }, getElm : function() { return this.frameContent; }, setContent : function(c) { this.content = c; this.ne.fireEvent('set',this); this.frameContent.innerHTML = this.content; this.heightUpdate(); }, getSel : function() { return (this.frameWin) ? this.frameWin.getSelection() : this.frameDoc.selection; }, heightUpdate : function() { this.elmFrame.style.height = Math.max(this.frameContent.offsetHeight,this.initialHeight)+'px'; }, nicCommand : function(cmd,args) { this.frameDoc.execCommand(cmd,false,args); setTimeout(this.heightUpdate.closure(this),100); } }); var nicEditorPanel = bkClass.extend({ construct : function(e,options,nicEditor) { this.elm = e; this.options = options; this.ne = nicEditor; this.panelButtons = new Array(); this.buttonList = bkExtend([],this.ne.options.buttonList); this.panelContain = new bkElement('DIV').setStyle({overflow : 'hidden', width : '100%', border : '1px solid #cccccc', backgroundColor : '#efefef'}).addClass('panelContain'); this.panelElm = new bkElement('DIV').setStyle({margin : '2px', marginTop : '0px', zoom : 1, overflow : 'hidden'}).addClass('panel').appendTo(this.panelContain); this.panelContain.appendTo(e); var opt = this.ne.options; var buttons = opt.buttons; for(button in buttons) { this.addButton(button,opt,true); } this.reorder(); e.noSelect(); }, addButton : function(buttonName,options,noOrder) { var button = options.buttons[buttonName]; var type = (button['type']) ? eval('(typeof('+button['type']+') == "undefined") ? null : '+button['type']+';') : nicEditorButton; var hasButton = bkLib.inArray(this.buttonList,buttonName); if(type && (hasButton || this.ne.options.fullPanel)) { this.panelButtons.push(new type(this.panelElm,buttonName,options,this.ne)); if(!hasButton) { this.buttonList.push(buttonName); } } }, findButton : function(itm) { for(var i=0;i"}if(O==""&&Q=="span"){A=false}if(A){G+="<"+Q;if(Q!="br"){G+=O}}}if(!N&&!bkLib.inArray(this.noShort,M)){if(A){G+=" />"}}else{if(A){G+=">"}for(var F=0;F"}for(var F=0;F"}break;case 3:G+=C.nodeValue;break}return G}});nicEditors.registerPlugin(nicXHTML); var nicBBCode=bkClass.extend({construct:function(A){this.ne=A;if(this.ne.options.bbCode){A.addEvent("get",this.bbGet.closure(this));A.addEvent("set",this.bbSet.closure(this));var B=this.ne.loadedPlugins;for(itm in B){if(B[itm].toXHTML){this.xhtml=B[itm]}}}},bbGet:function(A){var B=this.xhtml.toXHTML(A.getElm());A.content=this.toBBCode(B)},bbSet:function(A){A.content=this.fromBBCode(A.content)},toBBCode:function(B){function A(D,C){B=B.replace(D,C)}A(/\n/gi,"");A(/(.*?)<\/strong>/gi,"[b]$1[/b]");A(/(.*?)<\/em>/gi,"[i]$1[/i]");A(/(.*?)<\/span>/gi,"[u]$1[/u]");A(/
    (.*?)<\/ul>/gi,"[list]$1[/list]");A(/
  • (.*?)<\/li>/gi,"[*]$1[]");A(/
      (.*?)<\/ol>/gi,"[list=1]$1[/list]");A(//gi,"[img]$1[/img]");A(/(.*?)<\/a>/gi,"[url=$1]$2[/url]");A(//gi,"\n");A(/<.*?>.*?<\/.*?>/gi,"");return B},fromBBCode:function(A){function B(D,C){A=A.replace(D,C)}B(/\[b\](.*?)\[\/b\]/gi,"$1");B(/\[i\](.*?)\[\/i\]/gi,"$1");B(/\[u\](.*?)\[\/u\]/gi,'$1');B(/\[list\](.*?)\[\/list\]/gi,"
        $1
      ");B(/\[list=1\](.*?)\[\/list\]/gi,"
        $1
      ");B(/\[\*\](.*?)\[\/\*\]/gi,"
    1. $1
    2. ");B(/\[img\](.*?)\[\/img\]/gi,'');B(/\[url=(.*?)\](.*?)\[\/url\]/gi,'$2');B(/\n/gi,"
      ");return A}});nicEditors.registerPlugin(nicBBCode); nicEditor=nicEditor.extend({floatingPanel:function(){this.floating=new bkElement("DIV").setStyle({position:"absolute",top:"-1000px"}).appendTo(document.body);this.addEvent("focus",this.reposition.closure(this)).addEvent("blur",this.hide.closure(this));this.setPanel(this.floating)},reposition:function(){var B=this.selectedInstance.e;this.floating.setStyle({width:(parseInt(B.getStyle("width"))||B.clientWidth)+"px"});var A=B.offsetTop-this.floating.offsetHeight;if(A<0){A=B.offsetTop+B.offsetHeight}this.floating.setStyle({top:A+"px",left:B.offsetLeft+"px",display:"block"})},hide:function(){this.floating.setStyle({top:"-1000px"})}}); var nicCodeOptions = { buttons : { 'xhtml' : {name : 'Edit HTML', type : 'nicCodeButton'} } }; var nicCodeButton=nicEditorAdvancedButton.extend({width:"350px",addPane:function(){this.addForm({"":{type:"title",txt:"Edit HTML"},code:{type:"content",value:this.ne.selectedInstance.getContent(),style:{width:"340px",height:"200px"}}})},submit:function(B){var A=this.inputs.code.value;this.ne.selectedInstance.setContent(A);this.removePane()}});nicEditors.registerPlugin(nicPlugin,nicCodeOptions);