function supportstorage() { if (typeof window.localStorage=='object') return true; else return false; } function handleSaveLayout() { var e = $(".demo").html(); if (!stopsave && e != window.demoHtml) { stopsave++; window.demoHtml = e; saveLayout(); stopsave--; } } var layouthistory; function saveLayout(){ var data = layouthistory; if (!data) { data={}; data.count = 0; data.list = []; } if (data.list.length>data.count) { for (i=data.count;i' }); if (e == 12) { $(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(); layouthistory = null; if (supportstorage()) localStorage.removeItem("layoutdata"); } 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 downloadLayoutSrc() { 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") } 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"] ] }); $("#download-layout").html(formatSrc); $("#downloadModal textarea").empty(); $("#downloadModal textarea").val(formatSrc) } var currentDocument = null; var timerSave = 1000; var stopsave = 0; var startdrag = 0; var demoHtml = $(".demo").html(); var currenteditor = null; $(window).resize(function() { $("body").css("min-height", $(window).height() - 90); $(".demo").css("min-height", $(window).height() - 160) }); function restoreData(){ if (supportstorage()) { layouthistory = JSON.parse(localStorage.getItem("layoutdata")); if (!layouthistory) return false; window.demoHtml = layouthistory.list[layouthistory.count-1]; if (window.demoHtml) $(".demo").html(window.demoHtml); } } function initContainer(){ $(".demo, .demo .column").sortable({ connectWith: ".column", opacity: .35, handle: ".drag", start: function(e,t) { if (!startdrag) stopsave++; startdrag = 1; }, stop: function(e,t) { if(stopsave>0) stopsave--; startdrag = 0; } }); configurationElm(); } $(document).ready(function() { CKEDITOR.disableAutoInline = true; restoreData(); var contenthandle = CKEDITOR.replace( 'contenteditor' ,{ language: 'zh-cn', contentsCss: ['css/bootstrap-combined.min.css'], allowedContent: true }); $("body").css("min-height", $(window).height() - 90); $(".demo").css("min-height", $(window).height() - 160); $(".sidebar-nav .lyrow").draggable({ connectToSortable: ".demo", helper: "clone", handle: ".drag", start: function(e,t) { if (!startdrag) stopsave++; startdrag = 1; }, drag: function(e, t) { t.helper.width(400) }, stop: function(e, t) { $(".demo .column").sortable({ opacity: .35, connectWith: ".column", start: function(e,t) { if (!startdrag) stopsave++; startdrag = 1; }, stop: function(e,t) { if(stopsave>0) stopsave--; startdrag = 0; } }); if(stopsave>0) stopsave--; startdrag = 0; } }); $(".sidebar-nav .box").draggable({ connectToSortable: ".column", helper: "clone", handle: ".drag", start: function(e,t) { if (!startdrag) stopsave++; startdrag = 1; }, drag: function(e, t) { t.helper.width(400) }, stop: function() { handleJsIds(); if(stopsave>0) stopsave--; startdrag = 0; } }); initContainer(); $('body.edit .demo').on("click","[data-target=#editorModal]",function(e) { e.preventDefault(); currenteditor = $(this).parent().parent().find('.view'); var eText = currenteditor.html(); contenthandle.setData(eText); }); $("#savecontent").click(function(e) { e.preventDefault(); currenteditor.html(contenthandle.getData()); }); $("[data-target=#downloadModal]").click(function(e) { e.preventDefault(); downloadLayoutSrc(); }); $("[data-target=#shareModal]").click(function(e) { e.preventDefault(); handleSaveLayout(); }); $("#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 }); $("#fluidPage").click(function(e) { e.preventDefault(); changeStructure("container", "container-fluid"); $("#fixedPage").removeClass("active"); $(this).addClass("active"); downloadLayoutSrc() }); $("#fixedPage").click(function(e) { e.preventDefault(); changeStructure("container-fluid", "container"); $("#fluidPage").removeClass("active"); $(this).addClass("active"); downloadLayoutSrc() }); $(".nav-header").click(function() { $(".sidebar-nav .boxes, .sidebar-nav .rows").hide(); $(this).next().slideDown() }); $('#undo').click(function(){ stopsave++; if (undoLayout()) initContainer(); stopsave--; }); $('#redo').click(function(){ stopsave++; if (redoLayout()) initContainer(); stopsave--; }); removeElm(); gridSystemGenerator(); setInterval(function() { handleSaveLayout() }, timerSave) })