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.1.3 to 0.1.4

84

build/stay.js
/**
* stay v0.1.3 build Sep 20 2015
* stay v0.1.4 build Sep 23 2015
* https://github.com/vanruesc/stay
* Copyright 2015 Raoul van Rueschen, Apache-2.0
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.Stay = factory();
}(this, function () { 'use strict';
var Stay = (function () { 'use strict';

@@ -294,2 +290,13 @@ /**

/**
* The current history state.
* Can't rely on history.state right now.
*
* @property historyState
* @type Object
* @private
*/
this.historyState = null;
/**
* A list of references to the response field DOM elements.

@@ -536,14 +543,23 @@ *

this.dispatchEvent(this.eventNavigate);
this.xhr.open(this.eventNavigate.method, url, true);
if(post) {
try {
this.xhr.timeout = this.timeoutPost;
this.xhr.send(formData);
this.xhr.open(this.eventNavigate.method, url, true);
} else {
if(post) {
this.xhr.timeout = this.timeoutGet;
this.xhr.send();
this.xhr.timeout = this.timeoutPost;
this.xhr.send(formData);
} else {
this.xhr.timeout = this.timeoutGet;
this.xhr.send();
}
} catch(error) {
this.dispatchEvent(error);
}

@@ -698,3 +714,3 @@

* The update function needs to be called after each navigation in
* order to unlock the system. This happens by default, but that
* order to unlock the system! This happens by default, but that
* behaviour can be disabled. It is then the responsibility of the

@@ -723,16 +739,40 @@ * programmer to call stay.update(response) with the response data

try {
if(this.historyState === null || this.absolutePath !== this.historyState.url) {
origin = document.origin ? document.origin : "null";
this.historyState = {
url: this.absolutePath,
time: Date.now(),
changed: true
};
if(origin !== "null" && history.state && this.absolutePath !== history.state.url) {
} else {
history.pushState({url: this.absolutePath}, response.meta.title, this.absolutePath);
this.historyState.changed = false;
}
}
} catch(e) {
origin = document.origin ? document.origin : "null";
console.warn(e);
// Only try to push in a server environment.
if(origin !== "null") {
try {
if(this.historyState.changed) {
history.pushState(this.historyState, response.meta.title, this.absolutePath);
} else {
history.replaceState(this.historyState, response.meta.title, this.absolutePath);
}
} catch(e) {
// Browser-specific history error.
console.warn(e);
}
}

@@ -818,2 +858,2 @@

}));
})();
/**
* stay v0.1.3 build Sep 20 2015
* stay v0.1.4 build Sep 23 2015
* https://github.com/vanruesc/stay
* Copyright 2015 Raoul van Rueschen, Apache-2.0
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Stay=e()}(this,function(){"use strict";function t(){this._listeners={}}function e(t){var e=document.createElement("a");return e.href=t,e.pathname}function i(e){var n=this;if(t.call(this),this.local=new RegExp("^"+location.protocol+"//"+location.host),this.stderr=null,this.infix="/json",this.timeoutPost=6e4,this.timeoutGet=5e3,this.autoUpdate=!0,void 0!==e&&(void 0!==e.stderr&&(this.stderr=e.stderr),void 0!==e.infix&&(this.infix=e.infix),void 0!==e.timeoutPost&&(this.timeoutPost=e.timeoutPost),void 0!==e.timeoutGet&&(this.timeoutGet=e.timeoutGet),void 0!==e.autoUpdate&&(this.autoUpdate=e.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,status:0},this.eventLoad={type:"load"},void 0===XMLHttpRequest)throw new Error("XMLHttpRequest not supported.");this.xhr=new XMLHttpRequest,this.xhr.addEventListener("error",function(t){n.dispatchEvent(t)}),this.xhr.addEventListener("readystatechange",function(t){n._handleResponse(this,t)}),this.xhr.addEventListener("timeout",function(){var t={meta:{}};t.meta.title="Timeout Error",null!==n.stderr?t[n.stderr]="<p>"+i.Error.TIMEOUT+"</p>":console.error(i.Error.TIMEOUT),n.locked=!0,n.update(t)}),window.addEventListener("popstate",function(t){n.locked||null===t.state||(n.backForward=!0,n._navigate({href:t.state.url}))}),this._switchPage=function(t){var e=void 0!==t.preventDefault,i=!1;return"submit"===t.type?i=!0:t.metaKey||t.shiftKey||t.altKey||t.ctrlKey||(void 0!==t.which?i=1===t.which:void 0!==t.button&&(i=0===t.button)),i&&(e&&t.preventDefault(),n.locked||n._navigate(this)),!(i&&!e)},this.update({meta:{title:document.title,url:location.href}}),this._updateListeners()}return t.prototype.apply=function(e){e._listeners={},e.addEventListener=t.prototype.addEventListener,e.hasEventListener=t.prototype.hasEventListener,e.removeEventListener=t.prototype.removeEventListener,e.dispatchEvent=t.prototype.dispatchEvent},t.prototype.addEventListener=function(t,e){void 0===this._listeners[t]&&(this._listeners[t]=[]),-1===this._listeners[t].indexOf(e)&&this._listeners[t].push(e)},t.prototype.hasEventListener=function(t,e){return void 0!==this._listeners[t]&&-1!==this._listeners[t].indexOf(e)},t.prototype.removeEventListener=function(t,e){var i,n;n=this._listeners[t],void 0!==n&&(i=n.indexOf(e),-1!==i&&n.splice(i,1))},t.prototype.dispatchEvent=function(t){var e,i,n;if(n=this._listeners[t.type],void 0!==n)for(t.target=this,e=0,i=n.length;i>e;++e)n[e].call(this,t)},i.prototype=Object.create(t.prototype),i.prototype.constructor=i,i.prototype._navigate=function(t){var i,n,s,r=!1;this.locked=!0,t.action?(this.absolutePath=t.action,i=new FormData(t),r=!0):this.absolutePath=t.href,n=e(this.absolutePath),"/"!==n.charAt(0)&&(n="/"+n),s="/"===n?this.absolutePath.slice(0,this.absolutePath.length-1)+this.infix+n:this.absolutePath.replace(new RegExp(n),this.infix+n),this.eventNavigate.method=r?"POST":"GET",this.dispatchEvent(this.eventNavigate),this.xhr.open(this.eventNavigate.method,s,!0),r?(this.xhr.timeout=this.timeoutPost,this.xhr.send(i)):(this.xhr.timeout=this.timeoutGet,this.xhr.send())},i.prototype._updateView=function(t){var e,i,n,s=!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(e in t)if(n=t[e],"object"!=typeof n&&(i=this.containers[e],void 0===i&&(i=this.containers[e]=document.getElementById(e)),null!==i)){for(;i.children.length>0;)i.removeChild(i.children[0]);for(this.intermediateContainer.innerHTML=n;this.intermediateContainer.children.length>0;)i.appendChild(this.intermediateContainer.children[0]);s=!0}s&&this._updateListeners()},i.prototype.unbindListeners=function(){var t,e,i=this;for(t=0,e=this.navigationListeners.length;e>t;++t)this.navigationListeners[t][0].removeEventListener(this.navigationListeners[t][1],i._switchPage)},i.prototype._updateListeners=function(){var t,e,i=this,n=document.getElementsByTagName("a"),s=document.getElementsByTagName("form");for(this.unbindListeners(),t=0,e=n.length;e>t;++t)this.local.test(n[t].href)&&(n[t].addEventListener("click",i._switchPage),this.navigationListeners.push([n[t],"click"]));for(t=0,e=s.length;e>t;++t)this.local.test(s[t].action)&&(s[t].addEventListener("submit",i._switchPage),this.navigationListeners.push([s[t],"submit"]))},i.prototype.update=function(t){var e;if(this._updateView(t),document.title=t.meta.title,t.meta.url&&(this.absolutePath=t.meta.url.replace(this.infix,"")),this.backForward)this.backForward=!1;else try{e=document.origin?document.origin:"null","null"!==e&&history.state&&this.absolutePath!==history.state.url&&history.pushState({url:this.absolutePath},t.meta.title,this.absolutePath)}catch(i){console.warn(i)}this.eventReceive.response=null,this.dispatchEvent(this.eventLoad),this.locked=!1},i.prototype._handleResponse=function(t){var e={meta:{}};if(4===t.readyState){try{e=JSON.parse(t.responseText)}catch(n){e.meta.title="Parse Error",null!==this.stderr&&(e[this.stderr]="<p>"+i.Error.UNPARSABLE+"</p>"),console.error(i.Error.UNPARSABLE)}e.meta.url=t.responseURL,this.eventReceive.status=t.status,this.eventReceive.response=e,this.dispatchEvent(this.eventReceive),this.autoUpdate&&this.update(e)}},i.Error=Object.freeze({TIMEOUT:"The server didn't respond in time. Please try again later!",UNPARSABLE:"The received content could not be parsed."}),i});
var Stay=function(){"use strict";function t(){this._listeners={}}function e(t){var e=document.createElement("a");return e.href=t,e.pathname}function i(e){var s=this;if(t.call(this),this.local=new RegExp("^"+location.protocol+"//"+location.host),this.stderr=null,this.infix="/json",this.timeoutPost=6e4,this.timeoutGet=5e3,this.autoUpdate=!0,void 0!==e&&(void 0!==e.stderr&&(this.stderr=e.stderr),void 0!==e.infix&&(this.infix=e.infix),void 0!==e.timeoutPost&&(this.timeoutPost=e.timeoutPost),void 0!==e.timeoutGet&&(this.timeoutGet=e.timeoutGet),void 0!==e.autoUpdate&&(this.autoUpdate=e.autoUpdate)),this.locked=!1,this.backForward=!1,this.absolutePath=null,this.historyState=null,this.containers=[],this.intermediateContainer=null,this.navigationListeners=[],this.eventNavigate={type:"navigate"},this.eventReceive={type:"receive",response:null,status:0},this.eventLoad={type:"load"},void 0===XMLHttpRequest)throw new Error("XMLHttpRequest not supported.");this.xhr=new XMLHttpRequest,this.xhr.addEventListener("error",function(t){s.dispatchEvent(t)}),this.xhr.addEventListener("readystatechange",function(t){s._handleResponse(this,t)}),this.xhr.addEventListener("timeout",function(){var t={meta:{}};t.meta.title="Timeout Error",null!==s.stderr?t[s.stderr]="<p>"+i.Error.TIMEOUT+"</p>":console.error(i.Error.TIMEOUT),s.locked=!0,s.update(t)}),window.addEventListener("popstate",function(t){s.locked||null===t.state||(s.backForward=!0,s._navigate({href:t.state.url}))}),this._switchPage=function(t){var e=void 0!==t.preventDefault,i=!1;return"submit"===t.type?i=!0:t.metaKey||t.shiftKey||t.altKey||t.ctrlKey||(void 0!==t.which?i=1===t.which:void 0!==t.button&&(i=0===t.button)),i&&(e&&t.preventDefault(),s.locked||s._navigate(this)),!(i&&!e)},this.update({meta:{title:document.title,url:location.href}}),this._updateListeners()}return t.prototype.apply=function(e){e._listeners={},e.addEventListener=t.prototype.addEventListener,e.hasEventListener=t.prototype.hasEventListener,e.removeEventListener=t.prototype.removeEventListener,e.dispatchEvent=t.prototype.dispatchEvent},t.prototype.addEventListener=function(t,e){void 0===this._listeners[t]&&(this._listeners[t]=[]),-1===this._listeners[t].indexOf(e)&&this._listeners[t].push(e)},t.prototype.hasEventListener=function(t,e){return void 0!==this._listeners[t]&&-1!==this._listeners[t].indexOf(e)},t.prototype.removeEventListener=function(t,e){var i,s;s=this._listeners[t],void 0!==s&&(i=s.indexOf(e),-1!==i&&s.splice(i,1))},t.prototype.dispatchEvent=function(t){var e,i,s;if(s=this._listeners[t.type],void 0!==s)for(t.target=this,e=0,i=s.length;i>e;++e)s[e].call(this,t)},i.prototype=Object.create(t.prototype),i.prototype.constructor=i,i.prototype._navigate=function(t){var i,s,n,r=!1;this.locked=!0,t.action?(this.absolutePath=t.action,i=new FormData(t),r=!0):this.absolutePath=t.href,s=e(this.absolutePath),"/"!==s.charAt(0)&&(s="/"+s),n="/"===s?this.absolutePath.slice(0,this.absolutePath.length-1)+this.infix+s:this.absolutePath.replace(new RegExp(s),this.infix+s),this.eventNavigate.method=r?"POST":"GET",this.dispatchEvent(this.eventNavigate);try{this.xhr.open(this.eventNavigate.method,n,!0),r?(this.xhr.timeout=this.timeoutPost,this.xhr.send(i)):(this.xhr.timeout=this.timeoutGet,this.xhr.send())}catch(o){this.dispatchEvent(o)}},i.prototype._updateView=function(t){var e,i,s,n=!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(e in t)if(s=t[e],"object"!=typeof s&&(i=this.containers[e],void 0===i&&(i=this.containers[e]=document.getElementById(e)),null!==i)){for(;i.children.length>0;)i.removeChild(i.children[0]);for(this.intermediateContainer.innerHTML=s;this.intermediateContainer.children.length>0;)i.appendChild(this.intermediateContainer.children[0]);n=!0}n&&this._updateListeners()},i.prototype.unbindListeners=function(){var t,e,i=this;for(t=0,e=this.navigationListeners.length;e>t;++t)this.navigationListeners[t][0].removeEventListener(this.navigationListeners[t][1],i._switchPage)},i.prototype._updateListeners=function(){var t,e,i=this,s=document.getElementsByTagName("a"),n=document.getElementsByTagName("form");for(this.unbindListeners(),t=0,e=s.length;e>t;++t)this.local.test(s[t].href)&&(s[t].addEventListener("click",i._switchPage),this.navigationListeners.push([s[t],"click"]));for(t=0,e=n.length;e>t;++t)this.local.test(n[t].action)&&(n[t].addEventListener("submit",i._switchPage),this.navigationListeners.push([n[t],"submit"]))},i.prototype.update=function(t){var e;if(this._updateView(t),document.title=t.meta.title,t.meta.url&&(this.absolutePath=t.meta.url.replace(this.infix,"")),this.backForward)this.backForward=!1;else if(null===this.historyState||this.absolutePath!==this.historyState.url?this.historyState={url:this.absolutePath,time:Date.now(),changed:!0}:this.historyState.changed=!1,e=document.origin?document.origin:"null","null"!==e)try{this.historyState.changed?history.pushState(this.historyState,t.meta.title,this.absolutePath):history.replaceState(this.historyState,t.meta.title,this.absolutePath)}catch(i){console.warn(i)}this.eventReceive.response=null,this.dispatchEvent(this.eventLoad),this.locked=!1},i.prototype._handleResponse=function(t){var e={meta:{}};if(4===t.readyState){try{e=JSON.parse(t.responseText)}catch(s){e.meta.title="Parse Error",null!==this.stderr&&(e[this.stderr]="<p>"+i.Error.UNPARSABLE+"</p>"),console.error(i.Error.UNPARSABLE)}e.meta.url=t.responseURL,this.eventReceive.status=t.status,this.eventReceive.response=e,this.dispatchEvent(this.eventReceive),this.autoUpdate&&this.update(e)}},i.Error=Object.freeze({TIMEOUT:"The server didn't respond in time. Please try again later!",UNPARSABLE:"The received content could not be parsed."}),i}();

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

"description": "Stay is a small but effective library for the creation of dynamic xhr-driven web applications.",
"version": "0.1.3",
"version": "0.1.4",
"url": "https://github.com/vanruesc/stay"

@@ -202,2 +202,13 @@ },

"line": 151,
"description": "The current history state.\nCan't rely on history.state right now.",
"itemtype": "property",
"name": "historyState",
"type": "Object",
"access": "private",
"tagname": "",
"class": "Stay"
},
{
"file": "src\\stay.js",
"line": 162,
"description": "A list of references to the response field DOM elements.",

@@ -213,3 +224,3 @@ "itemtype": "property",

"file": "src\\stay.js",
"line": 161,
"line": 172,
"description": "A container which is filled by setting its innerHTML.\nThe created DOM elements are taken from this container\nand appended to the response fields.",

@@ -225,3 +236,3 @@ "itemtype": "property",

"file": "src\\stay.js",
"line": 173,
"line": 184,
"description": "A list of navigation listeners for unbinding.",

@@ -237,3 +248,3 @@ "itemtype": "property",

"file": "src\\stay.js",
"line": 183,
"line": 194,
"description": "Signalises that a page navigation has started.",

@@ -246,3 +257,3 @@ "itemtype": "event",

"file": "src\\stay.js",
"line": 191,
"line": 202,
"description": "Returns the parsed server response.",

@@ -267,3 +278,3 @@ "itemtype": "event",

"file": "src\\stay.js",
"line": 201,
"line": 212,
"description": "Signalises that a page update has finished.",

@@ -276,3 +287,3 @@ "itemtype": "event",

"file": "src\\stay.js",
"line": 209,
"line": 220,
"description": "The internal XMLHttpRequest instance.",

@@ -288,3 +299,3 @@ "itemtype": "property",

"file": "src\\stay.js",
"line": 227,
"line": 238,
"description": "Returns XmlHttpRequest errors.",

@@ -297,3 +308,3 @@ "itemtype": "event",

"file": "src\\stay.js",
"line": 235,
"line": 246,
"description": "Triggers the internal response handler.",

@@ -315,3 +326,3 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 245,
"line": 256,
"description": "Handles xhr timeouts, ignores the event object.",

@@ -326,3 +337,3 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 273,
"line": 284,
"description": "Support browser functionality \"back\" and \"forward\".\nDepends on the boolean variable \"locked\" in order to\ndetermine whether this navigation should be executed.\nThe \"backForward\" flag tells the system that the next\nstate mustn't be pushed.",

@@ -344,3 +355,3 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 296,
"line": 307,
"description": "This function is bound to all links and forms\nand executes the desired page navigation on left clicks.",

@@ -362,3 +373,3 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 356,
"line": 367,
"description": "Navigates to the next target uri.",

@@ -380,3 +391,3 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 409,
"line": 429,
"description": "Updates the containers with the new data.",

@@ -398,3 +409,3 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 487,
"line": 507,
"description": "If you want to destroy Stay, you should call this method\nbefore you drop your reference to the Stay instance.",

@@ -407,3 +418,3 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 507,
"line": 527,
"description": "Binds event listeners to all links and forms.\nThis method is combined with the cleanup and basically refreshes \nthe navigation listeners.",

@@ -418,4 +429,4 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 549,
"description": "Updates the view, the navigation listeners and the history state.\nAlso emits an event to signilise that the page has been loaded.\n\nThe update function needs to be called after each navigation in \norder to unlock the system. This happens by default, but that\nbehaviour can be disabled. It is then the responsibility of the\nprogrammer to call stay.update(response) with the response data\nprovided by the \"receive\" event.",
"line": 569,
"description": "Updates the view, the navigation listeners and the history state.\nAlso emits an event to signilise that the page has been loaded.\n\nThe update function needs to be called after each navigation in \norder to unlock the system! This happens by default, but that\nbehaviour can be disabled. It is then the responsibility of the\nprogrammer to call stay.update(response) with the response data\nprovided by the \"receive\" event.",
"itemtype": "method",

@@ -434,3 +445,3 @@ "name": "update",

"file": "src\\stay.js",
"line": 606,
"line": 650,
"description": "This function acts when the xhr object changes its readyState.\nThe response will be a json object or an error page. Anything else will \nbe caught as a json parse exception and announced in stderr.",

@@ -452,3 +463,3 @@ "itemtype": "method",

"file": "src\\stay.js",
"line": 655,
"line": 699,
"description": "Enumeration of Error Messages.",

@@ -455,0 +466,0 @@ "itemtype": "property",

{
"name": "@zayesh/stay",
"version": "0.1.3",
"version": "0.1.4",
"description": "Stay is a small but effective library for the creation of dynamic xhr-driven web applications.",

@@ -32,15 +32,19 @@ "homepage": "https://github.com/vanruesc/stay",

"scripts": {
"jshint:banner": "jshint banner.js",
"jshint:test": "jshint test",
"jshint:lib": "jshint src",
"jshint": "npm run jshint:banner && npm run jshint:test && npm run jshint:lib",
"rollup": "rollup -f umd -n Stay -i src/stay.js -o build/stay.js",
"jshint": "npm run jshint:test && npm run jshint:lib",
"rollup": "rollup -f iife -n Stay -i src/stay.js -o build/stay.js",
"uglify": "uglifyjs build/stay.js -c -m -o build/stay.min.js",
"mocha": "mocha-phantomjs --setting webSecurityEnabled=false test/index.html",
"yuidoc": "yuidoc src -q -c yuidoc.json",
"prebuild": "npm run jshint",
"build": "npm run rollup",
"postbuild": "npm run uglify && node banner.js",
"build": "npm run rollup && npm run uglify",
"postbuild": "node banner.js",
"pretest": "npm run build",
"test": "npm run mocha"
},

@@ -47,0 +51,0 @@

@@ -41,3 +41,3 @@ # Stay

// Default is "/json"
infix: "/urlPatternForAsyncRequests",
infix: "/asyncRequests",

@@ -57,3 +57,3 @@ // Default is 60000ms, 0 means no timeout

alert("Page navigation has started.");
console.log("Page navigation has started.");

@@ -64,5 +64,5 @@ });

/* If autoUpdate is set to false, the programmer can
* decide when to update the page content.
* The response is the parsed JSON string from the server.
/* If autoUpdate is disabled, the programmer has to decide
* when to update the page content. The update() method MUST
* be called at some point to unlock the system!
*/

@@ -76,3 +76,3 @@

alert("The requested page has been loaded.");
console.log("The requested page has been loaded.");

@@ -84,16 +84,16 @@ });

> Every page needs to be available as a condensed json resource for Stay to work.
> This includes dynamically generated pages and error pages. The json version of each
> resource should only be served additionally to a traditional system to support users
> who block JavaScript.
> Every page has to be available in the form of a condensed JSON resource.
> This includes dynamically generated pages and error pages. The JSON version of each
> resource should be served additionally to support users who disable JavaScript.
> A traditional server system could be seen as your last bulwark.
KEeping your URIs well structured is very important.
Take a look at some best practices for URI design if you haven't already.
Stay is rather tolerant when it comes to different URI patterns, but a well-structured
URI configuration is of paramount importance. Take a look at some recommendations for
good URI design if you haven't already.
[These guidelines](https://css-tricks.com/guidelines-for-uri-design/) are a good starting point.
Stay is rather tolerant when it comes to different variations of URIs. Take a look at the following
example to see what's going on behind the scenes:
The following example shows what's going on behind the scenes of Stay:
```html
<a href="/fish/salmon">Salmon</a>
<a href="/foo/bar">Hyperlink</a>
```

@@ -104,7 +104,7 @@

```javascript
"http[s]://www.your-domain.com[:port]/json/fish/salmon"
"http[s]://www.your-domain.com[:port]/json/foo/bar"
```
The modified URI won't be seen by the user and the infix can freely be chosen by you.
If we assume that the original URI points to a simple html page which looks like this:
The modified URI won't be seen by the user and the infix can be freely chosen.
If we assume that the original URI points to a simple HTML page which looks like this:

@@ -123,3 +123,3 @@ ```html

then the json equivalent must look like this:
then the JSON equivalent must look like this:

@@ -138,9 +138,9 @@ ```javascript

managed for you to support the back and forward browser controls.
Although the above example html is minimal, it highlights the main aspects of asynchronous web applications.
Although the above example HTML is minimal, it highlights the main aspects of asynchronous web applications:
- More efficient bandwidth usage
- Better performance and loading feel
- Better loading performance
- More control over the navigation process
- Consolidation of a main page structure
- Still highly customisable
- Still highly customisable!

@@ -147,0 +147,0 @@

@@ -152,2 +152,13 @@ import EventDispatcher from "@zayesh/eventdispatcher";

/**
* The current history state.
* Can't rely on history.state right now.
*
* @property historyState
* @type Object
* @private
*/
this.historyState = null;
/**
* A list of references to the response field DOM elements.

@@ -394,14 +405,23 @@ *

this.dispatchEvent(this.eventNavigate);
this.xhr.open(this.eventNavigate.method, url, true);
if(post) {
try {
this.xhr.timeout = this.timeoutPost;
this.xhr.send(formData);
this.xhr.open(this.eventNavigate.method, url, true);
} else {
if(post) {
this.xhr.timeout = this.timeoutGet;
this.xhr.send();
this.xhr.timeout = this.timeoutPost;
this.xhr.send(formData);
} else {
this.xhr.timeout = this.timeoutGet;
this.xhr.send();
}
} catch(error) {
this.dispatchEvent(error);
}

@@ -556,3 +576,3 @@

* The update function needs to be called after each navigation in
* order to unlock the system. This happens by default, but that
* order to unlock the system! This happens by default, but that
* behaviour can be disabled. It is then the responsibility of the

@@ -581,16 +601,40 @@ * programmer to call stay.update(response) with the response data

try {
if(this.historyState === null || this.absolutePath !== this.historyState.url) {
origin = document.origin ? document.origin : "null";
this.historyState = {
url: this.absolutePath,
time: Date.now(),
changed: true
};
if(origin !== "null" && history.state && this.absolutePath !== history.state.url) {
} else {
history.pushState({url: this.absolutePath}, response.meta.title, this.absolutePath);
this.historyState.changed = false;
}
}
} catch(e) {
origin = document.origin ? document.origin : "null";
console.warn(e);
// Only try to push in a server environment.
if(origin !== "null") {
try {
if(this.historyState.changed) {
history.pushState(this.historyState, response.meta.title, this.absolutePath);
} else {
history.replaceState(this.historyState, response.meta.title, this.absolutePath);
}
} catch(e) {
// Browser-specific history error.
console.warn(e);
}
}

@@ -597,0 +641,0 @@

@@ -92,2 +92,65 @@ describe("Stay", function() {

describe("History", function() {
var stay;
before(function() {
stay = new Stay();
});
it("pushes history states", function(done) {
var previousState = stay.historyState;
stay.addEventListener("load", function handleLoad() {
stay.removeEventListener("load", handleLoad);
assert(previousState !== stay.historyState, "the history state hasn't been updated");
done();
});
stay._navigate({href: "./mock.json"});
});
it("doesn't push the same state consecutively", function(done) {
var phase = 1;
// Artificially reset the current state.
stay.historyState = null;
stay.addEventListener("load", function handleLoad() {
if(phase++ === 1) {
assert(stay.historyState.changed === true, "state should change for the first navigation");
stay._navigate({href: "./mock.json"});
} else {
stay.removeEventListener("load", handleLoad);
assert(stay.historyState.changed === false, "state shouldn't change for the second navigation");
done();
}
});
stay._navigate({href: "./mock.json"});
});
after(function() {
stay.unbindListeners();
stay = null;
});
});
});
{
"name": "Stay API",
"description": "Stay is a small but effective library for the creation of dynamic xhr-driven web applications.",
"version": "0.1.3",
"version": "0.1.4",
"url": "https://github.com/vanruesc/stay",

@@ -6,0 +6,0 @@ "options": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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