diff options
| author | Caitlin Potter | 2014-02-15 20:19:10 -0500 |
|---|---|---|
| committer | Peter Bacon Darwin | 2014-02-16 19:03:45 +0000 |
| commit | f7fad29fd99cabdbb17fa02dc214de2354f93cdf (patch) | |
| tree | 61fc2299fe732d189f85b0afe84e70667bf9fd13 /docs/content/guide/dev_guide.services.$location.ngdoc | |
| parent | 896e34689dfe0d66c09627179940a7b3eaac41bc (diff) | |
| download | angular.js-f7fad29fd99cabdbb17fa02dc214de2354f93cdf.tar.bz2 | |
docs(bike-shed-migration): convert guide <doc:...> examples to <example>...
This CL also contains style fixes as the converted scripts caused jshint to complain.
Diffstat (limited to 'docs/content/guide/dev_guide.services.$location.ngdoc')
| -rw-r--r-- | docs/content/guide/dev_guide.services.$location.ngdoc | 212 |
1 files changed, 104 insertions, 108 deletions
diff --git a/docs/content/guide/dev_guide.services.$location.ngdoc b/docs/content/guide/dev_guide.services.$location.ngdoc index b3abd377..1d2b0e82 100644 --- a/docs/content/guide/dev_guide.services.$location.ngdoc +++ b/docs/content/guide/dev_guide.services.$location.ngdoc @@ -387,120 +387,116 @@ redirect to regular / hashbang url, as this conversion happens only during parsi = on page reload. In this examples we use `<base href="/base/index.html" />` -<doc:example> -<doc:source source="false"> - -<div ng-non-bindable class="html5-hashbang-example"> - <div id="html5-mode" ng-controller="Html5Cntl"> - <h3>Browser with History API</h3> - <div ng-address-bar browser="html5"></div><br><br> - $location.protocol() = {{$location.protocol()}}<br> - $location.host() = {{$location.host()}}<br> - $location.port() = {{$location.port()}}<br> - $location.path() = {{$location.path()}}<br> - $location.search() = {{$location.search()}}<br> - $location.hash() = {{$location.hash()}}<br> - <a href="http://www.example.com/base/first?a=b">/base/first?a=b</a> | - <a href="http://www.example.com/base/sec/ond?flag#hash">sec/ond?flag#hash</a> | - <a href="/other-base/another?search">external</a> - </div> - - <div id="hashbang-mode" ng-controller="HashbangCntl"> - <h3>Browser without History API</h3> - <div ng-address-bar browser="hashbang"></div><br><br> - $location.protocol() = {{$location.protocol()}}<br> - $location.host() = {{$location.host()}}<br> - $location.port() = {{$location.port()}}<br> - $location.path() = {{$location.path()}}<br> - $location.search() = {{$location.search()}}<br> - $location.hash() = {{$location.hash()}}<br> - <a href="http://www.example.com/base/first?a=b">/base/first?a=b</a> | - <a href="http://www.example.com/base/sec/ond?flag#hash">sec/ond?flag#hash</a> | - <a href="/other-base/another?search">external</a> - </div> -</div> - -<script> - function FakeBrowser(initUrl, baseHref) { - this.onUrlChange = function(fn) { - this.urlChange = fn; - }; - - this.url = function() { - return initUrl; - }; - - this.defer = function(fn, delay) { - setTimeout(function() { fn(); }, delay || 0); - }; - - this.baseHref = function() { - return baseHref; +<example> + <file name="index.html"> + <div id="html5-mode" ng-controller="Html5Cntl"> + <h3>Browser with History API</h3> + <div ng-address-bar browser="html5"></div><br><br> + $location.protocol() = {{$location.protocol()}}<br> + $location.host() = {{$location.host()}}<br> + $location.port() = {{$location.port()}}<br> + $location.path() = {{$location.path()}}<br> + $location.search() = {{$location.search()}}<br> + $location.hash() = {{$location.hash()}}<br> + <a href="http://www.example.com/base/first?a=b">/base/first?a=b</a> | + <a href="http://www.example.com/base/sec/ond?flag#hash">sec/ond?flag#hash</a> | + <a href="/other-base/another?search">external</a> + </div> + + <div id="hashbang-mode" ng-controller="HashbangCntl"> + <h3>Browser without History API</h3> + <div ng-address-bar browser="hashbang"></div><br><br> + $location.protocol() = {{$location.protocol()}}<br> + $location.host() = {{$location.host()}}<br> + $location.port() = {{$location.port()}}<br> + $location.path() = {{$location.path()}}<br> + $location.search() = {{$location.search()}}<br> + $location.hash() = {{$location.hash()}}<br> + <a href="http://www.example.com/base/first?a=b">/base/first?a=b</a> | + <a href="http://www.example.com/base/sec/ond?flag#hash">sec/ond?flag#hash</a> | + <a href="/other-base/another?search">external</a> + </div> + </file> + + <file name="script.js"> + function FakeBrowser(initUrl, baseHref) { + this.onUrlChange = function(fn) { + this.urlChange = fn; + }; + + this.url = function() { + return initUrl; + }; + + this.defer = function(fn, delay) { + setTimeout(function() { fn(); }, delay || 0); + }; + + this.baseHref = function() { + return baseHref; + }; + + this.notifyWhenOutstandingRequests = angular.noop; + } + + var browsers = { + html5: new FakeBrowser('http://www.example.com/base/path?a=b#h', '/base/index.html'), + hashbang: new FakeBrowser('http://www.example.com/base/index.html#!/path?a=b#h', '/base/index.html') }; - this.notifyWhenOutstandingRequests = angular.noop; - } - - var browsers = { - html5: new FakeBrowser('http://www.example.com/base/path?a=b#h', '/base/index.html'), - hashbang: new FakeBrowser('http://www.example.com/base/index.html#!/path?a=b#h', '/base/index.html') - }; - - function Html5Cntl($scope, $location) { - $scope.$location = $location; - } - - function HashbangCntl($scope, $location) { - $scope.$location = $location; - } - - function initEnv(name) { - var root = angular.element(document.getElementById(name + '-mode')); - // We must kill a link to the injector for this element otherwise angular will - // complain that it has been bootstrapped already. - root.data('$injector', null); - angular.bootstrap(root, [function($compileProvider, $locationProvider, $provide){ - $locationProvider.html5Mode(true).hashPrefix('!'); - - $provide.value('$browser', browsers[name]); - $provide.value('$sniffer', {history: name == 'html5'}); - - $compileProvider.directive('ngAddressBar', function() { - return function(scope, elm, attrs) { - var browser = browsers[attrs.browser], - input = angular.element('<input type="text" style="width: 400px">').val(browser.url()), - delay; - - input.on('keypress keyup keydown', function() { - if (!delay) { - delay = setTimeout(fireUrlChange, 250); + function Html5Cntl($scope, $location) { + $scope.$location = $location; + } + + function HashbangCntl($scope, $location) { + $scope.$location = $location; + } + + function initEnv(name) { + var root = angular.element(document.getElementById(name + '-mode')); + // We must kill a link to the injector for this element otherwise angular will + // complain that it has been bootstrapped already. + root.data('$injector', null); + angular.bootstrap(root, [function($compileProvider, $locationProvider, $provide){ + $locationProvider.html5Mode(true).hashPrefix('!'); + + $provide.value('$browser', browsers[name]); + $provide.value('$sniffer', {history: name == 'html5'}); + + $compileProvider.directive('ngAddressBar', function() { + return function(scope, elm, attrs) { + var browser = browsers[attrs.browser], + input = angular.element('<input type="text" style="width: 400px">').val(browser.url()), + delay; + + input.on('keypress keyup keydown', function() { + if (!delay) { + delay = setTimeout(fireUrlChange, 250); + } + }); + + browser.url = function(url) { + return input.val(url); + }; + + elm.append('Address: ').append(input); + + function fireUrlChange() { + delay = null; + browser.urlChange(input.val()); } - }); - - browser.url = function(url) { - return input.val(url); }; - - elm.append('Address: ').append(input); - - function fireUrlChange() { - delay = null; - browser.urlChange(input.val()); - } - }; + }); + }]); + root.on('click', function(e) { + e.stopPropagation(); }); - }]); - root.on('click', function(e) { - e.stopPropagation(); - }); - } + } - initEnv('html5'); - initEnv('hashbang'); -</script> - -</doc:source> -</doc:example> + initEnv('html5'); + initEnv('hashbang'); + </file> +</example> # Caveats |
