try {
ActiveMTGeneralURL = $(‘.ActiveMTGeneral’, parent.document).val();
basePortalCss = $(‘#hBasePortalCssUrl’, parent.document).val();
resPortalCss = $(‘#hresPortalCssUrl’, parent.document).val();
roxyFileman = $(‘#hRoxyUrl’, parent.document).val();

function destroyCKEDITOR() {
if (typeof CKEDITOR != “undefined”) {
for (name in CKEDITOR.instances) {
if (CKEDITOR.instances[name] != “contenteditor” && CKEDITOR.instances[name] != undefined) {
CKEDITOR.instances[name].destroy(true);
}
}
$(“.cke”).remove();
}
}

function renderCKInline(x,y) {
CKEDITOR.disableAutoInline = true;
CKEDITOR.inline(x, {
//contentsLangDirection: ‘ltr’,
extraPlugins: ‘sourcedialog,closebtn,floatingspace,divarea,pastefromword’,
startupFocus: true,
toolbar: y,
language: ‘en’,
contentsCss: [basePortalCss, resPortalCss, ActiveMTGeneralURL],
//floatSpaceDockedOffsetX: parseInt($(“.resizeBox”).css(“marginLeft”)) + 40,
//floatSpacePinnedOffsetX: parseInt($(“.resizeBox”).css(“marginLeft”)) + 40,
//floatSpaceDockedOffsetY: 2,
//floatSpacePinnedOffsetY: 0,
filebrowserUploadUrl1: $(‘#hImageUploadUrl’, parent.document).val(),
allowedContent: true,
//forcePasteAsPlainText: true,
filebrowserBrowseUrl: roxyFileman,
filebrowserImageBrowseUrl: roxyFileman + ‘?type=image’,
removeDialogTabs: ‘link:upload;image:upload’,
});
}

function sortables() {
/ knows about f /
fTop = $(“body”).parent();

if (fTop.find(“:ui-sortable”).length > 0) {
fSortables = fTop.find(“:ui-sortable”);
fTop.find(“:ui-sortable”).sortable(“destroy”);
}

fTop.find(“body, .container, .container-fluid, .container-narrow, .column, .be-div-block, .be-section”).sortable({
connectWith: “body, .container, .container-fluid, .container-narrow, .column, .be-div-block, .be-section”,
helper: “clone”,
items: “.tool-c, .container, .row, .container-fluid, .container-narrow, .be-div-block, .be-section”,
containment: false,
tolerance: “pointer”,
distance: 5,
scroll: true,
scrollSensitivity: 100,
scrollSpeed: 25,
snap:false,
placeholder: “sortable-placeholder”,
forcePlaceholderSize: false,
start: function (event, ui) {
bbb = ui;
/ hide helper on sort if Firefox /
if ($(“html”).hasClass(“ff”)) {
$(ui.helper[0]).hide();
}
/ ONLY SHOW GHOST OF MOVING ELEMENT IF IT’S A TOOL. LAYOUTS DISABLED BECAUSE IT CRASHES ON DRAG INTO SELF /
if ($(ui.item).hasClass(‘tool-c’)) {
ui.item.addClass(“sortable-original”);
}

if ($(“body”).find(“.fSortHelper”).length == 0) {
$(“body”).append(“

“);
}

$(“body”).addClass(“dragging sorting”);

},
sort: function (event, ui) {
/ check if placeholder position is 0 add back placeholder /
var pos = ui.placeholder.position();
if (pos.left == 0 & pos.top == 0) {
$(ui.item).before(ui.placeholder);
}
},
update: function (ev, ui) {
if (this === ui.item.parent()[0]) {
/ PREVENT NEW COMPONENT BEING DROPPED ON BODY DIRECTLY // NEEDS TO BE DROPPED ON LAYOUT! /
if ($(ui.item).hasClass(‘tool’) && !$(ui.item).hasClass(‘lyts’) && $(ui.item[0].offsetParent).is(“body”)) {
$(ui.sender).sortable(‘cancel’);
ui.item.remove();
/ close htmlcode popup if it was triggered /
setTimeout(function () {
if ($(ui.item).hasClass(“htmlcode”)) {
window.parent.closeHTMLCode();
}
}, 100);
window.parent.redAlert(“Component must be dropped on a layout block.”);
}

/ PREVENT EXISTING COMPONENT (MOVING ONLY) BEING SORTED ON BODY DIRECTLY // NEEDS TO BE DROPPED ON LAYOUT! /
if ($(ui.item).hasClass(‘tool-c’) && $(ui.item[0].offsetParent).is(“body”)) {
$(ui.sender).sortable(‘cancel’);
window.parent.redAlert(“Component must be dropped on a layout block.”);
}

if ($(ui.item).hasClass(‘container’) && $(ui.item[0].offsetParent).is(“.container”) || $(ui.item).hasClass(‘container’) && $(ui.item[0].offsetParent).is(“.container-narrow”) || $(ui.item).hasClass(‘container’) && $(ui.item[0].offsetParent).closest(“.container”).length > 0) {
$(ui.sender).sortable(‘cancel’);
/ remove a NEW container – exisiting sorted should not be removed /
if ($(ui.item[0]).hasClass(“sideToolsDragHelper”)) {
$(ui.item).remove();
}
window.parent.redAlert(“Container can only be placed into a Wide/Fluid containers.”);
}

}

},
beforeStop: function (ev, ui) {

},
stop: function (event, ui) {
ui.item.removeClass(“sortable-original”);

$(“body”).find(“.fSortHelper”).remove();

window.parent.iframeResize();
$(“body”).removeClass(“dragging sorting”);
}
});

if (fTop.find(“:ui-sortable”).length > 0) {
fSortables = fTop.find(“:ui-sortable”);
}
}

function insideToolsDrag() {
if ($(“:ui-draggable”).length > 0) {
$(“:ui-draggable”).draggable(“destroy”);
}

$(“.sidebar-nav .tool”).draggable({
helper: “clone”,
scroll: false,
handle: false,
opacity: 1,
connectToSortable: $(“body, .container, .container-fluid, .container-narrow, .column, .be-div-block, .be-section”),
start: function (event, ui) {
$(ui.helper[0]).addClass(“sideToolsDragHelper”);
$(“body”).addClass(“dragging”);
var WhatIsThis = $(ui.helper[0]).find(‘.preview’).text();
WhatIsThis = WhatIsThis.replace(/s+/g, ”);
$(ui.helper[0]).find(‘.tool-c’).addClass(WhatIsThis + ‘ Activated’);
$(ui.helper[0]).find(‘.tool-c’).attr(‘data-who’, WhatIsThis);

var bodyH = $(“body”).outerHeight(true);
$(“body,html”).css({ “maxHeight”: bodyH });

hideTools();
$(ui.helper[0]).css({“opacity”: 0});
},
drag: function (event, ui) {
},
stop: function (event, ui) {
$(“body,html”).css({ “maxHeight”: “”});
var sourceList = ui.sender;
var targetList = $(this);
$(ui.helper[0]).find(‘.preview’).remove();
$(ui.helper[0]).find(‘.toolpush’).contents().unwrap();
$(“body”).removeClass(“dragging”);
$(“body”).find(“.block-empty”).each(function () {
if ($(this).find(“.tool-c, .row, .container, .container-fluid, .container-narrow, .column, .be-div-block, .be-section”).length > 0) {
$(this).removeClass(“block-empty”);
}
});

/ OPEN HTML CODE EDITOR IF HTMLCODE COMPONENT WAS CREATED /
if ($(ui.helper[0]).hasClass(“htmlcode”)) {
window.parent.openHTMLCode($(ui.helper[0]).find(“.HTMLCode”));
}

setTimeout(function () {
$(ui.helper[0]).contents().unwrap();
}, 0);
setTimeout(function () {
//sortableRefresh();
window.parent.initContainer();
window.parent.iframeResize();
window.parent.sideSettingsBoxFunc();
window.parent.sortableEditor();

}, 100);
}
});
}

function sortableRefresh() {
if ($(document).find(“:ui-sortable”).length > 0) {
$(document).find(“body”).sortable(“refresh”);
$(document).find(“:ui-sortable”).sortable(“refresh”);
fSortables = $(document).find(“:ui-sortable”);
}
}

function tempDisableSortables() {
if (typeof fSortables != “undefined”) {
fSortables.sortable(“disable”);
$(“body”).find(“.tool-c”).unbind(“mouseout.fsrtbmouseout mouseover.fsrtbmouseover”);
$(“body”).find(“.tool-c.BlockFocus”).bind(‘mouseout.fsrtbmouseout’, function () {
fSortables.sortable();
fSortables.sortable(“enable”);
});
$(“body”).find(“.tool-c.BlockFocus”).on(‘mouseover.fsrtbmouseover’, function () {
fSortables.sortable();
fSortables.sortable(“disable”);
});
}
}

function enableSortables() {
if (typeof fSortables != “undefined”) {
fSortables.sortable();
fSortables.sortable(“enable”);
$(“body”).find(“.tool-c”).unbind(“mouseout.fsrtbmouseout mouseover.fsrtbmouseover”);
}
}

function hideTools() {

if ($(“.sidebar-nav”).is(“:visible”)) {
$(“.sidebar-nav”).hide();
$(“.sidebar-nav”).detach().appendTo($(“.sidebarnavButton”, parent.document));
setTimeout(function () {
$(“.sidebut.showTools”, parent.document).removeClass(“factive”);
}, 50);
}

if ($(“:ui-draggable”).length > 0) {
$(“:ui-draggable”).draggable(“destroy”);
}

}

function showTools() {
$(“.toolsMenuWrap”, parent.document).detach().prependTo($(“body”));
$(“.toolsMenuWrap”).show();
insideToolsDrag();

setTimeout(function () {
$(“.sidebut.showTools”, parent.document).addClass(“factive”);
}, 50);
}

$(document).ready(function () {
$(“.sidebut.showTools”, parent.document).off(“click”).on(“click”, function () {
if ($(“.sidebut.showTools”, parent.document).hasClass(“factive”)) {
hideTools();
} else {
showTools();
}
});
});

$(window).load(function () {
window.top.contentIframeLoaded();
});

} catch(ex){console.log(‘Error was found on ‘ + ex)}

Author: Life Enthusiast