Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | 325fe554ea | |
Vitaliy Filippov | 8051a6ff28 | |
Vitaliy Filippov | 465d6f41d1 | |
parhelionix | ea38538bcc | |
Vitaliy Filippov | 854d63da40 |
|
@ -0,0 +1,9 @@
|
|||
NicEdit License
|
||||
|
||||
Copyright (c) 2007-2008 Brian Kirchoff [(http://nicedit.com)](http://nicedit.com), (c) 2012+ Vitaliy Filippov (vitalif@mail.ru)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,12 @@
|
|||
nicEdit is a lightweight, Cross Platform WYSIWYG editor
|
||||
|
||||
This is my (Vitaliy Filippov's) fork of nicEdit which I use in my projects since 2012.
|
||||
|
||||
It has several improvements:
|
||||
* Table plugin
|
||||
* Example plugins for "wiki-like CMS integrated" image uploads and link insertions
|
||||
* Russian localisation
|
||||
* Reworked nicFloatingPanel
|
||||
* Sanitize pasted HTML plugin (removes all the crap that MSWord inserts)
|
||||
|
||||
Not sure if it's easy to merge all this to upstream, but I'll try... maybe :)
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
cat nicRu.js nicCore.js nicPane.js nicAdvancedButton.js nicButtonTips.js \
|
||||
nicFontSelect.js nicColors.js nicXHTML.js nicCodeButton.js nicTable.js nicFloatingPanel.js \
|
||||
nicSanitize.js sanitize-html.js > nicEdit.js
|
||||
yui-compressor nicEdit.js > nicEdit.min.js
|
|
@ -0,0 +1,110 @@
|
|||
/** nicAdvancedButton */
|
||||
|
||||
var nicEditorAdvancedButton = nicEditorButton.extend({
|
||||
|
||||
init : function() {
|
||||
this.ne.addEvent('selected',this.removePane.closure(this)).addEvent('blur',this.removePane.closure(this));
|
||||
},
|
||||
|
||||
mouseClick : function() {
|
||||
if(!this.isDisabled) {
|
||||
if(this.pane && this.pane.pane) {
|
||||
this.removePane();
|
||||
} else {
|
||||
this.pane = new nicEditorPane(this.contain,this.ne,{width : (this.width || '270px'), backgroundColor : '#fff'},this);
|
||||
this.addPane();
|
||||
this.ne.selectedInstance.saveRng();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addForm : function(f,elm) {
|
||||
this.form = new bkElement('form').setAttributes({className: 'niceabf'}).addEvent('submit',this.submit.closureListener(this));
|
||||
this.pane.append(this.form);
|
||||
this.inputs = {};
|
||||
if (!document._nicCss) {
|
||||
document._nicCss = document.createElement('style');
|
||||
document._nicCss.appendChild(document.createTextNode(
|
||||
'.niceabf table { border-collapse: collapse; }\n'+
|
||||
'.niceabf td { padding: 2px 5px 2px 0; }\n'+
|
||||
'.niceabf td.h { vertical-align: top; padding-top: 4px; white-space: nowrap; }\n'+
|
||||
'.niceabf h2 { font-size: 14px; font-weight: bold; padding: 0; margin: 0; }\n'+
|
||||
'.niceabf input, .niceabf select { text-transform: none; font-weight: normal; height: auto; padding: 1px; vertical-align: middle; font-size: 13px; border: 1px solid #ccc; }\n'+
|
||||
'.niceabf textarea { border: 1px solid #ccc; }\n'+
|
||||
'.niceabf input.button { background-color: #efefef; color: black; margin: 3px 0; }\n'
|
||||
));
|
||||
document.getElementsByTagName('head')[0].appendChild(document._nicCss);
|
||||
}
|
||||
var tab, tr, td;
|
||||
|
||||
for(itm in f) {
|
||||
var field = f[itm];
|
||||
var val = '';
|
||||
if(elm) {
|
||||
val = elm.getAttribute(itm);
|
||||
}
|
||||
if(!val) {
|
||||
val = field['value'] || '';
|
||||
}
|
||||
var type = f[itm].type;
|
||||
|
||||
if(type == 'title') {
|
||||
new bkElement('h2').setContent(field.txt).appendTo(this.form);
|
||||
} else {
|
||||
if (!tab) {
|
||||
tab = new bkElement('table').appendTo(this.form);
|
||||
}
|
||||
tr = new bkElement('tr').appendTo(tab);
|
||||
if(field.txt) {
|
||||
td = new bkElement('td').setAttributes({className: 'h'}).appendTo(tr);
|
||||
new bkElement('label').setAttributes({htmlFor: itm}).setContent(field.txt).appendTo(td);
|
||||
}
|
||||
td = new bkElement('td').appendTo(tr);
|
||||
if(!field.txt) {
|
||||
td.setAttributes({colspan: 2});
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case 'text':
|
||||
this.inputs[itm] = new bkElement('input').setAttributes({id: itm, value: val, type: 'text'}).setStyle(field.style).appendTo(td);
|
||||
break;
|
||||
case 'select':
|
||||
this.inputs[itm] = new bkElement('select').setAttributes({id: itm}).appendTo(td);
|
||||
for(opt in field.options) {
|
||||
var o = new bkElement('option').setAttributes({value: opt, selected: (opt == val) ? 'selected' : ''}).setContent(field.options[opt]).appendTo(this.inputs[itm]);
|
||||
}
|
||||
break;
|
||||
case 'content':
|
||||
this.inputs[itm] = new bkElement('textarea').setAttributes({id: itm}).setStyle(field.style).appendTo(td);
|
||||
this.inputs[itm].value = val;
|
||||
break;
|
||||
case 'container':
|
||||
this.inputs[itm] = td;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
new bkElement('input').setAttributes({type: 'submit', value: __('Submit'), className: 'button'}).appendTo(this.form);
|
||||
this.form.onsubmit = bkLib.cancelEvent;
|
||||
},
|
||||
|
||||
submit : function() { },
|
||||
|
||||
findElm : function(tag,attr,val) {
|
||||
var list = this.ne.selectedInstance.getElm().getElementsByTagName(tag);
|
||||
for(var i=0;i<list.length;i++) {
|
||||
if(list[i].getAttribute(attr) == val) {
|
||||
return $BK(list[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
removePane : function() {
|
||||
if(this.pane) {
|
||||
this.pane.remove();
|
||||
this.pane = null;
|
||||
this.ne.selectedInstance.restoreRng();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/** nicButtonTips */
|
||||
|
||||
var nicButtonTips = bkClass.extend({
|
||||
construct : function(nicEditor) {
|
||||
this.ne = nicEditor;
|
||||
nicEditor.addEvent('buttonOver',this.show.closure(this)).addEvent('buttonOut',this.hide.closure(this));
|
||||
|
||||
},
|
||||
|
||||
show : function(button) {
|
||||
this.timer = setTimeout(this.create.closure(this,button),400);
|
||||
},
|
||||
|
||||
create : function(button) {
|
||||
this.timer = null;
|
||||
if(!this.pane) {
|
||||
this.pane = new nicEditorPane(button.button,this.ne,{fontSize : '12px', marginTop : '5px'});
|
||||
this.pane.setContent(button.options.name);
|
||||
}
|
||||
},
|
||||
|
||||
hide : function(button) {
|
||||
if(this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
if(this.pane) {
|
||||
this.pane = this.pane.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
nicEditors.registerPlugin(nicButtonTips);
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/** nicCode */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicCodeOptions = {
|
||||
buttons : {
|
||||
'xhtml' : {name : __('Edit HTML'), type : 'nicCodeButton'}
|
||||
}
|
||||
|
||||
};
|
||||
/* END CONFIG */
|
||||
|
||||
var nicCodeButton = nicEditorAdvancedButton.extend({
|
||||
width : '350px',
|
||||
|
||||
addPane : function() {
|
||||
this.addForm({
|
||||
'' : {type : 'title', txt : __('Edit HTML')},
|
||||
'code' : {type : 'content', 'value' : this.ne.selectedInstance.getContent(), style : {width: '340px', height : '200px'}}
|
||||
});
|
||||
},
|
||||
|
||||
submit : function(e) {
|
||||
var code = this.inputs['code'].value;
|
||||
this.ne.selectedInstance.setContent(code);
|
||||
this.removePane();
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicPlugin,nicCodeOptions);
|
|
@ -0,0 +1,58 @@
|
|||
/** nicColors */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicColorOptions = {
|
||||
buttons : {
|
||||
'forecolor' : {name : __('Change Text Color'), type : 'nicEditorColorButton', noClose : true},
|
||||
'bgcolor' : {name : __('Change Background Color'), type : 'nicEditorBgColorButton', noClose : true}
|
||||
}
|
||||
};
|
||||
/* END CONFIG */
|
||||
|
||||
var nicEditorColorButton = nicEditorAdvancedButton.extend({
|
||||
addPane : function() {
|
||||
var colorList = {0 : '00',1 : '33',2 : '66',3 :'99',4 : 'CC',5 : 'FF'};
|
||||
var colorItems = new bkElement('DIV').setStyle({width: '270px'});
|
||||
|
||||
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());
|
||||
},
|
||||
|
||||
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});
|
||||
}
|
||||
});
|
||||
|
||||
var nicEditorBgColorButton = nicEditorColorButton.extend({
|
||||
colorSelect : function(c) {
|
||||
this.ne.nicCommand('hiliteColor',c);
|
||||
this.removePane();
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicPlugin,nicColorOptions);
|
||||
|
|
@ -734,7 +734,14 @@ var nicEditorPanel = bkClass.extend({
|
|||
|
||||
addButton : function(buttonName,options,noOrder) {
|
||||
var button = options.buttons[buttonName];
|
||||
var type = (button['type']) ? eval('(typeof('+button['type']+') == "undefined") ? null : '+button['type']+';') : nicEditorButton;
|
||||
var type = null;
|
||||
|
||||
if (button['type']) {
|
||||
type = typeof(window[button['type']]) == undefined ? null : window[button['type']];
|
||||
}
|
||||
else {
|
||||
type = nicEditorButton;
|
||||
}
|
||||
var hasButton = bkLib.inArray(this.buttonList,buttonName);
|
||||
if(type && (hasButton || this.ne.options.fullPanel)) {
|
||||
this.panelButtons.push(new type(this.panelElm,buttonName,options,this.ne));
|
||||
|
@ -928,679 +935,3 @@ var nicPlugin = bkClass.extend({
|
|||
init : function() { }
|
||||
});
|
||||
|
||||
/** nicPane */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicPaneOptions = { };
|
||||
/* END CONFIG */
|
||||
|
||||
var nicEditorPane = bkClass.extend({
|
||||
construct : function(elm,nicEditor,options,openButton) {
|
||||
this.ne = nicEditor;
|
||||
this.elm = elm;
|
||||
this.pos = elm.pos();
|
||||
|
||||
this.contain = new bkElement('div').setStyle({zIndex: '999', overflow: 'hidden', position: 'absolute', left: this.pos[0]+'px', top : (this.pos[1]+elm.offsetHeight)+'px'})
|
||||
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);
|
||||
|
||||
if(openButton && !openButton.options.noClose) {
|
||||
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);
|
||||
}
|
||||
|
||||
this.contain.noSelect().appendTo(document.body);
|
||||
|
||||
this.position();
|
||||
this.init();
|
||||
},
|
||||
|
||||
init : function() { },
|
||||
|
||||
position : function() {
|
||||
if(this.ne.nicPanel) {
|
||||
var panelElm = this.ne.nicPanel.elm;
|
||||
var panelPos = panelElm.pos();
|
||||
var newLeft = panelPos[0]+parseInt(panelElm.getStyle('width'))-(parseInt(this.pane.getStyle('width'))+8);
|
||||
if(newLeft < this.pos[0]) {
|
||||
this.contain.setStyle({left : newLeft+'px'});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
toggle : function() {
|
||||
this.isVisible = !this.isVisible;
|
||||
this.contain.setStyle({display : ((this.isVisible) ? 'block' : 'none')});
|
||||
},
|
||||
|
||||
remove : function() {
|
||||
if(this.contain) {
|
||||
this.contain.remove();
|
||||
this.contain = null;
|
||||
}
|
||||
},
|
||||
|
||||
append : function(c) {
|
||||
c.appendTo(this.pane);
|
||||
},
|
||||
|
||||
setContent : function(c) {
|
||||
this.pane.setContent(c);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/** nicAdvancedButton */
|
||||
|
||||
var nicEditorAdvancedButton = nicEditorButton.extend({
|
||||
|
||||
init : function() {
|
||||
this.ne.addEvent('selected',this.removePane.closure(this)).addEvent('blur',this.removePane.closure(this));
|
||||
},
|
||||
|
||||
mouseClick : function() {
|
||||
if(!this.isDisabled) {
|
||||
if(this.pane && this.pane.pane) {
|
||||
this.removePane();
|
||||
} else {
|
||||
this.pane = new nicEditorPane(this.contain,this.ne,{width : (this.width || '270px'), backgroundColor : '#fff'},this);
|
||||
this.addPane();
|
||||
this.ne.selectedInstance.saveRng();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addForm : function(f,elm) {
|
||||
this.form = new bkElement('form').setAttributes({className: 'niceabf'}).addEvent('submit',this.submit.closureListener(this));
|
||||
this.pane.append(this.form);
|
||||
this.inputs = {};
|
||||
if (!document._nicCss) {
|
||||
document._nicCss = document.createElement('style');
|
||||
document._nicCss.appendChild(document.createTextNode(
|
||||
'.niceabf table { border-collapse: collapse; }\n'+
|
||||
'.niceabf td { padding: 2px 5px 2px 0; }\n'+
|
||||
'.niceabf td.h { vertical-align: top; padding-top: 4px; white-space: nowrap; }\n'+
|
||||
'.niceabf h2 { font-size: 14px; font-weight: bold; padding: 0; margin: 0; }\n'+
|
||||
'.niceabf input, .niceabf select { text-transform: none; font-weight: normal; height: auto; padding: 1px; vertical-align: middle; font-size: 13px; border: 1px solid #ccc; }\n'+
|
||||
'.niceabf textarea { border: 1px solid #ccc; }\n'+
|
||||
'.niceabf input.button { background-color: #efefef; color: black; margin: 3px 0; }\n'
|
||||
));
|
||||
document.getElementsByTagName('head')[0].appendChild(document._nicCss);
|
||||
}
|
||||
var tab, tr, td;
|
||||
|
||||
for(itm in f) {
|
||||
var field = f[itm];
|
||||
var val = '';
|
||||
if(elm) {
|
||||
val = elm.getAttribute(itm);
|
||||
}
|
||||
if(!val) {
|
||||
val = field['value'] || '';
|
||||
}
|
||||
var type = f[itm].type;
|
||||
|
||||
if(type == 'title') {
|
||||
new bkElement('h2').setContent(field.txt).appendTo(this.form);
|
||||
} else {
|
||||
if (!tab) {
|
||||
tab = new bkElement('table').appendTo(this.form);
|
||||
}
|
||||
tr = new bkElement('tr').appendTo(tab);
|
||||
if(field.txt) {
|
||||
td = new bkElement('td').setAttributes({className: 'h'}).appendTo(tr);
|
||||
new bkElement('label').setAttributes({htmlFor: itm}).setContent(field.txt).appendTo(td);
|
||||
}
|
||||
td = new bkElement('td').appendTo(tr);
|
||||
if(!field.txt) {
|
||||
td.setAttributes({colspan: 2});
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case 'text':
|
||||
this.inputs[itm] = new bkElement('input').setAttributes({id: itm, value: val, type: 'text'}).setStyle(field.style).appendTo(td);
|
||||
break;
|
||||
case 'select':
|
||||
this.inputs[itm] = new bkElement('select').setAttributes({id: itm}).appendTo(td);
|
||||
for(opt in field.options) {
|
||||
var o = new bkElement('option').setAttributes({value: opt, selected: (opt == val) ? 'selected' : ''}).setContent(field.options[opt]).appendTo(this.inputs[itm]);
|
||||
}
|
||||
break;
|
||||
case 'content':
|
||||
this.inputs[itm] = new bkElement('textarea').setAttributes({id: itm}).setStyle(field.style).appendTo(td);
|
||||
this.inputs[itm].value = val;
|
||||
break;
|
||||
case 'container':
|
||||
this.inputs[itm] = td;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
new bkElement('input').setAttributes({type: 'submit', value: __('Submit'), className: 'button'}).appendTo(this.form);
|
||||
this.form.onsubmit = bkLib.cancelEvent;
|
||||
},
|
||||
|
||||
submit : function() { },
|
||||
|
||||
findElm : function(tag,attr,val) {
|
||||
var list = this.ne.selectedInstance.getElm().getElementsByTagName(tag);
|
||||
for(var i=0;i<list.length;i++) {
|
||||
if(list[i].getAttribute(attr) == val) {
|
||||
return $BK(list[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
removePane : function() {
|
||||
if(this.pane) {
|
||||
this.pane.remove();
|
||||
this.pane = null;
|
||||
this.ne.selectedInstance.restoreRng();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/** nicButtonTips */
|
||||
|
||||
var nicButtonTips = bkClass.extend({
|
||||
construct : function(nicEditor) {
|
||||
this.ne = nicEditor;
|
||||
nicEditor.addEvent('buttonOver',this.show.closure(this)).addEvent('buttonOut',this.hide.closure(this));
|
||||
|
||||
},
|
||||
|
||||
show : function(button) {
|
||||
this.timer = setTimeout(this.create.closure(this,button),400);
|
||||
},
|
||||
|
||||
create : function(button) {
|
||||
this.timer = null;
|
||||
if(!this.pane) {
|
||||
this.pane = new nicEditorPane(button.button,this.ne,{fontSize : '12px', marginTop : '5px'});
|
||||
this.pane.setContent(button.options.name);
|
||||
}
|
||||
},
|
||||
|
||||
hide : function(button) {
|
||||
if(this.timer) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
if(this.pane) {
|
||||
this.pane = this.pane.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
nicEditors.registerPlugin(nicButtonTips);
|
||||
|
||||
/** nicSelect */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicSelectOptions = {
|
||||
buttons : {
|
||||
'fontSize' : {name : __('Select Font Size'), type : 'nicEditorFontSizeSelect', command : 'fontsize'},
|
||||
'fontFamily' : {name : __('Select Font Family'), type : 'nicEditorFontFamilySelect', command : 'fontname'},
|
||||
'fontFormat' : {name : __('Select Font Format'), type : 'nicEditorFontFormatSelect', command : 'formatBlock'}
|
||||
}
|
||||
};
|
||||
/* END CONFIG */
|
||||
var nicEditorSelect = bkClass.extend({
|
||||
|
||||
construct : function(e,buttonName,options,nicEditor) {
|
||||
this.options = options.buttons[buttonName];
|
||||
this.elm = e;
|
||||
this.ne = nicEditor;
|
||||
this.name = buttonName;
|
||||
this.selOptions = new Array();
|
||||
|
||||
this.margin = new bkElement('div').setStyle({'float' : 'left', margin : '2px 1px 0 1px'}).appendTo(this.elm);
|
||||
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);
|
||||
this.items = new bkElement('div').setStyle({overflow : 'hidden', zoom : 1, border: '1px solid #ccc', paddingLeft : '3px', backgroundColor : '#fff'}).appendTo(this.contain);
|
||||
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);
|
||||
this.txt = new bkElement('div').setStyle({overflow : 'hidden', 'float' : 'left', width : '66px', height : '14px', marginTop : '1px', fontFamily : 'sans-serif', textAlign : 'center', fontSize : '12px'}).addClass('selectTxt').appendTo(this.items);
|
||||
|
||||
if(!window.opera) {
|
||||
this.contain.onmousedown = this.control.onmousedown = this.txt.onmousedown = bkLib.cancelEvent;
|
||||
}
|
||||
|
||||
this.margin.noSelect();
|
||||
|
||||
this.ne.addEvent('selected', this.enable.closure(this)).addEvent('blur', this.disable.closure(this));
|
||||
|
||||
this.disable();
|
||||
this.init();
|
||||
},
|
||||
|
||||
disable : function() {
|
||||
this.isDisabled = true;
|
||||
this.close();
|
||||
this.contain.setStyle({opacity : 0.6});
|
||||
},
|
||||
|
||||
enable : function(t) {
|
||||
this.isDisabled = false;
|
||||
this.close();
|
||||
this.contain.setStyle({opacity : 1});
|
||||
},
|
||||
|
||||
setDisplay : function(txt) {
|
||||
this.txt.setContent(txt);
|
||||
},
|
||||
|
||||
toggle : function() {
|
||||
if(!this.isDisabled) {
|
||||
(this.pane) ? this.close() : this.open();
|
||||
}
|
||||
},
|
||||
|
||||
open : function() {
|
||||
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'});
|
||||
|
||||
for(var i=0;i<this.selOptions.length;i++) {
|
||||
var opt = this.selOptions[i];
|
||||
var itmContain = new bkElement('div').setStyle({overflow : 'hidden', borderBottom : '1px solid #ccc', width: '88px', textAlign : 'left', overflow : 'hidden', cursor : 'pointer'});
|
||||
var itm = new bkElement('div').setStyle({padding : '0px 4px'}).setContent(opt[1]).appendTo(itmContain).noSelect();
|
||||
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]);
|
||||
this.pane.append(itmContain);
|
||||
if(!window.opera) {
|
||||
itm.onmousedown = bkLib.cancelEvent;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
close : function() {
|
||||
if(this.pane) {
|
||||
this.pane = this.pane.remove();
|
||||
}
|
||||
},
|
||||
|
||||
over : function(opt) {
|
||||
opt.setStyle({backgroundColor : '#ccc'});
|
||||
},
|
||||
|
||||
out : function(opt) {
|
||||
opt.setStyle({backgroundColor : '#fff'});
|
||||
},
|
||||
|
||||
|
||||
add : function(k,v) {
|
||||
this.selOptions.push(new Array(k,v));
|
||||
},
|
||||
|
||||
update : function(elm) {
|
||||
this.ne.nicCommand(this.options.command,elm);
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
|
||||
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...'));
|
||||
for(itm in this.sel) {
|
||||
this.add(itm,'<font size="'+itm+'">'+this.sel[itm]+'</font>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var nicEditorFontFamilySelect = nicEditorSelect.extend({
|
||||
sel : {'sans-serif':__('Sans-Serif'), 'serif':__('Serif'), 'fantasy':__('Fantasy'), 'monospace':__('Monospace'), 'cursive':__('Cursive'), 'georgia':'Georgia'},
|
||||
|
||||
init : function() {
|
||||
this.setDisplay(__('Font Family...'));
|
||||
for(itm in this.sel) {
|
||||
this.add(itm,'<font face="'+itm+'">'+this.sel[itm]+'</font>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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')},
|
||||
|
||||
init : function() {
|
||||
this.setDisplay(__('Font Format...'));
|
||||
for(itm in this.sel) {
|
||||
var tag = itm.toUpperCase();
|
||||
this.add('<'+tag+'>','<'+itm+' style="padding: 0px; margin: 0px;">'+this.sel[itm]+'</'+tag+'>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicPlugin,nicSelectOptions);
|
||||
|
||||
/** nicColors */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicColorOptions = {
|
||||
buttons : {
|
||||
'forecolor' : {name : __('Change Text Color'), type : 'nicEditorColorButton', noClose : true},
|
||||
'bgcolor' : {name : __('Change Background Color'), type : 'nicEditorBgColorButton', noClose : true}
|
||||
}
|
||||
};
|
||||
/* END CONFIG */
|
||||
|
||||
var nicEditorColorButton = nicEditorAdvancedButton.extend({
|
||||
addPane : function() {
|
||||
var colorList = {0 : '00',1 : '33',2 : '66',3 :'99',4 : 'CC',5 : 'FF'};
|
||||
var colorItems = new bkElement('DIV').setStyle({width: '270px'});
|
||||
|
||||
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());
|
||||
},
|
||||
|
||||
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});
|
||||
}
|
||||
});
|
||||
|
||||
var nicEditorBgColorButton = nicEditorColorButton.extend({
|
||||
colorSelect : function(c) {
|
||||
this.ne.nicCommand('hiliteColor',c);
|
||||
this.removePane();
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicPlugin,nicColorOptions);
|
||||
|
||||
/** nicXHTML */
|
||||
|
||||
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 = '';
|
||||
var cssTxt = '';
|
||||
var nType = n.nodeType;
|
||||
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';
|
||||
break;
|
||||
case 'i':
|
||||
nName = 'em';
|
||||
break;
|
||||
case 'font':
|
||||
nName = 'span';
|
||||
break;
|
||||
}
|
||||
|
||||
if(r) {
|
||||
for(var i=0;i<nAttributes.length;i++) {
|
||||
var attr = nAttributes[i];
|
||||
|
||||
var attributeName = attr.nodeName.toLowerCase();
|
||||
var attributeValue = attr.nodeValue;
|
||||
|
||||
if(!attr.specified || !attributeValue || bkLib.inArray(this.stripAttributes,attributeName) || typeof(attributeValue) == "function") {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(attributeName) {
|
||||
case 'style':
|
||||
var css = attributeValue.replace(/ /g,"");
|
||||
for(itm in this.cssReplace) {
|
||||
if(css.indexOf(itm) != -1) {
|
||||
extraNodes.push(this.cssReplace[itm]);
|
||||
css = css.replace(itm,'');
|
||||
}
|
||||
}
|
||||
cssTxt += css;
|
||||
attributeValue = "";
|
||||
break;
|
||||
case 'class':
|
||||
attributeValue = attributeValue.replace("Apple-style-span","");
|
||||
break;
|
||||
case 'size':
|
||||
cssTxt += "font-size:"+this.sizes[attributeValue]+';';
|
||||
attributeValue = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if(attributeValue) {
|
||||
attrTxt += ' '+attributeName+'="'+attributeValue+'"';
|
||||
}
|
||||
}
|
||||
|
||||
if(cssTxt) {
|
||||
attrTxt += ' style="'+cssTxt+'"';
|
||||
}
|
||||
|
||||
for(var i=0;i<extraNodes.length;i++) {
|
||||
txt += '<'+extraNodes[i]+'>';
|
||||
}
|
||||
|
||||
if(attrTxt == "" && nName == "span") {
|
||||
r = false;
|
||||
}
|
||||
if(r) {
|
||||
txt += '<'+nName;
|
||||
if(nName != 'br') {
|
||||
txt += attrTxt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!nChild && !bkLib.inArray(this.noShort,attributeName)) {
|
||||
if(r) {
|
||||
txt += ' />';
|
||||
}
|
||||
} else {
|
||||
if(r) {
|
||||
txt += '>';
|
||||
}
|
||||
|
||||
for(var i=0;i<n.childNodes.length;i++) {
|
||||
var results = this.toXHTML(n.childNodes[i],true,true);
|
||||
if(results) {
|
||||
txt += results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(r && nChild) {
|
||||
txt += '</'+nName+'>';
|
||||
}
|
||||
|
||||
for(var i=0;i<extraNodes.length;i++) {
|
||||
txt += '</'+extraNodes[i]+'>';
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
//if(n.nodeValue != '\n') {
|
||||
txt += n.nodeValue;
|
||||
//}
|
||||
break;
|
||||
}
|
||||
|
||||
return txt;
|
||||
}
|
||||
});
|
||||
nicEditors.registerPlugin(nicXHTML);
|
||||
|
||||
/** nicCode */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicCodeOptions = {
|
||||
buttons : {
|
||||
'xhtml' : {name : __('Edit HTML'), type : 'nicCodeButton'}
|
||||
}
|
||||
|
||||
};
|
||||
/* END CONFIG */
|
||||
|
||||
var nicCodeButton = nicEditorAdvancedButton.extend({
|
||||
width : '350px',
|
||||
|
||||
addPane : function() {
|
||||
this.addForm({
|
||||
'' : {type : 'title', txt : __('Edit HTML')},
|
||||
'code' : {type : 'content', 'value' : this.ne.selectedInstance.getContent(), style : {width: '340px', height : '200px'}}
|
||||
});
|
||||
},
|
||||
|
||||
submit : function(e) {
|
||||
var code = this.inputs['code'].value;
|
||||
this.ne.selectedInstance.setContent(code);
|
||||
this.removePane();
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicPlugin,nicCodeOptions);
|
||||
|
||||
/** nicTable (c) Vitaliy Filippov */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicTableOptions = {
|
||||
buttons : {
|
||||
'table' : {name : __('Add Table'), type : 'nicTableButton', tags : ['TABLE']}
|
||||
}
|
||||
|
||||
};
|
||||
/* END CONFIG */
|
||||
|
||||
var nicTableButton = nicEditorAdvancedButton.extend({
|
||||
addPane: function() {
|
||||
this.t = this.ne.selectedInstance.selElm().parentTag('TABLE');
|
||||
var r = 3, c = 3, h = '', b = 'yes';
|
||||
if (this.t && (r = this.t.rows.length)) {
|
||||
c = this.t.rows[0].cells.length;
|
||||
if (this.t.rows[0].cells[c-1].nodeName == 'TH') h += 'top';
|
||||
if (this.t.rows[r-1].cells[0].nodeName == 'TH') h += 'left';
|
||||
if (this.t.className.indexOf('bordered') < 0) b = 'no';
|
||||
}
|
||||
this.addForm({
|
||||
'': {type: 'title', txt: __('Add/Edit Table')},
|
||||
'cols': {type: 'text', txt: __('Columns'), value: c, style: {width: '50px'}},
|
||||
'rows': {type: 'text', txt: __('Rows'), value: r, style: {width: '50px'}},
|
||||
'header': {type: 'select', txt: __('Headers'), value: h, options: {'':__('None'), left:__('Left'), top:__('Top'), topleft:__('Top and Left')}},
|
||||
'bordered': {type: 'select', txt: __('Borders'), value: b, options: {'no':__('No'), 'yes':__('Yes')}}
|
||||
},this.t);
|
||||
},
|
||||
|
||||
submit: function(e) {
|
||||
var r = parseInt(this.inputs['rows'].value);
|
||||
var c = parseInt(this.inputs['cols'].value);
|
||||
var cl = this.inputs['bordered'].value == 'no' ? '' : 'bordered';
|
||||
var i, j;
|
||||
if(!this.t) {
|
||||
var tmp = 'javascript:nicImTemp();', h = '';
|
||||
for (i = 0; i < r; i++) {
|
||||
h += '<tr>'+(new Array(c+1)).join('<td>-</td>')+'</tr>';
|
||||
}
|
||||
this.ne.nicCommand("insertHTML", '<table title="'+tmp+'">'+h+'</table>');
|
||||
this.t = this.findElm('TABLE','title',tmp);
|
||||
}
|
||||
if(this.t) {
|
||||
this.t.className = cl;
|
||||
this.t.removeAttribute('title');
|
||||
for (i = this.t.rows.length-1; i >= r; i--) {
|
||||
this.t.deleteRow(r);
|
||||
}
|
||||
for (i = this.t.rows.length; i < r; i++) {
|
||||
this.t.insertRow(i).innerHTML = (new Array(c+1)).join('<td>-</td>');
|
||||
}
|
||||
if (this.t.rows.length && this.t.rows[0].cells.length != c) {
|
||||
for (i = 0; i < r; i++) {
|
||||
for (j = this.t.rows[i].cells.length; j < c; j++) {
|
||||
this.t.rows[i].insertCell(j).innerHTML = '-';
|
||||
}
|
||||
for (j = this.t.rows[i].cells.length-1; j >= c; j--) {
|
||||
$BK(this.t.rows[i].cells[c]).remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.t.rows.length) {
|
||||
var ht = this.inputs['header'].value;
|
||||
var repl = function(node, name) {
|
||||
var nn = document.createElement(name ? 'th' : 'td');
|
||||
nn.innerHTML = node.innerHTML;
|
||||
node.parentNode.insertBefore(nn, node);
|
||||
node.parentNode.removeChild(node);
|
||||
};
|
||||
repl(this.t.rows[0].cells[0], ht != '');
|
||||
j = ht == 'top' || ht == 'topleft';
|
||||
for (i = 1; i < c; i++) {
|
||||
repl(this.t.rows[0].cells[i], j);
|
||||
}
|
||||
j = ht == 'left' || ht == 'topleft';
|
||||
for (i = 1; i < r; i++) {
|
||||
repl(this.t.rows[i].cells[0], j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicPlugin,nicTableOptions);
|
||||
|
||||
/** nicFloatingPanel */
|
||||
|
||||
nicEditor = nicEditor.extend({
|
||||
floatingPanel: function() {
|
||||
this.floating = new bkElement('DIV').setStyle({display: 'inline-block', position: 'absolute', left: '-1000px', top: '-1000px', zIndex: 100}).appendTo(document.body);
|
||||
this.addEvent('focus', this.reposition.closure(this)).addEvent('blur', this.hide.closure(this));
|
||||
bkLib.addEvent(window, 'scroll', this.reposition.closure(this));
|
||||
this.setPanel(this.floating);
|
||||
},
|
||||
|
||||
reposition: function() {
|
||||
var e = this.selectedInstance;
|
||||
if (!e || !(e = e.elm)) return;
|
||||
var h = this.floating.offsetHeight;
|
||||
var p = e.pos();
|
||||
var d = document;
|
||||
d = window.pageYOffset || d.body.scrollTop || d.documentElement.scrollTop;
|
||||
var top = p[1]-h;
|
||||
this.floating.setStyle({ top: (top < d ? d : top)+'px', left: p[0]+'px' });
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.floating.setStyle({ top: '-1000px', left: '-1000px' });
|
||||
}
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
/** nicFloatingPanel */
|
||||
|
||||
nicEditor = nicEditor.extend({
|
||||
floatingPanel: function() {
|
||||
this.floating = new bkElement('DIV').setStyle({display: 'inline-block', position: 'absolute', left: '-1000px', top: '-1000px', zIndex: 100}).appendTo(document.body);
|
||||
this.addEvent('focus', this.reposition.closure(this)).addEvent('blur', this.hide.closure(this));
|
||||
bkLib.addEvent(window, 'scroll', this.reposition.closure(this));
|
||||
this.setPanel(this.floating);
|
||||
},
|
||||
|
||||
reposition: function() {
|
||||
var e = this.selectedInstance;
|
||||
if (!e || !(e = e.elm)) return;
|
||||
var h = this.floating.offsetHeight;
|
||||
var p = e.pos();
|
||||
var d = document;
|
||||
d = window.pageYOffset || d.body.scrollTop || d.documentElement.scrollTop;
|
||||
var top = p[1]-h;
|
||||
this.floating.setStyle({ top: (top < d ? d : top)+'px', left: p[0]+'px' });
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.floating.setStyle({ top: '-1000px', left: '-1000px' });
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
/** nicSelect */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicSelectOptions = {
|
||||
buttons : {
|
||||
'fontSize' : {name : __('Select Font Size'), type : 'nicEditorFontSizeSelect', command : 'fontsize'},
|
||||
'fontFamily' : {name : __('Select Font Family'), type : 'nicEditorFontFamilySelect', command : 'fontname'},
|
||||
'fontFormat' : {name : __('Select Font Format'), type : 'nicEditorFontFormatSelect', command : 'formatBlock'}
|
||||
}
|
||||
};
|
||||
/* END CONFIG */
|
||||
var nicEditorSelect = bkClass.extend({
|
||||
|
||||
construct : function(e,buttonName,options,nicEditor) {
|
||||
this.options = options.buttons[buttonName];
|
||||
this.elm = e;
|
||||
this.ne = nicEditor;
|
||||
this.name = buttonName;
|
||||
this.selOptions = new Array();
|
||||
|
||||
this.margin = new bkElement('div').setStyle({'float' : 'left', margin : '2px 1px 0 1px'}).appendTo(this.elm);
|
||||
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);
|
||||
this.items = new bkElement('div').setStyle({overflow : 'hidden', zoom : 1, border: '1px solid #ccc', paddingLeft : '3px', backgroundColor : '#fff'}).appendTo(this.contain);
|
||||
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);
|
||||
this.txt = new bkElement('div').setStyle({overflow : 'hidden', 'float' : 'left', width : '66px', height : '14px', marginTop : '1px', fontFamily : 'sans-serif', textAlign : 'center', fontSize : '12px'}).addClass('selectTxt').appendTo(this.items);
|
||||
|
||||
if(!window.opera) {
|
||||
this.contain.onmousedown = this.control.onmousedown = this.txt.onmousedown = bkLib.cancelEvent;
|
||||
}
|
||||
|
||||
this.margin.noSelect();
|
||||
|
||||
this.ne.addEvent('selected', this.enable.closure(this)).addEvent('blur', this.disable.closure(this));
|
||||
|
||||
this.disable();
|
||||
this.init();
|
||||
},
|
||||
|
||||
disable : function() {
|
||||
this.isDisabled = true;
|
||||
this.close();
|
||||
this.contain.setStyle({opacity : 0.6});
|
||||
},
|
||||
|
||||
enable : function(t) {
|
||||
this.isDisabled = false;
|
||||
this.close();
|
||||
this.contain.setStyle({opacity : 1});
|
||||
},
|
||||
|
||||
setDisplay : function(txt) {
|
||||
this.txt.setContent(txt);
|
||||
},
|
||||
|
||||
toggle : function() {
|
||||
if(!this.isDisabled) {
|
||||
(this.pane) ? this.close() : this.open();
|
||||
}
|
||||
},
|
||||
|
||||
open : function() {
|
||||
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'});
|
||||
|
||||
for(var i=0;i<this.selOptions.length;i++) {
|
||||
var opt = this.selOptions[i];
|
||||
var itmContain = new bkElement('div').setStyle({overflow : 'hidden', borderBottom : '1px solid #ccc', width: '88px', textAlign : 'left', overflow : 'hidden', cursor : 'pointer'});
|
||||
var itm = new bkElement('div').setStyle({padding : '0px 4px'}).setContent(opt[1]).appendTo(itmContain).noSelect();
|
||||
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]);
|
||||
this.pane.append(itmContain);
|
||||
if(!window.opera) {
|
||||
itm.onmousedown = bkLib.cancelEvent;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
close : function() {
|
||||
if(this.pane) {
|
||||
this.pane = this.pane.remove();
|
||||
}
|
||||
},
|
||||
|
||||
over : function(opt) {
|
||||
opt.setStyle({backgroundColor : '#ccc'});
|
||||
},
|
||||
|
||||
out : function(opt) {
|
||||
opt.setStyle({backgroundColor : '#fff'});
|
||||
},
|
||||
|
||||
|
||||
add : function(k,v) {
|
||||
this.selOptions.push(new Array(k,v));
|
||||
},
|
||||
|
||||
update : function(elm) {
|
||||
this.ne.nicCommand(this.options.command,elm);
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
|
||||
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...'));
|
||||
for(itm in this.sel) {
|
||||
this.add(itm,'<font size="'+itm+'">'+this.sel[itm]+'</font>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var nicEditorFontFamilySelect = nicEditorSelect.extend({
|
||||
sel : {'sans-serif':__('Sans-Serif'), 'serif':__('Serif'), 'fantasy':__('Fantasy'), 'monospace':__('Monospace'), 'cursive':__('Cursive'), 'georgia':'Georgia'},
|
||||
|
||||
init : function() {
|
||||
this.setDisplay(__('Font Family...'));
|
||||
for(itm in this.sel) {
|
||||
this.add(itm,'<font face="'+itm+'">'+this.sel[itm]+'</font>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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')},
|
||||
|
||||
init : function() {
|
||||
this.setDisplay(__('Font Format...'));
|
||||
for(itm in this.sel) {
|
||||
var tag = itm.toUpperCase();
|
||||
this.add('<'+tag+'>','<'+itm+' style="padding: 0px; margin: 0px;">'+this.sel[itm]+'</'+tag+'>');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicPlugin,nicSelectOptions);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
/** nicImageUploadGT (Image + Upload + Lightbox support) */
|
||||
/** nicImageUploadGT (Image + Upload + Lightbox support) -- example image uploads integrated with wiki-like site CMS */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicImageUploadGTOptions = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/** nicLink */
|
||||
/** nicLinkGT -- example link insertion integrated with wiki-like site CMS */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicLinkGTOptions = {
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/** nicPane */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicPaneOptions = { };
|
||||
/* END CONFIG */
|
||||
|
||||
var nicEditorPane = bkClass.extend({
|
||||
construct : function(elm,nicEditor,options,openButton) {
|
||||
this.ne = nicEditor;
|
||||
this.elm = elm;
|
||||
this.pos = elm.pos();
|
||||
|
||||
this.contain = new bkElement('div').setStyle({zIndex: '999', overflow: 'hidden', position: 'absolute', left: this.pos[0]+'px', top : (this.pos[1]+elm.offsetHeight)+'px'})
|
||||
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);
|
||||
|
||||
if(openButton && !openButton.options.noClose) {
|
||||
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);
|
||||
}
|
||||
|
||||
this.contain.noSelect().appendTo(document.body);
|
||||
|
||||
this.position();
|
||||
this.init();
|
||||
},
|
||||
|
||||
init : function() { },
|
||||
|
||||
position : function() {
|
||||
if(this.ne.nicPanel) {
|
||||
var panelElm = this.ne.nicPanel.elm;
|
||||
var panelPos = panelElm.pos();
|
||||
var newLeft = panelPos[0]+parseInt(panelElm.getStyle('width'))-(parseInt(this.pane.getStyle('width'))+8);
|
||||
if(newLeft < this.pos[0]) {
|
||||
this.contain.setStyle({left : newLeft+'px'});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
toggle : function() {
|
||||
this.isVisible = !this.isVisible;
|
||||
this.contain.setStyle({display : ((this.isVisible) ? 'block' : 'none')});
|
||||
},
|
||||
|
||||
remove : function() {
|
||||
if(this.contain) {
|
||||
this.contain.remove();
|
||||
this.contain = null;
|
||||
}
|
||||
},
|
||||
|
||||
append : function(c) {
|
||||
c.appendTo(this.pane);
|
||||
},
|
||||
|
||||
setContent : function(c) {
|
||||
this.pane.setContent(c);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/** nicSanitize */
|
||||
|
||||
// Sanitize pasted HTML
|
||||
|
||||
var nicSanitize = bkClass.extend({
|
||||
construct: function(nicEditor)
|
||||
{
|
||||
this.ne = nicEditor;
|
||||
this.ne.addEvent('add', this.add.closure(this));
|
||||
},
|
||||
add: function(instance)
|
||||
{
|
||||
instance.elm.addEvent('paste', this.paste.closureListener(this));
|
||||
},
|
||||
paste: function(ev, target)
|
||||
{
|
||||
var d = ev.clipboardData || window.clipboardData;
|
||||
var h = d.getData('text/html') || d.getData('Text');
|
||||
if (h)
|
||||
{
|
||||
this.sanitizeCfg = this.sanitizeCfg || getSanitizeCfg();
|
||||
h = sanitizeHtml(h, this.sanitizeCfg);
|
||||
if (h)
|
||||
this.ne.nicCommand('insertHTML', h);
|
||||
bkLib.cancelEvent(ev);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicSanitize);
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/** nicTable (c) Vitaliy Filippov */
|
||||
|
||||
/* START CONFIG */
|
||||
var nicTableOptions = {
|
||||
buttons : {
|
||||
'table' : {name : __('Add Table'), type : 'nicTableButton', tags : ['TABLE']}
|
||||
}
|
||||
|
||||
};
|
||||
/* END CONFIG */
|
||||
|
||||
var nicTableButton = nicEditorAdvancedButton.extend({
|
||||
addPane: function() {
|
||||
this.t = this.ne.selectedInstance.selElm().parentTag('TABLE');
|
||||
var r = 3, c = 3, h = '', b = 'yes';
|
||||
if (this.t && (r = this.t.rows.length)) {
|
||||
c = this.t.rows[0].cells.length;
|
||||
if (this.t.rows[0].cells[c-1].nodeName == 'TH') h += 'top';
|
||||
if (this.t.rows[r-1].cells[0].nodeName == 'TH') h += 'left';
|
||||
if (this.t.className.indexOf('bordered') < 0) b = 'no';
|
||||
}
|
||||
this.addForm({
|
||||
'': {type: 'title', txt: __('Add/Edit Table')},
|
||||
'cols': {type: 'text', txt: __('Columns'), value: c, style: {width: '50px'}},
|
||||
'rows': {type: 'text', txt: __('Rows'), value: r, style: {width: '50px'}},
|
||||
'header': {type: 'select', txt: __('Headers'), value: h, options: {'':__('None'), left:__('Left'), top:__('Top'), topleft:__('Top and Left')}},
|
||||
'bordered': {type: 'select', txt: __('Borders'), value: b, options: {'no':__('No'), 'yes':__('Yes')}}
|
||||
},this.t);
|
||||
},
|
||||
|
||||
submit: function(e) {
|
||||
var r = parseInt(this.inputs['rows'].value);
|
||||
var c = parseInt(this.inputs['cols'].value);
|
||||
var cl = this.inputs['bordered'].value == 'no' ? '' : 'bordered';
|
||||
var i, j;
|
||||
if(!this.t) {
|
||||
var tmp = 'javascript:nicImTemp();', h = '';
|
||||
for (i = 0; i < r; i++) {
|
||||
h += '<tr>'+(new Array(c+1)).join('<td>-</td>')+'</tr>';
|
||||
}
|
||||
this.ne.nicCommand("insertHTML", '<table title="'+tmp+'">'+h+'</table>');
|
||||
this.t = this.findElm('TABLE','title',tmp);
|
||||
}
|
||||
if(this.t) {
|
||||
this.t.className = cl;
|
||||
this.t.removeAttribute('title');
|
||||
for (i = this.t.rows.length-1; i >= r; i--) {
|
||||
this.t.deleteRow(r);
|
||||
}
|
||||
for (i = this.t.rows.length; i < r; i++) {
|
||||
this.t.insertRow(i).innerHTML = (new Array(c+1)).join('<td>-</td>');
|
||||
}
|
||||
if (this.t.rows.length && this.t.rows[0].cells.length != c) {
|
||||
for (i = 0; i < r; i++) {
|
||||
for (j = this.t.rows[i].cells.length; j < c; j++) {
|
||||
this.t.rows[i].insertCell(j).innerHTML = '-';
|
||||
}
|
||||
for (j = this.t.rows[i].cells.length-1; j >= c; j--) {
|
||||
$BK(this.t.rows[i].cells[c]).remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.t.rows.length) {
|
||||
var ht = this.inputs['header'].value;
|
||||
var repl = function(node, name) {
|
||||
var nn = document.createElement(name ? 'th' : 'td');
|
||||
nn.innerHTML = node.innerHTML;
|
||||
node.parentNode.insertBefore(nn, node);
|
||||
node.parentNode.removeChild(node);
|
||||
};
|
||||
repl(this.t.rows[0].cells[0], ht != '');
|
||||
j = ht == 'top' || ht == 'topleft';
|
||||
for (i = 1; i < c; i++) {
|
||||
repl(this.t.rows[0].cells[i], j);
|
||||
}
|
||||
j = ht == 'left' || ht == 'topleft';
|
||||
for (i = 1; i < r; i++) {
|
||||
repl(this.t.rows[i].cells[0], j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
nicEditors.registerPlugin(nicPlugin,nicTableOptions);
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
/** nicXHTML */
|
||||
|
||||
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 = '';
|
||||
var cssTxt = '';
|
||||
var nType = n.nodeType;
|
||||
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';
|
||||
break;
|
||||
case 'i':
|
||||
nName = 'em';
|
||||
break;
|
||||
case 'font':
|
||||
nName = 'span';
|
||||
break;
|
||||
}
|
||||
|
||||
if(r) {
|
||||
for(var i=0;i<nAttributes.length;i++) {
|
||||
var attr = nAttributes[i];
|
||||
|
||||
var attributeName = attr.nodeName.toLowerCase();
|
||||
var attributeValue = attr.nodeValue;
|
||||
|
||||
if(!attr.specified || !attributeValue || bkLib.inArray(this.stripAttributes,attributeName) || typeof(attributeValue) == "function") {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(attributeName) {
|
||||
case 'style':
|
||||
var css = attributeValue.replace(/ /g,"");
|
||||
for(itm in this.cssReplace) {
|
||||
if(css.indexOf(itm) != -1) {
|
||||
extraNodes.push(this.cssReplace[itm]);
|
||||
css = css.replace(itm,'');
|
||||
}
|
||||
}
|
||||
cssTxt += css;
|
||||
attributeValue = "";
|
||||
break;
|
||||
case 'class':
|
||||
attributeValue = attributeValue.replace("Apple-style-span","");
|
||||
break;
|
||||
case 'size':
|
||||
cssTxt += "font-size:"+this.sizes[attributeValue]+';';
|
||||
attributeValue = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if(attributeValue) {
|
||||
attrTxt += ' '+attributeName+'="'+attributeValue+'"';
|
||||
}
|
||||
}
|
||||
|
||||
if(cssTxt) {
|
||||
attrTxt += ' style="'+cssTxt+'"';
|
||||
}
|
||||
|
||||
for(var i=0;i<extraNodes.length;i++) {
|
||||
txt += '<'+extraNodes[i]+'>';
|
||||
}
|
||||
|
||||
if(attrTxt == "" && nName == "span") {
|
||||
r = false;
|
||||
}
|
||||
if(r) {
|
||||
txt += '<'+nName;
|
||||
if(nName != 'br') {
|
||||
txt += attrTxt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!nChild && !bkLib.inArray(this.noShort,attributeName)) {
|
||||
if(r) {
|
||||
txt += ' />';
|
||||
}
|
||||
} else {
|
||||
if(r) {
|
||||
txt += '>';
|
||||
}
|
||||
|
||||
for(var i=0;i<n.childNodes.length;i++) {
|
||||
var results = this.toXHTML(n.childNodes[i],true,true);
|
||||
if(results) {
|
||||
txt += results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(r && nChild) {
|
||||
txt += '</'+nName+'>';
|
||||
}
|
||||
|
||||
for(var i=0;i<extraNodes.length;i++) {
|
||||
txt += '</'+extraNodes[i]+'>';
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
//if(n.nodeValue != '\n') {
|
||||
txt += n.nodeValue;
|
||||
//}
|
||||
break;
|
||||
}
|
||||
|
||||
return txt;
|
||||
}
|
||||
});
|
||||
nicEditors.registerPlugin(nicXHTML);
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
* DOM based HTML sanitizer
|
||||
* License: Mozilla Public License 2.0 or later version
|
||||
* (c) Vitaliy Filippov 2015+
|
||||
* Version 2015-08-11
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
window.getSanitizeCfg = function(nest, attr)
|
||||
{
|
||||
// Default configuration is for sanitizing pasted html
|
||||
if (!nest)
|
||||
{
|
||||
var inline = 'a b i strong em strike code tt sub sup br table span font';
|
||||
nest = {
|
||||
'hr br': '/',
|
||||
'p': '#text '+inline,
|
||||
'ul': 'li',
|
||||
'ol': 'li',
|
||||
'dl': 'dt dd',
|
||||
'table': 'tr thead tbody',
|
||||
'thead tbody': 'tr',
|
||||
'tr': 'td th',
|
||||
'* h1 h2 h3 h4 h5 h6 blockquote li dt dd pre td th': 'h1 h2 h3 h4 h5 h6 blockquote p ul ol dl pre hr #text '+inline,
|
||||
'td th': '/'
|
||||
};
|
||||
nest[inline] = '#text '+inline;
|
||||
}
|
||||
if (!attr)
|
||||
{
|
||||
attr = {
|
||||
'p': 'align',
|
||||
'a': 'href name target',
|
||||
'td': 'colspan rowspan',
|
||||
'th': 'colspan rowspan'
|
||||
};
|
||||
}
|
||||
var r = { nest: {}, attr: {} };
|
||||
for (var k in nest)
|
||||
{
|
||||
var v = nest[k];
|
||||
k = k.toUpperCase().split(' ');
|
||||
v = v.toUpperCase().split(' ');
|
||||
for (var i = 0; i < k.length; i++)
|
||||
{
|
||||
for (var j = 0; j < v.length; j++)
|
||||
{
|
||||
r.nest[k[i]] = r.nest[k[i]] || {};
|
||||
r.nest[k[i]][v[j]] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var k in attr)
|
||||
{
|
||||
var v = attr[k].split(' ');
|
||||
k = k.toUpperCase();
|
||||
r.attr[k] = {};
|
||||
for (var i = 0; i < v.length; i++)
|
||||
r.attr[k][v[i]] = true;
|
||||
}
|
||||
return r;
|
||||
};
|
||||
|
||||
window.sanitizeHtml = function(html, cfg)
|
||||
{
|
||||
var r = document.createElement('div');
|
||||
r.innerHTML = html;
|
||||
sanitize(r, true, cfg);
|
||||
return r.innerHTML.replace(/[ \t]*(\n[ \t]*)+/g, '\n').replace(/[ \t]{2,}/g, ' ').replace(/^\s*/, '');
|
||||
};
|
||||
|
||||
function sanitize(el, is_root, cfg)
|
||||
{
|
||||
var n = is_root ? '*' : el.nodeName;
|
||||
for (var i = 0; i < el.childNodes.length; i++)
|
||||
{
|
||||
var c = el.childNodes[i];
|
||||
if (c.nodeType != 1 && c.nodeType != 3 ||
|
||||
!cfg.nest[n][c.nodeType == 1 ? c.nodeName : '#TEXT'] ||
|
||||
c.nodeType == 1 && !sanitize(c, false, cfg))
|
||||
{
|
||||
// Keep contents of generally allowed tags which are just not in place
|
||||
if (c.nodeType == 1 && cfg.nest[c.nodeName])
|
||||
while (c.childNodes.length)
|
||||
el.insertBefore(c.childNodes[0], c);
|
||||
el.removeChild(c);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
if (!is_root)
|
||||
{
|
||||
for (var i = el.attributes.length-1; i >= 0; i--)
|
||||
if (!cfg.attr[n] || !cfg.attr[n][el.attributes[i].nodeName])
|
||||
el.removeAttribute(el.attributes[i].nodeName);
|
||||
if (el.nodeName == 'A' && !(el.getAttribute('href') || '').match(/^https?:\/\/|^mailto:/i))
|
||||
el.removeAttribute('href');
|
||||
if ((el.nodeName == 'A' || el.nodeName == 'SPAN' || el.nodeName == 'FONT') && !el.attributes.length ||
|
||||
el.innerHTML.match(/^\s*$/) && !cfg.nest[n]['/'])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
})();
|
Loading…
Reference in New Issue