📄 bootstrap.js
字号:
/**
* <b>boot strap functions</b>
* @version : 1.0
* @since : 2007-6-14
*
* @Description :
* startup working enviroment
*
* @author xp yanbo@staff.sina.com.cn | drdr.xp@gmail.com
* @copyright sina.com
*/
/**-------------------------/// Boot-strap \\\---------------------------
*
* 1. decide who is the top frame
* 2. preLoad configs
* 3. fix config data
* 4. supply some function for loading external resource
*
*--------------------------\\\ Boot-strap ///---------------------------*/
/**
*
*/
document.domain="blog.sina.com.cn";
if (window.scope == null){
try {
if (window.parent.scope != null) window.scope = window.parent.scope;
} catch (e) {
scope.trace("---\n" + e);
}
try {
if (window.scope == null) window.scope = window;
} catch (e) {
scope.trace(e);
}
}
/* fix $BASE */
if ($BASE.lastIndexOf("/") < $BASE.length-1) $BASE = $BASE + "/";
/**
* @author xp
* write script tag to document. Can be used only in page-loading phase.
* only script text or script url can be accepted. u cant specify none or two of them or an error will be raised
* @param o {
* id : id of the created tag,
* url : String,
* script : String
* }
*/
function dwScript(o){
o.id = o.id || "";
o.charset = o.charset || "utf-8";
if (o.script && o.script != ""){
document.write("<script id='" + o.id + "'>" + o.script + "<\/script>");
} else if (o.url && o.url != ""){
document.write("<script id='" + o.id + "' src='" + o.url + "' charset='" + o.charset + "'><\/script>");
} else throw new Error("no script content or url specified");
}
/**
* @author xp
* write link tag or style tag to document. Can be used only in page-loading phase.
* only script text or script url can be accepted. u cant specify none or two of them or an error will be raised
* @param o {
* id : id of the created tag,
* url : String,
* script : String
* }
*/
function dwCSS(o){
o.id = o.id || "";
if (o.url){
document.write('<link id="' + o.id + '" rel="stylesheet" type="text/css" href="' + o.url + '" />');
} else if (o.styles){
document.write('<style id="' + o.id + '" >'+o.styles+'<\/style>');
}
}
/**
* determine which page it is in
*/
function $getPageId(win){
win = win || this;
var ref = win.location.href;
if (ref.indexOf("/s/blog_") > -1) return "article";
if (ref.indexOf("/s/comment_") > -1) return "comment";
return "blog";
}
function fixConfig(){
if (scope.fixed) return;
scope.fixed = true;
function fix(o, name, value){ if (o[name] == null || o[name] == -1) o[name] = value; }
function int(str) {return parseInt(str);}
var scp = window.scope;
scp.config = scp.config || {};
var cfg = scp.config;
fix(cfg, "theme" , 1);
fix(cfg, "countTheme" , 301);
fix(cfg, "isRandom" , false);
fix(cfg, "customTheme", { calendar : 1, music : 1, photo : 1, bannar : 1, menu : 1, box_1 : 1, box_2 : 1, bg : 1 });
var ctm = cfg.customTheme;
fix(ctm, "calendar", 1);
fix(ctm, "music", 1);
fix(ctm, "photo", 1);
fix(ctm, "bannar", 1);
fix(ctm, "menu", 1);
fix(ctm, "box_1", 1);
fix(ctm, "box_2", 1);
fix(ctm, "bg", 1);
if (cfg.isRandom && scope.themeRange && scope.themeRange[cfg.theme-1]) {
var ct = cfg.customTheme;
var tr = scope.themeRange[cfg.theme-1];
for (var i in ct){
if (tr[i] != null) ct[i] = Math.ceil(Math.random()*tr[i]);
}
}
fix(cfg, "client_ver" , "");
var vers = cfg.client_ver.split(",") || [];
fix(cfg, "resourceVersion" , int(vers[0]) || new Date().getDate());
fix(cfg, "cssVer" , int(vers[1]) || 1);
fix(cfg, "jsVer" , int(vers[2]) || 1);
fix(cfg, "imgVer" , int(vers[3]) || 1);
fix(cfg, "isModified" , false);
fix(cfg, "layout" , null);
fix(cfg, "isCommentAllowed", true);
fix(cfg, "isMessageAllowed", true);
var lo = cfg.layout;
/* force article page config.layout */
if ($getPageId() == "article") {
lo = cfg.layout = {
column_1 : [ "blog_photo", "blog_zone", "blog_sort", /*"new_module",*/ "blog_last_updated_blog" ],
column_2 : [ "blog_feeds" ]
}
} else if (lo && lo.column_1) {
/* lo.column_1.push("blog_counter", "blog_feeds_addr"); */
}
/* config doesnt output layout order */
/* fix the bug in theme 4 left-right hasnt been reversed */
if (cfg.theme == 4 && lo && lo.column_1 && lo.column_2){
var t;
t = lo.column_1; lo.column_1 = lo.column_2; lo.column_2 = t;
}
}
/**
* This method will not be called until config data hs been loaded.
* In-page script should invoke this method.
*
*/
function loadPreProcedure(){
fixConfig();
var cfg = window.scope.config;
var jsVer = cfg.resourceVersion + '_' + cfg.jsVer+".js";
dwScript({url:$BASE + 'js/preProcess.js?'+jsVer});
}
function loadCss(){
fixConfig();
var cfg = window.scope.config;
var cssVer = cfg.resourceVersion + '_' + cfg.cssVer+".css";
dwCSS({url:$BASE + 'css/default.template.css?'+cssVer}); /* write frame css */
dwCSS({url:$BASE + 'css/theme/'+ cfg.theme +'.css?'+cssVer}); /* write theme css */
var cus = cfg.customTheme;
var icalendar=scope.themeRange[cfg.theme].icalendar;
icalendar==0 ? cus["photo"]=cus["calendar"]:"";
var url_1 = "css.cached.4.0/" + cfg.theme + "_1/{$photo}/{$bannar}_{$menu}.css?"+cssVer;
var url_2 = "css.cached.4.0/" + cfg.theme + "_2/{$box_1}/{$box_2}_{$bg}.css?"+cssVer;
url_1 = url_1.replace(/\{\$(\w+)\}/g,function (a,s){return cus[s];});
url_2 = url_2.replace(/\{\$(\w+)\}/g,function (a,s){return cus[s];});
dwCSS({url:$BASE + url_1}); /* write custome css */
dwCSS({url:$BASE + url_2}); /* write custome css */
}
function loadResource(id){
id = id || $getPageId();
fixConfig();
var cfg = window.scope.config;
var jsVer = cfg.resourceVersion + '_' + cfg.jsVer+".js";
switch (id){
case "fl":
dwScript({url : $BASE + 'js/fl.js?' +jsVer}); break;
case "article":
/* dwScript({url : $BASE + 'js/article.js?' +jsVer}); break; */
case "comment":
case "index":
case "circle":
case "gbook":
case "alist":
case "list":
/* dwScript({url : $BASE + 'js/list.js?' +jsVer}); break; */
case "blog":
default: dwScript({url : $BASE + 'js/blog.js?'+jsVer});
}
}
//TODO correct the url
if (window == window.scope) {
var code = checkAuthor() ? "1" : "0";
dwScript({
url : "http://conf.blog.sina.com.cn/cnf?" + window.scope.uid + "&"+code+"&" + Math.random() + ".js",
charset : "gb2312"
});
dwScript({
url : $BASE + "js/staticConfig.js",
charset : "gb2312"
});
}
/* From util.js @ Stan */
/**
* check user status by cookie
* @author stan
* return Boolean true if the author is visiting its own blog
*/
function checkAuthor(){
trace("uid : "+scope.uid, "#00FFFF");
var AuthorInfo = getCookie("nick");
scope.AuthorUID = AuthorInfo ? AuthorInfo.match(/\(\d{10,12}\)/g)[0].replace(/\(|\)/g, "") : null;
trace("UID : "+scope.AuthorUID, "#00FFFF");
return scope.AuthorUID && scope.uid == scope.AuthorUID;
}
/**
* get cookie by name
* @author stan
*/
function getCookie(name) {
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
function trace(){} /* for debug */
window.scope.EI = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -