gutenberg
4 years ago
debug-page.js
4 years ago
jquery.tipTip.js
4 years ago
multiple-page.js
3 years ago
network-settings-page.js
3 years ago
prior-consent-settings.js
3 years ago
settings-page.js
3 years ago
support-page.js
3 years ago
multiple-page.js
99 lines
| 1 | /** |
| 2 | * Load init function when the page is ready |
| 3 | * |
| 4 | * @since 1.8.0 |
| 5 | */ |
| 6 | jQuery( document ).ready( init ); |
| 7 | |
| 8 | function init() { |
| 9 | showMultipleConfig(); |
| 10 | selectRegion(); |
| 11 | toggleRegionSelector(); |
| 12 | } |
| 13 | |
| 14 | function showMultipleConfig() { |
| 15 | jQuery('#multiple-config').on('change', function(){ |
| 16 | if(jQuery(this).is(':checked')){ |
| 17 | jQuery('.cb-multiple__container').removeClass('hidden'); |
| 18 | }else{ |
| 19 | jQuery('.cb-multiple__container').addClass('hidden'); |
| 20 | } |
| 21 | }); |
| 22 | } |
| 23 | |
| 24 | function toggleRegionSelector() { |
| 25 | const initialValues = jQuery('form').serialize(); |
| 26 | let submitBtn = jQuery('p.submit #submit'); |
| 27 | const region_list = jQuery('.cb-region__region__list'); |
| 28 | jQuery('.cb-region__region__selector').on('click', function(){ |
| 29 | region_list.removeClass('hidden'); |
| 30 | }); |
| 31 | |
| 32 | jQuery('.cb-region__veil').on('click', function(){ |
| 33 | region_list.addClass('hidden'); |
| 34 | let newValues = jQuery('form').serialize(); |
| 35 | if(newValues !== initialValues) { |
| 36 | submitBtn.addClass('enabled'); |
| 37 | }else{ |
| 38 | submitBtn.removeClass('enabled'); |
| 39 | } |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | function selectRegion() { |
| 44 | jQuery('.cb-region__region__item').on('click', function(){ |
| 45 | let code = jQuery(this).data('region'); |
| 46 | let name = jQuery(this).text(); |
| 47 | if(jQuery(this).hasClass('selected-region')){ |
| 48 | jQuery(this).removeClass('selected-region'); |
| 49 | toggleCode(code,name); |
| 50 | }else{ |
| 51 | jQuery(this).addClass('selected-region'); |
| 52 | toggleCode(code,name); |
| 53 | } |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | function toggleCode(code,name) { |
| 58 | const regionInput = jQuery('#second-banner-regions'); |
| 59 | const regionVal = jQuery('#second-banner-regions').val(); |
| 60 | const ccpaInput = jQuery('#ccpa-compatibility'); |
| 61 | const submitBtn = jQuery('p.submit #submit'); |
| 62 | const selectedBox = jQuery('.selected-regions'); |
| 63 | let regionList = regionVal.split(', '); |
| 64 | |
| 65 | if(regionList[0]==='') |
| 66 | regionList = []; |
| 67 | |
| 68 | if(regionList.indexOf(code)!==-1){ |
| 69 | regionList.splice(regionList.indexOf(code),1); |
| 70 | if(code==='US-06') |
| 71 | ccpaInput.val(''); |
| 72 | }else{ |
| 73 | regionList.push(code); |
| 74 | if(code==='US-06') |
| 75 | ccpaInput.val('1'); |
| 76 | } |
| 77 | |
| 78 | let itemSelector = '#'+code; |
| 79 | let selected = jQuery(itemSelector); |
| 80 | |
| 81 | if(selected.length<=0){ |
| 82 | let newItem = document.createElement('div'); |
| 83 | newItem.classList.add('selected-regions-item'); |
| 84 | newItem.id = code; |
| 85 | newItem.innerText = name; |
| 86 | selectedBox.append(newItem); |
| 87 | }else{ |
| 88 | selected.remove(); |
| 89 | } |
| 90 | |
| 91 | const newRegions = regionList.join(', '); |
| 92 | if(newRegions.length<=0){ |
| 93 | jQuery('.default-none').removeClass('hidden'); |
| 94 | }else{ |
| 95 | jQuery('.default-none').addClass('hidden'); |
| 96 | } |
| 97 | regionInput.val(newRegions); |
| 98 | submitBtn.addClass('enabled'); |
| 99 | } |