scripts.min.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. function getContextPath() {
  2. var pathName = document.location.pathname;
  3. var index = pathName.substr(1).indexOf("/");
  4. var result = pathName.substr(0,index+1);
  5. return result;
  6. }
  7. function handleSaveLayout() {
  8. var e = $(".demo").html();
  9. if (e != window.demoHtml) {
  10. saveLayout();
  11. window.demoHtml = e
  12. }
  13. }
  14. function handleJsIds() {
  15. handleModalIds();
  16. handleAccordionIds();
  17. handleCarouselIds();
  18. handleTabsIds()
  19. }
  20. function handleAccordionIds() {
  21. var e = $(".demo #myAccordion");
  22. var t = randomNumber();
  23. var n = "panel-" + t;
  24. var r;
  25. e.attr("id", n);
  26. e.find(".panel").each(function(e, t) {
  27. r = "panel-element-" + randomNumber();
  28. $(t).find(".panel-title").each(function(e, t) {
  29. $(t).attr("data-parent", "#" + n);
  30. $(t).attr("href", "#" + r)
  31. });
  32. $(t).find(".panel-collapse").each(function(e, t) {
  33. $(t).attr("id", r)
  34. })
  35. })
  36. }
  37. function handleCarouselIds() {
  38. var e = $(".demo #myCarousel");
  39. var t = randomNumber();
  40. var n = "carousel-" + t;
  41. e.attr("id", n);
  42. e.find(".carousel-indicators li").each(function(e, t) {
  43. $(t).attr("data-target", "#" + n)
  44. });
  45. e.find(".left").attr("href", "#" + n);
  46. e.find(".right").attr("href", "#" + n)
  47. }
  48. function handleModalIds() {
  49. var e = $(".demo #myModalLink");
  50. var t = randomNumber();
  51. var n = "modal-container-" + t;
  52. var r = "modal-" + t;
  53. e.attr("id", r);
  54. e.attr("href", "#" + n);
  55. e.next().attr("id", n)
  56. }
  57. function handleTabsIds() {
  58. var e = $(".demo #myTabs");
  59. var t = randomNumber();
  60. var n = "tabs-" + t;
  61. e.attr("id", n);
  62. e.find(".tab-pane").each(function(e, t) {
  63. var n = $(t).attr("id");
  64. var r = "panel-" + randomNumber();
  65. $(t).attr("id", r);
  66. $(t).parent().parent().find("a[href=#" + n + "]").attr("href", "#" + r)
  67. })
  68. }
  69. function randomNumber() {
  70. return randomFromInterval(1, 1e6)
  71. }
  72. function randomFromInterval(e, t) {
  73. return Math.floor(Math.random() * (t - e + 1) + e)
  74. }
  75. function gridSystemGenerator() {
  76. $(".lyrow .preview input").bind("keyup", function() {
  77. var e = 0;
  78. var t = "";
  79. var n = false;
  80. var r = $(this).val().split(" ", 12);
  81. $.each(r, function(r, i) {
  82. if (!n) {
  83. if (parseInt(i) <= 0)
  84. n = true;
  85. e = e + parseInt(i);
  86. t += '<div class="col-md-' + i + ' column"></div>'
  87. }
  88. });
  89. if (e == 12 && !n) {
  90. $(this).parent().next().children().html(t);
  91. $(this).parent().prev().show()
  92. } else {
  93. $(this).parent().prev().hide()
  94. }
  95. })
  96. }
  97. function configurationElm(e, t) {
  98. $(".demo").delegate(".configuration > a", "click", function(e) {
  99. e.preventDefault();
  100. var t = $(this).parent().next().next().children();
  101. $(this).toggleClass("active");
  102. t.toggleClass($(this).attr("rel"))
  103. });
  104. $(".demo").delegate(".configuration .dropdown-menu a", "click",
  105. function(e) {
  106. e.preventDefault();
  107. var t = $(this).parent().parent();
  108. var n = t.parent().parent().next().next().children();
  109. t.find("li").removeClass("active");
  110. $(this).parent().addClass("active");
  111. var r = "";
  112. t.find("a").each(function() {
  113. r += $(this).attr("rel") + " "
  114. });
  115. t.parent().removeClass("open");
  116. n.removeClass(r);
  117. n.addClass($(this).attr("rel"))
  118. })
  119. }
  120. function removeElm() {
  121. $(".demo").delegate(".remove", "click", function(e) {
  122. e.preventDefault();
  123. $(this).parent().remove();
  124. if (!$(".demo .lyrow").length > 0) {
  125. clearDemo()
  126. }
  127. })
  128. }
  129. function clearDemo() {
  130. $(".demo").empty()
  131. }
  132. function removeMenuClasses() {
  133. $("#menu-layoutit li button").removeClass("active")
  134. }
  135. function changeStructure(e, t) {
  136. $("#download-layout ." + e).removeClass(e).addClass(t)
  137. }
  138. function cleanHtml(e) {
  139. $(e).parent().append($(e).children().html())
  140. }
  141. function getLayoutSrc(){
  142. var e = "";
  143. $("#download-layout").children().html($(".demo").html());
  144. var t = $("#download-layout").children();
  145. t.find(".preview, .configuration, .drag, .remove").remove();
  146. t.find(".lyrow").addClass("removeClean");
  147. t.find(".box-element").addClass("removeClean");
  148. t.find(".lyrow .lyrow .lyrow .lyrow .lyrow .removeClean").each(function() {
  149. cleanHtml(this)
  150. });
  151. t.find(".lyrow .lyrow .lyrow .lyrow .removeClean").each(function() {
  152. cleanHtml(this)
  153. });
  154. t.find(".lyrow .lyrow .lyrow .removeClean").each(function() {
  155. cleanHtml(this)
  156. });
  157. t.find(".lyrow .lyrow .removeClean").each(function() {
  158. cleanHtml(this)
  159. });
  160. t.find(".lyrow .removeClean").each(function() {
  161. cleanHtml(this)
  162. });
  163. t.find(".removeClean").each(function() {
  164. cleanHtml(this)
  165. });
  166. t.find(".removeClean").remove();
  167. $("#download-layout .column").removeClass("ui-sortable");
  168. $("#download-layout .row-fluid").removeClass("clearfix").children()
  169. .removeClass("column");
  170. if ($("#download-layout .container").length > 0) {
  171. changeStructure("row-fluid", "row")
  172. }
  173. //myconsole.log($("#download-layout").html());
  174. formatSrc = $.htmlClean($("#download-layout").html(), {
  175. format : true,
  176. allowedAttributes : [
  177. [ "id" ], [ "class" ], [ "data-toggle" ],
  178. [ "data-target" ], [ "data-parent" ], [ "role" ],
  179. [ "data-dismiss" ], [ "aria-labelledby" ], [ "aria-hidden" ],
  180. [ "data-slide-to" ], [ "data-slide" ] ,
  181. ["th:with"],
  182. ["th:text"],
  183. ["th:each"],
  184. ["th:class"],
  185. ["th:utext"],
  186. ["th:remove"],
  187. ["th:classappend"],
  188. ["th:attr"],
  189. ["th:src"],
  190. ["th:href"],
  191. ["th:if"],
  192. ["style"],
  193. ["align"],
  194. ["target"]
  195. ]
  196. });
  197. return formatSrc;
  198. }
  199. function downloadLayoutSrc() {
  200. var formatSrc=getLayoutSrc();
  201. $("#download-layout").html(formatSrc);
  202. $("#downloadModal textarea").empty();
  203. $("#downloadModal textarea").val(formatSrc)
  204. }
  205. function saveHtmlLayout(tmpFile){
  206. $.ajax({
  207. type: "POST",
  208. url: getContextPath()+"/myconsole/design/save",
  209. data: { "layout": getLayoutSrc(),"layoutData":$('.demo').html(),"tmpFile":tmpFile},
  210. success: function(data) {
  211. //alert(data);
  212. }
  213. });
  214. }
  215. var currentDocument = null;
  216. var timerSave = 2e3;
  217. var demoHtml = $(".demo").html();
  218. $(window).resize(function() {
  219. $("body").css("min-height", $(window).height() - 90);
  220. $(".demo").css("min-height", $(window).height() - 160)
  221. });
  222. $(document).ready(function() {
  223. $("body").css("min-height", $(window).height() - 90);
  224. $(".demo").css("min-height", $(window).height() - 160);
  225. $(".demo, .demo .column").sortable({
  226. connectWith : ".column",
  227. opacity : .35,
  228. handle : ".drag"
  229. });
  230. $(".sidebar-nav .lyrow").draggable({
  231. connectToSortable : ".demo",
  232. helper : "clone",
  233. handle : ".drag",
  234. drag : function(e, t) {
  235. t.helper.width(400)
  236. },
  237. stop : function(e, t) {
  238. $(".demo .column").sortable({
  239. opacity : .35,
  240. cancel:".box>.view",
  241. connectWith : ".column"
  242. })
  243. }
  244. });
  245. $(".sidebar-nav .box").draggable({
  246. connectToSortable : ".column",
  247. helper : "clone",
  248. handle : ".drag",
  249. drag : function(e, t) {
  250. t.helper.width(400)
  251. },
  252. stop : function() {
  253. handleJsIds()
  254. }
  255. });
  256. $("[data-target=#downloadModal]").click(function(e) {
  257. e.preventDefault();
  258. downloadLayoutSrc()
  259. });
  260. $("#download").click(function() {
  261. downloadLayout();
  262. return false
  263. });
  264. $("#downloadhtml").click(function() {
  265. downloadHtmlLayout();
  266. return false
  267. });
  268. $("#edit").click(function() {
  269. $("body").removeClass("devpreview sourcepreview");
  270. $("body").addClass("edit");
  271. removeMenuClasses();
  272. $(this).addClass("active");
  273. return false
  274. });
  275. $("#clear").click(function(e) {
  276. e.preventDefault();
  277. clearDemo()
  278. });
  279. $("#devpreview").click(function() {
  280. $("body").removeClass("edit sourcepreview");
  281. $("body").addClass("devpreview");
  282. removeMenuClasses();
  283. $(this).addClass("active");
  284. return false
  285. });
  286. $("#sourcepreview").click(function() {
  287. $("body").removeClass("edit");
  288. $("body").addClass("devpreview sourcepreview");
  289. removeMenuClasses();
  290. $(this).addClass("active");
  291. return false
  292. });
  293. $(".nav-header").click(function() {
  294. $(".sidebar-nav .boxes, .sidebar-nav .rows").hide();
  295. $(this).next().slideDown()
  296. });
  297. removeElm();
  298. configurationElm();
  299. gridSystemGenerator();
  300. setInterval(function() {
  301. handleSaveLayout()
  302. }, timerSave)
  303. })