您的位置:首页 > 移动开发

QQ网站里AppTui对象脚本

2011-12-11 16:32 323 查看
/* APP Common Begin*/
try
{
document.domain = "qq.com";
}
catch (e)
{
}

if (typeof AppTui == "undefined")
{
var AppTui = new Object();
}

AppTui.$ = function(s)
{
return (typeof s == "object") ? s: document.getElementById(s);
};

AppTui.Cookie = {
getCookie: function(name)
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));

if (arr != null)
{
return window.unescape(arr[2]);

}

return null;
},
setCookie:function(name,value,expires,path,domain,secure){
var expDays = expires*24*60*60*1000;
var expDate = new Date();
expDate.setTime(expDate.getTime()+expDays);
var expString = expires ? "; expires="+expDate.toGMTString() : "";
var pathString = "; path="+(path||"/");
var domain = domain ? "; domain="+domain : "";
document.cookie = name + "=" + escape(value) + expString + domain + pathString + (secure?"; secure":"");
}
};

AppTui.HashTable = function()
{
this.__construct();
};

AppTui.HashTable.prototype = {
__construct: function()
{
this._hash = new Object();
},

set: function(key, value, rewrite)
{
if (rewrite !== false)
{
this._hash[key] = value;
}
else if (this.get(key) != null)
{
this._hash[key] = value;
}
},

get: function(key)
{
if (typeof this._hash[key] != "undefined")
{
return this._hash[key];
}
else
{
return null;
}
},

remove: function(key)
{
delete this._hash[key];
}
};

AppTui.HashTable.getInstance = function()
{
if (!this.__instance__)
{
this.__instance__ = new AppTui.HashTable();
};

return this.__instance__;
};

AppTui.Element = {
getElementLeft: function(e)
{
return (e==null) ? 0 :
(AppTui.$(e).offsetLeft + AppTui.Element.getElementLeft(AppTui.$(e).offsetParent));
},

getElementTop: function(e)
{
return (e==null) ? 0 :
(AppTui.$(e).offsetTop + AppTui.Element.getElementTop(AppTui.$(e).offsetParent));
},

scrollIntoView: function(e)
{
var x = AppTui.Element.getElementLeft(e);
var y = AppTui.Element.getElementTop(e);
window.scrollTo(x, y);
},

remove: function()
{
for (var i=0; i<arguments.length; i++)
{
try
{
AppTui.$(arguments[i]).parentNode.removeChild(AppTui.$(arguments[i]));
}
catch (e)
{
}
}
}
};

AppTui.Page = {
getPageWidth: function()
{
return document.body.scrollWidth || document.documentElement.scrollWidth || 0;
},

getPageHeight: function()
{
return document.body.scrollHeight || document.documentElement.scrollHeight || 0;
},

getBodyWidth: function()
{
return document.body.clientWidth || document.documentElement.clientWidth || 0;
},

getBodyTop: function()
{
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
},
getPostionByDom: function(element)
{
var el;
var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera') != -1);
var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
if (typeof element == 'object'){
el = element;
}
else{
el = document.getElementById(element);
}
/*if (typeof el.parentNode == 'undefined' || el.style.display == 'none')
{
return false;
}*/

var parent = null;
var pos = [];
var box;
if(el.getBoundingClientRect) //IE&FF
{
box = el.getBoundingClientRect();
var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
return {x:box.left + scrollLeft, y:box.top + scrollTop};
}
else if(document.getBoxObjectFor) // gecko
{
box = document.getBoxObjectFor(el);
var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;
var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;
pos = [box.x - borderLeft, box.y - borderTop];
}
else // safari & opera
{
pos = [el.offsetLeft, el.offsetTop];
parent = el.offsetParent;
if (parent != el) {
while (parent) {
pos[0] += parent.offsetLeft;
pos[1] += parent.offsetTop;
parent = parent.offsetParent;
}
}
}

if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' ))
{
pos[0] -= document.body.offsetLeft;
pos[1] -= document.body.offsetTop;
}
if (el.parentNode) { parent = el.parentNode; }
else { parent = null; }
while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML')
{ // account for any scrolled ancestors
pos[0] -= parent.scrollLeft;
pos[1] -= parent.scrollTop;
if (parent.parentNode) { parent = parent.parentNode; }
else { parent = null; }
}
return {x:pos[0], y:pos[1]};
}
};

AppTui.Browser = new Object();
AppTui.Browser.ua = window.navigator.userAgent.toLowerCase();
AppTui.Browser.ie = /msie/.test(AppTui.Browser.ua);
AppTui.Browser.moz = /gecko/.test(AppTui.Browser.ua);

AppTui.User = {
getUin: function()
{
if (AppTui.Cookie.getCookie("uin") && AppTui.Cookie.getCookie("skey"))
{
return parseInt(AppTui.Cookie.getCookie("uin").replace(/^o0*/, ""));
}
else
{
return 0;
}
},
isLogin: function(e)
{
if(typeof _addPtlogin2_onResizeFunc == 'function' && typeof IFr_ptlogin2resize == 'function'){
_addPtlogin2_onResizeFunc(IFr_ptlogin2resize);
}
AppTui.HashTable.getInstance().set("current_node",e);
if(AppTui.User.getUin() > 0)
{
AppTui.Tui.getTuiData();
}
else{
this.createLoginDiv();
this.showLoginBox();
}

},
loginBoxTopPos: function(){
//
var node = null;
var top;
if (typeof AppTui.HashTable.getInstance().get("current_node") == "object")
{
node = AppTui.HashTable.getInstance().get("current_node");
}
var pos = AppTui.Page.getPostionByDom(node);
var clientPos = pos.y - AppTui.Page.getBodyTop();
if (parseInt(clientPos) > 400)
{
top = pos.y - 340 +"px";
}
else{
top = pos.y + 30 + "px";
}
return top;
},
showLoginBox: function(){
AppTui.$("Login_Box").style.top = this.loginBoxTopPos();
AppTui.$("Login_Box").style.left = (AppTui.Page.getBodyWidth() - 370)/2 + "px";
AppTui.$("Login_Box").style.display = 'block';
},
createLoginDiv: function(){
if(AppTui.$("Login_Box") == null ){
var Login_Box = document.createElement("div");
Login_Box.setAttribute("id", "Login_Box");
Login_Box.className = 'share_layer';
Login_Box.style.width = 399+'px';
Login_Box.style.height = 212+'px';
Login_Box.innerHTML = '<div class="share_layer_main" id="login_box_main"><div class="share_layer_title" style="cursor: move;"><h3 class="">ÍƼöÖÁÎÒµÄÌÚѶÍø</h3><a title="¹Ø±Õ" class="del_fri" onclick="AppTui.User.hide();">X</a></div><div class="share_layer_cont"><iframe frameborder="0" name="Login_Frame2" id="Login_Frame2" width="397" height="190" style="display:block;" scrolling="no" src="about:blank"></iframe></div></div>';
document.getElementsByTagName("body")[0].appendChild(Login_Box);
AppTui.$("Login_Frame2").src="http://ui.ptlogin2.qq.com/cgi-bin/login?link_target=blank&hide_title_bar=1&f_url=loginerroralert&target=self&appid=638003502&s_url=http://www.qq.com/user/user_login.html";
}
else
{
AppTui.$("Login_Frame2").src="about:blank";
AppTui.$("Login_Frame2").src="http://ui.ptlogin2.qq.com/cgi-bin/login?link_target=blank&hide_title_bar=1&f_url=loginerroralert&target=self&appid=638003502&s_url=http://www.qq.com/user/user_login.html";
AppTui.$("Login_Frame2").style.display = "block";
}
},
hide: function()
{
AppTui.$("Login_Box").style.display = "none";
AppTui.$("Login_Frame2").src = "about:blank";
},
ok: function()
{
//login.htmµÄcookieÉèÖÃ
try{
this.hide();
AppTui.Tui.getTuiData();
}catch(e){
this.hide();
}
},
resize:function(a) {
//document.getElementById('Login_Box').style.height= c +'px';
document.getElementById('Login_Frame2').style.height= a.height +'px';

}
};

/*¿ÉÄÜÊǶàƪÎÄÕ£¬¿ÉÄÜÊÇһƪ*/
AppTui.Tui ={
_url:"http://u.qq.com/commend/commend",
_refer:2,
_aids:[],
_aidnum_name:"tui_num",
init:function(){
if(AppTui.Tui._aids.length>0){
for(var i in AppTui.Tui._aids)
{
this.getNumber(AppTui.Tui._aids[i]);
}
}else{
var tmp_aid = this.getaid();
this.getNumber(tmp_aid);
}
},
getaid: function(){
var localUrl = window.location.href.toString();
var re = /http:\/\/(\w+[.]{1})?(\w+).qq.com\/a\/(\d+)\/(\d+).(\w+)/;
var res = localUrl.match(re);
if (res == null)
{
return;
}
var _site = res[2];
var _id = res[3] +''+ res[4];
var res = _site+'_'+_id;
return res;
},
getTuiData : function(){
var node;
var node_id;
if (typeof AppTui.HashTable.getInstance().get("current_node") == "object")
{
node = AppTui.HashTable.getInstance().get("current_node");
}
if (node.id != null && node.id != ''){
node_id = node.id;
}
else{
node_id = this.getaid();
}
if( node_id == null || node_id == '') return;
var str = node_id.split('_');
var _site = str[0];
var _id = str[1];
var _posturl = this._url+"-id-"+_id+"-site-"+_site+"-r-"+this._refer+"&random="+Math.random();

JsLoad(_posturl,{
method:'GET',
varname:'TuiResult',
completeListener : function(){
if(typeof arguments[0] == 'undefined') return;
var responseText = arguments[0];
if(typeof AppTui.Tui.tuiAction == 'function'){
AppTui.Tui.tuiAction(responseText);
}
},
errorListener : function(){
//do nothing
}

});
var pathname = _posturl.replace(/http:\/\/u.qq.com/g,'');
icenterGo(pathname);

},
tuiAction :function(u){
if(typeof u["code"]=="undefined"){
return false;
}
var code = u["code"];
if(code==1){
this.successAction();
this.showFloatTips('ÎÄÕÂÒÑÍƸøQQºÃÓÑ');
return true;
}else if(code==-1){
//this.showFloatTips('ÎÄÕÂÍÆʧ°Ü£¬²ÎÊý´íÎó');

}
else if(code==-2){
//this.showFloatTips('Óû§µÇ¼³¬Ê±£¬ÇëÖØеǼ');
}
else if(code==-3){
this.NoAction();
this.showFloatTips('Äã¸ÕÍƹý£¬Ò»»á¶ùÔÙÀ´ÍÆÍÆ');
return true;
}
else if(code==-4){
//this.showFloatTips('ÎÄÕÂÍÆʧ°Ü£¬Ò»»á¶ùÔÙÀ´ÊÔÊÔ');
}
return true;
},
showFloatTips:function(tips_wording){
if(AppTui.$("tui_tips") == null){
var div = document.createElement('div');
div.setAttribute("id","tui_tips");
div.className = 'share_layer';
div.style.width =396+'px';
div.style.left = 486+'px';
div.innerHTML = '<div class="share_layer_main"><div class="share_layer_title" style="cursor: move;"><h3 class="">ÍƼöÖÁÎÒµÄÌÚѶÍø</h3><a title="¹Ø±Õ" class="del_fri" onclick="AppTui.Tui.hide();">X</a></div><div class="share_layer_cont"><div class="tui_done"><div class="tui_text">'+tips_wording+'</div><div class="tui_bt"><a href="http://u.qq.com" target="_blank">È¥ÎÒµÄÌÚѶÍø¿´¿´</a></div><div class="tui_autoclose"><span>3</span>Ãëºó×Ô¶¯¹Ø±Õ</div></div></div></div><div class="bg"></div>';
document.getElementsByTagName("body")[0].appendChild(div);
}
var pos = AppTui.User.loginBoxTopPos();
AppTui.$('tui_tips').style.top = pos ;
AppTui.$("tui_tips").display = 'block';
setTimeout(function(){AppTui.Tui.hide();},3000);
AppTui.HashTable.getInstance().remove("current_node");
},
hide: function(){
AppTui.$('tui_tips').style.display = 'none';
},
NoAction:function(){
var node;
var node_id;
if (typeof AppTui.HashTable.getInstance().get("current_node") == "object")
{
node = AppTui.HashTable.getInstance().get("current_node");
}
if (node.id != null && node.id != ''){
node_id = node.id;
var mod_id = node_id +'_mod';
if (AppTui.$(mod_id) != null)
{
AppTui.$(mod_id).className = '';
AppTui.$(mod_id).className = 'tui_mod done';
AppTui.$(mod_id).style.cursor = 'default';
}
}
else{
AppTui.$('tui_mod').className = '';
AppTui.$('tui_mod').className = 'tui_mod done';
AppTui.$('tui_mod').style.cursor = 'default';
}
node.onclick =function(){return false;};
node.style.cursor = 'default';
node.disabled = true;
},

successAction: function(){
/*add class*/
var node;
var node_id;
if (typeof AppTui.HashTable.getInstance().get("current_node") == "object")
{
node = AppTui.HashTable.getInstance().get("current_node");
}
if (node.id != null && node.id != ''){
node_id = node.id;
var mod_id = node_id +'_mod';
if (AppTui.$(mod_id) != null)
{
AppTui.$(mod_id).className = '';
AppTui.$(mod_id).className = 'tui_mod done';
AppTui.$(mod_id).style.cursor = 'default';
}
if(AppTui.$(num_id) != null){
var num = parseInt(AppTui.$(num_id).innerHTML);
if (!num || isNaN(num))
{

AppTui.$(num_id).innerHTML = 1;
}
else{
AppTui.$(num_id).innerHTML = num +1;
}
}
}
else{
AppTui.$('tui_mod').className = '';
AppTui.$('tui_mod').className = 'tui_mod done';
AppTui.$('tui_mod').style.cursor = 'default';
var num = parseInt(AppTui.$('tui_num').innerHTML);
if (!num || isNaN(num))
{
AppTui.$('tui_num').innerHTML = 1;
}
else{
AppTui.$('tui_num').innerHTML = num +1;
}

}
node.onclick =function(){return false;};
node.style.cursor = 'default';
node.disabled = true;
},
getNumber: function(aid){
//TODO: site id
var _retId = aid;
var _tuiurl = 'http://u.qq.com:8080/?id='+ _retId +'&random='+ Math.random();
JsLoad(_tuiurl,{
method:'GET',
varname:_retId,
completeListener : function(){
try{
if(typeof arguments[0] == 'undefined') return;
var number = arguments[0];
var obj = null;
var num_id = aid+'_num';
if(AppTui.$(num_id) != null){
obj = AppTui.$(num_id);
}
else{
obj = AppTui.$(AppTui.Tui._aidnum_name);
}
if( obj != null){
obj.innerHTML = parseInt(number);
}
}
catch(e){
//do nothing
}

},
errorListener : function(){
//do nothing
}

});
}
};

function JsLoad(sUrl ,options){

options = options || {};

if(!options.sId) options.sId = 'jsload_'+Math.random();

if(!options.varname) options.varname = 'datav4';

var sId = 'jsload_'+options.sId;

if(AppTui.$(sId)!='undefined'&&AppTui.$(sId)!=null){
AppTui.$(sId).parentNode.removeChild(AppTui.$(sId));
}
var _script = document.createElement("script");
_script.setAttribute("id", sId);
_script.setAttribute("type", "text/javascript");
_script.setAttribute("src", sUrl);
document.getElementsByTagName("head")[0].appendChild(_script);

if (!!document.all) {// IE
_script.onreadystatechange = function(){
var responseText = null;
if (this.readyState == "loaded" || this.readyState == "complete") {
if(options.completeListener) {
try{
responseText = eval('('+options.varname+')');
if(typeof responseText != null){
options.completeListener(responseText);
}else{
if(options.errorListener) {
options.errorListener();
}
}
}
catch(e)
{
if(options.errorListener)
{
options.errorListener();
}
}
}
_data=null;
if(AppTui.$(sId)!='undefined'&&AppTui.$(sId)!=null){
AppTui.$(sId).parentNode.removeChild(AppTui.$(sId));
}
}
};
}
else {// FF
_script.onload = function(){

var responseText = null;
if(options.completeListener) {
try{
responseText = eval('('+options.varname+')');
if(typeof responseText!=null){
options.completeListener(responseText);
}else{
if(options.errorListener) {
options.errorListener();
}
}
}
catch(e)
{
if(options.errorListener) {
options.errorListener();
}
}
}
_data=null;
//alert( sId );

if(AppTui.$(sId)!='undefined'&&AppTui.$(sId)!=null){
AppTui.$(sId).parentNode.removeChild(AppTui.$(sId));
}
};
}
};

window.IFr_ptlogin2resize = function(width, height) {
AppTui.User.resize({height: height});
}
window._addPtlogin2_onResizeFunc = function(func){
var t = window.ptlogin2_onResize;
if(typeof t != "function"){
window.ptlogin2_onResize = func;
}else{
window.ptlogin2_onResize = function(width,height){
//try{t(width,height);}catch(e){};
try{func(width,height);}catch(e){}
}
}
}

//AppTui.Tui._aids = ['ent_20110218000021'];
AppTui.Tui.init();
function icenterGo(pathname)
{
if(typeof(pgvMain) == 'function'){
pvRepeatCount = 1;
vsPgvCol = "icenter";
pvCurDomain = "u.qq.com";
pvCurUrl = pathname;
pgvMain();
}
}/* |xGv00|8ef1d856c33cbefd3c785b84107e0ed4 */
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: