From 351b27bd7d3ddf6e8cb9f75af9ffa3421d4e3648 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 28 Apr 2015 16:11:51 -0400 Subject: [PATCH] Reformat nicedit.js This initial format should allow for the code to be a bit more readable. It also adds scoping, radix arguments, and other small "trivial" changes that should tighten up how the code works. --- nicEdit.js | 3304 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 1939 insertions(+), 1365 deletions(-) diff --git a/nicEdit.js b/nicEdit.js index 6bb27a0..c52b79f 100755 --- a/nicEdit.js +++ b/nicEdit.js @@ -1,3 +1,4 @@ + /* NicEdit - Micro Inline WYSIWYG * Copyright 2007-2008 Brian Kirchoff * @@ -5,935 +6,1197 @@ * 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]; +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() { } + +function bkClass() {} bkClass.prototype.construct = function() {}; bkClass.extend = function(def) { var classDef = function() { - if (arguments[0] !== bkClass) { return this.construct.apply(this, arguments); } + if (arguments[0] !== bkClass) { + return this.construct.apply(this, arguments); + } }; var proto = new this(bkClass); - bkExtend(proto,def); + 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; - }, + 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; - }, + appendTo: function(elm) { + elm.appendChild(this); + return this; + }, - appendBefore : function(elm) { - elm.parentNode.insertBefore(this,elm); - return this; - }, + appendBefore: function(elm) { + elm.parentNode.insertBefore(this, elm); + return this; + }, - addEvent : function(type, fn) { - bkLib.addEvent(this,type,fn); - return this; - }, + addEvent: function(type, fn) { + bkLib.addEvent(this, type, fn); + return this; + }, - setContent : function(c) { - this.innerHTML = c; - 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]; - }, + 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, 10) || 0 : 0; + return [curleft + b, curtop + b + this.offsetHeight]; + }, - noSelect : function() { - bkLib.noSelect(this); - return this; - }, + 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; - }, + 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|$)')); - }, + 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; - }, + 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; - }, + 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; - }, + 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) ]; - }, + getStyle: function(cssRule, d) { + var doc = (!d) ? document.defaultView : d; + if (this.nodeType == 1) { + if (doc && doc.getComputedStyle) { + return doc.getComputedStyle(this, null).getPropertyValue(cssRule); + } else { + return this.currentStyle[bkLib.camelize(cssRule)]; + } + } + }, - remove : function() { - this.parentNode.removeChild(this); - return this; - }, + remove: function() { + this.parentNode.removeChild(this); + return this; + }, - setAttributes : function(at) { - for(var itm in at) { - this[itm] = at[itm]; - } - return this; - } + setAttributes: function(at) { + for (var itm in at) { + this[itm] = at[itm]; + } + return this; + } }); var bkLib = { - isMSIE : (navigator.appVersion.indexOf("MSIE") != -1), + isMSIE: (navigator.appVersion.indexOf("MSIE") != -1), - addEvent : function(obj, type, fn) { - (obj.addEventListener) ? obj.addEventListener( type, fn, false ) : obj.attachEvent("on"+type, fn); - }, + addEvent: function(obj, type, fn) { + if (obj.addEventListener) { + obj.addEventListener(type, fn, false); + } else { + obj.attachEvent("on" + type, fn); + } + }, - toArray : function(iterable) { - var length = iterable.length, results = new Array(length); - while (length--) { results[length] = iterable[length] }; - return results; - }, + 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; - } + noSelect: function(element) { + if (element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') { + element.setAttribute('unselectable', 'on'); + } + for (var i = 0; i < element.childNodes.length; i++) { + bkLib.noSelect(element.childNodes[i]); + } + }, + camelize: function(s) { + return s.replace(/\-(.)/g, function(m, l) { + return l.toUpperCase(); + }); + }, + inArray: function(arr, item) { + return (bkLib.search(arr, item) !== null); + }, + search: function(arr, itm) { + for (var i = 0; i < arr.length; i++) { + if (arr[i] == itm) + return i; + } + return null; + }, + cancelEvent: function(e) { + e = e || window.event; + if (e.preventDefault && e.stopPropagation) { + e.preventDefault(); + e.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); + } else if (bkLib.isMSIE) { + document.write("<\/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; + 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); - }, + init: function() { + this.elm.setAttribute('contentEditable', 'true'); + if (this.getContent() === "" && this.options.initWithLineBreak) { + this.setContent('
'); + } + 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); - }, + 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'); - }, + disable: function() { + this.elm.setAttribute('contentEditable', 'false'); + }, - getSel : function() { - return (window.getSelection) ? window.getSelection() : document.selection; - }, + 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 && s.createRange() || document.createRange(); - }, + getRng: function() { + var s = this.getSel(); + if (!s) { + return null; + } + return (s.rangeCount > 0) ? s.getRangeAt(0) : + s.createRange && s.createRange() || document.createRange(); + }, - selRng : function(rng,s) { - if(window.getSelection) { - s.removeAllRanges(); - s.addRange(rng); - } else { - rng.select(); - } - }, + 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; + initFrame: function() { + var fd = $BK(this.elmFrame.contentWindow.document); + fd.designMode = "on"; + fd.open(); + var css = this.ne.options.externalCSS; + fd.write('' + ((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.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); - }, + 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; - }, + getElm: function() { + return this.frameContent; + }, - setContent : function(c) { - this.content = c; - this.ne.fireEvent('set',this); - this.frameContent.innerHTML = this.content; - this.heightUpdate(); - }, + 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; - }, + 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'; - }, + 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); - } + 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); + construct: function(e, options, nicEditor) { + this.elm = e; + this.options = options; + this.ne = nicEditor; + this.panelButtons = []; + 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); + 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(); - }, + var opt = this.ne.options; + var buttons = opt.buttons; + for (var button in buttons) { + this.addButton(button, opt, true); + } + this.reorder(); + e.noSelect(); + }, - addButton : function(buttonName,options,noOrder) { - var button = options.buttons[buttonName]; - var type = null; + addButton: function(buttonName, options, noOrder) { + var button = options.buttons[buttonName]; + var type = null; - if (button['type']) { - type = typeof(window[button['type']]) == undefined ? null : window[button['type']]; - } - else { - 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); - } - } - }, + if (button['type']) { + type = typeof(window[button['type']]) === undefined ? null : window[button['type']]; + } else { + 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'+this.sel[itm]+''); - } - } + sel: { + 1: '1 (8pt)', + 2: '2 (10pt)', + 3: '3 (12pt)', + 4: '4 (14pt)', + 5: '5 (18pt)', + 6: '6 (24pt)' + }, + init: function() { + this.setDisplay('Font Size...'); + for (var itm in this.sel) { + this.add(itm, '' + this.sel[itm] + ''); + } + } }); var nicEditorFontFamilySelect = nicEditorSelect.extend({ - sel : {'arial' : 'Arial','comic sans ms' : 'Comic Sans','courier new' : 'Courier New','georgia' : 'Georgia', 'helvetica' : 'Helvetica', 'impact' : 'Impact', 'times new roman' : 'Times', 'trebuchet ms' : 'Trebuchet', 'verdana' : 'Verdana'}, + sel: { + 'arial': 'Arial', + 'comic sans ms': 'Comic Sans', + 'courier new': 'Courier New', + 'georgia': 'Georgia', + 'helvetica': 'Helvetica', + 'impact': 'Impact', + 'times new roman': 'Times', + 'trebuchet ms': 'Trebuchet', + 'verdana': 'Verdana' + }, - init : function() { - this.setDisplay('Font Family...'); - for(itm in this.sel) { - this.add(itm,''+this.sel[itm]+''); - } - } + init: function() { + this.setDisplay('Font Family...'); + for (var itm in this.sel) { + this.add(itm, '' + this.sel[itm] + ''); + } + } }); var nicEditorFontFormatSelect = nicEditorSelect.extend({ - sel : {'p' : 'Paragraph', 'pre' : 'Pre', 'h6' : 'Heading 6', 'h5' : 'Heading 5', 'h4' : 'Heading 4', 'h3' : 'Heading 3', 'h2' : 'Heading 2', 'h1' : 'Heading 1'}, + sel: { + 'p': 'Paragraph', + 'pre': 'Pre', + 'h6': 'Heading 6', + 'h5': 'Heading 5', + 'h4': 'Heading 4', + 'h3': 'Heading 3', + 'h2': 'Heading 2', + 'h1': 'Heading 1' + }, - init : function() { - this.setDisplay('Font Format...'); - for(itm in this.sel) { - var tag = itm.toUpperCase(); - this.add('<'+tag+'>','<'+itm+' style="padding: 0px; margin: 0px;">'+this.sel[itm]+''); - } - } + init: function() { + this.setDisplay('Font Format...'); + for (var itm in this.sel) { + var tag = itm.toUpperCase(); + this.add('<' + tag + '>', '<' + itm + ' style="padding: 0px; margin: 0px;">' + this.sel[itm] + ''); + } + } }); -nicEditors.registerPlugin(nicPlugin,nicSelectOptions); +nicEditors.registerPlugin(nicPlugin, nicSelectOptions); /* START CONFIG */ var nicLinkOptions = { - buttons : { - 'link' : {name : 'Add Link', type : 'nicLinkButton', tags : ['A']}, - 'unlink' : {name : 'Remove Link', command : 'unlink', noActive : true} - } + buttons: { + 'link': { + name: 'Add Link', + type: 'nicLinkButton', + tags: ['A'] + }, + 'unlink': { + name: 'Remove Link', + command: 'unlink', + noActive: true + } + } }; /* END CONFIG */ var nicLinkButton = nicEditorAdvancedButton.extend({ - addPane : function() { - this.ln = this.ne.selectedInstance.selElm().parentTag('A'); - this.addForm({ - '' : {type : 'title', txt : 'Add/Edit Link'}, - 'href' : {type : 'text', txt : 'URL', value : 'http://', style : {width: '150px'}}, - 'title' : {type : 'text', txt : 'Title'}, - 'target' : {type : 'select', txt : 'Open In', options : {'' : 'Current Window', '_blank' : 'New Window'},style : {width : '100px'}} - },this.ln); - }, + addPane: function() { + this.ln = this.ne.selectedInstance.selElm().parentTag('A'); + this.addForm({ + '': { + type: 'title', + txt: 'Add/Edit Link' + }, + 'href': { + type: 'text', + txt: 'URL', + value: 'http://', + style: { + width: '150px' + } + }, + 'title': { + type: 'text', + txt: 'Title' + }, + 'target': { + type: 'select', + txt: 'Open In', + options: { + '': 'Current Window', + '_blank': 'New Window' + }, + style: { + width: '100px' + } + } + }, this.ln); + }, - submit : function(e) { - var url = this.inputs['href'].value; - if(url == "http://" || url == "") { - alert("You must enter a URL to Create a Link"); - return false; - } - this.removePane(); + submit: function(e) { + var url = this.inputs['href'].value; + if (url === "http://" || url === "") { + alert("You must enter a URL to Create a Link"); + return false; + } + this.removePane(); - if(!this.ln) { - var tmp = 'javascript:nicTemp();'; - this.ne.nicCommand("createlink",tmp); - this.ln = this.findElm('A','href',tmp); - // set the link text to the title or the url if there is no text selected - if (this.ln.innerHTML == tmp) { - this.ln.innerHTML = this.inputs['title'].value || url; - }; - } - if(this.ln) { - var oldTitle = this.ln.title; - this.ln.setAttributes({ - href : this.inputs['href'].value, - title : this.inputs['title'].value, - target : this.inputs['target'].options[this.inputs['target'].selectedIndex].value - }); - // set the link text to the title or the url if the old text was the old title - if (this.ln.innerHTML == oldTitle) { - this.ln.innerHTML = this.inputs['title'].value || this.inputs['href'].value; - }; - } - } + if (!this.ln) { + var tmp = 'javascript:nicTemp();'; + this.ne.nicCommand("createlink", tmp); + this.ln = this.findElm('A', 'href', tmp); + // set the link text to the title or the url if there is no text selected + if (this.ln.innerHTML == tmp) { + this.ln.innerHTML = this.inputs['title'].value || url; + } + } + if (this.ln) { + var oldTitle = this.ln.title; + this.ln.setAttributes({ + href: this.inputs['href'].value, + title: this.inputs['title'].value, + target: this.inputs['target'].options[this.inputs['target'].selectedIndex].value + }); + // set the link text to the title or the url if the old text was the old title + if (this.ln.innerHTML == oldTitle) { + this.ln.innerHTML = this.inputs['title'].value || this.inputs['href'].value; + } + } + } }); -nicEditors.registerPlugin(nicPlugin,nicLinkOptions); +nicEditors.registerPlugin(nicPlugin, nicLinkOptions); /* START CONFIG */ var nicColorOptions = { - buttons : { - 'forecolor' : {name : __('Change Text Color'), type : 'nicEditorColorButton', noClose : true}, - 'bgcolor' : {name : __('Change Background Color'), type : 'nicEditorBgColorButton', noClose : true} - } + buttons: { + 'forecolor': { + name: __('Change Text Color'), + type: 'nicEditorColorButton', + noClose: true + }, + 'bgcolor': { + name: __('Change Background Color'), + type: 'nicEditorBgColorButton', + noClose: true + } + } }; /* END CONFIG */ var nicEditorColorButton = nicEditorAdvancedButton.extend({ - addPane : function() { - var colorList = {0 : '00',1 : '33',2 : '66',3 :'99',4 : 'CC',5 : 'FF'}; - var colorItems = new bkElement('DIV').setStyle({width: '270px'}); + addPane: function() { + var colorList = { + 0: '00', + 1: '33', + 2: '66', + 3: '99', + 4: 'CC', + 5: 'FF' + }; + var colorItems = new bkElement('DIV').setStyle({ + width: '270px' + }); - for(var r in colorList) { - for(var b in colorList) { - for(var g in colorList) { - var colorCode = '#'+colorList[r]+colorList[g]+colorList[b]; + for (var r in colorList) { + for (var b in colorList) { + for (var g in colorList) { + var colorCode = '#' + colorList[r] + colorList[g] + colorList[b]; - var colorSquare = new bkElement('DIV').setStyle({'cursor' : 'pointer', 'height' : '15px', 'float' : 'left'}).appendTo(colorItems); - var colorBorder = new bkElement('DIV').setStyle({border: '2px solid '+colorCode}).appendTo(colorSquare); - var colorInner = new bkElement('DIV').setStyle({backgroundColor : colorCode, overflow : 'hidden', width : '11px', height : '11px'}).addEvent('click',this.colorSelect.closure(this,colorCode)).addEvent('mouseover',this.on.closure(this,colorBorder)).addEvent('mouseout',this.off.closure(this,colorBorder,colorCode)).appendTo(colorBorder); + var colorSquare = new bkElement('DIV').setStyle({ + 'cursor': 'pointer', + 'height': '15px', + 'float': 'left' + }).appendTo(colorItems); + var colorBorder = new bkElement('DIV').setStyle({ + border: '2px solid ' + colorCode + }).appendTo(colorSquare); + var colorInner = new bkElement('DIV').setStyle({ + backgroundColor: colorCode, + overflow: 'hidden', + width: '11px', + height: '11px' + }).addEvent('click', this.colorSelect.closure(this, colorCode)).addEvent('mouseover', this.on.closure(this, colorBorder)).addEvent('mouseout', this.off.closure(this, colorBorder, colorCode)).appendTo(colorBorder); - if(!window.opera) { - colorSquare.onmousedown = colorInner.onmousedown = bkLib.cancelEvent; - } + if (!window.opera) { + colorSquare.onmousedown = colorInner.onmousedown = bkLib.cancelEvent; + } - } - } - } - this.pane.append(colorItems.noSelect()); - }, + } + } + } + this.pane.append(colorItems.noSelect()); + }, - colorSelect : function(c) { - this.ne.nicCommand('foreColor',c); - this.removePane(); - }, + colorSelect: function(c) { + this.ne.nicCommand('foreColor', c); + this.removePane(); + }, - on : function(colorBorder) { - colorBorder.setStyle({border : '2px solid #000'}); - }, + on: function(colorBorder) { + colorBorder.setStyle({ + border: '2px solid #000' + }); + }, - off : function(colorBorder,colorCode) { - colorBorder.setStyle({border : '2px solid '+colorCode}); - } + off: function(colorBorder, colorCode) { + colorBorder.setStyle({ + border: '2px solid ' + colorCode + }); + } }); var nicEditorBgColorButton = nicEditorColorButton.extend({ - colorSelect : function(c) { - this.ne.nicCommand('hiliteColor',c); - this.removePane(); - } + colorSelect: function(c) { + this.ne.nicCommand('hiliteColor', c); + this.removePane(); + } }); -nicEditors.registerPlugin(nicPlugin,nicColorOptions); +nicEditors.registerPlugin(nicPlugin, nicColorOptions); /* START CONFIG */ var nicImageOptions = { - buttons : { - 'image' : {name : 'Add Image', type : 'nicImageButton', tags : ['IMG']} - } + buttons: { + 'image': { + name: 'Add Image', + type: 'nicImageButton', + tags: ['IMG'] + } + } }; /* END CONFIG */ var nicImageButton = nicEditorAdvancedButton.extend({ - addPane : function() { - this.im = this.ne.selectedInstance.selElm().parentTag('IMG'); - this.addForm({ - '' : {type : 'title', txt : 'Add/Edit Image'}, - 'src' : {type : 'text', txt : 'URL', 'value' : 'http://', style : {width: '150px'}}, - 'alt' : {type : 'text', txt : 'Alt Text', style : {width: '100px'}}, - 'align' : {type : 'select', txt : 'Align', options : {none : 'Default','left' : 'Left', 'right' : 'Right'}} - },this.im); - }, + addPane: function() { + this.im = this.ne.selectedInstance.selElm().parentTag('IMG'); + this.addForm({ + '': { + type: 'title', + txt: 'Add/Edit Image' + }, + 'src': { + type: 'text', + txt: 'URL', + 'value': 'http://', + style: { + width: '150px' + } + }, + 'alt': { + type: 'text', + txt: 'Alt Text', + style: { + width: '100px' + } + }, + 'align': { + type: 'select', + txt: 'Align', + options: { + none: 'Default', + 'left': 'Left', + 'right': 'Right' + } + } + }, this.im); + }, - submit : function(e) { - var src = this.inputs['src'].value; - if(src == "" || src == "http://") { - alert("You must enter a Image URL to insert"); - return false; - } - this.removePane(); + submit: function(e) { + var src = this.inputs['src'].value; + if (src === "" || src === "http://") { + alert("You must enter a Image URL to insert"); + return false; + } + this.removePane(); - if(!this.im) { - var tmp = 'javascript:nicImTemp();'; - this.ne.nicCommand("insertImage",tmp); - this.im = this.findElm('IMG','src',tmp); - } - if(this.im) { - this.im.setAttributes({ - src : this.inputs['src'].value, - alt : this.inputs['alt'].value, - align : this.inputs['align'].value - }); - } - } + if (!this.im) { + var tmp = 'javascript:nicImTemp();'; + this.ne.nicCommand("insertImage", tmp); + this.im = this.findElm('IMG', 'src', tmp); + } + if (this.im) { + this.im.setAttributes({ + src: this.inputs['src'].value, + alt: this.inputs['alt'].value, + align: this.inputs['align'].value + }); + } + } }); -nicEditors.registerPlugin(nicPlugin,nicImageOptions); +nicEditors.registerPlugin(nicPlugin, nicImageOptions); /* START CONFIG */ var nicSaveOptions = { - buttons : { - 'save' : {name : __('Save this content'), type : 'nicEditorSaveButton'} - } + buttons: { + 'save': { + name: __('Save this content'), + type: 'nicEditorSaveButton' + } + } }; /* END CONFIG */ var nicEditorSaveButton = nicEditorButton.extend({ - init : function() { - if(!this.ne.options.onSave) { - this.margin.setStyle({'display' : 'none'}); - } - }, - mouseClick : function() { - var onSave = this.ne.options.onSave; - var selectedInstance = this.ne.selectedInstance; - onSave(selectedInstance.getContent(), selectedInstance.elm.id, selectedInstance); - } + init: function() { + if (!this.ne.options.onSave) { + this.margin.setStyle({ + 'display': 'none' + }); + } + }, + mouseClick: function() { + var onSave = this.ne.options.onSave; + var selectedInstance = this.ne.selectedInstance; + onSave(selectedInstance.getContent(), selectedInstance.elm.id, selectedInstance); + } }); -nicEditors.registerPlugin(nicPlugin,nicSaveOptions); +nicEditors.registerPlugin(nicPlugin, nicSaveOptions); /* START CONFIG */ var nicUploadOptions = { - buttons : { - 'upload' : {name : 'Upload Image', type : 'nicUploadButton'} - } + buttons: { + 'upload': { + name: 'Upload Image', + type: 'nicUploadButton' + } + } }; /* END CONFIG */ var nicUploadButton = nicEditorAdvancedButton.extend({ - nicURI : 'http://files.nicedit.com/', + nicURI: 'http://files.nicedit.com/', - addPane : function() { - this.im = this.ne.selectedInstance.selElm().parentTag('IMG'); - this.myID = Math.round(Math.random()*Math.pow(10,15)); - this.requestInterval = 1000; - this.uri = this.ne.options.uploadURI || this.nicURI; - nicUploadButton.lastPlugin = this; + addPane: function() { + this.im = this.ne.selectedInstance.selElm().parentTag('IMG'); + this.myID = Math.round(Math.random() * Math.pow(10, 15)); + this.requestInterval = 1000; + this.uri = this.ne.options.uploadURI || this.nicURI; + nicUploadButton.lastPlugin = this; - this.myFrame = new bkElement('iframe').setAttributes({ width : '100%', height : '100px', frameBorder : 0, scrolling : 'no' }).setStyle({border : 0}).appendTo(this.pane.pane); - this.progressWrapper = new bkElement('div').setStyle({display: 'none', width: '100%', height: '20px', border : '1px solid #ccc'}).appendTo(this.pane.pane); - this.progress = new bkElement('div').setStyle({width: '0%', height: '20px', backgroundColor : '#ccc'}).setContent(' ').appendTo(this.progressWrapper); + this.myFrame = new bkElement('iframe').setAttributes({ + width: '100%', + height: '100px', + frameBorder: 0, + scrolling: 'no' + }).setStyle({ + border: 0 + }).appendTo(this.pane.pane); + this.progressWrapper = new bkElement('div').setStyle({ + display: 'none', + width: '100%', + height: '20px', + border: '1px solid #ccc' + }).appendTo(this.pane.pane); + this.progress = new bkElement('div').setStyle({ + width: '0%', + height: '20px', + backgroundColor: '#ccc' + }).setContent(' ').appendTo(this.progressWrapper); - setTimeout(this.addForm.closure(this),50); - }, + setTimeout(this.addForm.closure(this), 50); + }, - addForm : function() { - var myDoc = this.myDoc = this.myFrame.contentWindow.document; - myDoc.open(); - myDoc.write(""); - myDoc.write('
'); - myDoc.write(''); - if(this.uri == this.nicURI) { - myDoc.write('
Hosted by
ImageShack
'); - } - myDoc.write('
Insert an Image
'); - myDoc.write(''); - myDoc.write('
'); - myDoc.write(""); - myDoc.close(); + addForm: function() { + var myDoc = this.myDoc = this.myFrame.contentWindow.document; + myDoc.open(); + myDoc.write(""); + myDoc.write('
'); + myDoc.write(''); + if (this.uri == this.nicURI) { + myDoc.write('
Hosted by
ImageShack
'); + } + myDoc.write('
Insert an Image
'); + myDoc.write(''); + myDoc.write('
'); + myDoc.write(""); + myDoc.close(); - this.myBody = myDoc.body; + this.myBody = myDoc.body; - this.myForm = $BK(this.myBody.getElementsByTagName('form')[0]); - this.myInput = $BK(this.myBody.getElementsByTagName('input')[1]).addEvent('change', this.startUpload.closure(this)); - this.myStatus = new bkElement('div',this.myDoc).setStyle({textAlign : 'center', fontSize : '14px'}).appendTo(this.myBody); - }, + this.myForm = $BK(this.myBody.getElementsByTagName('form')[0]); + this.myInput = $BK(this.myBody.getElementsByTagName('input')[1]).addEvent('change', this.startUpload.closure(this)); + this.myStatus = new bkElement('div', this.myDoc).setStyle({ + textAlign: 'center', + fontSize: '14px' + }).appendTo(this.myBody); + }, - startUpload : function() { - this.myForm.setStyle({display : 'none'}); - this.myStatus.setContent('Uploading...
Please wait'); - this.myForm.submit(); - setTimeout(this.makeRequest.closure(this),this.requestInterval); - }, + startUpload: function() { + this.myForm.setStyle({ + display: 'none' + }); + this.myStatus.setContent('Uploading...
Please wait'); + this.myForm.submit(); + setTimeout(this.makeRequest.closure(this), this.requestInterval); + }, - makeRequest : function() { - if(this.pane && this.pane.pane) { - nicUploadButton.lastPlugin = this; - var s = new bkElement('script').setAttributes({ type : 'text/javascript', src : this.uri+'?check='+this.myID+'&rand='+Math.round(Math.random()*Math.pow(10,15))}).addEvent('load', function() { - s.parentNode.removeChild(s); - }).appendTo(document.getElementsByTagName('head')[0]); - if(this.requestInterval) { - setTimeout(this.makeRequest.closure(this), this.requestInterval); - } - } - }, + makeRequest: function() { + if (this.pane && this.pane.pane) { + nicUploadButton.lastPlugin = this; + var s = new bkElement('script').setAttributes({ + type: 'text/javascript', + src: this.uri + '?check=' + this.myID + '&rand=' + Math.round(Math.random() * Math.pow(10, 15)) + }).addEvent('load', function() { + s.parentNode.removeChild(s); + }).appendTo(document.getElementsByTagName('head')[0]); + if (this.requestInterval) { + setTimeout(this.makeRequest.closure(this), this.requestInterval); + } + } + }, - setProgress : function(percent) { - this.progressWrapper.setStyle({display: 'block'}); - this.progress.setStyle({width : percent+'%'}); - }, + setProgress: function(percent) { + this.progressWrapper.setStyle({ + display: 'block' + }); + this.progress.setStyle({ + width: percent + '%' + }); + }, - update : function(o) { - if(o == false) { - this.progressWrapper.setStyle({display : 'none'}); - } else if(o.url) { - this.setProgress(100); - this.requestInterval = false; + update: function(o) { + if (o === false) { + this.progressWrapper.setStyle({ + display: 'none' + }); + } else if (o.url) { + this.setProgress(100); + this.requestInterval = false; - if(!this.im) { - this.ne.selectedInstance.restoreRng(); - var tmp = 'javascript:nicImTemp();'; - this.ne.nicCommand("insertImage",tmp); - this.im = this.findElm('IMG','src',tmp); - } - var w = parseInt(this.ne.selectedInstance.elm.getStyle('width')); - if(this.im) { - this.im.setAttributes({ - src : o.url, - width : (w && o.width) ? Math.min(w,o.width) : '' - }); - } + if (!this.im) { + this.ne.selectedInstance.restoreRng(); + var tmp = 'javascript:nicImTemp();'; + this.ne.nicCommand("insertImage", tmp); + this.im = this.findElm('IMG', 'src', tmp); + } + var w = parseInt(this.ne.selectedInstance.elm.getStyle('width'), 10); + if (this.im) { + this.im.setAttributes({ + src: o.url, + width: (w && o.width) ? Math.min(w, o.width) : '' + }); + } - this.removePane(); - } else if(o.error) { - this.requestInterval = false; - this.setProgress(100); - alert("There was an error uploading your image ("+o.error+")."); - this.removePane(); - } else if(o.noprogress) { - this.progressWrapper.setStyle({display : 'none'}); - if(this.uri.indexOf('http:') == -1 || this.uri.indexOf(window.location.host) != -1) { - this.requestInterval = false; - } - } else { - this.setProgress( Math.round( (o.current/o.total) * 75) ); - if(o.interval) { - this.requestInterval = o.interval; - } - } - } + this.removePane(); + } else if (o.error) { + this.requestInterval = false; + this.setProgress(100); + alert("There was an error uploading your image (" + o.error + ")."); + this.removePane(); + } else if (o.noprogress) { + this.progressWrapper.setStyle({ + display: 'none' + }); + if (this.uri.indexOf('http:') == -1 || this.uri.indexOf(window.location.host) != -1) { + this.requestInterval = false; + } + } else { + this.setProgress(Math.round((o.current / o.total) * 75)); + if (o.interval) { + this.requestInterval = o.interval; + } + } + } }); nicUploadButton.statusCb = function(o) { - nicUploadButton.lastPlugin.update(o); -} + nicUploadButton.lastPlugin.update(o); +}; -nicEditors.registerPlugin(nicPlugin,nicUploadOptions); +nicEditors.registerPlugin(nicPlugin, nicUploadOptions); var nicXHTML = bkClass.extend({ - stripAttributes : ['_moz_dirty','_moz_resizing','_extended'], - noShort : ['style','title','script','textarea','a'], - cssReplace : {'font-weight:bold;' : 'strong', 'font-style:italic;' : 'em'}, - sizes : {1 : 'xx-small', 2 : 'x-small', 3 : 'small', 4 : 'medium', 5 : 'large', 6 : 'x-large'}, + stripAttributes: ['_moz_dirty', '_moz_resizing', '_extended'], + noShort: ['style', 'title', 'script', 'textarea', 'a'], + cssReplace: { + 'font-weight:bold;': 'strong', + 'font-style:italic;': 'em' + }, + sizes: { + 1: 'xx-small', + 2: 'x-small', + 3: 'small', + 4: 'medium', + 5: 'large', + 6: 'x-large' + }, - construct : function(nicEditor) { - this.ne = nicEditor; - if(this.ne.options.xhtml) { - nicEditor.addEvent('get',this.cleanup.closure(this)); - } - }, + construct: function(nicEditor) { + this.ne = nicEditor; + if (this.ne.options.xhtml) { + nicEditor.addEvent('get', this.cleanup.closure(this)); + } + }, - cleanup : function(ni) { - var node = ni.getElm(); - var xhtml = this.toXHTML(node); - ni.content = xhtml; - }, + cleanup: function(ni) { + var node = ni.getElm(); + var xhtml = this.toXHTML(node); + ni.content = xhtml; + }, - toXHTML : function(n,r,d) { - var txt = ''; - var attrTxt = ''; - var cssTxt = ''; - var nType = n.nodeType; - var nName = n.nodeName.toLowerCase(); - var nChild = n.hasChildNodes && n.hasChildNodes(); - var extraNodes = new Array(); + toXHTML: function(n, r, d) { + var txt = ''; + var attrTxt = ''; + var cssTxt = ''; + var nType = n.nodeType; + var nName = n.nodeName.toLowerCase(); + var nChild = n.hasChildNodes && n.hasChildNodes(); + var extraNodes = []; - switch(nType) { - case 1: - var nAttributes = n.attributes; + switch (nType) { + case 1: + var nAttributes = n.attributes; - switch(nName) { - case 'b': - nName = 'strong'; - break; - case 'i': - nName = 'em'; - break; - case 'font': - nName = 'span'; - break; - } + switch (nName) { + case 'b': + nName = 'strong'; + break; + case 'i': + nName = 'em'; + break; + case 'font': + nName = 'span'; + break; + } - if(r) { - for(var i=0;i'; - } + for (var j = 0; j < extraNodes.length; j++) { + txt += '<' + extraNodes[j] + '>'; + } - if(attrTxt == "" && nName == "span") { - r = false; - } - if(r) { - txt += '<'+nName; - if(nName != 'br') { - txt += attrTxt; - } - } - } + if (attrTxt === "" && nName == "span") { + r = false; + } + if (r) { + txt += '<' + nName; + if (nName != 'br') { + txt += attrTxt; + } + } + } + if (!nChild && !bkLib.inArray(this.noShort, attributeName)) { + if (r) { + txt += ' />'; + } + } else { + if (r) { + txt += '>'; + } + for (var k = 0; k < n.childNodes.length; k++) { + var results = this.toXHTML(n.childNodes[k], true, true); + if (results) { + txt += results; + } + } + } - if(!nChild && !bkLib.inArray(this.noShort,attributeName)) { - if(r) { - txt += ' />'; - } - } else { - if(r) { - txt += '>'; - } + if (r && nChild) { + txt += ''; + } - for(var i=0;i'; + } - if(r && nChild) { - txt += ''; - } + break; + case 3: + //if(n.nodeValue != '\n') { + txt += n.nodeValue; + //} + break; + } - for(var i=0;i'; - } - - break; - case 3: - //if(n.nodeValue != '\n') { - txt += n.nodeValue; - //} - break; - } - - return txt; - } + return txt; + } }); nicEditors.registerPlugin(nicXHTML); var nicBBCode = bkClass.extend({ - construct : function(nicEditor) { - this.ne = nicEditor; - if(this.ne.options.bbCode) { - nicEditor.addEvent('get',this.bbGet.closure(this)); - nicEditor.addEvent('set',this.bbSet.closure(this)); + construct: function(nicEditor) { + this.ne = nicEditor; + if (this.ne.options.bbCode) { + nicEditor.addEvent('get', this.bbGet.closure(this)); + nicEditor.addEvent('set', this.bbSet.closure(this)); - var loadedPlugins = this.ne.loadedPlugins; - for(itm in loadedPlugins) { - if(loadedPlugins[itm].toXHTML) { - this.xhtml = loadedPlugins[itm]; - } - } - } - }, + var loadedPlugins = this.ne.loadedPlugins; + for (var itm in loadedPlugins) { + if (loadedPlugins[itm].toXHTML) { + this.xhtml = loadedPlugins[itm]; + } + } + } + }, - bbGet : function(ni) { - var xhtml = this.xhtml.toXHTML(ni.getElm()); - ni.content = this.toBBCode(xhtml); - }, + bbGet: function(ni) { + var xhtml = this.xhtml.toXHTML(ni.getElm()); + ni.content = this.toBBCode(xhtml); + }, - bbSet : function(ni) { - ni.content = this.fromBBCode(ni.content); - }, + bbSet: function(ni) { + ni.content = this.fromBBCode(ni.content); + }, - toBBCode : function(xhtml) { - function rp(r,m) { - xhtml = xhtml.replace(r,m); - } + toBBCode: function(xhtml) { + function rp(r, m) { + xhtml = xhtml.replace(r, m); + } - rp(/\n/gi,""); - rp(/(.*?)<\/strong>/gi,"[b]$1[/b]"); - rp(/(.*?)<\/em>/gi,"[i]$1[/i]"); - rp(/(.*?)<\/span>/gi,"[u]$1[/u]"); - rp(/
    (.*?)<\/ul>/gi,"[list]$1[/list]"); - rp(/
  • (.*?)<\/li>/gi,"[*]$1[/*]"); - rp(/
      (.*?)<\/ol>/gi,"[list=1]$1[/list]"); - rp(//gi,"[img]$1[/img]"); - rp(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); - rp(//gi,"\n"); - rp(/<.*?>.*?<\/.*?>/gi,""); + rp(/\n/gi, ""); + rp(/(.*?)<\/strong>/gi, "[b]$1[/b]"); + rp(/(.*?)<\/em>/gi, "[i]$1[/i]"); + rp(/(.*?)<\/span>/gi, "[u]$1[/u]"); + rp(/
        (.*?)<\/ul>/gi, "[list]$1[/list]"); + rp(/
      • (.*?)<\/li>/gi, "[*]$1[/*]"); + rp(/
          (.*?)<\/ol>/gi, "[list=1]$1[/list]"); + rp(//gi, "[img]$1[/img]"); + rp(/(.*?)<\/a>/gi, "[url=$1]$2[/url]"); + rp(//gi, "\n"); + rp(/<.*?>.*?<\/.*?>/gi, ""); - return xhtml; - }, + return xhtml; + }, - fromBBCode : function(bbCode) { - function rp(r,m) { - bbCode = bbCode.replace(r,m); - } + fromBBCode: function(bbCode) { + function rp(r, m) { + bbCode = bbCode.replace(r, m); + } - rp(/\[b\](.*?)\[\/b\]/gi,"$1"); - rp(/\[i\](.*?)\[\/i\]/gi,"$1"); - rp(/\[u\](.*?)\[\/u\]/gi,"$1"); - rp(/\[list\](.*?)\[\/list\]/gi,"
            $1
          "); - rp(/\[list=1\](.*?)\[\/list\]/gi,"
            $1
          "); - rp(/\[\*\](.*?)\[\/\*\]/gi,"
        1. $1
        2. "); - rp(/\[img\](.*?)\[\/img\]/gi,""); - rp(/\[url=(.*?)\](.*?)\[\/url\]/gi,"$2"); - rp(/\n/gi,"
          "); - //rp(/\[.*?\](.*?)\[\/.*?\]/gi,"$1"); + rp(/\[b\](.*?)\[\/b\]/gi, "$1"); + rp(/\[i\](.*?)\[\/i\]/gi, "$1"); + rp(/\[u\](.*?)\[\/u\]/gi, "$1"); + rp(/\[list\](.*?)\[\/list\]/gi, "
            $1
          "); + rp(/\[list=1\](.*?)\[\/list\]/gi, "
            $1
          "); + rp(/\[\*\](.*?)\[\/\*\]/gi, "
        3. $1
        4. "); + rp(/\[img\](.*?)\[\/img\]/gi, ""); + rp(/\[url=(.*?)\](.*?)\[\/url\]/gi, "$2"); + rp(/\n/gi, "
          "); + //rp(/\[.*?\](.*?)\[\/.*?\]/gi,"$1"); - return bbCode; - } + return bbCode; + } }); @@ -1711,56 +2263,78 @@ 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); - }, + 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 e = this.selectedInstance.e; - this.floating.setStyle({ width : (parseInt(e.getStyle('width')) || e.clientWidth)+'px' }); - var top = e.offsetTop-this.floating.offsetHeight; - if(top < 0) { - top = e.offsetTop+e.offsetHeight; - } + reposition: function() { + var e = this.selectedInstance.e; + this.floating.setStyle({ + width: (parseInt(e.getStyle('width'), 10) || e.clientWidth) + 'px' + }); + var top = e.offsetTop - this.floating.offsetHeight; + if (top < 0) { + top = e.offsetTop + e.offsetHeight; + } - this.floating.setStyle({ top : top+'px', left : e.offsetLeft+'px', display : 'block' }); - }, + this.floating.setStyle({ + top: top + 'px', + left: e.offsetLeft + 'px', + display: 'block' + }); + }, - hide : function() { - this.floating.setStyle({ top : '-1000px'}); - } + hide: function() { + this.floating.setStyle({ + top: '-1000px' + }); + } }); /* START CONFIG */ var nicCodeOptions = { - buttons : { - 'xhtml' : {name : 'Edit HTML', type : 'nicCodeButton'} - } + buttons: { + 'xhtml': { + name: 'Edit HTML', + type: 'nicCodeButton' + } + } }; /* END CONFIG */ var nicCodeButton = nicEditorAdvancedButton.extend({ - width : '350px', + width: '350px', - addPane : function() { - this.addForm({ - '' : {type : 'title', txt : 'Edit HTML'}, - 'code' : {type : 'content', 'value' : this.ne.selectedInstance.getContent(), style : {width: '340px', height : '200px'}} - }); - }, + addPane: function() { + this.addForm({ + '': { + type: 'title', + txt: 'Edit HTML' + }, + 'code': { + type: 'content', + 'value': this.ne.selectedInstance.getContent(), + style: { + width: '340px', + height: '200px' + } + } + }); + }, - submit : function(e) { - var code = this.inputs['code'].value; - this.ne.selectedInstance.setContent(code); - this.removePane(); - } + submit: function(e) { + var code = this.inputs['code'].value; + this.ne.selectedInstance.setContent(code); + this.removePane(); + } }); -nicEditors.registerPlugin(nicPlugin,nicCodeOptions); - - +nicEditors.registerPlugin(nicPlugin, nicCodeOptions);