-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UMD wrapper for AMD, node and browser globals.
- Loading branch information
Showing
3 changed files
with
2,133 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,36 +4,38 @@ | |
// For all details and documentation: | ||
// http://documentcloud.github.com/backbone | ||
|
||
(function(){ | ||
(function(root, factory) { | ||
// Set up Backbone appropriately for the environment. | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD | ||
define(['underscore', 'jquery', 'exports'], function(_, $, exports) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
// Export global even in AMD case in case this script is loaded with | ||
// others that may still expect a global Backbone. | ||
root.Backbone = factory(root, exports, _, $); | ||
}); | ||
} else if (typeof exports !== 'undefined') { | ||
// Node/CommonJS, no need for jQuery in that case. | ||
factory(root, exports, require('underscore')); | ||
} else { | ||
// Browser globals | ||
// For Backbone's purposes, jQuery, Zepto, or Ender owns the `$` variable. | ||
root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$)); | ||
} | ||
}(this, function(root, Backbone, _, $) { | ||
|
||
// Initial Setup | ||
// ------------- | ||
|
||
// Save a reference to the global object. | ||
var root = this; | ||
|
||
// Save the previous value of the `Backbone` variable. | ||
var previousBackbone = root.Backbone; | ||
|
||
// The top-level namespace. All public Backbone classes and modules will | ||
// be attached to this. Exported for both CommonJS and the browser. | ||
var Backbone; | ||
if (typeof exports !== 'undefined') { | ||
Backbone = exports; | ||
} else { | ||
Backbone = root.Backbone = {}; | ||
} | ||
|
||
// Current version of the library. Keep in sync with `package.json`. | ||
Backbone.VERSION = '0.5.3'; | ||
|
||
// Require Underscore, if we're on the server, and it's not already present. | ||
var _ = root._; | ||
if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._; | ||
This comment has been minimized.
Sorry, something went wrong.
juhovh
|
||
|
||
// For Backbone's purposes, jQuery, Zepto, or Ender owns the `$` variable. | ||
var $ = root.jQuery || root.Zepto || root.ender; | ||
|
||
// Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable | ||
// to its previous owner. Returns a reference to this Backbone object. | ||
Backbone.noConflict = function() { | ||
|
@@ -1161,4 +1163,5 @@ | |
return string.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/'); | ||
}; | ||
|
||
}).call(this); | ||
return Backbone; | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>Backbone Test Suite</title> | ||
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" /> | ||
<script type="text/javascript" src="vendor/json2.js"></script> | ||
<script type="text/javascript" src="vendor/qunit.js"></script> | ||
<script type="text/javascript" src="vendor/jslitmus.js"></script> | ||
<script type="text/javascript" src="vendor/require.js"></script> | ||
<script> | ||
// Tests are loaded async, so wait for them | ||
// to load before starting. | ||
QUnit.config.autostart = false; | ||
|
||
require.config({ | ||
paths: { | ||
'jquery': 'vendor/jquery-1.5', | ||
'underscore': 'vendor/underscore-1.1.6', | ||
'backbone': '../backbone' | ||
}, | ||
// jQuery/underscore are old, so shim. | ||
shim: { | ||
jquery: { | ||
exports: 'jQuery' | ||
}, | ||
underscore: { | ||
exports: '_' | ||
} | ||
} | ||
}); | ||
|
||
var root = this; | ||
|
||
require(['backbone'], function(Backbone) { | ||
require([ | ||
'noconflict', | ||
'events', | ||
'model', | ||
'collection', | ||
'router', | ||
'view', | ||
'sync', | ||
'speed', | ||
], function() { | ||
QUnit.start(); | ||
}); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<h1 id="qunit-header">Backbone Test Suite</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
<br /><br /> | ||
<h1 id="qunit-header"><a href="#">Backbone Speed Suite</a></h1> | ||
<div id="jslitmus_container" style="margin: 20px 10px;"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.
What is the 'exports' dependency used for? Why wouldn't a simple {} as in the browser global work?