Move Base.capitalize() and Base.read() out of Bootstrap core into Paper.js, so normal Bootstrap libs can work with it too.

This commit is contained in:
Jürg Lehni 2011-03-05 14:17:17 +00:00
parent 352b3f0d40
commit 8e25a951bc
2 changed files with 35 additions and 28 deletions

37
lib/bootstrap.js vendored
View file

@ -76,7 +76,7 @@ var Base = this.Base = new function() {
&& (val.get ? val : val.value),
func = typeof val == 'function', res = val,
prev = preserve || func
? (val && val.get ? name in dest : dest[name]) : null;
? (val && val.get ? name in dest : dest[name]) : null;
if (generics && func && (!preserve || !generics[name])) {
generics[name] = function(bind) {
return bind && dest[name].apply(bind,
@ -91,7 +91,7 @@ var Base = this.Base = new function() {
res = function() {
var tmp = describe(this, 'base');
define(this, 'base', { value: fromBase
? base[name] : prev, configurable: true });
? base[name] : prev, configurable: true });
try {
return val.apply(this, arguments);
} finally {
@ -174,7 +174,7 @@ var Base = this.Base = new function() {
? function(val) { return val }
: typeof iter != 'function'
? function(val) { return val == iter }
: iter;
: iter;
}
function clone(obj) {
@ -188,10 +188,12 @@ var Base = this.Base = new function() {
inject: function(src) {
if (src) {
var proto = this.prototype,
base = proto.__proto__ && proto.__proto__.constructor;
inject(proto, src, src.enumerable, base && base.prototype,
src.preserve, src.generics && this);
inject(this, src.statics, true, base, src.preserve);
base = proto.__proto__ && proto.__proto__.constructor,
statics = src.statics == true ? src : src.statics;
if (statics != src)
inject(proto, src, src.enumerable, base && base.prototype,
src.preserve, src.generics && this);
inject(this, statics, true, base, src.preserve);
}
for (var i = 1, l = arguments.length; i < l; i++)
this.inject(arguments[i]);
@ -257,27 +259,6 @@ var Base = this.Base = new function() {
return null;
},
read: function(args, index, length) {
var index = index || 0, length = length || args.length - index;
if (length <= 1) {
var arg = args[index];
// Return null when nothing was provided
if (arg instanceof this || arg == null)
return arg;
}
var obj = new this(this.dont);
obj = obj.initialize.apply(obj, index > 0 || length < args.length
? slice.call(args, index, index + length)
: args) || obj;
return obj;
},
capitalize: function(str) {
return str.replace(/\b[a-z]/g, function(match) {
return match.toUpperCase();
});
},
stop: {}
}
});

View file

@ -12,6 +12,32 @@ this.install = function(scope) {
// Inline Base core inside the paper scope first:
//#include "../lib/bootstrap.js"
Base.inject({
statics: {
read: function(args, index, length) {
var index = index || 0, length = length || args.length - index;
if (length <= 1) {
var arg = args[index];
// Return null when nothing was provided
if (arg instanceof this || arg == null)
return arg;
}
var obj = new this(this.dont);
obj = obj.initialize.apply(obj, index > 0 || length < args.length
? slice.call(args, index, index + length)
: args) || obj;
return obj;
},
capitalize: function(str) {
return str.replace(/\b[a-z]/g, function(match) {
return match.toUpperCase();
});
}
}
});
//#include "basic/Point.js"
//#include "basic/Size.js"
//#include "basic/Rectangle.js"