📄 starblogmain.js
字号:
/**
* 可初始化的全局变量
*/
var isStatic = true;
var customVarContainer = {};
var g_XDoc = [];
if(g_XDoc[3] == undefined) g_XDoc[3] = {selectSingleNode:function(){return {text:""}}};
var g_JData = new Object();
var msgLife =1000;
g_XDoc["blogCommentCount"] = {};
/**
* 利用ShareObject存储数据
* @param {string} key 存储的key
* @param {string} value 存储内容
* @deprecated 不建议存Object
*/
function setShareData(key,value){
if (window._shareObjectReady){
$("shareObject").set("seed",Math.random());
$("shareObject").set(key,value);
$("shareObject").flush();
}
}
//////////////////////////////////////////////basic start
//检查登陆态
function checkLogin(){
if(parent.g_iLoginUin>10000){
return parent.g_iLoginUin;
}else{
var t=parseInt(QZONE.cookie.get("zzpaneluin"),10);
if (!isNaN(t) && (t > 10000)) {
return t;
}
t=parseInt(QZONE.cookie.get("uin").replace(/[^\d]/g,""),10);
if (!isNaN(t) && (t > 10000)) {
return t;
} else return 0;
}
}
//优化setTimeout
if(!window.setTimeout.constructor){
(function(){
var s=window.setTimeout;
window.setTimeout=function(f, d){
if(typeof f=='function'){
var a=Array.prototype.slice.call(arguments,2);
return s((function(){f.apply(null,a);}),d);
}
return s(f,d);
}
})()
}
//优化setInterval
if(!window.setInterval.constructor){
(function(){
var i=window.setInterval;
window.setInterval=function(f,d){
if(typeof f=='function'){
var a=Array.prototype.slice.call(arguments,2);
return i((function(){f.apply(null,a);}),d);
}
return i(f,d);
}
})()
}
//基础函数
String.prototype.trim=function(t){
return (!t)?(this.replace(/^\s+|\s+$/g,"")):((t=="L")?(this.replace(/^\s+/,"")):((t=="R")?(this.replace(/\s+$/,"")):(this)));
};
String.prototype.convCR=function(r){
return (!!r)?this.replace(/<br \/>/g,"\n"):this.replace(/\n/g,"<br />");
};
String.prototype.convSP=function(r){
return (!!r)?this.replace(/ /g," "):this.replace(/\x20\x20/g," ");
};
String.prototype.convHtmlChar = function(){
return this.replace(/\/g,"\\").replace(/"/g,"\"").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/'/g,"\'");
};
String.prototype.s2n=function(){
var t=parseInt(this.replace(/px$/i,""),10);
return isNaN(t)?0:t;
};
String.prototype.toInnerHTML=function(){
var s=this.replace(/&/g,"&").replace(/\"/g,""").replace(/\'/g,"'").replace(/</g,"<").replace(/>/g,">");
return Browser.isIE?s.replace(/'/g,"'"):s;
};
String.prototype.toRealStr=function(){
return this.replace(/"/g,"\"").replace(/(?:')|(?:')/g,"\'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&");
};
String.prototype.getRealLength = function(){
return this.replace(/[^\x00-\xff]/g,"aa").length;
};
String.prototype.URLencode=function(){
return this.replace(/[\x09\x0A\x0D\x21-\x29\x2B\x2C\x2F\x3A-\x3F\x5B-\x5E\x60\x7B-\x7E]/g,function(a){return "%"+((a.charCodeAt(0)<16)?("0"+a.charCodeAt(0).toString(16)):(a.charCodeAt(0).toString(16)))}).replace(/[\x00-\x20 ]/g,"+");
};
// 折半
String.prototype.cutWord = function(nRealLength) {
var oThis = this.toRealStr();
if(oThis.getRealLength() <= nRealLength || nRealLength <= 0)
return oThis.toInnerHTML();
var str = "";
var nEndIndex = Math.floor(nRealLength/2);
while(1) {
str = oThis.substr(0, nEndIndex);
if(str.getRealLength() < nRealLength-1) {
nEndIndex = nEndIndex + Math.floor((nRealLength-str.getRealLength())/2);
}
else if(str.getRealLength() > nRealLength) {
nEndIndex = nEndIndex - Math.floor((str.getRealLength()-nRealLength)/2);
}
else if(str.getRealLength() == nRealLength) {
break;
}
else {
if(nEndIndex<oThis.length && !isMultipleByte(oThis.charCodeAt(nEndIndex))) {
str = oThis.substr(0, nEndIndex+1);
}
break;
}
}
return str.toInnerHTML();
}
function isMultipleByte(ch) {
var value = parseInt(ch.toString(16), 16);
if(value < 0x00 || value > 0xff)
return true;
return false;
}
function $(id){
return document.getElementById(id);
}
function _$(id){
return document.getElementsByName(id);
}
function $n(tagName, name) {
var arr = new Array();
var e = document.getElementsByTagName(tagName);
for(i=0; i<e.length; ++i) {
if(e[i].getAttribute("name") == name) {
arr.push(e[i]);
}
}
if(arr.length==0){//用name获取不到的情况下,执行getElementsByTagNameAndId的逻辑
for(i=0; i<e.length; ++i) {
if(e[i].getAttribute("id") == name) {
arr.push(e[i]);
}
}
}
return arr;
}
//清空数组
function clearArray(arr){
arr.splice(0,arr.length);
}
//取消数组中的重复项目除了undefined
function destinctArray(arr){
var res=[];
for(var i=0;i<arr.length;i++){
if(arr[i]===void(0))
continue;
for(var j=i+1;j<arr.length;j++){
if(arr[i]===arr[j])
arr[j]=void(0);
}
res.push(arr[i]);
}
return res;
}
//获取element的位置
function getPosition(obj) {
var top=0;
var left=0;
var width=obj.offsetWidth;
var height=obj.offsetHeight;
while (obj.offsetParent) {
top += obj.offsetTop;
left += obj.offsetLeft;
obj = obj.offsetParent;
}
return {"top":top,"left":left,"width":width,"height":height};
}
//删除DOM
function removeElement(element){
if((typeof element)=="string")
element=$(element);
if(!!element && (typeof element)=="object"){
element.parentNode.removeChild(element);
}
}
function showLoginBox(s, t, msg){
if (!!s && !!t) s += ("&anon=" + ((!!t) ? 1 : 0));
if (!!s && !!msg) s += ("&msg=" + encodeURIComponent(msg));
popupDialog("登录Qzone", '<iframe frameborder="no" style="border:none;width:370px;height:240px" src="http://ui.ptlogin2.qq.com/cgi-bin/login?appid=8000108&hide_title_bar=1&target=self&link_target=blank&f_url=http%3A%2F%2F' + imgcacheDomain + '%2Fqzone%2Fv5%2Floginerr.html&s_url=http%3A%2F%2F' + imgcacheDomain + '%2Fqzone%2Fv5%2Floginsucc.html' + (!!s ? ('%3fpara%3d' + s) : '') + '"></iframe>', 376, 280);
QZONE.event.preventDefault();
}
function popupNewDialog(title, html, width, height){
height+=30;
if (!window._currentPop) {
window._currentPop = QZONE.dialog.create(title, html, width, height);
var b = QZONE.dom.get("dialog_button_" + window._currentPop._id);
b.onclick = closeNewPopup;
pContent = QZONE.dom.get("dialog_content_" + window._currentPop._id);
if (pContent.childNodes[0].tagName == "IFRAME") {
if (width && height) {
pContent.childNodes[0].style.width = "100%";
pContent.childNodes[0].style.height = pContent.offsetHeight + "px";
}
}
ENV.set("popupMaskId",QZONE.maskLayout.create());
}
var oDialog = QZONE.dom.get("dialog_" + window._currentPop._id);
oDialog.style.top = (QZONE.dom.getClientHeight() - height)/2 - 20 + "px";
}
function closeNewPopup(){
if (window.popupCallback) {
window._currentPop.onUnload = function(){
if (typeof(window.popupCallback) == 'function') window.popupCallback();
window.popupCallback = null;
}
}
if (window._currentPop) {
window._currentPop.unload();
window._currentPop = null;
} else if (QZONE.dialog.lastFocus) {
QZONE.dialog.lastFocus.unload();
}
QZONE.maskLayout.remove(ENV.get("popupMaskId"));
ENV.del("popupMaskId");
return true;
}
var popupDialog = popupNewDialog;
var closePopup = closeNewPopup;
function getScrollTop() {
return Math.max(document.documentElement.scrollTop, document.body.scrollTop);
}
function getClientHeight (){
return document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight;
}
function getClientWidth() {
return document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth;
}
function getPosition(obj) {
var top=0;
var left=0;
var width=obj.offsetWidth;
var height=obj.offsetHeight;
while (obj.offsetParent) {
top += obj.offsetTop;
left += obj.offsetLeft;
obj = obj.offsetParent;
}
return {"top":top,"left":left,"width":width,"height":height};
}
function getElementInBody(id,tagName,insertFirst,parentNodeID,className,initCSSText){
var e = $(id);
if (!e){
tagName = (!tagName)?"div":tagName; //如果没有设置tagName 则默认为div
e = document.createElement(tagName);
e.id = id;
var parentNode = (!parentNodeID)?document.body:$(parentNodeID)
if (insertFirst)
parentNode.insertBefore(e,parentNode.firstChild);
else
parentNode.appendChild(e);
e.className = className?className:"";
e.style.cssText = initCSSText?initCSSText:"";
}
parentNode = null;
return e;
}
function getBitMapFlag(i){
if(typeof g_UserBitmap=="string")
return parseInt(g_UserBitmap.charAt(15-Math.floor((i-1)/4)),16) >>((i-1)%4) &1;
else
return 0;
}
function showMsgbox(msg,type,liveTime,imageSrc,isCenter,left,top){
msg = (!msg)?"正在处理,请稍候...":msg;
type = type?type:0;
var msgBox = getElementInBody("msgBoxDiv","div");
msgBox.style.cssText = "position:absolute;width:100%;left:0px;top:0px;height:100%;" + (left?"":"text-align:center;");
var strHTML;
if (imageSrc){
strHTML = '<img src="'+imageSrc+'" border="0"/>';
var img = new Image();
img.src = imageSrc;
h = parseInt(img.height);
}else{
var msgTemp = '<div id="__className__" style="position:static;display:inline"><span class="tipsl"></span><span class="tipsm">__text__</span><span class="__tipsType__"></span></div>';
var c = (type<2)?"mode_tipss":"mode_tips";
var c1 = (type == 1 || type == 3)?"tipsrn":"tipsr";
strHTML = msgTemp.replace(/__className__/,c).replace(/__tipsType__/,c1).replace(/__text__/,msg);
}
msgBox.innerHTML = strHTML;
var pos = getPosition(msgBox);
msgBox.style.marginLeft = getClientWidth()/2 - 100 + "px";
msgBox.style.paddingTop = getClientHeight() / 2 + getScrollTop() - 40 + "px";
if (liveTime) window.setTimeout(hideMsgbox,liveTime);
}
/**
* 隐藏信息框
* @see #showMsgbox
*/
function hideMsgbox(){
var msgBox = $("msgBoxDiv");
if (!msgBox) return;
removeElement(msgBox);
}
function fixImagesSize(){
var imgs = $('veryContent').getElementsByTagName('img');
for(var i=0;i<imgs.length;i++)
if(imgs[i].complete){
picsize(imgs[i],670);
}else{
imgs[i].onload = function(){
picsize(this,670);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -