mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Further clean-up Bootstrap code.
This commit is contained in:
parent
c25db2377f
commit
7b237ceedc
1 changed files with 48 additions and 24 deletions
72
lib/bootstrap.js
vendored
72
lib/bootstrap.js
vendored
|
@ -1,9 +1,9 @@
|
||||||
/**
|
/**
|
||||||
* Bootstrap JavaScript Library
|
* Bootstrap JavaScript Library
|
||||||
* (c) 2006 - 2010 Juerg Lehni, http://scratchdisk.com/
|
* (c) 2006 - 2011 Juerg Lehni, http://lehni.org/
|
||||||
*
|
*
|
||||||
* Bootstrap is released under the MIT license
|
* Bootstrap is released under the MIT license
|
||||||
* http://bootstrap-js.net/
|
* http://bootstrapjs.org/
|
||||||
*
|
*
|
||||||
* Inspirations:
|
* Inspirations:
|
||||||
* http://dean.edwards.name/weblog/2006/03/base/
|
* http://dean.edwards.name/weblog/2006/03/base/
|
||||||
|
@ -35,11 +35,15 @@ var Base = this.Base = new function() {
|
||||||
_describe = Object.getOwnPropertyDescriptor;
|
_describe = Object.getOwnPropertyDescriptor;
|
||||||
|
|
||||||
function define(obj, name, desc) {
|
function define(obj, name, desc) {
|
||||||
if (_define)
|
if (_define) {
|
||||||
try { delete obj[name]; return _define(obj, name, desc); } catch (e) {}
|
try {
|
||||||
|
delete obj[name];
|
||||||
|
return _define(obj, name, desc);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
if ((desc.get || desc.set) && obj.__defineGetter__) {
|
if ((desc.get || desc.set) && obj.__defineGetter__) {
|
||||||
if (desc.get) obj.__defineGetter__(name, desc.get);
|
desc.get && obj.__defineGetter__(name, desc.get);
|
||||||
if (desc.set) obj.__defineSetter__(name, desc.set);
|
desc.set && obj.__defineSetter__(name, desc.set);
|
||||||
} else {
|
} else {
|
||||||
obj[name] = desc.value;
|
obj[name] = desc.value;
|
||||||
}
|
}
|
||||||
|
@ -47,13 +51,18 @@ var Base = this.Base = new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function describe(obj, name) {
|
function describe(obj, name) {
|
||||||
if (_describe)
|
if (_describe) {
|
||||||
try { return _describe(obj, name); } catch (e) {}
|
try {
|
||||||
|
return _describe(obj, name);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
var get = obj.__lookupGetter__ && obj.__lookupGetter__(name);
|
var get = obj.__lookupGetter__ && obj.__lookupGetter__(name);
|
||||||
return get
|
return get
|
||||||
? { enumerable: true, configurable: true, get: get, set: obj.__lookupSetter__(name) }
|
? { get: get, set: obj.__lookupSetter__(name), enumerable: true,
|
||||||
|
configurable: true }
|
||||||
: has.call(obj, name)
|
: has.call(obj, name)
|
||||||
? { enumerable: true, configurable: true, writable: true, value: obj[name] }
|
? { value: obj[name], enumerable: true, configurable: true,
|
||||||
|
writable: true }
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,21 +70,32 @@ var Base = this.Base = new function() {
|
||||||
var beans, bean;
|
var beans, bean;
|
||||||
|
|
||||||
function field(name, val, dontCheck, generics) {
|
function field(name, val, dontCheck, generics) {
|
||||||
var val = val || (val = describe(src, name)) && (val.get ? val : val.value),
|
var val = val || (val = describe(src, name))
|
||||||
|
&& (val.get ? val : val.value),
|
||||||
func = typeof val == 'function', res = val,
|
func = typeof val == 'function', res = val,
|
||||||
prev = preserve || func ? (val && val.get ? name in dest : dest[name]) : null;
|
prev = preserve || func
|
||||||
if (generics && func && (!preserve || !generics[name])) generics[name] = function(bind) {
|
? (val && val.get ? name in dest : dest[name]) : null;
|
||||||
return bind && dest[name].apply(bind, slice.call(arguments, 1));
|
if (generics && func && (!preserve || !generics[name])) {
|
||||||
|
generics[name] = function(bind) {
|
||||||
|
return bind && dest[name].apply(bind,
|
||||||
|
slice.call(arguments, 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((dontCheck || val !== undefined && has.call(src, name)) && (!preserve || !prev)) {
|
if ((dontCheck || val !== undefined && has.call(src, name))
|
||||||
|
&& (!preserve || !prev)) {
|
||||||
if (func) {
|
if (func) {
|
||||||
if (prev && /\bthis\.base\b/.test(val)) {
|
if (prev && /\bthis\.base\b/.test(val)) {
|
||||||
var fromBase = base && base[name] == prev;
|
var fromBase = base && base[name] == prev;
|
||||||
res = function() {
|
res = function() {
|
||||||
var tmp = describe(this, 'base');
|
var tmp = describe(this, 'base');
|
||||||
define(this, 'base', { value: fromBase ? base[name] : prev, configurable: true });
|
define(this, 'base', { value: fromBase
|
||||||
try { return val.apply(this, arguments); }
|
? base[name] : prev, configurable: true });
|
||||||
finally { tmp ? define(this, 'base', tmp) : delete this.base; }
|
try {
|
||||||
|
return val.apply(this, arguments);
|
||||||
|
} finally {
|
||||||
|
tmp ? define(this, 'base', tmp)
|
||||||
|
: delete this.base;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
res.toString = function() {
|
res.toString = function() {
|
||||||
return val.toString();
|
return val.toString();
|
||||||
|
@ -89,7 +109,8 @@ var Base = this.Base = new function() {
|
||||||
}
|
}
|
||||||
if (!res || func || !res.get && !res.set)
|
if (!res || func || !res.get && !res.set)
|
||||||
res = { value: res, writable: true };
|
res = { value: res, writable: true };
|
||||||
if ((describe(dest, name) || { configurable: true }).configurable) {
|
if ((describe(dest, name)
|
||||||
|
|| { configurable: true }).configurable) {
|
||||||
res.configurable = true;
|
res.configurable = true;
|
||||||
res.enumerable = enumerable;
|
res.enumerable = enumerable;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +120,8 @@ var Base = this.Base = new function() {
|
||||||
if (src) {
|
if (src) {
|
||||||
beans = src.beans && [];
|
beans = src.beans && [];
|
||||||
for (var name in src)
|
for (var name in src)
|
||||||
if (has.call(src, name) && !/^(statics|generics|preserve|beans|prototype|__proto__|toString|valueOf)$/.test(name))
|
if (has.call(src, name)
|
||||||
|
&& !/^(statics|generics|preserve|beans|prototype|__proto__|toString|valueOf)$/.test(name))
|
||||||
field(name, null, true, generics);
|
field(name, null, true, generics);
|
||||||
field('toString');
|
field('toString');
|
||||||
field('valueOf');
|
field('valueOf');
|
||||||
|
@ -161,8 +183,10 @@ var Base = this.Base = new function() {
|
||||||
|
|
||||||
Base.inject = function(src) {
|
Base.inject = function(src) {
|
||||||
if (src) {
|
if (src) {
|
||||||
var proto = this.prototype, base = proto.__proto__ && proto.__proto__.constructor;
|
var proto = this.prototype,
|
||||||
inject(proto, src, false, base && base.prototype, src.preserve, src.generics && this);
|
base = proto.__proto__ && proto.__proto__.constructor;
|
||||||
|
inject(proto, src, false, base && base.prototype, src.preserve,
|
||||||
|
src.generics && this);
|
||||||
inject(this, src.statics, true, base, src.preserve);
|
inject(this, src.statics, true, base, src.preserve);
|
||||||
}
|
}
|
||||||
for (var i = 1, l = arguments.length; i < l; i++)
|
for (var i = 1, l = arguments.length; i < l; i++)
|
||||||
|
@ -172,7 +196,8 @@ var Base = this.Base = new function() {
|
||||||
|
|
||||||
Base.extend = function(src) {
|
Base.extend = function(src) {
|
||||||
var proto = new this(this.dont), ctor = extend(proto);
|
var proto = new this(this.dont), ctor = extend(proto);
|
||||||
define(proto, 'constructor', { value: ctor, writable: true, configurable: true });
|
define(proto, 'constructor',
|
||||||
|
{ value: ctor, writable: true, configurable: true });
|
||||||
ctor.dont = {};
|
ctor.dont = {};
|
||||||
inject(ctor, this, true);
|
inject(ctor, this, true);
|
||||||
return arguments.length ? this.inject.apply(ctor, arguments) : ctor;
|
return arguments.length ? this.inject.apply(ctor, arguments) : ctor;
|
||||||
|
@ -253,4 +278,3 @@ var Base = this.Base = new function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue