");
ot.jq('#_tryitEditor_toolbar button').css({padding:'2px 1px 2px 1px', display:'inline-block', 'font-size':'14px','line-height':'1em', cursor:'pointer'});
ot.jq('#_tryitEditor_toolbar select').css({'font-size':'14px',padding:'2px',width:'60px',height:'25px'});
ot.jq('#_tryitEditor_toolbar select, #_tryitEditor_toolbar .button').css({cursor: 'pointer', margin:'2px 3px 4px 0', 'box-shadow': '#FFECEC 1px 1px 1px', border: '1px solid #ADADAD','background-color':'#fff','-webkit-border-radius':'3px', '-moz-border-radius':'3px', 'border-radius':'3px', 'vertical-align':'middle'});
var h = ot.tryitEditor.opt.html || ot.tryitEditor.__get_init();
if (opt.empty_str && h == opt.empty_str) {
h = '
';
}
if (!h) {
h = '
';
}
o.after("
"+h+"
");
o.after("");
o = ot.jq('#_tryitEditor_contents');
o.width(ot.tryitEditor.opt.width)
.css({'overflow-x':'auto', 'border-color':'#c0c0c0', 'border-style':'solid', 'border-width':'1px', 'padding':'5px', 'min-height':'20px'})
;
if (ot.tryitEditor.opt.body_css) {
ot.jq('#_tryitEditor_contents').addClass(ot.tryitEditor.opt.body_css);
}
ot.jq('#_tryitEditor_toolbar').width(ot.tryitEditor.opt.width-10);
if (ot.tryitEditor.opt.height) {
ot.jq('#_tryitEditor_contents').height(ot.tryitEditor.opt.height);
} else {
ot.jq('#_tryitEditor_toolbar_outer').height(ot.jq('#_tryitEditor_toolbar').height()+10);
if (ot.tryitEditor.navigator == 'firefox') {
ot.jq(document).scroll(ot.tryitEditor.__scroll);
} else {
ot.jq(window).scroll(ot.tryitEditor.__scroll);
}
}
if (opt.keydown) {
ot.jq('#_tryitEditor_contents').keydown(opt.keydown);
}
};
ot.tryitEditor.quit = function() {
if (typeof(ot.tryitEditor.opt.onquit) == "function") {
ot.tryitEditor.opt.onquit();
}
ot.jq('#_tryitEditor_toolbar_outer, #_tryitEditor_contents, #_tryitEditor_html').remove();
ot.jq(ot.tryitEditor.sel).show();
};
ot.tryitEditor.close = function() {
ot.jq('#_tryitEditor_toolbar_outer, #_tryitEditor_contents, #_tryitEditor_html').remove();
ot.jq(ot.tryitEditor.sel).html(ot.tryitEditor.html()).show();
};
ot.tryitEditor.check_instance = function() {
return ot.jq('#_tryitEditor_toolbar_outer, #_tryitEditor_contents, #_tryitEditor_html').length;
};
ot.tryitEditor.__get_init = function () {
var o = ot.jq(ot.tryitEditor.sel);
if (o[0] && o[0].tagName=='TEXTAREA') {
return o.val();
}
return o.html();
};
ot.tryitEditor.__scroll = function () {
var b = ot.jq('#_tryitEditor_toolbar');
if (!b.length) {ot.jq(window).unbind('scroll', ot.tryitEditor.__scroll);return;}
var a = ot.jq('#_tryitEditor_toolbar_outer');
if (ot.tryitEditor.navigator == 'mobile' && document.activeElement.id == '_tryitEditor_contents') {
return;
}
if (b.css('position') != 'fixed') {
if (a.offset().top < ot.jq(window).scrollTop()) {
b.css({'position':'fixed','top':'2px'});
}
} else {
var h = ot.jq('#_tryitEditor_toolbar').height();
if (a.offset().top > ot.jq(window).scrollTop()) {
b.css({'position':'relative'});
}
}
};
ot.tryitEditor.save_cursor = function () {
ot.tryitEditor.edit_rng = ot.tryitEditor.edit_obj = ot.tryitEditor.edit_objs = null;
ot.tryitEditor.edit_sel = document.getSelection();
if (ot.tryitEditor.edit_sel && ot.tryitEditor.edit_sel.type == 'None') { return; }
ot.tryitEditor.edit_rng = ot.tryitEditor.edit_sel.getRangeAt(0);
return ot.tryitEditor.edit_rng;
};
ot.tryitEditor.recov_cursor = function () {
var r = ot.tryitEditor.edit_rng;
if (r && ot.tryitEditor.edit_sel) {
ot.tryitEditor.edit_sel.removeAllRanges();
ot.tryitEditor.edit_sel.addRange(r);
}
};
ot.tryitEditor.__span_range = function () {
if (!ot.tryitEditor.edit_objs.length) { return; }
var step1 = function (r,oj) {
if (ot.tryitEditor.edit_objs.length == 1) {
var oj = ot.tryitEditor.edit_objs[0];
if (oj.nodeName=='#text') {
ot.tryitEditor.edit_objs[0] = oj.parentNode;
}
} else {
for (var i=0; i < ot.tryitEditor.edit_objs.length; ++i) {
var oj = ot.tryitEditor.edit_objs[i];
if (oj.nodeName=='#text') {
if (oj.nodeValue == oj.parentNode.innerText) {
ot.tryitEditor.edit_objs[i] = oj.parentNode;
}
}
}
}
};
var step2 = function (r,oj) {
var r = ot.tryitEditor.edit_rng;
if (!ot.tryitEditor.edit_objs.length || r.startContainer.id=='_tryitEditor_contents') { return; }
if (r.startContainer == r.endContainer) {
if (!r.startOffset || r.startOffset == r.endOffset) { return; }
var h = r.startContainer.textContent.substr(r.startOffset,r.endOffset-r.startOffset);
r.deleteContents();
var n = document.createElement("span");
ot.jq(n).text(h);
r.insertNode(n);
ot.tryitEditor.edit_objs[0] = n;
return;
}
if (r.startOffset) {
var h = r.startContainer.textContent.substr(r.startOffset);
var oj = r.startContainer;
var of = r.startOffset;
var ln = r.startContainer.textContent.length;
var rx = document.createRange();
rx.setStart(oj,of);
rx.setEnd(oj,ln);
ot.tryitEditor.edit_sel.addRange(rx);
rx.deleteContents();
var n = document.createElement("span");
ot.jq(n).text(h);
rx.insertNode(n);
ot.tryitEditor.edit_objs[0] = n;
} else {
var oj = ot.tryitEditor.edit_objs[0];
if (oj.nodeName=='#text') {
ot.tryitEditor.edit_objs[0] = oj.parentNode;
}
}
if (r.endContainer.nodeName == '#text' && r.endContainer.textContent.length > r.endOffset) {
var h = r.endContainer.textContent;
h = h.substr(0,r.endOffset);
var oj = r.endContainer;
var of = r.endOffset;
var rx = document.createRange();
rx.setStart(oj,0);
rx.setEnd(oj,of);
ot.tryitEditor.edit_sel.addRange(rx);
rx.deleteContents();
var n = document.createElement("span");
n.innerHTML = h;
rx.insertNode(n);
ot.tryitEditor.edit_objs[ot.tryitEditor.edit_objs.length-1] = n;
} else {
var oj = ot.tryitEditor.edit_objs[ot.tryitEditor.edit_objs.length-1];
if (oj.nodeName=='#text') {
if (ot.tryitEditor.edit_objs[0] == oj.parentNode) {
ot.tryitEditor.edit_objs.pop();
} else {
ot.tryitEditor.edit_objs[ot.tryitEditor.edit_objs.length-1] = oj.parentNode;
}
}
}
};
step1();
step2();
var n = [];
for (var j=0; j < ot.tryitEditor.edit_objs.length; ++j) {
var oj = ot.tryitEditor.edit_objs[j];
for (var i=0; i < n.length; ++i) {
if (n[i] == oj) { oj=false; break; }
}
if (oj && oj.nodeName!='#text') { n.push(oj); }
}
ot.tryitEditor.edit_objs = n;
if (ot.tryitEditor.edit_objs.length) {
ot.tryitEditor.edit_sel.removeAllRanges();
var r = ot.tryitEditor.edit_rng;
r.setStart(ot.tryitEditor.edit_objs[0],0);
r.setEnd(ot.tryitEditor.edit_objs[ot.tryitEditor.edit_objs.length-1],ot.tryitEditor.edit_objs[ot.tryitEditor.edit_objs.length-1].length);
ot.tryitEditor.edit_sel.addRange(r);
}
};
ot.tryitEditor.__get_cursor_objs = function (span_part) {
var r = ot.tryitEditor.save_cursor();
if (!r) {
return false;
}
var r = ot.tryitEditor.edit_rng;
var s = ot.tryitEditor.edit_sel;
var i = 0;
var x;
ot.tryitEditor.edit_objs = [];
var check_end = function (r,oj) {
var x;
if (oj == r.endContainer ) {
return oj;
}
if (!oj.childNodes || oj.childNodes.length == 0) {
if (oj.nextElementSibling) {
return check_end(r,oj.nextElementSibling);
}
return false;
}
for (var i=0; i < oj.childNodes.length; ++i) {
if (x = check_end(r,oj.childNodes[i])) {
return x;
}
}
return false;
};
var store_obj = function (oj) {
if (!oj) { return; }
if (oj.nodeName == '#text') {
var r = ot.tryitEditor.edit_rng;
if (oj.nodeValue == '') { return; }
if (r.startContainer == r.endContainer) {
if (r.startOffset != r.endOffset && r.endOffset!=1) {
var h = r.startContainer.textContent.substr(r.startOffset,r.endOffset-r.startOffset)
r.deleteContents();
ot.tryitEditor.edit_sel.removeAllRanges();
var n = document.createElement("span");
ot.jq(n).text(h);
r.insertNode(n);
ot.tryitEditor.edit_objs.push(n);
r.selectNode(n.childNodes[0]);
ot.tryitEditor.edit_sel.addRange(r);
return;
}
}
}
for (var i=0; i < ot.tryitEditor.edit_objs.length; ++i) {
if (ot.tryitEditor.edit_objs[i] == oj) { return; }
}
if (oj.nodeName == '#text' && oj.parentNode.id != '_tryitEditor_contents') {
oj = oj.parentNode;
}
ot.tryitEditor.edit_objs.push(oj);
};
if (r.startContainer == r.endContainer) {
//singe line select
if (r.startContainer.nodeName == '#text') {
x = r.startContainer;
store_obj(x);
} else {
if (r.commonAncestorContainer.childNodes && r.commonAncestorContainer.childNodes.length) {
if (r.commonAncestorContainer.childNodes.length == 1) {
x = r.commonAncestorContainer.childNodes[0];
if (x.tagName=='BR') {
x = x.parentNode;
}
store_obj(x);
} else {
for (var i=r.startOffset; i 0) {
ot.tryitEditor.__span_range();
return true;
}
return false;
}
//mult line select
var m = false;
var toj = r.startContainer;
if (toj.nodeName=='#text') {
toj = toj.parentNode;
}
for (i=0; i < r.commonAncestorContainer.childNodes.length; ++i) {
var oj = r.commonAncestorContainer.childNodes[i];
var x;
if (m == true) {
store_obj(oj);
if (x = check_end(r,oj)) {
store_obj(x);
return true;
}
} else {
if (oj == toj || oj == toj.parentNode) {
m = true;
store_obj(oj);
}
}
}
return false;
};
ot.tryitEditor.__open_form = function (h,btn) {
if (!btn) { btn = ''; }
ot.jq('#_tryitEditor_toolbar button, #_tryitEditor_toolbar input').attr('disabled','disabled').css('background-color','rgba(54, 52, 52, 0.66)');
var a = "
"+h+"
"+btn;
a += "
";
ot.jq('#_tryitEditor_toolbar').append(a);
ot.jq("#_tryitEditor_form input[type=button]").css({'border-radius':'1em','border':'none','background-color':'#fff','padding':'2px 10px','margin':'3px 5px'});
ot.jq("#_tryitEditor_form p").css({'margin':'5px'});
ot.jq('#_tryitEditor_form ._close').click(function(){
ot.tryitEditor.__close_form();
});
var x = ot.jq('#_tryitEditor_form').height() - ot.jq('#_tryitEditor_toolbar_outer').height();
if (x > ot.jq('#_tryitEditor_contents').height()) {
ot.jq('#_tryitEditor_contents').height(x+30);
}
};
ot.tryitEditor.__close_form = function (h,btn) {
ot.jq('#_tryitEditor_form').remove();
ot.jq('#_tryitEditor_toolbar button, #_tryitEditor_toolbar input').removeAttr('disabled').css('background-color','#fff');
};
ot.tryitEditor.__insertHTML = function (html) {
if (!ot.tryitEditor.__get_cursor_objs(false)) {
var h = ot.tryitEditor.html() + html;
if (h) {
var o = ot.jq('#_tryitEditor_contents');
if (o) {
if (ot.tryitEditor.navigator != 'firefox') {
o.html(h);
} else {
document.execCommand('selectAll',false);
document.execCommand('insertHTML',false,h);
}
}
return;
}
}
if (document.selection) {
var r = document.selection.createRange();
if (r.pasteHTML) {
if (ot.tryitEditor.ie9over) { document.execCommand("ms-beginUndoUnit"); }
r.pasteHTML(html);
if (ot.tryitEditor.ie9over) { document.execCommand("ms-endUndoUnit"); }
}
} else {
if (ot.tryitEditor.ie9over) {
document.execCommand("ms-beginUndoUnit");
var r = document.getSelection().getRangeAt(0);
r.deleteContents();
r.insertNode(r.createContextualFragment(html));
document.execCommand("ms-endUndoUnit");
} else {
document.execCommand('insertHTML',false,html);
}
}
};
ot.tryitEditor._undo = function () { if (!document.execCommand('undo',false)) { ot.jq('#_tryitEditor_contents').html(ot.tryitEditor.__get_init()); } };
ot.tryitEditor._redo = function () { document.execCommand('redo',false); };
ot.tryitEditor._ol = function () {
//document.execCommand('insertOrderedList',false); for chrome, ie bug
if (!ot.tryitEditor.__get_cursor_objs(true)) { return; }
if (ot.tryitEditor.ie9over) {document.execCommand("ms-beginUndoUnit");}
if (ot.tryitEditor.edit_objs.length) {
ot.tryitEditor.edit_sel.removeAllRanges();
var h = '';
for (var i=0; i"+ot.tryitEditor.edit_objs[i].innerText+"";
}
for (var i=0; i"+ot.tryitEditor.edit_objs[i].innerText+"";
}
for (var i=0; i", btn);
if (h) {
h = unescape(h); // for onethird tag
ot.jq('#_tryitEditor_form input[type=text]').val(h);
}
ot.jq('#_tryitEditor_form .ok').click(function(){
var a = ot.jq('#_tryitEditor_form input[type=text]').val();
ot.tryitEditor.__close_form();
if (ot.tryitEditor.edit_obj.tagName=='A') {
var h = a;
h = h.replace(/\"/g,"'"); // 'for onethird
ot.tryitEditor.edit_obj.href = h;
} else {
ot.tryitEditor.edit_obj.outerHTML = ""+ot.tryitEditor.edit_obj.textContent+"";
}
});
ot.jq('#_tryitEditor_form .remove').click(function(){
ot.tryitEditor.__close_form();
var r = ot.tryitEditor.edit_rng;
r.selectNode(ot.tryitEditor.edit_obj);
ot.tryitEditor.edit_sel.removeAllRanges();
ot.tryitEditor.edit_sel.addRange(r);
document.execCommand('unlink',false);
});
};
ot.tryitEditor._color = function() {
if (!ot.tryitEditor.__get_cursor_objs(true)) { return; }
var colours = [
"#ff8080"
,"#ffff80"
,"#80ff80"
,"#00ff80"
,"#80ffff"
,"#0080ff"
,"#ff80c0"
,"#ff80ff"
,"#ff0000"
,"#ffff00"
,"#80ff00"
,"#00ff40"
,"#00ffff"
,"#0080c0"
,"#8080c0"
,"#ff00ff"
,"#804040"
,"#ff8040"
,"#00ff00"
,"#008080"
,"#7292b2"
,"#8080ff"
,"#800040"
,"#ff0080"
,"#800000"
,"#ff8000"
,"#008000"
,"#008040"
,"#0000ff"
,"#0000a0"
,"#800080"
,"#8000ff"
,"#400000"
,"#804000"
,"#004000"
,"#004040"
,"#7272b2"
,"#000040"
,"#400040"
,"#9272b2"
,"#f0f0f0"
,"#808000"
,"#808040"
,"#808080"
,"#408080"
,"#c0c0c0"
,"#400040"
,"#ffffff"
];
var h = "";
for (var i=0; i < colours.length; ++i) {
h += "";
}
ot.tryitEditor.__open_form("
"+h+"
");
ot.jq('#_tryitEditor_form .ok').hide();
ot.jq('#_tryitEditor_form span').click(function(){
if (ot.tryitEditor.ie9over) {
document.execCommand("ms-beginUndoUnit");
}
if (ot.tryitEditor.edit_objs.length) {
for (var i=0; i";
ot.tryitEditor.__open_form("
"+h+"
");
ot.jq('#_tryitEditor_form .try_panel').hide();
ot.jq('#_tryitEditor_form select').change(function(){
var a = ot.jq(this);
if (!a.length) { return; }
var v = a.val();
if (!v) { return; }
if (ot.tryitEditor.ie9over) { document.execCommand("ms-beginUndoUnit"); }
if (ot.tryitEditor.edit_objs.length) {
for (var i=0; i"+t+"");
};
ot.tryitEditor._tag_edit = function () {
if (!ot.tryitEditor.__get_cursor_objs(false)) { return; }
ot.tryitEditor.edit_obj = ot.tryitEditor.edit_objs[0];
if (ot.tryitEditor.edit_obj.nodeName == '#text' && ot.tryitEditor.edit_obj.parentNode.id == '_tryitEditor_contents') {
return;
}
var h = '';
h = ot.tryitEditor.edit_obj.outerHTML.replace(/(^\s+)|(\s+$)|(\t)/g, "");
var t = "";
var d = "";
d += "";
d += "";
d += "";
d += "";
d += "";
d += " ";
d += "";
var opt = "";
d += "";
d += "";
ot.tryitEditor.__open_form(t,d);
ot.jq('#_tryitEditor_form textarea').val(h);
ot.jq('#_tryitEditor_form .upper').click(function(){
if (ot.tryitEditor.edit_objs[0].parentNode.id != '_tryitEditor_contents') {
ot.tryitEditor.edit_sel.removeAllRanges();
var r = ot.tryitEditor.edit_rng;
var n = ot.tryitEditor.edit_objs[0].parentNode;
r.selectNode(n);
ot.tryitEditor.edit_sel.addRange(r);
if (!ot.tryitEditor.__get_cursor_objs(false)) { return; }
var a = n.outerHTML;
ot.tryitEditor.edit_obj = n;
a = a.replace(/(^\s+)|(\s+$)|(\t)/g, "");
ot.jq('#_tryitEditor_form textarea').val(a);
}
});
ot.jq('#_tryitEditor_form .next').click(function(){
if (ot.tryitEditor.edit_objs[0].nextElementSibling) {
ot.tryitEditor.edit_sel.removeAllRanges();
var r = ot.tryitEditor.edit_rng;
var n = ot.tryitEditor.edit_objs[0].nextElementSibling;
//if (n.nodeName =='#text') {
// n = n.nextElementSibling;
//}
r.selectNode(n);
ot.tryitEditor.edit_sel.addRange(r);
if (!ot.tryitEditor.__get_cursor_objs(false)) { return; }
var a = n.outerHTML;
ot.tryitEditor.edit_obj = n;
a = a.replace(/(^\s+)|(\s+$)|(\t)/g, "");
ot.jq('#_tryitEditor_form textarea').val(a);
}
});
ot.jq('#_tryitEditor_form .prev').click(function(){
if (ot.tryitEditor.edit_objs[0].previousElementSibling) {
ot.tryitEditor.edit_sel.removeAllRanges();
var r = ot.tryitEditor.edit_rng;
var n = ot.tryitEditor.edit_objs[0].previousElementSibling;
r.selectNode(n);
ot.tryitEditor.edit_sel.addRange(r);
if (!ot.tryitEditor.__get_cursor_objs(false)) { return; }
var a = n.outerHTML;
ot.tryitEditor.edit_obj = n;
a = a.replace(/(^\s+)|(\s+$)|(\t)/g, "");
ot.jq('#_tryitEditor_form textarea').val(a);
}
});
ot.jq('#_tryitEditor_form .chg_block').change(function(){
var a = ot.jq(this).val();
var h = ot.jq('#_tryitEditor_form textarea').val();
if (a == '-esc-') {
ot.jq('#_tryitEditor_form textarea').val(ot.tryitEditor._esc(h));
} else {
var m1 = h.match(/<([A-z0-9]*)/i);
var m2 = h.match(/<\/([A-z0-9]*)>$/i);
if (m1 && m2) {
if (m1[0][0] == '<' && m2[0].substr(0,2) == '' && m1[1] == m2[1]) {
h = h.replace(/<([A-z0-9]*)/i,'<'+a);
h = h.replace(/<\/([A-z0-9]*)>$/i,''+a+'>');
ot.jq('#_tryitEditor_form textarea').val(h);
}
} else {
ot.jq('#_tryitEditor_form textarea').val('<'+a+'>'+h+''+a+'>');
}
}
});
ot.jq('#_tryitEditor_form .add_block').change(function(){
var a = ot.jq(this).val();
var h = ot.jq('#_tryitEditor_form textarea').val();
var b = (a=='p' || a=='div') ? ' ':' ';
h += '<'+a+'>'+b+''+a+'>'
ot.jq('#_tryitEditor_form textarea').val(h);
});
ot.jq('#_tryitEditor_form .ins_block').change(function(){
var a = ot.jq(this).val();
var h = ot.jq('#_tryitEditor_form textarea').val();
var b = (a=='p' || a=='div') ? ' ':' ';
h = '<'+a+'>'+b+''+a+'>' + h;
ot.jq('#_tryitEditor_form textarea').val(h);
});
ot.jq('#_tryitEditor_form .remove_tag').click(function(){
var h = ot.jq('#_tryitEditor_form textarea').val();
h = h.replace(/<\/*[A-z0-9]*?>|<[A-z0-9]*? .*?[^-]>/gm,'');
ot.jq('#_tryitEditor_form textarea').val(h);
});
ot.jq('#_tryitEditor_form .remove_style').click(function(){
var h = ot.jq('#_tryitEditor_form textarea').val();
h = h.replace(/style\s*='.*?'/g,'');
h = h.replace(/style\s*=".*?"/g,'');
ot.jq('#_tryitEditor_form textarea').val(h);
});
ot.jq('#_tryitEditor_form .ok').click(function(){
var h = ot.jq('#_tryitEditor_form textarea').val();
ot.tryitEditor.edit_sel.removeAllRanges();
if (ot.tryitEditor.ie9over) {document.execCommand("ms-beginUndoUnit");}
ot.tryitEditor.edit_obj.outerHTML = h;
if (ot.tryitEditor.ie9over) {document.execCommand("ms-endUndoUnit");}
ot.tryitEditor.__close_form();
});
ot.jq('#_tryitEditor_form .style_html').click(function(){
var h = ot.jq('#_tryitEditor_form textarea').val();
ot.jq('#_tryitEditor_form textarea').val(style_html(h));
});
};
ot.tryitEditor._attribute = function (obj) {
if (!ot.tryitEditor.__get_cursor_objs(true)) { return; }
ot.tryitEditor.edit_obj = ot.tryitEditor.edit_objs[0];
var h = "";
h += "
"+ot.tryitEditor.edit_obj.innerHTML+"
";
h += "
";
h += "tag ";
h += "class ";
h += "css";
h += " ";
h += "
";
h += "
";
h += "";
h += "";
h += "
";
ot.tryitEditor.__open_form("
"+h+"
");
ot.jq('#_tryitEditor_form .ok').click(function(){
var cssText = ot.jq('#_tryitEditor_form .cssText').val();
var className = ot.jq('#_tryitEditor_form .className').val();
for (var i=0; i ');
if (ot.tryitEditor.ie9over) {document.execCommand("ms-endUndoUnit");}
ot.tryitEditor.edit_sel.removeAllRanges();
ot.tryitEditor.__close_form();
});
ot.jq('#_tryitEditor_form .upper').click(function(){
if (ot.tryitEditor.edit_objs[0].parentNode.id != '_tryitEditor_contents') {
ot.tryitEditor.edit_sel.removeAllRanges();
var r = ot.tryitEditor.edit_rng;
var n = ot.tryitEditor.edit_objs[0].parentNode;
r.selectNode(n);
ot.tryitEditor.edit_sel.addRange(r);
if (!ot.tryitEditor.__get_cursor_objs(false)) { return; }
ot.jq('#_tryitEditor_form .text').html(n.innerHTML);
ot.jq('#_tryitEditor_form .tagName').val(n.tagName);
ot.jq('#_tryitEditor_form .className').val(n.className);
ot.jq('#_tryitEditor_form .cssText').val(n.style.cssText);
}
});
};
ot.tryitEditor._esc = function (v) {
return String(v).replace( //g, ">" ).replace( /"/g, """ ).replace( /'/g, "'" ).replace( /\$/g, "$" );
}; //"
ot.tryitEditor._table = function () {
var r = ot.tryitEditor.save_cursor();
if (!r) { return; }
x = r.toString();
var o = r.commonAncestorContainer;
var i = 0;
ot.tryitEditor.table_new_html = false;
while (o.tagName != 'TABLE') {
if (++i > 5) {
var ar = ot.tryitEditor.opt.table_style;
var h = "
";
for (var j=ar.row; j > 0; --j) {
h += "
";
for (var i=ar.col; i >0; --i) {
h += "
"+((ar.cell)?ar.cell:'')+"
";
}
h += "
";
}
h += "
";
ot.tryitEditor.table_new_html = h;
break;
}
o = o.parentNode;
}
ot.tryitEditor.edit_obj = o;
ot.tryitEditor.edit_sel.removeAllRanges();
var h = "";
var d = "";
d += "
";
d += "";
d += "";
d += "";
d += "
";
d += "
";
d += "";
d += "";
d += "";
d += "";
d += "
";
ot.tryitEditor.__open_form(h,d);
if (!ot.tryitEditor.table_new_html) {
ot.jq('#_tryitEditor_tbl').html(ot.tryitEditor.edit_obj.outerHTML);
} else {
ot.jq('#_tryitEditor_tbl').html(ot.tryitEditor.table_new_html);
}
ot.jq('#_tryitEditor_form .ok').click(function(){
var h = ot.jq('#_tryitEditor_tbl').html();
ot.tryitEditor.__close_form();
ot.tryitEditor.edit_sel.removeAllRanges();
var r = ot.tryitEditor.edit_rng;
if (ot.tryitEditor.table_new_html) {
ot.tryitEditor.edit_sel.addRange(r);
} else {
r.selectNode(ot.tryitEditor.edit_obj);
ot.tryitEditor.edit_sel.addRange(r);
}
ot.tryitEditor.__insertHTML(h);
ot.tryitEditor.table_new_html = false;
});
ot.jq('#_tryitEditor_form .add_row').click(function(){
var s = document.getSelection();
if (s.type == 'None') { return ; }
var r = s.getRangeAt(0);
var n = r.commonAncestorContainer.parentNode;
if (n.tagName != 'TR') { n = n.parentNode; }
if (n.tagName != 'TR') {
return;
}
var a = n.outerHTML;
if (!a) { return; }
a = a.replace(/>.*? <');
if (!a) { return; }
ot.jq('#_tryitEditor_tbl tbody').append(a);
});
ot.jq('#_tryitEditor_form .ins_row').click(function(){
var s = document.getSelection();
if (s.type == 'None') { return ; }
var r = s.getRangeAt(0);
var n = r.commonAncestorContainer.parentNode;
if (n.tagName != 'TR') { n = n.parentNode; }
if (n.tagName != 'TR') {
return;
}
var a = n.outerHTML;
if (!a) { return; }
a = a.replace(/>.*? <');
if (!a) { return; }
var s = document.getSelection();
if (s.type == 'None') { return ; }
var r = s.getRangeAt(0);
var n = r.commonAncestorContainer.parentNode;
if (n.tagName != 'TR') { n = n.parentNode; }
if (n.tagName != 'TR') {
return;
}
ot.jq(n).before(a);
});
ot.jq('#_tryitEditor_form .chg_td').click(function(){
var s = document.getSelection();
if (s.type == 'None') { return ; }
var r = s.getRangeAt(0);
var n = r.commonAncestorContainer.parentNode;
var x = false;
if (n.tagName == 'TD') {
var o = n.outerHTML;
var a = o.replace(/
/mi,'<\/th>');
n.outerHTML = a;
} else if (n.tagName == 'TH') {
var o = n.outerHTML;
var a = o.replace(/
/mi,'<\/td>');
n.outerHTML = a;
}
});
ot.jq('#_tryitEditor_form .del_row').click(function(){
var s = document.getSelection();
if (s.type == 'None') { return ; }
var r = s.getRangeAt(0);
var n = r.commonAncestorContainer.parentNode;
if (n.tagName != 'TR') { n = n.parentNode; }
if (n.tagName != 'TR') {
return;
}
ot.jq(n).remove();
});
ot.jq('#_tryitEditor_form .del_col').click(function(){
var r = false;
var s = document.getSelection();
if (s.type == 'None') { return ; }
r = s.getRangeAt(0);
var n = r.commonAncestorContainer.parentNode;
if (n.tagName != 'TD' && n.tagName != 'TH') { return; }
var i = -1;
var tmp = n;
while (++i < 20) {
if (!(tmp = tmp.previousElementSibling)) { break; }
}
ot.jq('#_tryitEditor_tbl tr').each(function(){
ot.jq(this).children('td:nth('+i+'),th:nth('+i+')').remove();
});
});
ot.jq('#_tryitEditor_form .ins_col').click(function(){
var r = false;
var s = document.getSelection();
if (s.type == 'None') { return ; }
r = s.getRangeAt(0);
var n = r.commonAncestorContainer.parentNode;
if (n.tagName != 'TD' && n.tagName != 'TH') { return; }
var i = 0;
var tmp = n;
while (i < 50) {
if (!(tmp = tmp.previousElementSibling)) { break; }
if (tmp.tagName != 'TD' && tmp.tagName != 'TH') { continue; }
++i;
}
ot.jq('#_tryitEditor_tbl tr').each(function(){
var o = ot.jq(this).children('td:nth('+i+'), th:nth('+i+')');
var a = o[0].outerHTML;
a = a.replace(/>.*? <');
if (a) {
a = a.replace(/>.*? <');
o.before(a);
}
});
});
ot.jq('#_tryitEditor_form .add_col').click(function(){
ot.jq('#_tryitEditor_tbl tbody tr').each(function(){
var o = ot.jq(this).children('td:last, th:last');
var a = o[0].outerHTML;
a = a.replace(/>.*? <');
if (a) {
ot.jq(this).append(a);
}
});
});
};
ot.tryitEditor.html = function (a) {
var o = ot.jq('#_tryitEditor_contents');
if (o.is(':visible')) {
if (a !== undefined) {
return o.html(a);
} else {
return o.html();
}
} else {
if (a !== undefined) {
ot.jq('#_tryitEditor_html').val(a);
} else {
return ot.jq('#_tryitEditor_html').val();
}
}
};
ot.tryitEditor.insert = function (html) {
var r = ot.tryitEditor.save_cursor();
if (ot.tryitEditor.navigator == 'ie') {
var a = ot.jq('#_tryitEditor_contents')[0];
ot.jq(a).focus();
}
ot.tryitEditor.__insertHTML(html);
};
/* jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
/*
Style HTML
---------------
Written by Nochum Sossonko, (nsossonko@hotmail.com)
Based on code initially developed by: Einar Lielmanis,
http://jsbeautifier.org/
You are free to use this in any way you want, in case you find this useful or working for you.
Usage:
style_html(html_source);
style_html(html_source, options);
The options are:
indent_size (default 4) indentation size,
indent_char (default space) character to indent with,
max_char (default 250) - maximum amount of characters per line (0 = disable)
brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line.
unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted
indent_scripts (default normal) - "keep"|"separate"|"normal"
e.g.
style_html(html_source, {
'indent_size': 2,
'indent_char': ' ',
'max_char': 78,
'brace_style': 'expand',
'unformatted': ['a', 'sub', 'sup', 'b', 'i', 'u']
});
*/
function style_html(html_source, options) {
//Wrapper function to invoke all the necessary constructors and deal with the output.
var multi_parser,
indent_size,
indent_character,
max_char,
brace_style,
unformatted;
options = options || {};
indent_size = options.indent_size || 4;
indent_character = options.indent_char || ' ';
brace_style = options.brace_style || 'collapse';
max_char = options.max_char === 0 ? Infinity : options.max_char || 250;
unformatted = options.unformatted || ['a', 'span', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike', 'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
function Parser() {
this.pos = 0; //Parser position
this.token = '';
this.current_mode = 'CONTENT'; //reflects the current Parser mode: TAG/CONTENT
this.tags = { //An object to hold tags, their position, and their parent-tags, initiated with default values
parent: 'parent1',
parentcount: 1,
parent1: ''
};
this.tag_type = '';
this.token_text = this.last_token = this.last_text = this.token_type = '';
this.Utils = { //Uilities made available to the various functions
whitespace: "\n\r\t ".split(''),
single_token: 'br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed,?php,?,?='.split(','), //all the single tags for HTML
extra_liners: 'head,body,/html'.split(','), //for tags that need a line of whitespace before them
in_array: function (what, arr) {
for (var i=0; i= this.input.length) {
return content.length?content.join(''):['', 'TK_EOF'];
}
input_char = this.input.charAt(this.pos);
this.pos++;
this.line_char_count++;
if (this.Utils.in_array(input_char, this.Utils.whitespace)) {
if (content.length) {
space = true;
}
this.line_char_count--;
continue; //don't want to insert unnecessary space
}
else if (space) {
if (this.line_char_count >= this.max_char) { //insert a line when the max_char is reached
content.push('\n');
for (var i=0; i', 'igm');
reg_match.lastIndex = this.pos;
var reg_array = reg_match.exec(this.input);
var end_script = reg_array?reg_array.index:this.input.length; //absolute end of script
if(this.pos < end_script) { //get everything in between the script tags
content = this.input.substring(this.pos, end_script);
this.pos = end_script;
}
return content;
};
this.record_tag = function (tag){ //function to record a tag and its parent in this.tags Object
if (this.tags[tag + 'count']) { //check for the existence of this tag type
this.tags[tag + 'count']++;
this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
}
else { //otherwise initialize this tag type
this.tags[tag + 'count'] = 1;
this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
}
this.tags[tag + this.tags[tag + 'count'] + 'parent'] = this.tags.parent; //set the parent (i.e. in the case of a div this.tags.div1parent)
this.tags.parent = tag + this.tags[tag + 'count']; //and make this the current parent (i.e. in the case of a div 'div1')
};
this.retrieve_tag = function (tag) { //function to retrieve the opening tag to the corresponding closer
if (this.tags[tag + 'count']) { //if the openener is not in the Object we ignore it
var temp_parent = this.tags.parent; //check to see if it's a closable tag.
while (temp_parent) { //till we reach '' (the initial value);
if (tag + this.tags[tag + 'count'] === temp_parent) { //if this is it use it
break;
}
temp_parent = this.tags[temp_parent + 'parent']; //otherwise keep on climbing up the DOM Tree
}
if (temp_parent) { //if we caught something
this.indent_level = this.tags[tag + this.tags[tag + 'count']]; //set the indent_level accordingly
this.tags.parent = this.tags[temp_parent + 'parent']; //and set the current parent
}
delete this.tags[tag + this.tags[tag + 'count'] + 'parent']; //delete the closed tags parent reference...
delete this.tags[tag + this.tags[tag + 'count']]; //...and the tag itself
if (this.tags[tag + 'count'] === 1) {
delete this.tags[tag + 'count'];
}
else {
this.tags[tag + 'count']--;
}
}
};
this.get_tag = function (peek) { //function to get a full tag and parse its type
var input_char = '',
content = [],
comment = '',
space = false,
tag_start, tag_end,
orig_pos = this.pos,
orig_line_char_count = this.line_char_count;
peek = peek !== undefined ? peek : false;
do {
if (this.pos >= this.input.length) {
if (peek) {
this.pos = orig_pos;
this.line_char_count = orig_line_char_count;
}
return content.length?content.join(''):['', 'TK_EOF'];
}
input_char = this.input.charAt(this.pos);
this.pos++;
this.line_char_count++;
if (this.Utils.in_array(input_char, this.Utils.whitespace)) { //don't want to insert unnecessary space
space = true;
this.line_char_count--;
continue;
}
if (input_char === "'" || input_char === '"') {
if (!content[1] || content[1] !== '!') { //if we're in a comment strings don't get treated specially
input_char += this.get_unformatted(input_char);
space = true;
}
}
if (input_char === '=') { //no space before =
space = false;
}
if (content.length && content[content.length-1] !== '=' && input_char !== '>' && space) {
//no space after = or before >
if (this.line_char_count >= this.max_char) {
this.print_newline(false, content);
this.line_char_count = 0;
}
else {
content.push(' ');
this.line_char_count++;
}
space = false;
}
if (input_char === '<') {
tag_start = this.pos - 1;
}
content.push(input_char); //inserts character at-a-time (or string)
} while (input_char !== '>');
var tag_complete = content.join('');
var tag_index;
if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
tag_index = tag_complete.indexOf(' ');
}
else { //otherwise go with the tag ending
tag_index = tag_complete.indexOf('>');
}
var tag_check = tag_complete.substring(1, tag_index).toLowerCase();
if (tag_complete.charAt(tag_complete.length-2) === '/' ||
this.Utils.in_array(tag_check, this.Utils.single_token)) { //if this tag name is a single tag type (either in the list or has a closing /)
if ( ! peek) {
this.tag_type = 'SINGLE';
}
}
else if (tag_check === 'script') { //for later script handling
if ( ! peek) {
this.record_tag(tag_check);
this.tag_type = 'SCRIPT';
}
}
else if (tag_check === 'style') { //for future style handling (for now it justs uses get_content)
if ( ! peek) {
this.record_tag(tag_check);
this.tag_type = 'STYLE';
}
}
else if (this.is_unformatted(tag_check, unformatted)) { // do not reformat the "unformatted" tags
comment = this.get_unformatted(''+tag_check+'>', tag_complete); //...delegate to get_unformatted function
content.push(comment);
// Preserve collapsed whitespace either before or after this tag.
if (tag_start > 0 && this.Utils.in_array(this.input.charAt(tag_start - 1), this.Utils.whitespace)){
content.splice(0, 0, this.input.charAt(tag_start - 1));
}
tag_end = this.pos - 1;
if (this.Utils.in_array(this.input.charAt(tag_end + 1), this.Utils.whitespace)){
content.push(this.input.charAt(tag_end + 1));
}
this.tag_type = 'SINGLE';
}
else if (tag_check.charAt(0) === '!') { //peek for so...
comment = this.get_unformatted('-->', tag_complete); //...delegate to get_unformatted
content.push(comment);
}
if ( ! peek) {
this.tag_type = 'START';
}
}
else if (tag_check.indexOf('[endif') !== -1) {//peek for ', tag_complete);
content.push(comment);
this.tag_type = 'SINGLE';
}
}
else if ( ! peek) {
if (tag_check.charAt(0) === '/') { //this tag is a double tag so check for tag-ending
this.retrieve_tag(tag_check.substring(1)); //remove it and all ancestors
this.tag_type = 'END';
}
else { //otherwise it's a start-tag
this.record_tag(tag_check); //push it on the tag stack
this.tag_type = 'START';
}
if (this.Utils.in_array(tag_check, this.Utils.extra_liners)) { //check if this double needs an extra line
this.print_newline(true, this.output);
}
}
if (peek) {
this.pos = orig_pos;
this.line_char_count = orig_line_char_count;
}
return content.join(''); //returns fully formatted tag
};
this.get_unformatted = function (delimiter, orig_tag) { //function to return unformatted content in its entirety
if (orig_tag && orig_tag.toLowerCase().indexOf(delimiter) !== -1) {
return '';
}
var input_char = '';
var content = '';
var space = true;
do {
if (this.pos >= this.input.length) {
return content;
}
input_char = this.input.charAt(this.pos);
this.pos++;
if (this.Utils.in_array(input_char, this.Utils.whitespace)) {
if (!space) {
this.line_char_count--;
continue;
}
if (input_char === '\n' || input_char === '\r') {
content += '\n';
/* Don't change tab indention for unformatted blocks. If using code for html editing, this will greatly affect
tags if they are specified in the 'unformatted array'
for (var i=0; i 0) {
this.indent_level--;
}
};
};
return this;
}
/*_____________________--------------------_____________________*/
multi_parser = new Parser(); //wrapping functions Parser
multi_parser.printer(html_source, indent_character, indent_size, max_char, brace_style); //initialize starting values
while (true) {
var t = multi_parser.get_token();
multi_parser.token_text = t[0];
multi_parser.token_type = t[1];
if (multi_parser.token_type === 'TK_EOF') {
break;
}
switch (multi_parser.token_type) {
case 'TK_TAG_START':
multi_parser.print_newline(false, multi_parser.output);
multi_parser.print_token(multi_parser.token_text);
multi_parser.indent();
multi_parser.current_mode = 'CONTENT';
break;
case 'TK_TAG_STYLE':
case 'TK_TAG_SCRIPT':
multi_parser.print_newline(false, multi_parser.output);
multi_parser.print_token(multi_parser.token_text);
multi_parser.current_mode = 'CONTENT';
break;
case 'TK_TAG_END':
//Print new line only if the tag has no content and has child
if (multi_parser.last_token === 'TK_CONTENT' && multi_parser.last_text === '') {
var tag_name = multi_parser.token_text.match(/\w+/)[0];
var tag_extracted_from_last_output = multi_parser.output[multi_parser.output.length -1].match(/<\s*(\w+)/);
if (tag_extracted_from_last_output === null || tag_extracted_from_last_output[1] !== tag_name) {
multi_parser.print_newline(true, multi_parser.output);
}
}
multi_parser.print_token(multi_parser.token_text);
multi_parser.current_mode = 'CONTENT';
break;
case 'TK_TAG_SINGLE':
// Don't add a newline before elements that should remain unformatted.
var tag_check = multi_parser.token_text.match(/^\s*<([a-z]+)/i);
if (!tag_check || !multi_parser.Utils.in_array(tag_check[1], unformatted)){
multi_parser.print_newline(false, multi_parser.output);
}
multi_parser.print_token(multi_parser.token_text);
multi_parser.current_mode = 'CONTENT';
break;
case 'TK_CONTENT':
if (multi_parser.token_text !== '') {
multi_parser.print_token(multi_parser.token_text);
}
multi_parser.current_mode = 'TAG';
break;
case 'TK_STYLE':
case 'TK_SCRIPT':
if (multi_parser.token_text !== '') {
multi_parser.output.push('\n');
var text = multi_parser.token_text,
_beautifier,
script_indent_level = 1;
if (multi_parser.token_type === 'TK_SCRIPT') {
_beautifier = typeof js_beautify === 'function' && js_beautify;
} else if (multi_parser.token_type === 'TK_STYLE') {
_beautifier = typeof css_beautify === 'function' && css_beautify;
}
if (options.indent_scripts === "keep") {
script_indent_level = 0;
} else if (options.indent_scripts === "separate") {
script_indent_level = -multi_parser.indent_level;
}
var indentation = multi_parser.get_full_indent(script_indent_level);
if (_beautifier) {
// call the Beautifier if avaliable
text = _beautifier(text.replace(/^\s*/, indentation), options);
} else {
// simply indent the string otherwise
var white = text.match(/^\s*/)[0];
var _level = white.match(/[^\n\r]*$/)[0].split(multi_parser.indent_string).length - 1;
var reindent = multi_parser.get_full_indent(script_indent_level -_level);
text = text.replace(/^\s*/, indentation)
.replace(/\r\n|\r|\n/g, '\n' + reindent)
.replace(/\s*$/, '');
}
if (text) {
multi_parser.print_token(text);
multi_parser.print_newline(true, multi_parser.output);
}
}
multi_parser.current_mode = 'TAG';
break;
}
multi_parser.last_token = multi_parser.token_type;
multi_parser.last_text = multi_parser.token_text;
}
return multi_parser.output.join('');
}