PageSourceSearch

https://www.royalqueenseeds.es/modules/cookingguide/js/main.js?_=6c9a6423f357c5101cbd67eca6a378ed

js royalqueenseeds.es collected 2026-09-26 05:45:09 UTC 16,460 bytes, 463 lines download raw bytes

1$(document).ready(function () {
2  const $recipesSpoilerContainer = $('.js-sweet-spoiler-recipes-container');
3  const $recipesContainer = $('.js-rqs-recipes-container');
4  const $productsContainer = $('.js-essential-products-container');
5  const $guideFeaturesContainer = $('.js-guide-features-container');
6  let spoilerSwiperInstance  = null;
7  let recipesSwiperInstance = null;
8  let productsSwiperInstance = null;
9  let guideFeaturesSwiperInstance = null;
10
11  spoilerSwiperInstance = toggleSpoilerSwiper($recipesSpoilerContainer, spoilerSwiperInstance);
12  recipesSwiperInstance = toggleRecipesSwiper($recipesContainer, recipesSwiperInstance);
13  productsSwiperInstance = toggleProductsSwiper($productsContainer, productsSwiperInstance);
14  guideFeaturesSwiperInstance = toggleGuideFeaturesSwiper($guideFeaturesContainer, guideFeaturesSwiperInstance);
15
16  $(window).on('resize', function() {
17    spoilerSwiperInstance = toggleSpoilerSwiper($recipesSpoilerContainer, spoilerSwiperInstance);
18    recipesSwiperInstance = toggleRecipesSwiper($recipesContainer, recipesSwiperInstance);
19    productsSwiperInstance = toggleProductsSwiper($productsContainer, productsSwiperInstance);
20    guideFeaturesSwiperInstance = toggleGuideFeaturesSwiper($guideFeaturesContainer, guideFeaturesSwiperInstance);
21  });
22
23  let hubspotForm = $('.js-cooking-guide-hs-form');
24  if (hubspotForm.length) {
25    let isCookingGuideSubmitting = false;
26    let isCookingGuideSubmitPending = false;
27    let isCookingGuideLockedAfterError = false;
28
29    hubspotForm.on('submit', function () {
30      const $form = $(this);
31      const $submitButton = $form.find('button[type="submit"], .submit-button').first();
32
33      isCookingGuideSubmitPending = true;
34      isCookingGuideLockedAfterError = false;
35
36      $form.addClass('is-submitting');
37      $submitButton.prop('disabled', true).attr('aria-disabled', 'true').addClass('is-disabled');
38    });
39
40    hubspotForm.validate({
41      invalidHandler: function (event, validator) {
42        const $form = $(validator.currentForm);
43        const $submitButton = $form.find('button[type="submit"], .submit-button').first();
44        isCookingGuideSubmitPending = false;
45        isCookingGuideLockedAfterError = false;
46        if (!isCookingGuideSubmitting) {
47          $form.removeClass('is-submitting');
48          $submitButton.prop('disabled', false).removeAttr('aria-disabled').removeClass('is-disabled');
49        }
50      },
51      rules: {
52        email: {
53          email: true,
54          required: true
55        },
56        firstname: {
57          required: true,
58        },
59        legal_consent: {
60          required: true
61        }
62      },
63      messages: {
64        firstname: {
65          required: fieldRequiredError
66        },
67        email: {
68          required: fieldRequiredError,
69          email: emailInvalidError,
70        },
71        legal_consent: {
72          required: fieldRequiredError
73        }
74      },
75      errorPlacement: function (error, element) {
76        if (element.attr('name') === 'email') {
77          error.appendTo(element.siblings('.email-errors'));
78        } else if (element.attr('name') === 'firstname') {
79          error.appendTo(element.siblings('.firstname-errors'));
80        } else if (element.attr('name') === 'legal_consent') {
81          error.appendTo(element.closest('.legal-consent-container').siblings('.legal-consent-errors'));
82        } else {
83          error.insertAfter(element);
84        }
85      },
86      submitHandler: function (form) {
87        const $form = $(form);
88        const $submitButton = $form.find('button[type="submit"], .submit-button').first();
89        if (isCookingGuideSubmitting || $form.data('submitting')) {
90          return false;
91        }
92        isCookingGuideSubmitting = true;
93        isCookingGuideSubmitPending = false;
94        $form.data('submitting', true);
95        $form.addClass('is-submitting');
96        $submitButton.prop('disabled', true).attr('aria-disabled', 'true').addClass('is-disabled');
97
98        let email = $form.find('.email');
99        let firstname = $form.find('.firstname');
100        let langId = (typeof idLang != 'undefined' && idLang) ? idLang : null;
101        $.ajax({
102          type: 'POST',
103          url: ajaxUrl,
104          data: 'ajax=1&email=' + email.val() + '&firstname=' + firstname.val() + '&id_lang=' + langId,
105          dataType: 'json',
106          success: function (data) {
107            if (data && data.error) {
108              isCookingGuideLockedAfterError = true;
109              if (data.exist) {
110                $('label.js-already-in-use-error').remove();
111                $('<label class="error js-already-in-use-error">'+emailAlreadyInUseError+'</label>').appendTo($(form).find('.email-errors'));
112              } else {
113                $('label.js-technical-error').remove();
114                $('<label class="error js-technical-error">'+hubspotTechnicalError+'</label>').attr({}).appendTo($(form).find('.email-errors'));
115              }
116            } else if (data && data.success) {
117              hubspotForm.hide();
118              $('.js-form-sent-message').show();
119            }
120          },
121          complete: function () {
122            isCookingGuideSubmitting = false;
123            $form.data('submitting', false);
124            if ($form.is(':visible') && !isCookingGuideLockedAfterError) {
125              $form.removeClass('is-submitting');
126              $submitButton.prop('disabled', false).removeAttr('aria-disabled').removeClass('is-disabled');
127            }
128          },
129          error: function (XMLHttpRequest, textStatus, errorThrown) {
130            alert('TECHNICAL ERROR Details: '+XMLHttpRequest.responseText);
131          }
132        });
133
134        return false;
135      }
136    });
137
138    hubspotForm.on('click', 'button[type="submit"], .submit-button', function (e) {
139      if (isCookingGuideSubmitting || isCookingGuideSubmitPending) {
140        e.preventDefault();
141        e.stopImmediatePropagation();
142        return false;
143      }
144    });
145
146    hubspotForm.on('input change', 'input, textarea, select', function () {
147      if (!isCookingGuideLockedAfterError) {
148        return;
149      }
150      const $form = $(this).closest('form');
151      const $submitButton = $form.find('button[type="submit"], .submit-button').first();
152
153      isCookingGuideLockedAfterError = false;
154      $form.removeClass('is-submitting');
155      $submitButton.prop('disabled', false).removeAttr('aria-disabled').removeClass('is-disabled');
156    });
157  }
158
159  $(document).on('click', '.js-like-button', function(e) {
160    e.preventDefault();
161    var self		= $(this),
162      is_like		= Number(!self.hasClass('fill')),
163      news_id		= self.data('blogid'),
164      counter		= self.parent().find('.js-likes-counter');
165
166    if ('undefined' != typeof(news_id)) {
167      $.ajax({
168        type: 'POST',
169        url: baseDir + 'modules/prestablog/ajax_like_button.php',
170        data:{id_prestablog_news: news_id, is_like: is_like}
171      });
172
173      self.toggleClass('fill');
174      counter.text(function(index, value){
175        value = Number($.trim(value));
176        return (is_like ? value + 1 : value - 1);
177      });
178    }
179  })
180
181  $('.js-sweet-spoiler-video-bg').each(function() {
182    var $video = $(this);
183    var video = $video.get(0);
184
185    $video.prop('muted', true);
186    $video.prop('loop', true);
187    $video.prop('autoplay', true);
188    $video.attr('playsinline', '');
189    $video.attr('webkit-playsinline', '');
190
191    $video.on('loadedmetadata', function() {
192      video.currentTime = 0.5;
193    });
194
195    $video.on('seeked', function() {
196      var canvas = document.createElement('canvas');
197      var ctx = canvas.getContext('2d');
198      canvas.width = video.videoWidth;
199      canvas.height = video.videoHeight;
200      ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
201      var poster = canvas.toDataURL('image/jpeg');
202      $video.attr('poster', poster);
203    });
204
205    $video.on('ended', function() {
206      video.currentTime = 0;
207      var playPromise = video.play();
208      if (playPromise && typeof playPromise.catch === 'function') {
209        playPromise.catch(function () {});
210      }
211    });
212
213    $video.on('canplay', function () {
214      var playPromise = video.play();
215      if (playPromise && typeof playPromise.catch === 'function') {
216        playPromise.catch(function () {});
217      }
218    });
219  });
220
221  $('.js-cannabis-amount-range-input').on('input change keyup', function() {
222    $('.js-cannabis-amount-input').val($(this).val());
223    $('.js-cannabis-amount-value').text($(this).val());
224  });
225
226  $('.js-cannabis-amount-input').on('input change keyup', function() {
227    $('.js-cannabis-amount-range-input').val($(this).val());
228    $('.js-cannabis-amount-value').text($(this).val());
229  });
230
231  $('.js-carrier-amount-input').on('input change keyup', function() {
232    $('.js-carrier-amount-value').text($(this).val());
233  });
234
235  $('.js-thc-strength-input').on('input change keyup', function() {
236    $('.js-thc-strength-value').text($(this).val());
237  });
238
239  $('.js-cbd-strength-input').on('input change keyup', function() {
240    $('.js-cbd-strength-value').text($(this).val());
241  });
242
243  $('.js-cooking-guide-input').on('input change keyup', calcb);
244
245  $('.products-container').each(function (i, e) {
246    $(this).find('.ajax_block_product .product-link').height('auto')
247    $(this).find('.ajax_block_product .product-link').equalHeights()
248  })
249});
250
251function toggleSpoilerSwiper($container, swiper) {
252  if (window.innerWidth < 768 && $container.length) {
253    if (!swiper) {
254      $container.addClass('swiper-container');
255      $container.find('.js-sweet-spoiler-recipe-items').addClass('swiper-wrapper');
256      $container.find('.js-sweet-spoiler-recipe-item').addClass('swiper-slide');
257
258      const swiperOptions = {
259        slidesPerView: 1.5,
260        spaceBetween: 30,
261        loop: true,
262        loopedSlides: 10,
263        speed: 1000,
264      };
265
266      swiper = new Swiper('.js-sweet-spoiler-section .swiper-container', swiperOptions);
267    }
268  } else {
269    if (swiper) {
270      swiper.destroy(true, true);
271      swiper = null;
272      $container.removeClass('swiper-container');
273      $container.find('.js-sweet-spoiler-recipe-items').removeClass('swiper-wrapper');
274      $container.find('.js-sweet-spoiler-recipe-item').removeClass('swiper-slide');
275    }
276  }
277
278  return swiper;
279}
280
281function toggleRecipesSwiper($container, swiper) {
282  if (window.innerWidth >= 768 && $container.length) {
283    if (!swiper) {
284      $container.addClass('swiper-container');
285      $container.find('.js-rqs-recipe-items').addClass('swiper-wrapper');
286      $container.find('.js-rqs-recipe-item').addClass('swiper-slide');
287
288      const swiperOptions = {
289        slidesPerView: 4,
290        spaceBetween: 30,
291        loop: false,
292        loopedSlides: 10,
293        speed: 1000,
294        navigation: {
295          nextEl: '.js-rqs-recipes-section .js-swiper-button-next',
296          prevEl: '.js-rqs-recipes-section .js-swiper-button-prev',
297        },
298      };
299
300      swiper = new Swiper($container[0], swiperOptions);
301    }
302  } else {
303    if (swiper) {
304      swiper.destroy(true, true);
305      swiper = null;
306      $container.removeClass('swiper-container');
307      $container.find('.js-rqs-recipe-items').removeClass('swiper-wrapper');
308      $container.find('.js-rqs-recipe-item').removeClass('swiper-slide');
309    }
310  }
311
312  return swiper;
313}
314
315function toggleProductsSwiper($container, swiper) {
316  if (window.innerWidth < 768 && $container.length) {
317    if (!swiper) {
318      $container.addClass('swiper-container');
319      $container.find('.js-essential-products-items').addClass('swiper-wrapper');
320      $container.find('.cookingguide').addClass('swiper-slide');
321
322      const swiperOptions = {
323        slidesPerView: 1.5,
324        spaceBetween: 30,
325        loop: true,
326        loopedSlides: 4,
327        speed: 1000,
328      };
329
330      swiper = new Swiper('.js-essentials-section .swiper-container', swiperOptions);
331    }
332  } else {
333    if (swiper) {
334      swiper.destroy(true, true);
335      swiper = null;
336      $container.removeClass('swiper-container');
337      $container.find('.js-essential-products-items').removeClass('swiper-wrapper');
338      $container.find('.cookingguide').removeClass('swiper-slide');
339    }
340  }
341
342  return swiper;
343}
344
345function toggleGuideFeaturesSwiper($container, swiper) {
346  if (window.innerWidth < 768 && $container.length) {
347    if (!swiper) {
348      $container.addClass('swiper-container');
349      $container.find('.js-guide-features-items').addClass('swiper-wrapper');
350      $container.find('.js-guide-features-item').addClass('swiper-slide');
351
352      const swiperOptions = {
353        slidesPerView: 2.5,
354        spaceBetween: 15,
355        loop: true,
356        loopedSlides: 4,
357        speed: 1000,
358        initialSlide: 0,
359      };
360
361      swiper = new Swiper('.js-guide-section .swiper-container', swiperOptions);
362    }
363  } else {
364    if (swiper) {
365      swiper.destroy(true, true);
366      swiper = null;
367      $container.removeClass('swiper-container');
368      $container.find('.js-guide-features-items').removeClass('swiper-wrapper');
369      $container.find('.js-guide-features-item').removeClass('swiper-slide');
370    }
371  }
372
373  return swiper;
374}
375
376function calcb() {
377  var canaB = $('.js-cannabis-amount-input').val();
378  var canathcb = $('.js-thc-strength-input').val();
379  var canacbdb = $('.js-cbd-strength-input').val();
380  var canabutb = $('.js-carrier-amount-input').val();
381  var canacanbutb = $('.js-infused-butter-input').val();
382  var portionsamb = $('.js-portions-input').val();
383
384//Cantidad total de THC (mg) en la marihuana
385  totalTHC = canaB * canathcb / 100 * 1000;
386  totalTHCM = Math.round(totalTHC * 10) / 10;
387
388//Cantidad total de CBD (mg) en la marihuana
389  totalCBD = canaB * canacbdb / 100 * 1000;
390  totalCBDM = Math.round(totalCBD * 10) / 10;
391
392//Cantidad final de cannabutter (g)
393  Cantmant = canabutb * 0.75;
394  CantmantM = Math.round(Cantmant * 10) / 10;
395
396//Cantidad total de THC (mg) en la cannabutter
397  cantthccannab = totalTHC * 0.6;
398  cantthccannabM = Math.round(cantthccannab * 10) / 10;
399
400//Cantidad total de CBD (mg) en la cannabutter
401  cantcbdcannab = totalCBD * 0.6;
402  cantcbdcannabM = Math.round(cantcbdcannab * 10) / 10;
403
404//Cantidad de THC (mg) en la cannabutter empleada
405  cantthcncanab = Cantmant > 0 ? (cantthccannab * canacanbutb / Cantmant) : 0;
406  cantthcncanabM = Math.round(cantthcncanab * 10) / 10;
407
408//Cantidad de CBD (mg) en la cannabutter empleada
409  cantcbdncanab = cantcbdcannab * canacanbutb / Cantmant;
410  cantcbdncanabM = Math.round(cantcbdncanab * 10) / 10;
411
412// Cantidad de THC (mg) por porción
413  cantthcporc = portionsamb > 0 ? (cantthcncanab / portionsamb) : 0;
414  cantthcporcM = Math.round(cantthcporc * 10) / 10;
415
416// Cantidad de CBD (mg) por porción
417  cantcbdporc = cantcbdncanab / portionsamb;
418  cantcbdporcM = Math.round(cantcbdporc * 10) / 10;
419
420  butterStrength = Cantmant > 0 ? (cantthccannab / Cantmant) : 0;
421  butterStrengthM = Math.round(butterStrength * 10) / 10;
422
423  $('.carrier-amount-max-value').text(CantmantM.toFixed(1));
424
425  var thcgradedesk = goodDoseText;
426  var thcDoseLevelColor = "#42B06E";
427  var thcDoseLevelIcon = $(".js-thc-good-dose-icon");
428  var thcDoseLevelBlock = $(".js-thc-dose-level");
429  var thcDoseLevelText = $(".js-thc-dose-level-text");
430  var thcDoseLevelBarFill = $(".js-dose-level-bar-fill");
431  $(".js-thc-dose-level .js-dose-icon").addClass('hidden');
432  if (cantthcporcM <= 20) {
433    thcgradedesk = goodDoseText;
434    thcDoseLevelColor = "#42B06E";
435    thcDoseLevelIcon = $(".js-thc-good-dose-icon");
436  }
437  if (cantthcporcM > 20 && cantthcporcM <= 30) {
438    thcgradedesk = moderateDoseText;
439    thcDoseLevelColor = "#FF6900";
440    thcDoseLevelIcon = $(".js-thc-moderate-dose-icon");
441  }
442  if (cantthcporcM > 30) {
443    thcgradedesk = strongDoseText;
444    thcDoseLevelColor = "#DF3636";
445    thcDoseLevelIcon = $(".js-thc-strong-dose-icon");
446  }
447
448// Insert values into results desktop
449  $(".js-infused-fat-value").html(CantmantM);
450  $(".js-thc-batch-value").html(cantthccannabM);
451  $(".js-butter-strength-value").html(butterStrengthM);
452  $(".js-cbd-batch-value").html(cantcbdcannabM);
453  $(".js-thc-per-portion").html(cantthcporcM);
454  thcDoseLevelText.text(thcgradedesk);
455  thcDoseLevelBlock.css("border-color", thcDoseLevelColor);
456  thcDoseLevelBarFill.css("background-color", thcDoseLevelColor);
457  thcDoseLevelIcon.removeClass('hidden');
458
459  var maxTHC = 50;
460  var progressPercent = (cantthcporcM / maxTHC) * 100;
461  progressPercent = Math.max(0, Math.min(progressPercent, 100));
462  thcDoseLevelBarFill.css("width", progressPercent + "%");
463}

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.