From 304995bb048ab9ceabd4c1edc436c33a4f464ea6 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Tue, 6 Jan 2015 10:37:14 -0500 Subject: [PATCH] chore(all): prepare release 0.2.0 --- bower.json | 2 +- dist/amd/index.js | 47 ++++----- dist/commonjs/index.js | 51 +++++----- dist/es6/index.js | 35 +++---- dist/system/index.js | 226 +++++++++++++++++++++++++++++++++++++++++ doc/CHANGELOG.md | 14 +++ doc/api.json | 2 +- package.json | 2 +- 8 files changed, 302 insertions(+), 77 deletions(-) create mode 100644 dist/system/index.js diff --git a/bower.json b/bower.json index 76e2788..db1679a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-history-browser", - "version": "0.1.1", + "version": "0.2.0", "description": "An implementation of the Aurelia history interface based on standard browser hash change and push state mechanisms.", "keywords": [ "aurelia", diff --git a/dist/amd/index.js b/dist/amd/index.js index 27945e3..7affff4 100644 --- a/dist/amd/index.js +++ b/dist/amd/index.js @@ -1,8 +1,11 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { "use strict"; - var _extends = function (child, parent) { - child.prototype = Object.create(parent.prototype, { + var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } + child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, enumerable: false, @@ -10,7 +13,7 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { configurable: true } }); - child.__proto__ = parent; + if (parent) child.__proto__ = parent; }; var History = _aureliaHistory.History; @@ -31,23 +34,8 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { } } - function extend(obj) { - var rest = Array.prototype.slice.call(arguments, 1); - - for (var i = 0, length = rest.length; i < length; i++) { - var source = rest[i]; - - if (source) { - for (var prop in source) { - obj[prop] = source[prop]; - } - } - } - - return obj; - } - - var BrowserHistory = (function (History) { + var BrowserHistory = (function () { + var _History = History; var BrowserHistory = function BrowserHistory() { this.interval = 50; this.active = false; @@ -60,7 +48,7 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { } }; - _extends(BrowserHistory, History); + _inherits(BrowserHistory, _History); BrowserHistory.prototype.getHash = function (window) { var match = (window || this).location.href.match(/#(.*)$/); @@ -68,10 +56,12 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { }; BrowserHistory.prototype.getFragment = function (fragment, forcePushState) { + var root; + if (!fragment) { if (this._hasPushState || !this._wantsHashChange || forcePushState) { fragment = this.location.pathname + this.location.search; - var root = this.root.replace(trailingSlash, ""); + root = this.root.replace(trailingSlash, ""); if (!fragment.indexOf(root)) { fragment = fragment.substr(root.length); } @@ -90,7 +80,7 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { this.active = true; - this.options = extend({}, { root: "/" }, this.options, options); + this.options = Object.assign({}, { root: "/" }, this.options, options); this.root = this.options.root; this._wantsHashChange = this.options.hashChange !== false; this._wantsPushState = !!this.options.pushState; @@ -102,7 +92,7 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { if (this._hasPushState) { window.onpopstate = this._checkUrlCallback; - } else if (this._wantsHashChange && ("onhashchange" in window)) { + } else if (this._wantsHashChange && "onhashchange" in window) { window.addEventListener("hashchange", this._checkUrlCallback); } else if (this._wantsHashChange) { this._checkUrlInterval = setInterval(this._checkUrlCallback, this.interval); @@ -199,7 +189,7 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { } else if (this._wantsHashChange) { updateHash(this.location, fragment, options.replace); - if (this.iframe && (fragment !== this.getFragment(this.getHash(this.iframe)))) { + if (this.iframe && fragment !== this.getFragment(this.getHash(this.iframe))) { if (!options.replace) { this.iframe.document.open().close(); } @@ -222,7 +212,12 @@ define(["exports", "aurelia-history"], function (exports, _aureliaHistory) { }; return BrowserHistory; - })(History); + })(); + + function install(aurelia) { + aurelia.withSingleton(History, BrowserHistory); + } exports.BrowserHistory = BrowserHistory; + exports.install = install; }); \ No newline at end of file diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js index 20a403a..aa268cc 100644 --- a/dist/commonjs/index.js +++ b/dist/commonjs/index.js @@ -1,7 +1,10 @@ "use strict"; -var _extends = function (child, parent) { - child.prototype = Object.create(parent.prototype, { +var _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } + child.prototype = Object.create(parent && parent.prototype, { constructor: { value: child, enumerable: false, @@ -9,10 +12,10 @@ var _extends = function (child, parent) { configurable: true } }); - child.__proto__ = parent; + if (parent) child.__proto__ = parent; }; -var History = require('aurelia-history').History; +var History = require("aurelia-history").History; var routeStripper = /^[#\/]|\s+$/g; var rootStripper = /^\/+|\/+$/g; @@ -30,23 +33,8 @@ function updateHash(location, fragment, replace) { } } -function extend(obj) { - var rest = Array.prototype.slice.call(arguments, 1); - - for (var i = 0, length = rest.length; i < length; i++) { - var source = rest[i]; - - if (source) { - for (var prop in source) { - obj[prop] = source[prop]; - } - } - } - - return obj; -} - -var BrowserHistory = (function (History) { +var BrowserHistory = (function () { + var _History = History; var BrowserHistory = function BrowserHistory() { this.interval = 50; this.active = false; @@ -59,7 +47,7 @@ var BrowserHistory = (function (History) { } }; - _extends(BrowserHistory, History); + _inherits(BrowserHistory, _History); BrowserHistory.prototype.getHash = function (window) { var match = (window || this).location.href.match(/#(.*)$/); @@ -67,10 +55,12 @@ var BrowserHistory = (function (History) { }; BrowserHistory.prototype.getFragment = function (fragment, forcePushState) { + var root; + if (!fragment) { if (this._hasPushState || !this._wantsHashChange || forcePushState) { fragment = this.location.pathname + this.location.search; - var root = this.root.replace(trailingSlash, ""); + root = this.root.replace(trailingSlash, ""); if (!fragment.indexOf(root)) { fragment = fragment.substr(root.length); } @@ -89,7 +79,7 @@ var BrowserHistory = (function (History) { this.active = true; - this.options = extend({}, { root: "/" }, this.options, options); + this.options = Object.assign({}, { root: "/" }, this.options, options); this.root = this.options.root; this._wantsHashChange = this.options.hashChange !== false; this._wantsPushState = !!this.options.pushState; @@ -101,7 +91,7 @@ var BrowserHistory = (function (History) { if (this._hasPushState) { window.onpopstate = this._checkUrlCallback; - } else if (this._wantsHashChange && ("onhashchange" in window)) { + } else if (this._wantsHashChange && "onhashchange" in window) { window.addEventListener("hashchange", this._checkUrlCallback); } else if (this._wantsHashChange) { this._checkUrlInterval = setInterval(this._checkUrlCallback, this.interval); @@ -198,7 +188,7 @@ var BrowserHistory = (function (History) { } else if (this._wantsHashChange) { updateHash(this.location, fragment, options.replace); - if (this.iframe && (fragment !== this.getFragment(this.getHash(this.iframe)))) { + if (this.iframe && fragment !== this.getFragment(this.getHash(this.iframe))) { if (!options.replace) { this.iframe.document.open().close(); } @@ -221,6 +211,11 @@ var BrowserHistory = (function (History) { }; return BrowserHistory; -})(History); +})(); + +function install(aurelia) { + aurelia.withSingleton(History, BrowserHistory); +} -exports.BrowserHistory = BrowserHistory; \ No newline at end of file +exports.BrowserHistory = BrowserHistory; +exports.install = install; \ No newline at end of file diff --git a/dist/es6/index.js b/dist/es6/index.js index 963cbe8..629491a 100644 --- a/dist/es6/index.js +++ b/dist/es6/index.js @@ -24,23 +24,7 @@ function updateHash(location, fragment, replace) { } } -function extend(obj) { - var rest = Array.prototype.slice.call(arguments, 1); - - for (var i = 0, length = rest.length; i < length; i++) { - var source = rest[i]; - - if (source) { - for (var prop in source) { - obj[prop] = source[prop]; - } - } - } - - return obj; -} - -export class BrowserHistory extends History { +class BrowserHistory extends History { constructor(){ this.interval = 50; this.active = false; @@ -59,10 +43,12 @@ export class BrowserHistory extends History { } getFragment(fragment, forcePushState) { + var root; + if (!fragment) { if (this._hasPushState || !this._wantsHashChange || forcePushState) { fragment = this.location.pathname + this.location.search; - var root = this.root.replace(trailingSlash, ''); + root = this.root.replace(trailingSlash, ''); if (!fragment.indexOf(root)) { fragment = fragment.substr(root.length); } @@ -83,7 +69,7 @@ export class BrowserHistory extends History { // Figure out the initial configuration. Do we need an iframe? // Is pushState desired ... is it available? - this.options = extend({}, { root: '/' }, this.options, options); + this.options = Object.assign({}, { root: '/' }, this.options, options); this.root = this.options.root; this._wantsHashChange = this.options.hashChange !== false; this._wantsPushState = !!this.options.pushState; @@ -238,4 +224,13 @@ export class BrowserHistory extends History { navigateBack() { this.history.back(); } -} \ No newline at end of file +} + +function install(aurelia){ + aurelia.withSingleton(History, BrowserHistory); +} + +export { + BrowserHistory, + install +}; \ No newline at end of file diff --git a/dist/system/index.js b/dist/system/index.js new file mode 100644 index 0000000..58b0aa5 --- /dev/null +++ b/dist/system/index.js @@ -0,0 +1,226 @@ +System.register(["aurelia-history"], function (_export) { + "use strict"; + + var History, _inherits, routeStripper, rootStripper, isExplorer, trailingSlash, BrowserHistory; + function updateHash(location, fragment, replace) { + if (replace) { + var href = location.href.replace(/(javascript:|#).*$/, ""); + location.replace(href + "#" + fragment); + } else { + location.hash = "#" + fragment; + } + } + + function install(aurelia) { + aurelia.withSingleton(History, BrowserHistory); + } + + return { + setters: [function (_aureliaHistory) { + History = _aureliaHistory.History; + }], + execute: function () { + _inherits = function (child, parent) { + if (typeof parent !== "function" && parent !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof parent); + } + child.prototype = Object.create(parent && parent.prototype, { + constructor: { + value: child, + enumerable: false, + writable: true, + configurable: true + } + }); + if (parent) child.__proto__ = parent; + }; + + routeStripper = /^[#\/]|\s+$/g; + rootStripper = /^\/+|\/+$/g; + isExplorer = /msie [\w.]+/; + trailingSlash = /\/$/; + BrowserHistory = (function () { + var _History = History; + var BrowserHistory = function BrowserHistory() { + this.interval = 50; + this.active = false; + this.previousFragment = ""; + this._checkUrlCallback = this.checkUrl.bind(this); + + if (typeof window !== "undefined") { + this.location = window.location; + this.history = window.history; + } + }; + + _inherits(BrowserHistory, _History); + + BrowserHistory.prototype.getHash = function (window) { + var match = (window || this).location.href.match(/#(.*)$/); + return match ? match[1] : ""; + }; + + BrowserHistory.prototype.getFragment = function (fragment, forcePushState) { + var root; + + if (!fragment) { + if (this._hasPushState || !this._wantsHashChange || forcePushState) { + fragment = this.location.pathname + this.location.search; + root = this.root.replace(trailingSlash, ""); + if (!fragment.indexOf(root)) { + fragment = fragment.substr(root.length); + } + } else { + fragment = this.getHash(); + } + } + + return fragment.replace(routeStripper, ""); + }; + + BrowserHistory.prototype.activate = function (options) { + if (this.active) { + throw new Error("History has already been activated."); + } + + this.active = true; + + this.options = Object.assign({}, { root: "/" }, this.options, options); + this.root = this.options.root; + this._wantsHashChange = this.options.hashChange !== false; + this._wantsPushState = !!this.options.pushState; + this._hasPushState = !!(this.options.pushState && this.history && this.history.pushState); + + var fragment = this.getFragment(); + + this.root = ("/" + this.root + "/").replace(rootStripper, "/"); + + if (this._hasPushState) { + window.onpopstate = this._checkUrlCallback; + } else if (this._wantsHashChange && "onhashchange" in window) { + window.addEventListener("hashchange", this._checkUrlCallback); + } else if (this._wantsHashChange) { + this._checkUrlInterval = setInterval(this._checkUrlCallback, this.interval); + } + + this.fragment = fragment; + + var loc = this.location; + var atRoot = loc.pathname.replace(/[^\/]$/, "$&/") === this.root; + + if (this._wantsHashChange && this._wantsPushState) { + if (!this._hasPushState && !atRoot) { + this.fragment = this.getFragment(null, true); + this.location.replace(this.root + this.location.search + "#" + this.fragment); + return true; + } else if (this._hasPushState && atRoot && loc.hash) { + this.fragment = this.getHash().replace(routeStripper, ""); + this["this"].replaceState({}, document.title, this.root + this.fragment + loc.search); + } + } + + if (!this.options.silent) { + return this.loadUrl(); + } + }; + + BrowserHistory.prototype.deactivate = function () { + window.onpopstate = null; + window.removeEventListener("hashchange", this._checkUrlCallback); + clearInterval(this._checkUrlInterval); + this.active = false; + }; + + BrowserHistory.prototype.checkUrl = function () { + var current = this.getFragment(); + + if (current === this.fragment && this.iframe) { + current = this.getFragment(this.getHash(this.iframe)); + } + + if (current === this.fragment) { + return false; + } + + if (this.iframe) { + this.navigate(current, false); + } + + this.loadUrl(); + }; + + BrowserHistory.prototype.loadUrl = function (fragmentOverride) { + var fragment = this.fragment = this.getFragment(fragmentOverride); + + return this.options.routeHandler ? this.options.routeHandler(fragment) : false; + }; + + BrowserHistory.prototype.navigate = function (fragment, options) { + if (fragment && fragment.indexOf("://") != -1) { + window.location.href = fragment; + return true; + } + + if (!this.active) { + return false; + } + + if (options === undefined) { + options = { + trigger: true + }; + } else if (typeof options === "boolean") { + options = { + trigger: options + }; + } + + fragment = this.getFragment(fragment || ""); + + if (this.fragment === fragment) { + return; + } + + this.fragment = fragment; + + var url = this.root + fragment; + + if (fragment === "" && url !== "/") { + url = url.slice(0, -1); + } + + if (this._hasPushState) { + this.history[options.replace ? "replaceState" : "pushState"]({}, document.title, url); + } else if (this._wantsHashChange) { + updateHash(this.location, fragment, options.replace); + + if (this.iframe && fragment !== this.getFragment(this.getHash(this.iframe))) { + if (!options.replace) { + this.iframe.document.open().close(); + } + + updateHash(this.iframe.location, fragment, options.replace); + } + } else { + return this.location.assign(url); + } + + if (options.trigger) { + return this.loadUrl(fragment); + } else { + this.previousFragment = fragment; + } + }; + + BrowserHistory.prototype.navigateBack = function () { + this.history.back(); + }; + + return BrowserHistory; + })(); + _export("BrowserHistory", BrowserHistory); + + _export("install", install); + } + }; +}); \ No newline at end of file diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 0accca4..e3a0566 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,17 @@ +## 0.2.0 (2015-01-06) + + +#### Bug Fixes + +* **package:** add es6-shim dependency for Object.assign ([517b7e8e](http://github.com/aurelia/history-browser/commit/517b7e8ee94ba18ce662af21a7fdd594d9ed8adb)) + + +#### Features + +* **build:** update compiler and switch to register module format ([ff2a572b](http://github.com/aurelia/history-browser/commit/ff2a572b4858ce16eea17b66ded4912b89919d85)) +* **history:** enable usage as plugin ([f73c967b](http://github.com/aurelia/history-browser/commit/f73c967b64d75da43d31ad8b7305c495ebdf08a8)) + + ### 0.1.1 (2014-12-17) diff --git a/doc/api.json b/doc/api.json index b648957..6de3c0a 100644 --- a/doc/api.json +++ b/doc/api.json @@ -1 +1 @@ -{"project":{},"files":{},"modules":{},"classes":{},"classitems":[],"warnings":[]} \ No newline at end of file +{"classes":[],"methods":[],"properties":[],"events":[]} \ No newline at end of file diff --git a/package.json b/package.json index c41e7c8..4158d74 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-history-browser", - "version": "0.1.1", + "version": "0.2.0", "description": "An implementation of the Aurelia history interface based on standard browser hash change and push state mechanisms.", "keywords": [ "aurelia",