123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- function getContextPath() {
- var pathName = document.location.pathname;
- var index = pathName.substr(1).indexOf("/");
- var result = pathName.substr(0,index+1);
- return result;
- }
- function handleSaveLayout() {
- var e = $(".demo").html();
- if (e != window.demoHtml) {
- saveLayout();
- window.demoHtml = e
- }
- }
- function handleJsIds() {
- handleModalIds();
- handleAccordionIds();
- handleCarouselIds();
- handleTabsIds()
- }
- function handleAccordionIds() {
- var e = $(".demo #myAccordion");
- var t = randomNumber();
- var n = "panel-" + t;
- var r;
- e.attr("id", n);
- e.find(".panel").each(function(e, t) {
- r = "panel-element-" + randomNumber();
- $(t).find(".panel-title").each(function(e, t) {
- $(t).attr("data-parent", "#" + n);
- $(t).attr("href", "#" + r)
- });
- $(t).find(".panel-collapse").each(function(e, t) {
- $(t).attr("id", r)
- })
- })
- }
- function handleCarouselIds() {
- var e = $(".demo #myCarousel");
- var t = randomNumber();
- var n = "carousel-" + t;
- e.attr("id", n);
- e.find(".carousel-indicators li").each(function(e, t) {
- $(t).attr("data-target", "#" + n)
- });
- e.find(".left").attr("href", "#" + n);
- e.find(".right").attr("href", "#" + n)
- }
- function handleModalIds() {
- var e = $(".demo #myModalLink");
- var t = randomNumber();
- var n = "modal-container-" + t;
- var r = "modal-" + t;
- e.attr("id", r);
- e.attr("href", "#" + n);
- e.next().attr("id", n)
- }
- function handleTabsIds() {
- var e = $(".demo #myTabs");
- var t = randomNumber();
- var n = "tabs-" + t;
- e.attr("id", n);
- e.find(".tab-pane").each(function(e, t) {
- var n = $(t).attr("id");
- var r = "panel-" + randomNumber();
- $(t).attr("id", r);
- $(t).parent().parent().find("a[href=#" + n + "]").attr("href", "#" + r)
- })
- }
- function randomNumber() {
- return randomFromInterval(1, 1e6)
- }
- function randomFromInterval(e, t) {
- return Math.floor(Math.random() * (t - e + 1) + e)
- }
- function gridSystemGenerator() {
- $(".lyrow .preview input").bind("keyup", function() {
- var e = 0;
- var t = "";
- var n = false;
- var r = $(this).val().split(" ", 12);
- $.each(r, function(r, i) {
- if (!n) {
- if (parseInt(i) <= 0)
- n = true;
- e = e + parseInt(i);
- t += '<div class="col-md-' + i + ' column"></div>'
- }
- });
- if (e == 12 && !n) {
- $(this).parent().next().children().html(t);
- $(this).parent().prev().show()
- } else {
- $(this).parent().prev().hide()
- }
- })
- }
- function configurationElm(e, t) {
- $(".demo").delegate(".configuration > a", "click", function(e) {
- e.preventDefault();
- var t = $(this).parent().next().next().children();
- $(this).toggleClass("active");
- t.toggleClass($(this).attr("rel"))
- });
- $(".demo").delegate(".configuration .dropdown-menu a", "click",
- function(e) {
- e.preventDefault();
- var t = $(this).parent().parent();
- var n = t.parent().parent().next().next().children();
- t.find("li").removeClass("active");
- $(this).parent().addClass("active");
- var r = "";
- t.find("a").each(function() {
- r += $(this).attr("rel") + " "
- });
- t.parent().removeClass("open");
- n.removeClass(r);
- n.addClass($(this).attr("rel"))
- })
- }
- function removeElm() {
- $(".demo").delegate(".remove", "click", function(e) {
- e.preventDefault();
- $(this).parent().remove();
- if (!$(".demo .lyrow").length > 0) {
- clearDemo()
- }
- })
- }
- function clearDemo() {
- $(".demo").empty()
- }
- function removeMenuClasses() {
- $("#menu-layoutit li button").removeClass("active")
- }
- function changeStructure(e, t) {
- $("#download-layout ." + e).removeClass(e).addClass(t)
- }
- function cleanHtml(e) {
- $(e).parent().append($(e).children().html())
- }
- function getLayoutSrc(){
- var e = "";
- $("#download-layout").children().html($(".demo").html());
- var t = $("#download-layout").children();
- t.find(".preview, .configuration, .drag, .remove").remove();
- t.find(".lyrow").addClass("removeClean");
- t.find(".box-element").addClass("removeClean");
- t.find(".lyrow .lyrow .lyrow .lyrow .lyrow .removeClean").each(function() {
- cleanHtml(this)
- });
- t.find(".lyrow .lyrow .lyrow .lyrow .removeClean").each(function() {
- cleanHtml(this)
- });
- t.find(".lyrow .lyrow .lyrow .removeClean").each(function() {
- cleanHtml(this)
- });
- t.find(".lyrow .lyrow .removeClean").each(function() {
- cleanHtml(this)
- });
- t.find(".lyrow .removeClean").each(function() {
- cleanHtml(this)
- });
- t.find(".removeClean").each(function() {
- cleanHtml(this)
- });
- t.find(".removeClean").remove();
- $("#download-layout .column").removeClass("ui-sortable");
- $("#download-layout .row-fluid").removeClass("clearfix").children()
- .removeClass("column");
- if ($("#download-layout .container").length > 0) {
- changeStructure("row-fluid", "row")
- }
- //myconsole.log($("#download-layout").html());
- formatSrc = $.htmlClean($("#download-layout").html(), {
- format : true,
- allowedAttributes : [
- [ "id" ], [ "class" ], [ "data-toggle" ],
- [ "data-target" ], [ "data-parent" ], [ "role" ],
- [ "data-dismiss" ], [ "aria-labelledby" ], [ "aria-hidden" ],
- [ "data-slide-to" ], [ "data-slide" ] ,
- ["th:with"],
- ["th:text"],
- ["th:each"],
- ["th:class"],
- ["th:utext"],
- ["th:remove"],
- ["th:classappend"],
- ["th:attr"],
- ["th:src"],
- ["th:href"],
- ["th:if"],
- ["style"],
- ["align"],
- ["target"]
- ]
- });
- return formatSrc;
- }
- function downloadLayoutSrc() {
- var formatSrc=getLayoutSrc();
- $("#download-layout").html(formatSrc);
- $("#downloadModal textarea").empty();
- $("#downloadModal textarea").val(formatSrc)
- }
- function saveHtmlLayout(tmpFile){
- $.ajax({
- type: "POST",
- url: getContextPath()+"/myconsole/design/save",
- data: { "layout": getLayoutSrc(),"layoutData":$('.demo').html(),"tmpFile":tmpFile},
- success: function(data) {
- //alert(data);
- }
- });
- }
- var currentDocument = null;
- var timerSave = 2e3;
- var demoHtml = $(".demo").html();
- $(window).resize(function() {
- $("body").css("min-height", $(window).height() - 90);
- $(".demo").css("min-height", $(window).height() - 160)
- });
- $(document).ready(function() {
- $("body").css("min-height", $(window).height() - 90);
- $(".demo").css("min-height", $(window).height() - 160);
- $(".demo, .demo .column").sortable({
- connectWith : ".column",
- opacity : .35,
- handle : ".drag"
- });
- $(".sidebar-nav .lyrow").draggable({
- connectToSortable : ".demo",
- helper : "clone",
- handle : ".drag",
- drag : function(e, t) {
- t.helper.width(400)
- },
- stop : function(e, t) {
- $(".demo .column").sortable({
- opacity : .35,
- cancel:".box>.view",
- connectWith : ".column"
- })
- }
- });
- $(".sidebar-nav .box").draggable({
- connectToSortable : ".column",
- helper : "clone",
- handle : ".drag",
- drag : function(e, t) {
- t.helper.width(400)
- },
- stop : function() {
- handleJsIds()
- }
- });
- $("[data-target=#downloadModal]").click(function(e) {
- e.preventDefault();
- downloadLayoutSrc()
- });
- $("#download").click(function() {
- downloadLayout();
- return false
- });
- $("#downloadhtml").click(function() {
- downloadHtmlLayout();
- return false
- });
- $("#edit").click(function() {
- $("body").removeClass("devpreview sourcepreview");
- $("body").addClass("edit");
- removeMenuClasses();
- $(this).addClass("active");
- return false
- });
- $("#clear").click(function(e) {
- e.preventDefault();
- clearDemo()
- });
- $("#devpreview").click(function() {
- $("body").removeClass("edit sourcepreview");
- $("body").addClass("devpreview");
- removeMenuClasses();
- $(this).addClass("active");
- return false
- });
- $("#sourcepreview").click(function() {
- $("body").removeClass("edit");
- $("body").addClass("devpreview sourcepreview");
- removeMenuClasses();
- $(this).addClass("active");
- return false
- });
- $(".nav-header").click(function() {
- $(".sidebar-nav .boxes, .sidebar-nav .rows").hide();
- $(this).next().slideDown()
- });
- removeElm();
- configurationElm();
- gridSystemGenerator();
- setInterval(function() {
- handleSaveLayout()
- }, timerSave)
- })
|