Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8aa18f0

Browse files
committed
chore($location) switch to use $rootElement
1 parent 85632cb commit 8aa18f0

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/ng/location.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ function locationGetterSetter(property, preprocess) {
405405
*
406406
* @requires $browser
407407
* @requires $sniffer
408-
* @requires $document
408+
* @requires $rootElement
409409
*
410410
* @description
411411
* The $location service parses the URL in the browser address bar (based on the {@link https://developer.mozilla.org/en/window.location window.location}) and makes the URL available to your application. Changes to the URL in the address bar are reflected into $location service and changes to $location are reflected into the browser address bar.
@@ -468,8 +468,8 @@ function $LocationProvider(){
468468
}
469469
};
470470

471-
this.$get = ['$rootScope', '$browser', '$sniffer', '$document',
472-
function( $rootScope, $browser, $sniffer, $document) {
471+
this.$get = ['$rootScope', '$browser', '$sniffer', '$rootElement',
472+
function( $rootScope, $browser, $sniffer, $rootElement) {
473473
var currentUrl,
474474
basePath = $browser.baseHref() || '/',
475475
pathPrefix = pathPrefixFromBase(basePath),
@@ -487,7 +487,7 @@ function $LocationProvider(){
487487
var u = currentUrl,
488488
absUrlPrefix = composeProtocolHostPort(u.protocol(), u.host(), u.port()) + pathPrefix;
489489

490-
$document.bind('click', function(event) {
490+
$rootElement.bind('click', function(event) {
491491
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
492492
// currently we open nice url link and redirect then
493493

src/ng/rootElement.js

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
* location where the applications {@link angular.module.AUTO.$injector $injector} service gets
1212
* published, it can be retrieved using `$rootElement.injector()`.
1313
*/
14+
15+
16+
// the implementation is in angular.bootstrap

test/ng/locationSpec.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ describe('$location', function() {
498498
// html5 history enabled, but not supported by browser
499499
describe('history on old browser', function() {
500500

501-
afterEach(inject(function($document){
502-
dealoc($document);
501+
afterEach(inject(function($rootElement){
502+
dealoc($rootElement);
503503
}));
504504

505505
it('should use hashbang url with hash prefix', function() {
@@ -532,8 +532,8 @@ describe('$location', function() {
532532
// html5 history enabled and supported by browser
533533
describe('history on new browser', function() {
534534

535-
afterEach(inject(function($document){
536-
dealoc($document);
535+
afterEach(inject(function($rootElement){
536+
dealoc($rootElement);
537537
}));
538538

539539
it('should use new url', function() {
@@ -681,7 +681,6 @@ describe('$location', function() {
681681

682682
function configureService(linkHref, html5Mode, supportHist, attrs, content) {
683683
module(function($provide, $locationProvider) {
684-
var jqRoot = jqLite('<div></div>');
685684
attrs = attrs ? ' ' + attrs + ' ' : '';
686685

687686
// fake the base behavior
@@ -692,14 +691,16 @@ describe('$location', function() {
692691
}
693692

694693
link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0];
695-
root = jqRoot.append(link)[0];
696694

697-
jqLite(document.body).append(jqRoot);
698-
699-
$provide.value('$document', jqRoot);
700695
$provide.value('$sniffer', {history: supportHist});
701696
$locationProvider.html5Mode(html5Mode);
702697
$locationProvider.hashPrefix('!');
698+
return function($rootElement, $document) {
699+
$rootElement.append(link);
700+
root = $rootElement[0];
701+
// we need to do this otherwise we can't simulate events
702+
$document.find('body').append($rootElement);
703+
};
703704
});
704705
}
705706

@@ -711,11 +712,11 @@ describe('$location', function() {
711712
}
712713

713714
function initLocation() {
714-
return function($browser, $location, $document) {
715+
return function($browser, $location, $rootElement) {
715716
originalBrowser = $browser.url();
716717
// we have to prevent the default operation, as we need to test absolute links (http://...)
717718
// and navigating to these links would kill jstd
718-
$document.bind('click', function(e) {
719+
$rootElement.bind('click', function(e) {
719720
lastEventPreventDefault = e.isDefaultPrevented();
720721
e.preventDefault();
721722
});

0 commit comments

Comments
 (0)