@zayesh/stay
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -29,3 +29,3 @@ /** | ||
function EventTarget() | ||
function EventDispatcher() | ||
{ | ||
@@ -42,14 +42,12 @@ this._listeners = {}; | ||
EventTarget.prototype.addEventListener = function(type, listener) | ||
EventDispatcher.prototype.addEventListener = function(type, listener) | ||
{ | ||
var listeners = this._listeners; | ||
if(listeners[type] === undefined) | ||
if(this._listeners[type] === undefined) | ||
{ | ||
listeners[type] = []; | ||
this._listeners[type] = []; | ||
} | ||
if(listeners[type].indexOf(listener) === -1) | ||
if(this._listeners[type].indexOf(listener) === -1) | ||
{ | ||
listeners[type].push(listener); | ||
this._listeners[type].push(listener); | ||
} | ||
@@ -65,6 +63,5 @@ }; | ||
EventTarget.prototype.hasEventListener = function(type, listener) | ||
EventDispatcher.prototype.hasEventListener = function(type, listener) | ||
{ | ||
var listeners = this._listeners; | ||
return(listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1); | ||
return(this._listeners[type] !== undefined && this._listeners[type].indexOf(listener) !== -1); | ||
}; | ||
@@ -79,15 +76,14 @@ | ||
EventTarget.prototype.removeEventListener = function(type, listener) | ||
EventDispatcher.prototype.removeEventListener = function(type, listener) | ||
{ | ||
var listeners = this._listeners, | ||
listenerArray = listeners[type], | ||
index; | ||
var i, listeners = this._listeners, | ||
listenerArray = listeners[type]; | ||
if(listenerArray !== undefined) | ||
{ | ||
index = listenerArray.indexOf(listener); | ||
i = listenerArray.indexOf(listener); | ||
if(index !== -1) | ||
if(i !== -1) | ||
{ | ||
listenerArray.splice(index, 1); | ||
listenerArray.splice(i, 1); | ||
} | ||
@@ -100,10 +96,9 @@ } | ||
* | ||
* @param {Event} event - The event. | ||
* @param {Object} event - The event. | ||
*/ | ||
EventTarget.prototype.dispatchEvent = function(event) | ||
EventDispatcher.prototype.dispatchEvent = function(event) | ||
{ | ||
var listeners = this._listeners, | ||
listenerArray = listeners[event.type], | ||
array, length, i; | ||
var i, l, listeners = this._listeners, | ||
listenerArray = listeners[event.type]; | ||
@@ -113,18 +108,11 @@ if(listenerArray !== undefined) | ||
event.target = this; | ||
array = []; | ||
length = listenerArray.length; | ||
for(i = 0; i < length; ++i) | ||
for(i = 0, l = listenerArray.length; i < l; ++i) | ||
{ | ||
array[i] = listenerArray[i]; | ||
listenerArray[i].call(this, event); | ||
} | ||
for(i = 0; i < length; ++i) | ||
{ | ||
array[i].call(this, event); | ||
} | ||
} | ||
}; | ||
module.exports = EventTarget; | ||
module.exports = EventDispatcher; | ||
@@ -134,3 +122,3 @@ },{}],2:[function(require,module,exports){ | ||
var EventTarget = require("@zayesh/eventtarget"), | ||
var EventDispatcher = require("@zayesh/eventdispatcher"), | ||
index = "/"; | ||
@@ -175,3 +163,3 @@ | ||
EventTarget.call(this); | ||
EventDispatcher.call(this); | ||
@@ -288,3 +276,3 @@ this.responseFields = ["content", "navigation"]; | ||
Stay.prototype = Object.create(EventTarget.prototype); | ||
Stay.prototype = Object.create(EventDispatcher.prototype); | ||
Stay.prototype.constructor = Stay; | ||
@@ -522,3 +510,3 @@ | ||
},{"@zayesh/eventtarget":1}]},{},[2])(2) | ||
},{"@zayesh/eventdispatcher":1}]},{},[2])(2) | ||
}); |
@@ -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){var c=this._listeners;void 0===c[a]&&(c[a]=[]),-1===c[a].indexOf(b)&&c[a].push(b)},d.prototype.hasEventListener=function(a,b){var c=this._listeners;return void 0!==c[a]&&-1!==c[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,e=this._listeners,f=e[a.type];if(void 0!==f){for(a.target=this,b=[],c=f.length,d=0;c>d;++d)b[d]=f[d];for(d=0;c>d;++d)b[d].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;e.call(this),this.responseFields=["content","navigation"],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.eventContentReceived={type:"contentreceived",response:null},this.eventLoad={type:"load"},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.buttons?d=0===a.buttons:void 0!==a.which?d=1===a.which:void 0!==a.button?d=0===a.button:void 0!==a.keyCode&&(d=0===a.keyCode)),d&&(c&&a.preventDefault(),b.locked||b._navigate(this)),!(d&&!c)},this._updateListeners()}var e=a("@zayesh/eventtarget"),f="/";Stay.prototype=Object.create(e.prototype),Stay.prototype.constructor=Stay,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(c.pathname,this.infix+c.pathname),this.eventNavigate.method=g?"POST":"GET",this.dispatchEvent(this.eventNavigate),g?(this.xhr.open("POST",e,!0),this.xhr.timeout=this.timeoutPost,this.xhr.send(b)):(this.xhr.open("GET",e,!0),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.eventContentReceived.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.eventContentReceived.response=b,this.dispatchEvent(this.eventContentReceived),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/eventtarget":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;e.call(this),this.responseFields=["content","navigation"],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.eventContentReceived={type:"contentreceived",response:null},this.eventLoad={type:"load"},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.buttons?d=0===a.buttons:void 0!==a.which?d=1===a.which:void 0!==a.button?d=0===a.button:void 0!==a.keyCode&&(d=0===a.keyCode)),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._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(c.pathname,this.infix+c.pathname),this.eventNavigate.method=g?"POST":"GET",this.dispatchEvent(this.eventNavigate),g?(this.xhr.open("POST",e,!0),this.xhr.timeout=this.timeoutPost,this.xhr.send(b)):(this.xhr.open("GET",e,!0),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.eventContentReceived.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.eventContentReceived.response=b,this.dispatchEvent(this.eventContentReceived),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.3", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/vanruesc/stay", | ||
@@ -28,3 +28,3 @@ "author": { | ||
"dependencies": { | ||
"@zayesh/eventtarget": "x.x.x" | ||
"@zayesh/eventdispatcher": "x.x.x" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
"use strict"; | ||
var EventTarget = require("@zayesh/eventtarget"), | ||
var EventDispatcher = require("@zayesh/eventdispatcher"), | ||
index = "/"; | ||
@@ -43,3 +43,3 @@ | ||
EventTarget.call(this); | ||
EventDispatcher.call(this); | ||
@@ -156,3 +156,3 @@ this.responseFields = ["content", "navigation"]; | ||
Stay.prototype = Object.create(EventTarget.prototype); | ||
Stay.prototype = Object.create(EventDispatcher.prototype); | ||
Stay.prototype.constructor = Stay; | ||
@@ -159,0 +159,0 @@ |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
38396
882
+ Added@zayesh/eventdispatcher@0.1.8(transitive)
- Removed@zayesh/eventtarget@x.x.x