PageSourceSearch

https://meltmethod.ca/wp-content/plugins/MobiusWP/js/vendor/hijinx/hijinx.js?ver=1791509999

js meltmethod.ca collected 2026-10-09 01:40:16 UTC 12,869 bytes, 322 lines download raw bytes

1/**
2 * Notes
3 *
4 * Make sure Arrive or MutationObserver is used to confirm their presence in the DOM
5 *
6 * Support nesting but don't go nuts with it. 2 levels deep is probably enough
7 *
8 * Everything is when.load
9 *
10 * promises for done tag
11 *
12 * events with on-* like <on-click>
13 *
14 *
15 */
16
17(function ($) {
18
19    gsap.registerPlugin(ScrollTrigger);
20
21    // Function to index the variables
22    // function indexVars() {
23    //     var vars = {};
24    //     $('hijinx var').each(function () {
25    //         var node = $(this);
26    //         var name = node.attr('name');
27    //         var targets = node.find('select-all').attr('targets');
28    //         vars[name] = $(targets);
29    //     });
30    //     return vars;
31    // }
32
33
34
35
36    function indexAnimations() {
37        var animations = {};
38        $('hijinx > animation').each(function () {
39            var node = $(this);
40            var name = node.attr('name') || 'default';
41            var users = $(node.attr('users')); // Get the user elements
42            var timelineNode = node.find('timeline');
43            var scrollTriggerNode = node.find('scrolltrigger');
44            var setNodes = node.find('set');
45
46            animations[name] = { users: [] }; // Initialize the users array
47
48            users.each(function (index, userElement) { // Iterate over each user element
49                var timeline;
50                var scrollTrigger;
51                var sets = [];
52
53                // Process 'set' tags
54                setNodes.each(function () {
55                    var setNode = $(this);
56                    var targets = $(userElement).find(setNode.attr('targets')); // Find the targets within the user element
57                    var properties = {};
58                    setNode.children().each(function () {
59                        var property = $(this);
60                        properties[property.prop('tagName').toLowerCase()] = property.text();
61                    });
62                    sets.push({ targets: targets, properties: properties });
63                    gsap.set(targets, properties); // Apply the set immediately
64                });
65
66                if (timelineNode.length > 0) {
67                    timeline = gsap.timeline({ paused: true });
68                    timelineNode.children().each(function () {
69                        var action = $(this);
70                        var actionType = action.prop('tagName').toLowerCase();
71                        var targets = $(userElement).find(action.attr('targets')); // Find the targets within the user element
72                        var properties = {};
73                        var position = action.attr('position'); // Extract the position attribute
74                        action.children().each(function () {
75                            var property = $(this);
76                            properties[property.prop('tagName').toLowerCase()] = property.text();
77                        });
78                        timeline.actions = timeline.actions || [];
79                        timeline.actions.push({ type: actionType, targets: targets, properties: properties, position: position });
80                    });
81                    // Apply the actions to the timeline
82                    timeline.actions.forEach(function (action) {
83                        if (action.type === 'to') {
84                            timeline[action.type](action.targets, action.properties, action.position);
85                        } else {
86                            timeline[action.type](action.targets, action.properties);
87                        }
88                    });
89                }
90
91                if (scrollTriggerNode.length > 0) {
92                    var properties = {};
93                    scrollTriggerNode.children().each(function () {
94                        var property = $(this);
95                        var propName = property.prop('tagName').toLowerCase().replace(/-(.)/g, function (match, group1) {
96                            return group1.toUpperCase();
97                        });
98                        properties[propName] = property.text();
99                    });
100                    properties.trigger = userElement; // Set the trigger to the user element
101                    properties.animation = timeline;
102                    var scrollTriggerInstance = ScrollTrigger.create(properties);
103                    scrollTrigger = scrollTriggerInstance;
104                }
105
106                // Add the user to the users array
107                animations[name].users.push({ element: userElement, timeline: timeline, scrollTrigger: scrollTrigger, sets: sets });
108            });
109        });
110        return animations;
111    }
112
113    // Function to index the variables
114    function indexVars() {
115        var vars = {};
116        $('hijinx var').each(function () {
117            var node = $(this);
118            var name = node.attr('name');
119            var value = processVarSelectAlls(node, vars);
120            vars[name] = value !== undefined ? value : node;
121        });
122        return vars;
123    }
124
125    // Function to process the select-alls inside a var tag
126    function processVarSelectAlls(node, vars) {
127        var value;
128        node.find('select-all').each(function () {
129            var selectAll = $(this);
130            var targets = selectAll.attr('targets');
131            var elements = vars[targets] || $(targets); // If the target is not a var, treat it as a selector
132            if (selectAll.children().length > 0) {
133                // If the select-all tag has children, process them
134                selectAll.children().each(function () {
135                    var action = $(this);
136                    switch (action.prop('tagName').toLowerCase()) {
137                        case 'css':
138                            // Use the map method to get the value from each matched element
139                            value = elements.map(function () {
140                                return $(this).css(action.text());
141                            }).get(); // Use the get method to convert the jQuery object to a regular array
142                            break;
143                        // Add more cases here for other jQuery methods you want to supp
143ort
144                    }
145                });
146            } else {
147                // If the select-all tag has no children, return the jQuery object
148                value = elements;
149            }
150        });
151        return value;
152    }
153
154
155    // Function to index the select-alls
156    function indexSelectAlls() {
157        var selectAlls = {};
158        $('hijinx > select-all').each(function () {
159            var node = $(this);
160            var targets = node.attr('targets');
161            var actions = node.children();
162            if (!selectAlls[targets]) {
163                selectAlls[targets] = [];
164            }
165            actions.each(function () {
166                var action = $(this);
167                var properties = {};
168                action.children().each(function () {
169                    var property = $(this);
170                    if (property.is('select-all')) {
171                        properties[property.prop('tagName').toLowerCase()] = property.attr('targets');
172                    } else {
173                        properties[property.prop('tagName').toLowerCase()] = property.text();
174                    }
175                });
176                selectAlls[targets].push({
177                    action: action.prop('tagName').toLowerCase(),
178                    properties: properties
179                });
180            });
181        });
182        return selectAlls;
183    }
184
185    // Function to process the select-alls
186    function processSelectAlls(vars, selectAlls) {
187        $.each(selectAlls, function (targets, actions) {
188            var elements = vars[targets] || $(targets); // If the target is not a var, treat it as a selector
189            actions.forEach(function (action) {
190                switch (action.action) {
191                    case 'on-click':
192                        elements.click(function () {
193                            processSelectAlls(vars, action.properties);
194                        });
195                        break;
196                    case 'append-to':
197                        var appendToTargets = action.properties['select-all'];
198                        var appendToElements = vars[appendToTargets] || $(appendToTargets);
199                        elements.appendTo(appendToElements);
200                        break;
201                    case 'insert-after':
202                        var insertAfterTargets = action.properties['select-all'];
203                        var insertAfterElements = vars[insertAfterTargets] || $(insertAfterTargets);
204                        elements.insertAfter(insertAfterElements);
205                        break;
206                    case 'prepend-to':
207                        var prependToTargets = action.properties['select-all'];
208                        var prependToElements = vars[prependToTargets] || $(prependToTargets);
209                        elements.prependTo(prependToElements);
210                        break;
211                    case 'insert-before':
212                        var insertBeforeTargets = action.properties['select-all'];
213                        var insertBeforeElements = vars[insertBeforeTargets] || $(insertBeforeTargets);
214                        elements.insertBefore(insertBeforeElements);
215                        break;
216                    default:
217                        elements[action.action](action.properties);
218                }
219            });
220        });
221    }
222
223    // Function to index the done tags
224    function indexDone() {
225        var done = {};
226        $('hijinx done').each(function () {
227            var node = $(this);
228            var selectAll = node.find('select-all');
229            var targets = selectAll.attr('targets');
230            var actions = selectAll.children();
231            if (!done[targets]) {
232                done[targets] = [];
233            }
234            actions.each(function () {
235                var action = $(this);
236                var properties = {};
237                action.children().each(function () {
238                    var property = $(this);
239                    properties[property.prop('tagName').toLowerCase()] = property.text();
240                });
241                done[targets].push({
242                    action: action.prop('tagName').toLowerCase(),
243                    properties: properties
244                });
245            });
246        });
247        return done;
248    }
249
250    // Function to process the done tags
251    function processDone(done) {
252        $.each(done, function (targets, actions) {
253            var elements = $(targets);
254            actions.forEach(function (action) {
255                switch (action.action) {
256                    case 'css':
257                        elements.css(action.properties);
258                        break;
259                    // Add more cases here for other actions you want to supp
259ort
260                }
261            });
262        });
263    }
264
265    function refresh() {
266        return new Promise((resolve, reject) => {
267            try {
268                //console.log('Refresh function started'); // Log when the function starts
269
270                // Clear existing objects
271                this.vars = {};
272                this.selectAlls = {};
273
274                // Destroy existing animations
275                for (var key in this.animations) {
276                    this.animations[key].users.forEach(function (user) {
277                        if (user.timeline) {
278                            user.timeline.kill();
279                        }
280                        if (user.scrollTrigger) {
281                            user.scrollTrigger.kill();
282                        }
283                    });
284                }
285
286                // Clear animations
287                this.animations = {};
288                this.vars = indexVars();
289                this.animations = indexAnimations();
290                this.selectAlls = indexSelectAlls();
291                processSelectAlls(this.vars, this.selectAlls);
292
293                // Index and process done tags
294                var done = indexDone();
295                processDone(done);
296
297                // Add the done actions to the hijinx object
298                window.hijinx.done = done;
299
300                //console.log('Refresh function finished'); // Log when the function finishes
301
302                resolve();
303            } catch (error) {
304                reject(error);
305            }
306        });
307    }
308
309    // Expose the refresh function, the sets, select-alls, and done actions
310    window.hijinx = {
311        refresh: refresh,
312        vars: {},
313        selectAlls: {},
314        done: [] // Add this line to expose the done actions
315    };
316
317    // When the window loads, refresh the hijinx
318    $(window).on('load', function () {
319        hijinx.refresh();
320    });
321
322})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.