history-events
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,1 +0,1 @@ | ||
!function(){function e(e,t,n){var a;document.createEvent?(a=document.createEvent("HTMLEvents"),a.initEvent(t,!0,!0)):document.createEventObject&&(a=document.createEventObject(),a.eventType=t),a.data=n,a.eventName=t,e.dispatchEvent?e.dispatchEvent(a):e.fireEvent&&htmlEvents["on"+t]?e.fireEvent("on"+a.eventType,a):e[t]?e[t]():e["on"+t]&&e["on"+t]()}function t(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&htmlEvents["on"+t]?e.attachEvent("on"+t,n):e["on"+t]=n}function n(e,t,n){e.removeventListener?e.removeEventListener(t,n,!1):e.detachEvent&&htmlEvents["on"+t]?e.detachEvent("on"+t,n):e["on"+t]=null}function a(){return"undefined"!=typeof window&&window.history&&"pushState"in window.history}if(a()){var o=window.history,i=o.pushState;o.pushState=function(t){return e(window,"pushstate",{state:t}),e(window,"changestate",{state:t}),i.apply(o,arguments)};var r=o.replaceState;o.replaceState=function(t){return e(window,"replacestate",{state:t}),e(window,"changestate",{state:t}),r.apply(o,arguments)},t(window,"popstate",function(t){e(window,"changestate",{state:t})})}"undefined"!=typeof module&&(module.exports={isHistorySupported:a,addEventListener:t,removeEventListener:n,triggerEvent:e})}(); | ||
!function(){function e(e,t,n){var o;document.createEvent?(o=document.createEvent("HTMLEvents"),o.initEvent(t,!0,!0)):document.createEventObject&&(o=document.createEventObject(),o.eventType=t),o.state=n,o.eventName=t,e.dispatchEvent?e.dispatchEvent(o):e.fireEvent&&htmlEvents["on"+t]?e.fireEvent("on"+o.eventType,o):e[t]?e[t]():e["on"+t]&&e["on"+t]()}function t(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&htmlEvents["on"+t]?e.attachEvent("on"+t,n):e["on"+t]=n}function n(e,t,n){e.removeventListener?e.removeEventListener(t,n,!1):e.detachEvent&&htmlEvents["on"+t]?e.detachEvent("on"+t,n):e["on"+t]=null}function o(){return"undefined"!=typeof window&&window.history&&"pushState"in window.history}if(o()){var a=window.history,i=a.pushState;a.pushState=function(t){var n=i.apply(a,arguments);return e(window,"pushstate",t),e(window,"changestate",t),n};var r=a.replaceState;a.replaceState=function(t){var n=r.apply(a,arguments);return e(window,"replacestate",t),e(window,"changestate",t),n},t(window,"popstate",function(t){e(window,"changestate",t.state)})}var v={isHistorySupported:o,addEventListener:t,removeEventListener:n,triggerEvent:e};console.log(o()),o()&&(window.HistoryEvents=v),"undefined"!=typeof module&&(module.exports=v)}(); |
33
index.js
(function() { | ||
function triggerEvent(el, eventName, data) { | ||
function triggerEvent(el, eventName, state) { | ||
var event; | ||
@@ -12,3 +12,3 @@ if (document.createEvent) { | ||
} | ||
event.data = data; | ||
event.state = state; | ||
event.eventName = eventName; | ||
@@ -56,4 +56,4 @@ if (el.dispatchEvent) { | ||
var ps = pushState.apply(history, arguments); | ||
triggerEvent(window, 'pushstate', {state: state}); | ||
triggerEvent(window, 'changestate', {state: state}); | ||
triggerEvent(window, 'pushstate', state); | ||
triggerEvent(window, 'changestate', state); | ||
return ps; | ||
@@ -65,21 +65,22 @@ } | ||
var rs = replaceState.apply(history, arguments); | ||
triggerEvent(window, 'replacestate', {state: state}); | ||
triggerEvent(window, 'changestate', {state: state}); | ||
triggerEvent(window, 'replacestate', state); | ||
triggerEvent(window, 'changestate', state); | ||
return rs; | ||
} | ||
addEventListener(window, 'popstate', function(state) { | ||
triggerEvent(window, 'changestate', {state: state}); | ||
addEventListener(window, 'popstate', function(e) { | ||
triggerEvent(window, 'changestate', e.state); | ||
}); | ||
} | ||
if (typeof module != 'undefined') { | ||
module.exports = { | ||
isHistorySupported: isHistorySupported, | ||
addEventListener: addEventListener, | ||
removeEventListener: removeEventListener, | ||
triggerEvent: triggerEvent | ||
}; | ||
} | ||
var publicInterface = { | ||
isHistorySupported: isHistorySupported, | ||
addEventListener: addEventListener, | ||
removeEventListener: removeEventListener, | ||
triggerEvent: triggerEvent | ||
}; | ||
console.log( isHistorySupported()) | ||
if (isHistorySupported()) window.HistoryEvents = publicInterface; | ||
if (typeof module != 'undefined') module.exports = publicInterface; | ||
})(); |
{ | ||
"name": "history-events", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Adds missing window.history events onpushstate, onreplacestate and onchangestate.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
7255
6
78