String.prototype.trim = function () { var str = this, str = str.replace(/^\s+/, ''); for (var i = str.length - 1; i >= 0; i--) { if (/\S/.test(str.charAt(i))) { str = str.substring(0, i + 1); break; } } return str; } Array.prototype.Contain = function (item) { var array = this; for (var i = array.length - 1; i >= 0; i--) { if (array[i] == item) return true; } return false; } var trendInit = function () { if (typeof $("#chartData")[0] == "undefined") return; var c = trendChart("chartData", "chartLine"); c.Init(); $(".ctl-list").children(".ctl-item").children(":checkbox").click(function () { var $this = $(this); var $checked = $this.attr("checked") || false; var _name = $this.attr("name"); $(".ctl-box").children(".ctl-item").children("[name='" + _name + "']").each(function () { $(this).attr("checked", $checked); }); switch (_name) { case "ctl_foldLine": c.ShowLine($checked); break; case "ctl_miss": $("#trendBox").attr("class", $checked ? "item nomiss" : "item"); break; case "ctl_sliceMiss": c.SliceMiss($checked); break; case "ctl_repeat": c.Repeat($checked); break; case "ctl_continuous": c.Continuous($checked); break case "ctl_near": c.Near($checked); break; case "ctl_jump": c.Jump($checked); break; } //Modified by zizi at 2016-6-2 setTimeout(function() { $('.cancel').click(); }, 200); }); var _pbox = $("tbody.presele-box"); if (2 == _pbox.length) { _pbox.eq(1).children("tr").children("td").each(function () { var $this = $(this); var pl = $this.attr("pl") || ""; var _s = (pl === "orange" || pl === "bgblue") ? "presele-square" : "presele-ball"; if (0 < pl.length) { $this.click(function () { $this.attr("class", ($this.attr("class") == _s ? "presele-" + pl : _s)); }); } }); _pbox.eq(0).children("tr").each(function (i) { var $this = $(this); $this.children("td").children("span").click(function () { //$this.hide(); _pbox.eq(1).children("tr").eq(i).hide(); }); $this.children("td").children("strong").click(function () { var t = _pbox.eq(0).children("tr"); for (var i = 1; i < t.length; i++) { if ("none" == t.eq(i).css("display")) { t.eq(i).show(); break; } } var s = _pbox.eq(1).children("tr"); for (var i = 1; i < s.length; i++) { if ("none" == s.eq(i).css("display")) { s.eq(i).show(); break; } } }); }); } $(".dataAnalysisBox").children(":radio").click(function () { var $this = $(this); var $checked = $this.attr("checked") || false; var _id = $this.attr("id"); var c = "currentAnalysis" == _id; if ((c && $checked) || (!c && !$checked)) { $("#currentData").attr("style", ""); $("#historyData").hide(); } else { $("#currentData").hide(); $("#historyData").attr("style", ""); } }); } var trendSearch = function () { $("input.searchs").click(function () { var _s = $("#startTerm").val(), _e = $("#endTerm").val(); if ($("#startTerm").attr("type") != "Date") { if (7 != _s.length) { alert("查询开始期数错误,请重新输入!"); return; } if (7 != _e.length) { alert("查询结束期数错误,请重新输入!"); return; } window.location = window.location.href.split("?")[0] + "?startTerm=" + _s + "&endTerm=" + _e; } else { if (10 != _s.length) { alert("查询开始期数错误,请重新输入!"); return; } window.location = window.location.href.split("?")[0] + "?searchTime=" + _s; } }); /*modify by djp 2016-06-03 修正addclass、prop */ var _search = window.location.search.toLowerCase(); if (_search.indexOf("record") != -1) { $(".search-link").children("a").each(function () { var $this = $(this); $this.removeClass("select"); if ($this.attr("href").toLowerCase() === _search) { $this.addClass("select"); } }); } if (_search.indexOf("year") != -1) { var _i = _search.split("&")[0].split("=")[1] + "年", _b = false; ; $(".mSelectBox").children("option").each(function () { var $this = $(this); $this.prop("selected", false); if ($this.text() == _i) { $this.prop("selected", true); _b = true; } }); if (!_b) { $(".mSelectBox").children("option").eq(0).text("selected",true); }; } } var trendChart = function (t, d, s) { this.sortDirection = 0; var _d = $("#" + d); var _e = $("#" + t); var _s = s || 1.5; var a_p = new Array(); var a_term = new Array(); this.Init = function () { _d.html(""); var row = _e.children("tr"); var t = "", c = "", n = "", r = 0, k = 0, u = new Array(), l = new Array(); for (var i = row.length - 1; i >= 0; i--) { var col = row.eq(i).children("td"); a_term.push(col.eq(0).text()); for (var j = col.length - 1; j >= 0; j--) { t = col.eq(j).attr("lgroup") || ""; if (0 >= t.length) { continue; } n = col.eq(j)[0].className; if (n.indexOf("ball") > -1) { r = 8; } if (n.indexOf("triangle") > -1) { r = 4; } if (n.indexOf("round") > -1) { r = 6; } c = col.eq(j).attr("lcolor"); if (4 > c.length) { c = n.indexOf("red") == -1 ? "#387ec0" : "#b94c59"; } l[k] = f_a(col.eq(j), t, r); if (u && u[k] && u[k].g == l[k].g) { f_paint(f_b(u[k], l[k], c)); } k++; } k = 0; u = l; l = new Array(); } a_term.sort(); }; this.Sort = function () { var row = new Array(); var _tr = _e.children("tr"); for (var i = _tr.length - 1; i >= 0; i--) { row.push(_tr.eq(i)[0].outerHTML); } _d.html(""); _e.html(row.join("")); f_repaint(); }; this.ShowLine = function (show) { if (!show) { _d.hide(); } else { _d.show(); } }; this.SliceMiss = function (show) { var row = _e.children("tr"); var v = 0, name = "", cell = new Array(), a_sm = new Array(); if (0 == this.sortDirection) { for (var i = row.length - 1; i >= 0; i--) { var col = row.eq(i).children("td"); for (var j = col.length - 1; j >= 0; j--) { name = col.eq(j).attr("lgroup") || ""; if (0 < name.length) { if (!cell.Contain(j)) { cell.push(j); } continue; } name = col.eq(j).attr("class") || ""; if (name.indexOf("miss") == -1) { if (!cell.Contain(j)) { cell.push(j); } continue; } if (!cell.Contain(j)) { a_sm.push({ obj: col.eq(j), cell: j, row: v }); } } v++; } } else { for (var i = 0; i < row.length; i++) { var col = row.eq(i).children("td"); for (var j = col.length - 1; j >= 0; j--) { name = col.eq(j).attr("lgroup") || ""; if (0 < name.length) { if (!cell.Contain(j)) { cell.push(j); } continue; } name = col.eq(j).attr("class") || ""; if (name.indexOf("miss") == -1) { if (!cell.Contain(j)) { cell.push(j); } continue; } if (!cell.Contain(j)) { a_sm.push({ obj: col.eq(j), cell: j, row: v }); } } v++; } } var cssCell = new Array(); for (var i = a_sm.length - 1; i >= 0; i--) { if (a_sm[i].row > 11) { cssCell[a_sm[i].cell] = "sliceMiss-m"; continue; } if (a_sm[i].row > 5) { cssCell[a_sm[i].cell] = cssCell[a_sm[i].cell] || "sliceMiss-11"; continue; } cssCell[a_sm[i].cell] = cssCell[a_sm[i].cell] || "sliceMiss-5"; } var css = ""; for (var i = a_sm.length - 1; i >= 0; i--) { css = cssCell[a_sm[i].cell] || "sliceMiss-5"; if (show) a_sm[i].obj.attr("class", a_sm[i].obj.attr("class") + " " + css); else a_sm[i].obj.attr("class", a_sm[i].obj.attr("class").replace(css, "")); } }; this.Repeat = function (show) { var row = _e.children("tr"); if (0 == this.sortDirection) { for (var i = 1; i < row.length; i++) { var col = row.eq(i).children("td"); var cot = row.eq(i - 1).children("td"); for (var j = col.length - 1; j >= 0; j--) { if ((col.eq(j).attr("class") || "").indexOf("ball") == -1) continue; if (0 >= (col.eq(j).attr("lgroup") || "").length) continue; if (0 >= (cot.eq(j).attr("lgroup") || "").length) continue; col.eq(j)[0].className = show ? col.eq(j)[0].className + " ball-green" : col.eq(j)[0].className.replace("ball-green", ""); } } } else { for (var i = row.length - 2; i >= 0; i--) { var col = row.eq(i).children("td"); var cot = row.eq(i + 1).children("td"); for (var j = col.length - 1; j >= 0; j--) { if ((col.eq(j).attr("class") || "").indexOf("ball") == -1) continue; if (0 >= (col.eq(j).attr("lgroup") || "").length) continue; if (0 >= (cot.eq(j).attr("lgroup") || "").length) continue; col.eq(j)[0].className = show ? col.eq(j)[0].className + " ball-green" : col.eq(j)[0].className.replace("ball-green", ""); } } } }; this.Near = function (show) { var row = _e.children("tr"); var g = "", gtl = "", gtr = ""; if (0 == this.sortDirection) { for (var i = 1; i < row.length; i++) { var col = row.eq(i).children("td"); var cot = row.eq(i - 1).children("td"); for (var j = col.length - 1; j >= 0; j--) { if ((col.eq(j).attr("class") || "").indexOf("ball") == -1) continue; g = col.eq(j).attr("lgroup") || ""; if (0 >= g.length) continue; gtl = cot.eq(j - 1).attr("lgroup") || ""; gtr = cot.eq(j + 1).attr("lgroup") || ""; if (g == gtl || g == gtr) { col.eq(j)[0].className = show ? col.eq(j)[0].className + " ball-orange" : col.eq(j)[0].className.replace("ball-orange", ""); } } } } else { for (var i = row.length - 2; i >= 0; i--) { var col = row.eq(i).children("td"); var cot = row.eq(i + 1).children("td"); for (var j = col.length - 1; j >= 0; j--) { if ((col.eq(j).attr("class") || "").indexOf("ball") == -1) continue; g = col.eq(j).attr("lgroup") || ""; if (0 >= g.length) continue; gtl = cot.eq(j - 1).attr("lgroup") || ""; gtr = cot.eq(j + 1).attr("lgroup") || ""; if (g == gtl || g == gtr) { col.eq(j)[0].className = show ? col.eq(j)[0].className + " ball-orange" : col.eq(j)[0].className.replace("ball-orange", ""); } } } } }; this.Jump = function (show) { var row = _e.children("tr"); if (0 == this.sortDirection) { for (var i = 2; i < row.length; i++) { var col = row.eq(i).children("td"); var cot = row.eq(i - 2).children("td"); for (var j = col.length - 1; j >= 0; j--) { if ((col.eq(j).attr("class") || "").indexOf("ball") == -1) continue; if (0 >= (col.eq(j).attr("lgroup") || "").length) continue; if (0 >= (cot.eq(j).attr("lgroup") || "").length) continue; col.eq(j)[0].className = show ? col.eq(j)[0].className + " ball-purple" : col.eq(j)[0].className.replace("ball-purple", ""); } } } else { for (var i = row.length - 3; i >= 0; i--) { var col = row.eq(i).children("td"); var cot = row.eq(i + 2).children("td"); for (var j = col.length - 1; j >= 0; j--) { if ((col.eq(j).attr("class") || "").indexOf("ball") == -1) continue; if (0 >= (col.eq(j).attr("lgroup") || "").length) continue; if (0 >= (cot.eq(j).attr("lgroup") || "").length) continue; col.eq(j)[0].className = show ? col.eq(j)[0].className + " ball-purple" : col.eq(j)[0].className.replace("ball-purple", ""); } } } }; this.Continuous = function (show) { var row = _e.children("tr"); var g = "", gr = ""; for (var i = row.length - 1; i >= 0; i--) { var col = row.eq(i).children("td"); for (var j = 1; j < col.length; j++) { if ((col.eq(j).attr("class") || "").indexOf("ball") == -1) continue; g = col.eq(j).attr("lgroup") || ""; if (0 >= g.length) continue; gr = col.eq(j - 1).attr("lgroup") || ""; if (g == gr) { col.eq(j)[0].className = show ? col.eq(j)[0].className + " ball-lightgreen" : col.eq(j)[0].className.replace("ball-lightgreen", ""); } } } }; var f_paint = function (p) { if (!p || p == "undefined") return; _d.append(chartLine(p, _s)); }; var f_repaint = function () { var h = _e.height(), t = _e.position().top; for (var i = a_p.length - 1; i >= 0; i--) { a_p[i].s.t = h + 2 * t - a_p[i].s.t; a_p[i].e.t = h + 2 * t - a_p[i].e.t; _d.append(f_paint(a_p[i])); } }; var f_b = function (x, y, z) { var x1 = x.l - y.l, x2 = x.t - y.t; var s = Math.round(Math.sqrt(Math.pow(x1, 2) + Math.pow(x2, 2))); var i = x.r, t, p; if (1 > i) { if (x2 / x1 >= x.rh / x.rw) { i = x.rh; } else { i = x.rw; } } t = Math.round((x1 * i) / s); p = Math.round((x2 * i) / s); var a = { s: { l: x.l - t, t: x.t - p }, e: { l: y.l + t, t: y.t + p }, c: z }; a_p.push(a); return a; }; var f_a = function (o, p, r) { var _o = o.position(), _w = o.width() / 2, _h = o.height() / 2; return { l: _o.left + _w, t: _o.top + _h, g: p, rw: _w - 1, rh: _h - 1, r: r }; }; return this; } var chartLine = function (r, s) { var k = document.createElement("canvas"); var u = Math.min(r.s.t, r.e.t), v = Math.min(r.s.l, r.e.l); var w = Math.abs(r.s.l - r.e.l); k.width = w < 2 ? 2 : w; k.height = Math.abs(r.s.t - r.e.t); k.style.top = u + "px"; k.style.left = v + "px"; k.style.position = "absolute"; k.style.visibility = "visible"; var d = k.getContext("2d"); d.save(); d.strokeStyle = r.c || "#000"; d.lineWidth = s || 1.5; d.beginPath(); d.moveTo((r.s.l - v) <= 2 ? 1 : (r.s.l - v), r.s.t - u); d.lineTo((r.e.l - v) <= 2 ? 1 : (r.e.l - v), r.e.t - u); d.closePath(); d.stroke(); d.restore(); return k; }