PageSourceSearch

https://photoshopcafe.com/wp-content/themes/photoshop-cafe/js/gallery.js

js photoshopcafe.com collected 2026-10-02 04:49:14 UTC 6,889 bytes, 203 lines download raw bytes

1jQuery(document).ready(function ($) {
2  const initLightbox = () => {
3    GLightbox({ selector: '.glightbox' });
4  };
5
6  initLightbox();
7
8  $('.gallery-tabs li').click(function () {
9    const tabId = $(this).data('tab');
10    $('.gallery-tabs li').removeClass('active');
11    $(this).addClass('active');
12    $('.gallery-tab-content').removeClass('active');
13    $('#' + tabId).addClass('active');
14
15    // Reset gallery-section class
16    $('.gallery-section').removeClass('no-more');
17
18    // Check if Load More button is present in the active tab
19    if (!$('#' + tabId).find('.load-more-btn').length) {
20      $('.gallery-section').addClass('no-more');
21    }
22  });
23
24
25  $(document).on('click', '.load-more-btn', function () {
26    const $btn = $(this);
27    const postId = $btn.data('post-id');
28    const tabId = $btn.data('tab-id');
29    let offset = parseInt($btn.data('offset'), 10);
30
31    $.ajax({
32      url: gallery_ajax.ajax_url,
33      type: 'POST',
34      data: {
35        action: 'load_more_gallery_images',
36        post_id: postId,
37        offset: offset
38      },
39      beforeSend: function () {
40        $btn.text('Loading...');
41      },
42      success: function (res) {
43        const $gallerySection = $('.gallery-section');
44
45        if (res.success && res.data.html) {
46          $('#' + tabId + ' .gallery-grid').append(res.data.html);
47          $btn.data('offset', offset + 6);
48          $btn.text('Load More');
49          initLightbox();
50
51          // Content loaded; assume more exists for now
52          $gallerySection.removeClass('no-more');
53
54          if (res.data.finished) {
55            $btn.remove();
56            $gallerySection.addClass('no-more');
57          }
58        } else {
59          $btn.remove();
60          $('.gallery-section').addClass('no-more');
61        }
62      }
63    });
64  });
65});
66
67// Custom Code For the MailerLite Form
68
69
70
71function mailterlite_submit(submitBtn) {
72  // Prevent default form submission
73  event.preventDefault();
74  
75  // Get the email input from the form
76  const emailInput = submitBtn.closest('form').querySelector('input[type="email"]');
77  const email = emailInput ? emailInput.value : '';
78  
79  if (!email) {
80    jQuery('.ml-validate-email').addClass('ml-error');
81    jQuery('.ml-block-form').addClass('ml-error');
82    
83    // console.log('No email found in form');
84    return;
85  }
86  
87  // console.log('Checking if user exists for email:', email);
88  
89  // Make AJAX call to check if user exists
90  jQuery.ajax({
91    url: gallery_ajax.ajax_url,
92    type: 'POST',
93    data: {
94      action: 'check_mailerlite_user',
95      email: email
96    },
97    beforeSend: function() {
98      jQuery('.ml-form-embedSubmit button.loading').show();
99      jQuery('.ml-form-embedSubmit button.mailerliteSubmitBtn').hide();
100      jQuery('.ml-form-embedSubmit button.primary').hide();
101    },
102    success: function(response) {
103      if (response.success) {
104        if (response.data.userExists) {
105          // console.log('User EXISTS - Email:', email);
106          // User exists, redirect to vault
107          window.location.href = '/photoshopcafe-vault';
108          jQuery('.ml-form-embedSubmit button.loading').hide();
109          jQuery('.ml-form-embedSubmit button.mailerliteSubmitBtn').show();
110        } else {
111          // console.log('User does NOT exist - Email:', email);
112          // User doesn't exist, submit to MailerLite via AJAX to prevent redirect
113          // console.log('Submitting to MailerLite via AJAX...');
114          
115          // Get the form data
116          const form = submitBtn.closest('form');
117          const formData = new FormData(form);
118          
119          // Submit to MailerLite via AJAX to prevent redirect
120          jQuery.ajax({
121            url: form.action,
122            type: 'POST',
123            data: formData,
124            processData: false,
125            contentType: false,
126            beforeSend: function() {
127              jQuery('.ml-form-embedSubmit button.loading').show();
128              jQuery('.ml-form-embedSubmit button.mailerliteSubmitBtn').hide();
129              jQuery('.ml-form-embedSubmit button.primary').hide();
130              // submitBtn.textContent = 'SUBSCRIBING...';
131            },
132            success: function(mailerliteResponse) {
133              // console.log('MailerLite submission successful:', mailerliteResponse);
134              // Handle success (e.g., show success message, redirect to vault)
135              // alert('Subscription successful! Redirecting to vault...');
136              window.location.href = '/vault?action=confirmation';
137              jQuery('.ml-form-embedSubmit button.loading').hide();
138              jQuery('.ml-form-embedSubmit button.mailerliteSubmitBtn').show();
139              // jQuery('.ml-form-embedSubmit button.primary').show();
140            },
141            error: function(xhr, status, error) {
142              console.log('MailerLite submission error:', error);
143              // alert('Subscription failed. Please try again.');
144            }
145          });
146        }
147      } else {
148        // console.log('Error checking user:', response.data);
149        // On error, allow form submission
150        submitBtn.closest('form').submit();
151      }
152    },
153    error: function(xhr, status, error) {
154      console.log('AJAX error:', error);
155      // On error, allow form submission
156      submitBtn.closest('form').submit();
157    }
158  });
159}
160
161document.addEventListener('DOMContentLoaded', () => {
162  const targets = document.querySelectorAll('.ml-embedded'); // all forms
163
164  targets.forEach(target => {
165    if (!target) return;
166
167    const observer = new MutationObserver(() => {
168      const submitBtn = target.querySelector('button[type="submit"]');
169
170      if (submitBtn) {
171        // Hide original button
172        submitBtn.style.display = 'none';
173
174        // Prevent Enter key submission
175        target.addEventListener('keydown', function(event) {
176          if (event.key === 'Enter') {
177            event.preventDefault();
178          }
179        });
180
181        // Add new button only if not already added
182        if (!target.querySelector('.mailerliteSubmitBtn')) {
183          const newBtn = document.createElement('button');
184          newBtn.type = 'button';
185          newBtn.className = 'primary secondary mailerliteSubmitBtn';
186          newBtn.textContent = 'UNLOCK FREEBEES';
187
188          // Trigger original submission
189          newBtn.addEventListener('click', () => {
190            // submitBtn.click();
191            mailterlite_submit(submitBtn); // <-- your custom function
192          });
193
194          submitBtn.parentNode.appendChild(newBtn);
195        }
196
197        observer.disconnect(); // stop watching once replaced
198      }
199    });
200
201    observer.observe(target, { childList: true, subtree: true });
202  });
203});

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.