/**
- * Created by WebStorm on 15-9-13.
+ * Material is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI
+ *
+ * luci-theme-material
+ * Copyright 2015 Lutty Yang <lutty@wcan.in>
+ *
+ * Have a bug? Please create an issue here on GitHub!
+ * https://github.com/LuttyYang/luci-theme-material/issues
+ *
+ * luci-theme-bootstrap:
+ * Copyright 2008 Steven Barth <steven@midlink.org>
+ * Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
+ * Copyright 2012 David Menting <david@nut-bolt.nl>
+ *
+ * MUI:
+ * https://github.com/muicss/mui
+ *
+ * Licensed to the public under the Apache License 2.0
*/
(function ($) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
};
}(jQuery));
+(function ($) {
+ $(".main > .loading").fadeOut();
+
+ /**
+ * trim text, Remove spaces, wrap
+ * @param text
+ * @returns {string}
+ */
+ function trimText(text) {
+ return text.replace(/[ \t\n\r]+/g, " ");
+ }
-function trimText(text) {
- return text.replace(/[ \t\n\r]+/g, " ");
-}
-(function ($) {
var tree = undefined;
var lastNode = undefined;
+ var mainNodeName = undefined;
- function getCurrentNodeByHash() {
- var ret = false;
- var hash = window.location.hash;
- if (hash.substr(0, 6) == "#tree-") {
- hash = $.base64.decode(hash.substr(6));
- tree = hash.split("|");
- $(".main > .main-left > .nav > .slide > .menu").each(function () {
- var that = $(this);
- if (trimText(that.data("title")) == tree[0]) {
- that.click();
- that.next().find("a").each(function () {
- var that = $(this);
- if (trimText(that.data("title")) == tree[1]) {
- lastNode = that.parent();
- lastNode.addClass("active");
- ret = true;
- return true;
- }
- });
- }
- });
- }
- return ret;
- }
-
+ /**
+ * get the current node by Burl (primary)
+ * @returns {boolean} success?
+ */
function getCurrentNodeByUrl() {
var ret = false;
var getUrlNode = function (href){
- var linkPos = href.indexOf(";");
- if (linkPos == -1){
+ if (!$('body').hasClass('logged-in')){
return "login";
}else{
- linkPos = href.indexOf("/", linkPos);
+ var linkPos = href.indexOf("/", linkPos);
if (linkPos == -1){
return "overview";
}else{
if (currentNode.indexOf(getUrlNode(href)) != -1){
ulNode.click();
+ ulNode.next(".slide-menu").stop(true,true);
lastNode = that.parent();
tree = [trimText(ulNode.data("title")), trimText(that.data("title"))];
lastNode.addClass("active");
return ret;
}
+ /**
+ * menu click
+ */
$(".main > .main-left > .nav > .slide > .menu").click(function () {
var ul = $(this).next(".slide-menu");
var menu = $(this);
if (!ul.is(":visible")) {
menu.addClass("active");
ul.addClass("active");
- ul.stop(true).slideDown();
+ ul.stop(true).slideDown("fast");
} else {
- ul.slideUp(function () {
+ ul.stop(true).slideUp("fast", function () {
menu.removeClass("active");
ul.removeClass("active");
});
}
});
+ /**
+ * hook menu click and add the hash
+ */
$(".main > .main-left > .nav > .slide > .slide-menu > li > a").click(function () {
- var href = $(this).attr("href");
- var tree = trimText($(this).parent().parent().prev().data("title")) + "|" + trimText($(this).data("title"));
- tree = $.base64.encode(tree);
- window.location = href + "#tree-" + tree;
if (lastNode != undefined) lastNode.removeClass("active");
$(this).parent().addClass("active");
- return false;
+ $(".main > .loading").fadeIn("fast");
+ return true;
});
+ /**
+ * fix menu click
+ */
$(".main > .main-left > .nav > .slide > .slide-menu > li").click(function () {
- $(this).find("a").click();
+ if (lastNode != undefined) lastNode.removeClass("active");
+ $(this).addClass("active");
+ $(".main > .loading").fadeIn("fast");
+ window.location = $($(this).find("a")[0]).attr("href");
+ return;
});
-
+ /**
+ * get current node and open it
+ */
if (!getCurrentNodeByUrl()){
- getCurrentNodeByHash();
- if (tree[0] == "Status" && tree[1] == "Overview"){
+ if (tree != undefined && tree[0] == "Status" && tree[1] == "Overview"){
//overview
lastNode.addClass("active");
$($(".main > .main-left > .nav > .slide > .menu")[0]).click();
}
}
- var mainNodeName = "node-"+ tree[0] + "-" + tree[1];
- $("body").addClass(mainNodeName.replace(/[ \t\n\r\/]+/g,"_").toLowerCase());
+ if (tree != undefined){
+ mainNodeName = "node-"+ tree[0] + "-" + tree[1];
+ mainNodeName = mainNodeName.replace(/[ \t\n\r\/]+/g,"_").toLowerCase();
+ $("body").addClass(mainNodeName);
+
+ }
$(".cbi-button-up").val("");
$(".cbi-button-down").val("");
+ /**
+ * hook other "A Label" and add hash to it.
+ */
$("#maincontent > .container").find("a").each(function () {
var that = $(this);
var onclick = that.attr("onclick");
if (onclick == undefined || onclick == ""){
that.click(function () {
var href = that.attr("href");
- if (tree != undefined && href.indexOf("Text") == -1) {
- window.location = href + "#tree-" + $.base64.encode(tree[0] + "|" + tree[1]);
- return false;
- }else{
+ if (href.indexOf("#") == -1){
+ $(".main > .loading").fadeIn("fast");
return true;
}
});
}
});
+ /**
+ * Sidebar expand
+ */
var showSide = false;
$(".showSide").click(function () {
if (showSide){
- $(".darkMask").stop(true).fadeOut();
+ $(".darkMask").stop(true).fadeOut("fast");
$(".main-left").stop(true).animate({
width: "0"
- });
+ },"fast");
showSide = false;
}else{
- $(".darkMask").stop(true).fadeIn();
+ $(".darkMask").stop(true).fadeIn("fast");
$(".main-left").stop(true).animate({
width: "15rem"
- });
+ },"fast");
showSide = true;
}
});
$(".darkMask").click(function () {
if (showSide){
showSide = false;
- $(".darkMask").stop(true).fadeOut();
+ $(".darkMask").stop(true).fadeOut("fast");
$(".main-left").stop(true).animate({
width: "0"
- });
+ },"fast");
}
});
}
});
+ /**
+ * fix legend position
+ */
$("legend").each(function () {
var that = $(this);
that.after("<span class='panel-title'>" + that.text() + "</span>");
});
- window.scrollTo(0,1);
+
+ $(".main-right").focus();
+ $(".main-right").blur();
+ $("input").attr("size", "0");
+
+ if (mainNodeName != undefined){
+ console.log(mainNodeName);
+ switch (mainNodeName){
+ case "node-status-system_log":
+ case "node-status-kernel_log":
+ $("#syslog").focus(function () {
+ $("#syslog").blur();
+ $(".main-right").focus();
+ $(".main-right").blur();
+ });
+ break;
+ case "node-status-firewall":
+ var button = $(".node-status-firewall > .main fieldset li > a");
+ button.addClass("cbi-button cbi-button-reset a-to-btn");
+ break;
+ case "node-system-reboot":
+ var button = $(".node-system-reboot > .main > .main-right p > a");
+ button.addClass("cbi-button cbi-input-reset a-to-btn");
+ break;
+ }
+ }
+
+
+ document.addEventListener("touchmove", function(evt){
+ evt.preventDefault();
+ }, false);
+ var container = document.getElementById("maincontent");
+ container.addEventListener("touchmove", function(evt){
+ evt.stopPropagation();
+ }, false);
})(jQuery);