//創建一個對象 對象名稱為ext 初始有一個屬性version
Ext = {version: '2.0.1'};
//ie5之前的瀏覽器,undefined 并不是windows對象的子對象 window.undefined=undefined
Window["undefined"] = window["undefined"];
//實現一個類方法,apply方法的作用是 把C中的屬性和方法copy到o 中,如果有些默認的屬性和方法需要一同進入o中,只需把
//這些屬性和值組成一個對象(也可以是使用“{}”包含鍵值對方式) 放在第三個參數位置即可
Ext.apply = function(o, c, defaults){
if(defaults){
Ext.apply(o, defaults);
}
if(o && c && typeof c == 'object'){
for(var p in c){
o[p] = c[p];
}
}
return o;
};
//內函數,頁面加載即調用,調用完后即釋放變量空間
(function(){
var idSeed = 0;
//navigator.userAgent 的值是得到客戶端瀏覽器的相關信息 得到內容樣式為: Mozilla/2.0 (Win16; I)
var ua = navigator.userAgent.toLowerCase();
//當文檔有了標準申明時, document.compatMode 的值就等于 "CSS1compat"
//IE對盒模型的渲染在Standards Mode和Quirks Mode是有很大差別的,在Standards Mode下對於盒模型的解釋和其他的標準瀏覽器是一樣的
//但是在Quirks Mode模式下則有很大的差別,在不申明Doctype的情況下,ie默認為Quirks Mode,所以為兼容性考慮,我們要獲取當前文檔的渲染方式
var isStrict = document.compatMode == "CSS1Compat",
//標示請求方是不是opera瀏覽器
isOpera = ua.indexOf("opera") > -1,
//標示請求方是不是是mac操作系統
isSafari = (/webkit|khtml/).test(ua),
isIE = !isOpera && ua.indexOf("msie") > -1,
isIE7 = !isOpera && ua.indexOf("msie 7") > -1,
//Mozilla家族網頁瀏覽器以及Netscape 6以後版本瀏覽器所使用
isGecko = !isSafari && ua.indexOf("gecko") > -1,
//判斷客戶端方瀏覽器是不是會按Standards Mode模式處理盒模型控件
isBorderBox = isIE && !isStrict,
//標示windows操作系統
isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
//標示mac操作系統
isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
//標示linux操作系統
isLinux = (ua.indexOf("linux") != -1),
//標示當前瀏覽器傳遞的URL是不是以https開頭,即標示是不是安全的訪問
isSecure = window.location.href.toLowerCase().indexOf("https") === 0;
/*
a {}{
background:url(images/normal.gif);
}
a:hover {}{
background:url(images/hover.gif);
}
如果為超級連接定義這樣的CSS樣式以實現鼠標懸浮時的動態效果,在firefox下是沒有問題的
第一次加載之後,瀏覽器都會從緩存讀取背景圖片;而ie7以前的版本有一個bug,每次都從服務器端
讀取背景圖片,結果是背景圖片加載時會出現短暫空白
以下代碼 執行從本地緩存池中讀取已存在的背景圖
*/
if(isIE && !isIE7){
try{
document.execCommand("BackgroundImageCache", false, true);
}catch(e){}
}
//給這個全局對象添加屬性
Ext.apply(Ext, {
/**
* 如果瀏覽器使用 strict模式,這個屬性為true
* @type Boolean
*/
isStrict : isStrict,
/**
* 如果瀏覽器使用https方式訪問(即http的安全模式),這個屬性為true
* @type Boolean
*/
isSecure : isSecure,
/**
* 當文檔加載完成時此值會設置為true,初始為FALSE
* @type Boolean
*/
isReady : false,
/**
* 設定 是否自動清除緩存中沒有被引用的元素,默認為TRUE
* @type Boolean
*/
enableGarbageCollector : true,
/**
* 設定 是否自動取消對清楚出緩存元素的監聽 這個屬性只有當enableGarbageCollector設定為true時才設定有效
* @type Boolean
*/
enableListenerCollection:false,
/**
* 當一個受保護的資源被請求時,重定向到一個空白頁面,ie瀏覽器會彈出風險警告
* @type String
*/
SSL_SECURE_URL : "javascript:false",
/**
設置ext默認背景圖片,如果不設置會從網站服務器上加載
* @type String
*/
BLANK_IMAGE_URL : "http:/"+"/extjs.com/s.gif",
/**
*可重複使用的空方法
*/
emptyFn : function(){},
/**
把o中不存在 但是c中存在的屬性 拷貝給 o 返回
*/
applyIf : function(o, c){
if(o && c){
for(var p in c){
if(typeof o[p] == "undefined"){ o[p] = c[p]; }
}
}
return o;
},