pagesjs 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +7 -0
- data/README.md +48 -7
- data/lib/assets/javascripts/pages.js +198 -113
- metadata +8 -8
    
        data/ChangeLog
    CHANGED
    
    | @@ -1,3 +1,10 @@ | |
| 1 | 
            +
            == 0.1 (Ignacy Hryniewiecki)
         | 
| 2 | 
            +
            * Add API to redefine work with URL.
         | 
| 3 | 
            +
            * Rename Pages.pagesSelector to Pages.selector.
         | 
| 4 | 
            +
            * Simpler API in Pages.animating.
         | 
| 5 | 
            +
            * Abort previous page loading, when start to load new one.
         | 
| 6 | 
            +
            * Decrease files size (by compressible code and UnglifyJS 2).
         | 
| 7 | 
            +
             | 
| 1 8 | 
             
            == 0.0.5 (Pyotr Kakhovsky)
         | 
| 2 9 | 
             
            * Add data.from with URL changing source.
         | 
| 3 10 | 
             
            * Pages.open() will change URL if it necessary.
         | 
    
        data/README.md
    CHANGED
    
    | @@ -76,7 +76,9 @@ For Ruby on Rails you can use gem for Assets Pipeline. | |
| 76 76 |  | 
| 77 77 | 
             
            If you don’t use any assets packaging manager (it’s very bad idea), you can use
         | 
| 78 78 | 
             
            already minified version of the library.
         | 
| 79 | 
            -
            Take | 
| 79 | 
            +
            Take it from: [github.com/ai/pages.js/downloads].
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            [github.com/ai/pages.js/downloads]: https://github.com/ai/pages.js/downloads
         | 
| 80 82 |  | 
| 81 83 | 
             
            ## Usage
         | 
| 82 84 |  | 
| @@ -118,7 +120,7 @@ Callbacks get three arguments: | |
| 118 120 | 
             
            * `$`: jQuery.
         | 
| 119 121 | 
             
            * `$$`: jQuery finder only in current page (a little bit faster and more safely
         | 
| 120 122 | 
             
              than `$`). For example `$$('a')` is equal to `$('a', page)`.
         | 
| 121 | 
            -
            * `page`: jQuery-nodes of selected  | 
| 123 | 
            +
            * `page`: jQuery-nodes of selected page.
         | 
| 122 124 |  | 
| 123 125 | 
             
            You can pass `load` as second argument without other options:
         | 
| 124 126 |  | 
| @@ -165,7 +167,7 @@ You can create you own animation, just add object with `animate` function. | |
| 165 167 | 
             
            When animation ends, you *must* call `done` argument.
         | 
| 166 168 |  | 
| 167 169 | 
             
            ```js
         | 
| 168 | 
            -
            Pages. | 
| 170 | 
            +
            Pages.animations.cool = {
         | 
| 169 171 | 
             
              animate: function(prev, next, done, data) {
         | 
| 170 172 | 
             
                prev.coolHiding();
         | 
| 171 173 | 
             
                next.coolShowing(function() {
         | 
| @@ -185,7 +187,7 @@ Argument `data` contains merged page and link data attributes: | |
| 185 187 | 
             
            ```
         | 
| 186 188 |  | 
| 187 189 | 
             
            ```js
         | 
| 188 | 
            -
            Pages. | 
| 190 | 
            +
            Pages.animations.slide = {
         | 
| 189 191 | 
             
              animate: function(prev, next, done, data) {
         | 
| 190 192 | 
             
                prev.slideHide(data.direction);
         | 
| 191 193 | 
             
                next.slideShow(data.direction, function() {
         | 
| @@ -222,6 +224,42 @@ $(document).load(function() { | |
| 222 224 | 
             
            });
         | 
| 223 225 | 
             
            ```
         | 
| 224 226 |  | 
| 227 | 
            +
            ### History API support
         | 
| 228 | 
            +
             | 
| 229 | 
            +
            I prefer graceful degradation and think, that old browsers should reload full
         | 
| 230 | 
            +
            page by old way. But if you want to add page changes animation to old browser,
         | 
| 231 | 
            +
            you can redefine `Pages.isSupported`, `Pages.getURL`, `Pages.setURL`,
         | 
| 232 | 
            +
            `Pages.watchURL` and `Pages.unwatchURL` methods to support any of History API
         | 
| 233 | 
            +
            polyffils.
         | 
| 234 | 
            +
             | 
| 235 | 
            +
            ### URL Methods
         | 
| 236 | 
            +
             | 
| 237 | 
            +
            You can redefine way, that Pages.js use to get/set current page URL.
         | 
| 238 | 
            +
            For example, to synchronize open page between different tabs by Session Storage,
         | 
| 239 | 
            +
            or to support one page sites:
         | 
| 240 | 
            +
             | 
| 241 | 
            +
            ```js
         | 
| 242 | 
            +
            Pages.isSupported = function() {
         | 
| 243 | 
            +
              return true;
         | 
| 244 | 
            +
            };
         | 
| 245 | 
            +
             | 
| 246 | 
            +
            Pages.setURL = function(url) {
         | 
| 247 | 
            +
              location.hash = url;
         | 
| 248 | 
            +
            };
         | 
| 249 | 
            +
             | 
| 250 | 
            +
            Pages.getURL = function() {
         | 
| 251 | 
            +
              return location.hash;
         | 
| 252 | 
            +
            };
         | 
| 253 | 
            +
             | 
| 254 | 
            +
            Pages.watchURL = function(callback) {
         | 
| 255 | 
            +
              $(window).on('hashchange.pages', callback);
         | 
| 256 | 
            +
            };
         | 
| 257 | 
            +
             | 
| 258 | 
            +
            Pages.unwatchURL = function() {
         | 
| 259 | 
            +
              $(window).off('hashchange.pages');
         | 
| 260 | 
            +
            };
         | 
| 261 | 
            +
            ```
         | 
| 262 | 
            +
             | 
| 225 263 | 
             
            ## Contributing
         | 
| 226 264 |  | 
| 227 265 | 
             
            1. To run tests you need node.js and npm. For example, in Ubuntu run:
         | 
| @@ -239,9 +277,12 @@ $(document).load(function() { | |
| 239 277 | 
             
            3. Run test server:
         | 
| 240 278 |  | 
| 241 279 | 
             
               ```sh
         | 
| 242 | 
            -
               ./node_modules/.bin/cake  | 
| 280 | 
            +
               ./node_modules/.bin/cake server
         | 
| 243 281 | 
             
               ```
         | 
| 244 282 |  | 
| 245 | 
            -
            4. Open tests in browser:  | 
| 283 | 
            +
            4. Open tests in browser: [localhost:8000].
         | 
| 246 284 | 
             
            5. Also you can see real usage example in integration test:
         | 
| 247 | 
            -
                | 
| 285 | 
            +
               [localhost:8000/integration].
         | 
| 286 | 
            +
             | 
| 287 | 
            +
            [localhost:8000]: http://localhost:8000
         | 
| 288 | 
            +
            [localhost:8000/integration]: http://localhost:8000/integration
         | 
| @@ -16,7 +16,7 @@ | |
| 16 16 | 
             
             * along with this program.  If not, see <http://www.gnu.org/licenses/>.
         | 
| 17 17 | 
             
             */
         | 
| 18 18 |  | 
| 19 | 
            -
            ;(function( | 
| 19 | 
            +
            ;(function($, undefined) {
         | 
| 20 20 | 
             
              "use strict";
         | 
| 21 21 |  | 
| 22 22 | 
             
              // Pages.js is a framework for History pushState. It allow you to manage
         | 
| @@ -30,7 +30,7 @@ | |
| 30 30 | 
             
              //    page content without layout. Just check `HTTP_X_REQUESTED_WITH`
         | 
| 31 31 | 
             
              //    HTTP header to equal `"XMLHttpRequest"`.
         | 
| 32 32 | 
             
              // 3. Load jQuery before Pages.js.
         | 
| 33 | 
            -
              window.Pages = {
         | 
| 33 | 
            +
              var self = window.Pages = {
         | 
| 34 34 |  | 
| 35 35 | 
             
                // Is history management disabled.
         | 
| 36 36 | 
             
                disabled: false,
         | 
| @@ -45,8 +45,8 @@ | |
| 45 45 | 
             
                //
         | 
| 46 46 | 
             
                // Be default it is `article.page` (`article` tag with `page` class).
         | 
| 47 47 | 
             
                //
         | 
| 48 | 
            -
                //  Pages. | 
| 49 | 
            -
                 | 
| 48 | 
            +
                //  Pages.selector = '.page';
         | 
| 49 | 
            +
                selector: 'article.page',
         | 
| 50 50 |  | 
| 51 51 | 
             
                // Current animation name. For some page or link you can set
         | 
| 52 52 | 
             
                // custom animation by `data-page-animation` attribute.
         | 
| @@ -71,7 +71,31 @@ | |
| 71 71 | 
             
                //     }
         | 
| 72 72 | 
             
                //   };
         | 
| 73 73 | 
             
                //   Pages.animation = 'slideUpDown';
         | 
| 74 | 
            -
                animations: { | 
| 74 | 
            +
                animations: {
         | 
| 75 | 
            +
                  // The simplest “animation”. Just immediately hide/show pages
         | 
| 76 | 
            +
                  // by CSS display property.
         | 
| 77 | 
            +
                  immediately: {
         | 
| 78 | 
            +
                    animate: function(prev, next, done, data) {
         | 
| 79 | 
            +
                      prev.hide();
         | 
| 80 | 
            +
                      next.show();
         | 
| 81 | 
            +
                      done();
         | 
| 82 | 
            +
                    }
         | 
| 83 | 
            +
                  },
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                  // Simple fade in/out animation.
         | 
| 86 | 
            +
                  fade: {
         | 
| 87 | 
            +
                    // Animation duration in milliseconds.
         | 
| 88 | 
            +
                    duration: 300,
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                    animate: function(prev, next, done, data) {
         | 
| 91 | 
            +
                      var half = this.duration / 2;
         | 
| 92 | 
            +
                      prev.fadeOut(half, function() {
         | 
| 93 | 
            +
                        next.fadeIn(half, done);
         | 
| 94 | 
            +
                      });
         | 
| 95 | 
            +
                    }
         | 
| 96 | 
            +
                  },
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                },
         | 
| 75 99 |  | 
| 76 100 | 
             
                // Add description for page with `selector`. Allow options:
         | 
| 77 101 | 
             
                // * `load`: `function ($, $$, page)` which is called, when page is loaded
         | 
| @@ -122,24 +146,24 @@ | |
| 122 146 | 
             
                //     });
         | 
| 123 147 | 
             
                //   });
         | 
| 124 148 | 
             
                add: function(selector, options) {
         | 
| 125 | 
            -
                  if (  | 
| 126 | 
            -
                     | 
| 149 | 
            +
                  if ( options == undefined ) {
         | 
| 150 | 
            +
                    self._liveCallbacks.push(selector);
         | 
| 127 151 | 
             
                  } else {
         | 
| 128 152 | 
             
                    if ( typeof(options) == 'function' ) {
         | 
| 129 153 | 
             
                      options = { load: options };
         | 
| 130 154 | 
             
                    }
         | 
| 131 155 | 
             
                    options.selector = selector;
         | 
| 132 | 
            -
                     | 
| 156 | 
            +
                    self._pages.push(options);
         | 
| 133 157 | 
             
                  }
         | 
| 134 158 | 
             
                },
         | 
| 135 159 |  | 
| 136 160 | 
             
                // Run Pages.js. It’s called automatically on document ready.
         | 
| 137 161 | 
             
                // It’s used for tests.
         | 
| 138 162 | 
             
                init: function() {
         | 
| 139 | 
            -
                   | 
| 140 | 
            -
                  var current =  | 
| 163 | 
            +
                  self._enlive($(self._doc));
         | 
| 164 | 
            +
                  var current = self._findCurrent();
         | 
| 141 165 | 
             
                  if ( current.length ) {
         | 
| 142 | 
            -
                     | 
| 166 | 
            +
                    self._setCurrent(current);
         | 
| 143 167 | 
             
                  }
         | 
| 144 168 | 
             
                },
         | 
| 145 169 |  | 
| @@ -148,6 +172,13 @@ | |
| 148 172 | 
             
                //   if ( !Pages.isSupported() ) {
         | 
| 149 173 | 
             
                //     $('.old-browser-notice').show();
         | 
| 150 174 | 
             
                //   }
         | 
| 175 | 
            +
                //
         | 
| 176 | 
            +
                // If you rewrite `setURL` and other URL methods, you maybe need
         | 
| 177 | 
            +
                // to override this method too:
         | 
| 178 | 
            +
                //
         | 
| 179 | 
            +
                //   Pages.isSupported = function() {
         | 
| 180 | 
            +
                //     return true;
         | 
| 181 | 
            +
                //   };
         | 
| 151 182 | 
             
                isSupported: function() {
         | 
| 152 183 | 
             
                  return !!(window.history && history.pushState);
         | 
| 153 184 | 
             
                },
         | 
| @@ -155,20 +186,20 @@ | |
| 155 186 | 
             
                // Start session history management. It’s called automatically on
         | 
| 156 187 | 
             
                // document ready. You can use it manually after `Pages.disable` calling.
         | 
| 157 188 | 
             
                enable: function() {
         | 
| 158 | 
            -
                  if (  | 
| 189 | 
            +
                  if ( self._events || !self.isSupported() ) {
         | 
| 159 190 | 
             
                    return false;
         | 
| 160 191 | 
             
                  }
         | 
| 161 | 
            -
                   | 
| 162 | 
            -
                   | 
| 192 | 
            +
                  self.disabled = false;
         | 
| 193 | 
            +
                  self._events  = true;
         | 
| 163 194 |  | 
| 164 | 
            -
                   | 
| 165 | 
            -
                    if (  | 
| 166 | 
            -
                       | 
| 195 | 
            +
                  self.watchURL(function() {
         | 
| 196 | 
            +
                    if ( self._lastUrl != self.getURL() ) {
         | 
| 197 | 
            +
                      self.open(self.getURL(), { from: 'popstate' });
         | 
| 167 198 | 
             
                    }
         | 
| 168 199 | 
             
                  });
         | 
| 169 200 |  | 
| 170 | 
            -
                  $( | 
| 171 | 
            -
                    return  | 
| 201 | 
            +
                  $(self._doc).on('click.pages', 'a', function() {
         | 
| 202 | 
            +
                    return self._openLink($(this));
         | 
| 172 203 | 
             
                  });
         | 
| 173 204 |  | 
| 174 205 | 
             
                  return true;
         | 
| @@ -177,10 +208,10 @@ | |
| 177 208 | 
             
                // Disable session history management. Pages.js will load by default browser
         | 
| 178 209 | 
             
                // way without AJAX and animations.
         | 
| 179 210 | 
             
                disable: function() {
         | 
| 180 | 
            -
                  $( | 
| 181 | 
            -
                   | 
| 182 | 
            -
                   | 
| 183 | 
            -
                   | 
| 211 | 
            +
                  $(self._doc).off('click.pages', 'a');
         | 
| 212 | 
            +
                  self.unwatchURL();
         | 
| 213 | 
            +
                  self.disabled = true;
         | 
| 214 | 
            +
                  self._events = false;
         | 
| 184 215 | 
             
                },
         | 
| 185 216 |  | 
| 186 217 | 
             
                // Show page by `url` with overrided page `data`. Return true if page is
         | 
| @@ -190,29 +221,29 @@ | |
| 190 221 | 
             
                //     Pages.open('/gameover');
         | 
| 191 222 | 
             
                //   }, 5000);
         | 
| 192 223 | 
             
                open: function(url, data) {
         | 
| 193 | 
            -
                  if (  | 
| 194 | 
            -
                     | 
| 224 | 
            +
                  if ( self.getURL() != url ) {
         | 
| 225 | 
            +
                    self.setURL(url);
         | 
| 195 226 | 
             
                  }
         | 
| 196 227 |  | 
| 197 | 
            -
                  if (  | 
| 228 | 
            +
                  if ( data == undefined ) {
         | 
| 198 229 | 
             
                    data = { };
         | 
| 199 230 | 
             
                  }
         | 
| 200 | 
            -
                  if (  | 
| 231 | 
            +
                  if ( data.from == undefined ) {
         | 
| 201 232 | 
             
                    data.from = 'js';
         | 
| 202 233 | 
             
                  }
         | 
| 203 234 | 
             
                  data.url = url;
         | 
| 204 | 
            -
                   | 
| 235 | 
            +
                  self._lastUrl = url;
         | 
| 205 236 |  | 
| 206 | 
            -
                  var page =  | 
| 237 | 
            +
                  var page = self.page(url);
         | 
| 207 238 | 
             
                  if ( page.length ) {
         | 
| 208 | 
            -
                     | 
| 239 | 
            +
                    self._openPage(page, data);
         | 
| 209 240 | 
             
                    return true;
         | 
| 210 241 | 
             
                  } else {
         | 
| 211 | 
            -
                     | 
| 242 | 
            +
                    self._loadPages(url, data, function(nodes) {
         | 
| 212 243 | 
             
                      nodes.hide();
         | 
| 213 | 
            -
                      page =  | 
| 244 | 
            +
                      page = self.page(url, nodes);
         | 
| 214 245 | 
             
                      if ( page.length ) {
         | 
| 215 | 
            -
                         | 
| 246 | 
            +
                        self._openPage(page, data);
         | 
| 216 247 | 
             
                      }
         | 
| 217 248 | 
             
                    });
         | 
| 218 249 | 
             
                    return false;
         | 
| @@ -220,16 +251,16 @@ | |
| 220 251 | 
             
                },
         | 
| 221 252 |  | 
| 222 253 | 
             
                // Find loaded page by URL in `data-url` attribute.
         | 
| 223 | 
            -
                // It use `Pages. | 
| 254 | 
            +
                // It use `Pages.selector` to detect pages tags.
         | 
| 224 255 | 
             
                //
         | 
| 225 256 | 
             
                //   if ( Pages.page('/comments').length ) {
         | 
| 226 257 | 
             
                //     // Comment page is loaded to DOM
         | 
| 227 258 | 
             
                //   }
         | 
| 228 259 | 
             
                page: function(url, base) {
         | 
| 229 260 | 
             
                  if ( !base ) {
         | 
| 230 | 
            -
                    base = $( | 
| 261 | 
            +
                    base = $(self._doc);
         | 
| 231 262 | 
             
                  }
         | 
| 232 | 
            -
                  var selector =  | 
| 263 | 
            +
                  var selector = self.selector + '[data-url="' + url + '"]';
         | 
| 233 264 | 
             
                  return base.filter(selector).add(base.find(selector));
         | 
| 234 265 | 
             
                },
         | 
| 235 266 |  | 
| @@ -247,10 +278,24 @@ | |
| 247 278 | 
             
                // from AJAX (but `HTTP_X_REQUESTED_WITH` is better way):
         | 
| 248 279 | 
             
                //
         | 
| 249 280 | 
             
                //   Page.load = function(url, data, callbacks) {
         | 
| 250 | 
            -
                //     $.get(url + '?no_layout=1', callback);
         | 
| 281 | 
            +
                //     return $.get(url + '?no_layout=1', callback);
         | 
| 251 282 | 
             
                //   };
         | 
| 283 | 
            +
                //
         | 
| 284 | 
            +
                // It must return some AJAX request object or ID to use it in `stopLoading`.
         | 
| 285 | 
            +
                // If you use non-jQuery AJAX, you need also override `stopLoading`.
         | 
| 252 286 | 
             
                load: function(url, data, callback) {
         | 
| 253 | 
            -
                  $.get(url, callback);
         | 
| 287 | 
            +
                  return $.get(url, callback);
         | 
| 288 | 
            +
                },
         | 
| 289 | 
            +
             | 
| 290 | 
            +
                // Stop current AJAX page loading. It just abort jQuery AJAX, but allow you
         | 
| 291 | 
            +
                // to override it.
         | 
| 292 | 
            +
                //
         | 
| 293 | 
            +
                // It will get as argument, what `load` was return.
         | 
| 294 | 
            +
                //
         | 
| 295 | 
            +
                // You need to override this method, only if your `load` override, don’t
         | 
| 296 | 
            +
                // return jQuery jqXHR object (`$.get` and `$.post` return correct jqXHR).
         | 
| 297 | 
            +
                stopLoading: function(loading) {
         | 
| 298 | 
            +
                  loading.abort();
         | 
| 254 299 | 
             
                },
         | 
| 255 300 |  | 
| 256 301 | 
             
                // Change document title. It is internal method, used by `Pages.open`,
         | 
| @@ -268,17 +313,59 @@ | |
| 268 313 | 
             
                //
         | 
| 269 314 | 
             
                //   Pages.preload('/posts/all');
         | 
| 270 315 | 
             
                preload: function(url) {
         | 
| 271 | 
            -
                   | 
| 316 | 
            +
                  self._loadPages(url, { }, function(nodes) {
         | 
| 272 317 | 
             
                    nodes.hide();
         | 
| 273 318 | 
             
                  })
         | 
| 274 319 | 
             
                },
         | 
| 275 320 |  | 
| 321 | 
            +
                // Change document URL to `url`. By default it will use
         | 
| 322 | 
            +
                // `history.pushState`, but you can change it to support
         | 
| 323 | 
            +
                // your history library or some hacks.
         | 
| 324 | 
            +
                //
         | 
| 325 | 
            +
                //   Pages.setURL = function(url) {
         | 
| 326 | 
            +
                //     location.hash = url;
         | 
| 327 | 
            +
                //   };
         | 
| 328 | 
            +
                setURL: function(url) {
         | 
| 329 | 
            +
                  history.pushState({ }, '', url);
         | 
| 330 | 
            +
                },
         | 
| 331 | 
            +
             | 
| 332 | 
            +
                // Get current page URL. By default it will use `location.pathname`,
         | 
| 333 | 
            +
                // but you can change it to support your history library or some hacks.
         | 
| 334 | 
            +
                //
         | 
| 335 | 
            +
                //   Pages.getURL = function() {
         | 
| 336 | 
            +
                //     return location.hash;
         | 
| 337 | 
            +
                //   };
         | 
| 338 | 
            +
                getURL: function() {
         | 
| 339 | 
            +
                  return location.pathname;
         | 
| 340 | 
            +
                },
         | 
| 341 | 
            +
             | 
| 342 | 
            +
                // Set `callback` to watch for current page URL changes.
         | 
| 343 | 
            +
                // By default it will bind to `popstate` event, but you can change it
         | 
| 344 | 
            +
                // to support your history library or some hacks.
         | 
| 345 | 
            +
                //
         | 
| 346 | 
            +
                //   Pages.watchURL = function(callback) {
         | 
| 347 | 
            +
                //     $(window).on('hashchange.pages', callback);
         | 
| 348 | 
            +
                //   };
         | 
| 349 | 
            +
                watchURL: function(callback) {
         | 
| 350 | 
            +
                  $(window).on('popstate.pages', callback);
         | 
| 351 | 
            +
                },
         | 
| 352 | 
            +
             | 
| 353 | 
            +
                // Disable listening, which was set by `watchURL`.
         | 
| 354 | 
            +
                // By default it will unbind from `popstate` event, but you can change it
         | 
| 355 | 
            +
                // to support your history library or some hacks.
         | 
| 356 | 
            +
                //
         | 
| 357 | 
            +
                //   Pages.unwatchURL = function() {
         | 
| 358 | 
            +
                //     $(window).off('hashchange.pages');
         | 
| 359 | 
            +
                //   };
         | 
| 360 | 
            +
                unwatchURL: function() {
         | 
| 361 | 
            +
                  $(window).off('popstate.pages');
         | 
| 362 | 
            +
                },
         | 
| 363 | 
            +
             | 
| 276 364 | 
             
                // Internal API to wait previous animation, before start new one.
         | 
| 277 365 | 
             
                //
         | 
| 278 | 
            -
                //   Pages.animating. | 
| 279 | 
            -
                //     Pages.animating.start();
         | 
| 366 | 
            +
                //   Pages.animating.run(function(done) {
         | 
| 280 367 | 
             
                //     // Animation code
         | 
| 281 | 
            -
                //      | 
| 368 | 
            +
                //     done();
         | 
| 282 369 | 
             
                //   });
         | 
| 283 370 | 
             
                animating: {
         | 
| 284 371 |  | 
| @@ -288,9 +375,14 @@ | |
| 288 375 | 
             
                  // True if some animation is played now.
         | 
| 289 376 | 
             
                  waiting: false,
         | 
| 290 377 |  | 
| 291 | 
            -
                  //  | 
| 292 | 
            -
                   | 
| 293 | 
            -
             | 
| 378 | 
            +
                  // If there isn’t animation now, `callback` will be executed now.
         | 
| 379 | 
            +
                  // Else `callback` will wait, until previous animation will call `end`.
         | 
| 380 | 
            +
                  wait: function(callback) {
         | 
| 381 | 
            +
                    if ( this.waiting ) {
         | 
| 382 | 
            +
                      this._waiters.push(callback);
         | 
| 383 | 
            +
                    } else {
         | 
| 384 | 
            +
                      callback();
         | 
| 385 | 
            +
                    }
         | 
| 294 386 | 
             
                  },
         | 
| 295 387 |  | 
| 296 388 | 
             
                  // Mark, that current animation is ended.
         | 
| @@ -302,20 +394,27 @@ | |
| 302 394 | 
             
                    }
         | 
| 303 395 | 
             
                  },
         | 
| 304 396 |  | 
| 305 | 
            -
                  //  | 
| 306 | 
            -
                  //  | 
| 307 | 
            -
                   | 
| 308 | 
            -
             | 
| 309 | 
            -
             | 
| 310 | 
            -
             | 
| 311 | 
            -
             | 
| 312 | 
            -
             | 
| 397 | 
            +
                  // Wait for previous animation end, execute `callback` and run another
         | 
| 398 | 
            +
                  // animations, only after `callback` will execute it first argument.
         | 
| 399 | 
            +
                  //
         | 
| 400 | 
            +
                  //   Pages.animating.run(function(done) {
         | 
| 401 | 
            +
                  //     // Animation code
         | 
| 402 | 
            +
                  //     done();
         | 
| 403 | 
            +
                  //   });
         | 
| 404 | 
            +
                  run: function(callback) {
         | 
| 405 | 
            +
                    var animating = this;
         | 
| 406 | 
            +
                    animating.wait(function() {
         | 
| 407 | 
            +
                      animating.waiting = true;
         | 
| 408 | 
            +
                      callback(function() {
         | 
| 409 | 
            +
                        animating.end();
         | 
| 410 | 
            +
                      });
         | 
| 411 | 
            +
                    });
         | 
| 313 412 | 
             
                  }
         | 
| 314 413 |  | 
| 315 414 | 
             
                },
         | 
| 316 415 |  | 
| 317 416 | 
             
                // Link to current `window.document`. It is used for tests.
         | 
| 318 | 
            -
                 | 
| 417 | 
            +
                _doc: document,
         | 
| 319 418 |  | 
| 320 419 | 
             
                // Arra of added pages options.
         | 
| 321 420 | 
             
                _pages: [],
         | 
| @@ -331,19 +430,22 @@ | |
| 331 430 |  | 
| 332 431 | 
             
                // Find first current page.
         | 
| 333 432 | 
             
                _findCurrent: function() {
         | 
| 334 | 
            -
                  return $( | 
| 433 | 
            +
                  return $(self.selector + ':visible:first', self._doc)
         | 
| 335 434 | 
             
                },
         | 
| 336 435 |  | 
| 436 | 
            +
                // AJAX request, if some page is loading now.
         | 
| 437 | 
            +
                _loading: null,
         | 
| 438 | 
            +
             | 
| 337 439 | 
             
                // Find pages in new content, set caches and trigger load event on them.
         | 
| 338 440 | 
             
                _enlive: function(nodes) {
         | 
| 339 | 
            -
                  var args =  | 
| 340 | 
            -
                  for (var i = 0; i <  | 
| 341 | 
            -
                     | 
| 441 | 
            +
                  var args = self._callbackArgs(divs)
         | 
| 442 | 
            +
                  for (var i = 0; i < self._liveCallbacks.length; i++) {
         | 
| 443 | 
            +
                    self._liveCallbacks[i].apply(nodes, args);
         | 
| 342 444 | 
             
                  }
         | 
| 343 445 |  | 
| 344 446 | 
             
                  var page, pages;
         | 
| 345 | 
            -
                  for (var i = 0; i <  | 
| 346 | 
            -
                    page =  | 
| 447 | 
            +
                  for (var i = 0; i < self._pages.length; i++) {
         | 
| 448 | 
            +
                    page = self._pages[i];
         | 
| 347 449 | 
             
                    var divs = nodes.filter(page.selector);
         | 
| 348 450 | 
             
                    divs = divs.add( nodes.find(page.selector) );
         | 
| 349 451 | 
             
                    if ( divs.length ) {
         | 
| @@ -354,7 +456,7 @@ | |
| 354 456 | 
             
                        divs.data('pages', [page]);
         | 
| 355 457 | 
             
                      }
         | 
| 356 458 | 
             
                      if ( page.load ) {
         | 
| 357 | 
            -
                        page.load.apply(divs,  | 
| 459 | 
            +
                        page.load.apply(divs, self._callbackArgs(divs));
         | 
| 358 460 | 
             
                      }
         | 
| 359 461 | 
             
                    }
         | 
| 360 462 | 
             
                  }
         | 
| @@ -382,7 +484,7 @@ | |
| 382 484 | 
             
                  for (var i = 0; i < pages.length; i++) {
         | 
| 383 485 | 
             
                    page = pages[i];
         | 
| 384 486 | 
             
                    if ( page[type] ) {
         | 
| 385 | 
            -
                      page[type].apply(div,  | 
| 487 | 
            +
                      page[type].apply(div, self._callbackArgs(div));
         | 
| 386 488 | 
             
                    }
         | 
| 387 489 | 
             
                  }
         | 
| 388 490 | 
             
                },
         | 
| @@ -390,11 +492,11 @@ | |
| 390 492 | 
             
                // Find page descriptions for current and next page and fire `close` and
         | 
| 391 493 | 
             
                // `open` events.
         | 
| 392 494 | 
             
                _setCurrent: function(next) {
         | 
| 393 | 
            -
                  if (  | 
| 394 | 
            -
                     | 
| 495 | 
            +
                  if ( self.current ) {
         | 
| 496 | 
            +
                    self._callback(self.current, 'close');
         | 
| 395 497 | 
             
                  }
         | 
| 396 | 
            -
                   | 
| 397 | 
            -
                   | 
| 498 | 
            +
                  self._callback(next, 'open');
         | 
| 499 | 
            +
                  self.current = next;
         | 
| 398 500 | 
             
                },
         | 
| 399 501 |  | 
| 400 502 | 
             
                // Open URL from link.
         | 
| @@ -403,7 +505,7 @@ | |
| 403 505 | 
             
                  if ( !href || href[0] != '/' ) {
         | 
| 404 506 | 
             
                    return true;
         | 
| 405 507 | 
             
                  }
         | 
| 406 | 
            -
                  if (  | 
| 508 | 
            +
                  if ( link.data().pagesDisable != undefined ) {
         | 
| 407 509 | 
             
                    return true;
         | 
| 408 510 | 
             
                  }
         | 
| 409 511 |  | 
| @@ -415,7 +517,7 @@ | |
| 415 517 | 
             
                  var path = href[0];
         | 
| 416 518 | 
             
                  var hash = href[1];
         | 
| 417 519 |  | 
| 418 | 
            -
                   | 
| 520 | 
            +
                  self.open(path, data);
         | 
| 419 521 | 
             
                  if ( hash && location.hash != hash ) {
         | 
| 420 522 | 
             
                    location.hash = hash;
         | 
| 421 523 | 
             
                  }
         | 
| @@ -424,8 +526,8 @@ | |
| 424 526 |  | 
| 425 527 | 
             
                // Open loaded page.
         | 
| 426 528 | 
             
                _openPage: function(page, data) {
         | 
| 427 | 
            -
                  if ( page[0] ==  | 
| 428 | 
            -
                     | 
| 529 | 
            +
                  if ( page[0] == self.current[0] ) {
         | 
| 530 | 
            +
                    self._setCurrent(page);
         | 
| 429 531 | 
             
                    return;
         | 
| 430 532 | 
             
                  }
         | 
| 431 533 |  | 
| @@ -442,38 +544,43 @@ | |
| 442 544 | 
             
                      }
         | 
| 443 545 | 
             
                    }
         | 
| 444 546 | 
             
                    if ( pageAnimation ) {
         | 
| 445 | 
            -
                      anim = pageAnimation( | 
| 547 | 
            +
                      anim = pageAnimation(self.current);
         | 
| 446 548 | 
             
                    }
         | 
| 447 549 | 
             
                  }
         | 
| 448 | 
            -
                  anim = anim ||  | 
| 550 | 
            +
                  anim = anim || self.animation;
         | 
| 449 551 |  | 
| 450 | 
            -
                   | 
| 451 | 
            -
                    if (  | 
| 452 | 
            -
                       | 
| 552 | 
            +
                  self.animating.run(function(done) {
         | 
| 553 | 
            +
                    if ( data.title != undefined ) {
         | 
| 554 | 
            +
                      self.title(data.title);
         | 
| 453 555 | 
             
                    }
         | 
| 454 | 
            -
                     | 
| 455 | 
            -
             | 
| 456 | 
            -
                       | 
| 457 | 
            -
                      Pages._setCurrent(page);
         | 
| 556 | 
            +
                    self.animations[anim].animate(self.current, page, function() {
         | 
| 557 | 
            +
                      done();
         | 
| 558 | 
            +
                      self._setCurrent(page);
         | 
| 458 559 | 
             
                    }, data);
         | 
| 459 560 | 
             
                  });
         | 
| 460 561 | 
             
                },
         | 
| 461 562 |  | 
| 462 563 | 
             
                // Internal method to load pages. Used in `open` and `preload`.
         | 
| 463 564 | 
             
                _loadPages: function(url, data, callback) {
         | 
| 464 | 
            -
                  var body = $('body',  | 
| 565 | 
            +
                  var body = $('body', self._doc).addClass('page-loading');
         | 
| 465 566 | 
             
                    body.trigger('page-loading', data);
         | 
| 466 567 | 
             
                    if ( data.link ) {
         | 
| 467 568 | 
             
                      data.link.addClass('page-loading');
         | 
| 468 569 | 
             
                      data.link.trigger('page-loading', data);
         | 
| 469 570 | 
             
                    }
         | 
| 470 571 |  | 
| 471 | 
            -
                     | 
| 572 | 
            +
                    if ( self._loading ) {
         | 
| 573 | 
            +
                      self.stopLoading(self._loading);
         | 
| 574 | 
            +
                    }
         | 
| 575 | 
            +
             | 
| 576 | 
            +
                    self._loading = self.load(url, data, function(html) {
         | 
| 577 | 
            +
                      self._loading = null;
         | 
| 578 | 
            +
             | 
| 472 579 | 
             
                      var nodes = $(html);
         | 
| 473 | 
            -
                      if (  | 
| 474 | 
            -
                         | 
| 580 | 
            +
                      if ( self.current.length ) {
         | 
| 581 | 
            +
                        self.current.after(nodes);
         | 
| 475 582 | 
             
                      } else {
         | 
| 476 | 
            -
                         | 
| 583 | 
            +
                        $(self._doc.body).append(nodes);
         | 
| 477 584 | 
             
                      }
         | 
| 478 585 |  | 
| 479 586 | 
             
                      body.removeClass('page-loading');
         | 
| @@ -483,41 +590,19 @@ | |
| 483 590 | 
             
                        data.link.trigger('page-loaded', data);
         | 
| 484 591 | 
             
                      }
         | 
| 485 592 |  | 
| 486 | 
            -
                       | 
| 593 | 
            +
                      self._enlive(nodes);
         | 
| 487 594 | 
             
                      callback(nodes);
         | 
| 488 595 | 
             
                    });
         | 
| 489 596 | 
             
                }
         | 
| 490 597 |  | 
| 491 598 | 
             
              };
         | 
| 492 599 |  | 
| 493 | 
            -
              // The simplest “animation”. Just immediately hide/show pages
         | 
| 494 | 
            -
              // by CSS display property.
         | 
| 495 | 
            -
              Pages.animations.immediately = {
         | 
| 496 | 
            -
                animate: function(prev, next, done, data) {
         | 
| 497 | 
            -
                  prev.hide();
         | 
| 498 | 
            -
                  next.show();
         | 
| 499 | 
            -
                  done();
         | 
| 500 | 
            -
                }
         | 
| 501 | 
            -
              };
         | 
| 502 | 
            -
             | 
| 503 | 
            -
              // Simple fade in/out animation.
         | 
| 504 | 
            -
              Pages.animations.fade = {
         | 
| 505 | 
            -
                // Animation duration in milliseconds.
         | 
| 506 | 
            -
                duration: 300,
         | 
| 507 | 
            -
             | 
| 508 | 
            -
                animate: function(prev, next, done, data) {
         | 
| 509 | 
            -
                  var half = this.duration / 2;
         | 
| 510 | 
            -
                  prev.fadeOut(half, function() {
         | 
| 511 | 
            -
                    next.fadeIn(half, done);
         | 
| 512 | 
            -
                  });
         | 
| 513 | 
            -
                }
         | 
| 514 | 
            -
              };
         | 
| 515 | 
            -
             | 
| 516 600 | 
             
              $(document).ready(function() {
         | 
| 517 | 
            -
                 | 
| 518 | 
            -
                 | 
| 519 | 
            -
                if ( ! | 
| 520 | 
            -
                   | 
| 601 | 
            +
                self._lastUrl = self.getURL();
         | 
| 602 | 
            +
                self.init();
         | 
| 603 | 
            +
                if ( !self.disabled ) {
         | 
| 604 | 
            +
                  self.enable();
         | 
| 521 605 | 
             
                }
         | 
| 522 606 | 
             
              });
         | 
| 523 | 
            -
             | 
| 607 | 
            +
             | 
| 608 | 
            +
            })(jQuery);
         | 
    
        metadata
    CHANGED
    
    | @@ -1,32 +1,32 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: pagesjs
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0.5
         | 
| 5 4 | 
             
              prerelease: 
         | 
| 5 | 
            +
              version: 0.1.0
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| 8 8 | 
             
            - Andrey "A.I." Sitnik
         | 
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012- | 
| 12 | 
            +
            date: 2012-11-30 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              type: :runtime
         | 
| 15 16 | 
             
              name: sprockets
         | 
| 17 | 
            +
              prerelease: false
         | 
| 16 18 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            -
                none: false
         | 
| 18 19 | 
             
                requirements:
         | 
| 19 20 | 
             
                - - ! '>='
         | 
| 20 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 21 22 | 
             
                    version: '2'
         | 
| 22 | 
            -
              type: :runtime
         | 
| 23 | 
            -
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 23 | 
             
                none: false
         | 
| 24 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 25 | 
             
                requirements:
         | 
| 27 26 | 
             
                - - ! '>='
         | 
| 28 27 | 
             
                  - !ruby/object:Gem::Version
         | 
| 29 28 | 
             
                    version: '2'
         | 
| 29 | 
            +
                none: false
         | 
| 30 30 | 
             
            description: Pages.js allow you to manage pages JS code and forget about low-level
         | 
| 31 31 | 
             
              History API.
         | 
| 32 32 | 
             
            email:
         | 
| @@ -50,17 +50,17 @@ rdoc_options: [] | |
| 50 50 | 
             
            require_paths:
         | 
| 51 51 | 
             
            - lib
         | 
| 52 52 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 53 | 
            -
              none: false
         | 
| 54 53 | 
             
              requirements:
         | 
| 55 54 | 
             
              - - ! '>='
         | 
| 56 55 | 
             
                - !ruby/object:Gem::Version
         | 
| 57 56 | 
             
                  version: '0'
         | 
| 58 | 
            -
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 59 57 | 
             
              none: false
         | 
| 58 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 60 59 | 
             
              requirements:
         | 
| 61 60 | 
             
              - - ! '>='
         | 
| 62 61 | 
             
                - !ruby/object:Gem::Version
         | 
| 63 62 | 
             
                  version: '0'
         | 
| 63 | 
            +
              none: false
         | 
| 64 64 | 
             
            requirements: []
         | 
| 65 65 | 
             
            rubyforge_project: 
         | 
| 66 66 | 
             
            rubygems_version: 1.8.23
         |