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

27
lib/bootstrap.js vendored
View file

@ -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;
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, src.statics, true, base, src.preserve);
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"