");
$(this).addClass("hidden");
$(this).after(c);
d.find("*").each(function () {
$(this).off("click");
$(this).prop("onclick", "");
});
d.on("blur", function () {
$(this).find("br.eos-editor").remove();
source.val($.rescript($.trim($(this).html())));
});
p.on("blur", function () {
source.val($.rescript($.trim($(this).val())));
});
d.on("focus", function () {
d.append("\n
");
});
var mousedown = false;
$(d).on("mousedown", function (e) {
mousedown = true;
});
$(d).after("
html:
");
var current_selection = c.find(".current-selection");
current_selection.css({
width: "100%",
"font-size": "small",
"background-color": "#cccccc"
});
var selection_feedback = c.find(".selection-code");
$(d).on("mousemove", function (e) {
if (mousedown) {
setTimeout(function () {
selection_feedback.text("");
var sel = $.get_selection();
var range = $.get_range();//expand selection automatically if between tags
if (sel.focusNode) {
if (!$(sel.focusNode).parents(".eos-editor").length) {//event triggered outside of editor so ignore it
return;
}
var rc = range.cloneContents();
//console.log(rc);
var rcd = $("
");
rcd.append(rc);
selection_feedback.text(rcd.html());
}
}, 100);
}
});
$(d).on("mouseup", function (e) {
mousedown = false;
setTimeout(function () {
selection_feedback.text("");
var sel = $.get_selection();
$(".eos-table-ctrls", h).addClass("hidden");
$(".eos-table-ctrls", h).data({"table-element": null});
if (sel) {
var range = $.get_range(true);//expand selection automatically if between tags
if (sel.focusNode) {
if (!$(sel.focusNode).parents(".eos-editor").length) {//event triggered outside of editor so ignore it
return;
}
var rc = range.cloneContents();
var rcd = $("
");
rcd.append(rc);
selection_feedback.text(rcd.html());
var parent = sel.focusNode.parentNode;
var sel_tag = "";
if (!$(parent).hasClass("eos-editor")) {
sel_tag = $(parent).prop("tagName").toLowerCase();
}
var sobj = $(this).prev().find("select[name='tag']");
if (tags[sel_tag]) {
sobj.val(sel_tag);
} else {
sobj.val("");
}
//check for a table and show the table controls if so
var tag = $(parent);
var panic = 0;
while (true) {
if (panic++ > 25) {
console.log("possible infinte loop - stopping looking for table");
break;
}
if (tag.hasClass("eos-editor")) {
break;
}
if (tag.prop("tagName").toLowerCase() == "table") {
$(".eos-table-ctrls", h).removeClass("hidden");
$(".eos-table-ctrls", h).data({"table-element": tag});
break;
}
tag = tag.parent();
}
}
}
}, 100);//range and selection lag behind the mouse up event, so wait a bit to see if anything is actually still selected.
});
//belt & braces if save buttons are standardised
$(".button.save").on("click", function () {
$(d).find("br.eos-editor").remove();
if (c.data("mode") != "source") {
source.val(d.html());
} else {
source.val(p.val());
}
});
$(".ee-button", h).on("click", function (e) {
e.preventDefault();
//console.log("clicked");
var action = $(this).attr("data-action");
if (action != "toggle-source") {
if (c.data("mode") == "source") {
e.stopPropagation();
alert("Please Exit source view first");
return;
}
}
switch (action) {
case "revert":
d.html(orig_content);
d.find("*").each(function () {
$(this).off("click");
$(this).prop("onclick", "");
});
break;
case "link":
link_dialogue();
break;
case "class":
class_dialogue();
break;
case "bullets":
$.demand_dialogue({
title: "Bullet Selection",
href: options.base_path + "ajax/bullet-dialogue.php",
parent: source,
"content-after": true
});
break;
var element = $.get_tag_in_range("ul", true);
if (element) {//un-bullet
if (element.find("li").length) {
//var wrapper = element.wrap("
").parent();
element.children("li").append("
");
element.children("li").contents().unwrap();
element.contents().unwrap();
//element = wrapper;
} else {//not bulleted, so do it.
var html = "";
var parts = element.html().split("
");
$(parts).each(function () {
if (this.length) {
html += "
" + this + "";
}
});
element.html(html);
$.set_range(element[0]);
}
}
break;
case "image":
image_dialogue();
break;
case "colour":
//do nothing - its taken care of by the colour picker.
break;
case "table":
table_dialogue();
break;
case "toggle-source":
if (c.data("mode") == "source") {
c.data({
mode: 'wysiwig'
});
var query = {
"html": p.val() + "\n
"
};
$.fancybox.showActivity();
$.post("/include/eos-editor/ajax/fix-flow.php", query, function (data) {
$.fancybox.hideActivity();
if (!data.html) {
alert(data);
return;
}
d.html(data.html);
p.addClass("hidden");
d.removeClass("hidden");
d.find("*").each(function () {
$(this).off("click");
$(this).prop("onclick", "");
});
});
} else {
$("br.eos-editor", d).remove();
var query = {
"html": d.html()
};
$.fancybox.showActivity();
$.post("/include/eos-editor/ajax/format-html.php", query, function (data) {
$.fancybox.hideActivity();
p.val(data.html);
p.removeClass("hidden");
d.addClass("hidden");
c.data({
mode: 'source'
});
});
}
break;
case "delete-table":
var table = $(".eos-table-ctrls").data("table-element");
if (table) {
$(table).remove();
}
break;
case "removeformat":
var elements = $.wrap_selection("
", true);
$.strip_tags(elements);
break;
default:
dcmd(action);
}
d.focus();
});
var table_dialogue = function () {
/*
var element = $.get_tag_in_range("table", true);
element.append("
| |
").parent();
element.children("li").append("