NicEdit





  1. /* NicEdit - Micro Inline WYSIWYG
  2.  * Copyright 2007-2008 Brian Kirchoff
  3.  *
  4.  * NicEdit is distributed under the terms of the MIT license
  5.  * For more information visit http://nicedit.com/
  6.  * Do not remove this copyright message
  7.  */
  8. var bkExtend = function(){
  9.     var args = arguments;
  10.     if (args.length == 1) args = [this, args[0]];
  11.     for (var prop in args[1]) args[0][prop] = args[1][prop];
  12.     return args[0];
  13. };
  14. function bkClass() { }
  15. bkClass.prototype.construct = function() {};
  16. bkClass.extend = function(def) {
  17.   var classDef = function() {
  18.       if (arguments[0] !== bkClass) { return this.construct.apply(this, arguments); }
  19.   };
  20.   var proto = new this(bkClass);
  21.   bkExtend(proto,def);
  22.   classDef.prototype = proto;
  23.   classDef.extend = this.extend;      
  24.   return classDef;
  25. };
  26. var bkElement = bkClass.extend({
  27.     construct : function(elm,d) {
  28.         if(typeof(elm) == "string") {
  29.             elm = (d || document).createElement(elm);
  30.         }
  31.         elm = $BK(elm);
  32.         return elm;
  33.     },
  34.     
  35.     appendTo : function(elm) {
  36.         elm.appendChild(this);  
  37.         return this;
  38.     },
  39.     
  40.     appendBefore : function(elm) {
  41.         elm.parentNode.insertBefore(this,elm);  
  42.         return this;
  43.     },
  44.     
  45.     addEvent : function(type, fn) {
  46.         bkLib.addEvent(this,type,fn);
  47.         return this;    
  48.     },
  49.     
  50.     setContent : function(c) {
  51.         this.innerHTML = c;
  52.         return this;
  53.     },
  54.     
  55.     pos : function() {
  56.         var curleft = curtop = 0;
  57.         var o = obj = this;
  58.         if (obj.offsetParent) {
  59.             do {
  60.                 curleft += obj.offsetLeft;
  61.                 curtop += obj.offsetTop;
  62.             } while (obj = obj.offsetParent);
  63.         }
  64.         var b = (!window.opera) ? parseInt(this.getStyle('border-width') || this.style.border) || 0 : 0;
  65.         return [curleft+b,curtop+b+this.offsetHeight];
  66.     },
  67.     
  68.     noSelect : function() {
  69.         bkLib.noSelect(this);
  70.         return this;
  71.     },
  72.     
  73.     parentTag : function(t) {
  74.         var elm = this;
  75.          do {
  76.             if(elm && elm.nodeName && elm.nodeName.toUpperCase() == t) {
  77.                 return elm;
  78.             }
  79.             elm = elm.parentNode;
  80.         } while(elm);
  81.         return false;
  82.     },
  83.     
  84.     hasClass : function(cls) {
  85.         return this.className.match(new RegExp('(//s|^)nicEdit-'+cls+'(//s|$)'));
  86.     },
  87.     
  88.     addClass : function(cls) {
  89.         if (!this.hasClass(cls)) { this.className += " nicEdit-"+cls };
  90.         return this;
  91.     },
  92.     
  93.     removeClass : function(cls) {
  94.         if (this.hasClass(cls)) {
  95.             this.className = this.className.replace(new RegExp('(//s|^)nicEdit-'+cls+'(//s|$)'),' ');
  96.         }
  97.         return this;
  98.     },
  99.     setStyle : function(st) {
  100.         var elmStyle = this.style;
  101.         for(var itm in st) {
  102.             switch(itm) {
  103.                 case 'float':
  104.                     elmStyle['cssFloat'] = elmStyle['styleFloat'] = st[itm];
  105.                     break;
  106.                 case 'opacity':
  107.                     elmStyle.opacity = st[itm];
  108.                     elmStyle.filter = "alpha(opacity=" + Math.round(st[itm]*100) + ")"
  109.                     break;
  110.                 case 'className':
  111.                     this.className = st[itm];
  112.                     break;
  113.                 default:
  114.                     //if(document.compatMode || itm != "cursor") { // Nasty Workaround for IE 5.5
  115.                         elmStyle[itm] = st[itm];
  116.                     //}     
  117.             }
  118.         }
  119.         return this;
  120.     },
  121.     
  122.     getStyle : function( cssRule, d ) {
  123.         var doc = (!d) ? document.defaultView : d; 
  124.         if(this.nodeType == 1)
  125.         return (doc && doc.getComputedStyle) ? doc.getComputedStyle( thisnull ).getPropertyValue(cssRule) : this.currentStyle[ bkLib.camelize(cssRule) ];
  126.     },
  127.     
  128.     remove : function() {
  129.         this.parentNode.removeChild(this);
  130.         return this;    
  131.     },
  132.     
  133.     setAttributes : function(at) {
  134.         for(var itm in at) {
  135.             this[itm] = at[itm];
  136.         }
  137.         return this;
  138.     }
  139. });
  140. var bkLib = {
  141.     isMSIE : (navigator.appVersion.indexOf("MSIE") != -1),
  142.     
  143.     addEvent : function(obj, type, fn) {
  144.         (obj.addEventListener) ? obj.addEventListener( type, fn, false ) : obj.attachEvent("on"+type, fn);  
  145.     },
  146.     
  147.     toArray : function(iterable) {
  148.         var length = iterable.length, results = new Array(length);
  149.         while (length--) { results[length] = iterable[length] };
  150.         return results; 
  151.     },
  152.     
  153.     noSelect : function(element) {
  154.         if(element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') {
  155.             element.setAttribute('unselectable','on');
  156.         }
  157.         for(var i=0;i<element.childNodes.length;i++) {
  158.             bkLib.noSelect(element.childNodes[i]);
  159.         }
  160.     },
  161.     camelize : function(s) {
  162.         return s.replace(//-(.)/g, function(m, l){return l.toUpperCase()});
  163.     },
  164.     inArray : function(arr,item) {
  165.         return (bkLib.search(arr,item) != null);
  166.     },
  167.     search : function(arr,itm) {
  168.         for(var i=0; i < arr.length; i++) {
  169.             if(arr[i] == itm)
  170.                 return i;
  171.         }
  172.         return null;    
  173.     },
  174.     cancelEvent : function(e) {
  175.         e = e || window.event;
  176.         if(e.preventDefault && e.stopPropagation) {
  177.             e.preventDefault();
  178.             e.stopPropagation();
  179.         }
  180.         return false;
  181.     },
  182.     domLoad : [],
  183.     domLoaded : function() {
  184.         if (arguments.callee.done) return;
  185.         arguments.callee.done = true;
  186.         for (i = 0;i < bkLib.domLoad.length;i++) bkLib.domLoad[i]();
  187.     },
  188.     onDomLoaded : function(fireThis) {
  189.         this.domLoad.push(fireThis);
  190.         if (document.addEventListener) {
  191.             document.addEventListener("DOMContentLoaded", bkLib.domLoaded, null);
  192.         } else if(bkLib.isMSIE) {
  193.             document.write("<style>.nicEdit-main p { margin: 0; }</style><scr"+"ipt id=__ie_onload defer " + ((location.protocol == "https:") ? "src='javascript:void(0)'" : "src=//0") + "><//scr"+"ipt>");
  194.             $BK("__ie_onload").onreadystatechange = function() {
  195.                 if (this.readyState == "complete"){bkLib.domLoaded();}
  196.             };
  197.         }
  198.         window.onload = bkLib.domLoaded;
  199.     }
  200. };
  201. function $BK(elm) {
  202.     if(typeof(elm) == "string") {
  203.         elm = document.getElementById(elm);
  204.     }
  205.     return (elm && !elm.appendTo) ? bkExtend(elm,bkElement.prototype) : elm;
  206. }
  207. var bkEvent = {
  208.     addEvent : function(evType, evFunc) {
  209.         if(evFunc) {
  210.             this.eventList = this.eventList || {};
  211.             this.eventList[evType] = this.eventList[evType] || [];
  212.             this.eventList[evType].push(evFunc);
  213.         }
  214.         return this;
  215.     },
  216.     fireEvent : function() {
  217.         var args = bkLib.toArray(arguments), evType = args.shift();
  218.         if(this.eventList && this.eventList[evType]) {
  219.             for(var i=0;i<this.eventList[evType].length;i++) {
  220.                 this.eventList[evType][i].apply(this,args);
  221.             }
  222.         }
  223.     }   
  224. };
  225. function __(s) {
  226.     return s;
  227. }
  228. Function.prototype.closure = function() {
  229.   var __method = this, args = bkLib.toArray(arguments), obj = args.shift();
  230.   return function() { if(typeof(bkLib) != 'undefined') { return __method.apply(obj,args.concat(bkLib.toArray(arguments))); } };
  231. }
  232.     
  233. Function.prototype.closureListener = function() {
  234.     var __method = this, args = bkLib.toArray(arguments), object = args.shift(); 
  235.     return function(e) { 
  236.     e = e || window.event;
  237.     if(e.target) { var target = e.target; } else { var target =  e.srcElement };
  238.         return __method.apply(object, [e,target].concat(args) ); 
  239.     };
  240. }       
  241. /* START CONFIG */
  242. var nicEditorConfig = bkClass.extend({
  243.     buttons : {
  244.         'bold' : {name : __('Click to Bold'), command : 'Bold', tags : ['B','STRONG'], css : {'font-weight' : 'bold'}, key : 'b'},
  245.         'italic' : {name : __('Click to Italic'), command : 'Italic', tags : ['EM','I'], css : {'font-style' : 'italic'}, key : 'i'},
  246.         'underline' : {name : __('Click to Underline'), command : 'Underline', tags : ['U'], css : {'text-decoration' : 'underline'}, key : 'u'},
  247.         'left' : {name : __('Left Align'), command : 'justifyleft', noActive : true},
  248.         'center' : {name : __('Center Align'), command : 'justifycenter', noActive : true},
  249.         'right' : {name : __('Right Align'), command : 'justifyright', noActive : true},
  250.         'justify' : {name : __('Justify Align'), command : 'justifyfull', noActive : true},
  251.         'ol' : {name : __('Insert Ordered List'), command : 'insertorderedlist', tags : ['OL']},
  252.         'ul' :  {name : __('Insert Unordered List'), command : 'insertunorderedlist', tags : ['UL']},
  253.         'subscript' : {name : __('Click to Subscript'), command : 'subscript', tags : ['SUB']},
  254.         'superscript' : {name : __('Click to Superscript'), command : 'superscript', tags : ['SUP']},
  255.         'strikethrough' : {name : __('Click to Strike Through'), command : 'strikeThrough', css : {'text-decoration' : 'line-through'}},
  256.         'removeformat' : {name : __('Remove Formatting'), command : 'removeformat', noActive : true},
  257.         'indent' : {name : __('Indent Text'), command : 'indent', noActive : true},
  258.         'outdent' : {name : __('Remove Indent'), command : 'outdent', noActive : true},
  259.         'hr' : {name : __('Horizontal Rule'), command : 'insertHorizontalRule', noActive : true}
  260.     },
  261.     iconsPath : '../nicEditorIcons2.gif',
  262.     buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','bgcolor','smile'],
  263.     iconList : {"bold":1,"center":2,"hr":3,"indent":4,"italic":5,"justify":6,"left":7,"ol":8,"outdent":9,"removeformat":10,"right":11,"save":22,"strikethrough":13,"subscript":14,"superscript":15,"ul":16,"underline":17,"image":18,"link":19,"unlink":20,"close":21,"arrow":23,"upload":24,"smile":25}
  264.     
  265. });
  266. /* END CONFIG */
  267. var nicEditors = {
  268.     nicPlugins : [],
  269.     editors : [],
  270.     
  271.     registerPlugin : function(plugin,options) {
  272.         this.nicPlugins.push({p : plugin, o : options});
  273.     },
  274.     allTextAreas : function(nicOptions) {
  275.         var textareas = document.getElementsByTagName("textarea");
  276.         for(var i=0;i<textareas.length;i++) {
  277.             nicEditors.editors.push(new nicEditor(nicOptions).panelInstance(textareas[i]));
  278.         }
  279.         return nicEditors.editors;
  280.     },
  281.     
  282.     findEditor : function(e) {
  283.         var editors = nicEditors.editors;
  284.         for(var i=0;i<editors.length;i++) {
  285.             if(editors[i].instanceById(e)) {
  286.                 return editors[i].instanceById(e);
  287.             }
  288.         }
  289.     }
  290. };
  291. var nicEditor = bkClass.extend({
  292.     construct : function(o) {
  293.         this.options = new nicEditorConfig();
  294.         bkExtend(this.options,o);
  295.         this.nicInstances = new Array();
  296.         this.loadedPlugins = new Array();
  297.         
  298.         var plugins = nicEditors.nicPlugins;
  299.         for(var i=0;i<plugins.length;i++) {
  300.             this.loadedPlugins.push(new plugins[i].p(this,plugins[i].o));
  301.         }
  302.         nicEditors.editors.push(this);
  303.         bkLib.addEvent(document.body,'mousedown'this.selectCheck.closureListener(this) );
  304.     },
  305.     
  306.     panelInstance : function(e,o) {
  307.         e = this.checkReplace($BK(e));
  308.         var panelElm = new bkElement('DIV').setStyle({width : (parseInt(e.getStyle('width')) || e.clientWidth)+'px'}).appendBefore(e);
  309.         this.setPanel(panelElm);
  310.         return this.addInstance(e,o);   
  311.     },
  312.     checkReplace : function(e) {
  313.         var r = nicEditors.findEditor(e);
  314.         if(r) {
  315.             r.removeInstance(e);
  316.             r.removePanel();
  317.         }
  318.         return e;
  319.     },
  320.     addInstance : function(e,o) {
  321.         e = this.checkReplace($BK(e));
  322.         if( (e.contentEditable || !!window.opera) && navigator.userAgent.indexOf('Firefox/3') == -1 ) {
  323.             var newInstance = new nicEditorInstance(e,o,this);
  324.         } else {
  325.             var newInstance = new nicEditorIFrameInstance(e,o,this);
  326.         }
  327.         this.nicInstances.push(newInstance);
  328.         return this;
  329.     },
  330.     
  331.     removeInstance : function(e) {
  332.         e = $BK(e);
  333.         var instances = this.nicInstances;
  334.         for(var i=0;i<instances.length;i++) {   
  335.             if(instances[i].e == e) {
  336.                 instances[i].remove();
  337.                 this.nicInstances.splice(i,1);
  338.             }
  339.         }
  340.     },
  341.     removePanel : function(e) {
  342.         if(this.nicPanel) {
  343.             this.nicPanel.remove();
  344.             this.nicPanel = null;
  345.         }   
  346.     },
  347.     instanceById : function(e) {
  348.         e = $BK(e);
  349.         var instances = this.nicInstances;
  350.         for(var i=0;i<instances.length;i++) {
  351.             if(instances[i].e == e) {
  352.                 return instances[i];
  353.             }
  354.         }   
  355.     },
  356.     setPanel : function(e) {
  357.         this.nicPanel = new nicEditorPanel($BK(e),this.options,this);
  358.         this.fireEvent('panel',this.nicPanel);
  359.         return this;
  360.     },
  361.     
  362.     nicCommand : function(cmd,args) {   
  363.         if(this.selectedInstance) {
  364.             this.selectedInstance.nicCommand(cmd,args);
  365.         }
  366.     },
  367.     
  368.     getIcon : function(iconName,options) {
  369.         var icon = this.options.iconList[iconName];
  370.         var file = (options.iconFiles) ? options.iconFiles[iconName] : '';
  371.         return {backgroundImage : "url('"+((icon) ? this.options.iconsPath : file)+"')", backgroundPosition : ((icon) ? ((icon-1)*-18) : 0)+'px 0px'};  
  372.     },
  373.         
  374.     selectCheck : function(e,t) {
  375.         var found = false;
  376.         do{
  377.             if(t.className && t.className.indexOf('nicEdit') != -1) {
  378.                 return false;
  379.             }
  380.         } while(t = t.parentNode);
  381.         this.fireEvent('blur',this.selectedInstance,t);
  382.         this.lastSelectedInstance = this.selectedInstance;
  383.         this.selectedInstance = null;
  384.         return false;
  385.     }
  386.     
  387. });
  388. nicEditor = nicEditor.extend(bkEvent);
  389.  
  390. var nicEditorInstance = bkClass.extend({
  391.     isSelected : false,
  392.     
  393.     construct : function(e,options,nicEditor) {
  394.         this.ne = nicEditor;
  395.         this.elm = this.e = e;
  396.         this.options = options || {};
  397.         
  398.         newX = parseInt(e.getStyle('width')) || e.clientWidth;
  399.         newY = parseInt(e.getStyle('height')) || e.clientHeight;
  400.         this.initialHeight = newY-8;
  401.         
  402.         var isTextarea = (e.nodeName.toLowerCase() == "textarea");
  403.         if(isTextarea || this.options.hasPanel) {
  404.             var ie7s = (bkLib.isMSIE && !((typeof document.body.style.maxHeight != "undefined") && document.compatMode == "CSS1Compat"))
  405.             var s = {width: newX+'px', border : '1px solid #ccc', borderTop : 0, overflowY : 'auto', overflowX: 'hidden' };
  406.             s[(ie7s) ? 'height' : 'maxHeight'] = (this.ne.options.maxHeight) ? this.ne.options.maxHeight+'px' : null;
  407.             this.editorContain = new bkElement('DIV').setStyle(s).appendBefore(e);
  408.             var editorElm = new bkElement('DIV').setStyle({width : (newX-8)+'px', margin: '4px', minHeight : newY+'px'}).addClass('main').appendTo(this.editorContain);
  409.             e.setStyle({display : 'none'});
  410.                 
  411.             editorElm.innerHTML = e.innerHTML;      
  412.             if(isTextarea) {
  413.                 editorElm.setContent(e.value);
  414.                 this.copyElm = e;
  415.                 var f = e.parentTag('FORM');
  416.                 if(f) { bkLib.addEvent( f, 'submit'this.saveContent.closure(this)); }
  417.             }
  418.             editorElm.setStyle((ie7s) ? {height : newY+'px'} : {overflow: 'hidden'});
  419.             this.elm = editorElm;   
  420.         }
  421.         this.ne.addEvent('blur',this.blur.closure(this));
  422.         this.init();
  423.         this.blur();
  424.     },
  425.     
  426.     init : function() {
  427.         this.elm.setAttribute('contentEditable','true');    
  428.         if(this.getContent() == "") {
  429.             this.setContent('<br />');
  430.         }
  431.         this.instanceDoc = document.defaultView;
  432.         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));
  433.         this.ne.fireEvent('add',this);
  434.     },
  435.     
  436.     remove : function() {
  437.         this.saveContent();
  438.         if(this.copyElm || this.options.hasPanel) {
  439.             this.editorContain.remove();
  440.             this.e.setStyle({'display' : 'block'});
  441.             this.ne.removePanel();
  442.         }
  443.         this.disable();
  444.         this.ne.fireEvent('remove',this);
  445.     },
  446.     
  447.     disable : function() {
  448.         this.elm.setAttribute('contentEditable','false');
  449.     },
  450.     
  451.     getSel : function() {
  452.         return (window.getSelection) ? window.getSelection() : document.selection;  
  453.     },
  454.     
  455.     getRng : function() {
  456.         var s = this.getSel();
  457.         if(!s) { return null; }
  458.         return (s.rangeCount > 0) ? s.getRangeAt(0) : s.createRange();
  459.     },
  460.     
  461.     selRng : function(rng,s) {
  462.         if(window.getSelection) {
  463.             s.removeAllRanges();
  464.             s.addRange(rng);
  465.         } else {
  466.             rng.select();
  467.         }
  468.     },
  469.     
  470.     selElm : function() {
  471.         var r = this.getRng();
  472.         if(r.startContainer) {
  473.             var contain = r.startContainer;
  474.             if(r.cloneContents().childNodes.length == 1) {
  475.                 for(var i=0;i<contain.childNodes.length;i++) {
  476.                     var rng = contain.childNodes[i].ownerDocument.createRange();
  477.                     rng.selectNode(contain.childNodes[i]);                  
  478.                     if(r.compareBoundaryPoints(Range.START_TO_START,rng) != 1 && 
  479.                         r.compareBoundaryPoints(Range.END_TO_END,rng) != -1) {
  480.                         return $BK(contain.childNodes[i]);
  481.                     }
  482.                 }
  483.             }
  484.             return $BK(contain);
  485.         } else {
  486.             return $BK((this.getSel().type == "Control") ? r.item(0) : r.parentElement());
  487.         }
  488.     },
  489.     
  490.     saveRng : function() {
  491.         this.savedRange = this.getRng();
  492.         this.savedSel = this.getSel();
  493.     },
  494.     
  495.     restoreRng : function() {
  496.         if(this.savedRange) {
  497.             this.selRng(this.savedRange,this.savedSel);
  498.         }
  499.     },
  500.     
  501.     keyDown : function(e,t) {
  502.         if(e.ctrlKey) {
  503.             this.ne.fireEvent('key',this,e);
  504.         }
  505.     },
  506.     
  507.     selected : function(e,t) {
  508.         if(!t) {t = this.selElm()}
  509.         if(!e.ctrlKey) {
  510.             var selInstance = this.ne.selectedInstance;
  511.             if(selInstance != this) {
  512.                 if(selInstance) {
  513.                     this.ne.fireEvent('blur',selInstance,t);
  514.                 }
  515.                 this.ne.selectedInstance = this;    
  516.                 this.ne.fireEvent('focus',selInstance,t);
  517.             }
  518.             this.ne.fireEvent('selected',selInstance,t);
  519.             this.isFocused = true;
  520.             this.elm.addClass('selected');
  521.         }
  522.         return false;
  523.     },
  524.     
  525.     blur : function() {
  526.         this.isFocused = false;
  527.         this.elm.removeClass('selected');
  528.     },
  529.     
  530.     saveContent : function() {
  531.         if(this.copyElm || this.options.hasPanel) {
  532.             this.ne.fireEvent('save',this);
  533.             (this.copyElm) ? this.copyElm.value = this.getContent() : this.e.innerHTML = this.getContent();
  534.         }   
  535.     },
  536.     
  537.     getElm : function() {
  538.         return this.elm;
  539.     },
  540.     
  541.     getContent : function() {
  542.         this.content = this.getElm().innerHTML;
  543.         this.ne.fireEvent('get',this);
  544.         return this.content;
  545.     },
  546.     
  547.     setContent : function(e) {
  548.         this.content = e;
  549.         this.ne.fireEvent('set',this);
  550.         this.elm.innerHTML = this.content;  
  551.     },
  552.     
  553.     nicCommand : function(cmd,args) {
  554.         document.execCommand(cmd,false,args);
  555.     }       
  556. });
  557. var nicEditorIFrameInstance = nicEditorInstance.extend({
  558.     savedStyles : [],
  559.     
  560.     init : function() { 
  561.         var c = this.elm.innerHTML.replace(/^/s+|/s+$/g, '');
  562.         this.elm.innerHTML = '';
  563.         (!c) ? c = "<br />" : c;
  564.         this.initialContent = c;
  565.         
  566.         this.elmFrame = new bkElement('iframe').setAttributes({'src' : 'javascript:;''frameBorder' : 0, 'allowTransparency' : 'true''scrolling' : 'no'}).setStyle({height: '100px', width: '100%'}).addClass('frame').appendTo(this.elm);
  567.         if(this.copyElm) { this.elmFrame.setStyle({width : (this.elm.offsetWidth-4)+'px'}); }
  568.         
  569.         var styleList = ['font-size','font-family','font-weight','color'];
  570.         for(itm in styleList) {
  571.             this.savedStyles[bkLib.camelize(itm)] = this.elm.getStyle(itm);
  572.         }
  573.         
  574.         setTimeout(this.initFrame.closure(this),50);
  575.     },
  576.     
  577.     disable : function() {
  578.         this.elm.innerHTML = this.getContent();
  579.     },
  580.     
  581.     initFrame : function() {
  582.         var fd = $BK(this.elmFrame.contentWindow.document);
  583.         fd.designMode = "on";       
  584.         fd.open();
  585.         var css = this.ne.options.externalCSS;
  586.         fd.write('<html><head>'+((css) ? '<link href="'+css+'" rel="stylesheet" type="text/css" />' : '')+'</head><body id="nicEditContent" style="margin: 0 !important; background-color: transparent !important;">'+this.initialContent+'</body></html>');
  587.         fd.close();
  588.         this.frameDoc = fd;
  589.         this.frameWin = $BK(this.elmFrame.contentWindow);
  590.         this.frameContent = $BK(this.frameWin.document.body).setStyle(this.savedStyles);
  591.         this.instanceDoc = this.frameWin.document.defaultView;
  592.         
  593.         this.heightUpdate();
  594.         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));
  595.         this.ne.fireEvent('add',this);
  596.     },
  597.     
  598.     getElm : function() {
  599.         return this.frameContent;
  600.     },
  601.     
  602.     setContent : function(c) {
  603.         this.content = c;
  604.         this.ne.fireEvent('set',this);
  605.         this.frameContent.innerHTML = this.content; 
  606.         this.heightUpdate();
  607.     },
  608.     
  609.     getSel : function() {
  610.         return (this.frameWin) ? this.frameWin.getSelection() : this.frameDoc.selection;
  611.     },
  612.     
  613.     heightUpdate : function() { 
  614.         this.elmFrame.style.height = Math.max(this.frameContent.offsetHeight,this.initialHeight)+'px';
  615.     },
  616.     
  617.     nicCommand : function(cmd,args) {
  618.         this.frameDoc.execCommand(cmd,false,args);
  619.         setTimeout(this.heightUpdate.closure(this),100);
  620.     }
  621.     
  622. });
  623. var nicEditorPanel = bkClass.extend({
  624.     construct : function(e,options,nicEditor) {
  625.         this.elm = e;
  626.         this.options = options;
  627.         this.ne = nicEditor;
  628.         this.panelButtons = new Array();
  629.         this.buttonList = bkExtend([],this.ne.options.buttonList);
  630.         
  631.         this.panelContain = new bkElement('DIV').setStyle({overflow : 'hidden', width : '100%', border : '1px solid #cccccc', backgroundColor : '#efefef'}).addClass('panelContain');
  632.         this.panelElm = new bkElement('DIV').setStyle({margin : '2px', marginTop : '0px', zoom : 1, overflow : 'hidden'}).addClass('panel').appendTo(this.panelContain);
  633.         this.panelContain.appendTo(e);
  634.         var opt = this.ne.options;
  635.         var buttons = opt.buttons;
  636.         for(button in buttons) {
  637.                 this.addButton(button,opt,true);
  638.         }
  639.         this.reorder();
  640.         e.noSelect();
  641.     },
  642.     
  643.     addButton : function(buttonName,options,noOrder) {
  644.         var button = options.buttons[buttonName];
  645.         var type = (button['type']) ? eval('(typeof('+button['type']+') == "undefined") ? null : '+button['type']+';') : nicEditorButton;
  646.         var hasButton = bkLib.inArray(this.buttonList,buttonName);
  647.         if(type && (hasButton || this.ne.options.fullPanel)) {
  648.             this.panelButtons.push(new type(this.panelElm,buttonName,options,this.ne));
  649.             if(!hasButton) {    
  650.                 this.buttonList.push(buttonName);
  651.             }
  652.         }
  653.     },
  654.     
  655.     findButton : function(itm) {
  656.         for(var i=0;i<this.panelButtons.length;i++) {
  657.             if(this.panelButtons[i].name == itm)
  658.                 return this.panelButtons[i];
  659.         }   
  660.     },
  661.     
  662.     reorder : function() {
  663.         var bl = this.buttonList;
  664.         for(var i=0;i<bl.length;i++) {
  665.             var button = this.findButton(bl[i]);
  666.             if(button) {
  667.                 this.panelElm.appendChild(button.margin);
  668.             }
  669.         }   
  670.     },
  671.     
  672.     remove : function() {
  673.         this.elm.remove();
  674.     }
  675. });
  676. var nicEditorButton = bkClass.extend({
  677.     
  678.     construct : function(e,buttonName,options,nicEditor) {
  679.         this.options = options.buttons[buttonName];
  680.         this.name = buttonName;
  681.         this.ne = nicEditor;
  682.         this.elm = e;
  683.         this.margin = new bkElement('DIV').setStyle({'float' : 'left', marginTop : '2px'}).appendTo(e);
  684.         this.contain = new bkElement('DIV').setStyle({width : '20px', height : '20px'}).addClass('buttonContain').appendTo(this.margin);
  685.         this.border = new bkElement('DIV').setStyle({backgroundColor : '#efefef', border : '1px solid #efefef'}).appendTo(this.contain);
  686.         this.button = new bkElement('DIV').setStyle({width : '18px', height : '18px', overflow : 'hidden', zoom : 1, cursor : 'pointer'}).addClass('button').setStyle(this.ne.getIcon(buttonName,options)).appendTo(this.border);
  687.         this.button.addEvent('mouseover'this.hoverOn.closure(this)).addEvent('mouseout',this.hoverOff.closure(this)).addEvent('mousedown',this.mouseClick.closure(this)).noSelect();
  688.         
  689.         if(!window.opera) {
  690.             this.button.onmousedown = this.button.onclick = bkLib.cancelEvent;
  691.         }
  692.         
  693.         nicEditor.addEvent('selected'this.enable.closure(this)).addEvent('blur'this.disable.closure(this)).addEvent('key',this.key.closure(this));
  694.         
  695.         this.disable();
  696.         this.init();
  697.     },
  698.     
  699.     init : function() {  },
  700.     
  701.     hide : function() {
  702.         this.contain.setStyle({display : 'none'});
  703.     },
  704.     
  705.     updateState : function() {
  706.         if(this.isDisabled) { this.setBg(); }
  707.         else if(this.isHover) { this.setBg('hover'); }
  708.         else if(this.isActive) { this.setBg('active'); }
  709.         else { this.setBg(); }
  710.     },
  711.     
  712.     setBg : function(state) {
  713.         switch(state) {
  714.             case 'hover':
  715.                 var stateStyle = {border : '1px solid #666', backgroundColor : '#ddd'};
  716.                 break;
  717.             case 'active':
  718.                 var stateStyle = {border : '1px solid #666', backgroundColor : '#ccc'};
  719.                 break;
  720.             default:
  721.                 var stateStyle = {border : '1px solid #efefef', backgroundColor : '#efefef'};   
  722.         }
  723.         this.border.setStyle(stateStyle).addClass('button-'+state);
  724.     },
  725.     
  726.     checkNodes : function(e) {
  727.         var elm = e;    
  728.         do {
  729.             if(this.options.tags && bkLib.inArray(this.options.tags,elm.nodeName)) {
  730.                 this.activate();
  731.                 return true;
  732.             }
  733.         } while(elm = elm.parentNode && elm.className != "nicEdit");
  734.         elm = $BK(e);
  735.         while(elm.nodeType == 3) {
  736.             elm = $BK(elm.parentNode);
  737.         }
  738.         if(this.options.css) {
  739.             for(itm in this.options.css) {
  740.                 if(elm.getStyle(itm,this.ne.selectedInstance.instanceDoc) == this.options.css[itm]) {
  741.                     this.activate();
  742.                     return true;
  743.                 }
  744.             }
  745.         }
  746.         this.deactivate();
  747.         return false;
  748.     },
  749.     
  750.     activate : function() {
  751.         if(!this.isDisabled) {
  752.             this.isActive = true;
  753.             this.updateState(); 
  754.             this.ne.fireEvent('buttonActivate',this);
  755.         }
  756.     },
  757.     
  758.     deactivate : function() {
  759.         this.isActive = false;
  760.         this.updateState(); 
  761.         if(!this.isDisabled) {
  762.             this.ne.fireEvent('buttonDeactivate',this);
  763.         }
  764.     },
  765.     
  766.     enable : function(ins,t) {
  767.         this.isDisabled = false;
  768.         this.contain.setStyle({'opacity' : 1}).addClass('buttonEnabled');
  769.         this.updateState();
  770.         this.checkNodes(t);
  771.     },
  772.     
  773.     disable : function(ins,t) {     
  774.         this.isDisabled = true;
  775.         this.contain.setStyle({'opacity' : 0.6}).removeClass('buttonEnabled');
  776.         this.updateState(); 
  777.     },
  778.     
  779.     toggleActive : function() {
  780.         (this.isActive) ? this.deactivate() : this.activate();  
  781.     },
  782.     
  783.     hoverOn : function() {
  784.         if(!this.isDisabled) {
  785.             this.isHover = true;
  786.             this.updateState();
  787.             this.ne.fireEvent("buttonOver",this);
  788.         }
  789.     }, 
  790.     
  791.     hoverOff : function() {
  792.         this.isHover = false;
  793.         this.updateState();
  794.         this.ne.fireEvent("buttonOut",this);
  795.     },
  796.     
  797.     mouseClick : function() {
  798.         if(this.options.command) {
  799.             this.ne.nicCommand(this.options.command,this.options.commandArgs);
  800.             if(!this.options.noActive) {
  801.                 this.toggleActive();
  802.             }
  803.         }
  804.         this.ne.fireEvent("buttonClick",this);
  805.     },
  806.     
  807.     key : function(nicInstance,e) {
  808.         if(this.options.key && e.ctrlKey && String.fromCharCode(e.keyCode || e.charCode).toLowerCase() == this.options.key) {
  809.             this.mouseClick();
  810.             if(e.preventDefault) e.preventDefault();
  811.         }
  812.     }
  813.     
  814. });
  815.  
  816. var nicPlugin = bkClass.extend({
  817.     
  818.     construct : function(nicEditor,options) {
  819.         this.options = options;
  820.         this.ne = nicEditor;
  821.         this.ne.addEvent('panel',this.loadPanel.closure(this));
  822.         
  823.         this.init();
  824.     },
  825.     loadPanel : function(np) {
  826.         var buttons = this.options.buttons;
  827.         for(var button in buttons) {
  828.             np.addButton(button,this.options);
  829.         }
  830.         np.reorder();
  831.     },
  832.     init : function() {  }
  833. });
  834.  
  835.  /* START CONFIG */
  836. var nicPaneOptions = { };
  837. /* END CONFIG */
  838. var nicEditorPane = bkClass.extend({
  839.     construct : function(elm,nicEditor,options,openButton) {
  840.         this.ne = nicEditor;
  841.         this.elm = elm;
  842.         this.pos = elm.pos();
  843.         
  844.         this.contain = new bkElement('div').setStyle({zIndex : '99999', overflow : 'hidden', position : 'absolute', left : this.pos[0]+'px', top : this.pos[1]+'px'})
  845.         this.pane = new bkElement('div').setStyle({fontSize : '12px', border : '1px solid #ccc''overflow''hidden', padding : '4px', textAlign: 'left', backgroundColor : '#ffffc9'}).addClass('pane').setStyle(options).appendTo(this.contain);
  846.         
  847.         if(openButton && !openButton.options.noClose) {
  848.             this.close = new bkElement('div').setStyle({'float' : 'right', height: '16px', width : '16px', cursor : 'pointer'}).setStyle(this.ne.getIcon('close',nicPaneOptions)).addEvent('mousedown',openButton.removePane.closure(this)).appendTo(this.pane);
  849.         }
  850.         
  851.         this.contain.noSelect().appendTo(document.body);
  852.         
  853.         this.position();
  854.         this.init();    
  855.     },
  856.     
  857.     init : function() { },
  858.     
  859.     position : function() {
  860.         if(this.ne.nicPanel) {
  861.             var panelElm = this.ne.nicPanel.elm;    
  862.             var panelPos = panelElm.pos();
  863.             var newLeft = panelPos[0]+parseInt(panelElm.getStyle('width'))-(parseInt(this.pane.getStyle('width'))+8);
  864.             if(newLeft < this.pos[0]) {
  865.                 this.contain.setStyle({left : newLeft+'px'});
  866.             }
  867.         }
  868.     },
  869.     
  870.     toggle : function() {
  871.         this.isVisible = !this.isVisible;
  872.         this.contain.setStyle({display : ((this.isVisible) ? 'block' : 'none')});
  873.     },
  874.     
  875.     remove : function() {
  876.         if(this.contain) {
  877.             this.contain.remove();
  878.             this.contain = null;
  879.         }
  880.     },
  881.     
  882.     append : function(c) {
  883.         c.appendTo(this.pane);
  884.     },
  885.     
  886.     setContent : function(c) {
  887.         this.pane.setContent(c);
  888.     }
  889.     
  890. });
  891.  
  892. var nicEditorAdvancedButton = nicEditorButton.extend({
  893.     
  894.     init : function() {
  895.         this.ne.addEvent('selected',this.removePane.closure(this)).addEvent('blur',this.removePane.closure(this));  
  896.     },
  897.     
  898.     mouseClick : function() {
  899.         if(!this.isDisabled) {
  900.             if(this.pane && this.pane.pane) {
  901.                 this.removePane();
  902.             } else {
  903.                 this.pane = new nicEditorPane(this.contain,this.ne,{width : (this.width || '270px'), backgroundColor : '#fff'},this);
  904.                 this.addPane();
  905.                 this.ne.selectedInstance.saveRng();
  906.             }
  907.         }
  908.     },
  909.     
  910.     addForm : function(f,elm) {
  911.         this.form = new bkElement('form').addEvent('submit',this.submit.closureListener(this));
  912.         this.pane.append(this.form);
  913.         this.inputs = {};
  914.         
  915.         for(itm in f) {
  916.             var field = f[itm];
  917.             var val = '';
  918.             if(elm) {
  919.                 val = elm.getAttribute(itm);
  920.             }
  921.             if(!val) {
  922.                 val = field['value'] || '';
  923.             }
  924.             var type = f[itm].type;
  925.             
  926.             if(type == 'title') {
  927.                     new bkElement('div').setContent(field.txt).setStyle({fontSize : '14px', fontWeight: 'bold', padding : '0px', margin : '2px 0'}).appendTo(this.form);
  928.             } else {
  929.                 var contain = new bkElement('div').setStyle({overflow : 'hidden', clear : 'both'}).appendTo(this.form);
  930.                 if(field.txt) {
  931.                     new bkElement('label').setAttributes({'for' : itm}).setContent(field.txt).setStyle({margin : '2px 4px', fontSize : '13px', width: '50px', lineHeight : '20px', textAlign : 'right''float' : 'left'}).appendTo(contain);
  932.                 }
  933.                 
  934.                 switch(type) {
  935.                     case 'text':
  936.                         this.inputs[itm] = new bkElement('input').setAttributes({id : itm, 'value' : val, 'type' : 'text'}).setStyle({margin : '2px 0', fontSize : '13px''float' : 'left', height : '20px', border : '1px solid #ccc', overflow : 'hidden'}).setStyle(field.style).appendTo(contain);
  937.                         break;
  938.                     case 'select':
  939.                         this.inputs[itm] = new bkElement('select').setAttributes({id : itm}).setStyle({border : '1px solid #ccc''float' : 'left', margin : '2px 0'}).appendTo(contain);
  940.                         for(opt in field.options) {
  941.                             var o = new bkElement('option').setAttributes({value : opt, selected : (opt == val) ? 'selected' : ''}).setContent(field.options[opt]).appendTo(this.inputs[itm]);
  942.                         }
  943.                         break;
  944.                     case 'content':
  945.                         this.inputs[itm] = new bkElement('textarea').setAttributes({id : itm}).setStyle({border : '1px solid #ccc''float' : 'left'}).setStyle(field.style).appendTo(contain);
  946.                         this.inputs[itm].value = val;
  947.                 }   
  948.             }
  949.         }
  950.         new bkElement('input').setAttributes({'type' : 'submit'}).setStyle({backgroundColor : '#efefef',border : '1px solid #ccc', margin : '3px 0''float' : 'left''clear' : 'both'}).appendTo(this.form);
  951.         this.form.onsubmit = bkLib.cancelEvent; 
  952.     },
  953.     
  954.     submit : function() { },
  955.     
  956.     findElm : function(tag,attr,val) {
  957.         var list = this.ne.selectedInstance.getElm().getElementsByTagName(tag);
  958.         for(var i=0;i<list.length;i++) {
  959.             if(list[i].getAttribute(attr) == val) {
  960.                 return $BK(list[i]);
  961.             }
  962.         }
  963.     },
  964.     
  965.     removePane : function() {
  966.         if(this.pane) {
  967.             this.pane.remove();
  968.             this.pane = null;
  969.             this.ne.selectedInstance.restoreRng();
  970.         }   
  971.     }   
  972. });
  973. var nicButtonTips = bkClass.extend({
  974.     construct : function(nicEditor) {
  975.         this.ne = nicEditor;
  976.         nicEditor.addEvent('buttonOver',this.show.closure(this)).addEvent('buttonOut',this.hide.closure(this));
  977.     },
  978.     
  979.     show : function(button) {
  980.         this.timer = setTimeout(this.create.closure(this,button),400);
  981.     },
  982.     
  983.     create : function(button) {
  984.         this.timer = null;
  985.         if(!this.pane) {
  986.             this.pane = new nicEditorPane(button.button,this.ne,{fontSize : '12px', marginTop : '5px'});
  987.             this.pane.setContent(button.options.name);
  988.         }       
  989.     },
  990.     
  991.     hide : function(button) {
  992.         if(this.timer) {
  993.             clearTimeout(this.timer);
  994.         }
  995.         if(this.pane) {
  996.             this.pane = this.pane.remove();
  997.         }
  998.     }
  999. });
  1000. nicEditors.registerPlugin(nicButtonTips);
  1001.  
  1002.  /* START CONFIG */
  1003. var nicSelectOptions = {
  1004.     buttons : {
  1005.         'fontSize' : {name : __('Select Font Size'), type : 'nicEditorFontSizeSelect', command : 'fontsize'},
  1006.         'fontFamily' : {name : __('Select Font Family'), type : 'nicEditorFontFamilySelect', command : 'fontname'},
  1007.         'fontFormat' : {name : __('Select Font Format'), type : 'nicEditorFontFormatSelect', command : 'formatBlock'}
  1008.     }
  1009. };
  1010. /* END CONFIG */
  1011. var nicEditorSelect = bkClass.extend({
  1012.     
  1013.     construct : function(e,buttonName,options,nicEditor) {
  1014.         this.options = options.buttons[buttonName];
  1015.         this.elm = e;
  1016.         this.ne = nicEditor;
  1017.         this.name = buttonName;
  1018.         this.selOptions = new Array();
  1019.         
  1020.         this.margin = new bkElement('div').setStyle({'float' : 'left', margin : '2px 1px 0 1px'}).appendTo(this.elm);
  1021.         this.contain = new bkElement('div').setStyle({width: '90px', height : '20px', cursor : 'pointer', overflow: 'hidden'}).addClass('selectContain').addEvent('click',this.toggle.closure(this)).appendTo(this.margin);
  1022.         this.items = new bkElement('div').setStyle({overflow : 'hidden', zoom : 1, border: '1px solid #ccc', paddingLeft : '3px', backgroundColor : '#fff'}).appendTo(this.contain);
  1023.         this.control = new bkElement('div').setStyle({overflow : 'hidden''float' : 'right', height: '18px', width : '16px'}).addClass('selectControl').setStyle(this.ne.getIcon('arrow',options)).appendTo(this.items);
  1024.         this.txt = new bkElement('div').setStyle({overflow : 'hidden''float' : 'left', width : '66px', height : '14px', marginTop : '1px', fontFamily : 'sans-serif', textAlign : 'center', fontSize : '12px'}).addClass('selectTxt').appendTo(this.items);
  1025.         
  1026.         if(!window.opera) {
  1027.             this.contain.onmousedown = this.control.onmousedown = this.txt.onmousedown = bkLib.cancelEvent;
  1028.         }
  1029.         
  1030.         this.margin.noSelect();
  1031.         
  1032.         this.ne.addEvent('selected'this.enable.closure(this)).addEvent('blur'this.disable.closure(this));
  1033.         
  1034.         this.disable();
  1035.         this.init();
  1036.     },
  1037.     
  1038.     disable : function() {
  1039.         this.isDisabled = true;
  1040.         this.close();
  1041.         this.contain.setStyle({opacity : 0.6});
  1042.     },
  1043.     
  1044.     enable : function(t) {
  1045.         this.isDisabled = false;
  1046.         this.close();
  1047.         this.contain.setStyle({opacity : 1});
  1048.     },
  1049.     
  1050.     setDisplay : function(txt) {
  1051.         this.txt.setContent(txt);
  1052.     },
  1053.     
  1054.     toggle : function() {
  1055.         if(!this.isDisabled) {
  1056.             (this.pane) ? this.close() : this.open();
  1057.         }
  1058.     },
  1059.     
  1060.     open : function() {
  1061.         this.pane = new nicEditorPane(this.items,this.ne,{width : '88px', padding: '0px', borderTop : 0, borderLeft : '1px solid #ccc', borderRight : '1px solid #ccc', borderBottom : '0px', backgroundColor : '#fff'});
  1062.         
  1063.         for(var i=0;i<this.selOptions.length;i++) {
  1064.             var opt = this.selOptions[i];
  1065.             var itmContain = new bkElement('div').setStyle({overflow : 'hidden', borderBottom : '1px solid #ccc', width: '88px', textAlign : 'left', overflow : 'hidden', cursor : 'pointer'});
  1066.             var itm = new bkElement('div').setStyle({padding : '0px 4px'}).setContent(opt[1]).appendTo(itmContain).noSelect();
  1067.             itm.addEvent('click',this.update.closure(this,opt[0])).addEvent('mouseover',this.over.closure(this,itm)).addEvent('mouseout',this.out.closure(this,itm)).setAttributes('id',opt[0]);
  1068.             this.pane.append(itmContain);
  1069.             if(!window.opera) {
  1070.                 itm.onmousedown = bkLib.cancelEvent;
  1071.             }
  1072.         }
  1073.     },
  1074.     
  1075.     close : function() {
  1076.         if(this.pane) {
  1077.             this.pane = this.pane.remove();
  1078.         }   
  1079.     },
  1080.     
  1081.     over : function(opt) {
  1082.         opt.setStyle({backgroundColor : '#ccc'});           
  1083.     },
  1084.     
  1085.     out : function(opt) {
  1086.         opt.setStyle({backgroundColor : '#fff'});
  1087.     },
  1088.     
  1089.     
  1090.     add : function(k,v) {
  1091.         this.selOptions.push(new Array(k,v));   
  1092.     },
  1093.     
  1094.     update : function(elm) {
  1095.         this.ne.nicCommand(this.options.command,elm);
  1096.         this.close();   
  1097.     }
  1098. });
  1099. var nicEditorFontSizeSelect = nicEditorSelect.extend({
  1100.     sel : {1 : '1 (8pt)', 2 : '2 (10pt)', 3 : '3 (12pt)', 4 : '4 (14pt)', 5 : '5 (18pt)', 6 : '6 (24pt)'},
  1101.     init : function() {
  1102.         this.setDisplay('Font Size...');
  1103.         for(itm in this.sel) {
  1104.             this.add(itm,'<font size="'+itm+'">'+this.sel[itm]+'</font>');
  1105.         }       
  1106.     }
  1107. });
  1108. var nicEditorFontFamilySelect = nicEditorSelect.extend({
  1109.     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'},
  1110.     
  1111.     init : function() {
  1112.         this.setDisplay('Font Family...');
  1113.         for(itm in this.sel) {
  1114.             this.add(itm,'<font face="'+itm+'">'+this.sel[itm]+'</font>');
  1115.         }
  1116.     }
  1117. });
  1118. var nicEditorFontFormatSelect = nicEditorSelect.extend({
  1119.         sel : {'p' : 'Paragraph''pre' : 'Pre''h6' : 'Heading 6''h5' : 'Heading 5''h4' : 'Heading 4''h3' : 'Heading 3''h2' : 'Heading 2''h1' : 'Heading 1'},
  1120.         
  1121.     init : function() {
  1122.         this.setDisplay('Font Format...');
  1123.         for(itm in this.sel) {
  1124.             var tag = itm.toUpperCase();
  1125.             this.add('<'+tag+'>','<'+itm+' style="padding: 0px; margin: 0px;">'+this.sel[itm]+'</'+tag+'>');
  1126.         }
  1127.     }
  1128. });
  1129. nicEditors.registerPlugin(nicPlugin,nicSelectOptions);
  1130. /* START CONFIG */
  1131. var nicLinkOptions = {
  1132.     buttons : {
  1133.         'link' : {name : 'Add Link', type : 'nicLinkButton', tags : ['A']},
  1134.         'unlink' : {name : 'Remove Link',  command : 'unlink', noActive : true}
  1135.     }
  1136. };
  1137. /* END CONFIG */
  1138. var nicLinkButton = nicEditorAdvancedButton.extend({    
  1139.     addPane : function() {
  1140.         this.ln = this.ne.selectedInstance.selElm().parentTag('A');
  1141.         this.addForm({
  1142.             '' : {type : 'title', txt : 'Add/Edit Link'},
  1143.             'href' : {type : 'text', txt : 'URL', value : 'http://', style : {width: '150px'}},
  1144.             'title' : {type : 'text', txt : 'Title'},
  1145.             'target' : {type : 'select', txt : 'Open In', options : {'' : 'Current Window''_blank' : 'New Window'},style : {width : '100px'}}
  1146.         },this.ln);
  1147.     },
  1148.     
  1149.     submit : function(e) {
  1150.         var url = this.inputs['href'].value;
  1151.         if(url == "http://" || url == "") {
  1152.             alert("You must enter a URL to Create a Link");
  1153.             return false;
  1154.         }
  1155.         this.removePane();
  1156.         
  1157.         if(!this.ln) {
  1158.             var tmp = 'javascript:nicTemp();';
  1159.             this.ne.nicCommand("createlink",tmp);
  1160.             this.ln = this.findElm('A','href',tmp);
  1161.         }
  1162.         if(this.ln) {
  1163.             this.ln.setAttributes({
  1164.                 href : this.inputs['href'].value,
  1165.                 title : this.inputs['title'].value,
  1166.                 target : this.inputs['target'].options[this.inputs['target'].selectedIndex].value
  1167.             });
  1168.         }
  1169.     }
  1170. });
  1171. nicEditors.registerPlugin(nicPlugin,nicLinkOptions);
  1172. /* START CONFIG */
  1173. var nicImageOptions = {
  1174.     buttons : {
  1175.         'image' : {name : 'Add Image', type : 'nicImageButton', tags : ['IMG']}
  1176.     }
  1177.     
  1178. };
  1179. /* END CONFIG */
  1180. var nicImageButton = nicEditorAdvancedButton.extend({   
  1181.     addPane : function() {
  1182.         this.im = this.ne.selectedInstance.selElm().parentTag('IMG');
  1183.         this.addForm({
  1184.             '' : {type : 'title', txt : 'Add/Edit Image'},
  1185.             'src' : {type : 'text', txt : 'URL''value' : 'http://', style : {width: '150px'}},
  1186.             'alt' : {type : 'text', txt : 'Alt Text', style : {width: '100px'}},
  1187.             'align' : {type : 'select', txt : 'Align', options : {none : 'Default','left' : 'Left''right' : 'Right'}}
  1188.         },this.im);
  1189.     },
  1190.     
  1191.     submit : function(e) {
  1192.         var src = this.inputs['src'].value;
  1193.         if(src == "" || src == "http://") {
  1194.             alert("You must enter a Image URL to insert");
  1195.             return false;
  1196.         }
  1197.         this.removePane();
  1198.         if(!this.im) {
  1199.             var tmp = 'javascript:nicImTemp();';
  1200.             this.ne.nicCommand("insertImage",tmp);
  1201.             this.im = this.findElm('IMG','src',tmp);
  1202.         }
  1203.         if(this.im) {
  1204.             this.im.setAttributes({
  1205.                 src : this.inputs['src'].value,
  1206.                 alt : this.inputs['alt'].value,
  1207.                 align : this.inputs['align'].value
  1208.             });
  1209.         }
  1210.     }
  1211. });
  1212. nicEditors.registerPlugin(nicPlugin,nicImageOptions);
  1213. /* START CONFIG */
  1214. var nicSaveOptions = {
  1215.     buttons : {
  1216.         'save' : {name : __('Save this content'), type : 'nicEditorSaveButton'}
  1217.     }
  1218. };
  1219. /* END CONFIG */
  1220. var nicEditorSaveButton = nicEditorButton.extend({
  1221.     init : function() {
  1222.         if(!this.ne.options.onSave) {
  1223.             this.margin.setStyle({'display' : 'none'});
  1224.         }
  1225.     },
  1226.     mouseClick : function() {
  1227.         var onSave = this.ne.options.onSave;
  1228.         var selectedInstance = this.ne.selectedInstance;
  1229.         onSave(selectedInstance.getContent(), selectedInstance.elm.id, selectedInstance);
  1230.     }
  1231. });
  1232. nicEditors.registerPlugin(nicPlugin,nicSaveOptions);
  1233. /* START CONFIG */
  1234. var nicUploadOptions = {
  1235.     buttons : {
  1236.         'upload' : {name : 'Upload Image', type : 'nicUploadButton'}
  1237.     }
  1238.     
  1239. };
  1240. /* END CONFIG */
  1241. var nicUploadButton = nicEditorAdvancedButton.extend({  
  1242.     serverURI : 'http://files.nicedit.com/',
  1243.     addPane : function() {
  1244.         this.im = this.ne.selectedInstance.selElm().parentTag('IMG');
  1245.         this.myID = Math.round(Math.random()*Math.pow(10,15));
  1246.         this.requestInterval = 1000;
  1247.         this.myFrame = new bkElement('iframe').setAttributes({ width : '100%', height : '100px', frameBorder : 0, scrolling : 'no' }).setStyle({border : 0}).appendTo(this.pane.pane);
  1248.         this.progressWrapper = new bkElement('div').setStyle({display: 'none', width: '100%', height: '20px', border : '1px solid #ccc'}).appendTo(this.pane.pane);
  1249.         this.progress = new bkElement('div').setStyle({width: '0%', height: '20px', backgroundColor : '#ccc'}).setContent(' ').appendTo(this.progressWrapper);
  1250.         setTimeout(this.addForm.closure(this),50);
  1251.     },
  1252.     addForm : function() {
  1253.         var myDoc = this.myDoc = this.myFrame.contentWindow.document;
  1254.         myDoc.open();
  1255.         myDoc.write("<html><body>");
  1256.         myDoc.write('<form method="post" action="'+this.serverURI+'?id='+this.myID+'" enctype="multipart/form-data">');
  1257.         myDoc.write('<input type="hidden" name="APC_UPLOAD_PROGRESS" value="'+this.myID+'" />');
  1258.         myDoc.write('<div style="position: absolute; margin-left: 160px;"><img src="http://imageshack.us/img/imageshack.png" width="30" style="float: left;" /><div style="float: left; margin-left: 5px; font-size: 10px;">Hosted by<br /><a href="http://www.imageshack.us/" target="_blank">ImageShack</a></div></div>');
  1259.         myDoc.write('<div style="font-size: 14px; font-weight: bold; padding-top: 5px;">Insert an Image</div>');
  1260.         myDoc.write('<input name="nicImage" type="file" style="margin-top: 10px;" />');
  1261.         myDoc.write('</form>');
  1262.         myDoc.write("</body></html>");
  1263.         myDoc.close();
  1264.         this.myBody = myDoc.body;
  1265.         this.myForm = $BK(this.myBody.getElementsByTagName('form')[0]);
  1266.         this.myInput = $BK(this.myBody.getElementsByTagName('input')[1]).addEvent('change'this.startUpload.closure(this));
  1267.         this.myStatus = new bkElement('div',this.myDoc).setStyle({textAlign : 'center', fontSize : '14px'}).appendTo(this.myBody);
  1268.   },
  1269.     startUpload : function() {
  1270.         this.myForm.setStyle({display : 'none'});
  1271.         this.myStatus.setContent('<img src="http://files.nicedit.com/ajax-loader.gif" style="float: right; margin-right: 40px;" /><strong>Uploading...</strong><br />Please wait');
  1272.         this.setProgress(10);
  1273.         this.myForm.submit();
  1274.         setTimeout(this.makeRequest.closure(this),this.requestInterval);
  1275.     },
  1276.     makeRequest : function() {
  1277.         if(this.pane && this.pane.pane) {
  1278.             nicUploadButton.lastPlugin = this;
  1279.             var s = new bkElement('script').setAttributes({ type : 'text/javascript', src : this.serverURI+'?check='+this.myID+'&rand='+Math.round(Math.random()*Math.pow(10,15))}).addEvent('load'function() {
  1280.                 s.parentNode.removeChild(s);
  1281.             }).appendTo(document.getElementsByTagName('head')[0]);
  1282.             if(this.requestInterval) {
  1283.                 setTimeout(this.makeRequest.closure(this), this.requestInterval);
  1284.             }
  1285.         }
  1286.     },
  1287.     setProgress : function(percent) {
  1288.         this.progressWrapper.setStyle({display: 'block'});
  1289.         this.progress.setStyle({width : percent+'%'});
  1290.     },
  1291.     update : function(o) {
  1292.         if(!this.requestInterval) return;
  1293.         if(o == false) {
  1294.             this.progressWrapper.setStyle({display : 'none'});
  1295.         } else if(o.url) {
  1296.             this.setProgress(100);
  1297.             this.requestInterval = false;
  1298.             if(!this.im) {
  1299.                 this.ne.selectedInstance.restoreRng();
  1300.                 var tmp = 'javascript:nicImTemp();';
  1301.                 this.ne.nicCommand("insertImage",tmp);
  1302.                 this.im = this.findElm('IMG','src',tmp);
  1303.             }
  1304.             var w = parseInt(this.ne.selectedInstance.elm.getStyle('width'));
  1305.             if(this.im) {
  1306.                 this.im.setAttributes({
  1307.                     src : o.url,
  1308.                     width : (w && o.width) ? Math.min(w,o.width) : ''
  1309.                 });
  1310.             }
  1311.             this.removePane();
  1312.         } else if(o.error) {
  1313.             this.requestInterval = false;
  1314.             this.setProgress(100);
  1315.             alert("There was an error uploading your image ("+o.error+").");
  1316.             this.removePane();
  1317.         } else {
  1318.             this.setProgress( Math.round( (o.current/o.total) * 75) );
  1319.             if(o.interval) {
  1320.                 this.requestInterval = o.interval;
  1321.             }
  1322.         }
  1323.     }
  1324. });
  1325. nicUploadButton.statusCb = function(o) {
  1326.     nicUploadButton.lastPlugin.update(o);
  1327. }
  1328. nicEditors.registerPlugin(nicPlugin,nicUploadOptions);
  1329. /* START CONFIG */
  1330. var smileOptions = {
  1331.     buttons : {
  1332.         'smile' : {name : 'Add Smile', type : 'nicEditorSmileButton', noClose : true,tags : ['Sm']}
  1333.     }
  1334. };
  1335. /* END CONFIG */
  1336. var nicEditorSmileButton = nicEditorAdvancedButton.extend({ 
  1337.     addPane : function() {
  1338.             var smileList = [1,2,3,4,5,6,7,8,9];
  1339.             var smileItems = new bkElement('DIV').setStyle({width: '270px'});                   
  1340.             for(var g in smileList) {
  1341.                 var smileSrc = '../smile/'+smileList[g]+'.gif';
  1342.                 var smileImg = '<img src='+smileSrc+' />';
  1343.                 var smileSquare = new bkElement('DIV').setStyle({'cursor' : 'pointer''height' : '17px''width' : '17px''float' : 'left'}).appendTo(smileItems);
  1344.                 var smileBorder = new bkElement('DIV').appendTo(smileSquare);
  1345.                 var smileInner = new bkElement('DIV').setStyle({overflow : 'hidden', width : '17px', height : '17px'}).addEvent('click',this.smileSelect.closure(this,smileSrc)).addEvent('mouseover',this.on.closure(this,smileBorder)).addEvent('mouseout',this.off.closure(this,smileBorder)).appendTo(smileBorder);
  1346.                 smileInner.innerHTML = smileImg;
  1347.                 if(!window.opera) {
  1348.                     smileSquare.onmousedown = smileInner.onmousedown = bkLib.cancelEvent;
  1349.                 }
  1350.             }   
  1351.             this.pane.append(smileItems.noSelect());    
  1352.     },
  1353.     
  1354.     smileSelect : function(smileSrc) {
  1355.         this.ne.nicCommand('insertImage',smileSrc);
  1356.         this.removePane();
  1357.     },
  1358.     
  1359.     on : function(smileBorder) {
  1360.         smileBorder.setStyle({border : '1px solid #000'});
  1361.     },
  1362.     
  1363.     off : function(smileBorder) {
  1364.         smileBorder.setStyle({border : 'none'});        
  1365.     }
  1366. });
  1367. nicEditors.registerPlugin(nicPlugin,smileOptions);










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值