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 : __('粗体'), command : 'Bold', tags : ['B','STRONG'], css : {'font-weight' : 'bold'}, key : 'b'},
  245.         'italic' : {name : __('斜体'), command : 'Italic', tags : ['EM','I'], css : {'font-style' : 'italic'}, key : 'i'},
  246.         'underline' : {name : __('下划线'), command : 'Underline', tags : ['U'], css : {'text-decoration' : 'underline'}, key : 'u'},
  247.         'left' : {name : __('左对齐'), command : 'justifyleft', noActive : true},
  248.         'center' : {name : __('居中对齐'), command : 'justifycenter', noActive : true},
  249.         'right' : {name : __('右对齐'), command : 'justifyright', noActive : true},
  250.         'justify' : {name : __('两端对齐'), command : 'justifyfull', noActive : true},
  251.         'ol' : {name : __('有序列表'), command : 'insertorderedlist', tags : ['OL']},
  252.         'ul' :  {name : __('无序列表'), command : 'insertunorderedlist', tags : ['UL']},
  253.         'subscript' : {name : __('下标'), command : 'subscript', tags : ['SUB']},
  254.         'superscript' : {name : __('上标'), command : 'superscript', tags : ['SUP']},
  255.         'strikethrough' : {name : __('删除线'), command : 'strikeThrough', css : {'text-decoration' : 'line-through'}},
  256.         'removeformat' : {name : __('取消'), command : 'removeformat', noActive : true},
  257.         'indent' : {name : __('增加缩进'), command : 'indent', noActive : true},
  258.         'outdent' : {name : __('减少缩进'), command : 'outdent', noActive : true},
  259.         'hr' : {name : __('水平线'), command : 'insertHorizontalRule', noActive : true}
  260.     },
  261.     iconsPath : '../nicEditorIcons.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 : {"xhtml":1,"bgcolor":2,"forecolor":3,"bold":4,"center":5,"hr":6,"indent":7,"italic":8,"justify":9,"left":10,"ol":11,"outdent":12,"removeformat":13,"right":14,"save":25,"strikethrough":16,"subscript":17,"superscript":18,"ul":19,"underline":20,"image":21,"link":22,"unlink":23,"close":24,"arrow":26,"upload":27,'smile':28}
  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) { 
  568.             this.elmFrame.setStyle({width : (this.elm.offsetWidth-4)+'px'}); 
  569.         }
  570.         
  571.         var styleList = ['font-size','font-family','font-weight','color'];
  572.         for(itm in styleList) {
  573.             this.savedStyles[bkLib.camelize(itm)] = this.elm.getStyle(itm);
  574.         }
  575.         
  576.         setTimeout(this.initFrame.closure(this),50);
  577.     },
  578.     
  579.     disable : function() {
  580.         this.elm.innerHTML = this.getContent();
  581.     },
  582.     
  583.     initFrame : function() {
  584.         var fd = $BK(this.elmFrame.contentWindow.document);
  585.         fd.designMode = "on";       
  586.         fd.open();
  587.         var css = this.ne.options.externalCSS;
  588.         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>');
  589.         fd.close();
  590.         this.frameDoc = fd;
  591.         this.frameWin = $BK(this.elmFrame.contentWindow);
  592.         this.frameContent = $BK(this.frameWin.document.body).setStyle(this.savedStyles);
  593.         this.instanceDoc = this.frameWin.document.defaultView;
  594.         
  595.         this.heightUpdate();
  596.         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));
  597.         this.ne.fireEvent('add',this);
  598.     },
  599.     
  600.     getElm : function() {
  601.         return this.frameContent;
  602.     },
  603.     
  604.     setContent : function(c) {
  605.         this.content = c;
  606.         this.ne.fireEvent('set',this);
  607.         this.frameContent.innerHTML = this.content; 
  608.         this.heightUpdate();
  609.     },
  610.     
  611.     getSel : function() {
  612.         return (this.frameWin) ? this.frameWin.getSelection() : this.frameDoc.selection;
  613.     },
  614.     
  615.     heightUpdate : function() { 
  616.         this.elmFrame.style.height = Math.max(this.frameContent.offsetHeight,this.initialHeight)+'px';
  617.     },
  618.     
  619.     nicCommand : function(cmd,args) {
  620.         this.frameDoc.execCommand(cmd,false,args);
  621.         setTimeout(this.heightUpdate.closure(this),100);
  622.     }
  623.     
  624. });
  625. var nicEditorPanel = bkClass.extend({
  626.     construct : function(e,options,nicEditor) {
  627.         this.elm = e;
  628.         this.options = options;
  629.         this.ne = nicEditor;
  630.         this.panelButtons = new Array();
  631.         this.buttonList = bkExtend([],this.ne.options.buttonList);
  632.         
  633.         this.panelContain = new bkElement('DIV').setStyle({overflow : 'hidden', width : '100%', border : '1px solid #cccccc', backgroundColor : '#efefef'}).addClass('panelContain');
  634.         this.panelElm = new bkElement('DIV').setStyle({margin : '2px', marginTop : '0px', zoom : 1, overflow : 'hidden'}).addClass('panel').appendTo(this.panelContain);
  635.         this.panelContain.appendTo(e);
  636.         var opt = this.ne.options;
  637.         var buttons = opt.buttons;
  638.         for(button in buttons) {
  639.                 this.addButton(button,opt,true);
  640.         }
  641.         this.reorder();
  642.         e.noSelect();
  643.     },
  644.     
  645.     addButton : function(buttonName,options,noOrder) {
  646.         var button = options.buttons[buttonName];
  647.         var type = (button['type']) ? eval('(typeof('+button['type']+') == "undefined") ? null : '+button['type']+';') : nicEditorButton;
  648.         var hasButton = bkLib.inArray(this.buttonList,buttonName);
  649.         if(type && (hasButton || this.ne.options.fullPanel)) {
  650.             this.panelButtons.push(new type(this.panelElm,buttonName,options,this.ne));
  651.             if(!hasButton) {    
  652.                 this.buttonList.push(buttonName);
  653.             }
  654.         }
  655.     },
  656.     
  657.     findButton : function(itm) {
  658.         for(var i=0;i<this.panelButtons.length;i++) {
  659.             if(this.panelButtons[i].name == itm)
  660.                 return this.panelButtons[i];
  661.         }   
  662.     },
  663.     
  664.     reorder : function() {
  665.         var bl = this.buttonList;
  666.         for(var i=0;i<bl.length;i++) {
  667.             var button = this.findButton(bl[i]);
  668.             if(button) {
  669.                 this.panelElm.appendChild(button.margin);
  670.             }
  671.         }   
  672.     },
  673.     
  674.     remove : function() {
  675.         this.elm.remove();
  676.     }
  677. });
  678. var nicEditorButton = bkClass.extend({
  679.     
  680.     construct : function(e,buttonName,options,nicEditor) {
  681.         this.options = options.buttons[buttonName];
  682.         this.name = buttonName;
  683.         this.ne = nicEditor;
  684.         this.elm = e;
  685.         this.margin = new bkElement('DIV').setStyle({'float' : 'left', marginTop : '2px'}).appendTo(e);
  686.         this.contain = new bkElement('DIV').setStyle({width : '20px', height : '20px'}).addClass('buttonContain').appendTo(this.margin);
  687.         this.border = new bkElement('DIV').setStyle({backgroundColor : '#efefef', border : '1px solid #efefef'}).appendTo(this.contain);
  688.         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);
  689.         this.button.addEvent('mouseover'this.hoverOn.closure(this)).addEvent('mouseout',this.hoverOff.closure(this)).addEvent('mousedown',this.mouseClick.closure(this)).noSelect();
  690.         
  691.         if(!window.opera) {
  692.             this.button.onmousedown = this.button.onclick = bkLib.cancelEvent;
  693.         }
  694.         
  695.         nicEditor.addEvent('selected'this.enable.closure(this)).addEvent('blur'this.disable.closure(this)).addEvent('key',this.key.closure(this));
  696.         
  697.         this.disable();
  698.         this.init();
  699.     },
  700.     
  701.     init : function() {  },
  702.     
  703.     hide : function() {
  704.         this.contain.setStyle({display : 'none'});
  705.     },
  706.     
  707.     updateState : function() {
  708.         if(this.isDisabled) { this.setBg(); }
  709.         else if(this.isHover) { this.setBg('hover'); }
  710.         else if(this.isActive) { this.setBg('active'); }
  711.         else { this.setBg(); }
  712.     },
  713.     
  714.     setBg : function(state) {
  715.         switch(state) {
  716.             case 'hover':
  717.                 var stateStyle = {border : '1px solid #666', backgroundColor : '#ddd'};
  718.                 break;
  719.             case 'active':
  720.                 var stateStyle = {border : '1px solid #666', backgroundColor : '#ccc'};
  721.                 break;
  722.             default:
  723.                 var stateStyle = {border : '1px solid #efefef', backgroundColor : '#efefef'};   
  724.         }
  725.         this.border.setStyle(stateStyle).addClass('button-'+state);
  726.     },
  727.     
  728.     checkNodes : function(e) {
  729.         var elm = e;    
  730.         do {
  731.             if(this.options.tags && bkLib.inArray(this.options.tags,elm.nodeName)) {
  732.                 this.activate();
  733.                 return true;
  734.             }
  735.         } while(elm = elm.parentNode && elm.className != "nicEdit");
  736.         elm = $BK(e);
  737.         while(elm.nodeType == 3) {
  738.             elm = $BK(elm.parentNode);
  739.         }
  740.         if(this.options.css) {
  741.             for(itm in this.options.css) {
  742.                 if(elm.getStyle(itm,this.ne.selectedInstance.instanceDoc) == this.options.css[itm]) {
  743.                     this.activate();
  744.                     return true;
  745.                 }
  746.             }
  747.         }
  748.         this.deactivate();
  749.         return false;
  750.     },
  751.     
  752.     activate : function() {
  753.         if(!this.isDisabled) {
  754.             this.isActive = true;
  755.             this.updateState(); 
  756.             this.ne.fireEvent('buttonActivate',this);
  757.         }
  758.     },
  759.     
  760.     deactivate : function() {
  761.         this.isActive = false;
  762.         this.updateState(); 
  763.         if(!this.isDisabled) {
  764.             this.ne.fireEvent('buttonDeactivate',this);
  765.         }
  766.     },
  767.     
  768.     enable : function(ins,t) {
  769.         this.isDisabled = false;
  770.         this.contain.setStyle({'opacity' : 1}).addClass('buttonEnabled');
  771.         this.updateState();
  772.         this.checkNodes(t);
  773.     },
  774.     
  775.     disable : function(ins,t) {     
  776.         this.isDisabled = true;
  777.         this.contain.setStyle({'opacity' : 0.6}).removeClass('buttonEnabled');
  778.         this.updateState(); 
  779.     },
  780.     
  781.     toggleActive : function() {
  782.         (this.isActive) ? this.deactivate() : this.activate();  
  783.     },
  784.     
  785.     hoverOn : function() {
  786.         if(!this.isDisabled) {
  787.             this.isHover = true;
  788.             this.updateState();
  789.             this.ne.fireEvent("buttonOver",this);
  790.         }
  791.     }, 
  792.     
  793.     hoverOff : function() {
  794.         this.isHover = false;
  795.         this.updateState();
  796.         this.ne.fireEvent("buttonOut",this);
  797.     },
  798.     
  799.     mouseClick : function() {
  800.         if(this.options.command) {
  801.             this.ne.nicCommand(this.options.command,this.options.commandArgs);
  802.             if(!this.options.noActive) {
  803.                 this.toggleActive();
  804.             }
  805.         }
  806.         this.ne.fireEvent("buttonClick",this);
  807.     },
  808.     
  809.     key : function(nicInstance,e) {
  810.         if(this.options.key && e.ctrlKey && String.fromCharCode(e.keyCode || e.charCode).toLowerCase() == this.options.key) {
  811.             this.mouseClick();
  812.             if(e.preventDefault) e.preventDefault();
  813.         }
  814.     }
  815.     
  816. });
  817.  
  818. var nicPlugin = bkClass.extend({
  819.     
  820.     construct : function(nicEditor,options) {
  821.         this.options = options;
  822.         this.ne = nicEditor;
  823.         this.ne.addEvent('panel',this.loadPanel.closure(this));
  824.         
  825.         this.init();
  826.     },
  827.     loadPanel : function(np) {
  828.         var buttons = this.options.buttons;
  829.         for(var button in buttons) {
  830.             np.addButton(button,this.options);
  831.         }
  832.         np.reorder();
  833.     },
  834.     init : function() {  }
  835. });
  836.  
  837.  /* START CONFIG */
  838. var nicPaneOptions = { };
  839. /* END CONFIG */
  840. var nicEditorPane = bkClass.extend({
  841.     construct : function(elm,nicEditor,options,openButton) {
  842.         this.ne = nicEditor;
  843.         this.elm = elm;
  844.         this.pos = elm.pos();
  845.         
  846.         this.contain = new bkElement('div').setStyle({zIndex : '99999', overflow : 'hidden', position : 'absolute', left : this.pos[0]+'px', top : this.pos[1]+'px'});
  847.         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);
  848.         
  849.         if(openButton && !openButton.options.noClose) {
  850.             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);
  851.         }
  852.         
  853.         this.contain.noSelect().appendTo(document.body);
  854.         
  855.         this.position();
  856.         this.init();    
  857.     },
  858.     
  859.     init : function() { },
  860.     
  861.     position : function() {
  862.         if(this.ne.nicPanel) {
  863.             var panelElm = this.ne.nicPanel.elm;    
  864.             var panelPos = panelElm.pos();
  865.             var newLeft = panelPos[0]+parseInt(panelElm.getStyle('width'))-(parseInt(this.pane.getStyle('width'))+8);
  866.             if(newLeft < this.pos[0]) {
  867.                 this.contain.setStyle({left : newLeft+'px'});
  868.             }
  869.         }
  870.     },
  871.     
  872.     toggle : function() {
  873.         this.isVisible = !this.isVisible;
  874.         this.contain.setStyle({display : ((this.isVisible) ? 'block' : 'none')});
  875.     },
  876.     
  877.     remove : function() {
  878.         if(this.contain) {
  879.             this.contain.remove();
  880.             this.contain = null;
  881.         }
  882.     },
  883.     
  884.     append : function(c) {
  885.         c.appendTo(this.pane);
  886.     },
  887.     
  888.     setContent : function(c) {
  889.         this.pane.setContent(c);
  890.     }
  891.     
  892. });
  893.  
  894. var nicEditorAdvancedButton = nicEditorButton.extend({
  895.     
  896.     init : function() {
  897.         this.ne.addEvent('selected',this.removePane.closure(this)).addEvent('blur',this.removePane.closure(this));  
  898.     },
  899.     
  900.     mouseClick : function() {
  901.         if(!this.isDisabled) {
  902.             if(this.pane && this.pane.pane) {
  903.                 this.removePane();
  904.             } else {
  905.                 this.pane = new nicEditorPane(this.contain,this.ne,{width : (this.width || '270px'), backgroundColor : '#fff'},this);
  906.                 this.addPane();
  907.                 this.ne.selectedInstance.saveRng();
  908.             }
  909.         }
  910.     },
  911.     
  912.     addForm : function(f,elm) {
  913.         this.form = new bkElement('form').addEvent('submit',this.submit.closureListener(this));
  914.         this.pane.append(this.form);
  915.         this.inputs = {};
  916.         
  917.         for(itm in f) {
  918.             var field = f[itm];
  919.             var val = '';
  920.             if(elm) {
  921.                 val = elm.getAttribute(itm);
  922.             }
  923.             if(!val) {
  924.                 val = field['value'] || '';
  925.             }
  926.             var type = f[itm].type;
  927.             
  928.             if(type == 'title') {
  929.                     new bkElement('div').setContent(field.txt).setStyle({fontSize : '14px', fontWeight: 'bold', padding : '0px', margin : '2px 0'}).appendTo(this.form);
  930.             } else {
  931.                 var contain = new bkElement('div').setStyle({overflow : 'hidden', clear : 'both'}).appendTo(this.form);
  932.                 if(field.txt) {
  933.                     new bkElement('label').setAttributes({'for' : itm}).setContent(field.txt).setStyle({margin : '2px 4px', fontSize : '13px', width: '55px', lineHeight : '20px', textAlign : 'right''float' : 'left'}).appendTo(contain);
  934.                 }
  935.                 
  936.                 switch(type) {
  937.                     case 'text':
  938.                         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);
  939.                         break;
  940.                     case 'select':
  941.                         this.inputs[itm] = new bkElement('select').setAttributes({id : itm}).setStyle({border : '1px solid #ccc''float' : 'left', margin : '2px 0'}).appendTo(contain);
  942.                         for(opt in field.options) {
  943.                             var o = new bkElement('option').setAttributes({value : opt, selected : (opt == val) ? 'selected' : ''}).setContent(field.options[opt]).appendTo(this.inputs[itm]);
  944.                         }
  945.                         break;
  946.                     case 'content':
  947.                         this.inputs[itm] = new bkElement('textarea').setAttributes({id : itm}).setStyle({border : '1px solid #ccc''float' : 'left'}).setStyle(field.style).appendTo(contain);
  948.                         this.inputs[itm].value = val;
  949.                 }   
  950.             }
  951.         }
  952.         new bkElement('input').setAttributes({'type' : 'submit'}).setAttributes({'value' : '确定'}).setStyle({backgroundColor : '#efefef',border : '1px solid #ccc', margin : '3px 0''float' : 'left''clear' : 'both'}).appendTo(this.form);
  953.         this.form.onsubmit = bkLib.cancelEvent; 
  954.     },
  955.     
  956.     submit : function() { },
  957.     
  958.     findElm : function(tag,attr,val) {
  959.         var list = this.ne.selectedInstance.getElm().getElementsByTagName(tag);
  960.         for(var i=0;i<list.length;i++) {
  961.             if(list[i].getAttribute(attr) == val) {
  962.                 return $BK(list[i]);
  963.             }
  964.         }
  965.     },
  966.     
  967.     removePane : function() {
  968.         if(this.pane) {
  969.             this.pane.remove();
  970.             this.pane = null;
  971.             this.ne.selectedInstance.restoreRng();
  972.         }   
  973.     }   
  974. });
  975. var nicButtonTips = bkClass.extend({
  976.     construct : function(nicEditor) {
  977.         this.ne = nicEditor;
  978.         nicEditor.addEvent('buttonOver',this.show.closure(this)).addEvent('buttonOut',this.hide.closure(this));
  979.     },
  980.     
  981.     show : function(button) {
  982.         this.timer = setTimeout(this.create.closure(this,button),400);
  983.     },
  984.     
  985.     create : function(button) {
  986.         this.timer = null;
  987.         if(!this.pane) {
  988.             this.pane = new nicEditorPane(button.button,this.ne,{fontSize : '12px', marginTop : '5px'});
  989.             this.pane.setContent(button.options.name);
  990.         }       
  991.     },
  992.     
  993.     hide : function(button) {
  994.         if(this.timer) {
  995.             clearTimeout(this.timer);
  996.         }
  997.         if(this.pane) {
  998.             this.pane = this.pane.remove();
  999.         }
  1000.     }
  1001. });
  1002. nicEditors.registerPlugin(nicButtonTips);
  1003.  
  1004.  /* START CONFIG */
  1005. var nicSelectOptions = {
  1006.     buttons : {
  1007.         'fontSize' : {name : __('字体大小'), type : 'nicEditorFontSizeSelect', command : 'fontsize'},
  1008.         'fontFamily' : {name : __('字体类型'), type : 'nicEditorFontFamilySelect', command : 'fontname'},
  1009.         'fontFormat' : {name : __('字体格式'), type : 'nicEditorFontFormatSelect', command : 'formatBlock'}
  1010.     }
  1011. };
  1012. /* END CONFIG */
  1013. var nicEditorSelect = bkClass.extend({
  1014.     
  1015.     construct : function(e,buttonName,options,nicEditor) {
  1016.         this.options = options.buttons[buttonName];
  1017.         this.elm = e;
  1018.         this.ne = nicEditor;
  1019.         this.name = buttonName;
  1020.         this.selOptions = new Array();
  1021.         
  1022.         this.margin = new bkElement('div').setStyle({'float' : 'left', margin : '2px 1px 0 1px'}).appendTo(this.elm);
  1023.         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);
  1024.         this.items = new bkElement('div').setStyle({overflow : 'hidden', zoom : 1, border: '1px solid #ccc', paddingLeft : '3px', backgroundColor : '#fff'}).appendTo(this.contain);
  1025.         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);
  1026.         this.txt = new bkElement('div').setStyle({overflow : 'hidden''float' : 'left', width : '66px', height : 'auto',fontFamily : 'sans-serif', textAlign : 'center', fontSize : '12px'}).addClass('selectTxt').appendTo(this.items);
  1027.         
  1028.         if(!window.opera) {
  1029.             this.contain.onmousedown = this.control.onmousedown = this.txt.onmousedown = bkLib.cancelEvent;
  1030.         }
  1031.         
  1032.         this.margin.noSelect();
  1033.         
  1034.         this.ne.addEvent('selected'this.enable.closure(this)).addEvent('blur'this.disable.closure(this));
  1035.         
  1036.         this.disable();
  1037.         this.init();
  1038.     },
  1039.     
  1040.     disable : function() {
  1041.         this.isDisabled = true;
  1042.         this.close();
  1043.         this.contain.setStyle({opacity : 0.6});
  1044.     },
  1045.     
  1046.     enable : function(t) {
  1047.         this.isDisabled = false;
  1048.         this.close();
  1049.         this.contain.setStyle({opacity : 1});
  1050.     },
  1051.     
  1052.     setDisplay : function(txt) {
  1053.         this.txt.setContent(txt);
  1054.     },
  1055.     
  1056.     toggle : function() {
  1057.         if(!this.isDisabled) {
  1058.             (this.pane) ? this.close() : this.open();
  1059.         }
  1060.     },
  1061.     
  1062.     open : function() {
  1063.         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'});
  1064.         
  1065.         for(var i=0;i<this.selOptions.length;i++) {
  1066.             var opt = this.selOptions[i];
  1067.             var itmContain = new bkElement('div').setStyle({overflow : 'hidden', borderBottom : '1px solid #ccc', width: '88px', textAlign : 'left', overflow : 'hidden', cursor : 'pointer'});
  1068.             var itm = new bkElement('div').setStyle({padding : '0px 4px'}).setContent(opt[1]).appendTo(itmContain).noSelect();
  1069.             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]);
  1070.             this.pane.append(itmContain);
  1071.             if(!window.opera) {
  1072.                 itm.onmousedown = bkLib.cancelEvent;
  1073.             }
  1074.         }
  1075.     },
  1076.     
  1077.     close : function() {
  1078.         if(this.pane) {
  1079.             this.pane = this.pane.remove();
  1080.         }   
  1081.     },
  1082.     
  1083.     over : function(opt) {
  1084.         opt.setStyle({backgroundColor : '#ccc'});           
  1085.     },
  1086.     
  1087.     out : function(opt) {
  1088.         opt.setStyle({backgroundColor : '#fff'});
  1089.     },
  1090.     
  1091.     
  1092.     add : function(k,v) {
  1093.         this.selOptions.push(new Array(k,v));   
  1094.     },
  1095.     
  1096.     update : function(elm) {
  1097.         this.ne.nicCommand(this.options.command,elm);
  1098.         this.close();   
  1099.     }
  1100. });
  1101. var nicEditorFontSizeSelect = nicEditorSelect.extend({
  1102.     sel : {1 : '1 (8pt)', 2 : '2 (10pt)', 3 : '3 (12pt)', 4 : '4 (14pt)', 5 : '5 (18pt)', 6 : '6 (24pt)'},
  1103.     init : function() {
  1104.         this.setDisplay('字体大小');
  1105.         for(itm in this.sel) {
  1106.             this.add(itm,'<font size="'+itm+'">'+this.sel[itm]+'</font>');
  1107.         }       
  1108.     }
  1109. });
  1110. var nicEditorFontFamilySelect = nicEditorSelect.extend({
  1111.     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'},
  1112.     
  1113.     init : function() {
  1114.         this.setDisplay('字体类型');
  1115.         for(itm in this.sel) {
  1116.             this.add(itm,'<font face="'+itm+'">'+this.sel[itm]+'</font>');
  1117.         }
  1118.     }
  1119. });
  1120. var nicEditorFontFormatSelect = nicEditorSelect.extend({
  1121.     sel:{p:"段落",pre:"原始文本",h6:"标题 6",h5:"标题 5",h4:"标题 4",h3:"标题 3",h2:"标题 2",h1:"标题 1"},  
  1122.     init : function() {
  1123.         this.setDisplay('字体格式');
  1124.         for(itm in this.sel) {
  1125.             var tag = itm.toUpperCase();
  1126.             this.add('<'+tag+'>','<'+itm+' style="padding: 0px; margin: 0px;">'+this.sel[itm]+'</'+tag+'>');
  1127.         }
  1128.     }
  1129. });
  1130. nicEditors.registerPlugin(nicPlugin,nicSelectOptions);
  1131. /* START CONFIG */
  1132. var nicLinkOptions = {
  1133.     buttons : {
  1134.         'link' : {name : '添加链接', type : 'nicLinkButton', tags : ['A']},
  1135.         'unlink' : {name : '移除链接',  command : 'unlink', noActive : true}
  1136.     }
  1137. };
  1138. /* END CONFIG */
  1139. var nicLinkButton = nicEditorAdvancedButton.extend({    
  1140.     addPane : function() {
  1141.         this.ln = this.ne.selectedInstance.selElm().parentTag('A');
  1142.         this.addForm({
  1143.             '' : {type : 'title', txt : '添加/编辑 链接'},
  1144.             'href' : {type : 'text', txt : '链接地址', value : 'http://', style : {width: '150px'}},
  1145.             'title' : {type : 'text', txt : '名称'},
  1146.             'target' : {type : 'select', txt : '打开方式', options : {'' : '当前窗口''_blank' : '新窗口'},style : {width : '100px'}}
  1147.         },this.ln);
  1148.     },
  1149.     
  1150.     submit : function(e) {
  1151.         var url = this.inputs['href'].value;
  1152.         if(url == "http://" || url == "") {
  1153.             alert("请输入网址");
  1154.             return false;
  1155.         }
  1156.         this.removePane();
  1157.         
  1158.         if(!this.ln) {
  1159.             var tmp = 'javascript:nicTemp();';
  1160.             this.ne.nicCommand("createlink",tmp);
  1161.             this.ln = this.findElm('A','href',tmp);
  1162.         }
  1163.         if(this.ln) {
  1164.             this.ln.setAttributes({
  1165.                 href : this.inputs['href'].value,
  1166.                 title : this.inputs['title'].value,
  1167.                 target : this.inputs['target'].options[this.inputs['target'].selectedIndex].value
  1168.             });
  1169.         }
  1170.     }
  1171. });
  1172. nicEditors.registerPlugin(nicPlugin,nicLinkOptions);
  1173. /* START CONFIG */
  1174. var nicColorOptions = {
  1175.     buttons : {
  1176.         'forecolor' : {name : __('字体颜色'), type : 'nicEditorColorButton', noClose : true},
  1177.         'bgcolor' : {name : __('背景颜色'), type : 'nicEditorBgColorButton', noClose : true}
  1178.     }
  1179. };
  1180. /* END CONFIG */
  1181. var nicEditorColorButton = nicEditorAdvancedButton.extend({ 
  1182.     addPane : function() {
  1183.             var colorList = {0 : '00',1 : '33',2 : '66',3 :'99',4 : 'CC',5 : 'FF'};
  1184.             var colorItems = new bkElement('DIV').setStyle({width: '270px'});
  1185.             
  1186.             for(var r in colorList) {
  1187.                 for(var b in colorList) {
  1188.                     for(var g in colorList) {
  1189.                         var colorCode = '#'+colorList[r]+colorList[g]+colorList[b];
  1190.                         
  1191.                         var colorSquare = new bkElement('DIV').setStyle({'cursor' : 'pointer''height' : '15px''float' : 'left'}).appendTo(colorItems);
  1192.                         var colorBorder = new bkElement('DIV').setStyle({border: '2px solid '+colorCode}).appendTo(colorSquare);
  1193.                         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);
  1194.                         
  1195.                         if(!window.opera) {
  1196.                             colorSquare.onmousedown = colorInner.onmousedown = bkLib.cancelEvent;
  1197.                         }
  1198.                     }   
  1199.                 }   
  1200.             }
  1201.             this.pane.append(colorItems.noSelect());    
  1202.     },
  1203.     
  1204.     colorSelect : function(c) {
  1205.         this.ne.nicCommand('foreColor',c);
  1206.         this.removePane();
  1207.     },
  1208.     
  1209.     on : function(colorBorder) {
  1210.         colorBorder.setStyle({border : '2px solid #000'});
  1211.     },
  1212.     
  1213.     off : function(colorBorder,colorCode) {
  1214.         colorBorder.setStyle({border : '2px solid '+colorCode});        
  1215.     }
  1216. });
  1217. var nicEditorBgColorButton = nicEditorColorButton.extend({
  1218.     colorSelect : function(c) {
  1219.         this.ne.nicCommand('hiliteColor',c);
  1220.         this.removePane();
  1221.     }   
  1222. });
  1223. nicEditors.registerPlugin(nicPlugin,nicColorOptions);
  1224. /* START CONFIG */
  1225. var nicImageOptions = {
  1226.     buttons : {
  1227.         'image' : {name : '添加图片', type : 'nicImageButton', tags : ['IMG']}
  1228.     }
  1229.     
  1230. };
  1231. /* END CONFIG */
  1232. var nicImageButton = nicEditorAdvancedButton.extend({   
  1233.     addPane : function() {
  1234.         this.im = this.ne.selectedInstance.selElm().parentTag('IMG');
  1235.         this.addForm({
  1236.             '' : {type : 'title', txt : '添加/编辑 图片'},
  1237.             'src' : {type : 'text', txt : '图片地址''value' : 'http://', style : {width: '150px'}},
  1238.             'alt' : {type : 'text', txt : '说明文字', style : {width: '100px'}},
  1239.             'align' : {type : 'select', txt : '对齐方式', options : {none : '默认','left' : '左对齐''right' : '右对齐'}}
  1240.         },this.im);
  1241.     },
  1242.     
  1243.     submit : function(e) {
  1244.         var src = this.inputs['src'].value;
  1245.         if(src == "" || src == "http://") {
  1246.             alert("请添加图片");
  1247.             return false;
  1248.         }
  1249.         this.removePane();
  1250.         if(!this.im) {
  1251.             var tmp = 'javascript:nicImTemp();';
  1252.             this.ne.nicCommand("insertImage",tmp);
  1253.             this.im = this.findElm('IMG','src',tmp);
  1254.         }
  1255.         if(this.im) {
  1256.             this.im.setAttributes({
  1257.                 src : this.inputs['src'].value,
  1258.                 alt : this.inputs['alt'].value,
  1259.                 align : this.inputs['align'].value
  1260.             });
  1261.         }
  1262.     }
  1263. });
  1264. nicEditors.registerPlugin(nicPlugin,nicImageOptions);
  1265. /* START CONFIG */
  1266. var nicSaveOptions = {
  1267.     buttons : {
  1268.         'save' : {name : __('保存'), type : 'nicEditorSaveButton'}
  1269.     }
  1270. };
  1271. /* END CONFIG */
  1272. var nicEditorSaveButton = nicEditorButton.extend({
  1273.     init : function() {
  1274.         if(!this.ne.options.onSave) {
  1275.             this.margin.setStyle({'display' : 'none'});
  1276.         }
  1277.     },
  1278.     mouseClick : function() {
  1279.         var onSave = this.ne.options.onSave;
  1280.         var selectedInstance = this.ne.selectedInstance;
  1281.         onSave(selectedInstance.getContent(), selectedInstance.elm.id, selectedInstance);
  1282.     }
  1283. });
  1284. nicEditors.registerPlugin(nicPlugin,nicSaveOptions);
  1285. /* START CONFIG */
  1286. var nicUploadOptions = {
  1287.     buttons : {
  1288.         'upload' : {name : '上传图片', type : 'nicUploadButton'}
  1289.     }
  1290.     
  1291. };
  1292. /* END CONFIG */
  1293. var nicUploadButton = nicEditorAdvancedButton.extend({  
  1294.     serverURI : '/photo.php?action=addphoto&act=doupload',
  1295.     formElm:{html:''},
  1296.     loading:'/img/loading.gif',
  1297.     addPane : function() {
  1298.         this.im = this.ne.selectedInstance.selElm().parentTag('IMG');
  1299.         this.myID = Math.round(Math.random()*Math.pow(10,15));
  1300.         this.requestInterval = 1000;
  1301.         this.myFrame = new bkElement('iframe').setAttributes({ width : '100%', height : '100px', frameBorder : 0, scrolling : 'no' }).setStyle({border : 0}).appendTo(this.pane.pane);
  1302.         this.progressWrapper = new bkElement('div').setStyle({display: 'none', width: '100%', height: '20px', border : '1px solid #ccc'}).appendTo(this.pane.pane);
  1303.         this.progress = new bkElement('div').setStyle({width: '0%', height: '20px', backgroundColor : '#ccc'}).setContent(' ').appendTo(this.progressWrapper);
  1304.         setTimeout(this.addForm.closure(this),50);
  1305.     },
  1306.     addForm : function() {
  1307.         var myDoc = this.myDoc = this.myFrame.contentWindow.document;
  1308.         myDoc.open();
  1309.         myDoc.write("<html><body>");
  1310.         myDoc.write('<form method="post" action="'+this.serverURI+'&check='+this.myID+'" enctype="multipart/form-data">');
  1311.         myDoc.write('<input type="hidden" name="APC_UPLOAD_PROGRESS" value="'+this.myID+'" />');
  1312.         myDoc.write('<div style="font-size: 14px; font-weight: bold; padding-top: 5px;">上传图片</div>');
  1313.         myDoc.write(this.formElm.html||'没有创建分类');
  1314.         myDoc.write('<input name="photo_file" id="photo_file" type="file" style="margin-top: 10px;" />');
  1315.         myDoc.write('</form>');
  1316.         myDoc.write("</body></html>");
  1317.         myDoc.close();
  1318.         this.myBody = myDoc.body;
  1319.         this.myForm = $BK(this.myBody.getElementsByTagName('form')[0]);
  1320.         this.myInput = $BK(this.myBody.getElementsByTagName('input')[1]).addEvent('change'this.startUpload.closure(this));
  1321.         this.myStatus = new bkElement('div',this.myDoc).setStyle({textAlign : 'center', fontSize : '14px'}).appendTo(this.myBody);
  1322.   },
  1323.     startUpload : function() {
  1324.         this.myForm.setStyle({display : 'none'});
  1325.         this.myStatus.setContent('<img src="'+this.loading+'" style="float: right; margin-right: 40px;" /><strong>上传中...</strong><br />请稍等');
  1326.         this.setProgress(10);
  1327.         this.myForm.submit();
  1328.         setTimeout(this.makeRequest.closure(this),this.requestInterval);
  1329.     },
  1330.     makeRequest : function() {
  1331.         if(this.pane && this.pane.pane) {
  1332.             nicUploadButton.lastPlugin = this;
  1333.             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() {
  1334.                 s.parentNode.removeChild(s);
  1335.             }).appendTo(document.getElementsByTagName('head')[0]);
  1336.             if(this.requestInterval) {
  1337.                 setTimeout(this.makeRequest.closure(this), this.requestInterval);
  1338.             }
  1339.         }
  1340.     },
  1341.     setProgress : function(percent) {
  1342.         this.progressWrapper.setStyle({display: 'block'});
  1343.         this.progress.setStyle({width : percent+'%'});
  1344.     },
  1345.     update : function(o) {
  1346.         if(!this.requestInterval) return;
  1347.         if(o == false) {
  1348.             this.progressWrapper.setStyle({display : 'none'});
  1349.         } else if(o.url) {
  1350.             this.setProgress(100);
  1351.             this.requestInterval = false;
  1352.             if(!this.im) {
  1353.                 this.ne.selectedInstance.restoreRng();
  1354.                 var tmp = 'javascript:nicImTemp();';
  1355.                 this.ne.nicCommand("insertImage",tmp);
  1356.                 this.im = this.findElm('IMG','src',tmp);
  1357.             }
  1358.             var w = parseInt(this.ne.selectedInstance.elm.getStyle('width'));
  1359.             if(this.im) {
  1360.                 this.im.setAttributes({
  1361.                     src : o.url,
  1362.                     width : (w && o.width) ? Math.min(w,o.width) : ''
  1363.                 });
  1364.             }
  1365.             this.removePane();
  1366.         } else if(o.error) {
  1367.             this.requestInterval = false;
  1368.             this.setProgress(100);
  1369.             alert("上传失败 ("+o.error+").");
  1370.             this.removePane();
  1371.         } else {
  1372.             this.setProgress( Math.round( (o.current/o.total) * 75) );
  1373.             if(o.interval) {
  1374.                 this.requestInterval = o.interval;
  1375.             }
  1376.         }
  1377.     }
  1378. });
  1379. nicUploadButton.statusCb = function(o) {
  1380.     nicUploadButton.lastPlugin.update(o);
  1381. };
  1382. nicEditors.registerPlugin(nicPlugin,nicUploadOptions);
  1383. var nicXHTML = bkClass.extend({
  1384.     stripAttributes : ['_moz_dirty','_moz_resizing','_extended'],
  1385.     noShort : ['style','title','script','textarea','a'],
  1386.     cssReplace : {'font-weight:bold;' : 'strong''font-style:italic;' : 'em'},
  1387.     sizes : {1 : 'xx-small', 2 : 'x-small', 3 : 'small', 4 : 'medium', 5 : 'large', 6 : 'x-large'},
  1388.     
  1389.     construct : function(nicEditor) {
  1390.         this.ne = nicEditor;
  1391.         if(this.ne.options.xhtml) {
  1392.             nicEditor.addEvent('get',this.cleanup.closure(this));
  1393.         }
  1394.     },
  1395.     
  1396.     cleanup : function(ni) {
  1397.         var node = ni.getElm();
  1398.         var xhtml = this.toXHTML(node);
  1399.         ni.content = xhtml;
  1400.     },
  1401.     
  1402.     toXHTML : function(n,r,d) {
  1403.         var txt = '';
  1404.         var attrTxt = '';
  1405.         var cssTxt = '';
  1406.         var nType = n.nodeType;
  1407.         var nName = n.nodeName.toLowerCase();
  1408.         var nChild = n.hasChildNodes && n.hasChildNodes();
  1409.         var extraNodes = new Array();
  1410.         
  1411.         switch(nType) {
  1412.             case 1:
  1413.                 var nAttributes = n.attributes;
  1414.                 
  1415.                 switch(nName) {
  1416.                     case 'b':
  1417.                         nName = 'strong';
  1418.                         break;
  1419.                     case 'i':
  1420.                         nName = 'em';
  1421.                         break;
  1422.                     case 'font':
  1423.                         nName = 'span';
  1424.                         break;
  1425.                 }
  1426.                 
  1427.                 if(r) {
  1428.                     for(var i=0;i<nAttributes.length;i++) {
  1429.                         var attr = nAttributes[i];
  1430.                         
  1431.                         var attributeName = attr.nodeName.toLowerCase();
  1432.                         var attributeValue = attr.nodeValue;
  1433.                         
  1434.                         if(!attr.specified || !attributeValue || bkLib.inArray(this.stripAttributes,attributeName) || typeof(attributeValue) == "function") {
  1435.                             continue;
  1436.                         }
  1437.                         
  1438.                         switch(attributeName) {
  1439.                             case 'style':
  1440.                                 var css = attributeValue.replace(/ /g,"");
  1441.                                 for(itm in this.cssReplace) {
  1442.                                     if(css.indexOf(itm) != -1) {
  1443.                                         extraNodes.push(this.cssReplace[itm]);
  1444.                                         css = css.replace(itm,'');
  1445.                                     }
  1446.                                 }
  1447.                                 cssTxt += css;
  1448.                                 attributeValue = "";
  1449.                             break;
  1450.                             case 'class':
  1451.                                 attributeValue = attributeValue.replace("Apple-style-span","");
  1452.                             break;
  1453.                             case 'size':
  1454.                                 cssTxt += "font-size:"+this.sizes[attributeValue]+';';
  1455.                                 attributeValue = "";
  1456.                             break;
  1457.                         }
  1458.                         
  1459.                         if(attributeValue) {
  1460.                             attrTxt += ' '+attributeName+'="'+attributeValue+'"';
  1461.                         }
  1462.                     }
  1463.                     if(cssTxt) {
  1464.                         attrTxt += ' style="'+cssTxt+'"';
  1465.                     }
  1466.                     for(var i=0;i<extraNodes.length;i++) {
  1467.                         txt += '<'+extraNodes[i]+'>';
  1468.                     }
  1469.                 
  1470.                     if(attrTxt == "" && nName == "span") {
  1471.                         r = false;
  1472.                     }
  1473.                     if(r) {
  1474.                         txt += '<'+nName;
  1475.                         if(nName != 'br') {
  1476.                             txt += attrTxt;
  1477.                         }
  1478.                     }
  1479.                 }
  1480.                 
  1481.                 
  1482.                 if(!nChild && !bkLib.inArray(this.noShort,attributeName)) {
  1483.                     if(r) {
  1484.                         txt += ' />';
  1485.                     }
  1486.                 } else {
  1487.                     if(r) {
  1488.                         txt += '>';
  1489.                     }
  1490.                     
  1491.                     for(var i=0;i<n.childNodes.length;i++) {
  1492.                         var results = this.toXHTML(n.childNodes[i],true,true);
  1493.                         if(results) {
  1494.                             txt += results;
  1495.                         }
  1496.                     }
  1497.                 }
  1498.                     
  1499.                 if(r && nChild) {
  1500.                     txt += '</'+nName+'>';
  1501.                 }
  1502.                 
  1503.                 for(var i=0;i<extraNodes.length;i++) {
  1504.                     txt += '</'+extraNodes[i]+'>';
  1505.                 }
  1506.                 break;
  1507.             case 3:
  1508.                 //if(n.nodeValue != '/n') {
  1509.                     txt += n.nodeValue;
  1510.                 //}
  1511.                 break;
  1512.         }
  1513.         
  1514.         return txt;
  1515.     }
  1516. });
  1517. nicEditors.registerPlugin(nicXHTML);
  1518. var nicBBCode = bkClass.extend({
  1519.     construct : function(nicEditor) {
  1520.         this.ne = nicEditor;
  1521.         if(this.ne.options.bbCode) {
  1522.             nicEditor.addEvent('get',this.bbGet.closure(this));
  1523.             nicEditor.addEvent('set',this.bbSet.closure(this));
  1524.             
  1525.             var loadedPlugins = this.ne.loadedPlugins;
  1526.             for(itm in loadedPlugins) {
  1527.                 if(loadedPlugins[itm].toXHTML) {
  1528.                     this.xhtml = loadedPlugins[itm];
  1529.                 }
  1530.             }
  1531.         }
  1532.     },
  1533.     
  1534.     bbGet : function(ni) {
  1535.         var xhtml = this.xhtml.toXHTML(ni.getElm());
  1536.         ni.content = this.toBBCode(xhtml);
  1537.     },
  1538.     
  1539.     bbSet : function(ni) {
  1540.         ni.content = this.fromBBCode(ni.content);
  1541.     },
  1542.     
  1543.     toBBCode : function(xhtml) {
  1544.         function rp(r,m) {
  1545.             xhtml = xhtml.replace(r,m);
  1546.         }
  1547.         
  1548.         rp(//n/gi,"");
  1549.         rp(/<strong>(.*?)<//strong>/gi,"[b]$1[/b]");
  1550.         rp(/<em>(.*?)<//em>/gi,"[i]$1[/i]");
  1551.         rp(/<span.*?style="text-decoration:underline;">(.*?)<//span>/gi,"[u]$1[/u]");
  1552.         rp(/<ul>(.*?)<//ul>/gi,"[list]$1[/list]");
  1553.         rp(/<li>(.*?)<//li>/gi,"[*]$1[/*]");
  1554.         rp(/<ol>(.*?)<//ol>/gi,"[list=1]$1[/list]");
  1555.         rp(/<img.*?src="(.*?)".*?>/gi,"[img]$1[/img]");
  1556.         rp(/<a.*?href="(.*?)".*?>(.*?)<//a>/gi,"[url=$1]$2[/url]");
  1557.         rp(/<br.*?>/gi,"/n");
  1558.         rp(/<.*?>.*?<//.*?>/gi,"");
  1559.         
  1560.         return xhtml;
  1561.     },
  1562.     
  1563.     fromBBCode : function(bbCode) {
  1564.         function rp(r,m) {
  1565.             bbCode = bbCode.replace(r,m);
  1566.         }       
  1567.         
  1568.         rp(//[b/](.*?)/[//b/]/gi,"<strong>$1</strong>");
  1569.         rp(//[i/](.*?)/[//i/]/gi,"<em>$1</em>");
  1570.         rp(//[u/](.*?)/[//u/]/gi,"<span style=/"text-decoration:underline;/">$1</span>");
  1571.         rp(//[list/](.*?)/[//list/]/gi,"<ul>$1</ul>");
  1572.         rp(//[list=1/](.*?)/[//list/]/gi,"<ol>$1</ol>");
  1573.         rp(//[/*/](.*?)/[///*/]/gi,"<li>$1</li>");
  1574.         rp(//[img/](.*?)/[//img/]/gi,"<img src=/"$1/" />");
  1575.         rp(//[url=(.*?)/](.*?)/[//url/]/gi,"<a href=/"$1/">$2</a>");
  1576.         rp(//n/gi,"<br />");
  1577.         //rp(//[.*?/](.*?)/[//.*?/]/gi,"$1");
  1578.         
  1579.         return bbCode;
  1580.     }
  1581.     
  1582. });
  1583. nicEditors.registerPlugin(nicBBCode);
  1584. /* START CONFIG */
  1585. var nicCodeOptions = {
  1586.     buttons : {
  1587.         'xhtml' : {name : '源文件', type : 'nicCodeButton'}
  1588.     }
  1589.     
  1590. };
  1591. /* END CONFIG */
  1592. var nicCodeButton = nicEditorAdvancedButton.extend({
  1593.     width : '350px',
  1594.         
  1595.     addPane : function() {
  1596.         this.addForm({
  1597.             '' : {type : 'title', txt : '编辑 HTML'},
  1598.             'code' : {type : 'content''value' : this.ne.selectedInstance.getContent(), style : {width: '340px', height : '200px'}}
  1599.         });
  1600.     },
  1601.     
  1602.     submit : function(e) {
  1603.         var code = this.inputs['code'].value;
  1604.         this.ne.selectedInstance.setContent(code);
  1605.         this.removePane();
  1606.     }
  1607. });
  1608. nicEditors.registerPlugin(nicPlugin,nicCodeOptions);
  1609. /* START CONFIG */
  1610. var smileOptions = {
  1611.     buttons : {
  1612.         'smile' : {name : '添加表情', type : 'nicEditorSmileButton', noClose : true,tags : ['Sm']}
  1613.     }
  1614. };
  1615. /* END CONFIG */
  1616. var nicEditorSmileButton = nicEditorAdvancedButton.extend({
  1617.     addPane : function() {
  1618.         var smileList = this.smileList;
  1619.         var smileItems = new bkElement('DIV').setStyle({width: '270px'});
  1620.         for(var g in smileList) {
  1621.             var smileSrc = smileList[g];
  1622.             var smileImg = '<img src='+smileSrc+' />';
  1623.             var smileSquare = new bkElement('DIV').setStyle({'cursor':'pointer','height':'20px','width':'20px','float':'left'}).appendTo(smileItems);
  1624.             var smileBorder = new bkElement('DIV').appendTo(smileSquare).setStyle({border : '1px solid #fff'});
  1625.             var smileInner = new bkElement('DIV').setStyle({overflow : 'hidden', width : '18px', height : '18px'}).addEvent('click',this.smileSelect.closure(this,smileSrc)).addEvent('mouseover',this.on.closure(this,smileBorder)).addEvent('mouseout',this.off.closure(this,smileBorder)).appendTo(smileBorder);     
  1626.             smileInner.innerHTML = smileImg;
  1627.             if(!window.opera) {
  1628.                 smileSquare.onmousedown = smileInner.onmousedown = bkLib.cancelEvent;
  1629.             }
  1630.         }
  1631.         this.pane.append(smileItems.noSelect());
  1632.     },
  1633.     smileList:['/view/img/smile/1.gif','/view/img/smile/2.gif','/view/img/smile/3.gif','/view/img/smile/4.gif','/view/img/smile/5.gif','/view/img/smile/6.gif','/view/img/smile/7.gif','/view/img/smile/8.gif','/view/img/smile/9.gif','/view/img/smile/10.gif','/view/img/smile/11.gif','/view/img/smile/12.gif','/view/img/smile/13.gif','/view/img/smile/14.gif','/view/img/smile/15.gif','/view/img/smile/16.gif','/view/img/smile/17.gif','/view/img/smile/18.gif','/view/img/smile/19.gif','/view/img/smile/20.gif'],
  1634.     smileSelect : function(smileSrc) {
  1635.         this.ne.nicCommand('insertImage',smileSrc);
  1636.         this.removePane();
  1637.     },
  1638.     on:function(smileBorder){
  1639.         smileBorder.setStyle({border : '1px solid #000'});
  1640.     },
  1641.     off:function(smileBorder){
  1642.         smileBorder.setStyle({border : '1px solid #fff'});
  1643.     }
  1644. });
  1645. nicEditors.registerPlugin(nicPlugin,smileOptions);
图片上传的时候,php端返回:


  1. //图片上传进度条 
  2.     $rand  = $_GET['rand'];
  3.     $check = $_GET['check'];
  4.     $APC   = $_GET['APC'];
  5.     if ($rand) {
  6.         $status = apc_fetch('upload_' . $check);
  7.         $interval = $status['current']/$status['total']*100;
  8.         if(array_key_exists($check$_SESSION['apc_upload'])) {
  9.             $json = json_encode(array(
  10.                 'current'  => $status['current'],
  11.                 'total'    => $status['total'],
  12.                 'interval' => $interval,
  13.                 'width'    => 160,
  14.                 'url'      => $status['file'],
  15.             ));
  16.             unset($_SESSION['apc_upload'][$check]);
  17.         } else {
  18.             $json = json_encode(array(
  19.                  'current'  => $status['current'],
  20.                  'total'    => $status['total'],
  21.                  'interval' => $interval
  22.             ));
  23.         }
  24.         echo "nicUploadButton.statusCb(".$json.")";
  25.         exit;
  26.     } elseif($APC && !isset($_SESSION['apc_upload'][$APC])) {
  27.         $_SESSION['apc_upload'][$APC] = $id;
  28.     }

要用到php_apc.dll;

php.ini 配置 : apc.rfc1867 = on

参考  http://www.ibm.com/developerworks/cn/opensource/os-php-v525/  php 图片上传进度条的实现

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值