(function () { var Class = { create: function () { return function () { this.initialize.apply(this, arguments) } } }; Object.extend = function (destination, source) { for (property in source) { destination[property] = source[property] } return destination }; var Base = Class.create(); //Object.extend(Function.prototype, { // bind: function () { // var __m = this, // object = arguments[0], // args = new Array(); // for (var i = 1; i < arguments.length; i++) { // args.push(arguments[i]) // } // return function () { // return __m.apply(object, args) // } // } //}); Object.extend(Base.prototype, { initialize: function () { }, Browser: { IE: !!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1), Opera: navigator.userAgent.indexOf('Opera') > -1, WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') === -1, MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/) }, $: function (o) { return typeof (o) == 'string' ? document.getElementById(o) : o }, $Tag: function (o) { return typeof (o) == 'string' ? document.getElementsByTagName(o) : o }, $C: function (o) { return document.createElement(o) }, $E: function (e) { tempObj = e.target ? e.target : event.srcElement; return tempObj }, $aE: function (elm, evType, fn, useCapture) { if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true } else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r } else { elm['on' + evType] = fn } }, $dE: function (elm, evType, fn, useCapture) { if (elm.removeEventListener) { elm.removeEventListener(evType, fn, useCapture); return true } else if (elm.detachEvent) { var r = elm.detachEvent('on' + evType, fn); return r } else { elm['on' + evType] = null; return } }, stopBubble: function (e) { if (!this.Browser.IE) { e.stopPropagation() } else { window.event.cancelBubble = true } }, isNullorEmpty: function (obj) { if (obj == null || obj == "" || obj == "期货") { return true } return false }, getXY: function (obj) { var curleft = 0; var curtop = 0; var border; var x = 0; if (obj.offsetParent) { do { if (this.getStyle(obj, 'position') == 'relative') { border = this.getStyle(obj, 'border-top-width'); x = parseInt(border); if (!isNaN(x)) curtop += x; border = this.getStyle(obj, 'border-left-width'); x = parseInt(border); if (!isNaN(x)) curleft += x; break; } curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent) } return { 'left': curleft, 'top': curtop } }, getStyle: function (obj, styleProp) { if (obj.currentStyle) return obj.currentStyle[styleProp]; else if (window.getComputedStyle) return document.defaultView.getComputedStyle(obj, null).getPropertyValue(styleProp) } }); var Gee = new Base(); var StockSuggest = Class.create(); Object.extend(StockSuggest.prototype, { initialize: function (obj, arg) { this.input = obj; this.dataurl = "http://sys.hibor.com.cn/center/customershares/defaultall.ashx?name={#NAME}&input={#KEY}&type={#TYPE}"; this.type = Gee.isNullorEmpty(arg.type) ? "" : arg.type; this.valuecolumn = Gee.isNullorEmpty(arg.valuecolumn) ? 0 : arg.valuecolumn; this.width = Gee.isNullorEmpty(arg.width) ? "" : arg.width; this.opacity = Gee.isNullorEmpty(arg.opacity) ? 1 : arg.opacity; this.className = Gee.isNullorEmpty(arg.className) ? "" : arg.className; this.max = Gee.isNullorEmpty(arg.max) ? 10 : arg.max; this.watermark = arg.watermark; this.header = Gee.isNullorEmpty(arg.header) ? ["选项", "代码", "名称", "类型"] : arg.header; this.body = Gee.isNullorEmpty(arg.body) ? [-1, 1, 4, 6] : arg.body; this.callback = (arg.callback == null || arg.callback == "期货") ? null : arg.callback; this.results = null; this._D = null; this._R = null; this._W = null; this._X = {}; this._Y = {}; this._hidden = false; this.Market = ""; this.mType = ""; this.SName = ""; this._iF = null; this._iN = null; this.init(); this.binding = true; }, init: function () { this._Y = {}; this.input = typeof (this.input) == "string" ? Gee.$(this.input) : this.input; if (this.input) { if (this.watermark) { this.input.value = this.watermark; } this.input.setAttribute("autocomplete", "off"); this.input.autoComplete = "off"; this._iF = this._bd(this.inputFocus); this._iN = this._bd(this.Navigate); Gee.$aE(this.input, "focus", this._iF); Gee.$aE(this.input, "blur", this._iF); Gee.$aE(this.input, "keyup", this._iN); Gee.$aE(this.input, "mouseup", this._iN); } }, rebind: function (valueColumn) { if (valueColumn) { this.valuecolumn = valueColumn; } if (this.binding) { return; } this._Y = {}; if (this.input) { Gee.$aE(this.input, "focus", this._iF); Gee.$aE(this.input, "blur", this._iF); Gee.$aE(this.input, "keyup", this._iN); Gee.$aE(this.input, "mouseup", this._iN); this.binding = true; } }, unbind: function () { if (!this.binding) { return; } this._Y = {}; if (this.input) { Gee.$dE(this.input, "focus", this._iF); Gee.$dE(this.input, "blur", this._iF); Gee.$dE(this.input, "keyup", this._iN); Gee.$dE(this.input, "mouseup", this._iN); this.binding = false; } }, inputFocus: function (e) { var _t = e.type; if (_t.indexOf("focus") >= 0) { if (this.input.value == this.watermark) { this.input.value = ""; this._U = ""; } else { this.Suggest(); } } else if (this.input.value == "" && _t.indexOf("blur") >= 0) { if (this.watermark) { this.input.value = this.watermark; } this._U = ""; this.hiddenResults(); } else if (_t.indexOf("blur") >= 0) { this.hiddenResults(); } }, Navigate: function (e) { var _K = this.header == null ? 0 : 1; switch (e.keyCode) { case 38: if (this.results != null && this.results.innerHTML != "") { this.setLine(this.results.firstChild.rows[(!this._W || this._W.rowIndex == _K) ? this.results.firstChild.rows.length - 2 : this._W.rowIndex - 1]) } break; case 40: if (this.results != null && this.results.innerHTML != "") { this.setLine(this.results.firstChild.rows[(!this._W || this._W.rowIndex == this.results.firstChild.rows.length - 2) ? _K : this._W.rowIndex + 1]) } break; case 13: if (this.results != null && this.results.innerHTML != "") { var _s = this.input.value; var _u = ""; if (this._W != null) { if (("key_" + _s) in this._Y && this._Y["key_" + _s] != "") { _u = this._Y["key_" + _s].replace(/&/g, "&").replace(/;$/, "").split(";") } if (_u != "" && _u.length > 0) { var obj = Gee.$(_u[0]); if (typeof obj != "期货") this.setLine(obj, e) } else { this.setLine(this._W, e) } } else { var err = false; if (("key_" + _s) in this._Y && this._Y["key_" + _s] != "") { _u = this._Y["key_" + _s].replace(/&/g, "&").replace(/;$/, "").split(";") } if (_u != "" && _u.length > 0) { var obj = Gee.$(_u[0]); if (typeof obj != "期货") this.setLine(obj, e) } else { //alert("您输入的股票代码不存在!"); //err = true } } if (this.callback != null && !err) { this.callback({ code: this.input.value, type: this.Market, mt: this.mType, cnName: this.SName }) } } this.hiddenResults(); break; default: this.Suggest(); break } }, _bd: function (_b, _c) { var _d = this; return function () { var _e = null; if (typeof _c != "期货") { for (var i = 0; i < arguments.length; i++) { _c.push(arguments[i]) } _e = _c } else { _e = arguments } return _b.apply(_d, _e) } }, _gt: function () { return (new Date()).getTime() }, Suggest: function () { var _s = this.input.value; if (this._U != _s) { this._U = _s; if (_s != "") { if (("key_" + _s) in this._Y) { this.Tip() } else { this._io(_s, this._bd(this.Tip), this._bd(this.hiddenResults)) } } else { if (this.results != null && this.results.innerHTML != "") { this._W = null; } this.hiddenResults() } } else if (_s != "") { this.setResults() } }, setResults: function () { if (this.results != null) this.results.style.display = "" }, hiddenResults: function () { if (this._hidden == false) { if (this.results != null) this.results.style.display = "none" } }, _io: function (s, _E, _F) { if (this._R == null) { this._R = Gee.$C("div"); this._R.style.display = "none"; document.body.insertBefore(this._R, document.body.lastChild) } var dataObjName = "sData_" + this._gt(); var _H = Gee.$C("script"); _H.type = "text/javascript"; _H.charset = "utf-8"; _H.src = this.dataurl.replace("{#NAME}", dataObjName).replace("{#KEY}", escape(s)).replace("{#TYPE}", this.type.toString()); _H._0j = this; if (_E) { _H._0k = _E } if (_F) { _H._0l = _F } _H._0m = s; _H._0n = dataObjName; _H[document.all ? "onreadystatechange" : "onload"] = function () { if (document.all && this.readyState != "loaded" && this.readyState != "complete") { return; } var _I = window[this._0n]; if (typeof _I != "期货") { this._0j._Y["key_" + this._0m] = _I; this._0k(_I); window[this._0n] = null } this._0j = null; this._0m = null; this._0n = null; this[document.all ? "onreadystatechange" : "onload"] = null; this.parentNode.removeChild(this); }; this._R.appendChild(_H); }, setColor: function (o) { var _B = ""; if (o._0f && o._0g) { _B = "#F8FBDF" } else if (o._0f) { _B = "#F1F5FC" } else if (o._0g) { _B = "#FCFEDF" } if (o.style.backgroundColor != _B) { o.style.backgroundColor = _B } }, setLine: function (o, e) { var _C = o.id.split(","); this._D = _C; var _D = _C[this.valuecolumn]; var reg = /^[a-zA-Z|*]+$/; if (reg.test(_D)) { _D = _C[4]; } this._U = _D; this.Market = _C[2]; this.mType = _C[5]; this.SName = _C[4]; this.input.value = _D; if (this._W != null) { this._W._0f = false; this.setColor(this._W) } o._0f = true; this.setColor(o); this._W = o; }, mouseoverLine: function (o) { o._0g = true; this.setColor(o) }, mouseoutLine: function (o) { o._0g = false; this.setColor(o) }, setLineMouse: function (o) { this.setLine(o); if (this.callback != null) { this.callback({ code: this.input.value, type: this.Market, mt: this.mType, cnName: this.SName }) } }, hidepause: function () { this._hidden = true }, hideresume: function () { this._hidden = false; this.hiddenResults() }, setTip: function () { var p = Gee.getXY(this.input); var _j = p.top; var _k = p.left; var _o = [0, 0]; if (this.results.style.top != _j + "px") { this.results.style.top = _j + _o[0] + "px" } if (this.results.style.left != _k + "px") { this.results.style.left = _k + _o[1] + "px" } var _p = this.input.style.borderTopWidth; var _q = this.input.style.borderBottomWidth; var _r = this.input.clientHeight; _r += _p != "" ? _p.replace("px", "") * 1 : 2; _r += _q != "" ? _q.replace("px", "") * 1 : 2; if (this.results.style.marginTop != _r + "px") { this.results.style.marginTop = _r + "px" } }, Tip: function () { var _s = this.input.value; if (("key_" + _s) in this._Y && this._Y["key_" + _s] != "") { if (this.results == null) { this.results = Gee.$C("div"); this.results.id = "jj_suggest_result"; this.results.style.cssText = "z-index:9999;overflow:hidden;width:" + this.width + "px;opacity:" + this.opacity + ";filter:alpha(opacity:" + (this.opacity * 100) + ");position:absolute;display:none;"; if (this.className == "") this.results.style.border = "1px solid #ccc"; else this.results.className = this.className; this.input.parentNode.insertBefore(this.results, this.input); this.results["suggest"] = this; } this.setTip(); this.results.innerHTML = ""; var t = Gee.$C("table"); t.border = "0"; t.cellPadding = "0"; t.cellSpacing = "0"; t.style.cssText = "line-height:18px;background:#fff;font-size:13px;text-align:center;color:#333;width:100%;"; var tB = Gee.$C("tbody"); var _t_h_tr = Gee.$C("tr"); _t_h_tr.style.cssText = "background:#CCC;height:26px;overflow:hidden;"; if (this.header != null) { for (var i = 0; i < this.header.length; i++) { var _t_th = Gee.$C("th"); if (this.header[i] == "代码") _t_th.width = 66; if (this.header[i] == "类型") _t_th.width = 40; _t_th.innerHTML = this.header[i]; _t_h_tr.appendChild(_t_th) } } //tB.appendChild(_t_h_tr); var _u = this._Y["key_" + _s].replace(/&/g, "&").replace(/;$/, "").split(";"); var _v = _u.length > this.max ? this.max : _u.length; for (var i = 0; i < _v; i++) { var _x = _u[i].split(","); _x[-1] = _x[0].replace(_s.toUpperCase(), '' + _s.toUpperCase() + ''); var _t_tr = Gee.$C("tr"); _t_tr.id = _u[i]; _t_tr.style.cursor = "pointer"; _t_tr._oj = this; _t_tr.onmouseover = function () { this._oj.mouseoverLine(this) }; _t_tr.onmouseout = function () { this._oj.mouseoutLine(this) }; _t_tr.onmousedown = function () { return this._oj.hidepause(this) }; _t_tr.onclick = function () { this._oj.setLineMouse(this); this._oj.hideresume(this) }; var _t_td; for (var j = 0; j < this.body.length; j++) { _t_td = Gee.$C("td"); _t_td.hidefocus = "true"; _t_td.style.cssText = "word-break:break-all;padding:1px;height:26px;line-height:26px"; _t_td.innerHTML = _x[this.body[j]]; _t_tr.appendChild(_t_td) } _t_td = null; tB.appendChild(_t_tr) } t.appendChild(tB); var d = Gee.$C("div"); d.style.width = this.width + "px"; d.appendChild(t); this.results.appendChild(d); var ifr = Gee.$C("iframe");//ie6 select 穿透 ifr.frameBorder = "0"; ifr.style.cssText = "position:absolute;top:0px;left:0px;z-index:-1;width:" + this.width + "px;height:300px"; this.results.appendChild(ifr); this.setResults() } else { this.hiddenResults() } } }); window.StockSuggest = StockSuggest; })();