Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zayesh/stay

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zayesh/stay - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

37

build/stay.js

@@ -309,4 +309,6 @@ /**

{
var formData, parts, url, post = false;
var formData, pathname, url, post = false;
this.locked = true;
if(firingElement.action)

@@ -324,15 +326,13 @@ {

parts = getUrlParts(this.absolutePath);
this.locked = true;
pathname = getUrlParts(this.absolutePath).pathname;
if(pathname.charAt(0) !== "/") { pathname = "/" + pathname; }
// Special treatment for the index page.
url = (parts.pathname === index) ?
this.absolutePath.slice(0, this.absolutePath.length - 1) + this.infix + parts.pathname :
this.absolutePath.replace(new RegExp(parts.pathname), this.infix + parts.pathname);
url = (pathname === index) ?
this.absolutePath.slice(0, this.absolutePath.length - 1) + this.infix + pathname :
this.absolutePath.replace(new RegExp(pathname), this.infix + pathname);
this.eventNavigate.method = post ? "POST" : "GET";
this.dispatchEvent(this.eventNavigate);
this.xhr.open(this.eventNavigate.method, url, true);
this.xhr.responseType = "json";

@@ -499,18 +499,11 @@ if(post)

{
if(xhr.response !== undefined)
try
{
response = xhr.response;
response = JSON.parse(xhr.responseText);
}
else
catch(e)
{
try
{
response = JSON.parse(xhr.responseText);
}
catch(e)
{
response.title = "Parse Error";
response[this.responseFields[0]] = Stay.Error.UNPARSABLE;
console.log(e);
}
response.title = "Parse Error";
response[this.responseFields[0]] = Stay.Error.UNPARSABLE;
console.log(e);
}

@@ -536,3 +529,3 @@

UNPARSABLE: "<p>The received content could not be parsed.</p>",
NO_RESPONSE_FIELDS: "<p>No response fields have been specified.</p>"
NO_RESPONSE_FIELDS: "<p>No response fields have been specified!</p>"
});

@@ -539,0 +532,0 @@

@@ -18,2 +18,2 @@ /**

*/
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Stay=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";function d(){this._listeners={}}d.prototype.addEventListener=function(a,b){void 0===this._listeners[a]&&(this._listeners[a]=[]),-1===this._listeners[a].indexOf(b)&&this._listeners[a].push(b)},d.prototype.hasEventListener=function(a,b){return void 0!==this._listeners[a]&&-1!==this._listeners[a].indexOf(b)},d.prototype.removeEventListener=function(a,b){var c,d=this._listeners,e=d[a];void 0!==e&&(c=e.indexOf(b),-1!==c&&e.splice(c,1))},d.prototype.dispatchEvent=function(a){var b,c,d=this._listeners,e=d[a.type];if(void 0!==e)for(a.target=this,b=0,c=e.length;c>b;++b)e[b].call(this,a)},b.exports=d},{}],2:[function(a,b,c){"use strict";function d(a){var b=document.createElement("a");return b.href=a,b}function Stay(a){var b=this;if(e.call(this),this.responseFields=["main","navigation","footer"],this.infix="/json",this.timeoutPost=6e4,this.timeoutGet=5e3,this.autoUpdate=!0,void 0!==a&&(void 0!==a.responseFields&&(this.responseFields=a.responseFields),void 0!==a.infix&&(this.infix=a.infix),void 0!==a.timeoutPost&&(this.timeoutPost=a.timeoutPost),void 0!==a.timeoutGet&&(this.timeoutGet=a.timeoutGet),void 0!==a.autoUpdate&&(this.autoUpdate=a.autoUpdate)),this.locked=!1,this.backForward=!1,this.absolutePath=null,this.containers=[],this.intermediateContainer=null,this.navigationListeners=[],this.eventNavigate={type:"navigate"},this.eventReceive={type:"receive",response:null},this.eventLoad={type:"load"},void 0===XMLHttpRequest)throw new Error("XMLHttpRequest functionality not available.");this.xhr=new XMLHttpRequest,this.xhr.addEventListener("readystatechange",function(a){b._handleResponse(this,a)}),this.xhr.addEventListener("timeout",function(){var a={};b.responseFields.length&&(a.title="Timeout Error",a[b.responseFields[0]]=Stay.Error.TIMEOUT,b.locked=!0,b.update(a))}),window.addEventListener("popstate",function(a){b.locked||null===a.state||(b.backForward=!0,b._navigate({href:a.state.url}))}),this._switchPage=function(a){var c=void 0!==a.preventDefault,d=!1;return"submit"===a.type?d=!0:a.metaKey||a.shiftKey||a.altKey||a.ctrlKey||(void 0!==a.which?d=1===a.which:void 0!==a.button&&(d=0===a.button)),d&&(c&&a.preventDefault(),b.locked||b._navigate(this)),!(d&&!c)},this._updateListeners()}var e=a("@zayesh/eventdispatcher"),f="/";Stay.prototype=Object.create(e.prototype),Stay.prototype.constructor=Stay,Stay.prototype.addResponseField=function(a){-1===this.responseFields.indexOf(a)&&this.responseFields.push(a)},Stay.prototype.removeResponseField=function(a){var b=this.responseFields.indexOf(a);-1!==b&&this.responseFields.splice(b,1)},Stay.prototype._navigate=function(a){var b,c,e,g=!1;a.action?(this.absolutePath=a.action,b=new FormData(a),g=!0):this.absolutePath=a.href,c=d(this.absolutePath),this.locked=!0,e=c.pathname===f?this.absolutePath.slice(0,this.absolutePath.length-1)+this.infix+c.pathname:this.absolutePath.replace(new RegExp(c.pathname),this.infix+c.pathname),this.eventNavigate.method=g?"POST":"GET",this.dispatchEvent(this.eventNavigate),this.xhr.open(this.eventNavigate.method,e,!0),this.xhr.responseType="json",g?(this.xhr.timeout=this.timeoutPost,this.xhr.send(b)):(this.xhr.timeout=this.timeoutGet,this.xhr.send())},Stay.prototype._updateView=function(a){var b,c,d,e,f=!1;if(null===this.intermediateContainer)this.intermediateContainer=document.createElement("div");else for(;this.intermediateContainer.children.length>0;)this.intermediateContainer.removeChild(this.intermediateContainer.children[0]);for(b=0,c=this.responseFields.length;c>b;++b)if(d=this.containers[this.responseFields[b]],d||(d=this.containers[this.responseFields[b]]=document.getElementById(this.responseFields[b])),e=a[this.responseFields[b]]){for(;d.children.length>0;)d.removeChild(d.children[0]);for(this.intermediateContainer.innerHTML=e;this.intermediateContainer.children.length>0;)d.appendChild(this.intermediateContainer.children[0]);f=!0}f&&this._updateListeners()},Stay.prototype._updateListeners=function(){var a,b,c=this,d=document.getElementsByTagName("a"),e=document.getElementsByTagName("form");for(a=0,b=this.navigationListeners.length;b>a;++a)this.navigationListeners[a][0].removeEventListener(this.navigationListeners[a][1],c._switchPage);for(a=0,b=d.length;b>a;++a)d[a].addEventListener("click",c._switchPage),this.navigationListeners.push([d[a],"click"]);for(a=0,b=e.length;b>a;++a)e[a].addEventListener("submit",c._switchPage),this.navigationListeners.push([e[a],"submit"])},Stay.prototype.update=function(a){this._updateView(a),document.title=a.title,a.url&&(this.absolutePath=a.url.replace(this.infix,"")),this.backForward?this.backForward=!1:history.pushState({url:this.absolutePath},a.title,this.absolutePath),this.eventReceive.response=null,this.dispatchEvent(this.eventLoad),this.locked=!1},Stay.prototype._handleResponse=function(a){var b={};if(0===this.responseFields.length)b.title="Setup Error",b[this.responseFields[0]]=Stay.Error.NO_RESPONSE_FIELDS;else if(4===a.readyState){if(void 0!==a.response)b=a.response;else try{b=JSON.parse(a.responseText)}catch(c){b.title="Parse Error",b[this.responseFields[0]]=Stay.Error.UNPARSABLE,console.log(c)}b.url=a.responseURL,this.eventReceive.response=b,this.dispatchEvent(this.eventReceive),this.autoUpdate&&this.update(b)}},Stay.Error=Object.freeze({TIMEOUT:"<p>The server didn't respond in time. Please try again later!</p>",UNPARSABLE:"<p>The received content could not be parsed.</p>",NO_RESPONSE_FIELDS:"<p>No response fields have been specified.</p>"}),b.exports=Stay},{"@zayesh/eventdispatcher":1}]},{},[2])(2)});
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Stay=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){"use strict";function d(){this._listeners={}}d.prototype.addEventListener=function(a,b){void 0===this._listeners[a]&&(this._listeners[a]=[]),-1===this._listeners[a].indexOf(b)&&this._listeners[a].push(b)},d.prototype.hasEventListener=function(a,b){return void 0!==this._listeners[a]&&-1!==this._listeners[a].indexOf(b)},d.prototype.removeEventListener=function(a,b){var c,d=this._listeners,e=d[a];void 0!==e&&(c=e.indexOf(b),-1!==c&&e.splice(c,1))},d.prototype.dispatchEvent=function(a){var b,c,d=this._listeners,e=d[a.type];if(void 0!==e)for(a.target=this,b=0,c=e.length;c>b;++b)e[b].call(this,a)},b.exports=d},{}],2:[function(a,b,c){"use strict";function d(a){var b=document.createElement("a");return b.href=a,b}function Stay(a){var b=this;if(e.call(this),this.responseFields=["main","navigation","footer"],this.infix="/json",this.timeoutPost=6e4,this.timeoutGet=5e3,this.autoUpdate=!0,void 0!==a&&(void 0!==a.responseFields&&(this.responseFields=a.responseFields),void 0!==a.infix&&(this.infix=a.infix),void 0!==a.timeoutPost&&(this.timeoutPost=a.timeoutPost),void 0!==a.timeoutGet&&(this.timeoutGet=a.timeoutGet),void 0!==a.autoUpdate&&(this.autoUpdate=a.autoUpdate)),this.locked=!1,this.backForward=!1,this.absolutePath=null,this.containers=[],this.intermediateContainer=null,this.navigationListeners=[],this.eventNavigate={type:"navigate"},this.eventReceive={type:"receive",response:null},this.eventLoad={type:"load"},void 0===XMLHttpRequest)throw new Error("XMLHttpRequest functionality not available.");this.xhr=new XMLHttpRequest,this.xhr.addEventListener("readystatechange",function(a){b._handleResponse(this,a)}),this.xhr.addEventListener("timeout",function(){var a={};b.responseFields.length&&(a.title="Timeout Error",a[b.responseFields[0]]=Stay.Error.TIMEOUT,b.locked=!0,b.update(a))}),window.addEventListener("popstate",function(a){b.locked||null===a.state||(b.backForward=!0,b._navigate({href:a.state.url}))}),this._switchPage=function(a){var c=void 0!==a.preventDefault,d=!1;return"submit"===a.type?d=!0:a.metaKey||a.shiftKey||a.altKey||a.ctrlKey||(void 0!==a.which?d=1===a.which:void 0!==a.button&&(d=0===a.button)),d&&(c&&a.preventDefault(),b.locked||b._navigate(this)),!(d&&!c)},this._updateListeners()}var e=a("@zayesh/eventdispatcher"),f="/";Stay.prototype=Object.create(e.prototype),Stay.prototype.constructor=Stay,Stay.prototype.addResponseField=function(a){-1===this.responseFields.indexOf(a)&&this.responseFields.push(a)},Stay.prototype.removeResponseField=function(a){var b=this.responseFields.indexOf(a);-1!==b&&this.responseFields.splice(b,1)},Stay.prototype._navigate=function(a){var b,c,e,g=!1;this.locked=!0,a.action?(this.absolutePath=a.action,b=new FormData(a),g=!0):this.absolutePath=a.href,c=d(this.absolutePath).pathname,"/"!==c.charAt(0)&&(c="/"+c),e=c===f?this.absolutePath.slice(0,this.absolutePath.length-1)+this.infix+c:this.absolutePath.replace(new RegExp(c),this.infix+c),this.eventNavigate.method=g?"POST":"GET",this.dispatchEvent(this.eventNavigate),this.xhr.open(this.eventNavigate.method,e,!0),g?(this.xhr.timeout=this.timeoutPost,this.xhr.send(b)):(this.xhr.timeout=this.timeoutGet,this.xhr.send())},Stay.prototype._updateView=function(a){var b,c,d,e,f=!1;if(null===this.intermediateContainer)this.intermediateContainer=document.createElement("div");else for(;this.intermediateContainer.children.length>0;)this.intermediateContainer.removeChild(this.intermediateContainer.children[0]);for(b=0,c=this.responseFields.length;c>b;++b)if(d=this.containers[this.responseFields[b]],d||(d=this.containers[this.responseFields[b]]=document.getElementById(this.responseFields[b])),e=a[this.responseFields[b]]){for(;d.children.length>0;)d.removeChild(d.children[0]);for(this.intermediateContainer.innerHTML=e;this.intermediateContainer.children.length>0;)d.appendChild(this.intermediateContainer.children[0]);f=!0}f&&this._updateListeners()},Stay.prototype._updateListeners=function(){var a,b,c=this,d=document.getElementsByTagName("a"),e=document.getElementsByTagName("form");for(a=0,b=this.navigationListeners.length;b>a;++a)this.navigationListeners[a][0].removeEventListener(this.navigationListeners[a][1],c._switchPage);for(a=0,b=d.length;b>a;++a)d[a].addEventListener("click",c._switchPage),this.navigationListeners.push([d[a],"click"]);for(a=0,b=e.length;b>a;++a)e[a].addEventListener("submit",c._switchPage),this.navigationListeners.push([e[a],"submit"])},Stay.prototype.update=function(a){this._updateView(a),document.title=a.title,a.url&&(this.absolutePath=a.url.replace(this.infix,"")),this.backForward?this.backForward=!1:history.pushState({url:this.absolutePath},a.title,this.absolutePath),this.eventReceive.response=null,this.dispatchEvent(this.eventLoad),this.locked=!1},Stay.prototype._handleResponse=function(a){var b={};if(0===this.responseFields.length)b.title="Setup Error",b[this.responseFields[0]]=Stay.Error.NO_RESPONSE_FIELDS;else if(4===a.readyState){try{b=JSON.parse(a.responseText)}catch(c){b.title="Parse Error",b[this.responseFields[0]]=Stay.Error.UNPARSABLE,console.log(c)}b.url=a.responseURL,this.eventReceive.response=b,this.dispatchEvent(this.eventReceive),this.autoUpdate&&this.update(b)}},Stay.Error=Object.freeze({TIMEOUT:"<p>The server didn't respond in time. Please try again later!</p>",UNPARSABLE:"<p>The received content could not be parsed.</p>",NO_RESPONSE_FIELDS:"<p>No response fields have been specified!</p>"}),b.exports=Stay},{"@zayesh/eventdispatcher":1}]},{},[2])(2)});

@@ -5,3 +5,3 @@ {

"keywords": ["xhr", "xmlhttprequest", "ajax", "web", "application"],
"version": "0.0.9",
"version": "0.0.10",
"homepage": "https://github.com/vanruesc/stay",

@@ -8,0 +8,0 @@ "author": {

@@ -196,4 +196,6 @@ "use strict";

{
var formData, parts, url, post = false;
var formData, pathname, url, post = false;
this.locked = true;
if(firingElement.action)

@@ -211,15 +213,13 @@ {

parts = getUrlParts(this.absolutePath);
this.locked = true;
pathname = getUrlParts(this.absolutePath).pathname;
if(pathname.charAt(0) !== "/") { pathname = "/" + pathname; }
// Special treatment for the index page.
url = (parts.pathname === index) ?
this.absolutePath.slice(0, this.absolutePath.length - 1) + this.infix + parts.pathname :
this.absolutePath.replace(new RegExp(parts.pathname), this.infix + parts.pathname);
url = (pathname === index) ?
this.absolutePath.slice(0, this.absolutePath.length - 1) + this.infix + pathname :
this.absolutePath.replace(new RegExp(pathname), this.infix + pathname);
this.eventNavigate.method = post ? "POST" : "GET";
this.dispatchEvent(this.eventNavigate);
this.xhr.open(this.eventNavigate.method, url, true);
this.xhr.responseType = "json";

@@ -386,18 +386,11 @@ if(post)

{
if(xhr.response !== undefined)
try
{
response = xhr.response;
response = JSON.parse(xhr.responseText);
}
else
catch(e)
{
try
{
response = JSON.parse(xhr.responseText);
}
catch(e)
{
response.title = "Parse Error";
response[this.responseFields[0]] = Stay.Error.UNPARSABLE;
console.log(e);
}
response.title = "Parse Error";
response[this.responseFields[0]] = Stay.Error.UNPARSABLE;
console.log(e);
}

@@ -423,3 +416,3 @@

UNPARSABLE: "<p>The received content could not be parsed.</p>",
NO_RESPONSE_FIELDS: "<p>No response fields have been specified.</p>"
NO_RESPONSE_FIELDS: "<p>No response fields have been specified!</p>"
});

@@ -426,0 +419,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc