-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashChange.js
More file actions
45 lines (35 loc) · 1.19 KB
/
Copy pathhashChange.js
File metadata and controls
45 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/front/blob/master/LICENSE
*/
// hashChange
// script that sends the hash change event back to the nodes
Component.HashChange = function(persistent)
{
// not empty
if(Vari.isEmpty(this))
return null;
// nodes
const $nodes = this;
// event
const handler = ael(window,'hashchange',function(event) {
trigEvt($nodes,'hash:change',true);
});
// pour popstate, trigger seulement le hash change si le navigateur est ie, les autres navigateurs envoient un événement natif hashchange
const handler2 = ael(window,'hashChange:history',function(event,popstate) {
if(popstate !== true || Browser.isIe())
trigEvt($nodes,'hash:change',false);
});
// persistent
if(persistent !== true)
{
const teardown = function() {
rel(window,handler);
rel(window,handler2);
};
aelOnce(document,'doc:unmountPage',teardown);
aelOnce(this,'component:teardown',teardown);
}
return this;
}