@@ -387,120 +387,116 @@ redirect to regular / hashbang url, as this conversion happens only during parsi
387387= on page reload.
388388
389389In this examples we use `<base href="/base/index.html" />`
390- <doc:example>
391- <doc:source source="false">
392-
393- <div ng-non-bindable class="html5-hashbang-example">
394- <div id="html5-mode" ng-controller="Html5Cntl">
395- <h3>Browser with History API</h3>
396- <div ng-address-bar browser="html5"></div><br><br>
397- $location.protocol() = {{$location.protocol()}}<br>
398- $location.host() = {{$location.host()}}<br>
399- $location.port() = {{$location.port()}}<br>
400- $location.path() = {{$location.path()}}<br>
401- $location.search() = {{$location.search()}}<br>
402- $location.hash() = {{$location.hash()}}<br>
403- <a href="http://www.example.com/base/first?a=b">/base/first?a=b</a> |
404- <a href="http://www.example.com/base/sec/ond?flag#hash">sec/ond?flag#hash</a> |
405- <a href="/other-base/another?search">external</a>
406- </div>
407-
408- <div id="hashbang-mode" ng-controller="HashbangCntl">
409- <h3>Browser without History API</h3>
410- <div ng-address-bar browser="hashbang"></div><br><br>
411- $location.protocol() = {{$location.protocol()}}<br>
412- $location.host() = {{$location.host()}}<br>
413- $location.port() = {{$location.port()}}<br>
414- $location.path() = {{$location.path()}}<br>
415- $location.search() = {{$location.search()}}<br>
416- $location.hash() = {{$location.hash()}}<br>
417- <a href="http://www.example.com/base/first?a=b">/base/first?a=b</a> |
418- <a href="http://www.example.com/base/sec/ond?flag#hash">sec/ond?flag#hash</a> |
419- <a href="/other-base/another?search">external</a>
420- </div>
421- </div>
422-
423- <script>
424- function FakeBrowser(initUrl, baseHref) {
425- this.onUrlChange = function(fn) {
426- this.urlChange = fn;
427- };
428-
429- this.url = function() {
430- return initUrl;
431- };
432-
433- this.defer = function(fn, delay) {
434- setTimeout(function() { fn(); }, delay || 0);
435- };
436-
437- this.baseHref = function() {
438- return baseHref;
390+ <example>
391+ <file name="index.html">
392+ <div id="html5-mode" ng-controller="Html5Cntl">
393+ <h3>Browser with History API</h3>
394+ <div ng-address-bar browser="html5"></div><br><br>
395+ $location.protocol() = {{$location.protocol()}}<br>
396+ $location.host() = {{$location.host()}}<br>
397+ $location.port() = {{$location.port()}}<br>
398+ $location.path() = {{$location.path()}}<br>
399+ $location.search() = {{$location.search()}}<br>
400+ $location.hash() = {{$location.hash()}}<br>
401+ <a href="http://www.example.com/base/first?a=b">/base/first?a=b</a> |
402+ <a href="http://www.example.com/base/sec/ond?flag#hash">sec/ond?flag#hash</a> |
403+ <a href="/other-base/another?search">external</a>
404+ </div>
405+
406+ <div id="hashbang-mode" ng-controller="HashbangCntl">
407+ <h3>Browser without History API</h3>
408+ <div ng-address-bar browser="hashbang"></div><br><br>
409+ $location.protocol() = {{$location.protocol()}}<br>
410+ $location.host() = {{$location.host()}}<br>
411+ $location.port() = {{$location.port()}}<br>
412+ $location.path() = {{$location.path()}}<br>
413+ $location.search() = {{$location.search()}}<br>
414+ $location.hash() = {{$location.hash()}}<br>
415+ <a href="http://www.example.com/base/first?a=b">/base/first?a=b</a> |
416+ <a href="http://www.example.com/base/sec/ond?flag#hash">sec/ond?flag#hash</a> |
417+ <a href="/other-base/another?search">external</a>
418+ </div>
419+ </file>
420+
421+ <file name="script.js">
422+ function FakeBrowser(initUrl, baseHref) {
423+ this.onUrlChange = function(fn) {
424+ this.urlChange = fn;
425+ };
426+
427+ this.url = function() {
428+ return initUrl;
429+ };
430+
431+ this.defer = function(fn, delay) {
432+ setTimeout(function() { fn(); }, delay || 0);
433+ };
434+
435+ this.baseHref = function() {
436+ return baseHref;
437+ };
438+
439+ this.notifyWhenOutstandingRequests = angular.noop;
440+ }
441+
442+ var browsers = {
443+ html5: new FakeBrowser('http://www.example.com/base/path?a=b#h', '/base/index.html'),
444+ hashbang: new FakeBrowser('http://www.example.com/base/index.html#!/path?a=b#h', '/base/index.html')
439445 };
440446
441- this.notifyWhenOutstandingRequests = angular.noop;
442- }
443-
444- var browsers = {
445- html5: new FakeBrowser('http://www.example.com/base/path?a=b#h', '/base/index.html'),
446- hashbang: new FakeBrowser('http://www.example.com/base/index.html#!/path?a=b#h', '/base/index.html')
447- };
448-
449- function Html5Cntl($scope, $location) {
450- $scope.$location = $location;
451- }
452-
453- function HashbangCntl($scope, $location) {
454- $scope.$location = $location;
455- }
456-
457- function initEnv(name) {
458- var root = angular.element(document.getElementById(name + '-mode'));
459- // We must kill a link to the injector for this element otherwise angular will
460- // complain that it has been bootstrapped already.
461- root.data('$injector', null);
462- angular.bootstrap(root, [function($compileProvider, $locationProvider, $provide){
463- $locationProvider.html5Mode(true).hashPrefix('!');
464-
465- $provide.value('$browser', browsers[name]);
466- $provide.value('$sniffer', {history: name == 'html5'});
467-
468- $compileProvider.directive('ngAddressBar', function() {
469- return function(scope, elm, attrs) {
470- var browser = browsers[attrs.browser],
471- input = angular.element('<input type="text" style="width: 400px">').val(browser.url()),
472- delay;
473-
474- input.on('keypress keyup keydown', function() {
475- if (!delay) {
476- delay = setTimeout(fireUrlChange, 250);
447+ function Html5Cntl($scope, $location) {
448+ $scope.$location = $location;
449+ }
450+
451+ function HashbangCntl($scope, $location) {
452+ $scope.$location = $location;
453+ }
454+
455+ function initEnv(name) {
456+ var root = angular.element(document.getElementById(name + '-mode'));
457+ // We must kill a link to the injector for this element otherwise angular will
458+ // complain that it has been bootstrapped already.
459+ root.data('$injector', null);
460+ angular.bootstrap(root, [function($compileProvider, $locationProvider, $provide){
461+ $locationProvider.html5Mode(true).hashPrefix('!');
462+
463+ $provide.value('$browser', browsers[name]);
464+ $provide.value('$sniffer', {history: name == 'html5'});
465+
466+ $compileProvider.directive('ngAddressBar', function() {
467+ return function(scope, elm, attrs) {
468+ var browser = browsers[attrs.browser],
469+ input = angular.element('<input type="text" style="width: 400px">').val(browser.url()),
470+ delay;
471+
472+ input.on('keypress keyup keydown', function() {
473+ if (!delay) {
474+ delay = setTimeout(fireUrlChange, 250);
475+ }
476+ });
477+
478+ browser.url = function(url) {
479+ return input.val(url);
480+ };
481+
482+ elm.append('Address: ').append(input);
483+
484+ function fireUrlChange() {
485+ delay = null;
486+ browser.urlChange(input.val());
477487 }
478- });
479-
480- browser.url = function(url) {
481- return input.val(url);
482488 };
483-
484- elm.append('Address: ').append(input);
485-
486- function fireUrlChange() {
487- delay = null;
488- browser.urlChange(input.val());
489- }
490- };
489+ });
490+ }]);
491+ root.on('click', function(e) {
492+ e.stopPropagation();
491493 });
492- }]);
493- root.on('click', function(e) {
494- e.stopPropagation();
495- });
496- }
494+ }
497495
498- initEnv('html5');
499- initEnv('hashbang');
500- </script>
501-
502- </doc:source>
503- </doc:example>
496+ initEnv('html5');
497+ initEnv('hashbang');
498+ </file>
499+ </example>
504500
505501
506502# Caveats
0 commit comments