From 20a6e70f7f1a655e2de363c514156836c5dab956 Mon Sep 17 00:00:00 2001 From: Peter Marton Date: Wed, 13 Aug 2014 16:21:24 +0200 Subject: [PATCH 1/2] Use random hash for http callbacks --- src/ng/httpBackend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 965a960a0e65..1900820b6465 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -46,7 +46,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc url = url || $browser.url(); if (lowercase(method) == 'jsonp') { - var callbackId = '_' + (callbacks.counter++).toString(36); + var callbackId = '_' + Math.random().toString(36).substring(7); callbacks[callbackId] = function(data) { callbacks[callbackId].data = data; callbacks[callbackId].called = true; From 21e57fad49c2987c645c3257338c42ef3673c8d2 Mon Sep 17 00:00:00 2001 From: Peter Marton Date: Wed, 13 Aug 2014 16:29:45 +0200 Subject: [PATCH 2/2] Add noConflict to the public API --- src/Angular.js | 26 +++++++++++++++++++++++++- src/AngularPublic.js | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Angular.js b/src/Angular.js index 9d047ae04643..773f04ec2cf7 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -165,7 +165,8 @@ var /** holds major version number for IE or NaN for real browsers */ ngMinErr = minErr('ng'), /** @name angular */ - angular = window.angular || (window.angular = {}), + _angular = window.angular, + angular = window.angular = {}, angularModule, nodeName_, uid = ['0', '0', '0']; @@ -1494,3 +1495,26 @@ function getBlockElements(nodes) { return jqLite(elements); } + + +/** + @ngdoc function + * @name angular.noConflict + * @function + * + * @description + * Restores the previous global value of angular and returns the current instance. Other libraries may already use the + * angular namespace. Or a previous version of angular is already loaded on the page. In these cases you may want to + * restore the previous namespace and keep a reference to angular. + * + * @return {Object} The current angular namespace + */ +function noConflict() { + var a = window.angular; + + if(_angular) { + window.angular = _angular; + } + + return a; +} diff --git a/src/AngularPublic.js b/src/AngularPublic.js index 5160b28c2468..f07ef7f35d9e 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -128,7 +128,8 @@ function publishExternalAPI(angular){ 'uppercase': uppercase, 'callbacks': {counter: 0}, '$$minErr': minErr, - '$$csp': csp + '$$csp': csp, + 'noConflict': noConflict }); angularModule = setupModuleLoader(window);