/*********************************************************************
* 配置系統
在系統運行的開始就須要讀取系統中require.config()這個方法中所配置的項目 *
**********************************************************************/
//這裏寫在前面是爲了更加方便閱讀代碼,在實際運行中,這幾段代碼必須放在下面
kernel.debug = true kernel.plugins = plugins kernel.plugins['interpolate'](["{{", "}}"]) kernel.paths = {} kernel.shim = {} kernel.maxRepeatSize = 100 avalon.config = kernel
function kernel(settings) {
for (var p in settings) {
if (!ohasOwn.call(settings, p))
continue
var val = settings[p]
if (typeof kernel.plugins[p] === "function") {
kernel.plugins[p](val)
} else if (typeof kernel[p] === "object") {
avalon.mix(kernel[p], val)
} else {
kernel[p] = val
}
}
return this
}
var openTag, closeTag, rexpr, rexprg, rbind, rregexp = /[-.*+?^${}()|[\]\/\\]/g
function escapeRegExp(target) {
//http://stevenlevithan.com/regex/xregexp/
//將字符串安全格式化爲正則表達式的源碼
return (target + "").replace(rregexp, "\\$&")
}
var innerRequire = noop
var plugins = {
loader: function(builtin) {
window.define = builtin ? innerRequire.define : otherDefine
window.require = builtin ? innerRequire : otherRequire
},
interpolate: function(array) {
openTag = array[0]
closeTag = array[1]
if (openTag === closeTag) {
throw new SyntaxError("openTag!==closeTag")
} else if (array + "" === "<!--,-->") {
kernel.commentInterpolate = true
} else {
var test = openTag + "test" + closeTag
cinerator.innerHTML = test
if (cinerator.innerHTML !== test && cinerator.innerHTML.indexOf("<") > -1) {
throw new SyntaxError("此定界符不合法")
}
cinerator.innerHTML = ""
}
var o = escapeRegExp(openTag),
c = escapeRegExp(closeTag)
rexpr = new RegExp(o + "(.*?)" + c)
rexprg = new RegExp(o + "(.*?)" + c, "g")
rbind = new RegExp(o + ".*?" + c + "|\\sms-")
}
}