2 * Created by WebStorm on 15-9-13.
5 var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
12 * Encode multi-byte Unicode string into utf-8 multiple single-byte characters
13 * (BMP / basic multilingual plane only)
15 * Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars
17 * @param {String} strUni Unicode string to be encoded as UTF-8
18 * @returns {String} encoded string
20 encode: function (strUni) {
21 // use regular expressions & String.replace callback function for better efficiency
22 // than procedural approaches
23 var strUtf = strUni.replace(/[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz
25 var cc = c.charCodeAt(0);
26 return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f);
28 .replace(/[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz
30 var cc = c.charCodeAt(0);
31 return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f);
36 * Decode utf-8 encoded string back into multi-byte Unicode characters
38 * @param {String} strUtf UTF-8 string to be decoded back to Unicode
39 * @returns {String} decoded string
41 decode: function (strUtf) {
42 // note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char!
43 var strUni = strUtf.replace(/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars
44 function (c) { // (note parentheses for precence)
45 var cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | (c.charCodeAt(2) & 0x3f);
46 return String.fromCharCode(cc);
48 .replace(/[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars
49 function (c) { // (note parentheses for precence)
50 var cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f;
51 return String.fromCharCode(cc);
57 var c = String.fromCharCode(i);
60 r64[i] = b64.indexOf(c);
63 function code(s, discard, alpha, beta, w1, w2) {
71 var c = s.charCodeAt(i);
72 c = c < 256 ? alpha[c] : -1;
73 buffer = (buffer << w1) + c;
75 while (bitsInBuffer >= w2) {
77 var tmp = buffer >> bitsInBuffer;
78 result += beta.charAt(tmp);
79 buffer ^= tmp << bitsInBuffer;
83 if (!discard && bitsInBuffer > 0) result += beta.charAt(buffer << (w2 - bitsInBuffer));
87 var Plugin = $.base64 = function (dir, input, encode) {
88 return input ? Plugin[dir](input, encode) : dir ? null : this;
90 Plugin.btoa = Plugin.encode = function (plain, utf8encode) {
91 plain = Plugin.raw === false || Plugin.utf8encode || utf8encode ? UTF8.encode(plain) : plain;
92 plain = code(plain, false, r256, b64, 8, 6);
93 return plain + '===='.slice((plain.length % 4) || 4);
95 Plugin.atob = Plugin.decode = function (coded, utf8decode) {
96 coded = String(coded).split('=');
100 coded[i] = code(coded[i], true, r64, a256, 6, 8);
102 coded = coded.join('');
103 return Plugin.raw === false || Plugin.utf8decode || utf8decode ? UTF8.decode(coded) : coded;
108 function trimText(text) {
109 return text.replace(/[ \t\n\r]+/g, " ");
113 var tree = undefined;
114 var lastNode = undefined;
116 function getCurrentNodeByHash() {
118 var hash = window.location.hash;
119 if (hash.substr(0, 6) == "#tree-") {
120 hash = $.base64.decode(hash.substr(6));
121 tree = hash.split("|");
122 $(".main > .main-left > .nav > .slide > .menu").each(function () {
124 if (trimText(that.data("title")) == tree[0]) {
126 that.next().find("a").each(function () {
128 if (trimText(that.data("title")) == tree[1]) {
129 lastNode = that.parent();
130 lastNode.addClass("active");
141 function getCurrentNodeByUrl() {
143 var getUrlNode = function (href){
144 var linkPos = href.indexOf(";");
148 linkPos = href.indexOf("/", linkPos);
152 var link = href.substr(linkPos);
161 var currentNode = getUrlNode(window.location.pathname);
163 if (currentNode == "login"){
164 tree = ["Main", "Login"];
166 }else if(currentNode == "overview"){
167 tree = ["Status", "Overview"];
168 lastNode = $($($(".main > .main-left > .nav > .slide > .menu")[0]).next().find("a")[0]).parent();
172 $(".main > .main-left > .nav > .slide > .menu").each(function () {
173 var ulNode = $(this);
174 ulNode.next().find("a").each(function () {
176 var href = that.attr("href");
178 if (currentNode.indexOf(getUrlNode(href)) != -1){
180 lastNode = that.parent();
181 tree = [trimText(ulNode.data("title")), trimText(that.data("title"))];
182 lastNode.addClass("active");
191 $(".main > .main-left > .nav > .slide > .menu").click(function () {
192 var ul = $(this).next(".slide-menu");
194 if (!ul.is(":visible")) {
195 menu.addClass("active");
196 ul.addClass("active");
197 ul.stop(true).slideDown();
199 ul.slideUp(function () {
200 menu.removeClass("active");
201 ul.removeClass("active");
206 $(".main > .main-left > .nav > .slide > .slide-menu > li > a").click(function () {
207 var href = $(this).attr("href");
208 var tree = trimText($(this).parent().parent().prev().data("title")) + "|" + trimText($(this).data("title"));
209 tree = $.base64.encode(tree);
210 window.location = href + "#tree-" + tree;
211 if (lastNode != undefined) lastNode.removeClass("active");
212 $(this).parent().addClass("active");
216 $(".main > .main-left > .nav > .slide > .slide-menu > li").click(function () {
217 $(this).find("a").click();
221 if (!getCurrentNodeByUrl()){
222 getCurrentNodeByHash();
223 if (tree[0] == "Status" && tree[1] == "Overview"){
225 lastNode.addClass("active");
226 $($(".main > .main-left > .nav > .slide > .menu")[0]).click();
229 var mainNodeName = "node-"+ tree[0] + "-" + tree[1];
230 $("body").addClass(mainNodeName.replace(/[ \t\n\r\/]+/g,"_").toLowerCase());
231 $(".cbi-button-up").val("");
232 $(".cbi-button-down").val("");
235 $("#maincontent > .container").find("a").each(function () {
237 var onclick = that.attr("onclick");
238 if (onclick == undefined || onclick == ""){
239 that.click(function () {
240 var href = that.attr("href");
241 if (tree != undefined && href.indexOf("Text") == -1) {
242 window.location = href + "#tree-" + $.base64.encode(tree[0] + "|" + tree[1]);
251 var showSide = false;
252 $(".showSide").click(function () {
254 $(".darkMask").stop(true).fadeOut();
255 $(".main-left").stop(true).animate({
260 $(".darkMask").stop(true).fadeIn();
261 $(".main-left").stop(true).animate({
269 $(".darkMask").click(function () {
272 $(".darkMask").stop(true).fadeOut();
273 $(".main-left").stop(true).animate({
279 $(window).resize(function() {
280 if ($(window).width() > 921) {
281 $(".main-left").css("width", "");
282 $(".darkMask").stop(true);
283 $(".darkMask").css("display", "none");
288 $("legend").each(function () {
290 that.after("<span class='panel-title'>" + that.text() + "</span>");
293 window.scrollTo(0,1);