PageSourceSearch

https://guideposts.org/wp-content/plugins/free-downloads-woocommer…/assets/js/somdn_pro_script.js?ver=3.3.31

js guideposts.org collected 2026-09-24 09:03:42 UTC 18,111 bytes, 533 lines download raw bytes

1(function($) {
2
3  var clicked_button = '';
4
5  /**
6   * Scripts relating to adding/removing the "loading" class which some themes use
7   */
8
9  $('body').on('click', '.somdn-download-button:not(.somdn-checkbox-submit), .somdn-download-archive', function (e) {
10    // Assign the clicked link/button to the clicked_button variable for later
11    clicked_button = $(this);
12    var form = $(this).closest('form');
13    if (!capture_email_active_page(form)) {
14      $(this).addClass('loading');
15    }
16  });
17
18  $('body').on('click', '.somdn-download-button, .somdn-download-archive', function (e) {
19    var element = $(this);
20    setTimeout(
21      function() {
22        if (element.hasClass('loading')) {
23          element.removeClass('loading');
24        }
25      },
26    2000);
27  });
28
29  $('body').on('somdn_email_capture_submit_clicked_success', function(event, click_event, button, form) {
30
31    // If a button or archive page link was clicked add the "loading" class and remove it after 2 seconds.
32    if (clicked_button.length) {
33      clicked_button.addClass('loading');
34      setTimeout(
35        function() {
36          if (clicked_button.hasClass('loading')) {
37            clicked_button.removeClass('loading');
38          }
39        },
40        2000);
41    }
42
43  });
44
45  /**********************************************************************/
46
47  /**
48   * Scripts relating to download buttons that are actually anchor elements
49   */
50
51  $('body').on('click', 'a.somdn-download-archive', function (e) {
52    e.stopImmediatePropagation();
53    var form = $(this).closest('form.somdn-archive-download-form');
54    if (capture_email_active_page(form)) {
55      somdn_open_email_capture(form, e);
56    } else {
57      form.submit();
58    }
59    return false;
60  });
61
62  $('body').on('click', '.somdn-download-link', function (e) {
63    e.stopImmediatePropagation();
64    var form = $(this).closest('form');
65    if (capture_email_active_page(form)) {
66      somdn_open_email_capture(form, e);
67    } else {
68      form.submit();
69    }
70    return false;
71  });
72
73  $('body').on('click', '.bundled-single-file .somdn-download-button', function(e) {
74    e.stopImmediatePropagation();
75    var product_url = $(this).closest('.bundled-single-file').data('url');
76    var form = $('<form action="' + product_url + '" method="post"></form>');
77    var params = $(this).closest('.bundled-single-file').find('input');
78    params.clone().appendTo( form );
79    form.appendTo($('body'));
80    form.submit();
81    form.remove();
82    return false;
83  });
84
85  /**********************************************************************/
86
87  /**
88   * Scripts relating to the multiple file checkbox form
89   */
90
91  $('body').on('click', '.somdn-checkbox-form .somdn-checkbox-submit', function (e) {
92    var form = $(this).closest('form');
93    if ($(form).find('input[type="checkbox"]:checked').length == 0) {
94      e.preventDefault();
95      $('.somdn-form-validate').css('display', 'block');
96    } else {
97      $('.somdn-form-validate').css('display', 'none');
98      $(this).addClass('loading');
99      var form = $(this).closest('form');
100      if (capture_email_active_page(form)) {
101        e.preventDefault();
102        capture_email_checkbox_form(e, this);
103      }
104    }
105  });
106
107  $('body').on('click', '.somdn-select-all-wrap input[type="checkbox"]', function (e) {
108    var c = this.checked;
109    var form = $(this).closest('form');
110    $(form).find('.somdn-checkboxes-wrap input[type="checkbox"]').prop('checked', c);
111  });
112
113  $('body').on('click', '.somdn-checkbox-form .somdn-checkbox-form-checkbox', function (e) {
114    var form = $(this).closest('form');
115    var checkboxes = $(form).find('.somdn-checkbox-form-checkbox');
116    var checked_count = $(form).find('.somdn-checkbox-form-checkbox:checked').length;// How many checkboxes currently checked
117    var count = checkboxes.length;// How many checkboxes in total
118    if (checked_count < count) {
119      $(form).find('.somdn-checkbox-all').prop('checked', false);
120    } else {
121      $(form).find('.somdn-checkbox-all').prop('checked', true);
122    }
123  });
124
125  /**********************************************************************/
126
127  /**
128   * Quick View scripts
129   */
130
131  $('body').on('click', '.somdn-qview-link', function (e) {
132    var prod_wrap = $(this).closest('li.product');
133    if (qview_active()) {
134      e.preventDefault();
135      somdn_open_qview(prod_wrap, event);
136    }
137  });
138
139  /**
140   * Check if Quick View is active globally
141   */
142  function qview_active() {
143    var qview_enabled = somdn_script_params.somdn_qview_active;
144    if (qview_enabled) {
145      return true;
146    } else {
147      return false;
148    }  
149  }
150
151  /**
152   * Check if Quick View is active on the current page
153   */
154  function qview_active_page(form) {
155    var qview_enabled = somdn_script_params.somdn_qview_active;
156    if (qview_enabled) {
157      return true;
158    } else {
159      return false;
160    }  
161  }
162
163  /**
164   * Open the Quick View modal
165   */
166  function somdn_open_qview(prod_wrap, event) {
167    var the_qview_wrap = $(prod_wrap).find('.somdn-qview-wrap');
168
169    $('body').addClass('somdn-qview-open');
170    $(the_qview_wrap).addClass('open');
171
172    $('body').trigger('somdn_open_qview', [ prod_wrap, event ]);
173  }
174
175  /**
176   * Close the Quick View modal
177   */
178  function somdn_close_qview(prod_wrap, event) {
179    $(prod_wrap).find('.somdn-checkbox-form-checkbox, .somdn-checkbox-all').prop('checked', false);
180    $(prod_wrap).find('.somdn-qview-wrap').removeClass('open');
181    $('body').removeClass('somdn-qview-open');
182
183    $('body').trigger('somdn_close_qview', [ prod_wrap, event ]);
184  }
185
186  /**
187   * Two events that close the Quick View modal
188   * 1. Clicking the X in the top right corner of the modal
189   * 2. Clicking anywhere outside the modal when it is open
190   */
191  $('body').on('click', '.somdn-qview-wrap .somdn-qview-close', function (event) {
192    var prod_wrap =  $(this).closest('li.product');
193    somdn_close_qview(prod_wrap, event);
194  });
195
196  $(document).on('click', '.somdn-qview-wrap', function(event) {
197    var prod_wrap = $(this).closest('li.product');
198    somdn_close_qview(prod_wrap, event);
199  }).on('click', '.somdn-qview-window', function(e) {
200      e.stopPropagation();
201  });
202
203  /**********************************************************************/
204
205  /**
206   * Scripts relating to the download forms where email capture is being used
207   */
208
209  function capture_email_checkbox_form(e, this_var) {
210    e.stopImmediatePropagation();
211    var form = $(this_var).closest('form');
212    if (capture_email_active_page(form)) {
213      somdn_open_email_capture(form, e);
214    } else {
215      form.submit();
216    }
217    return false;
218  }
219
220  $('body').on('click', '.somdn-download-button:not(.somdn-checkbox-submit)', function (e) {
221    e.stopImmediatePropagation();
222    var form = $(this).closest('form');
223    if (capture_email_active_page(form)) {
224      somdn_open_email_capture(form, e);
225    } else {
226      form.submit();
227    }
228    return false;
229  });
230
231  /**
232   * Email Capture scripts
233   */
234
235  /**
236   * Check if capture email is active globally
237   */
238  function capture_email_active() {
239    var capture_enabled = somdn_script_params.somdn_capture_emails_active;
240    if (capture_enabled) {
241      return true;
242    } else {
243      return false;
244    }  
245  }
246
247  /**
248   * Check if capture email is active on the current page
249   */
250  function capture_email_active_page(form) {
251    var the_email_wrap = $(form).find('.somdn-capture-email-wrap');
252    var the_email = $(the_email_wrap).find('.somdn-download-user-email');
253    var capture_enabled = somdn_script_params.somdn_capture_emails_active;
254    if (the_email.length && capture_enabled) {
255      return true;
256    } else {
257      return false;
258    }  
259  }
260
261  /**
262   * Open the email capture modal
263   */
264  function somdn_open_email_capture(the_form, event) {
265    $(the_form).addClass('somdn-form-email-capture');
266
267    var the_email_wrap = $(the_form).find('.somdn-capture-email-wrap');
268    var the_email = $(the_email_wrap).find('.somdn-download-user-email');
269
270    $(the_form).find('.somdn-capture-required').prop('required', true);
271    $(the_form).find('.somdn-capture-checkbox-wrap input[type="checkbox"].somdn-checkbox-auto-blank').prop('checked', false);
272
273    $('body').addClass('somdn-capture-email-open');
274    $(the_email_wrap).addClass('open');
275
276    $('body').trigger('somdn_open_email_capture', [ the_form, event ]);
277  }
278
279  /**
280   * Close the email capture modal
281   */
282  function somdn_close_email_capture(the_form, event) {
283
284    $(the_form).removeClass('somdn-form-email-capture');
285    $(the_form).find('.somdn-capture-email-wrap').removeClass('open');
286    $('body').removeClass('somdn-capture-email-open');
287    $(the_form).find('.somdn-capture-required').prop('required', false);
288
289    $('body').trigger('somdn_close_email_capture', [ the_form, event ]);
290
291  }
292
293  /**
294   * Two events that close the email capture modal
295   * 1. Clicking the X in the top right corner of the modal
296   * 2. Clicking anywhere outside the modal when it is open
297   */
298  $('body').on('click', '.somdn-capture-email-header .dashicons-no', function (event) {
299    var form = $(this).closest('form');
300    somdn_close_email_capture(form, event);
301  });
302
303  $(document).on('click', '.somdn-capture-email-wrap', function(event) {
304    var form = $(this).closest('form');
305    somdn_close_email_capture(form, event);
306  }).on('click', '.somdn-capture-email-wrap-form', function(e) {
307      e.stopPropagation();
308  });
309
310  /**
311   * Event when the user clicks the email capture submit button (submit event instead of click)
312   */
313  $('body').on('submit', 'form.somdn-form-email-capture', function (e) {
314
315    var form = this;
316    var button = $(this).find('button.somdn-capture-email-button');
317
318    $('body').trigger('somdn_email_capture_submit_clicked', [ e, button, form ]);
319
320    var email_name = $(form).find('input[name="somdn_download_user_name"]');
321    if (email_name.length) {
322      if (!email_name.val() && $(email_name).hasClass('somdn-capture-required')) {
323        alert(somdn_script_params.somdn_capture_fname_empty);
324        e.preventDefault();
325        return;
326      }
327      $('body input[name="somdn_download_user_name"]').each(function() {
328        $(this).val(email_name.val());
329      });
330    }
331
332    var email_lname = $(form).find('input[name="somdn_download_user_lname"]');
333    if (email_lname.length) {
334      if (!email_lname.val() && $(email_lname).hasClass('somdn-capture-required')) {
335        alert(somdn_script_params.somdn_capture_lname_empty);
336        e.preventDefault();
337        return;
338      }
339      $('body input[name="somdn_download_user_lname"]').each(function() {
340        $(this).val(email_lname.val());
341      });
342    }
343
344    var email_tel = $(form).find('input[name="somdn_download_user_tel"]');
345    if (email_tel.length) {
346      if (!email_tel.val() && $(email_tel).hasClass('somdn-capture-required')) {
347        alert(somdn_script_params.somdn_capture_tel_empty);
348        e.preventDefault();
349        return;
350      }
351      $('body input[name="somdn_download_user_tel"]').each(function() {
352        $(this).val(email_tel.val());
353      });
354    }
355
356    var email_company = $(form).find('input[name="somdn_download_user_company"]');
357    if (email_company.length) {
358      if (!email_company.val() && $(email_company).hasClass('somdn-capture-required')) {
359        alert(somdn_script_params.somdn_capture_company_empty);
360        e.preventDefault();
361        return;
362      }
363      $('body input[name="somdn_download_user_company"]').each(function() {
364        $(this).val(email_company.val());
365      });
366    }
367
368    var email_website = $(form).find('input[name="somdn_download_user_website"]');
369    if (email_website.length) {
370      if (!email_website.val() && $(email_website).hasClass('somdn-capture-required')) {
371        alert(somdn_script_params.somdn_capture_website_empty);
372        e.preventDefault();
373        return;
374      }
375      $('body input[name="somdn_download_user_website"]').each(function() {
376        $(this).val(email_website.val());
377      });
378    }
379
380    var user_email = $(form).find('input[name="somdn_download_user_email"]');
381    if (user_email.length) {
382
383      if (!user_email.val()) {
384        alert(somdn_script_params.somdn_capture_email_empty);
385        e.preventDefault();
386        return;
387      }
388
389      if (!isValidEmailAddress(user_email.val())) {
390        alert(somdn_script_params.somdn_capture_email_invalid);
391        e.preventDefault();
392        return;
393      }
394
395      $('body .somdn-download-user-email').each(function() {
396        $(this).val(user_email.val());
397      });
398
399    }
400
401    var sub_checkbox = $(form).find('input[name="somdn_capture_email_subscribe"]');
402    if (sub_checkbox.length) {
403      if (!$(sub_checkbox).is(':checked') && $(sub_checkbox).hasClass('somdn-capture-required')) {
404        alert(somdn_script_params.somdn_capture_checkbox_error);
405        e.preventDefault();
406        return;
407      }
408    }
409
410    somdn_close_email_capture(form, e);
411
412    $('body').trigger('somdn_email_capture_submit_clicked_success', [ e, button, form ]);
413
414  });
415
416  $('body').on('somdn_email_capture_submit_clicked_success', function(event, click_event, button, form) {
417    // Example event hook for user submitting the email capture form successfully
418  });
419
420  function isValidEmailAddress(emailAddress) {
421    var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
422    return pattern.test(emailAddress);
423  };
424
425  /**********************************************************************/
426
427  /**
428   * Scripts for manipulating variation product page
429   */
430  $(document).on('hide_variation', function(event, variation) {
431
432    $('.somdn-download-wrap-variable').each(function() {
433      $(this).css('display', 'none');
434      var this_wrap_variation = $(this).attr('data-somdn-var-id');
435      $(this).insertAfter('.somdn-variable-anchor[data-somdn-anchor-var-id="'+this_wrap_variation+'"]');
436    });
437
438    var variation_wrap = $('.variations_form').find('.woocommerce-variation-add-to-cart');
439    $(variation_wrap).css('display', '');
440
441  });
442
443  $(document).on('show_variation', function(event, variation) {
444
445    $('.somdn-download-wrap-variable').each(function() {
446      $(this).css('display', 'none');
447      var this_wrap_variation = $(this).attr('data-somdn-var-id');
448      $(this).insertAfter('.somdn-variable-anchor[data-somdn-anchor-var-id="'+this_wrap_variation+'"]');
449    });
450
451    var variation_wrap = $('.variations_form').find('.woocommerce-variation-add-to-cart');
452    var variation_id = variation['variation_id'];
453    var variation_download = $('*[data-somdn-var-id="'+variation_id+'"]');
454    if (variation_download.length) {
455      $(variation_download).find('.single_add_to_cart_button').removeClass('disabled wc-variation-selection-needed wc-variation-is-unavailable');
456      $(variation_wrap).css('display', 'none');
457      $(variation_download).css('display', 'block');
458      $(variation_download).insertAfter(variation_wrap);
459    } else {
460      $(variation_wrap).css('display', '');
461    }
462
463  });
464
465  /**********************************************************************/
466
467  /**
468   * Scripts for the download redirecting
469   */
470
471  $('body').on('click', 'a.somdn-redirect-form-link', function (e) {
472    e.preventDefault();
473    e.stopImmediatePropagation();
474    var somdn_redirect_form = $('body').find('form#somdn_download_redirect_form');
475    if (somdn_redirect_form.length) {
476      $(somdn_redirect_form).addClass('somdn-redirect-download-submitted');
477      somdn_redirect_form.submit();
478    }
479  });
480
481  $(document).ready(function() {
482    var somdn_redirect_form = $('body').find('form#somdn_download_redirect_form'); 
483    if (somdn_redirect_form.length) {
484      var redirect_time = somdn_script_params.somdn_redirect_time;
485      if (!redirect_time) {
486        redirect_time = 5000;
487      }
488      setTimeout(function() {
489        if (!$(somdn_redirect_form).hasClass('somdn-redirect-download-submitted')) {
490          somdn_redirect_form.submit();
491        }
492      }, redirect_time);
493    }
494  });
495
496  /*
497   * Functionality to add the product review form to valid downloaded products
498   */
499  $(document).ready(function() {
500    var product_reviews = $('body').find('div#reviews');
501    if (product_reviews.length) {
502      var review_form = $('body').find('div#reviews div#review_form_wrapper');
503      // Bail if the review form is already rendered. It won't be a valid product.
504      if (review_form.length) {
505        return;
506      }
507
508      var somdn_review_form = $('body').find('div#somdn-review_form_wrapper');
509      var somdn_review_login = $('body').find('#somdn-download-review-required');
510      // Bail if the download review form is not present.
511      if (!somdn_review_form.length && !somdn_review_login.length) {
512        return;
513      }
514
515      if (somdn_review_form.length) {
516        $('div#reviews .woocommerce-verification-required').remove();
517        $('#somdn-review_form_wrapper').insertAfter($('div#reviews div#comments'));
518        $('#somdn-review_form_wrapper').attr('id', 'review_form_wrapper');
519        $('#somdn-review_form').attr('id', 'review_form');
520        return;
521      }
522
523      if (somdn_review_login.length) {
524        $('div#reviews .woocommerce-verification-required').remove();
525        $('#somdn-download-review-required').insertAfter($('div#reviews div#comments'));
526        $('#somdn-download-review-required').attr('id', '');
527        return;
528      }
529
530    }
531  });
532
533})(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.