mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
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:
parent
352b3f0d40
commit
8e25a951bc
2 changed files with 35 additions and 28 deletions
37
lib/bootstrap.js
vendored
37
lib/bootstrap.js
vendored
|
@ -76,7 +76,7 @@ var Base = this.Base = new function() {
|
||||||
&& (val.get ? val : val.value),
|
&& (val.get ? val : val.value),
|
||||||
func = typeof val == 'function', res = val,
|
func = typeof val == 'function', res = val,
|
||||||
prev = preserve || func
|
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])) {
|
if (generics && func && (!preserve || !generics[name])) {
|
||||||
generics[name] = function(bind) {
|
generics[name] = function(bind) {
|
||||||
return bind && dest[name].apply(bind,
|
return bind && dest[name].apply(bind,
|
||||||
|
@ -91,7 +91,7 @@ var Base = this.Base = new function() {
|
||||||
res = function() {
|
res = function() {
|
||||||
var tmp = describe(this, 'base');
|
var tmp = describe(this, 'base');
|
||||||
define(this, 'base', { value: fromBase
|
define(this, 'base', { value: fromBase
|
||||||
? base[name] : prev, configurable: true });
|
? base[name] : prev, configurable: true });
|
||||||
try {
|
try {
|
||||||
return val.apply(this, arguments);
|
return val.apply(this, arguments);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -174,7 +174,7 @@ var Base = this.Base = new function() {
|
||||||
? function(val) { return val }
|
? function(val) { return val }
|
||||||
: typeof iter != 'function'
|
: typeof iter != 'function'
|
||||||
? function(val) { return val == iter }
|
? function(val) { return val == iter }
|
||||||
: iter;
|
: iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clone(obj) {
|
function clone(obj) {
|
||||||
|
@ -188,10 +188,12 @@ var Base = this.Base = new function() {
|
||||||
inject: function(src) {
|
inject: function(src) {
|
||||||
if (src) {
|
if (src) {
|
||||||
var proto = this.prototype,
|
var proto = this.prototype,
|
||||||
base = proto.__proto__ && proto.__proto__.constructor;
|
base = proto.__proto__ && proto.__proto__.constructor,
|
||||||
inject(proto, src, src.enumerable, base && base.prototype,
|
statics = src.statics == true ? src : src.statics;
|
||||||
src.preserve, src.generics && this);
|
if (statics != src)
|
||||||
inject(this, src.statics, true, base, src.preserve);
|
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++)
|
for (var i = 1, l = arguments.length; i < l; i++)
|
||||||
this.inject(arguments[i]);
|
this.inject(arguments[i]);
|
||||||
|
@ -257,27 +259,6 @@ var Base = this.Base = new function() {
|
||||||
return null;
|
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: {}
|
stop: {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
26
src/paper.js
26
src/paper.js
|
@ -12,6 +12,32 @@ this.install = function(scope) {
|
||||||
// Inline Base core inside the paper scope first:
|
// Inline Base core inside the paper scope first:
|
||||||
//#include "../lib/bootstrap.js"
|
//#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/Point.js"
|
||||||
//#include "basic/Size.js"
|
//#include "basic/Size.js"
|
||||||
//#include "basic/Rectangle.js"
|
//#include "basic/Rectangle.js"
|
||||||
|
|
Loading…
Reference in a new issue