diff options
| author | Di Peng | 2011-07-20 19:29:54 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-07-26 16:35:42 -0700 | 
| commit | 9dea9de44917b0b72a786122e619d451ccb8b0dc (patch) | |
| tree | d4ac89c713fb0cc3e0607309bc46d1ca37ef0fc0 /docs/src/templates/docs.js | |
| parent | bee78a84922da51de647af96fe86f75b1322d3d9 (diff) | |
| download | angular.js-9dea9de44917b0b72a786122e619d451ccb8b0dc.tar.bz2 | |
feat(docs): add full offline support
Diffstat (limited to 'docs/src/templates/docs.js')
| -rw-r--r-- | docs/src/templates/docs.js | 35 | 
1 files changed, 29 insertions, 6 deletions
| diff --git a/docs/src/templates/docs.js b/docs/src/templates/docs.js index ab2d836a..7efb2a5e 100644 --- a/docs/src/templates/docs.js +++ b/docs/src/templates/docs.js @@ -1,15 +1,17 @@ -var HAS_HASH = /#/; -DocsController.$inject = ['$location', '$browser', '$window']; -function DocsController($location, $browser, $window) { +DocsController.$inject = ['$location', '$browser', '$window', '$cookies']; +function DocsController($location, $browser, $window, $cookies) {    window.$root = this.$root; -  var self = this; + +  var self = this, +      OFFLINE_COOKIE_NAME = 'ng-offline', +      HAS_HASH = /#/; +    this.$location = $location;    self.versionNumber = angular.version.full;    self.version = angular.version.full + "  " + angular.version.codeName; -  self.cookieName = "angularPref";    self.subpage = false; -  self.offlineEnabled = (document.cookie.indexOf(self.cookieName) !== -1); +  self.offlineEnabled = ($cookies[OFFLINE_COOKIE_NAME] == angular.version.full);    if (!HAS_HASH.test($location.href)) {      $location.hashPath = '!/api'; @@ -73,6 +75,27 @@ function DocsController($location, $browser, $window) {             "subject=" + escape("Feedback on " + $location.href) + "&" +             "body=" + escape("Hi there,\n\nI read " + $location.href + " and wanted to ask ....");    }; + +  /** stores a cookie that is used by apache to decide which manifest ot send */ +  this.enableOffline = function() { +    //The cookie will be good for one year! +    var date = new Date(); +    date.setTime(date.getTime()+(365*24*60*60*1000)); +    var expires = "; expires="+date.toGMTString(); +    var value = angular.version.full; +    document.cookie = OFFLINE_COOKIE_NAME + "="+value+expires+"; path=" + $location.path; + +    //force the page to reload so server can serve new manifest file +    window.location.reload(true); +  }; + +  // bind escape to hash reset callback +  angular.element(window).bind('keydown', function(e) { +    if (e.keyCode === 27) { +      self.subpage = false; +      self.$eval(); +    } +  });  }  // prevent compilation of code | 
