Skip to content

Commit

Permalink
⬆️ 2.6.0 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Sep 7, 2021
1 parent acf4e96 commit 41ea0e6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
35 changes: 31 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const Url = module.exports = {

_onPopStateCbs: []
, _isHash: false
, current_location: ""
, previous_location: ""

/**
* queryString
Expand Down Expand Up @@ -172,10 +174,11 @@ const Url = module.exports = {
*
* @name getLocation
* @function
* @param {Boolean} excludeHash If `true`, the location hash will not be appended in the result.
* @return {String} The page url (without domain).
*/
, getLocation () {
return window.location.pathname + window.location.search + window.location.hash;
, getLocation (excludeHash) {
return window.location.pathname + window.location.search + (excludeHash ? "" : window.location.hash);
}

/**
Expand All @@ -198,7 +201,12 @@ const Url = module.exports = {
}, 0);
Url._isHash = true;
}
return location.hash = newHash;


location.hash = newHash;
Url.previous_location = Url.current_location
Url.current_location = Url.getLocation(true)
return newHash
}

/**
Expand All @@ -215,6 +223,10 @@ const Url = module.exports = {
* @return {String} The set url.
*/
, _updateAll (s, push, triggerPopState) {
if (push) {
Url.previous_location = Url.current_location
}
Url.current_location = Url.getLocation(true)
window.history[push ? "pushState" : "replaceState"](null, "", s);
if (triggerPopState) {
Url.triggerPopStateCb({});
Expand Down Expand Up @@ -250,6 +262,19 @@ const Url = module.exports = {
* @function
*/
, triggerPopStateCb (e) {

setTimeout(function () {
Url.current_location = Url.getLocation(true)
}, 0)

if (Url.previous_location === Url.current_location) {
Url._isHash = true
setTimeout(function () {
Url._isHash = false
window.history.back()
}, 0);
return
}
if (this._isHash) { return; }
this._onPopStateCbs.forEach(function (c) {
c(e)
Expand Down Expand Up @@ -298,5 +323,7 @@ const Url = module.exports = {
this._updateAll(window.location.pathname + window.location.hash, push || false, trigger || false);
}

, version: "2.5.0"
, version: "2.6.0"
};

Url.current_location = Url.getLocation(true)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "urljs",
"version": "2.5.0",
"version": "2.6.0",
"description": "A lightweight JavaScript library to manipulate the page url.",
"main": "lib/index.js",
"directories": {
Expand Down Expand Up @@ -89,4 +89,4 @@
}
]
}
}
}

0 comments on commit 41ea0e6

Please sign in to comment.