From 6d7fe834695835fea6d9195392d1008a1fd0395f Mon Sep 17 00:00:00 2001 From: yu huang <286417333@qq.com> Date: Sat, 29 Aug 2015 19:19:11 -0400 Subject: [PATCH] move script from footer.js have fixed bug of multiple active of email and send to users. also make URL like "http://localhost:9000/admin/t?p=0&t=email/sendToUsers" work. --- public/admin/js/admin.js | 67 ++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/public/admin/js/admin.js b/public/admin/js/admin.js index 0c28c87..517adeb 100644 --- a/public/admin/js/admin.js +++ b/public/admin/js/admin.js @@ -274,21 +274,56 @@ function goNowToDatetime(goNow) { !function ($) { $(function(){ - // life - $(".nav li > a").click(function(e) { - $p = $(this).closest("ul"); - var $li = $(this).closest("li"); - if($li.find("ul").length == 0) { - return true; - } - e.preventDefault(); - var hasClass = $li.hasClass("active"); - $p.find("li").removeClass("active"); - if(hasClass) { - } else { - $li.addClass("active"); - } - }); + //navigation + !function ($) { + /** + * description + * every href must begin with "?t=" + */ + //initial + function getParameterByName(name, queryString) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); //address array [] condiion + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(queryString); + return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + } + + var pathname = window.location.pathname; // admin/t + var search = window.location.search; // ?t=xxx + var fullPath = pathname; + + //test case + //http://localhost:9000/admin/t?p=0&t=email/sendToUsers + //t=email/sendToUsers and t=email/send + var paramId = getParameterByName("t",window.location.search) + if(paramId !== "") { + var fullPath = pathname + "?t=" + paramId; // /admin/t?t=xxx + } + + $("#nav > li").removeClass("active"); + + var $thisLi = $('#nav a[href="' + fullPath + '"]').parent(); + // 自己 + $thisLi.addClass("active"); + // 父也active + $thisLi.parent().parent().addClass('active'); + + // event binding + $(".nav li > a").click(function(e) { + $p = $(this).closest("ul"); + var $li = $(this).closest("li"); + if($li.find("ul").length == 0) { + return true; + } + e.preventDefault(); + var hasClass = $li.hasClass("active"); + $p.find("li").removeClass("active"); + if(hasClass) { + } else { + $li.addClass("active"); + } + }); + }($); // sort $(".th-sortable").click(function() { @@ -566,4 +601,4 @@ function goNowToDatetime(goNow) { }); -}(window.jQuery); \ No newline at end of file +}(window.jQuery);