/**
* NicEdit - Micro Inline WYSIWYG
* Copyright 2007-2008 Brian Kirchoff, http://nicedit.com/
* Copyright 2012-2015 Vitaliy Filippov, http://yourcmc.ru/wiki/nicEdit
* Version: 2015-08-12
*
* NicEdit is distributed under the terms of the MIT license
* Do not remove this copyright message
*/
var bkExtend = function(){
var args = arguments;
if (args.length == 1) args = [this, args[0]];
for (var prop in args[1]) args[0][prop] = args[1][prop];
return args[0];
};
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 bkElement = bkClass.extend({
construct : function(elm,d) {
if(typeof(elm) == "string") {
elm = (d || document).createElement(elm);
}
elm = $BK(elm);
return elm;
},
appendTo : function(elm) {
elm.appendChild(this);
return this;
},
appendBefore : function(elm) {
elm.parentNode.insertBefore(this,elm);
return this;
},
addEvent : function(type, fn) {
bkLib.addEvent(this,type,fn);
return this;
},
removeAllEvents : function() {
bkLib.removeAllEvents(this);
return this;
},
setContent : function(c) {
this.innerHTML = c;
return this;
},
pos : function() {
var curleft = curtop = 0;
var o = obj = this;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
var b = (!window.opera) ? parseInt(this.getStyle('border-width') || this.style.border) || 0 : 0;
return [curleft+b,curtop+b];
},
noSelect : function() {
bkLib.noSelect(this);
return this;
},
parentTag : function(t) {
var elm = this;
do {
if(elm && elm.nodeName && elm.nodeName.toUpperCase() == t) {
return elm;
}
elm = elm.parentNode;
} 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|$)'),' ');
}
return this;
},
setStyle : function(st) {
var elmStyle = this.style;
for(var itm in st) {
switch(itm) {
case 'float':
elmStyle['cssFloat'] = elmStyle['styleFloat'] = st[itm];
break;
case 'opacity':
elmStyle.opacity = st[itm];
elmStyle.filter = "alpha(opacity=" + Math.round(st[itm]*100) + ")";
break;
case 'className':
this.className = st[itm];
break;
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;
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;
},
setAttributes : function(at) {
for(var itm in at) {
this[itm] = at[itm];
}
return this;
}
});
var bkLib = {
isMSIE : (navigator.appVersion.indexOf("MSIE") != -1),
addEvent : function(obj, type, fn) {
obj._bkE = obj._bkE||[];
obj._bkE.push([type, fn]);
(obj.addEventListener) ? obj.addEventListener( type, fn, false ) : obj.attachEvent("on"+type, fn);
},
removeEvent : function(obj, type, fn) {
(obj.removeEventListener) ? obj.removeEventListener( type, fn, false ) : obj.detachEvent("on"+type, fn);
},
removeAllEvents : function(obj) {
if (!obj._bkE) return;
for (var i = 0; i < obj._bkE.length; i++) {
bkLib.removeEvent(obj,obj._bkE[i][0],obj._bkE[i][1]);
}
obj._bkE = [];
},
toArray : function(iterable) {
var length = iterable.length, results = new Array(length);
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');
}
for(var i=0;i');
}
this.instanceDoc = document.defaultView;
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) {
this.editorContain.remove();
this.e.setStyle({'display' : 'block'});
this.ne.removePanel();
}
this.elm.removeAllEvents();
this.disable();
this.ne.fireEvent('remove',this);
},
disable : function() {
this.elm.setAttribute('contentEditable','false');
},
getSel : function() {
return (window.getSelection) ? window.getSelection() : document.selection;
},
getRng : function() {
var s = this.getSel();
if (!s) return;
if (s.rangeCount > 0) {
return s.getRangeAt(0);
} else if (typeof s.createRange == 'undefined') {
return document.createRange();
}
return s.createRange();
},
selRng : function(rng,s) {
if(window.getSelection) {
s.removeAllRanges();
s.addRange(rng);
} else {
rng.select();
}
},
selElm : function() {
var r = this.getRng();
if(!r) { return; }
if(r.startContainer) {
var contain = r.startContainer;
if(r.cloneContents().childNodes.length == 1) {
for(var i=0;i'+((css) ? '' : '')+''+this.initialContent+'