diff --git a/nicEdit.js b/nicEdit.js index c08b827..468cc84 100644 --- a/nicEdit.js +++ b/nicEdit.js @@ -4,7 +4,7 @@ * NicEdit is distributed under the terms of the MIT license * For more information visit http://nicedit.com/ * Do not remove this copyright message - */ + */ var bkExtend = function(){ var args = arguments; if (args.length == 1) args = [this, args[0]]; @@ -14,14 +14,14 @@ var bkExtend = function(){ function bkClass() { } bkClass.prototype.construct = function() {}; bkClass.extend = function(def) { - var classDef = function() { - if (arguments[0] !== bkClass) { return this.construct.apply(this, arguments); } - }; - var proto = new this(bkClass); - bkExtend(proto,def); - classDef.prototype = proto; - classDef.extend = this.extend; - return classDef; + var classDef = function() { + if (arguments[0] !== bkClass) { return this.construct.apply(this, arguments); } + }; + var proto = new this(bkClass); + bkExtend(proto,def); + classDef.prototype = proto; + classDef.extend = this.extend; + return classDef; }; var bkElement = bkClass.extend({ @@ -32,27 +32,27 @@ var bkElement = bkClass.extend({ elm = $BK(elm); return elm; }, - + appendTo : function(elm) { - elm.appendChild(this); + elm.appendChild(this); return this; }, - + appendBefore : function(elm) { - elm.parentNode.insertBefore(this,elm); + elm.parentNode.insertBefore(this,elm); return this; }, - + addEvent : function(type, fn) { bkLib.addEvent(this,type,fn); - return this; + return this; }, - + setContent : function(c) { this.innerHTML = c; return this; }, - + pos : function() { var curleft = curtop = 0; var o = obj = this; @@ -65,12 +65,12 @@ var bkElement = bkClass.extend({ var b = (!window.opera) ? parseInt(this.getStyle('border-width') || this.style.border) || 0 : 0; return [curleft+b,curtop+b+this.offsetHeight]; }, - + noSelect : function() { bkLib.noSelect(this); return this; }, - + parentTag : function(t) { var elm = this; do { @@ -81,16 +81,16 @@ var bkElement = bkClass.extend({ } while(elm); return false; }, - + hasClass : function(cls) { return this.className.match(new RegExp('(\\s|^)nicEdit-'+cls+'(\\s|$)')); }, - + addClass : function(cls) { if (!this.hasClass(cls)) { this.className += " nicEdit-"+cls }; return this; }, - + removeClass : function(cls) { if (this.hasClass(cls)) { this.className = this.className.replace(new RegExp('(\\s|^)nicEdit-'+cls+'(\\s|$)'),' '); @@ -107,7 +107,7 @@ var bkElement = bkClass.extend({ break; case 'opacity': elmStyle.opacity = st[itm]; - elmStyle.filter = "alpha(opacity=" + Math.round(st[itm]*100) + ")"; + elmStyle.filter = "alpha(opacity=" + Math.round(st[itm]*100) + ")"; break; case 'className': this.className = st[itm]; @@ -115,23 +115,23 @@ var bkElement = bkClass.extend({ default: //if(document.compatMode || itm != "cursor") { // Nasty Workaround for IE 5.5 elmStyle[itm] = st[itm]; - //} + //} } } return this; }, - + getStyle : function( cssRule, d ) { - var doc = (!d) ? document.defaultView : d; + var doc = (!d) ? document.defaultView : d; if(this.nodeType == 1) return (doc && doc.getComputedStyle) ? doc.getComputedStyle( this, null ).getPropertyValue(cssRule) : this.currentStyle[ bkLib.camelize(cssRule) ]; }, - + remove : function() { this.parentNode.removeChild(this); - return this; + return this; }, - + setAttributes : function(at) { for(var itm in at) { this[itm] = at[itm]; @@ -142,17 +142,17 @@ var bkElement = bkClass.extend({ var bkLib = { isMSIE : (navigator.appVersion.indexOf("MSIE") != -1), - + addEvent : function(obj, type, fn) { - (obj.addEventListener) ? obj.addEventListener( type, fn, false ) : obj.attachEvent("on"+type, fn); + (obj.addEventListener) ? obj.addEventListener( type, fn, false ) : obj.attachEvent("on"+type, fn); }, - + toArray : function(iterable) { var length = iterable.length, results = new Array(length); - while (length--) { results[length] = iterable[length] }; - return results; + while (length--) { results[length] = iterable[length] }; + return results; }, - + noSelect : function(element) { if(element.setAttribute && element.nodeName.toLowerCase() != 'input' && element.nodeName.toLowerCase() != 'textarea') { element.setAttribute('unselectable','on'); @@ -172,7 +172,7 @@ var bkLib = { if(arr[i] == itm) return i; } - return null; + return null; }, cancelEvent : function(e) { e = e || window.event; @@ -225,30 +225,32 @@ var bkEvent = { this.eventList[evType][i].apply(this,args); } } - } + } }; -function __(s) { - return s; +if (!__) { + __ = function(s) { + return s; + } } Function.prototype.closure = function() { - var __method = this, args = bkLib.toArray(arguments), obj = args.shift(); - return function() { if(typeof(bkLib) != 'undefined') { return __method.apply(obj,args.concat(bkLib.toArray(arguments))); } }; + var __method = this, args = bkLib.toArray(arguments), obj = args.shift(); + return function() { if(typeof(bkLib) != 'undefined') { return __method.apply(obj,args.concat(bkLib.toArray(arguments))); } }; } - -Function.prototype.closureListener = function() { - var __method = this, args = bkLib.toArray(arguments), object = args.shift(); - return function(e) { - e = e || window.event; - if(e.target) { var target = e.target; } else { var target = e.srcElement }; - return __method.apply(object, [e,target].concat(args) ); - }; -} - +Function.prototype.closureListener = function() { + var __method = this, args = bkLib.toArray(arguments), object = args.shift(); + return function(e) { + e = e || window.event; + if(e.target) { var target = e.target; } else { var target = e.srcElement }; + return __method.apply(object, [e,target].concat(args) ); + }; +} + + /* START CONFIG */ - + var nicEditorConfig = bkClass.extend({ buttons : { 'bold' : {name : __('Click to Bold'), command : 'Bold', tags : ['B','STRONG'], css : {'font-weight' : 'bold'}, key : 'b'}, @@ -259,7 +261,7 @@ var nicEditorConfig = bkClass.extend({ 'right' : {name : __('Right Align'), command : 'justifyright', noActive : true}, 'justify' : {name : __('Justify Align'), command : 'justifyfull', noActive : true}, 'ol' : {name : __('Insert Ordered List'), command : 'insertorderedlist', tags : ['OL']}, - 'ul' : {name : __('Insert Unordered List'), command : 'insertunorderedlist', tags : ['UL']}, + 'ul' : {name : __('Insert Unordered List'), command : 'insertunorderedlist', tags : ['UL']}, 'subscript' : {name : __('Click to Subscript'), command : 'subscript', tags : ['SUB']}, 'superscript' : {name : __('Click to Superscript'), command : 'superscript', tags : ['SUP']}, 'strikethrough' : {name : __('Click to Strike Through'), command : 'strikeThrough', css : {'text-decoration' : 'line-through'}}, @@ -269,17 +271,17 @@ var nicEditorConfig = bkClass.extend({ 'hr' : {name : __('Horizontal Rule'), command : 'insertHorizontalRule', noActive : true} }, iconsPath : '../nicEditorIcons.gif', - buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','bgcolor'], + buttonList : ['save','bold','italic','underline','strikethrough','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','image','upload','link','unlink','removeformat','forecolor','bgcolor','indent','outdent','subscript','superscript','xhtml'], 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} - + }); -/* END CONFIG */ +/* END CONFIG */ var nicEditors = { nicPlugins : [], editors : [], - + registerPlugin : function(plugin,options) { this.nicPlugins.push({p : plugin, o : options}); }, @@ -291,7 +293,7 @@ var nicEditors = { } return nicEditors.editors; }, - + findEditor : function(e) { var editors = nicEditors.editors; for(var i=0;i'); } @@ -455,7 +457,7 @@ var nicEditorInstance = bkClass.extend({ this.elm.addEvent('mousedown',this.selected.closureListener(this)).addEvent('keypress',this.keyDown.closureListener(this)).addEvent('focus',this.selected.closure(this)).addEvent('blur',this.blur.closure(this)).addEvent('keyup',this.selected.closure(this)); this.ne.fireEvent('add',this); }, - + remove : function() { this.saveContent(); if(this.copyElm || this.options.hasPanel) { @@ -466,21 +468,21 @@ var nicEditorInstance = bkClass.extend({ this.disable(); this.ne.fireEvent('remove',this); }, - + disable : function() { this.elm.setAttribute('contentEditable','false'); }, - + getSel : function() { - return (window.getSelection) ? window.getSelection() : document.selection; + return (window.getSelection) ? window.getSelection() : document.selection; }, - + getRng : function() { var s = this.getSel(); if(!s || s.rangeCount === 0) { return; } return (s.rangeCount > 0) ? s.getRangeAt(0) : s.createRange(); }, - + selRng : function(rng,s) { if(window.getSelection) { s.removeAllRanges(); @@ -489,7 +491,7 @@ var nicEditorInstance = bkClass.extend({ rng.select(); } }, - + selElm : function() { var r = this.getRng(); if(!r) { return; } @@ -498,8 +500,8 @@ var nicEditorInstance = bkClass.extend({ if(r.cloneContents().childNodes.length == 1) { for(var i=0;i'+((css) ? '' : '')+''+this.initialContent+''); @@ -616,38 +618,38 @@ var nicEditorIFrameInstance = nicEditorInstance.extend({ this.frameWin = $BK(this.elmFrame.contentWindow); this.frameContent = $BK(this.frameWin.document.body).setStyle(this.savedStyles); this.instanceDoc = this.frameWin.document.defaultView; - + this.heightUpdate(); this.frameDoc.addEvent('mousedown', this.selected.closureListener(this)).addEvent('keyup',this.heightUpdate.closureListener(this)).addEvent('keydown',this.keyDown.closureListener(this)).addEvent('keyup',this.selected.closure(this)); this.ne.fireEvent('add',this); }, - + getElm : function() { return this.frameContent; }, - + setContent : function(c) { this.content = c; this.ne.fireEvent('set',this); - this.frameContent.innerHTML = this.content; + this.frameContent.innerHTML = this.content; this.heightUpdate(); }, - + getSel : function() { return (this.frameWin) ? this.frameWin.getSelection() : this.frameDoc.selection; }, - - heightUpdate : function() { + + heightUpdate : function() { this.elmFrame.style.height = Math.max(this.frameContent.offsetHeight,this.initialHeight)+'px'; }, - + nicCommand : function(cmd,args) { this.frameDoc.execCommand(cmd,false,args); setTimeout(this.heightUpdate.closure(this),100); } - -}); + +}); var nicEditorPanel = bkClass.extend({ construct : function(e,options,nicEditor) { this.elm = e; @@ -655,7 +657,7 @@ var nicEditorPanel = bkClass.extend({ this.ne = nicEditor; this.panelButtons = new Array(); this.buttonList = bkExtend([],this.ne.options.buttonList); - + this.panelContain = new bkElement('DIV').setStyle({overflow : 'hidden', width : '100%', border : '1px solid #cccccc', backgroundColor : '#efefef'}).addClass('panelContain'); this.panelElm = new bkElement('DIV').setStyle({margin : '2px', marginTop : '0px', zoom : 1, overflow : 'hidden'}).addClass('panel').appendTo(this.panelContain); this.panelContain.appendTo(e); @@ -668,26 +670,26 @@ var nicEditorPanel = bkClass.extend({ this.reorder(); e.noSelect(); }, - + addButton : function(buttonName,options,noOrder) { var button = options.buttons[buttonName]; var type = (button['type']) ? eval('(typeof('+button['type']+') == "undefined") ? null : '+button['type']+';') : nicEditorButton; var hasButton = bkLib.inArray(this.buttonList,buttonName); if(type && (hasButton || this.ne.options.fullPanel)) { this.panelButtons.push(new type(this.panelElm,buttonName,options,this.ne)); - if(!hasButton) { + if(!hasButton) { this.buttonList.push(buttonName); } } }, - + findButton : function(itm) { for(var i=0;i'+this.sel[itm]+''); - } + } } }); var nicEditorFontFamilySelect = nicEditorSelect.extend({ - sel : {'arial' : 'Arial','comic sans ms' : 'Comic Sans','courier new' : 'Courier New','georgia' : 'Georgia', 'helvetica' : 'Helvetica', 'impact' : 'Impact', 'times new roman' : 'Times', 'trebuchet ms' : 'Trebuchet', 'verdana' : 'Verdana'}, - + sel : {'sans-serif':__('Sans-Serif'), 'serif':__('Serif'), 'fantasy':__('Fantasy'), 'monospace':__('Monospace'), 'cursive':__('Cursive'), 'georgia':'Georgia'}, + init : function() { - this.setDisplay('Font Family...'); + this.setDisplay(__('Font Family...')); for(itm in this.sel) { this.add(itm,''+this.sel[itm]+''); } @@ -1163,10 +1165,10 @@ var nicEditorFontFamilySelect = nicEditorSelect.extend({ }); var nicEditorFontFormatSelect = nicEditorSelect.extend({ - sel : {'p' : 'Paragraph', 'pre' : 'Pre', 'h6' : 'Heading 6', 'h5' : 'Heading 5', 'h4' : 'Heading 4', 'h3' : 'Heading 3', 'h2' : 'Heading 2', 'h1' : 'Heading 1'}, - + sel : {'p' : __('Paragraph'), 'pre' : __('Pre'), 'h6' : __('Heading 6'), 'h5' : __('Heading 5'), 'h4' : __('Heading 4'), 'h3' : __('Heading 3'), 'h2' : __('Heading 2'), 'h1' : __('Heading 1')}, + init : function() { - this.setDisplay('Font Format...'); + this.setDisplay(__('Font Format...')); for(itm in this.sel) { var tag = itm.toUpperCase(); this.add('<'+tag+'>','<'+itm+' style="padding: 0px; margin: 0px;">'+this.sel[itm]+''); @@ -1174,38 +1176,38 @@ var nicEditorFontFormatSelect = nicEditorSelect.extend({ } }); -nicEditors.registerPlugin(nicPlugin,nicSelectOptions); - +nicEditors.registerPlugin(nicPlugin,nicSelectOptions); + /* START CONFIG */ var nicLinkOptions = { buttons : { - 'link' : {name : 'Add Link', type : 'nicLinkButton', tags : ['A']}, - 'unlink' : {name : 'Remove Link', command : 'unlink', noActive : true} + 'link' : {name : __('Add Link'), type : 'nicLinkButton', tags : ['A']}, + 'unlink' : {name : __('Remove Link'), command : 'unlink', noActive : true} } }; /* END CONFIG */ -var nicLinkButton = nicEditorAdvancedButton.extend({ +var nicLinkButton = nicEditorAdvancedButton.extend({ addPane : function() { this.ln = this.ne.selectedInstance.selElm().parentTag('A'); this.addForm({ - '' : {type : 'title', txt : 'Add/Edit Link'}, + '' : {type : 'title', txt : __('Add/Edit Link')}, 'href' : {type : 'text', txt : 'URL', value : 'http://', style : {width: '150px'}}, - 'title' : {type : 'text', txt : 'Title'}, - 'target' : {type : 'select', txt : 'Open In', options : {'' : 'Current Window', '_blank' : 'New Window'},style : {width : '100px'}} + 'title' : {type : 'text', txt : __('Hint')}, + 'target' : {type : 'select', txt : __('Open In'), options : {'' : __('Current Window'), '_blank' : __('New Window')},style : {width : '100px'}} },this.ln); }, - + submit : function(e) { var url = this.inputs['href'].value; if(url == "http://" || url == "") { - alert("You must enter a URL to Create a Link"); + alert(__("You must enter a URL to Create a Link")); return false; } this.removePane(); - + if(!this.ln) { var tmp = 'javascript:nicTemp();'; this.ne.nicCommand("createlink",tmp); @@ -1221,8 +1223,8 @@ var nicLinkButton = nicEditorAdvancedButton.extend({ } }); -nicEditors.registerPlugin(nicPlugin,nicLinkOptions); - +nicEditors.registerPlugin(nicPlugin,nicLinkOptions); + /* START CONFIG */ @@ -1234,41 +1236,41 @@ var nicColorOptions = { }; /* END CONFIG */ -var nicEditorColorButton = nicEditorAdvancedButton.extend({ +var nicEditorColorButton = nicEditorAdvancedButton.extend({ addPane : function() { var colorList = {0 : '00',1 : '33',2 : '66',3 :'99',4 : 'CC',5 : 'FF'}; var colorItems = new bkElement('DIV').setStyle({width: '270px'}); - + for(var r in colorList) { for(var b in colorList) { for(var g in colorList) { var colorCode = '#'+colorList[r]+colorList[g]+colorList[b]; - + var colorSquare = new bkElement('DIV').setStyle({'cursor' : 'pointer', 'height' : '15px', 'float' : 'left'}).appendTo(colorItems); var colorBorder = new bkElement('DIV').setStyle({border: '2px solid '+colorCode}).appendTo(colorSquare); var colorInner = new bkElement('DIV').setStyle({backgroundColor : colorCode, overflow : 'hidden', width : '11px', height : '11px'}).addEvent('click',this.colorSelect.closure(this,colorCode)).addEvent('mouseover',this.on.closure(this,colorBorder)).addEvent('mouseout',this.off.closure(this,colorBorder,colorCode)).appendTo(colorBorder); - + if(!window.opera) { colorSquare.onmousedown = colorInner.onmousedown = bkLib.cancelEvent; } - } - } + } + } } - this.pane.append(colorItems.noSelect()); + this.pane.append(colorItems.noSelect()); }, - + colorSelect : function(c) { this.ne.nicCommand('foreColor',c); this.removePane(); }, - + on : function(colorBorder) { colorBorder.setStyle({border : '2px solid #000'}); }, - + off : function(colorBorder,colorCode) { - colorBorder.setStyle({border : '2px solid '+colorCode}); + colorBorder.setStyle({border : '2px solid '+colorCode}); } }); @@ -1276,37 +1278,37 @@ var nicEditorBgColorButton = nicEditorColorButton.extend({ colorSelect : function(c) { this.ne.nicCommand('hiliteColor',c); this.removePane(); - } + } }); -nicEditors.registerPlugin(nicPlugin,nicColorOptions); - +nicEditors.registerPlugin(nicPlugin,nicColorOptions); + /* START CONFIG */ var nicImageOptions = { buttons : { - 'image' : {name : 'Add Image', type : 'nicImageButton', tags : ['IMG']} + 'image' : {name : __('Add Image'), type : 'nicImageButton', tags : ['IMG']} } - + }; /* END CONFIG */ -var nicImageButton = nicEditorAdvancedButton.extend({ +var nicImageButton = nicEditorAdvancedButton.extend({ addPane : function() { this.im = this.ne.selectedInstance.selElm().parentTag('IMG'); this.addForm({ - '' : {type : 'title', txt : 'Add/Edit Image'}, + '' : {type : 'title', txt : __('Add/Edit Image')}, 'src' : {type : 'text', txt : 'URL', 'value' : 'http://', style : {width: '150px'}}, - 'alt' : {type : 'text', txt : 'Alt Text', style : {width: '100px'}}, - 'align' : {type : 'select', txt : 'Align', options : {none : 'Default','left' : 'Left', 'right' : 'Right'}} + 'alt' : {type : 'text', txt : __('Alt Text'), style : {width: '100px'}}, + 'align' : {type : 'select', txt : __('Align'), options : {none : __('Inline'),'left' : __('Left'), 'right' : __('Right')}} },this.im); }, - + submit : function(e) { var src = this.inputs['src'].value; if(src == "" || src == "http://") { - alert("You must enter a Image URL to insert"); + alert(__("You must enter a Image URL to insert")); return false; } this.removePane(); @@ -1320,6 +1322,7 @@ var nicImageButton = nicEditorAdvancedButton.extend({ this.im.setAttributes({ src : this.inputs['src'].value, alt : this.inputs['alt'].value, + title : this.inputs['alt'].value, align : this.inputs['align'].value }); } @@ -1327,161 +1330,135 @@ var nicImageButton = nicEditorAdvancedButton.extend({ }); nicEditors.registerPlugin(nicPlugin,nicImageOptions); - - -/* START CONFIG */ -var nicSaveOptions = { - buttons : { - 'save' : {name : __('Save this content'), type : 'nicEditorSaveButton'} - } -}; -/* END CONFIG */ - -var nicEditorSaveButton = nicEditorButton.extend({ - init : function() { - if(!this.ne.options.onSave) { - this.margin.setStyle({'display' : 'none'}); - } - }, - mouseClick : function() { - var onSave = this.ne.options.onSave; - var selectedInstance = this.ne.selectedInstance; - onSave(selectedInstance.getContent(), selectedInstance.elm.id, selectedInstance); - } -}); - -nicEditors.registerPlugin(nicPlugin,nicSaveOptions); - - /* START CONFIG */ var nicUploadOptions = { buttons : { - 'upload' : {name : 'Upload Image', type : 'nicUploadButton'} + 'upload' : {name : __('Upload Image'), type : 'nicUploadButton'} } - + }; /* END CONFIG */ -var nicUploadButton = nicEditorAdvancedButton.extend({ +var nicUploadButton = nicEditorAdvancedButton.extend({ nicURI : 'http://api.imgur.com/2/upload.json', - errorText : 'Failed to upload image', + errorText : __('Failed to upload image'), addPane : function() { - if(typeof window.FormData === "undefined") { - return this.onError("Image uploads are not supported in this browser, use Chrome, Firefox, or Safari instead."); - } - this.im = this.ne.selectedInstance.selElm().parentTag('IMG'); + if(typeof window.FormData === "undefined") { + return this.onError(__("Image uploads are not supported in this browser, use Chrome, Firefox, or Safari instead.")); + } + this.im = this.ne.selectedInstance.selElm().parentTag('IMG'); - var container = new bkElement('div') - .setStyle({ padding: '10px' }) - .appendTo(this.pane.pane); + var container = new bkElement('div') + .setStyle({ padding: '10px' }) + .appendTo(this.pane.pane); new bkElement('div') - .setStyle({ fontSize: '14px', fontWeight : 'bold', paddingBottom: '5px' }) - .setContent('Insert an Image') - .appendTo(container); + .setStyle({ fontSize: '14px', fontWeight : 'bold', paddingBottom: '5px' }) + .setContent(__('Insert an Image')) + .appendTo(container); - this.fileInput = new bkElement('input') - .setAttributes({ 'type' : 'file' }) - .appendTo(container); + this.fileInput = new bkElement('input') + .setAttributes({ 'type' : 'file' }) + .appendTo(container); - this.progress = new bkElement('progress') - .setStyle({ width : '100%', display: 'none' }) - .setAttributes('max', 100) - .appendTo(container); + this.progress = new bkElement('progress') + .setStyle({ width : '100%', display: 'none' }) + .setAttributes('max', 100) + .appendTo(container); - this.fileInput.onchange = this.uploadFile.closure(this); + this.fileInput.onchange = this.uploadFile.closure(this); }, - onError : function(msg) { - this.removePane(); - alert(msg || "Failed to upload image"); - }, + onError : function(msg) { + this.removePane(); + alert(msg || __("Failed to upload image")); + }, - uploadFile : function() { - var file = this.fileInput.files[0]; - if (!file || !file.type.match(/image.*/)) { - this.onError("Only image files can be uploaded"); - return; - } - this.fileInput.setStyle({ display: 'none' }); - this.setProgress(0); + uploadFile : function() { + var file = this.fileInput.files[0]; + if (!file || !file.type.match(/image.*/)) { + this.onError(__("Only image files can be uploaded")); + return; + } + this.fileInput.setStyle({ display: 'none' }); + this.setProgress(0); - var fd = new FormData(); // https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/ - fd.append("image", file); - fd.append("key", "b7ea18a4ecbda8e92203fa4968d10660"); - var xhr = new XMLHttpRequest(); - xhr.open("POST", this.ne.options.uploadURI || this.nicURI); + var fd = new FormData(); // https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/ + fd.append("image", file); + fd.append("key", "b7ea18a4ecbda8e92203fa4968d10660"); + var xhr = new XMLHttpRequest(); + xhr.open("POST", this.ne.options.uploadURI || this.nicURI); - xhr.onload = function() { - try { - var res = JSON.parse(xhr.responseText); - } catch(e) { - return this.onError(); - } - this.onUploaded(res.upload); - }.closure(this); - xhr.onerror = this.onError.closure(this); - xhr.upload.onprogress = function(e) { - this.setProgress(e.loaded / e.total); - }.closure(this); - xhr.send(fd); - }, + xhr.onload = function() { + try { + var res = JSON.parse(xhr.responseText); + } catch(e) { + return this.onError(); + } + this.onUploaded(res.upload); + }.closure(this); + xhr.onerror = this.onError.closure(this); + xhr.upload.onprogress = function(e) { + this.setProgress(e.loaded / e.total); + }.closure(this); + xhr.send(fd); + }, - setProgress : function(percent) { - this.progress.setStyle({ display: 'block' }); - if(percent < .98) { - this.progress.value = percent; - } else { - this.progress.removeAttribute('value'); - } - }, + setProgress : function(percent) { + this.progress.setStyle({ display: 'block' }); + if(percent < .98) { + this.progress.value = percent; + } else { + this.progress.removeAttribute('value'); + } + }, - onUploaded : function(options) { - this.removePane(); - var src = options.links.original; - if(!this.im) { - this.ne.selectedInstance.restoreRng(); - var tmp = 'javascript:nicImTemp();'; - this.ne.nicCommand("insertImage", src); - this.im = this.findElm('IMG','src', src); - } - var w = parseInt(this.ne.selectedInstance.elm.getStyle('width')); - if(this.im) { - this.im.setAttributes({ - src : src, - width : (w && options.image.width) ? Math.min(w, options.image.width) : '' - }); - } - } + onUploaded : function(options) { + this.removePane(); + var src = options.links.original; + if(!this.im) { + this.ne.selectedInstance.restoreRng(); + var tmp = 'javascript:nicImTemp();'; + this.ne.nicCommand("insertImage", src); + this.im = this.findElm('IMG','src', src); + } + var w = parseInt(this.ne.selectedInstance.elm.getStyle('width')); + if(this.im) { + this.im.setAttributes({ + src : src, + width : (w && options.image.width) ? Math.min(w, options.image.width) : '' + }); + } + } }); nicEditors.registerPlugin(nicPlugin,nicUploadOptions); - - + + var nicXHTML = bkClass.extend({ stripAttributes : ['_moz_dirty','_moz_resizing','_extended'], noShort : ['style','title','script','textarea','a'], cssReplace : {'font-weight:bold;' : 'strong', 'font-style:italic;' : 'em'}, sizes : {1 : 'xx-small', 2 : 'x-small', 3 : 'small', 4 : 'medium', 5 : 'large', 6 : 'x-large'}, - + construct : function(nicEditor) { this.ne = nicEditor; if(this.ne.options.xhtml) { nicEditor.addEvent('get',this.cleanup.closure(this)); } }, - + cleanup : function(ni) { var node = ni.getElm(); var xhtml = this.toXHTML(node); ni.content = xhtml; }, - + toXHTML : function(n,r,d) { var txt = ''; var attrTxt = ''; @@ -1490,11 +1467,11 @@ var nicXHTML = bkClass.extend({ var nName = n.nodeName.toLowerCase(); var nChild = n.hasChildNodes && n.hasChildNodes(); var extraNodes = new Array(); - + switch(nType) { case 1: var nAttributes = n.attributes; - + switch(nName) { case 'b': nName = 'strong'; @@ -1506,18 +1483,18 @@ var nicXHTML = bkClass.extend({ nName = 'span'; break; } - + if(r) { for(var i=0;i'; } - + if(attrTxt == "" && nName == "span") { r = false; } @@ -1562,9 +1539,7 @@ var nicXHTML = bkClass.extend({ } } } - - if(!nChild && !bkLib.inArray(this.noShort,attributeName)) { if(r) { txt += ' />'; @@ -1573,7 +1548,7 @@ var nicXHTML = bkClass.extend({ if(r) { txt += '>'; } - + for(var i=0;i'; } - + for(var i=0;i'; } @@ -1597,34 +1572,33 @@ var nicXHTML = bkClass.extend({ //} break; } - + return txt; } }); nicEditors.registerPlugin(nicXHTML); - - + /* START CONFIG */ var nicCodeOptions = { buttons : { - 'xhtml' : {name : 'Edit HTML', type : 'nicCodeButton'} + 'xhtml' : {name : __('Edit HTML'), type : 'nicCodeButton'} } - + }; /* END CONFIG */ var nicCodeButton = nicEditorAdvancedButton.extend({ width : '350px', - + addPane : function() { this.addForm({ - '' : {type : 'title', txt : 'Edit HTML'}, + '' : {type : 'title', txt : __('Edit HTML')}, 'code' : {type : 'content', 'value' : this.ne.selectedInstance.getContent(), style : {width: '340px', height : '200px'}} }); }, - + submit : function(e) { var code = this.inputs['code'].value; this.ne.selectedInstance.setContent(code); @@ -1633,5 +1607,3 @@ var nicCodeButton = nicEditorAdvancedButton.extend({ }); nicEditors.registerPlugin(nicPlugin,nicCodeOptions); - - diff --git a/nicRu.js b/nicRu.js new file mode 100644 index 0000000..99483eb --- /dev/null +++ b/nicRu.js @@ -0,0 +1,81 @@ +/* Russian localisation for NicEdit - Micro Inline WYSIWYG + * Copyright 2012 Vitaliy Filippov + * + * This file is distributed under the terms of the MIT license + */ + +var nicRu = { + 'Submit': 'Сохранить', + + 'Click to Bold': 'Полужирный', + 'Click to Italic': 'Курсив', + 'Click to Underline': 'Подчёркнутый', + 'Left Align': 'По левому краю', + 'Center Align': 'По центру', + 'Right Align': 'По правому краю', + 'Justify Align': 'По ширине', + 'Insert Ordered List': 'Нумерованный список', + 'Insert Unordered List': 'Маркированный список', + 'Click to Subscript': 'Нижний индекс', + 'Click to Superscript': 'Верхний индекс', + 'Click to Strike Through': 'Зачёркнутый', + 'Remove Formatting': 'Убрать форматирование', + 'Indent Text': 'Увеличить отступ', + 'Remove Indent': 'Уменьшить отступ', + 'Horizontal Rule': 'Горизонтальная линия', + + 'Font Size...': 'Размер...', + 'Font Family...': 'Шрифт...', + 'Font Format...': 'Формат...', + 'Select Font Size': 'Выберите размер шрифта', + 'Select Font Family': 'Выберите шрифт', + 'Select Font Format': 'Выберите формат абзаца', + 'Sans-Serif': 'Беззасечный', + 'Serif': 'С засечками', + 'Fantasy': 'Декоративный', + 'Monospace': 'Моноширинный', + 'Cursive': 'Рукописный', + 'Paragraph': 'Обычный', + 'Pre': 'Код', + 'Heading 6': 'Заголовок 6', + 'Heading 5': 'Заголовок 5', + 'Heading 4': 'Заголовок 4', + 'Heading 3': 'Заголовок 3', + 'Heading 2': 'Заголовок 2', + 'Heading 1': 'Заголовок 1', + + 'Change Text Color': 'Цвет текста', + 'Change Background Color': 'Цвет фона', + + 'Save this content': 'Сохранить', + + 'Add Link': 'Вставить ссылку', + 'Remove Link': 'Убрать ссылку', + 'Add/Edit Link': 'Ссылка', + 'Hint': 'Хинт', + 'Open In': 'Открыть', + 'Current Window': 'В этом окне', + 'New Window': 'В новом окне', + 'You must enter a URL to Create a Link': 'Чтобы создать ссылку, введите её URL', + + 'Add Image': 'Вставить картинку', + 'Add/Edit Image': 'Картинка', + 'Alt Text': 'Подсказка', + 'Align': 'Положение', + 'Inline': 'В тексте', + 'Left': 'Слева', + 'Right': 'Справа', + 'Insert an Image': 'Вставить картинку', + 'You must enter a Image URL to insert': 'Чтобы вставить картинку, введите её URL', + + 'Upload Image': 'Загрузить картинку', + 'Failed to upload image': 'Ошибка загрузки картинки', + 'Only image files can be uploaded': 'Так загружать можно только картинки', + 'Image uploads are not supported in this browser, use Chrome, Firefox, or Safari instead.': 'Чтобы загружать картинки, используйте современный браузер - Chrome, Firefox, или Safari.', + + 'Edit HTML': 'Править HTML-код' +}; + +function __(s) { + return nicRu[s] || s; +};