/**
* @preserve SeaJS - A Module Loader for the Web
* v1.3.0 | seajs.org | MIT Licensed
*/
/**
* Base namespace for the framework.
*/
this.seajs = { _seajs: this.seajs }
/**
* The version of the framework. It will be replaced with "major.minor.patch"
* when building.
*/
seajs.version = '1.3.0'
/**
* The private utilities. Internal use only.
*/
seajs._util = {}
/**
* The private configuration data. Internal use only.
*/
seajs._config = {
/**
* Debug mode. It will be turned off automatically when compressing.
*/
debug: '%DEBUG%',
/**
* Modules that are needed to load before all other modules.
*/
preload: []
}
/**
* The minimal language enhancement
*/
;(function(util) {
var toString = Object.prototype.toString
var AP = Array.prototype
util.isString = function(val) {
return toString.call(val) === '[object String]'
}
util.isFunction = function(val) {
return toString.call(val) === '[object Function]'
}
util.isRegExp = function(val) {
return toString.call(val) === '[object RegExp]'
}
util.isObject = function(val) {
return val === Object(val)
}
util.isArray = Array.isArray || function(val) {
return toString.call(val) === '[object Array]'
}
util.indexOf = AP.indexOf ?
function(arr, item) {
return arr.indexOf(item)
} :
function(arr, item) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === item) {
return i
}
}
return -1
}
var forEach = util.forEach = AP.forEach ?
function(arr, fn) {
arr.forEach(fn)
} :
function(arr, fn) {
for (var i = 0; i < arr.length; i++) {
fn(arr[i], i, arr)
}
}
util.map = AP.map ?
function(arr, fn) {
return arr.map(fn)
} :
function(arr, fn) {
var ret = []
forEach(arr, function(item, i, arr) {
ret.push(fn(item, i, arr))
})
return ret
}
util.filter = AP.filter ?
function(arr, fn) {
return arr.filter(fn)
} :
function(arr, fn) {
var ret = []
forEach(arr, function(item, i, arr) {
if (fn(item, i, arr)) {
ret.push(item)
}
})
return ret
}
var keys = util.keys = Object.keys || function(o) {
var ret = []
for (var p in o) {
if (o.hasOwnProperty(p)) {
ret.push(p)
}
}
return ret
}
util.unique = function(arr) {
var o = {}
forEach(arr, function(item) {
o[item] = 1
})
return keys(o)
}
util.now = Date.now || function() {
return new Date().getTime()
}
})(seajs._util)
/**
* The tiny console
*/
;(function(util) {
/**
* The safe wrapper of console.log/error/...
*/
util.log = function() {
if (typeof console === 'undefined') return
var args = Array.prototype.slice.call(arguments)
var type = 'log'
var last = args[args.length - 1]
console[last] && (type = args.pop())
// Only show log info in debug mode
if (type === 'log' && !seajs.debug) return
if (console[type].apply) {
console[type].apply(console, args)
return
}
// See issue#349
var length = args.length
if (length === 1) {
console[type](args[0])
}
else if (length === 2) {
console[type](args[0], args[1])
}
else if (length === 3) {
console[type](args[0], args[1], args[2])
}
else {
console[type](args.join(' '))
}
}
})(seajs._util)
/**
* Path utilities
*/
;(function(util, config, global) {
var DIRNAME_RE = /.*(?=\/.*$)/
var MULTIPLE_SLASH_RE = /([^:\/])\/\/+/g
var FILE_EXT_RE = /\.(?:css|js)$/
var ROOT_RE = /^(.*?\w)(?:\/|$)/
/**
* Extracts the directory portion of a path.
* dirname('a/b/c.js') ==> 'a/b/'
* dirname('d.js') ==> './'
* @see http://jsperf.com/regex-vs-split/2
*/
function dirname(path) {
var s = path.match(DIRNAME_RE)
return (s ? s[0] : '.') + '/'
}
/**
* Canonicalizes a path.
* realpath('./a//b/../c') ==> 'a/c'
*/
function realpath(path) {
MULTIPLE_SLASH_RE.lastIndex = 0
// 'file:///a//b/c' ==> 'file:///a/b/c'
// 'http://a//b/c' ==> 'http://a/b/c'
if (MULTIPLE_SLASH_RE.test(path)) {
path = path.replace(MULTIPLE_SLASH_RE, '$1\/')
}
// 'a/b/c', just return.
if (path.indexOf('.') === -1) {
return path
}
var original = path.split('/')
var ret = [], part
for (var i = 0; i < original.length; i++) {
part = original[i]
if (part === '..') {
if (ret.length === 0) {
throw new Error('The path is invalid: ' + path)
}
ret.pop()
}
else if (part !== '.') {
ret.push(part)
}
}
return ret.join('/')
}
/**
* Normalizes an uri.
*/
function normalize(uri) {
uri = realpath(uri)
var lastChar = uri.charAt(uri.length - 1)
if (lastChar === '/') {
return uri
}
// Adds the default '.js' extension except that the uri ends with #.
// ref: http://jsperf.com/get-the-last-character
if (lastChar === '#') {
uri = uri.slice(0, -1)
}
else if (uri.indexOf('?') === -1 && !FILE_EXT_RE.test(uri)) {
uri += '.js'
}
// Remove ':80/' for bug in IE
if (uri.indexOf(':80/') > 0) {
uri = uri.replace(':80/', '/')
}
return uri
}
/**
* Parses alias in the module id. Only parse the first part.
*/
function parseAlias(id) {
// #xxx means xxx is already alias-parsed.
if (id.charAt(0) === '#') {
return id.substring(1)
}
var alias = config.alias
// Only top-level id needs to parse alias.
if (alias && isTopLevel(id)) {
var parts = id.split('/')
var first = parts[0]
if (alias.hasOwnProperty(first)) {
parts[0] = alias[first]
id = parts.join('/')
}
}
return id
}
var mapCache = {}
/**
* Converts the uri according to the map rules.
*/
function parseMap(uri) {
// map: [[match, replace], ...]
var map = config.map || []
if (!map.length) return uri
var ret = uri
// Apply all matched rules in sequence.
for (var i = 0; i < map.length; i++) {
var rule = map[i]
if (util.isArray(rule) && rule.length === 2) {
var m = rule[0]
if (util.isString(m) && ret.indexOf(m) > -1 ||
util.isRegExp(m) && m.test(ret)) {
ret = ret.replace(m, rule[1])
}
}
else if (util.isFunction(rule)) {
ret = rule(ret)
}
}
if (!isAbsolute(ret)) {
ret = realpath(dirname(pageUri) + ret)
}
if (ret !== uri) {
mapCache[ret] = uri
}
return ret
}
/**
* Gets the original uri.
*/
function unParseMap(uri) {
return mapCache[uri] || uri
}
/**
* Converts id to uri.
*/
function id2Uri(id, refUri) {
if (!id) return ''
id = parseAlias(id)
refUri || (refUri = pageUri)
var ret
// absolute id
if (isAbsolute(id)) {
ret = id
}
// relative id
else if (isRelative(id)) {
// Converts './a' to 'a', to avoid unnecessary loop in realpath.
if (id.indexOf('./') === 0) {
id = id.substring(2)
}
ret = dirname(refUri) + id
}
// root id
else if (isRoot(id)) {
ret = refUri.match(ROOT_RE)[1] + id
}
// top-level id
else {
ret = config.base + '/' + id
}
return normalize(ret)
}
function isAbsolute(id) {
return id.indexOf('://') > 0 || id.indexOf('//') === 0
}
function isRelative(id) {
return id.indexOf('./') === 0 || id.indexOf('../') === 0
}
function isRoot(id) {
return id.charAt(0) === '/' && id.charAt(1) !== '/'
}
function isTopLevel(id) {
var c = id.charAt(0)
return id.indexOf('://') === -1 && c !== '.' && c !== '/'
}
/**
* Normalizes pathname t