PageSourceSearch

https://skiclassics.com/wp-content/themes/skiclassics/app.js?ver=1769116609

js skiclassics.com collected 2026-09-24 23:41:18 UTC 16,658 bytes, 527 lines download raw bytes

1// $(document).ready(async function() {
2
3//     if ($('#lastResultsContainer').is(':visible')) {
4//         console.log('Div is visible');
5
6//         let last_results_ajax_url = $("#baseUrl").val() + '/wp-content/themes/skiclassics/v3_content_parts/';
7
8//         // Create an array of promises for each div
9//         const promises = $("#lastResultsContainer .v3-last-results-container").map(function() {
10//             const series = $(this).data("series");
11//             return adminAction(
12//                 last_results_ajax_url + 'last_results_ajax.php',
13//                 { div: series }
14//             );
15//         }).get(); // .get() converts jQuery object to plain array
16
17//         try {
18//             // Wait for all AJAX calls to finish
19//             const responses = await Promise.all(promises);
20
21//             responses.forEach((response, index) => {
22//                 const series = $("#lastResultsContainer .v3-last-results-container").eq(index).data("series");
23//                 // console.log(`Response for series "${series}":`, response);
24//                 if(response.series_html){
25//                     $(`div[data-series="${series}"]`).prepend('<h2>'+response.series_html+'</h2>');
26
27//                     if(response.logo_html){
28//                         $(`div[data-series="${series}"]`).prepend(response.logo_html);
29//                     }
30
31//                     let label = series == 'challengers' ? 'Last Challengers' : 'Last Pro Tour';
32//                     $(`div[data-series="${series}"]`).prepend('<h3 class="v3-series-heading">'+label+'</h3>');
33//                 }
34                
35
36//                 if(response.html){
37//                     for (const key in response.html) {
38//                         if (response.html.hasOwnProperty(key)) {
39//                             $(`div[data-series="${series}"] .table-container`).append(response.html[key]);
40//                         }
41//                     }
42//                 }
43//             });
44//         } catch (err) {
45//             console.error('One of the AJAX calls failed:', err);
46//         }
47//     }
48// });
49
50
51$(document).ready(function(){
52
53
54
55
56
57    jQuery(document).on('click','span.admin-action', async function (){
58
59        let admin_action_url = jQuery("#baseUrl").val() + '/wp-content/themes/skiclassics/v3_user_actions/';
60
61        const response = await adminAction(admin_action_url + 'admin_action_ajax.php', { 
62            user_id:jQuery(this).parent().find("#adminUserId").val(),
63            cpt:jQuery(this).data("cpt"),
64        });
65
66        if(response.error){
67            jQuery("#adminActionContainer").html("<p>" + response.error + "</p>");
68            return;
69        }
70
71        console.log(response);
72
73        if(response.html){
74            jQuery("#adminActionContainer").html(response.html);
75            return;            
76        }
77
78    });
79
80
81    jQuery(document).on('click','table.admin-action-table tr td.update', async function (){
82
83        let admin_action_url = jQuery("#baseUrl").val() + '/wp-content/themes/skiclassics/v3_user_actions/';
84
85        const response = await adminAction(admin_action_url + 'admin_action_ajax.php', { 
86            user_id:jQuery("#adminUserId").val(),
87            cpt:jQuery(this).parent().parent().parent().data("cpt"),
88            specific:jQuery(this).parent().data("specific")
89        });
90
91        if(response.error){
92            jQuery("#adminActionContainer").html("<p>" + response.error + "</p>");
93            return;
94        }
95
96        console.log(response);
97
98        // if(response.message.updated == 0){
99            // jQuery(this).text("0 updates");
100            // return;
101        // }
102
103        if (response.message.updated !== undefined && response.message.updated !== null) {
104            jQuery(this).text(response.message.updated + " updates");
105            return;
106            // jQuery("#adminActionContainer").html("<p>Updated " + response.message.updated + " fields for "+(jQuery(this).parent().parent().parent().data("cpt") == 'scskier' ? 'scID ' : 'race_id ')+jQuery(this).parent().data("specific")+"...</p>");
107            // return;            
108        }
109
110
111
112    });
113    
114
115
116
117    // implemented APRIL 2025 along with Rule implementation
118    if(jQuery("#rule-marketing-checkbox").length > 0){
119        
120        if(localStorage.getItem('rule_marketing_opt_in') && localStorage.getItem('rule_marketing_opt_in') == 1){
121            $("#rule-marketing-checkbox").prop('checked', true);
122        }
123        jQuery("#rule-marketing-checkbox").on("change", function () {
124            console.log("change");
125            localStorage.setItem('rule_marketing_opt_in', jQuery("#rule-marketing-checkbox").is(":checked") ? 1 : 0);
126            console.log(jQuery("#rule-marketing-checkbox").is(":checked") ? 1 : 0);
127        });
128    } 
129
130
131
132    // SEARCH WITH ENTER KEY
133    $(document).on("input", ".search-content input#searchNews", function(e){
134        
135        var input = $(this).val();
136
137        if(e.which == 13){ 
138
139        }
140
141        if(input.length > 3){             
142            jQuery.ajax({
143                type: "post",
144                dataType: "json",
145                url: ajaxurl,
146                data: {
147                    action:'search_news', 
148                    query: input
149                },
150                success: function(result){
151                    if(result.count){
152                        // console.log("count:", result.count);
153                    }
154                    jQuery("#resultsOutput").html(result.content);
155                }
156            })
157        }
158        
159    });
160
161
162
163    // SEARCH WITH ENTER KEY
164    $(document).on("input", ".search-content input#searchSkier", function(e){
165        
166        var input = $(this).val();
167
168        if(e.which == 13){ 
169
170        }
171
172        if(input.length > 2){             
173            jQuery.ajax({
174                type: "post",
175                dataType: "json",
176                url: ajaxurl,
177                data: {
178                    action:'search_skier', 
179                    query: input
180                },
181                success: function(result){
182                    jQuery("#resultsOutput").html(result.content);
183                }
184            })
185        }
186        
187    });
188
189
190
191    var results = {
192        season: [],
193        series: [],
194        races: [],
195        gender: []
196    };
197
198    $('.results-content .gender-input select').on('change', function(i,e) {
199
200        $(".series-input select option:selected").each(function() {
201            series = this.value;
202        });
203
204        $(".season-input select option:selected").each(function() {
205            season = this.value;
206        });
207
208        $(".races-input select option:selected").each(function() {
209            tour_stop = this.value;
210        });
211
212        $(".gender-input select option:selected").each(function() {
213            gender = this.value;
214        });
215
216        $(".nationality-input select option:selected").each(function() {
217            nation = this.value;
218        });
219
220        var base = jQuery('#resultsBase').val();
221        var url = base + '?season=' + season + '&series=' + series + '&stop=' + tour_stop + '&gender=' + gender + '&nation='+nation;
222
223        console.log('Redirecting to:', url); 
224        window.location.assign(url)   
225
226    });
227
228
229
230    $('.results-content .races-input select').on('change', function(i,e) {
231
232        $(".series-input select option:selected").each(function() {
233            series = this.value;
234        });
235
236        $(".season-input select option:selected").each(function() {
237            season = this.value;
238        });
239
240        $(".races-input select option:selected").each(function() {
241            tour_stop = this.value;
242        });
243
244        $(".gender-input select option:selected").each(function() {
245            gender = this.value;
246        });
247
248        $(".nationality-input select option:selected").each(function() {
249            nation = this.value;
250        });
251
252        var base = jQuery('#resultsBase').val();
253        var url = base + '?season=' + season + '&series=' + series + '&stop=' + tour_stop + '&gender=' + gender + '&nation='+nation;
254
255        console.log('Redirecting to:', url); 
256        window.location.assign(url)   
257
258    });
259
260
261    $('.results-content .series-input select').on('change', function(i,e) {
262
263        $(".series-input select option:selected").each(function() {
264            series = this.value;
265        });
266
267        $(".season-input select option:selected").each(function() {
268            season = this.value;
269        });
270
271        $(".races-input select option:selected").each(function() {
272            tour_stop = this.value;
273        });
274
275        $(".gender-input select option:selected").each(function() {
276            gender = this.value;
277        });
278
279        $(".nationality-input select option:selected").each(function() {
280            nation = this.value;
281        });
282
283        var base = jQuery('#resultsBase').val();
284        var url = base + '?season=' + season + '&series=' + series + '&stop=' + tour_stop + '&gender=' + gender + '&nation='+nation;
285
286        console.log('Redirecting to:', url); 
287        window.location.assign(url)     
288
289    });
290
291    $('.results-content .season-input select').on('change', function(i,e) {
292
293        $(".series-input select option:selected").each(function() {
294            series = this.value;
295        });
296
297        $(".season-input select option:selected").each(function() {
298            season = this.value;
299        });
300
301        $(".races-input select option:selected").each(function() {
302            tour_stop = this.value;
303        });
304
305        $(".gender-input select option:selected").each(function() {
306            gender = this.value;
307        });
308
309        $(".nationality-input select option:selected").each(function() {
310            nation = this.value;
311        });
312
313        var base = jQuery('#resultsBase').val();
314        var url = base + '?season=' + season + '&series=' + series + '&stop=' + tour_stop + '&gender=' + gender + '&nation='+nation;
315
316        console.log('Redirecting to:', url); 
317        window.location.assign(url)     
318
319    });
320
321
322    $('.results-content .nationality-input select').on('change', function(i,e) {
323
324        $(".series-input select option:selected").each(function() {
325            series = this.value;
326        });
327
328        $(".season-input select option:selected").each(function() {
329            season = this.value;
330        });
331
332        $(".races-input select option:selected").each(function() {
333            tour_stop = this.value;
334        });
335
336        $(".gender-input select option:selected").each(function() {
337            gender = this.value;
338        });
339
340        $(".nationality-input select option:selected").each(function() {
341            nation = this.value;
342        });
343
344        var base = jQuery('#resultsBase').val();
345        var url = base + '?season=' + season + '&series=' + series + '&stop=' + tour_stop + '&gender=' + gender + '&nation='+nation;
346
347        console.log('Redirecting to:', url); 
348        window.location.assign(url)     
349
350    });
351
352
353    jQuery(document).on('click','#mapDivClose',function(){
354
355        console.log("here");
356        jQuery(this).parent().remove();
357
358    });
359    
360
361
362
363    jQuery(document).on('click','svg#menuIcon',function(){
364
365        if(jQuery(this).hasClass("fa-bars")){
366            jQuery("svg#menuIcon").replaceWith('<i class="fa-sharp fa-regular fa-xmark" id="menuIcon"></i>');
367        } else {
368            jQuery("svg#menuIcon").replaceWith('<i class="fa-regular fa-bars" id="menuIcon"></i>');
369        }
370
371        var display = jQuery(".main-menu a").css("display");
372        if(display == 'none'){
373            jQuery(".main-menu a").css("display", "block");
374        } else {
375            jQuery(".main-menu a").css("display", "none");
376        }
377        
378        // jQuery("svg#menuIcon").replaceWith('<i class="fa-sharp fa-regular fa-xmark" id="menuIcon"></i>');
379        jQuery(".main-menu").toggleClass("expanded-mobile-menu");
380        
381
382    });
383
384
385
386    jQuery(document).on('click','h2#expandCheckpoints',function(){
387        // console.log("hey");
388        jQuery(".checkpoint-menu div.checkpoints").css("display", "block");
389
390    });
391
392
393
394    jQuery(document).on('click','span#changeRefresh',function(){
395        let status = jQuery(this).attr('data-status');
396        if(status == 'turn_on'){
397            var expires = (new Date(Date.now() - 86400*30000)).toUTCString();    
398        } else {
399            var expires = (new Date(Date.now() + 86400*30000)).toUTCString();
400        }
401        
402        document.cookie = "wsm_auto_refresh=off; expires=" + expires + ";path=/;";
403        location.reload();
404
405    });
406
407    var timeleft = jQuery('span#changeRefresh').attr("data-interval");
408    var timestatus = jQuery('span#changeRefresh').attr("data-status");
409    if(timestatus == 'turn_off'){
410        var downloadTimer = setInterval(function(){
411            if(timeleft <= 0){
412              clearInterval(downloadTimer);
413              document.getElementById("pcountdown").innerHTML = "Finished";
414            } else {
415              document.getElementById("pcountdown").innerHTML = "This page will reload in " + timeleft + " seconds";
416            }
417            timeleft -= 1;
418          }, 1000);
419    
420    }
421    
422    
423
424    jQuery(document).on('click','span.load-more',function(){
425        $(".input-form select option:selected").each(function() {
426            let name = jQuery(this).parent().attr("name");
427            results[name] = this.value;
428        });
429
430        var offset_raw = jQuery(this).attr("item-counter");
431
432        var data = {
433            'action': 'treat_result_select_change',
434            'data' : results,
435            'offset' : offset_raw,
436            'nonce' : jQuery("#treat_result_select").val()
437        };
438        console.log(data);
439        jQuery.post(ajaxurl, data, function(response) {
440
441            if ( response != 0  ) {
442                const res = JSON.parse(response);
443                console.log(res);
444                jQuery("#resultsOutput").append(res.content);
445                
446            } else {
447                jQuery("#resultsOutput").append("Noe gikk galt!");
448            }
449        });       
450        jQuery(this).remove();
451
452    });    
453
454
455    $('select.minimal').on('change', function(i,e) {
456
457
458        var chkp_id = jQuery('select.minimal option:selected').attr("data-chkpt-id");
459        var gender = jQuery('select.minimal option:selected').attr("data-gender");
460        var live_id = jQuery('select.minimal option:selected').attr("data-live-id");
461
462        var str = '?live_event='+live_id+'&gender='+gender+'&checkpoint='+chkp_id;
463        window.location.href = jQuery("input#optionUrl").val() + str;
464
465
466
467    });
468
469
470    $('div[data-solution-ident]').each(function() {
471        let div = jQuery(this)[0]; // ← DOM-element
472        let ident = jQuery(this).attr("data-solution-ident");
473        // console.log(ident);
474        jQuery(this).css("text-align", "center");
475        insertSolutionDiv(div,ident);
476    });
477
478    afterAllDivsInserted();
479
480    function insertSolutionDiv(targetDiv, ident) {
481        const isMobile = window.innerWidth < 768;
482        let unitPart = '/222142442/skiclassics_new/';
483        
484        unitPart += isMobile ? 'm_' + ident : ident;
485    
486        const adDiv = document.createElement('div');
487        adDiv.setAttribute('data-ad-unit-id', unitPart);    
488        // Real working placeholder image
489        const adImg = document.createElement('img');
490        adImg.src = isMobile 
491        ? 'https://placehold.co/300x250?text='+ident 
492        : 'https://placehold.co/980x300?text='+ident;
493        adImg.alt = 'Ad Placeholder';
494        // adImg.style.width = '100%'; // Makes it responsive if needed
495        // adDiv.appendChild(adImg);
496        targetDiv.appendChild(adDiv);
497        console.log("inserted:", ident);
498    }
499    
500
501    function afterAllDivsInserted() {
502        console.debug('%cskiclassics.com <--> Solution', 'display: inline-block; color: #fff; background: green; padding: 1px 4px; border-radius: 3px;', `All divs are in DOM, now loading loadAds()`);
503        loadAds(); 
504    }
505
506
507});
508
509
510// https://www.youtube.com/watch?v=CWjNefiE47Y&ab_channel=TheNetNinja
511const kmnWsmPerformAjax = async (actionpar, itempar) => {
512    const rest = await $.ajax({url: ajaxurl, type: 'post', data: { action:actionpar, item:itempar, }, success: function(result){ return result; }});
513    const data = await rest;
514    return JSON.parse(data);
515};
516
517
518const adminAction = async (url, data) => {
519    const res = await fetch(url, {
520        method: 'POST',
521        headers: { 'Content-Type': 'application/json' },
522        body: JSON.stringify(data)
523    });
524
525    if (!res.ok) throw new Error(`HTTP ${res.status}`);
526    return res.json();
527};

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.