/** core script to handle the entire theme and core functions **/ var layout = function () { var _gourl = function(url, index, that) { if (index <= 0) { index = layer.load(2, { time: 10 * 1000 }); } var pagecontentbody = $('.wrapper .page-content'); $.ajax({ type: "get", cache: false, url: url, datatype: "html", success: function (res) { _handlegourl(index, that); pagecontentbody.html(res); }, error: function (xhr, ajaxoptions, thrownerror) { layer.close(index); layer.alert(xhr.responsetext, function (index) { layer.close(index); }); } }); }; var _handlegourl = function (index, that) { layer.close(index); if (that) { $('#navbar .sub-nav dd').removeclass('current'); $(that).parent().addclass('current'); $(that).closest('.j-root-menu-dd').addclass('current').siblings().removeclass('current'); } }; // handle sidebar menu var handlesidebarmenu = function () { // handle ajax links within sidebar menu $('#navbar').on('click', '.j-root-menu', function (e) { e.preventdefault(); var _href = $(this).attr('href'); if (_href != 'javascript:;') { _gourl(_href, 0, $(this)); } }); $('#navbar').on('click', '.sub-nav a', function (e) { e.preventdefault(); _gourl($(this).attr("href"), 0, $(this)); }); // handle ajax link within main content $('.page-content').on('click', '.ajaxify', function(e) { e.preventdefault(); _gourl($(this).attr("href"), 0, undefined); }); }; var loadpage = function (url) { _gourl(url, 0, undefined); }; return { init: function () { $.ajax({ url: '/admin/console/getmenulist', type: 'get', datatype: "json", success: function (result) { $('#navbar .nav').empty(); $("#tmplmenu").tmpl(result).appendto('#navbar .nav'); } }); handlesidebarmenu(); }, loadpage: function (url) { loadpage(url); } }; }();