[Pkg-javascript-commits] [backbone] 101/211: Adding Backbone.noConflict() and keeping track of the original root.Backbone.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:00:09 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.5.0
in repository backbone.
commit 67d61fc355b00fcbd402ca551799138441dcf764
Author: Samuel Clay <samuel at ofbrooklyn.com>
Date: Wed Mar 23 14:08:37 2011 -0400
Adding Backbone.noConflict() and keeping track of the original root.Backbone.
---
backbone.js | 19 ++++++++++++++++---
test/noconflict.js | 12 ++++++++++++
test/test.html | 1 +
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/backbone.js b/backbone.js
index e0c5fed..ed88feb 100644
--- a/backbone.js
+++ b/backbone.js
@@ -9,25 +9,38 @@
// 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 = this.Backbone = {};
+ Backbone = root.Backbone = {};
}
// Current version of the library. Keep in sync with `package.json`.
Backbone.VERSION = '0.3.3';
// Require Underscore, if we're on the server, and it's not already present.
- var _ = this._;
+ var _ = root._;
if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._;
// For Backbone's purposes, either jQuery or Zepto owns the `$` variable.
- var $ = this.jQuery || this.Zepto;
+ var $ = root.jQuery || root.Zepto;
+ // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
+ // to its previous owner. Returns a reference to this Backbone object.
+ Backbone.noConflict = function() {
+ root.Backbone = previousBackbone;
+ return this;
+ };
+
// Turn on `emulateHTTP` to use support legacy HTTP servers. Setting this option will
// fake `"PUT"` and `"DELETE"` requests via the `_method` parameter and set a
// `X-Http-Method-Override` header.
diff --git a/test/noconflict.js b/test/noconflict.js
new file mode 100644
index 0000000..6122f97
--- /dev/null
+++ b/test/noconflict.js
@@ -0,0 +1,12 @@
+$(document).ready(function() {
+
+ module("Backbone.noConflict");
+
+ test('Backbone.noConflict', function() {
+ var noconflictBackbone = Backbone.noConflict();
+ equals(window.Backbone, undefined, 'Returned window.Backbone');
+ window.Backbone = noconflictBackbone;
+ equals(window.Backbone, noconflictBackbone, 'Backbone is still pointing to the original Backbone');
+ });
+
+});
\ No newline at end of file
diff --git a/test/test.html b/test/test.html
index d350ad2..46dbad0 100644
--- a/test/test.html
+++ b/test/test.html
@@ -10,6 +10,7 @@
<script type="text/javascript" src="vendor/underscore-1.1.5.js"></script>
<script type="text/javascript" src="../backbone.js"></script>
+ <script type="text/javascript" src="noconflict.js"></script>
<script type="text/javascript" src="events.js"></script>
<script type="text/javascript" src="model.js"></script>
<script type="text/javascript" src="collection.js"></script>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list