Skip to content

Commit

Permalink
Merge pull request kriskowal#690 from kriskowal/firefox-add-on-script
Browse files Browse the repository at this point in the history
Favor window global over self global
  • Loading branch information
kriskowal committed May 17, 2015
2 parents 05e20dc + 22bd310 commit 86ce801
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@
}

// <script>
} else if (typeof self !== "undefined") {
} else if (typeof window !== "undefined" || typeof self !== "undefined") {
// Prefer window over self for add-on scripts. Use self for
// non-windowed contexts.
var global = typeof window !== "undefined" ? window : self;

// Get the `window` object, save the previous Q global
// and initialize Q as a global.
var previousQ = self.Q;
self.Q = definition();
var previousQ = global.Q;
global.Q = definition();

// Add a noConflict function so Q can be removed from the
// global namespace.
self.Q.noConflict = function () {
self.Q = previousQ;
global.Q.noConflict = function () {
global.Q = previousQ;
return this;
};

Expand Down

0 comments on commit 86ce801

Please sign in to comment.