From 8a8a00245f36f942aaf6986387d50ba69c6ad983 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Wed, 1 Jan 2025 17:38:35 -0500 Subject: [PATCH] update jHash to 2.2 --- index.html | 2 +- source_index.html | 2 +- jhash-2.1.min.js => sources/jhash-2.2.min.js | 35 +++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) rename jhash-2.1.min.js => sources/jhash-2.2.min.js (56%) mode change 100755 => 100644 diff --git a/index.html b/index.html index 2a487b2276..dde0442399 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@ - + diff --git a/source_index.html b/source_index.html index 569adc85a8..fd589476c5 100755 --- a/source_index.html +++ b/source_index.html @@ -8,7 +8,7 @@ - + diff --git a/jhash-2.1.min.js b/sources/jhash-2.2.min.js old mode 100755 new mode 100644 similarity index 56% rename from jhash-2.1.min.js rename to sources/jhash-2.2.min.js index 119147c198..3de3f7e58e --- a/jhash-2.1.min.js +++ b/sources/jhash-2.2.min.js @@ -1,17 +1,36 @@ -/* jHash v2.1 - http://jhash.codeplex.com - Copyright (c) 2013 Chris Pietschmann */ -(function(window){var ie_documentMode=window.document.documentMode;var hashChangeSupported=('onhashchange'in window)&&(ie_documentMode===undefined||ie_documentMode>7);var jHash=window.jHash={jhash:"2.1",change:function(handler){if(hashChangeSupported){attachEvent(window,"hashchange",handler);}else{eventHandlers.push(handler);}},unbind:function(handler){var i=0,len=0;if(hashChangeSupported){detachEvent(window,"hashchange",handler);}else{arrayRemove(eventHandlers,eventHandlers.indexOf(handler));} +/* +* jHash v2.2 +* https://github.com/crpietschmann/jHash +* Copyright (c) 2013-2023 Chris Pietschmann +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in the +* Software without restriction, including without limitation the rights to use, copy, +* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +* and to permit persons to whom the Software is furnished to do so, subject to the +* following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies +* or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +(function(window){var ie_documentMode=window.document.documentMode;var hashChangeSupported=('onhashchange'in window)&&(ie_documentMode===undefined||ie_documentMode>7);var jHash=window.jHash={jhash:"2.2",change:function(handler){if(hashChangeSupported){attachEvent(window,"hashchange",handler);}else{eventHandlers.push(handler);}},unbind:function(handler){var i=0,len=0;if(hashChangeSupported){detachEvent(window,"hashchange",handler);}else{arrayRemove(eventHandlers,eventHandlers.indexOf(handler));} return this;},val:function(name,value){var ho=jHash.query();if(arguments.length===2){ho[name.toLowerCase()]=(value===null?'':value);return this.set(this.root(),ho);}else if(arguments.length===1&&typeof(name)==='string'){return ho[name.toLowerCase()];}else if(typeof(name)==='object'){return this.set(this.root(),name);} return ho;},root:function(value){if(value===undefined){return parseHashRoot(window.location.hash);} return this.set(value,this.val());},set:function(root,query){var fullHashValue=null;if(root===null&&query===null){fullHashValue=null;}else if(query!==undefined){var rootValue=root;var queryValue=typeof(query)==="string"?query:objectToHash(query);if(queryValue.length>0){rootValue+='?';} fullHashValue=rootValue+queryValue;}else{fullHashValue=root;} -window.location.hash=fullHashValue;return this;},remove:function(name){var ho=jHash.query();ho[name.toLowerCase()]=undefined;return this.set(this.root(),ho);},query:function(){return hashToObject(window.location.hash);},clear:function(){window.location.hash='';return this;},clearQuery:function(){this.set(this.root());return this;},clearRoot:function(){this.set('',this.query());return this;},_routes:{},_routeHandlerRegistered:false,_defaultRoute:null,route:function(route,handler){this._routes[route]=handler;if(!this._routeHandlerRegistered){this._routeHandlerRegistered=true;jHash.change(routeHandler);}},processRoute:function(){routeHandler();},defaultRoute:function(root,query){if(arguments.length==0){return this._defaultRoute;} +window.location.hash=fullHashValue;return this;},remove:function(name){var ho=jHash.query();delete ho[name.toLowerCase()];return this.set(this.root(),ho);},query:function(){return hashToObject(window.location.hash);},clear:function(){window.location.hash='';return this;},clearQuery:function(){this.set(this.root());return this;},clearRoot:function(){this.set('',this.query());return this;},_routes:{},_routeHandlerRegistered:false,_defaultRoute:null,route:function(route,handler){this._routes[route]=handler;if(!this._routeHandlerRegistered){this._routeHandlerRegistered=true;jHash.change(routeHandler);}},processRoute:function(){routeHandler();},defaultRoute:function(root,query){if(arguments.length==0){return this._defaultRoute;} this._defaultRoute={root:root,query:query};}};if(!hashChangeSupported){window.setInterval(function(){var currentHash=window.location.hash;if(previousHashValue!==currentHash){for(var i in eventHandlers){eventHandlers[i].call(window);}} previousHashValue=currentHash;},200);} -var eventHandlers=[],previousHashValue=window.location.hash,attachEvent=function(element,evtName,handler){if(element.addEventListener){element.addEventListener(evtName,handler,false);}else if(element.attachEvent){element.attachEvent("on"+evtName,handler);}else{element["on"+evtName]+=handler;}},detachEvent=function(element,evtName,handler){if(element.removeEventListener){element.removeEventListener(evtName,handler,false);}else if(element.detachEvent){element.detachEvent("on"+evtName,handler);}else{element["on"+evtName]-=handler;}},arrayRemove=function(array,from,to){var rest=array.slice((to||from)+1||array.length);array.length=from<0?array.length+from:from;return array.push.apply(array,rest);},hashToObject=function(hash){var obj={},pair=null,strHash=hash.substring(0,hash.length);if(hash!==null&&hash!==undefined){if(strHash.indexOf("#")===0){strHash=strHash.substring(1,strHash.length);} -var queryIndex=strHash.indexOf("?");if(queryIndex>-1){strHash=strHash.substring(queryIndex+1,strHash.length);var parts=strHash.split("&");for(var i in parts){pair=parts[i].split("=");obj[pair[0].toString().toLowerCase()]=pair[1];}}} -return obj;},objectToHash=function(object){var s="";for(var i in object){if(object[i]!==undefined){if(s.length>0){s+="&";} -s+=i.toString()+"="+object[i].toString();}} -return s;},parseHashRoot=function(hash){var strHash=hash.substring(0,hash.length);if(strHash.indexOf("#")>-1){strHash=strHash.substring(1,strHash.length);} +var eventHandlers=[],previousHashValue=window.location.hash,attachEvent=function(element,evtName,handler){if(element.addEventListener){element.addEventListener(evtName,handler,false);}else if(element.attachEvent){element.attachEvent("on"+evtName,handler);}else{element["on"+evtName]+=handler;}},detachEvent=function(element,evtName,handler){if(element.removeEventListener){element.removeEventListener(evtName,handler,false);}else if(element.detachEvent){element.detachEvent("on"+evtName,handler);}else{element["on"+evtName]-=handler;}},arrayRemove=function(array,from,to){var rest=array.slice((to||from)+1||array.length);array.length=from<0?array.length+from:from;return array.push.apply(array,rest);},hashToObject=function(hash){var obj={},strHash=hash.substring(0,hash.length);if(hash!==null&&hash!==undefined){if(strHash.indexOf("#")===0){strHash=strHash.substring(1,strHash.length);} +var queryIndex=strHash.indexOf("?");if(queryIndex>-1){strHash=strHash.substring(queryIndex+1,strHash.length);(new URLSearchParams(strHash)).forEach(function(v,k){obj[k.toLowerCase()]=v;});}} +return obj;},objectToHash=function(object){return(new URLSearchParams(object)).toString();},parseHashRoot=function(hash){var strHash=hash.substring(0,hash.length);if(strHash.indexOf("#")>-1){strHash=strHash.substring(1,strHash.length);} if(strHash.indexOf("?")>-1){strHash=strHash.substring(0,strHash.indexOf("?"));} return strHash;},ROUTE_REPLACE="([^\/]+)",ROUTE_MATCH=/{([\w\d]+)}/g,getRouteMatches=function(route,root){var pathRegex=new RegExp(route.replace(ROUTE_MATCH,ROUTE_REPLACE)+"$") return root.match(pathRegex);},routeHandler=function(){var root=jHash.root();var defaultRoute=jHash.defaultRoute();if((root||'').length===0&&defaultRoute){jHash.set(defaultRoute.root,defaultRoute.query);return;}