gutenberg
3 years ago
account-static.js
1 year ago
account.js
1 year ago
consent-mapping.js
1 year ago
cookiebot-admin-script.js
1 year ago
dashboard.js
1 year ago
debug-page.js
1 year ago
jquery.tipTip.js
3 years ago
multiple-page.js
3 years ago
network-settings-page.js
1 year ago
prior-consent-settings.js
3 years ago
settings-page.js
1 year ago
support-page.js
3 years ago
prior-consent-settings.js
275 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 | /** |
| 9 | * Init settings |
| 10 | * |
| 11 | * @since 1.8.0 |
| 12 | */ |
| 13 | function init() { |
| 14 | placeholder_select_language(); |
| 15 | placeholder_toggle(); |
| 16 | button_add_placeholder_language(); |
| 17 | button_delete_language(); |
| 18 | tooltip(); |
| 19 | show_advanced_options(); |
| 20 | edit_embed_regex(); |
| 21 | set_default_embed_regex(); |
| 22 | closeSubmitMsg(); |
| 23 | submitEnable(); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Enable/disable placeholder |
| 28 | * |
| 29 | * @since 1.8.0 |
| 30 | */ |
| 31 | function placeholder_toggle() { |
| 32 | jQuery( document ).on( |
| 33 | 'change', |
| 34 | '.placeholder_enable', |
| 35 | function () { |
| 36 | const status = jQuery( this ).is( ':checked' ); |
| 37 | const addon = jQuery( this ).data( 'addon' ); |
| 38 | |
| 39 | if ( status ) { |
| 40 | placeholder_enable( addon ); |
| 41 | } else { |
| 42 | placeholder_disable( addon ); |
| 43 | } |
| 44 | } |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Placeholder disable |
| 50 | * |
| 51 | * @param addon |
| 52 | * |
| 53 | * @since 1.8.0 |
| 54 | */ |
| 55 | function placeholder_disable( addon ) { |
| 56 | jQuery( '.placeholder[data-addon="' + addon + '"]' ).hide(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Placeholder enable |
| 61 | * |
| 62 | * @param addon |
| 63 | * |
| 64 | * @since 1.8.0 |
| 65 | */ |
| 66 | function placeholder_enable( addon ) { |
| 67 | jQuery( '.placeholder[data-addon="' + addon + '"]' ).show(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Add language for placeholder |
| 72 | * |
| 73 | * @since 1.8.0 |
| 74 | */ |
| 75 | function button_add_placeholder_language() { |
| 76 | const initialValues = jQuery('form').serialize(); |
| 77 | jQuery( '.btn_add_language' ).on( |
| 78 | 'click', |
| 79 | function ( e ) { |
| 80 | e.preventDefault(); |
| 81 | |
| 82 | const addon = jQuery( this ).data( 'addon' ); |
| 83 | |
| 84 | add_placeholder_language_content( addon ); |
| 85 | |
| 86 | const newValues = jQuery('form').serialize(); |
| 87 | if(newValues!==initialValues) |
| 88 | jQuery('p.submit #submit').addClass('enabled'); |
| 89 | |
| 90 | return false; |
| 91 | } |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Add placeholder language div |
| 97 | * |
| 98 | * @param addon |
| 99 | * |
| 100 | * @since 1.8.0 |
| 101 | */ |
| 102 | function add_placeholder_language_content( addon ) { |
| 103 | const data = jQuery( '.placeholder[data-addon="' + addon + '"] .placeholder_content:first' )[ 0 ].outerHTML; |
| 104 | |
| 105 | jQuery( '.placeholder[data-addon="' + addon + '"] .add_placeholder_language' ).before( data ); |
| 106 | |
| 107 | jQuery( '.placeholder[data-addon="' + addon + '"] .placeholder_content:last select' ).after( php.remove_link ); |
| 108 | |
| 109 | tooltip(); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Replace select and textarea name |
| 114 | * |
| 115 | * @since 1.8.0 |
| 116 | */ |
| 117 | function placeholder_select_language() { |
| 118 | jQuery( document ).on( |
| 119 | 'change', |
| 120 | '.placeholder_select_language', |
| 121 | function () { |
| 122 | const new_value = jQuery( this ).val(); |
| 123 | let select_name = jQuery( this ).attr( 'name' ); |
| 124 | |
| 125 | // get new name |
| 126 | select_name = select_name.substr( 0, select_name.lastIndexOf( '[' ) ); |
| 127 | select_name += '[' + new_value + ']'; |
| 128 | |
| 129 | // rename select field |
| 130 | jQuery( this ).attr( 'name', select_name ); |
| 131 | |
| 132 | // rename textarea |
| 133 | jQuery( this ).parent().next().find( 'textarea' ).attr( 'name', select_name ); |
| 134 | } |
| 135 | ) |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Delete language |
| 140 | * |
| 141 | * @since 1.8.0 |
| 142 | */ |
| 143 | function button_delete_language() { |
| 144 | const initialValues = jQuery('form').serialize(); |
| 145 | jQuery( document ).on( |
| 146 | 'click', |
| 147 | '.submitdelete', |
| 148 | function ( e ) { |
| 149 | e.preventDefault(); |
| 150 | |
| 151 | jQuery( this ).parent().parent().remove(); |
| 152 | |
| 153 | let newValues = jQuery('form').serialize(); |
| 154 | if(newValues===initialValues) |
| 155 | jQuery('p.submit #submit').removeClass('enabled'); |
| 156 | |
| 157 | return false; |
| 158 | } |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Show tooltip |
| 164 | * |
| 165 | * @since 1.8.0 |
| 166 | */ |
| 167 | function tooltip() { |
| 168 | jQuery( '.help-tip' ).tipTip( |
| 169 | { |
| 170 | 'maxWidth': 300, |
| 171 | 'fadeIn': 50, |
| 172 | 'fadeOut': 50, |
| 173 | 'delay': 200 |
| 174 | } |
| 175 | ); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Show advanced options |
| 180 | * |
| 181 | * @since 2.4.5 |
| 182 | */ |
| 183 | function show_advanced_options() { |
| 184 | jQuery( document ).on( |
| 185 | 'click', |
| 186 | '.show_advanced_options', |
| 187 | function( e ) { |
| 188 | e.preventDefault(); |
| 189 | |
| 190 | /** Toggle displaying advanced options **/ |
| 191 | jQuery( this ).next().toggle(); |
| 192 | |
| 193 | return false; |
| 194 | } |
| 195 | ); |
| 196 | } |
| 197 | |
| 198 | function edit_embed_regex() { |
| 199 | jQuery( document ).on( |
| 200 | 'click', |
| 201 | '#edit_embed_regex', |
| 202 | function(e) { |
| 203 | e.preventDefault(); |
| 204 | |
| 205 | /** Get the textarea for the embed regex **/ |
| 206 | let embed_regex = document.getElementById( "embed_regex" ); |
| 207 | |
| 208 | /** Remove the disable attribute in the textarea **/ |
| 209 | embed_regex.disabled = false; |
| 210 | |
| 211 | /** Make the Reset default button back visible **/ |
| 212 | let default_button = document.getElementById( 'btn_default_embed_regex' ); |
| 213 | default_button.classList.remove( 'hidden' ); |
| 214 | |
| 215 | jQuery( this ).hide(); |
| 216 | |
| 217 | return false; |
| 218 | } |
| 219 | ); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Set default embed regex |
| 224 | * |
| 225 | * @since 2.4.5 |
| 226 | */ |
| 227 | function set_default_embed_regex() { |
| 228 | jQuery( document ).on( |
| 229 | 'click', |
| 230 | '#btn_default_embed_regex', |
| 231 | function( e ) { |
| 232 | e.preventDefault(); |
| 233 | |
| 234 | /** get the value of the default embed regex **/ |
| 235 | let default_regex = jQuery( "#default_embed_regex" ).val(); |
| 236 | |
| 237 | /** Update the textarea of the embed regex **/ |
| 238 | jQuery( '#embed_regex' ).val( default_regex ); |
| 239 | |
| 240 | return false; |
| 241 | } |
| 242 | ); |
| 243 | } |
| 244 | |
| 245 | function closeSubmitMsg() { |
| 246 | jQuery('.cb-submit__msg').on('click',function(){ |
| 247 | jQuery(this).addClass('hidden'); |
| 248 | }); |
| 249 | } |
| 250 | |
| 251 | function submitEnable() { |
| 252 | const initialValues = jQuery('form').serialize(); |
| 253 | const events = { |
| 254 | change: 'input:not([type=text]), select', |
| 255 | input: 'input[type="text"], textarea' |
| 256 | }; |
| 257 | |
| 258 | Object.entries(events).forEach(entry => { |
| 259 | const [eventName, elements] = entry; |
| 260 | jQuery(document).on(eventName,elements,{initialValues: initialValues},function(event){ |
| 261 | checkValues(event.data.initialValues) |
| 262 | }); |
| 263 | }); |
| 264 | } |
| 265 | |
| 266 | function checkValues(initialValues){ |
| 267 | let submitBtn = jQuery('p.submit #submit'); |
| 268 | let newValues = jQuery('form').serialize(); |
| 269 | if(newValues !== initialValues) { |
| 270 | submitBtn.addClass('enabled'); |
| 271 | }else{ |
| 272 | submitBtn.removeClass('enabled'); |
| 273 | } |
| 274 | } |
| 275 |