Change default buttons, add localisation, remove nicSaveButton

master
vitalif 2012-10-02 22:55:20 +00:00 committed by Vitaliy Filippov
parent 557d27551e
commit 270f537abd
2 changed files with 458 additions and 405 deletions

View File

@ -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({
@ -149,8 +149,8 @@ var bkLib = {
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) {
@ -228,21 +228,23 @@ var bkEvent = {
}
};
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) );
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) );
};
}
@ -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,7 +271,7 @@ 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}
});
@ -868,7 +870,7 @@ var nicPlugin = bkClass.extend({
/* START CONFIG */
/* START CONFIG */
var nicPaneOptions = { };
/* END CONFIG */
@ -986,7 +988,7 @@ var nicEditorAdvancedButton = nicEditorButton.extend({
}
}
}
new bkElement('input').setAttributes({'type' : 'submit'}).setStyle({backgroundColor : '#efefef',border : '1px solid #ccc', margin : '3px 0', 'float' : 'left', 'clear' : 'both'}).appendTo(this.form);
new bkElement('input').setAttributes({'type': 'submit', 'value': __('Submit')}).setStyle({backgroundColor : '#efefef',border : '1px solid #ccc', margin : '3px 0', 'float' : 'left', 'clear' : 'both'}).appendTo(this.form);
this.form.onsubmit = bkLib.cancelEvent;
},
@ -1144,7 +1146,7 @@ var nicEditorSelect = bkClass.extend({
var nicEditorFontSizeSelect = nicEditorSelect.extend({
sel : {1 : '1 (8pt)', 2 : '2 (10pt)', 3 : '3 (12pt)', 4 : '4 (14pt)', 5 : '5 (18pt)', 6 : '6 (24pt)'},
init : function() {
this.setDisplay('Font Size...');
this.setDisplay(__('Font Size...'));
for(itm in this.sel) {
this.add(itm,'<font size="'+itm+'">'+this.sel[itm]+'</font>');
}
@ -1152,10 +1154,10 @@ var nicEditorFontSizeSelect = nicEditorSelect.extend({
});
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&nbsp;Family...');
this.setDisplay(__('Font&nbsp;Family...'));
for(itm in this.sel) {
this.add(itm,'<font face="'+itm+'">'+this.sel[itm]+'</font>');
}
@ -1163,10 +1165,10 @@ var nicEditorFontFamilySelect = nicEditorSelect.extend({
});
var nicEditorFontFormatSelect = nicEditorSelect.extend({
sel : {'p' : 'Paragraph', 'pre' : 'Pre', 'h6' : 'Heading&nbsp;6', 'h5' : 'Heading&nbsp;5', 'h4' : 'Heading&nbsp;4', 'h3' : 'Heading&nbsp;3', 'h2' : 'Heading&nbsp;2', 'h1' : 'Heading&nbsp;1'},
sel : {'p' : __('Paragraph'), 'pre' : __('Pre'), 'h6' : __('Heading&nbsp;6'), 'h5' : __('Heading&nbsp;5'), 'h4' : __('Heading&nbsp;4'), 'h3' : __('Heading&nbsp;3'), 'h2' : __('Heading&nbsp;2'), 'h1' : __('Heading&nbsp;1')},
init : function() {
this.setDisplay('Font&nbsp;Format...');
this.setDisplay(__('Font&nbsp;Format...'));
for(itm in this.sel) {
var tag = itm.toUpperCase();
this.add('<'+tag+'>','<'+itm+' style="padding: 0px; margin: 0px;">'+this.sel[itm]+'</'+tag+'>');
@ -1181,8 +1183,8 @@ 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 */
@ -1191,17 +1193,17 @@ 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();
@ -1286,7 +1288,7 @@ 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']}
}
};
@ -1296,17 +1298,17 @@ 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
});
}
@ -1330,36 +1333,10 @@ 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'}
}
};
@ -1367,96 +1344,96 @@ var nicUploadOptions = {
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);
@ -1563,8 +1540,6 @@ var nicXHTML = bkClass.extend({
}
}
if(!nChild && !bkLib.inArray(this.noShort,attributeName)) {
if(r) {
txt += ' />';
@ -1605,11 +1580,10 @@ nicEditors.registerPlugin(nicXHTML);
/* START CONFIG */
var nicCodeOptions = {
buttons : {
'xhtml' : {name : 'Edit HTML', type : 'nicCodeButton'}
'xhtml' : {name : __('Edit HTML'), type : 'nicCodeButton'}
}
};
@ -1620,7 +1594,7 @@ var nicCodeButton = nicEditorAdvancedButton.extend({
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'}}
});
},
@ -1633,5 +1607,3 @@ var nicCodeButton = nicEditorAdvancedButton.extend({
});
nicEditors.registerPlugin(nicPlugin,nicCodeOptions);

81
nicRu.js Normal file
View File

@ -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&nbsp;Size...': 'Размер...',
'Font&nbsp;Family...': 'Шрифт...',
'Font&nbsp;Format...': 'Формат...',
'Select Font Size': 'Выберите размер шрифта',
'Select Font Family': 'Выберите шрифт',
'Select Font Format': 'Выберите формат абзаца',
'Sans-Serif': 'Беззасечный',
'Serif': 'С засечками',
'Fantasy': 'Декоративный',
'Monospace': 'Моноширинный',
'Cursive': 'Рукописный',
'Paragraph': 'Обычный',
'Pre': 'Код',
'Heading&nbsp;6': 'Заголовок&nbsp;6',
'Heading&nbsp;5': 'Заголовок&nbsp;5',
'Heading&nbsp;4': 'Заголовок&nbsp;4',
'Heading&nbsp;3': 'Заголовок&nbsp;3',
'Heading&nbsp;2': 'Заголовок&nbsp;2',
'Heading&nbsp;1': 'Заголовок&nbsp;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;
};