-
Notifications
You must be signed in to change notification settings - Fork 0
/
scratch.js
74 lines (61 loc) · 2.01 KB
/
scratch.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class Hijinx {
// ... (Your existing constructor and other methods)
setup() {
$("when").each((i, el) => {
const $when = $(el);
const event = $when.attr("event");
switch (event) {
case "ready":
// Execute actions immediately
break;
case "done":
// Queue for later execution
this.doneEventQueue.push($when);
break;
default:
// For all other events
$(window).on(event, () => {
// Execute actions
});
break;
}
$when.children("set").each((i, el) => {
this.processSet(el);
});
$when.children("get").each((i, el) => {
this.processGet(el);
});
});
// Log a message to the console once all sets and gets have completed
$.when.apply($, this.processedSetsAndGets).done(() => {
console.log("All sets and gets have been processed!");
// Process all queued `done` events
this.doneEventQueue.forEach(($when) => {
$when.children("set").each((i, el) => {
this.processSet(el);
});
$when.children("get").each((i, el) => {
this.processGet(el);
});
});
});
}
refreshHijinx() {
// Clear and reset your instance variables
this.sets = {};
this.index = 0;
this.processedSetsAndGets = [];
this.doneEventQueue = [];
// Call setup again to re-process all tags
this.setup();
}
init() {
$(document).ready(() => {
this.setup();
});
}
}
const hijinx = new Hijinx();
hijinx.init();
// Later in your code, you can call the refresh method to refresh Hijinx's functionality
// hijinx.refreshHijinx();