Universal module pattern (for browserify support)
This commit is contained in:
parent
4480a8e3ff
commit
6716fab883
50
springy.js
50
springy.js
|
@ -24,22 +24,24 @@
|
|||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['b'], function (b) {
|
||||
return (root.returnExportsGlobal = factory());
|
||||
});
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node. Does not work with strict CommonJS, but
|
||||
// only CommonJS-like enviroments that support module.exports,
|
||||
// like Node.
|
||||
module.exports = factory();
|
||||
} else {
|
||||
// Browser globals
|
||||
root.Springy = factory();
|
||||
}
|
||||
}(this, function() {
|
||||
|
||||
(function() {
|
||||
// Enable strict mode for EC5 compatible browsers
|
||||
"use strict";
|
||||
|
||||
// Establish the root object, `window` in the browser, or `global` on the server.
|
||||
var root = this;
|
||||
|
||||
// The top-level namespace. All public Springy classes and modules will
|
||||
// be attached to this. Exported for both CommonJS and the browser.
|
||||
var Springy;
|
||||
if (typeof exports !== 'undefined') {
|
||||
Springy = exports;
|
||||
} else {
|
||||
Springy = root.Springy = {};
|
||||
}
|
||||
var Springy = {};
|
||||
|
||||
var Graph = Springy.Graph = function() {
|
||||
this.nodeSet = {};
|
||||
|
@ -474,14 +476,14 @@
|
|||
|
||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; // stolen from coffeescript, thanks jashkenas! ;-)
|
||||
|
||||
Springy.requestAnimationFrame = __bind(root.requestAnimationFrame ||
|
||||
root.webkitRequestAnimationFrame ||
|
||||
root.mozRequestAnimationFrame ||
|
||||
root.oRequestAnimationFrame ||
|
||||
root.msRequestAnimationFrame ||
|
||||
Springy.requestAnimationFrame = __bind(this.requestAnimationFrame ||
|
||||
this.webkitRequestAnimationFrame ||
|
||||
this.mozRequestAnimationFrame ||
|
||||
this.oRequestAnimationFrame ||
|
||||
this.msRequestAnimationFrame ||
|
||||
(function(callback, element) {
|
||||
root.setTimeout(callback, 10);
|
||||
}), root);
|
||||
this.setTimeout(callback, 10);
|
||||
}), this);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -720,4 +722,6 @@
|
|||
}
|
||||
return true;
|
||||
};
|
||||
}).call(this);
|
||||
|
||||
return Springy;
|
||||
}));
|
||||
|
|
Loading…
Reference in New Issue
Block a user