/** * @file * Global utilities. * */ (function ($, Drupal) { var firebaseConfig = { apiKey: "AIzaSyBEYw4p40Dp-8s_D51hWEvryg9WCts220U", authDomain: "poker-fr.firebaseapp.com", databaseURL: "https://poker-fr.firebaseio.com", projectId: "poker-fr", storageBucket: "poker-fr.appspot.com", messagingSenderId: "593123066823", appId: "1:593123066823:web:23544741479f610d63cfe2", measurementId: "G-RK7HQVDMEZ" }; // Initialize Firebase firebase.initializeApp(firebaseConfig); var showalert = 0; function subscribetoken(currentToken) { var d= {}; $.ajax({ url :"https://api.coteur.com/notif/register", type: 'POST', contentType: 'application/json', data: JSON.stringify({token:currentToken,username:'',version:3,d,country:'fr' }) }) .done(function( data ) { // ok }); } const messaging = firebase.messaging(); messaging.usePublicVapidKey("BAHKZKft6iOKHdGffWnNlM3ggXmzJLm8AFeJ4Hr0BNN276f6T-nPh-NA3oltRk4qg1dib82JoSmwJ3bZYChe5SE"); messaging.onMessage((payload) => { console.log('Message received. ', payload); if (payload.notification!= null){ console.log('Message received. ', payload); showalert = 1; toastr.success(payload.data.title, payload.data.msg); } }); Notification.requestPermission().then((permission) => { if (permission === 'granted') { messaging.getToken().then((currentToken) => { if (currentToken != Cookies.get('currentToken')) { subscribetoken(currentToken); Cookies.set('currentToken', currentToken, { expires: 1, path: '/' }); } }).catch((err) => { //console.log('An error occurred while retrieving token. ', err); }); // Callback fired if Instance ID token is updated. messaging.onTokenRefresh(() => { messaging.getToken().then((refreshedToken) => { if (currentToken != Cookies.get('currentToken')) { //console.log("tokenrenew",currentToken); subscribetoken(currentToken); Cookies.set('currentToken', currentToken, { expires: 1, path: '/' }); } }).catch((err) => { // console.log('Unable to retrieve refreshed token ', err); //showToken('Unable to retrieve refreshed token ', err); }); }); } else { //console.log('Unable to get permission to notify.'); } }); 'use strict'; Drupal.behaviors.bootstrap_barrio_subtheme = { attach: function (context, settings) { } }; })(jQuery, Drupal); ; /*! js-cookie v3.0.0-rc.0 | MIT */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,function(){var r=e.Cookies,n=e.Cookies=t();n.noConflict=function(){return e.Cookies=r,n}}())}(this,function(){"use strict";function e(e){for(var t=1;t 1 && arguments[1] !== undefined ? arguments[1] : undefined; var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; key = key && !$.cookie.raw ? encodeURIComponent(key) : key; if (value !== undefined && !isFunction(value)) { var attributes = Object.assign({}, $.cookie.defaults, options); if (typeof attributes.expires === 'string' && attributes.expires !== '') { attributes.expires = new Date(attributes.expires); } var cookieSetter = cookies.withConverter({ write: function write(cookieValue) { return encodeURIComponent(cookieValue); } }); value = $.cookie.json && !$.cookie.raw ? JSON.stringify(value) : String(value); return cookieSetter.set(key, value, attributes); } var userProvidedConverter = value; var cookiesShim = cookies.withConverter({ read: function read(cookieValue, cookieName) { return reader(cookieValue, cookieName, userProvidedConverter, $.cookie.raw, $.cookie.json); } }); if (key !== undefined) { return cookiesShim.get(key); } var results = cookiesShim.get(); Object.keys(results).forEach(function (resultKey) { if (results[resultKey] === undefined) { delete results[resultKey]; } }); return results; }; $.cookie.defaults = Object.assign({ path: '' }, cookies.defaults); $.cookie.json = false; $.cookie.raw = false; $.removeCookie = function (key, options) { cookies.remove(key, Object.assign({}, $.cookie.defaults, options)); return !cookies.get(key); }; })(jQuery, Drupal, window.Cookies);; /** * @file * eu_cookie_compliance.js * * Defines the behavior of the eu cookie compliance banner. * * Statuses: * null: not yet agreed (or withdrawn), show popup * 0: Disagreed * 1: Agreed, show thank you banner * 2: Agreed */ (function ($, Drupal, drupalSettings) { 'use strict'; var euCookieComplianceBlockCookies; Drupal.behaviors.euCookieCompliancePopup = { attach: function (context) { $('body').once('eu-cookie-compliance').each(function () { // If configured, check JSON callback to determine if in EU. if (drupalSettings.eu_cookie_compliance.popup_eu_only_js) { if (Drupal.eu_cookie_compliance.showBanner()) { var url = drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix + 'eu-cookie-compliance-check'; var data = {}; $.getJSON(url, data, function (data) { // If in the EU, show the compliance banner. if (data.in_eu) { Drupal.eu_cookie_compliance.execute(); } // If not in EU, set an agreed cookie automatically. else { Drupal.eu_cookie_compliance.setStatus(2); } }); } } // Otherwise, fallback to standard behavior which is to render the banner. else { Drupal.eu_cookie_compliance.execute(); } }); }, }; Drupal.eu_cookie_compliance = {}; Drupal.eu_cookie_compliance.execute = function () { try { if (!drupalSettings.eu_cookie_compliance.popup_enabled) { return; } if (!Drupal.eu_cookie_compliance.cookiesEnabled()) { return; } var status = Drupal.eu_cookie_compliance.getCurrentStatus(); if ((status === 0 && drupalSettings.eu_cookie_compliance.method === 'default') || status === null || (drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup)) { if (!drupalSettings.eu_cookie_compliance.disagree_do_not_show_popup || status === null) { // Detect mobile here and use mobile_popup_html_info, if we have a mobile device. if (window.matchMedia('(max-width: ' + drupalSettings.eu_cookie_compliance.mobile_breakpoint + 'px)').matches && drupalSettings.eu_cookie_compliance.use_mobile_message) { Drupal.eu_cookie_compliance.createPopup(drupalSettings.eu_cookie_compliance.mobile_popup_html_info, (status !== null)); } else { Drupal.eu_cookie_compliance.createPopup(drupalSettings.eu_cookie_compliance.popup_html_info, (status !== null)); } Drupal.eu_cookie_compliance.initPopup(); } } if (status === 1 && drupalSettings.eu_cookie_compliance.popup_agreed_enabled) { // Thank you banner. Drupal.eu_cookie_compliance.createPopup(drupalSettings.eu_cookie_compliance.popup_html_agreed); Drupal.eu_cookie_compliance.attachHideEvents(); } else if (status === 2 && drupalSettings.eu_cookie_compliance.withdraw_enabled) { if (!drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { Drupal.eu_cookie_compliance.createWithdrawBanner(drupalSettings.eu_cookie_compliance.withdraw_markup); } Drupal.eu_cookie_compliance.attachWithdrawEvents(); } } catch (e) { } }; Drupal.eu_cookie_compliance.initPopup = function() { Drupal.eu_cookie_compliance.attachAgreeEvents(); if (drupalSettings.eu_cookie_compliance.method === 'categories') { var categories_checked = []; if (Drupal.eu_cookie_compliance.getCurrentStatus() === null) { if (drupalSettings.eu_cookie_compliance.select_all_categories_by_default) { categories_checked = drupalSettings.eu_cookie_compliance.cookie_categories; } } else { categories_checked = Drupal.eu_cookie_compliance.getAcceptedCategories(); } Drupal.eu_cookie_compliance.setPreferenceCheckboxes(categories_checked); Drupal.eu_cookie_compliance.attachSavePreferencesEvents(); } if (drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { Drupal.eu_cookie_compliance.attachWithdrawEvents(); var currentStatus = Drupal.eu_cookie_compliance.getCurrentStatus(); if (currentStatus === 1 || currentStatus === 2) { $('.eu-cookie-withdraw-button').show(); } } } Drupal.eu_cookie_compliance.createWithdrawBanner = function (html) { var $html = $('
').html(html); var $banner = $('.eu-cookie-withdraw-banner', $html); $html.attr('id', 'sliding-popup'); $html.addClass('eu-cookie-withdraw-wrapper'); if (!drupalSettings.eu_cookie_compliance.popup_use_bare_css) { $banner.height(drupalSettings.eu_cookie_compliance.popup_height) .width(drupalSettings.eu_cookie_compliance.popup_width); } $html.hide(); var height = 0; if (drupalSettings.eu_cookie_compliance.popup_position) { $html.prependTo('body'); height = $html.outerHeight(); $html.show() .addClass('sliding-popup-top') .addClass('clearfix') .css({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($('body').css('padding-top')) + parseInt($('body').css('margin-top')) + height) : -1 * height }); // For some reason, the tab outerHeight is -10 if we don't use a timeout // function to reveal the tab. setTimeout(function () { var height = $html.outerHeight(); $html.animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($('body').css('padding-top')) + parseInt($('body').css('margin-top')) + height) : -1 * height }, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { $html.trigger('eu_cookie_compliance_popup_open'); }); }.bind($html), 0); } else { if (drupalSettings.eu_cookie_compliance.better_support_for_screen_readers) { $html.prependTo('body'); } else { $html.appendTo('body'); } height = $html.outerHeight(); $html.show() .addClass('sliding-popup-bottom') .css({ bottom: -1 * height }); // For some reason, the tab outerHeight is -10 if we don't use a timeout // function to reveal the tab. setTimeout(function () { var height = $html.outerHeight(); $html.animate({ bottom: -1 * (height) }, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { $html.trigger('eu_cookie_compliance_popup_open'); }); }.bind($html), 0); } }; Drupal.eu_cookie_compliance.toggleWithdrawBanner = function () { var $wrapper = $('#sliding-popup'); var $tab = $('.eu-cookie-withdraw-tab'); var topBottom = (drupalSettings.eu_cookie_compliance.popup_position ? 'top' : 'bottom'); var height = $wrapper.outerHeight(); var $bannerIsShowing = drupalSettings.eu_cookie_compliance.popup_position ? parseInt($wrapper.css('top')) === (!drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($('body').css('padding-top')) + parseInt($('body').css('margin-top'))) : 0) : parseInt($wrapper.css('bottom')) === 0; if (drupalSettings.eu_cookie_compliance.popup_position) { if ($bannerIsShowing) { $wrapper.animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($('body').css('padding-top')) + parseInt($('body').css('margin-top')) + height) : -1 * height}, drupalSettings.eu_cookie_compliance.popup_delay); } else { $wrapper.animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($('body').css('padding-top')) + parseInt($('body').css('margin-top'))) : 0}, drupalSettings.eu_cookie_compliance.popup_delay); } } else { if ($bannerIsShowing) { $wrapper.animate({'bottom' : -1 * (height)}, drupalSettings.eu_cookie_compliance.popup_delay); } else { $wrapper.animate({'bottom' : 0}, drupalSettings.eu_cookie_compliance.popup_delay); } } }; Drupal.eu_cookie_compliance.createPopup = function (html, closed) { // This fixes a problem with jQuery 1.9. var popup = $('
').html(html); popup.attr('id', 'sliding-popup'); if (!drupalSettings.eu_cookie_compliance.popup_use_bare_css) { popup.height(drupalSettings.eu_cookie_compliance.popup_height) .width(drupalSettings.eu_cookie_compliance.popup_width); } popup.hide(); var height = 0; if (drupalSettings.eu_cookie_compliance.popup_position) { popup.prependTo('body'); height = popup.outerHeight(); popup.show() .addClass('sliding-popup-top clearfix') .css({ top: -1 * height }); if (closed !== true) { popup.animate({top: 0}, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { popup.trigger('eu_cookie_compliance_popup_open'); }); } } else { if (drupalSettings.eu_cookie_compliance.better_support_for_screen_readers) { popup.prependTo('body'); } else { popup.appendTo('body'); } height = popup.outerHeight(); popup.show() .addClass('sliding-popup-bottom') .css({bottom: -1 * height}); if (closed !== true) { popup.animate({bottom: 0}, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { popup.trigger('eu_cookie_compliance_popup_open'); }); } } }; Drupal.eu_cookie_compliance.attachAgreeEvents = function () { var clickingConfirms = drupalSettings.eu_cookie_compliance.popup_clicking_confirmation; var scrollConfirms = drupalSettings.eu_cookie_compliance.popup_scrolling_confirmation; if (drupalSettings.eu_cookie_compliance.method === 'categories' && drupalSettings.eu_cookie_compliance.enable_save_preferences_button) { // The agree button becomes an agree to all categories button when the 'save preferences' button is present. $('.agree-button').click(Drupal.eu_cookie_compliance.acceptAllAction); } else { $('.agree-button').click(Drupal.eu_cookie_compliance.acceptAction); } $('.decline-button').click(Drupal.eu_cookie_compliance.declineAction); if (clickingConfirms) { $('a, input[type=submit], button[type=submit]').not('.popup-content *').bind('click.euCookieCompliance', Drupal.eu_cookie_compliance.acceptAction); } if (scrollConfirms) { var alreadyScrolled = false; var scrollHandler = function () { if (alreadyScrolled) { Drupal.eu_cookie_compliance.acceptAction(); $(window).off('scroll', scrollHandler); } else { alreadyScrolled = true; } }; $(window).bind('scroll', scrollHandler); } $('.find-more-button').not('.find-more-button-processed').addClass('find-more-button-processed').click(Drupal.eu_cookie_compliance.moreInfoAction); }; Drupal.eu_cookie_compliance.attachSavePreferencesEvents = function () { $('.eu-cookie-compliance-save-preferences-button').click(Drupal.eu_cookie_compliance.savePreferencesAction); }; Drupal.eu_cookie_compliance.attachHideEvents = function () { var popupHideAgreed = drupalSettings.eu_cookie_compliance.popup_hide_agreed; var clickingConfirms = drupalSettings.eu_cookie_compliance.popup_clicking_confirmation; $('.hide-popup-button').click(function () { Drupal.eu_cookie_compliance.changeStatus(2); } ); if (clickingConfirms) { $('a, input[type=submit], button[type=submit]').unbind('click.euCookieCompliance'); } if (popupHideAgreed) { $('a, input[type=submit], button[type=submit]').bind('click.euCookieComplianceHideAgreed', function () { Drupal.eu_cookie_compliance.changeStatus(2); }); } $('.find-more-button').not('.find-more-button-processed').addClass('find-more-button-processed').click(Drupal.eu_cookie_compliance.moreInfoAction); }; Drupal.eu_cookie_compliance.attachWithdrawEvents = function () { $('.eu-cookie-withdraw-button').click(Drupal.eu_cookie_compliance.withdrawAction); $('.eu-cookie-withdraw-tab').click(Drupal.eu_cookie_compliance.toggleWithdrawBanner); }; Drupal.eu_cookie_compliance.acceptAction = function () { var agreedEnabled = drupalSettings.eu_cookie_compliance.popup_agreed_enabled; var nextStatus = 1; if (!agreedEnabled) { Drupal.eu_cookie_compliance.setStatus(1); nextStatus = 2; } if (!euCookieComplianceHasLoadedScripts && typeof euCookieComplianceLoadScripts === "function") { euCookieComplianceLoadScripts(); } if (typeof euCookieComplianceBlockCookies !== 'undefined') { clearInterval(euCookieComplianceBlockCookies); } if (drupalSettings.eu_cookie_compliance.method === 'categories') { // Select Checked categories. var categories = $("#eu-cookie-compliance-categories input:checkbox:checked").map(function(){ return $(this).val(); }).get(); Drupal.eu_cookie_compliance.setAcceptedCategories(categories); // Load scripts for all categories. Drupal.eu_cookie_compliance.loadCategoryScripts(categories); } Drupal.eu_cookie_compliance.changeStatus(nextStatus); }; Drupal.eu_cookie_compliance.acceptAllAction = function () { var allCategories = drupalSettings.eu_cookie_compliance.cookie_categories; Drupal.eu_cookie_compliance.setPreferenceCheckboxes(allCategories); Drupal.eu_cookie_compliance.acceptAction(); } Drupal.eu_cookie_compliance.savePreferencesAction = function () { var categories = $("#eu-cookie-compliance-categories input:checkbox:checked").map(function(){ return $(this).val(); }).get(); var agreedEnabled = drupalSettings.eu_cookie_compliance.popup_agreed_enabled; var nextStatus = 1; if (!agreedEnabled) { Drupal.eu_cookie_compliance.setStatus(1); nextStatus = 2; } Drupal.eu_cookie_compliance.setAcceptedCategories(categories); if (!euCookieComplianceHasLoadedScripts && typeof euCookieComplianceLoadScripts === "function") { euCookieComplianceLoadScripts(); } Drupal.eu_cookie_compliance.loadCategoryScripts(categories); Drupal.eu_cookie_compliance.changeStatus(nextStatus); }; Drupal.eu_cookie_compliance.loadCategoryScripts = function(categories) { for (var cat in categories) { if (euCookieComplianceHasLoadedScriptsForCategory[cat] !== true && typeof euCookieComplianceLoadScripts === "function") { euCookieComplianceLoadScripts(categories[cat]); euCookieComplianceHasLoadedScriptsForCategory[cat] = true; } } } Drupal.eu_cookie_compliance.declineAction = function () { Drupal.eu_cookie_compliance.setStatus(0); var popup = $('#sliding-popup'); if (popup.hasClass('sliding-popup-top')) { popup.animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($('body').css('padding-top')) + parseInt($('body').css('margin-top')) + popup.outerHeight()) : popup.outerHeight() * -1 }, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { popup.hide(); }).trigger('eu_cookie_compliance_popup_close'); } else { popup.animate({ bottom: popup.outerHeight() * -1 }, drupalSettings.eu_cookie_compliance.popup_delay, null, function () { popup.hide(); }).trigger('eu_cookie_compliance_popup_close'); } }; Drupal.eu_cookie_compliance.withdrawAction = function () { Drupal.eu_cookie_compliance.setStatus(0); Drupal.eu_cookie_compliance.setAcceptedCategories([]); location.reload(); }; Drupal.eu_cookie_compliance.moreInfoAction = function () { if (drupalSettings.eu_cookie_compliance.disagree_do_not_show_popup) { Drupal.eu_cookie_compliance.setStatus(0); if (drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { $('#sliding-popup .eu-cookie-compliance-banner').trigger('eu_cookie_compliance_popup_close').hide(); } else { $('#sliding-popup').trigger('eu_cookie_compliance_popup_close').remove(); } } else { if (drupalSettings.eu_cookie_compliance.popup_link_new_window) { window.open(drupalSettings.eu_cookie_compliance.popup_link); } else { window.location.href = drupalSettings.eu_cookie_compliance.popup_link; } } }; Drupal.eu_cookie_compliance.getCurrentStatus = function () { var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed' : drupalSettings.eu_cookie_compliance.cookie_name; var value = $.cookie(cookieName); value = parseInt(value); if (isNaN(value)) { value = null; } return value; }; Drupal.eu_cookie_compliance.setPreferenceCheckboxes = function (categories) { for (var i in categories) { $("#eu-cookie-compliance-categories input:checkbox[value='" + categories[i] + "']").prop("checked", true); } } Drupal.eu_cookie_compliance.getAcceptedCategories = function () { var allCategories = drupalSettings.eu_cookie_compliance.cookie_categories; var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-categories' : drupalSettings.eu_cookie_compliance.cookie_name + '-categories'; var value = $.cookie(cookieName); var selectedCategories = []; if (value !== null && typeof value !== 'undefined') { value = JSON.parse(value); selectedCategories = value; } if (Drupal.eu_cookie_compliance.fix_first_cookie_category && !$.inArray(allCategories[0], selectedCategories)) { selectedCategories.push(allCategories[0]); } return selectedCategories; }; Drupal.eu_cookie_compliance.changeStatus = function (value) { var status = Drupal.eu_cookie_compliance.getCurrentStatus(); var reloadPage = drupalSettings.eu_cookie_compliance.reload_page; if (status === value) { return; } if (drupalSettings.eu_cookie_compliance.popup_position) { $('.sliding-popup-top').animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($('body').css('padding-top')) + parseInt($('body').css('margin-top')) + $('#sliding-popup').outerHeight()) : $('#sliding-popup').outerHeight() * -1 }, drupalSettings.eu_cookie_compliance.popup_delay, function () { if (value === 1 && status === null && !reloadPage) { $('.sliding-popup-top').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.popup_html_agreed).animate({ top: !drupalSettings.eu_cookie_compliance.fixed_top_position ? -(parseInt($('body').css('padding-top')) + parseInt($('body').css('margin-top'))) : 0 }, drupalSettings.eu_cookie_compliance.popup_delay); Drupal.eu_cookie_compliance.attachHideEvents(); } else if (status === 1 && !(drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup)) { $('.sliding-popup-top').not('.eu-cookie-withdraw-wrapper').trigger('eu_cookie_compliance_popup_close').remove(); } Drupal.eu_cookie_compliance.showWithdrawBanner(value); }); } else { $('.sliding-popup-bottom').animate({ bottom: $('#sliding-popup').outerHeight() * -1 }, drupalSettings.eu_cookie_compliance.popup_delay, function () { if (value === 1 && status === null && !reloadPage) { $('.sliding-popup-bottom').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.popup_html_agreed).animate({ bottom: 0 }, drupalSettings.eu_cookie_compliance.popup_delay); Drupal.eu_cookie_compliance.attachHideEvents(); } else if (status === 1) { if (drupalSettings.eu_cookie_compliance.withdraw_enabled && drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { // Restore popup content. if (window.matchMedia('(max-width: ' + drupalSettings.eu_cookie_compliance.mobile_breakpoint + 'px)').matches && drupalSettings.eu_cookie_compliance.use_mobile_message) { $('.sliding-popup-bottom').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.mobile_popup_html_info); } else { $('.sliding-popup-bottom').not('.eu-cookie-withdraw-wrapper').html(drupalSettings.eu_cookie_compliance.popup_html_info); } Drupal.eu_cookie_compliance.initPopup(); } else { $('.sliding-popup-bottom').not('.eu-cookie-withdraw-wrapper').trigger('eu_cookie_compliance_popup_close').remove(); } } Drupal.eu_cookie_compliance.showWithdrawBanner(value); }); } if (drupalSettings.eu_cookie_compliance.reload_page) { location.reload(); } Drupal.eu_cookie_compliance.setStatus(value); }; Drupal.eu_cookie_compliance.showWithdrawBanner = function (value) { if (value === 2 && drupalSettings.eu_cookie_compliance.withdraw_enabled) { if (!drupalSettings.eu_cookie_compliance.withdraw_button_on_info_popup) { Drupal.eu_cookie_compliance.createWithdrawBanner(drupalSettings.eu_cookie_compliance.withdraw_markup); } Drupal.eu_cookie_compliance.attachWithdrawEvents(); } }; Drupal.eu_cookie_compliance.setStatus = function (status) { var date = new Date(); var domain = drupalSettings.eu_cookie_compliance.domain ? drupalSettings.eu_cookie_compliance.domain : ''; var path = drupalSettings.eu_cookie_compliance.domain_all_sites ? '/' : drupalSettings.path.baseUrl; var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed' : drupalSettings.eu_cookie_compliance.cookie_name; if (path.length > 1) { var pathEnd = path.length - 1; if (path.lastIndexOf('/') === pathEnd) { path = path.substring(0, pathEnd); } } var cookie_session = parseInt(drupalSettings.eu_cookie_compliance.cookie_session); if (cookie_session) { $.cookie(cookieName, status, { path: path, domain: domain }); } else { var lifetime = parseInt(drupalSettings.eu_cookie_compliance.cookie_lifetime); date.setDate(date.getDate() + lifetime); $.cookie(cookieName, status, { expires: date, path: path, domain: domain }); } $(document).trigger('eu_cookie_compliance.changeStatus', [status]); // Store consent if applicable. if (drupalSettings.eu_cookie_compliance.store_consent && ((status === 1 && drupalSettings.eu_cookie_compliance.popup_agreed_enabled) || (status === 2 && !drupalSettings.eu_cookie_compliance.popup_agreed_enabled))) { var url = drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix + 'eu-cookie-compliance/store_consent/banner'; $.post(url, {}, function (data) { }); } }; Drupal.eu_cookie_compliance.setAcceptedCategories = function (categories) { var date = new Date(); var domain = drupalSettings.eu_cookie_compliance.domain ? drupalSettings.eu_cookie_compliance.domain : ''; var path = drupalSettings.eu_cookie_compliance.domain_all_sites ? '/' : drupalSettings.path.baseUrl; var cookieName = (typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-categories' : drupalSettings.eu_cookie_compliance.cookie_name + '-categories'; if (path.length > 1) { var pathEnd = path.length - 1; if (path.lastIndexOf('/') === pathEnd) { path = path.substring(0, pathEnd); } } var categoriesString = JSON.stringify(categories); var cookie_session = parseInt(drupalSettings.eu_cookie_compliance.cookie_session); if (cookie_session) { $.cookie(cookieName, categoriesString, { path: path, domain: domain }); } else { var lifetime = parseInt(drupalSettings.eu_cookie_compliance.cookie_lifetime); date.setDate(date.getDate() + lifetime); $.cookie(cookieName, categoriesString, { expires: date, path: path, domain: domain }); } $(document).trigger('eu_cookie_compliance.changePreferences', [categories]); // TODO: Store categories with consent if applicable? }; Drupal.eu_cookie_compliance.hasAgreed = function (category) { var status = Drupal.eu_cookie_compliance.getCurrentStatus(); var agreed = (status === 1 || status === 2); if(category !== undefined && agreed) { agreed = Drupal.eu_cookie_compliance.hasAgreedWithCategory(category); } return agreed; }; Drupal.eu_cookie_compliance.hasAgreedWithCategory = function(category) { var allCategories = drupalSettings.eu_cookie_compliance.cookie_categories; var agreedCategories = Drupal.eu_cookie_compliance.getAcceptedCategories(); if (drupalSettings.eu_cookie_compliance.fix_first_cookie_category && category === allCategories[0]) { return true; } return $.inArray(category, agreedCategories) !== -1; }; Drupal.eu_cookie_compliance.showBanner = function () { var showBanner = false; var status = Drupal.eu_cookie_compliance.getCurrentStatus(); if ((status === 0 && drupalSettings.eu_cookie_compliance.method === 'default') || status === null) { if (!drupalSettings.eu_cookie_compliance.disagree_do_not_show_popup || status === null) { showBanner = true; } } else if (status === 1 && drupalSettings.eu_cookie_compliance.popup_agreed_enabled) { showBanner = true; } return showBanner; }; Drupal.eu_cookie_compliance.cookiesEnabled = function () { var cookieEnabled = (navigator.cookieEnabled); if (typeof navigator.cookieEnabled === 'undefined' && !cookieEnabled) { $.cookie('testcookie', 'testcookie', { expires: 100 }); cookieEnabled = ($.cookie('testcookie').indexOf('testcookie') !== -1); } return (cookieEnabled); }; Drupal.eu_cookie_compliance.isWhitelisted = function (cookieName) { // Skip the PHP session cookie. if (cookieName.indexOf('SESS') === 0 || cookieName.indexOf('SSESS') === 0) { return true; } // Split the white-listed cookies. var euCookieComplianceWhitelist = drupalSettings.eu_cookie_compliance.whitelisted_cookies.split(/\r\n|\n|\r/g); // Add the EU Cookie Compliance cookie. euCookieComplianceWhitelist.push((typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed' : drupalSettings.eu_cookie_compliance.cookie_name); euCookieComplianceWhitelist.push((typeof drupalSettings.eu_cookie_compliance.cookie_name === 'undefined' || drupalSettings.eu_cookie_compliance.cookie_name === '') ? 'cookie-agreed-categories' : drupalSettings.eu_cookie_compliance.cookie_name + '-categories'); // Check if the cookie is white-listed. for (var item in euCookieComplianceWhitelist) { if (cookieName === euCookieComplianceWhitelist[item]) { return true; } // Handle cookie names that are prefixed with a category. if (drupalSettings.eu_cookie_compliance.method === 'categories') { var separatorPos = euCookieComplianceWhitelist[item].indexOf(":"); if (separatorPos !== -1) { var category = euCookieComplianceWhitelist[item].substr(0, separatorPos); var wlCookieName = euCookieComplianceWhitelist[item].substr(separatorPos + 1); if (wlCookieName === cookieName && Drupal.eu_cookie_compliance.hasAgreedWithCategory(category)) { return true; } } } } return false; } // Load blocked scripts if the user has agreed to being tracked. var euCookieComplianceHasLoadedScripts = false; var euCookieComplianceHasLoadedScriptsForCategory = []; $(function () { if (Drupal.eu_cookie_compliance.hasAgreed() || (Drupal.eu_cookie_compliance.getCurrentStatus() === null && drupalSettings.eu_cookie_compliance.method !== 'opt_in' && drupalSettings.eu_cookie_compliance.method !== 'categories') ) { if (typeof euCookieComplianceLoadScripts === "function") { euCookieComplianceLoadScripts(); } euCookieComplianceHasLoadedScripts = true; if (drupalSettings.eu_cookie_compliance.method === 'categories') { var acceptedCategories = Drupal.eu_cookie_compliance.getAcceptedCategories(); Drupal.eu_cookie_compliance.loadCategoryScripts(acceptedCategories); } } }); // Block cookies when the user hasn't agreed. if ((drupalSettings.eu_cookie_compliance.method === 'opt_in' && (Drupal.eu_cookie_compliance.getCurrentStatus() === null || !Drupal.eu_cookie_compliance.hasAgreed())) || (drupalSettings.eu_cookie_compliance.method === 'opt_out' && !Drupal.eu_cookie_compliance.hasAgreed() && Drupal.eu_cookie_compliance.getCurrentStatus() !== null) || (drupalSettings.eu_cookie_compliance.method === 'categories') ) { var euCookieComplianceBlockCookies = setInterval(function () { // Load all cookies from jQuery. var cookies = $.cookie(); // Check each cookie and try to remove it if it's not white-listed. for (var i in cookies) { var remove = true; var hostname = window.location.hostname; var cookieRemoved = false; var index = 0; remove = !Drupal.eu_cookie_compliance.isWhitelisted(i); // Remove the cookie if it's not white-listed. if (remove) { while (!cookieRemoved && hostname !== '') { // Attempt to remove. cookieRemoved = $.removeCookie(i, { domain: '.' + hostname, path: '/' }); if (!cookieRemoved) { cookieRemoved = $.removeCookie(i, { domain: hostname, path: '/' }); } index = hostname.indexOf('.'); // We can be on a sub-domain, so keep checking the main domain as well. hostname = (index === -1) ? '' : hostname.substring(index + 1); } // Some jQuery Cookie versions don't remove cookies well. Try again // using plain js. if (!cookieRemoved) { document.cookie = i + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/;'; } } } }, 5000); } })(jQuery, Drupal, drupalSettings); ; /** * DO NOT EDIT THIS FILE. * See the following change record for more information, * https://www.drupal.org/node/2815083 * @preserve **/ Drupal.debounce = function (func, wait, immediate) { var timeout = void 0; var result = void 0; return function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var context = this; var later = function later() { timeout = null; if (!immediate) { result = func.apply(context, args); } }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) { result = func.apply(context, args); } return result; }; };; /** * DO NOT EDIT THIS FILE. * See the following change record for more information, * https://www.drupal.org/node/2815083 * @preserve **/ (function ($, Drupal, debounce) { $.fn.drupalGetSummary = function () { var callback = this.data('summaryCallback'); return this[0] && callback ? $.trim(callback(this[0])) : ''; }; $.fn.drupalSetSummary = function (callback) { var self = this; if (typeof callback !== 'function') { var val = callback; callback = function callback() { return val; }; } return this.data('summaryCallback', callback).off('formUpdated.summary').on('formUpdated.summary', function () { self.trigger('summaryUpdated'); }).trigger('summaryUpdated'); }; Drupal.behaviors.formSingleSubmit = { attach: function attach() { function onFormSubmit(e) { var $form = $(e.currentTarget); var formValues = $form.serialize(); var previousValues = $form.attr('data-drupal-form-submit-last'); if (previousValues === formValues) { e.preventDefault(); } else { $form.attr('data-drupal-form-submit-last', formValues); } } $('body').once('form-single-submit').on('submit.singleSubmit', 'form:not([method~="GET"])', onFormSubmit); } }; function triggerFormUpdated(element) { $(element).trigger('formUpdated'); } function fieldsList(form) { var $fieldList = $(form).find('[name]').map(function (index, element) { return element.getAttribute('id'); }); return $.makeArray($fieldList); } Drupal.behaviors.formUpdated = { attach: function attach(context) { var $context = $(context); var contextIsForm = $context.is('form'); var $forms = (contextIsForm ? $context : $context.find('form')).once('form-updated'); var formFields = void 0; if ($forms.length) { $.makeArray($forms).forEach(function (form) { var events = 'change.formUpdated input.formUpdated '; var eventHandler = debounce(function (event) { triggerFormUpdated(event.target); }, 300); formFields = fieldsList(form).join(','); form.setAttribute('data-drupal-form-fields', formFields); $(form).on(events, eventHandler); }); } if (contextIsForm) { formFields = fieldsList(context).join(','); var currentFields = $(context).attr('data-drupal-form-fields'); if (formFields !== currentFields) { triggerFormUpdated(context); } } }, detach: function detach(context, settings, trigger) { var $context = $(context); var contextIsForm = $context.is('form'); if (trigger === 'unload') { var $forms = (contextIsForm ? $context : $context.find('form')).removeOnce('form-updated'); if ($forms.length) { $.makeArray($forms).forEach(function (form) { form.removeAttribute('data-drupal-form-fields'); $(form).off('.formUpdated'); }); } } } }; Drupal.behaviors.fillUserInfoFromBrowser = { attach: function attach(context, settings) { var userInfo = ['name', 'mail', 'homepage']; var $forms = $('[data-user-info-from-browser]').once('user-info-from-browser'); if ($forms.length) { userInfo.forEach(function (info) { var $element = $forms.find('[name=' + info + ']'); var browserData = localStorage.getItem('Drupal.visitor.' + info); var emptyOrDefault = $element.val() === '' || $element.attr('data-drupal-default-value') === $element.val(); if ($element.length && emptyOrDefault && browserData) { $element.val(browserData); } }); } $forms.on('submit', function () { userInfo.forEach(function (info) { var $element = $forms.find('[name=' + info + ']'); if ($element.length) { localStorage.setItem('Drupal.visitor.' + info, $element.val()); } }); }); } }; var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e) { var url = void 0; if (e.type === 'click') { url = e.currentTarget.location ? e.currentTarget.location : e.currentTarget; } else { url = window.location; } var hash = url.hash.substr(1); if (hash) { var $target = $('#' + hash); $('body').trigger('formFragmentLinkClickOrHashChange', [$target]); setTimeout(function () { return $target.trigger('focus'); }, 300); } }; var debouncedHandleFragmentLinkClickOrHashChange = debounce(handleFragmentLinkClickOrHashChange, 300, true); $(window).on('hashchange.form-fragment', debouncedHandleFragmentLinkClickOrHashChange); $(document).on('click.form-fragment', 'a[href*="#"]', debouncedHandleFragmentLinkClickOrHashChange); })(jQuery, Drupal, Drupal.debounce);; /** * DO NOT EDIT THIS FILE. * See the following change record for more information, * https://www.drupal.org/node/2815083 * @preserve **/ (function ($, Drupal) { var states = { postponed: [] }; Drupal.states = states; function invert(a, invertState) { return invertState && typeof a !== 'undefined' ? !a : a; } function _compare2(a, b) { if (a === b) { return typeof a === 'undefined' ? a : true; } return typeof a === 'undefined' || typeof b === 'undefined'; } function ternary(a, b) { if (typeof a === 'undefined') { return b; } if (typeof b === 'undefined') { return a; } return a && b; } Drupal.behaviors.states = { attach: function attach(context, settings) { var $states = $(context).find('[data-drupal-states]'); var il = $states.length; var _loop = function _loop(i) { var config = JSON.parse($states[i].getAttribute('data-drupal-states')); Object.keys(config || {}).forEach(function (state) { new states.Dependent({ element: $($states[i]), state: states.State.sanitize(state), constraints: config[state] }); }); }; for (var i = 0; i < il; i++) { _loop(i); } while (states.postponed.length) { states.postponed.shift()(); } } }; states.Dependent = function (args) { var _this = this; $.extend(this, { values: {}, oldValue: null }, args); this.dependees = this.getDependees(); Object.keys(this.dependees || {}).forEach(function (selector) { _this.initializeDependee(selector, _this.dependees[selector]); }); }; states.Dependent.comparisons = { RegExp: function RegExp(reference, value) { return reference.test(value); }, Function: function Function(reference, value) { return reference(value); }, Number: function Number(reference, value) { return typeof value === 'string' ? _compare2(reference.toString(), value) : _compare2(reference, value); } }; states.Dependent.prototype = { initializeDependee: function initializeDependee(selector, dependeeStates) { var _this2 = this; this.values[selector] = {}; Object.keys(dependeeStates).forEach(function (i) { var state = dependeeStates[i]; if ($.inArray(state, dependeeStates) === -1) { return; } state = states.State.sanitize(state); _this2.values[selector][state.name] = null; $(selector).on('state:' + state, { selector: selector, state: state }, function (e) { _this2.update(e.data.selector, e.data.state, e.value); }); new states.Trigger({ selector: selector, state: state }); }); }, compare: function compare(reference, selector, state) { var value = this.values[selector][state.name]; if (reference.constructor.name in states.Dependent.comparisons) { return states.Dependent.comparisons[reference.constructor.name](reference, value); } return _compare2(reference, value); }, update: function update(selector, state, value) { if (value !== this.values[selector][state.name]) { this.values[selector][state.name] = value; this.reevaluate(); } }, reevaluate: function reevaluate() { var value = this.verifyConstraints(this.constraints); if (value !== this.oldValue) { this.oldValue = value; value = invert(value, this.state.invert); this.element.trigger({ type: 'state:' + this.state, value: value, trigger: true }); } }, verifyConstraints: function verifyConstraints(constraints, selector) { var result = void 0; if ($.isArray(constraints)) { var hasXor = $.inArray('xor', constraints) === -1; var len = constraints.length; for (var i = 0; i < len; i++) { if (constraints[i] !== 'xor') { var constraint = this.checkConstraints(constraints[i], selector, i); if (constraint && (hasXor || result)) { return hasXor; } result = result || constraint; } } } else if ($.isPlainObject(constraints)) { for (var n in constraints) { if (constraints.hasOwnProperty(n)) { result = ternary(result, this.checkConstraints(constraints[n], selector, n)); if (result === false) { return false; } } } } return result; }, checkConstraints: function checkConstraints(value, selector, state) { if (typeof state !== 'string' || /[0-9]/.test(state[0])) { state = null; } else if (typeof selector === 'undefined') { selector = state; state = null; } if (state !== null) { state = states.State.sanitize(state); return invert(this.compare(value, selector, state), state.invert); } return this.verifyConstraints(value, selector); }, getDependees: function getDependees() { var cache = {}; var _compare = this.compare; this.compare = function (reference, selector, state) { (cache[selector] || (cache[selector] = [])).push(state.name); }; this.verifyConstraints(this.constraints); this.compare = _compare; return cache; } }; states.Trigger = function (args) { $.extend(this, args); if (this.state in states.Trigger.states) { this.element = $(this.selector); if (!this.element.data('trigger:' + this.state)) { this.initialize(); } } }; states.Trigger.prototype = { initialize: function initialize() { var _this3 = this; var trigger = states.Trigger.states[this.state]; if (typeof trigger === 'function') { trigger.call(window, this.element); } else { Object.keys(trigger || {}).forEach(function (event) { _this3.defaultTrigger(event, trigger[event]); }); } this.element.data('trigger:' + this.state, true); }, defaultTrigger: function defaultTrigger(event, valueFn) { var oldValue = valueFn.call(this.element); this.element.on(event, $.proxy(function (e) { var value = valueFn.call(this.element, e); if (oldValue !== value) { this.element.trigger({ type: 'state:' + this.state, value: value, oldValue: oldValue }); oldValue = value; } }, this)); states.postponed.push($.proxy(function () { this.element.trigger({ type: 'state:' + this.state, value: oldValue, oldValue: null }); }, this)); } }; states.Trigger.states = { empty: { keyup: function keyup() { return this.val() === ''; } }, checked: { change: function change() { var checked = false; this.each(function () { checked = $(this).prop('checked'); return !checked; }); return checked; } }, value: { keyup: function keyup() { if (this.length > 1) { return this.filter(':checked').val() || false; } return this.val(); }, change: function change() { if (this.length > 1) { return this.filter(':checked').val() || false; } return this.val(); } }, collapsed: { collapsed: function collapsed(e) { return typeof e !== 'undefined' && 'value' in e ? e.value : !this.is('[open]'); } } }; states.State = function (state) { this.pristine = state; this.name = state; var process = true; do { while (this.name.charAt(0) === '!') { this.name = this.name.substring(1); this.invert = !this.invert; } if (this.name in states.State.aliases) { this.name = states.State.aliases[this.name]; } else { process = false; } } while (process); }; states.State.sanitize = function (state) { if (state instanceof states.State) { return state; } return new states.State(state); }; states.State.aliases = { enabled: '!disabled', invisible: '!visible', invalid: '!valid', untouched: '!touched', optional: '!required', filled: '!empty', unchecked: '!checked', irrelevant: '!relevant', expanded: '!collapsed', open: '!collapsed', closed: 'collapsed', readwrite: '!readonly' }; states.State.prototype = { invert: false, toString: function toString() { return this.name; } }; var $document = $(document); $document.on('state:disabled', function (e) { if (e.trigger) { $(e.target).prop('disabled', e.value).closest('.js-form-item, .js-form-submit, .js-form-wrapper').toggleClass('form-disabled', e.value).find('select, input, textarea').prop('disabled', e.value); } }); $document.on('state:required', function (e) { if (e.trigger) { if (e.value) { var label = 'label' + (e.target.id ? '[for=' + e.target.id + ']' : ''); var $label = $(e.target).attr({ required: 'required', 'aria-required': 'true' }).closest('.js-form-item, .js-form-wrapper').find(label); if (!$label.hasClass('js-form-required').length) { $label.addClass('js-form-required form-required'); } } else { $(e.target).removeAttr('required aria-required').closest('.js-form-item, .js-form-wrapper').find('label.js-form-required').removeClass('js-form-required form-required'); } } }); $document.on('state:visible', function (e) { if (e.trigger) { $(e.target).closest('.js-form-item, .js-form-submit, .js-form-wrapper').toggle(e.value); } }); $document.on('state:checked', function (e) { if (e.trigger) { $(e.target).prop('checked', e.value); } }); $document.on('state:collapsed', function (e) { if (e.trigger) { if ($(e.target).is('[open]') === e.value) { $(e.target).find('> summary').trigger('click'); } } }); })(jQuery, Drupal);; /** * @file * JavaScript behaviors for custom webform #states. */ (function ($, Drupal) { 'use strict'; Drupal.webform = Drupal.webform || {}; Drupal.webform.states = Drupal.webform.states || {}; Drupal.webform.states.slideDown = Drupal.webform.states.slideDown || {}; Drupal.webform.states.slideDown.duration = 'slow'; Drupal.webform.states.slideUp = Drupal.webform.states.slideUp || {}; Drupal.webform.states.slideUp.duration = 'fast'; /* ************************************************************************ */ // jQuery functions. /* ************************************************************************ */ /** * Check if an element has a specified data attribute. * * @param {string} data * The data attribute name. * * @return {boolean} * TRUE if an element has a specified data attribute. */ $.fn.hasData = function (data) { return (typeof this.data(data) !== 'undefined'); }; /** * Check if element is within the webform or not. * * @return {boolean} * TRUE if element is within the webform. */ $.fn.isWebform = function () { return $(this).closest('form[id^="webform"], form[data-is-webform]').length ? true : false; }; /** * Check if element is to be treated as a webform element. * * @return {boolean} * TRUE if element is to be treated as a webform element. */ $.fn.isWebformElement = function () { return ($(this).isWebform() || $(this).closest('[data-is-webform-element]').length) ? true : false; }; /* ************************************************************************ */ // Trigger. /* ************************************************************************ */ // The change event is triggered by cut-n-paste and select menus. // Issue #2445271: #states element empty check not triggered on mouse // based paste. // @see https://www.drupal.org/node/2445271 Drupal.states.Trigger.states.empty.change = function change() { return this.val() === ''; }; /* ************************************************************************ */ // Dependents. /* ************************************************************************ */ // Apply solution included in #1962800 patch. // Issue #1962800: Form #states not working with literal integers as // values in IE11. // @see https://www.drupal.org/project/drupal/issues/1962800 // @see https://www.drupal.org/files/issues/core-states-not-working-with-integers-ie11_1962800_46.patch // // This issue causes pattern, less than, and greater than support to break. // @see https://www.drupal.org/project/webform/issues/2981724 var states = Drupal.states; Drupal.states.Dependent.prototype.compare = function compare(reference, selector, state) { var value = this.values[selector][state.name]; var name = reference.constructor.name; if (!name) { name = $.type(reference); name = name.charAt(0).toUpperCase() + name.slice(1); } if (name in states.Dependent.comparisons) { return states.Dependent.comparisons[name](reference, value); } if (reference.constructor.name in states.Dependent.comparisons) { return states.Dependent.comparisons[reference.constructor.name](reference, value); } return _compare2(reference, value); }; function _compare2(a, b) { if (a === b) { return typeof a === 'undefined' ? a : true; } return typeof a === 'undefined' || typeof b === 'undefined'; } // Adds pattern, less than, and greater than support to #state API. // @see http://drupalsun.com/julia-evans/2012/03/09/extending-form-api-states-regular-expressions Drupal.states.Dependent.comparisons.Object = function (reference, value) { if ('pattern' in reference) { return (new RegExp(reference['pattern'])).test(value); } else if ('!pattern' in reference) { return !((new RegExp(reference['!pattern'])).test(value)); } else if ('less' in reference) { return (value !== '' && parseFloat(reference['less']) > parseFloat(value)); } else if ('less_equal' in reference) { return (value !== '' && parseFloat(reference['less_equal']) >= parseFloat(value)); } else if ('greater' in reference) { return (value !== '' && parseFloat(reference['greater']) < parseFloat(value)); } else if ('greater_equal' in reference) { return (value !== '' && parseFloat(reference['greater_equal']) <= parseFloat(value)); } else if ('between' in reference || '!between' in reference) { if (value === '') { return false; } var between = reference['between'] || reference['!between']; var betweenParts = between.split(':'); var greater = betweenParts[0]; var less = (typeof betweenParts[1] !== 'undefined') ? betweenParts[1] : null; var isGreaterThan = (greater === null || greater === '' || parseFloat(value) >= parseFloat(greater)); var isLessThan = (less === null || less === '' || parseFloat(value) <= parseFloat(less)); var result = (isGreaterThan && isLessThan); return (reference['!between']) ? !result : result; } else { return reference.indexOf(value) !== false; } }; /* ************************************************************************ */ // States events. /* ************************************************************************ */ var $document = $(document); $document.on('state:required', function (e) { if (e.trigger && $(e.target).isWebformElement()) { var $target = $(e.target); // Fix #required file upload. // @see Issue #2860529: Conditional required File upload field don't work. toggleRequired($target.find('input[type="file"]'), e.value); // Fix #required for radios. // @see Issue #2856795: If radio buttons are required but not filled form is nevertheless submitted. if ($target.is('.js-form-type-radios, .js-form-type-webform-radios-other, .js-webform-type-radios, .js-webform-type-webform-radios-other')) { toggleRequired($target.find('input[type="radio"]'), e.value); } // Fix #required for checkboxes. // @see Issue #2938414: Checkboxes don't support #states required. // @see checkboxRequiredhandler if ($target.is('.js-form-type-checkboxes, .js-form-type-webform-checkboxes-other, .js-webform-type-checkboxes, .js-webform-type-webform-checkboxes-other')) { var $checkboxes = $target.find('input[type="checkbox"]'); if (e.value) { // Add event handler. $checkboxes.on('click', statesCheckboxesRequiredEventHandler); // Initialize and add required attribute. checkboxesRequired($target); } else { // Remove event handler. $checkboxes.off('click', statesCheckboxesRequiredEventHandler); // Remove required attribute. toggleRequired($checkboxes, false); } } // Fix required label for elements without the for attribute. // @see Issue #3145300: Conditional Visible Select Other not working. if ($target.is('.js-form-type-webform-select-other, .js-webform-type-webform-select-other')) { var $select = $target.find('select'); toggleRequired($select, e.value); copyRequireMessage($target, $select); } if ($target.find('> label:not([for])').length) { $target.find('> label').toggleClass('js-form-required form-required', e.value); } // Fix required label for checkboxes and radios. // @see Issue #2938414: Checkboxes don't support #states required // @see Issue #2731991: Setting required on radios marks all options required. // @see Issue #2856315: Conditional Logic - Requiring Radios in a Fieldset. // Fix #required for fieldsets. // @see Issue #2977569: Hidden fieldsets that become visible with conditional logic cannot be made required. if ($target.is('.js-webform-type-radios, .js-webform-type-checkboxes, fieldset')) { $target.find('legend span.fieldset-legend:not(.visually-hidden)').toggleClass('js-form-required form-required', e.value); } // Issue #2986017: Fieldsets shouldn't have required attribute. if ($target.is('fieldset')) { $target.removeAttr('required aria-required'); } } }); $document.on('state:checked', function (e) { if (e.trigger) { $(e.target).change(); } }); $document.on('state:readonly', function (e) { if (e.trigger && $(e.target).isWebformElement()) { $(e.target).prop('readonly', e.value).closest('.js-form-item, .js-form-wrapper').toggleClass('webform-readonly', e.value).find('input, textarea').prop('readonly', e.value); // Trigger webform:readonly. $(e.target).trigger('webform:readonly') .find('select, input, textarea, button').trigger('webform:readonly'); } }); $document.on('state:visible state:visible-slide', function (e) { if (e.trigger && $(e.target).isWebformElement()) { if (e.value) { $(':input', e.target).addBack().each(function () { restoreValueAndRequired(this); triggerEventHandlers(this); }); } else { // @see https://www.sitepoint.com/jquery-function-clear-form-data/ $(':input', e.target).addBack().each(function () { backupValueAndRequired(this); clearValueAndRequired(this); triggerEventHandlers(this); }); } } }); $document.on('state:visible-slide', function (e) { if (e.trigger && $(e.target).isWebformElement()) { var effect = e.value ? 'slideDown' : 'slideUp'; var duration = Drupal.webform.states[effect].duration; $(e.target).closest('.js-form-item, .js-form-submit, .js-form-wrapper')[effect](duration); } }); Drupal.states.State.aliases['invisible-slide'] = '!visible-slide'; $document.on('state:disabled', function (e) { if (e.trigger && $(e.target).isWebformElement()) { // Make sure disabled property is set before triggering webform:disabled. // Copied from: core/misc/states.js $(e.target) .prop('disabled', e.value) .closest('.js-form-item, .js-form-submit, .js-form-wrapper').toggleClass('form-disabled', e.value) .find('select, input, textarea, button').prop('disabled', e.value); // Never disable hidden file[fids] because the existing values will // be completely lost when the webform is submitted. var fileElements = $(e.target) .find(':input[type="hidden"][name$="[fids]"]'); if (fileElements.length) { // Remove 'disabled' attribute from fieldset which will block // all disabled elements from being submitted. if ($(e.target).is('fieldset')) { $(e.target).prop('disabled', false); } fileElements.removeAttr('disabled'); } // Trigger webform:disabled. $(e.target).trigger('webform:disabled') .find('select, input, textarea, button').trigger('webform:disabled'); } }); /* ************************************************************************ */ // Behaviors. /* ************************************************************************ */ /** * Adds HTML5 validation to required checkboxes. * * @type {Drupal~behavior} * * @see https://www.drupal.org/project/webform/issues/3068998 */ Drupal.behaviors.webformCheckboxesRequired = { attach: function (context) { $('.js-form-type-checkboxes.required, .js-form-type-webform-checkboxes-other.required, .js-webform-type-checkboxes.required, .js-webform-type-webform-checkboxes-other.required, .js-webform-type-webform-radios-other.checkboxes', context) .once('webform-checkboxes-required') .each(function () { var $element = $(this); $element.find('input[type="checkbox"]').on('click', statesCheckboxesRequiredEventHandler); checkboxesRequired($element); }); } }; /** * Adds HTML5 validation to required radios. * * @type {Drupal~behavior} * * @see https://www.drupal.org/project/webform/issues/2856795 */ Drupal.behaviors.webformRadiosRequired = { attach: function (context) { $('.js-form-type-radios, .js-form-type-webform-radios-other, .js-webform-type-radios, .js-webform-type-webform-radios-other', context) .once('webform-radios-required') .each(function () { radiosRequired($(this)); }); } }; /** * Add HTML5 multiple checkboxes required validation. * * @param {jQuery} $element * An jQuery object containing HTML5 radios. * * @see https://stackoverflow.com/a/37825072/145846 */ function checkboxesRequired($element) { var $firstCheckbox = $element.find('input[type="checkbox"]').first(); var isChecked = $element.find('input[type="checkbox"]').is(':checked'); toggleRequired($firstCheckbox, !isChecked); copyRequireMessage($element, $firstCheckbox); } /** * Add HTML5 radios required validation. * * @param {jQuery} $element * An jQuery object containing HTML5 radios. * * @see https://www.drupal.org/project/webform/issues/2856795 */ function radiosRequired($element) { var $radios = $element.find('input[type="radio"]'); var isRequired = $element.hasClass('required'); toggleRequired($radios, isRequired); copyRequireMessage($element, $radios); } /* ************************************************************************ */ // Event handlers. /* ************************************************************************ */ /** * Trigger #states API HTML5 multiple checkboxes required validation. * * @see https://stackoverflow.com/a/37825072/145846 */ function statesCheckboxesRequiredEventHandler() { var $element = $(this).closest('.js-webform-type-checkboxes, .js-form-type-webform-checkboxes-other'); checkboxesRequired($element); } /** * Trigger an input's event handlers. * * @param {element} input * An input. */ function triggerEventHandlers(input) { var $input = $(input); var type = input.type; var tag = input.tagName.toLowerCase(); // Add 'webform.states' as extra parameter to event handlers. // @see Drupal.behaviors.webformUnsaved var extraParameters = ['webform.states']; if (type === 'checkbox' || type === 'radio') { $input .trigger('change', extraParameters) .trigger('blur', extraParameters); } else if (tag === 'select') { $input .trigger('change', extraParameters) .trigger('blur', extraParameters); } else if (type !== 'submit' && type !== 'button' && type !== 'file') { $input .trigger('input', extraParameters) .trigger('change', extraParameters) .trigger('keydown', extraParameters) .trigger('keyup', extraParameters) .trigger('blur', extraParameters); // Make sure input mask is reset when value is restored. // @see https://www.drupal.org/project/webform/issues/3124155 if ($input.attr('data-inputmask-mask')) { setTimeout(function () {$input.inputmask('remove').inputmask();}); } } } /* ************************************************************************ */ // Backup and restore value functions. /* ************************************************************************ */ /** * Backup an input's current value and required attribute * * @param {element} input * An input. */ function backupValueAndRequired(input) { var $input = $(input); var type = input.type; var tag = input.tagName.toLowerCase(); // Normalize case. // Backup required. if ($input.prop('required') && !$input.hasData('webform-required')) { $input.data('webform-required', true); } // Backup value. if (!$input.hasData('webform-value')) { if (type === 'checkbox' || type === 'radio') { $input.data('webform-value', $input.prop('checked')); } else if (tag === 'select') { var values = []; $input.find('option:selected').each(function (i, option) { values[i] = option.value; }); $input.data('webform-value', values); } else if (type !== 'submit' && type !== 'button') { $input.data('webform-value', input.value); } } } /** * Restore an input's value and required attribute. * * @param {element} input * An input. */ function restoreValueAndRequired(input) { var $input = $(input); // Restore value. var value = $input.data('webform-value'); if (typeof value !== 'undefined') { var type = input.type; var tag = input.tagName.toLowerCase(); // Normalize case. if (type === 'checkbox' || type === 'radio') { $input.prop('checked', value); } else if (tag === 'select') { $.each(value, function (i, option_value) { $input.find("option[value='" + option_value + "']").prop('selected', true); }); } else if (type !== 'submit' && type !== 'button') { input.value = value; } $input.removeData('webform-value'); } // Restore required. var required = $input.data('webform-required'); if (typeof required !== 'undefined') { if (required) { $input.prop('required', true); } $input.removeData('webform-required'); } } /** * Clear an input's value and required attributes. * * @param {element} input * An input. */ function clearValueAndRequired(input) { var $input = $(input); // Check for #states no clear attribute. // @see https://css-tricks.com/snippets/jquery/make-an-jquery-hasattr/ if ($input.closest('[data-webform-states-no-clear]').length) { return; } // Clear value. var type = input.type; var tag = input.tagName.toLowerCase(); // Normalize case. if (type === 'checkbox' || type === 'radio') { $input.prop('checked', false); } else if (tag === 'select') { if ($input.find('option[value=""]').length) { $input.val(''); } else { input.selectedIndex = -1; } } else if (type !== 'submit' && type !== 'button') { input.value = (type === 'color') ? '#000000' : ''; } // Clear required. $input.prop('required', false); } /* ************************************************************************ */ // Helper functions. /* ************************************************************************ */ /** * Toggle an input's required attributes. * * @param {element} $input * An input. * @param {boolean} required */ function toggleRequired($input, required) { if (required) { $input.attr({'required': 'required', 'aria-required': 'true'}); } else { $input.removeAttr('required aria-required'); } } /** * Copy the clientside_validation.module's message. * * @param {jQuery} $source * The source element. * @param {jQuery} $destination * The destination element. */ function copyRequireMessage($source, $destination) { if ($source.attr('data-msg-required')) { $destination.attr('data-msg-required', $source.attr('data-msg-required')); } } })(jQuery, Drupal); ; /** * @file * JavaScript behaviors for webforms. */ (function ($, Drupal) { 'use strict'; /** * Remove single submit event listener. * * @type {Drupal~behavior} * * @prop {Drupal~behaviorAttach} attach * Attaches the behavior for removing single submit event listener. * * @see Drupal.behaviors.formSingleSubmit */ Drupal.behaviors.webformRemoveFormSingleSubmit = { attach: function attach() { function onFormSubmit(e) { var $form = $(e.currentTarget); $form.removeAttr('data-drupal-form-submit-last'); } $('body') .once('webform-single-submit') .on('submit.singleSubmit', 'form.webform-remove-single-submit', onFormSubmit); } }; /** * Prevent webform autosubmit on wizard pages. * * @type {Drupal~behavior} * * @prop {Drupal~behaviorAttach} attach * Attaches the behavior for disabling webform autosubmit. * Wizard pages need to be progressed with the Previous or Next buttons, * not by pressing Enter. */ Drupal.behaviors.webformDisableAutoSubmit = { attach: function (context) { // Not using context so that inputs loaded via Ajax will have autosubmit // disabled. // @see http://stackoverflow.com/questions/11235622/jquery-disable-form-submit-on-enter $('.js-webform-disable-autosubmit input') .not(':button, :submit, :reset, :image, :file') .once('webform-disable-autosubmit') .on('keyup keypress', function (e) { if (e.which === 13) { e.preventDefault(); return false; } }); } }; /** * Skip client-side validation when submit button is pressed. * * @type {Drupal~behavior} * * @prop {Drupal~behaviorAttach} attach * Attaches the behavior for the skipping client-side validation. * * @deprecated in Webform 8.x-5.x and will be removed in Webform 8.x-6.x. * Use 'formnovalidate' attribute instead. */ Drupal.behaviors.webformSubmitNoValidate = { attach: function (context) { $(context).find(':submit.js-webform-novalidate') .once('webform-novalidate') .attr('formnovalidate', 'formnovalidate'); } }; /** * Custom required and pattern validation error messages. * * @type {Drupal~behavior} * * @prop {Drupal~behaviorAttach} attach * Attaches the behavior for the webform custom required and pattern * validation error messages. * * @see http://stackoverflow.com/questions/5272433/html5-form-required-attribute-set-custom-validation-message **/ Drupal.behaviors.webformRequiredError = { attach: function (context) { $(context).find(':input[data-webform-required-error], :input[data-webform-pattern-error]').once('webform-required-error') .on('invalid', function () { this.setCustomValidity(''); if (this.valid) { return; } if (this.validity.patternMismatch && $(this).attr('data-webform-pattern-error')) { this.setCustomValidity($(this).attr('data-webform-pattern-error')); } else if (this.validity.valueMissing && $(this).attr('data-webform-required-error')) { this.setCustomValidity($(this).attr('data-webform-required-error')); } }) .on('input change', function () { // Find all related elements by name and reset custom validity. // This specifically applies to required radios and checkboxes. var name = $(this).attr('name'); $(this.form).find(':input[name="' + name + '"]').each(function () { this.setCustomValidity(''); }); }); } }; // When #state:required is triggered we need to reset the target elements // custom validity. $(document).on('state:required', function (e) { $(e.target).filter('[data-webform-required-error]') .each(function () {this.setCustomValidity('');}); }); })(jQuery, Drupal); ; /** * @file * JavaScript behaviors for details element. */ (function ($, Drupal) { 'use strict'; // Determine if local storage exists and is enabled. // This approach is copied from Modernizr. // @see https://github.com/Modernizr/Modernizr/blob/c56fb8b09515f629806ca44742932902ac145302/modernizr.js#L696-731 var hasLocalStorage = (function () { try { localStorage.setItem('webform', 'webform'); localStorage.removeItem('webform'); return true; } catch (e) { return false; } }()); /** * Attach handler to save details open/close state. * * @type {Drupal~behavior} */ Drupal.behaviors.webformDetailsSave = { attach: function (context) { if (!hasLocalStorage) { return; } // Summary click event handler. $('details > summary', context).once('webform-details-summary-save').click(function () { var $details = $(this).parent(); // @see https://css-tricks.com/snippets/jquery/make-an-jquery-hasattr/ if ($details[0].hasAttribute('data-webform-details-nosave')) { return; } var name = Drupal.webformDetailsSaveGetName($details); if (!name) { return; } var open = ($details.attr('open') !== 'open') ? '1' : '0'; localStorage.setItem(name, open); }); // Initialize details open state via local storage. $('details', context).once('webform-details-save').each(function () { var $details = $(this); var name = Drupal.webformDetailsSaveGetName($details); if (!name) { return; } var open = localStorage.getItem(name); if (open === null) { return; } if (open === '1') { $details.attr('open', 'open'); } else { $details.removeAttr('open'); } }); } }; /** * Get the name used to store the state of details element. * * @param {jQuery} $details * A details element. * * @return {string} * The name used to store the state of details element. */ Drupal.webformDetailsSaveGetName = function ($details) { if (!hasLocalStorage) { return ''; } // Any details element not included a webform must have define its own id. var webformId = $details.attr('data-webform-element-id'); if (webformId) { return 'Drupal.webform.' + webformId.replace('--', '.'); } var detailsId = $details.attr('id'); if (!detailsId) { return ''; } var $form = $details.parents('form'); if (!$form.length || !$form.attr('id')) { return ''; } var formId = $form.attr('id'); if (!formId) { return ''; } // ISSUE: When Drupal renders a webform in a modal dialog it appends a unique // identifier to webform ids and details ids. (i.e. my-form--FeSFISegTUI) // WORKAROUND: Remove the unique id that delimited using double dashes. formId = formId.replace(/--.+?$/, '').replace(/-/g, '_'); detailsId = detailsId.replace(/--.+?$/, '').replace(/-/g, '_'); return 'Drupal.webform.' + formId + '.' + detailsId; }; })(jQuery, Drupal); ; /** * DO NOT EDIT THIS FILE. * See the following change record for more information, * https://www.drupal.org/node/2815083 * @preserve **/ (function (Drupal, debounce) { var liveElement = void 0; var announcements = []; Drupal.behaviors.drupalAnnounce = { attach: function attach(context) { if (!liveElement) { liveElement = document.createElement('div'); liveElement.id = 'drupal-live-announce'; liveElement.className = 'visually-hidden'; liveElement.setAttribute('aria-live', 'polite'); liveElement.setAttribute('aria-busy', 'false'); document.body.appendChild(liveElement); } } }; function announce() { var text = []; var priority = 'polite'; var announcement = void 0; var il = announcements.length; for (var i = 0; i < il; i++) { announcement = announcements.pop(); text.unshift(announcement.text); if (announcement.priority === 'assertive') { priority = 'assertive'; } } if (text.length) { liveElement.innerHTML = ''; liveElement.setAttribute('aria-busy', 'true'); liveElement.setAttribute('aria-live', priority); liveElement.innerHTML = text.join('\n'); liveElement.setAttribute('aria-busy', 'false'); } } Drupal.announce = function (text, priority) { announcements.push({ text: text, priority: priority }); return debounce(announce, 200)(); }; })(Drupal, Drupal.debounce);; /** * @file * JavaScript behaviors for details element. */ (function ($, Drupal) { 'use strict'; Drupal.webform = Drupal.webform || {}; Drupal.webform.detailsToggle = Drupal.webform.detailsToggle || {}; Drupal.webform.detailsToggle.options = Drupal.webform.detailsToggle.options || {}; /** * Attach handler to toggle details open/close state. * * @type {Drupal~behavior} */ Drupal.behaviors.webformDetailsToggle = { attach: function (context) { $('.js-webform-details-toggle', context).once('webform-details-toggle').each(function () { var $form = $(this); var $tabs = $form.find('.webform-tabs'); // Get only the main details elements and ignore all nested details. var selector = ($tabs.length) ? '.webform-tab' : '.js-webform-details-toggle, .webform-elements'; var $details = $form.find('details').filter(function () { var $parents = $(this).parentsUntil(selector); return ($parents.find('details').length === 0); }); // Toggle is only useful when there are two or more details elements. if ($details.length < 2) { return; } var options = $.extend({ button: '' }, Drupal.webform.detailsToggle.options); // Create toggle buttons. var $toggle = $(options.button) .attr('title', Drupal.t('Toggle details widget state.')) .on('click', function (e) { var open; if (Drupal.webform.detailsToggle.isFormDetailsOpen($form)) { $form.find('details').removeAttr('open'); open = 0; } else { $form.find('details').attr('open', 'open'); open = 1; } Drupal.webform.detailsToggle.setDetailsToggleLabel($form); // Set the saved states for all the details elements. // @see webform.element.details.save.js if (Drupal.webformDetailsSaveGetName) { $form.find('details').each(function () { // Note: Drupal.webformDetailsSaveGetName checks if localStorage // exists and is enabled. // @see webform.element.details.save.js var name = Drupal.webformDetailsSaveGetName($(this)); if (name) { localStorage.setItem(name, open); } }); } }) .wrap('
') .parent(); if ($tabs.length) { // Add toggle state before the tabs. $tabs.find('.item-list:first-child').eq(0).before($toggle); } else { // Add toggle state link to first details element. $details.eq(0).before($toggle); } Drupal.webform.detailsToggle.setDetailsToggleLabel($form); }); } }; /** * Determine if a webform's details are all opened. * * @param {jQuery} $form * A webform. * * @return {boolean} * TRUE if a webform's details are all opened. */ Drupal.webform.detailsToggle.isFormDetailsOpen = function ($form) { return ($form.find('details[open]').length === $form.find('details').length); }; /** * Set a webform's details toggle state widget label. * * @param {jQuery} $form * A webform. */ Drupal.webform.detailsToggle.setDetailsToggleLabel = function ($form) { var isOpen = Drupal.webform.detailsToggle.isFormDetailsOpen($form); var label = (isOpen) ? Drupal.t('Collapse all') : Drupal.t('Expand all'); $form.find('.webform-details-toggle-state').html(label); var text = (isOpen) ? Drupal.t('All details have been expanded.') : Drupal.t('All details have been collapsed.'); Drupal.announce(text); }; })(jQuery, Drupal); ; /** * @file * JavaScript behaviors for message element integration. */ (function ($, Drupal) { 'use strict'; // Determine if local storage exists and is enabled. // This approach is copied from Modernizr. // @see https://github.com/Modernizr/Modernizr/blob/c56fb8b09515f629806ca44742932902ac145302/modernizr.js#L696-731 var hasLocalStorage = (function () { try { localStorage.setItem('webform', 'webform'); localStorage.removeItem('webform'); return true; } catch (e) { return false; } }()); // Determine if session storage exists and is enabled. // This approach is copied from Modernizr. // @see https://github.com/Modernizr/Modernizr/blob/c56fb8b09515f629806ca44742932902ac145302/modernizr.js#L696-731 var hasSessionStorage = (function () { try { sessionStorage.setItem('webform', 'webform'); sessionStorage.removeItem('webform'); return true; } catch (e) { return false; } }()); /** * Behavior for handler message close. * * @type {Drupal~behavior} */ Drupal.behaviors.webformMessageClose = { attach: function (context) { $(context).find('.js-webform-message--close').once('webform-message--close').each(function () { var $element = $(this); var id = $element.attr('data-message-id'); var storage = $element.attr('data-message-storage'); var effect = $element.attr('data-message-close-effect') || 'hide'; switch (effect) { case 'slide': effect = 'slideUp'; break; case 'fade': effect = 'fadeOut'; break; } // Check storage status. if (isClosed($element, storage, id)) { return; } // Only show element if it's style is not set to 'display: none'. if ($element.attr('style') !== 'display: none;') { $element.show(); } $element.find('.js-webform-message__link').on('click', function (event) { $element[effect](); setClosed($element, storage, id); $element.trigger('close'); event.preventDefault(); }); }); } }; function isClosed($element, storage, id) { if (!id || !storage) { return false; } switch (storage) { case 'local': if (hasLocalStorage) { return localStorage.getItem('Drupal.webform.message.' + id) || false; } return false; case 'session': if (hasSessionStorage) { return sessionStorage.getItem('Drupal.webform.message.' + id) || false; } return false; default: return false; } } function setClosed($element, storage, id) { if (!id || !storage) { return; } switch (storage) { case 'local': if (hasLocalStorage) { localStorage.setItem('Drupal.webform.message.' + id, true); } break; case 'session': if (hasSessionStorage) { sessionStorage.setItem('Drupal.webform.message.' + id, true); } break; case 'user': case 'state': case 'custom': $.get($element.find('.js-webform-message__link').attr('href')); return true; } } })(jQuery, Drupal); ;