mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-27 09:54:46 +00:00
fix(docs): update docs to reflect new $location and fix e2e tests
This commit is contained in:
parent
22cb600280
commit
4421f3d435
5 changed files with 34 additions and 26 deletions
|
|
@ -43,7 +43,7 @@ The two partials are defined in the following URLs:
|
|||
AppCntl.$inject = ['$route']
|
||||
function AppCntl($route) {
|
||||
// define routes
|
||||
$route.when("", {template:'./examples/welcome.html', controller:WelcomeCntl});
|
||||
$route.when("/welcome", {template:'./examples/welcome.html', controller:WelcomeCntl});
|
||||
$route.when("/settings", {template:'./examples/settings.html', controller:SettingsCntl});
|
||||
$route.parent(this);
|
||||
|
||||
|
|
@ -61,7 +61,9 @@ The two partials are defined in the following URLs:
|
|||
}
|
||||
};
|
||||
|
||||
function SettingsCntl(){
|
||||
SettingsCntl.$inject = ['$location'];
|
||||
function SettingsCntl($location){
|
||||
this.$location = $location;
|
||||
this.cancel();
|
||||
}
|
||||
SettingsCntl.prototype = {
|
||||
|
|
@ -71,13 +73,13 @@ The two partials are defined in the following URLs:
|
|||
|
||||
save: function(){
|
||||
angular.copy(this.form, this.person);
|
||||
window.location.hash = "#";
|
||||
this.$location.path('/welcome');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<div ng:controller="AppCntl">
|
||||
<h1>Your App Chrome</h1>
|
||||
[ <a href="#">Welcome</a> | <a href="#/settings">Settings</a> ]
|
||||
[ <a href="#!/welcome">Welcome</a> | <a href="#!/settings">Settings</a> ]
|
||||
<hr/>
|
||||
<span style="background-color: blue; color: white; padding: 3px;">
|
||||
Partial: {{$route.current.template}}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ no connection between the controller and the view.
|
|||
'cursor': 'pointer'
|
||||
};
|
||||
this.reset();
|
||||
this.$watch('$location.hashSearch.board', this.readUrl);
|
||||
this.$watch('$location.search().board', this.readUrl);
|
||||
}
|
||||
TicTacToeCntl.prototype = {
|
||||
dropPiece: function(row, col) {
|
||||
|
|
@ -62,7 +62,7 @@ no connection between the controller and the view.
|
|||
angular.forEach(this.board, function(row){
|
||||
rows.push(row.join(','));
|
||||
});
|
||||
this.$location.hashSearch.board = rows.join(';') + '/' + this.nextMove;
|
||||
this.$location.search({board: rows.join(';') + '/' + this.nextMove});
|
||||
},
|
||||
readUrl: function(scope, value) {
|
||||
if (value) {
|
||||
|
|
@ -72,8 +72,6 @@ no connection between the controller and the view.
|
|||
this.board[col] = row.split(',');
|
||||
}, this);
|
||||
this.grade();
|
||||
} else {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ function DocsController($location, $browser, $window, $cookies) {
|
|||
|
||||
var self = this,
|
||||
OFFLINE_COOKIE_NAME = 'ng-offline',
|
||||
HAS_HASH = /#/;
|
||||
DOCS_PATH = /^\/(api)|(guide)|(cookbook)|(misc)|(tutorial)/;
|
||||
|
||||
this.$location = $location;
|
||||
|
||||
|
|
@ -13,13 +13,14 @@ function DocsController($location, $browser, $window, $cookies) {
|
|||
self.subpage = false;
|
||||
self.offlineEnabled = ($cookies[OFFLINE_COOKIE_NAME] == angular.version.full);
|
||||
|
||||
if (!HAS_HASH.test($location.href)) {
|
||||
$location.hashPath = '!/api';
|
||||
if (!$location.path()) {
|
||||
$location.path('/api').replace();
|
||||
}
|
||||
|
||||
this.$watch('$location.hashPath', function(scope, hashPath) {
|
||||
if (hashPath.match(/^!/)) {
|
||||
var parts = hashPath.substring(1).split('/');
|
||||
this.$watch('$location.path()', function(scope, path) {
|
||||
// ignore non-doc links which are used in examples
|
||||
if (DOCS_PATH.test(path)) {
|
||||
var parts = path.split('/');
|
||||
self.sectionId = parts[1];
|
||||
self.partialId = parts[2] || 'index';
|
||||
self.pages = angular.Array.filter(NG_PAGES, {section:self.sectionId});
|
||||
|
|
@ -67,13 +68,13 @@ function DocsController($location, $browser, $window, $cookies) {
|
|||
this.afterPartialLoaded = function() {
|
||||
SyntaxHighlighter.highlight();
|
||||
$window.scrollTo(0,0);
|
||||
$window._gaq.push(['_trackPageview', $location.hashPath.substr(1)]);
|
||||
$window._gaq.push(['_trackPageview', $location.path()]);
|
||||
};
|
||||
|
||||
this.getFeedbackUrl = function() {
|
||||
return "mailto:angular@googlegroups.com?" +
|
||||
"subject=" + escape("Feedback on " + $location.href) + "&" +
|
||||
"body=" + escape("Hi there,\n\nI read " + $location.href + " and wanted to ask ....");
|
||||
"subject=" + escape("Feedback on " + $location.absUrl()) + "&" +
|
||||
"body=" + escape("Hi there,\n\nI read " + $location.absUrl() + " and wanted to ask ....");
|
||||
};
|
||||
|
||||
/** stores a cookie that is used by apache to decide which manifest ot send */
|
||||
|
|
@ -123,3 +124,10 @@ function TutorialInstructionsCtrl($cookieStore) {
|
|||
$cookieStore.put('selEnv', id);
|
||||
};
|
||||
}
|
||||
|
||||
angular.service('$locationConfig', function() {
|
||||
return {
|
||||
html5Mode: false,
|
||||
hashPrefix: '!'
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -166,10 +166,10 @@ angularTextMarkup('option', function(text, textNode, parentElement){
|
|||
<input name="value" /><br />
|
||||
<a id="link-1" href ng:click="value = 1">link 1</a> (link, don't reload)<br />
|
||||
<a id="link-2" href="" ng:click="value = 2">link 2</a> (link, don't reload)<br />
|
||||
<a id="link-3" ng:href="#{{'123'}}" ng:click="value = 3">link 3</a> (link, reload!)<br />
|
||||
<a id="link-3" ng:href="#!/{{'123'}}" ng:click="value = 3">link 3</a> (link, reload!)<br />
|
||||
<a id="link-4" href="" name="xx" ng:click="value = 4">anchor</a> (link, don't reload)<br />
|
||||
<a id="link-5" name="xxx" ng:click="value = 5">anchor</a> (no link)<br />
|
||||
<a id="link-6" ng:href="#/{{value}}">link</a> (link, change hash)
|
||||
<a id="link-6" ng:href="#!/{{value}}">link</a> (link, change hash)
|
||||
</doc:source>
|
||||
<doc:scenario>
|
||||
it('should execute ng:click but not reload when href without value', function() {
|
||||
|
|
@ -187,8 +187,8 @@ angularTextMarkup('option', function(text, textNode, parentElement){
|
|||
it('should execute ng:click and change url when ng:href specified', function() {
|
||||
element('#link-3').click();
|
||||
expect(input('value').val()).toEqual('3');
|
||||
expect(element('#link-3').attr('href')).toBe("#123");
|
||||
expect(browser().location().hash()).toEqual('123');
|
||||
expect(element('#link-3').attr('href')).toBe("#!/123");
|
||||
expect(browser().location().hash()).toEqual('!/123');
|
||||
});
|
||||
|
||||
it('should execute ng:click but not reload when href empty string and name specified', function() {
|
||||
|
|
@ -206,8 +206,8 @@ angularTextMarkup('option', function(text, textNode, parentElement){
|
|||
it('should only change url when only ng:href', function() {
|
||||
input('value').enter('6');
|
||||
element('#link-6').click();
|
||||
expect(browser().location().hash()).toEqual('/6');
|
||||
expect(element('#link-6').attr('href')).toBe("#/6");
|
||||
expect(browser().location().hash()).toEqual('!/6');
|
||||
expect(element('#link-6').attr('href')).toBe("#!/6");
|
||||
});
|
||||
</doc:scenario>
|
||||
</doc:example>
|
||||
|
|
|
|||
|
|
@ -1391,9 +1391,9 @@ angularWidget("@ng:non-bindable", noop);
|
|||
function OverviewCtrl(){}
|
||||
</script>
|
||||
<div ng:controller="MyCtrl">
|
||||
<a href="#/overview">overview</a> |
|
||||
<a href="#/bootstrap">bootstrap</a> |
|
||||
<a href="#/undefined">undefined</a>
|
||||
<a href="#!/overview">overview</a> |
|
||||
<a href="#!/bootstrap">bootstrap</a> |
|
||||
<a href="#!/undefined">undefined</a>
|
||||
|
||||
<br/>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue