Function.prototype._BindForEvent = function() { var __m = this, object = arguments[0], args = new Array(); for(var i = 1; i < arguments.length; i++){ args.push(arguments[i]); } return function(event) { return __m.apply(object, [( event || window.event)].concat(args)); } }; S_SR_SHOW = function() { this.Init.apply(this, arguments); }; S_SR_SHOW.prototype = { _defaultConfig : {divid: 'STOCKRADAR_SHOW_DIV', owidth: 948, iwidth: 948, oheight: 25, iheight: 14, fontsize: 12, scrolldirect: 1, msgcount: 6, scrollstep: 1, scrolltime: 50, matchstop: 20, msgwidth: 144, logowidth: 25}, Init : function() { var t, tr, td, tb; var o, a, i; this._config = window.SINA_SR_SHOW_CONFIG; if (!this._config) { this._config = this._defaultConfig; } this._core = new S_SR_CORE(); this._arrSel = this._core.LoadConfig(); this._arrDOM = new Array(); this._oDivMain = document.getElementById(this._config.divid); if (!this._oDivMain) { this._oDivMain = document.createElement('div'); document.body.appendChild(this._oDivMain); this._oDivMain.setAttribute('id', this._config.divid); } this._oDivMain.style.width = this._config.owidth + 'px'; this._oDivMain.style.height = this._config.oheight + 'px'; this._oDivMain.style.fontSize = this._config.fontsize + 'px'; this._oDivMain.style.overflow = 'hidden'; /*this._oDivScroll = document.createElement('div'); if (this._config.scrolldirect) { this._oDivScroll.style.width = this._oDivMain.style.width; this._oDivScroll.style.height = '60000px'; } else { this._oDivScroll.style.width = '60000px'; this._oDivScroll.style.height = this._oDivMain.style.height; } this._oDivScroll.style.marginLeft = this._oDivScroll.style.marginTop = '0px'; this._oDivMain.appendChild(this._oDivScroll); */ this._iScrollStop = 0; this._iScrollPos = 0; t = document.createElement('table'); t.border = '0'; t.style.cellSpacing = t.style.cellPadding = '0px'; t.style.width = this._config.iwidth + 'px'; t.style.height = this._config.iheight + 'px'; t.style.overflow = 'hidden'; t.style.border = 'none 0px'; t.style.margin = '0px auto'; t.style.marginTop = ((this._config.oheight - this._config.iheight) / 2 - 2) + 'px'; t.style.overflow = 'hidden'; tb = document.createElement('tbody'); tr = document.createElement('tr'); td = document.createElement('td'); td.appendChild(document.createTextNode(' ')); td.style.width = this._config.logowidth + 'px'; td.style.heigth = this._config.iheight + 'px'; td.style.overflow = 'hidden'; tr.appendChild(td); this._aoTD = new Array(); for (i = 0; i < this._config.msgcount; i++) { td = document.createElement('td'); td.style.textAlign = 'center'; td.style.width = this._config.msgwidth + 'px'; td.style.height = this._config.iheight + 'px'; td.style.overflow = 'hidden'; this._aoTD[i] = td; tr.appendChild(td); } if (this._GetTailWidth() > 25) { td = document.createElement('td'); td.style.textAlign = 'center'; td.style.width = this._GetTailWidth() + 'px'; a = document.createElement('a'); a.setAttribute('href', 'http://finance.sina.com.cn/stockradar/config.html'); a.setAttribute('target', '_blank'); a.appendChild(document.createTextNode('ÉèÖÃ')); td.appendChild(a); if (this._GetTailWidth() >= 54) { td.appendChild(document.createTextNode(' ')); a = document.createElement('a'); a.setAttribute('href', 'http://finance.sina.com.cn/stockradar/stockradar.html'); a.setAttribute('target', '_blank'); a.appendChild(document.createTextNode('¸ü¶à')); td.appendChild(a); } tr.appendChild(td); } tr.style.verticalAlign = 'top'; tr.style.padding = tr.style.margin = '0px'; tb.appendChild(tr); tb.style.height = this._config.iheight + 'px'; tb.style.padding = tr.style.margin = '0px'; t.appendChild(tb); this._oDivMain.appendChild(t); this._oTblMain = t; //Util.AddEvent(this._oDivMain, 'mouseover', this._ScrollControl._BindForEvent(this, 0)); //Util.AddEvent(this._oDivMain, 'mouseout', this._ScrollControl._BindForEvent(this, 1)); //this._ScrollControl(null, 1); //this._oDivMain.style.border = '1px blue solid'; this._aoTmrSTD = new Array(); window.sr_show_callback = this.OnData._Bind(this); }, /*_ScrollControl : function(ev, act) { switch (act) { case 0: if (this._oTmrScroll) { clearInterval(this._oTmrScroll) } this._oTmrScroll = null; break; case 1: this._ScrollControl(ev, 0); this._oTmrScroll = setInterval(this._Scroll._Bind(this), this._config.scrolltime); break; } },*/ _Scroll : function() {/* var op, ip, fe, il; var i; if (this._iScrollStop) { this._iScrollStop--; return; } if (this._config.scrolldirect) { op = this._config.iheight; ip = parseInt(this._oDivScroll.style.marginTop); //fe = this._oDivScroll.firstChild.offsetHeight; } else { op = this._config.iwidth; ip = parseInt(this._oDivScroll.style.marginLeft); //fe = this._oDivScroll.firstChild.offsetWidth; } il = 0; for (i = 0; i < this._oDivScroll.childNodes.length; i++) { il += parseInt( this._config.scrolldirect ? this._oDivScroll.childNodes[i].offsetHeight : this._oDivScroll.childNodes[i].offsetWidth); } if(ip + il < 0) { if (this._config.scrolldirect) { this._oDivScroll.style.marginTop = op + 'px'; } else { this._oDivScroll.style.marginLeft = op + 'px'; } } else { if (this._config.scrolldirect) { this._oDivScroll.style.marginTop = (parseInt(this._oDivScroll.style.marginTop) - this._config.scrollstep) + 'px'; } else { this._oDivScroll.style.marginLeft = (parseInt(this._oDivScroll.style.marginLeft) - this._config.scrollstep) + 'px'; } } */ }, _StartScroll : function(o) { var id, i; //alert(this._oDivMain.style.display); if (this._iScrollPos == 0 && !this._aoTD[0].firstChild) { this._ShowTips(0); } this._oDivMain.style.display = ''; id = this._iScrollPos; this._iScrollPos = (this._iScrollPos + 1) % this._config.msgcount; if (this._aoTmrSTD[id]) { this._ResetSTD(id); } o.style.marginTop = '0px'; this._aoTD[id].appendChild(o); if (this._aoTD[id].childNodes.length > 1) { this._aoTmrSTD[id] = setInterval(this._ScrollTD._BindForEvent(this, id), this._config.scrolltime); } }, _ShowTips : function(act) { var a, i; if (act ) { a = ['', 'none']; } else { a = ['none', '']; } for (i = 0; i < this._oDivMain.childNodes.length; i++) { if ( this._oDivMain.childNodes[i].style) { if (this._oDivMain.childNodes[i] != this._oTblMain) { this._oDivMain.childNodes[i].style.display = a[0]; } else { this._oDivMain.childNodes[i].style.display = a[1]; } } } }, _ResetSTD : function(id) { if (this._aoTmrSTD[id]) { clearInterval(this._aoTmrSTD[id]); this._aoTmrSTD[id] = null; } while (this._aoTD[id].childNodes.length > 1) { this._aoTD[id].removeChild(this._aoTD[id].firstChild); } if (this._aoTD[id].firstChild) { this._aoTD[id].firstChild.style.marginTop = '0px'; } }, _StopSTD : function(id) { this._ResetSTD(id); }, _ScrollTD : function(ev, id) { var p, o; if (!this._aoTD[id])alert(id); o = this._aoTD[id].firstChild; p = parseInt(o.style.marginTop); if (isNaN(p)) { p = 0; } p -= this._config.scrollstep; if (p + o.offsetHeight <= 0) { this._StopSTD(id); } o.style.marginTop = p + 'px'; }, MessageCmd : function(o) { var c = o.y; if ((c & 0x7fff0000) == 0x7fff0000) { switch (c & 0xffff) { case 0: this._oDivMain.style.display = 'none'; break; case 1: this._oDivMain.style.display = ''; break; case 0x10: this._ShowTips(1); break; case 0x11: this._ShowTips(0); break; } return true; } }, OnData : function(data) { //{"t":1223947823,"c":"sh600305","y":262147,"s":1223968789,"n":"ºã˳´×Òµ","o":"ljsp"} var o; if (this.MessageCmd(data)) { return; } if (!this._core.Filter3(data, this._arrSel)) { return; } o = this.MessageDOM(data); this._StartScroll(o); //this._arrDOM.push(o); /* if (this._oDivScroll.firstChild) { this._oDivScroll.insertBefore(o, this._oDivScroll.firstChild); } else { this._oDivScroll.appendChild(o); } if (this._oDivScroll.childNodes.length > this._config.msgcount) { this._oDivScroll.removeChild(this._oDivScroll.lastChild); } if (this._config.scrolldirect) { this._oDivScroll.style.marginTop = 0;//this._config.iheight; } else { this._oDivScroll.style.marginLeft = 0;//this._config.iwidth; } this._iScrollStop = this._config.matchstop;*/ }, getStringLength: function (stringTarget) { return stringTarget.replace(/[^\x00-\xff]/g,"**").length; }, subString: function (__stringTarget, __intLength) { var __stringTargetTransformed = __stringTarget.replace(/[xy]/g, "z").replace(/[^\x00-\xff]/g,"xy"); if (__stringTargetTransformed.length > __intLength) { __stringTargetTransformed = __stringTargetTransformed.substr(0, __intLength); if (__stringTargetTransformed.substr(__intLength - 1, 1) == "x") { return __stringTarget.substr(0, __intLength - 1 - __stringTargetTransformed.match(/xy/g).length); } else { return __stringTarget.substr(0, __intLength - __stringTargetTransformed.match(/xy/g).length); } } else { return __stringTarget; } }, MessageDOM : function(msg) { //http://finance.sina.com.cn/realstock/company/sz000858/nc.shtml var o, a, t; o = document.createElement('div'); a = document.createElement('a'); a.setAttribute('href', 'http://finance.sina.com.cn/realstock/company/' + msg.c + '/nc.shtml'); a.setAttribute('target', '_blank'); t = this._TypeText(msg.y); var n = msg.n; if (this.getStringLength(this._TimeText(msg.t) + ' ' + msg.n + ' ' + t) > 23) { n = this.subString(msg.n, 8); } a.appendChild(document.createTextNode(this._TimeText(msg.t) + ' ' + n + ' ' + t)); o.appendChild(a); if (!this._config.scrolldirect) { o.style.cssFloat = o.style.styleFloat = 'left'; } //o.style.paddingLeft = o.style.paddingRight = '2px'; //o.style.border = '1px red solid'; return o; }, _TypeText : function(t) { var i; for (i = 0; i < SINA_SRMSGTYPES.length; i++) { if (SINA_SRMSGTYPES[i].t == t) { return SINA_SRMSGTYPES[i].s; } } return ''; }, _TimeText : function(t) { var d = new Date(); d.setTime(t * 1000); return this._Add0Before(d.getHours(), 2) + ':' + this._Add0Before(d.getMinutes(), 2)/* + ':' + this._Add0Before(d.getSeconds(), 2)*/; }, _Add0Before : function (n, c) { var x = n.toString(); while (x.length < c) { x = '0' + x; } return x; }, _GetTailWidth : function() { return this._config.iwidth - this._config.msgwidth * this._config.msgcount - this._config.logowidth; } } var StockEngineMod = function () { this._getElement = function (__stringId) { return document.getElementById(__stringId); }; this._bind = function(__functionBind, __argumentsBind) { var __this = this; return function () { var __arguments = null; if (typeof __argumentsBind != "undefined") { for (var i = 0; i < arguments.length; i++) { __argumentsBind.push(arguments[i]); } __arguments = __argumentsBind; } else { __arguments = arguments; } return __functionBind.apply(__this, __arguments); }; }; this._pusher = null; this.boot = function () { this._core = new S_SR_CORE(); this._arrSel = this._core.LoadConfig(); this._pusher = IO.WebPush2.getInstance({ "server": 'cluster.woocall.sina.com.cn', "divId": '__webpush2_box', //~ "onDebug": function (t,s) {if (typeof console != "undefined") {console.log(t + ": " + s);}}, "onConnected": this._bind(this._eventConnected) }); window.ssrs = new S_SR_SHOW(); }; this._eventConnected = function (__stringNickname) { this._pusher.addInfoKey('STOCKRADAR_DEFAULT', this._bind(this._eventMessage)); }; this._eventMessage = function (__stringKey, __stringMessage, __intType) { var objectMsg = null; try { eval("objectMsg = " + __stringMessage + ";"); } catch (e) { } if (objectMsg != null) { if(__stringKey == "STOCKRADAR_DEFAULT") { if(__intType == 0) { window.sr_show_callback(objectMsg); } else if(__intType == 1) { } } } }; };