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

Commit

Permalink
chore($location) switch to use $rootElement
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Jun 2, 2012
1 parent 85632cb commit 8aa18f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ function locationGetterSetter(property, preprocess) {
*
* @requires $browser
* @requires $sniffer
* @requires $document
* @requires $rootElement
*
* @description
* 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.
Expand Down Expand Up @@ -468,8 +468,8 @@ function $LocationProvider(){
}
};

this.$get = ['$rootScope', '$browser', '$sniffer', '$document',
function( $rootScope, $browser, $sniffer, $document) {
this.$get = ['$rootScope', '$browser', '$sniffer', '$rootElement',
function( $rootScope, $browser, $sniffer, $rootElement) {
var currentUrl,
basePath = $browser.baseHref() || '/',
pathPrefix = pathPrefixFromBase(basePath),
Expand All @@ -487,7 +487,7 @@ function $LocationProvider(){
var u = currentUrl,
absUrlPrefix = composeProtocolHostPort(u.protocol(), u.host(), u.port()) + pathPrefix;

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

Expand Down
3 changes: 3 additions & 0 deletions src/ng/rootElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
* location where the applications {@link angular.module.AUTO.$injector $injector} service gets
* published, it can be retrieved using `$rootElement.injector()`.
*/


// the implementation is in angular.bootstrap
23 changes: 12 additions & 11 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ describe('$location', function() {
// html5 history enabled, but not supported by browser
describe('history on old browser', function() {

afterEach(inject(function($document){
dealoc($document);
afterEach(inject(function($rootElement){
dealoc($rootElement);
}));

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

afterEach(inject(function($document){
dealoc($document);
afterEach(inject(function($rootElement){
dealoc($rootElement);
}));

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

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

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

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

jqLite(document.body).append(jqRoot);

$provide.value('$document', jqRoot);
$provide.value('$sniffer', {history: supportHist});
$locationProvider.html5Mode(html5Mode);
$locationProvider.hashPrefix('!');
return function($rootElement, $document) {
$rootElement.append(link);
root = $rootElement[0];
// we need to do this otherwise we can't simulate events
$document.find('body').append($rootElement);
};
});
}

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

function initLocation() {
return function($browser, $location, $document) {
return function($browser, $location, $rootElement) {
originalBrowser = $browser.url();
// we have to prevent the default operation, as we need to test absolute links (http://...)
// and navigating to these links would kill jstd
$document.bind('click', function(e) {
$rootElement.bind('click', function(e) {
lastEventPreventDefault = e.isDefaultPrevented();
e.preventDefault();
});
Expand Down

0 comments on commit 8aa18f0

Please sign in to comment.