UNPKG

swup

Version:

Complete, flexible, extensible and easy to use page transition library for your web.

60 lines (52 loc) 1.81 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Cache = exports.Cache = function () { function Cache() { _classCallCheck(this, Cache); this.pages = {}; this.last = null; } _createClass(Cache, [{ key: 'cacheUrl', value: function cacheUrl(page) { if (page.url in this.pages === false) { this.pages[page.url] = page; } this.last = this.pages[page.url]; this.swup.log('Cache (' + Object.keys(this.pages).length + ')', this.pages); } }, { key: 'getPage', value: function getPage(url) { return this.pages[url]; } }, { key: 'getCurrentPage', value: function getCurrentPage() { return this.getPage(window.location.pathname + window.location.search); } }, { key: 'exists', value: function exists(url) { return url in this.pages; } }, { key: 'empty', value: function empty() { this.pages = {}; this.last = null; this.swup.log('Cache cleared'); } }, { key: 'remove', value: function remove(url) { delete this.pages[url]; } }]); return Cache; }(); exports.default = Cache;