@zayesh/stay
Advanced tools
Comparing version 0.1.4 to 0.1.5
/** | ||
* Banner. | ||
* Recursively adds a banner to the specified files. | ||
*/ | ||
var prependFile = require("prepend-file"), | ||
pkg = require("./package"), | ||
pkgName = pkg.name.replace(/^@.+\//, ""), | ||
date = (new Date()).toDateString(), | ||
banner; | ||
var prependFile = require("prepend-file"); | ||
var pkg = require("./package"); | ||
var pkgName = pkg.name.replace(/^@.+\//, ""); | ||
var date = (new Date()).toDateString(); | ||
var banner = "/**\n * " + pkgName + " v" + pkg.version + " build " + date.slice(4) + "\n" + | ||
" * " + pkg.homepage + "\n" + | ||
" * Copyright " + date.slice(-4) + " " + pkg.author.name + ", " + pkg.license + "\n */\n"; | ||
function prepend(files) { | ||
@@ -29,6 +33,2 @@ | ||
banner = "/**\n * " + pkgName + " v" + pkg.version + " build " + date.slice(4) + "\n" + | ||
" * " + pkg.homepage + "\n" + | ||
" * Copyright " + date.slice(-4) + " " + pkg.author.name + ", " + pkg.license + "\n */\n"; | ||
prepend([ | ||
@@ -35,0 +35,0 @@ "build/" + pkgName + ".js", |
/** | ||
* stay v0.1.4 build Sep 23 2015 | ||
* stay v0.1.5 build Oct 05 2015 | ||
* https://github.com/vanruesc/stay | ||
@@ -199,2 +199,11 @@ * Copyright 2015 Raoul van Rueschen, Apache-2.0 | ||
/** | ||
* Regular expressions for excluded URIs. | ||
* | ||
* @property exclusions | ||
* @type Array | ||
*/ | ||
this.exclusions = []; | ||
/** | ||
* The standard error output. | ||
@@ -656,7 +665,8 @@ * This string represents the ID of the target | ||
var self = this; | ||
var i, l; | ||
var signature; | ||
for(i = 0, l = this.navigationListeners.length; i < l; ++i) { | ||
for(; this.navigationListeners.length > 0;) { | ||
this.navigationListeners[i][0].removeEventListener(this.navigationListeners[i][1], self._switchPage); | ||
signature = this.navigationListeners.pop(); | ||
signature[0].removeEventListener(signature[1], self._switchPage); | ||
@@ -679,15 +689,26 @@ } | ||
var self = this; | ||
var i, l; | ||
var links = document.getElementsByTagName("a"); | ||
var forms = document.getElementsByTagName("form"); | ||
var i, j, li, lj; | ||
var exclude; | ||
this.unbindListeners(); | ||
this.unbindListeners(); | ||
for(i = 0, l = links.length; i < l; ++i) { | ||
for(i = 0, li = links.length; i < li; ++i) { | ||
if(this.local.test(links[i].href)) { | ||
links[i].addEventListener("click", self._switchPage); | ||
this.navigationListeners.push([links[i], "click"]); | ||
for(j = 0, lj = this.exclusions.length, exclude = false; !exclude && j < lj; ++j) { | ||
if(this.exclusions[j].test(links[i].href)) { exclude = true; } | ||
} | ||
if(!exclude) { | ||
links[i].addEventListener("click", self._switchPage); | ||
this.navigationListeners.push([links[i], "click"]); | ||
} | ||
} | ||
@@ -697,9 +718,19 @@ | ||
for(i = 0, l = forms.length; i < l; ++i) { | ||
for(i = 0, li = forms.length; i < li; ++i) { | ||
if(this.local.test(forms[i].action)) { | ||
forms[i].addEventListener("submit", self._switchPage); | ||
this.navigationListeners.push([forms[i], "submit"]); | ||
for(j = 0, lj = this.exclusions.length, exclude = false; !exclude && j < lj; ++j) { | ||
if(this.exclusions[j].test(forms[i].action)) { exclude = true; } | ||
} | ||
if(!exclude) { | ||
forms[i].addEventListener("submit", self._switchPage); | ||
this.navigationListeners.push([forms[i], "submit"]); | ||
} | ||
} | ||
@@ -706,0 +737,0 @@ |
/** | ||
* stay v0.1.4 build Sep 23 2015 | ||
* stay v0.1.5 build Oct 05 2015 | ||
* https://github.com/vanruesc/stay | ||
* Copyright 2015 Raoul van Rueschen, Apache-2.0 | ||
*/ | ||
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}(); | ||
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.exclusions=[],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(){for(var t,e=this;this.navigationListeners.length>0;)t=this.navigationListeners.pop(),t[0].removeEventListener(t[1],e._switchPage)},i.prototype._updateListeners=function(){var t,e,i,s,n,r=this,o=document.getElementsByTagName("a"),a=document.getElementsByTagName("form");for(this.unbindListeners(),t=0,i=o.length;i>t;++t)if(this.local.test(o[t].href)){for(e=0,s=this.exclusions.length,n=!1;!n&&s>e;++e)this.exclusions[e].test(o[t].href)&&(n=!0);n||(o[t].addEventListener("click",r._switchPage),this.navigationListeners.push([o[t],"click"]))}for(t=0,i=a.length;i>t;++t)if(this.local.test(a[t].action)){for(e=0,s=this.exclusions.length,n=!1;!n&&s>e;++e)this.exclusions[e].test(a[t].action)&&(n=!0);n||(a[t].addEventListener("submit",r._switchPage),this.navigationListeners.push([a[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.4", | ||
"version": "0.1.5", | ||
"url": "https://github.com/vanruesc/stay" | ||
@@ -124,2 +124,11 @@ }, | ||
"line": 60, | ||
"description": "Regular expressions for excluded URIs.", | ||
"itemtype": "property", | ||
"name": "exclusions", | ||
"type": "Array", | ||
"class": "Stay" | ||
}, | ||
{ | ||
"file": "src\\stay.js", | ||
"line": 69, | ||
"description": "The standard error output.\nThis string represents the ID of the target \nDOM container which should hold any error\nmessages. If none is specified, errors will \nbe logged to the console. A request timeout\nis considered an error, for example.", | ||
@@ -133,3 +142,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 74, | ||
"line": 83, | ||
"description": "The infix to use for the asynchronous requests.", | ||
@@ -143,3 +152,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 83, | ||
"line": 92, | ||
"description": "POST timeout.", | ||
@@ -153,3 +162,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 92, | ||
"line": 101, | ||
"description": "GET timeout.", | ||
@@ -163,3 +172,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 101, | ||
"line": 110, | ||
"description": "Auto update flag.", | ||
@@ -173,3 +182,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 121, | ||
"line": 130, | ||
"description": "Lock flag.", | ||
@@ -185,3 +194,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 131, | ||
"line": 140, | ||
"description": "Back-forward flag.", | ||
@@ -197,3 +206,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 141, | ||
"line": 150, | ||
"description": "The current absolute path.", | ||
@@ -209,3 +218,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 151, | ||
"line": 160, | ||
"description": "The current history state.\nCan't rely on history.state right now.", | ||
@@ -221,3 +230,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 162, | ||
"line": 171, | ||
"description": "A list of references to the response field DOM elements.", | ||
@@ -233,3 +242,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 172, | ||
"line": 181, | ||
"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.", | ||
@@ -245,3 +254,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 184, | ||
"line": 193, | ||
"description": "A list of navigation listeners for unbinding.", | ||
@@ -257,3 +266,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 194, | ||
"line": 203, | ||
"description": "Signalises that a page navigation has started.", | ||
@@ -266,3 +275,3 @@ "itemtype": "event", | ||
"file": "src\\stay.js", | ||
"line": 202, | ||
"line": 211, | ||
"description": "Returns the parsed server response.", | ||
@@ -287,3 +296,3 @@ "itemtype": "event", | ||
"file": "src\\stay.js", | ||
"line": 212, | ||
"line": 221, | ||
"description": "Signalises that a page update has finished.", | ||
@@ -296,3 +305,3 @@ "itemtype": "event", | ||
"file": "src\\stay.js", | ||
"line": 220, | ||
"line": 229, | ||
"description": "The internal XMLHttpRequest instance.", | ||
@@ -308,3 +317,3 @@ "itemtype": "property", | ||
"file": "src\\stay.js", | ||
"line": 238, | ||
"line": 247, | ||
"description": "Returns XmlHttpRequest errors.", | ||
@@ -317,3 +326,3 @@ "itemtype": "event", | ||
"file": "src\\stay.js", | ||
"line": 246, | ||
"line": 255, | ||
"description": "Triggers the internal response handler.", | ||
@@ -335,3 +344,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 256, | ||
"line": 265, | ||
"description": "Handles xhr timeouts, ignores the event object.", | ||
@@ -346,3 +355,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 284, | ||
"line": 293, | ||
"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.", | ||
@@ -364,3 +373,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 307, | ||
"line": 316, | ||
"description": "This function is bound to all links and forms\nand executes the desired page navigation on left clicks.", | ||
@@ -382,3 +391,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 367, | ||
"line": 376, | ||
"description": "Navigates to the next target uri.", | ||
@@ -400,3 +409,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 429, | ||
"line": 438, | ||
"description": "Updates the containers with the new data.", | ||
@@ -418,3 +427,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 507, | ||
"line": 516, | ||
"description": "If you want to destroy Stay, you should call this method\nbefore you drop your reference to the Stay instance.", | ||
@@ -427,3 +436,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 527, | ||
"line": 537, | ||
"description": "Binds event listeners to all links and forms.\nThis method is combined with the cleanup and basically refreshes \nthe navigation listeners.", | ||
@@ -438,3 +447,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 569, | ||
"line": 600, | ||
"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.", | ||
@@ -454,3 +463,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 650, | ||
"line": 681, | ||
"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.", | ||
@@ -472,3 +481,3 @@ "itemtype": "method", | ||
"file": "src\\stay.js", | ||
"line": 699, | ||
"line": 730, | ||
"description": "Enumeration of Error Messages.", | ||
@@ -475,0 +484,0 @@ "itemtype": "property", |
{ | ||
"name": "@zayesh/stay", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Stay is a small but effective library for the creation of dynamic xhr-driven web applications.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/vanruesc/stay", |
@@ -80,10 +80,10 @@ # Stay | ||
> 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. | ||
> Every GET and POST endpoint has to be available as a condensed JSON resource. | ||
> This includes dynamically generated pages and error pages. Serving a JSON version of each resource | ||
> should always be seen as an additional feature and nothing more. You should make good use of | ||
> JavaScript, but you shouldn't depend on it. | ||
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. | ||
URI configuration is the foundation of a good web application. 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. | ||
@@ -103,3 +103,3 @@ | ||
The modified URI won't be seen by the user and the infix can be freely chosen. | ||
The modified URI won't be seen by the user and the infix can be freely chosen by you. | ||
If we assume that the original URI points to a simple HTML page which looks like this: | ||
@@ -131,4 +131,4 @@ | ||
Stay will replace the current children of ```#main``` with the received content which is a simple text | ||
node in this case. The current page's title will also be adjusted and the browser history will be | ||
managed for you to support the back and forward browser controls. | ||
node in this case, but could be any HTML content. The current page's title will also be adjusted and | ||
the browser history will be 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: | ||
@@ -143,14 +143,16 @@ | ||
## External Resources | ||
## External Resources and Media | ||
Stay detects external resources and doesn't touch them. | ||
Stay detects external resources and doesn't touch them. The user will experience a synchronous navigation. | ||
Resources like images or executable files are problematic because they can't be identified as such by their URI alone. | ||
You may, however, define an arbitrary number of regular expressions to exclude specific URIs. | ||
```javascript | ||
stay.exclusions.push(/\/nonJSON\//); | ||
``` | ||
## Other Resources | ||
When linking a resource that can't be represented in JSON format, you should consider moving it on a dedicated file server. | ||
Since Stay ignores external resources by default, the file would just open as expected. | ||
Resources like images or executable files are problematic because they can't be identified as such by their URI alone. | ||
When linking a resource that can't be represented in json format, you should consider moving it on a dedicated file server. | ||
Since Stay ignores external resources, the file will open as expected. | ||
## Documentation | ||
@@ -157,0 +159,0 @@ [API](http://vanruesc.github.io/stay/docs) |
@@ -61,2 +61,11 @@ import EventDispatcher from "@zayesh/eventdispatcher"; | ||
/** | ||
* Regular expressions for excluded URIs. | ||
* | ||
* @property exclusions | ||
* @type Array | ||
*/ | ||
this.exclusions = []; | ||
/** | ||
* The standard error output. | ||
@@ -518,7 +527,8 @@ * This string represents the ID of the target | ||
var self = this; | ||
var i, l; | ||
var signature; | ||
for(i = 0, l = this.navigationListeners.length; i < l; ++i) { | ||
for(; this.navigationListeners.length > 0;) { | ||
this.navigationListeners[i][0].removeEventListener(this.navigationListeners[i][1], self._switchPage); | ||
signature = this.navigationListeners.pop(); | ||
signature[0].removeEventListener(signature[1], self._switchPage); | ||
@@ -541,15 +551,26 @@ } | ||
var self = this; | ||
var i, l; | ||
var links = document.getElementsByTagName("a"); | ||
var forms = document.getElementsByTagName("form"); | ||
var i, j, li, lj; | ||
var exclude; | ||
this.unbindListeners(); | ||
this.unbindListeners(); | ||
for(i = 0, l = links.length; i < l; ++i) { | ||
for(i = 0, li = links.length; i < li; ++i) { | ||
if(this.local.test(links[i].href)) { | ||
links[i].addEventListener("click", self._switchPage); | ||
this.navigationListeners.push([links[i], "click"]); | ||
for(j = 0, lj = this.exclusions.length, exclude = false; !exclude && j < lj; ++j) { | ||
if(this.exclusions[j].test(links[i].href)) { exclude = true; } | ||
} | ||
if(!exclude) { | ||
links[i].addEventListener("click", self._switchPage); | ||
this.navigationListeners.push([links[i], "click"]); | ||
} | ||
} | ||
@@ -559,9 +580,19 @@ | ||
for(i = 0, l = forms.length; i < l; ++i) { | ||
for(i = 0, li = forms.length; i < li; ++i) { | ||
if(this.local.test(forms[i].action)) { | ||
forms[i].addEventListener("submit", self._switchPage); | ||
this.navigationListeners.push([forms[i], "submit"]); | ||
for(j = 0, lj = this.exclusions.length, exclude = false; !exclude && j < lj; ++j) { | ||
if(this.exclusions[j].test(forms[i].action)) { exclude = true; } | ||
} | ||
if(!exclude) { | ||
forms[i].addEventListener("submit", self._switchPage); | ||
this.navigationListeners.push([forms[i], "submit"]); | ||
} | ||
} | ||
@@ -568,0 +599,0 @@ |
@@ -44,2 +44,16 @@ describe("Stay", function() { | ||
it("should automatically bind a listener", function() { | ||
assert(stay.navigationListeners.length > 0); | ||
}); | ||
it("should ignore excluded URIs", function() { | ||
stay.exclusions.push(/\//); | ||
stay._updateListeners(); | ||
assert(stay.navigationListeners.length === 0); | ||
}); | ||
it("should fire a navigate event", function(done) { | ||
@@ -46,0 +60,0 @@ |
{ | ||
"name": "Stay API", | ||
"description": "Stay is a small but effective library for the creation of dynamic xhr-driven web applications.", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237560
3019
165