1jQuery( document ).ready( function( $ ) { 2 'use strict'; 3 4 // display required asterisks 5 $( '.dk-speakout-petition label.required' ).append( '<span> *</span>'); 6 7/* 8------------------------------- 9 Form submission 10------------------------------- 11*/ 12 $( '.dk-speakout-submit' ).click( function( e ) { 13 e.preventDefault(); 14 15 var id = $( this ).attr( 'name' ), 16 lang = $( '#dk-speakout-lang-' + id ).val(), 17 honorific = $( '#dk-speakout-honorific-' + id ).val(), 18 firstname = $( '#dk-speakout-first-name-' + id ).val(), 19 lastname = $( '#dk-speakout-last-name-' + id ).val(), 20 email = $( '#dk-speakout-email-' + id ).val(), 21 street = $( '#dk-speakout-street-' + id ).val(), 22 city = $( '#dk-speakout-city-' + id ).val(), 23 state = $( '#dk-speakout-state-' + id ).val(), 24 postcode = $( '#dk-speakout-postcode-' + id ).val(), 25 country = $( '#dk-speakout-country-' + id ).val(), 26 custom_field = $( '#dk-speakout-custom-field-' + id ).val(), 27 custom_field2 = $( '#dk-speakout-custom-field2-' + id ).val(), 28 custom_field3 = $( '#dk-speakout-custom-field3-' + id ).val(), 29 custom_field4 = $( '#dk-speakout-custom-field4-' + id ).val(), 30 custom_field5 = $( '#dk-speakout-custom-field5-' + id ).val(), 31 custom_field6 = 0, 32 custom_field7 = 0, 33 custom_field8 = 0, 34 custom_field9 = 0, 35 custom_message = $( '.dk-speakout-message-' + id ).val(), 36 optin = '', 37 bcc = '', 38 anonymise = '', 39 privacypolicy = $( '#dk-speakout-privacypolicy-' + id).prop( 'checked' ), 40 redirect_url = $( '#dk-speakout-redirect-url-' + id).val(), 41 redirect_delay = $( '#dk-speakout-redirect-delay-' + id).val(), 42 url_target = $( '#dk-speakout-url-target-' + id).val(), 43 petition_fade = $( '#dk-speakout-petition-fade-' + id).val(), 44 requires_confirmation = $( '#dk-speakout-requires_confirmation-' + id).val(), 45 ajaxloader = $( '#dk-speakout-ajaxloader-' + id ), 46 hide_email_field = $( '#dk-speakout-hide-email-field-' + id ).val(); 47 48 // toggle use of .text() / .val() to read from edited textarea properly on Firefox 49 50 if ( $( '#dk-speakout-textval-' + id ).val() === 'text' ) { 51 custom_message = $( '.dk-speakout-message-' + id ).text(); 52 } 53 if( $( '#dk-speakout-custom-field6-' + id ).prop( 'checked' ) ){ 54 custom_field6 = 1; 55 } 56 if( $( '#dk-speakout-custom-field7-' + id ).prop( 'checked' ) ){ 57 custom_field7 = 1; 58 } 59 if( $( '#dk-speakout-custom-field8-' + id ).prop( 'checked' ) ){ 60 custom_field8 = 1; 61 } 62 if( $( '#dk-speakout-custom-field9-' + id ).prop( 'checked' ) ){ 63 custom_field9 = 1; 64 } 65 if ( $( '#dk-speakout-optin-' + id ).prop( 'checked' ) ) { 66 optin = 1; 67 } 68 if ( $( '#dk-speakout-bcc-' + id ).prop( 'checked' ) ) { 69 bcc = 1; 70 } 71 if ( $( '#dk-speakout-anonymise-' + id ).prop( 'checked' ) ) { 72 anonymise = 1; 73 } 74 75 // make sure error notices are turned off before checking for new errors 76 $( '#dk-speakout-petition-' + id + ' input' ).removeClass( 'dk-speakout-error' ); 77 78 // validate form values 79 var errors = 0, 80 // allow for new gtlds 81 emailRegEx = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 82 83 84 // if email is empty or doesn't fit regext and IS being displayed 85 if ( ( email === '' || emailRegEx.test( email ) === false ) && hide_email_field == '0' ) { 86 $( '#dk-speakout-email-' + id ).addClass( 'dk-speakout-error' ); 87 errors ++; 88 } 89 else{ 90 $( '#dk-speakout-email-' + id ).removeClass( 'dk-speakout-error' ); 91 } 92 93 if ( firstname === '' ) {
94 $( '#dk-speakout-first-name-' + id ).addClass( 'dk-speakout-error' ); 95 errors ++; 96 } 97 else{ 98 $( '#dk-speakout-first-name-' + id ).removeClass( 'dk-speakout-error' ); 99 } 100 101 if ( lastname === '' ) { 102 $( '#dk-speakout-last-name-' + id ).addClass( 'dk-speakout-error' ); 103 errors ++; 104 } 105 else{ 106 $( '#dk-speakout-last-name-' + id ).removeClass( 'dk-speakout-error' ); 107 } 108 109 if ( $('#dk-speakout-privacypolicy-' + id).length && privacypolicy === false ){ 110 $( '#dk-speakout-privacypolicy-' + id ).addClass( 'dk-speakout-error' ); 111 errors ++; 112 } 113 else{ 114 $( '#dk-speakout-privacypolicy-' + id ).removeClass( 'dk-speakout-error' ); 115 } 116 117 //test for required fields if set 118 if ( $('#dk-speakout-custom-field-'+ id).prop('required') && custom_field === "") { 119 $( '#dk-speakout-custom-field-' + id ).addClass( 'dk-speakout-error' ); 120 errors ++; 121 } 122 else{ 123 $( '#dk-speakout-custom-field-' + id ).removeClass( 'dk-speakout-error' ); 124 } 125 126 if ($('#dk-speakout-custom-field2-'+ id).prop('required') && custom_field2 === "") { 127 $( '#dk-speakout-custom-field2-' + id ).addClass( 'dk-speakout-error' ); 128 errors ++; 129 } 130 else{ 131 $( '#dk-speakout-custom-field2-' + id ).removeClass( 'dk-speakout-error' ); 132 } 133 134 if ($('#dk-speakout-custom-field3-'+ id).prop('required') && custom_field3 === "") { 135 $( '#dk-speakout-custom-field3-' + id ).addClass( 'dk-speakout-error' ); 136 errors ++; 137 } 138 else{ 139 $( '#dk-speakout-custom-field3-' + id ).removeClass( 'dk-speakout-error' ); 140 } 141 142 if ($('#dk-speakout-custom-field4-'+ id).prop('required') && custom_field4 === "") { 143 $( '#dk-speakout-custom-field4-' + id ).addClass( 'dk-speakout-error' ); 144 errors ++; 145 } 146 else{ 147 $( '#dk-speakout-custom-field4-' + id ).removeClass( 'dk-speakout-error' ); 148 } 149 150 if ($('#dk-speakout-custom-field5-'+ id).prop('required') && custom_field5 === "") { 151 $( '#dk-speakout-custom-field5-' + id ).addClass( 'dk-speakout-error' ); 152 errors ++; 153 } 154 else{ 155 $( '#dk-speakout-custom-field5-' + id ).removeClass( 'dk-speakout-error' ); 156 } 157 158 if ($('#dk-speakout-custom-field6-'+ id).prop('required') && custom_field6 === false) { 159 $( '#dk-speakout-custom-field6-' + id ).addClass( 'dk-speakout-error' ); 160 errors ++; 161 } 162 else{ 163 $( '#dk-speakout-custom-field6-' + id ).removeClass( 'dk-speakout-error' ); 164 } 165 166 if ($('#dk-speakout-custom-field7-'+ id).prop('required') && custom_field7 === false) { 167 $( '#dk-speakout-custom-field7-' + id ).addClass( 'dk-speakout-error' ); 168 errors ++; 169 } 170 else{ 171 $( '#dk-speakout-custom-field7-' + id ).removeClass( 'dk-speakout-error' ); 172 } 173 174 if ($('#dk-speakout-custom-field8-'+ id).prop('required') && custom_field8 === false) { 175 $( '#dk-speakout-custom-field8-' + id ).addClass( 'dk-speakout-error' ); 176 errors ++; 177 } 178 else{ 179 $( '#dk-speakout-custom-field9-' + id ).removeClass( 'dk-speakout-error' ); 180 } 181 182 if ($('#dk-speakout-custom-field9-'+ id).prop('required') && custom_field9 === false) { 183 $( '#dk-speakout-custom-field9-' + id ).addClass( 'dk-speakout-error' ); 184 errors ++; 185 } 186 else{ 187 $( '#dk-speakout-custom-field7-' + id ).removeClass( 'dk-speakout-error' ); 188 } 189 190 if (document.getElementById('dk-speakout-street-' + id) && $( '#dk-speakout-street-' + id ).prop('required') && street === "") { 191 $( '#dk-speakout-street-' + id ).addClass( 'dk-speakout-error' ); 192 errors ++; 193 } 194 else{ 195 $( '#dk-speakout-street-' + id ).removeClass( 'dk-speakout-error' ); 196 } 197 198 if (document.getElementById('dk-speakout-city-' + id) && $( '#dk-speakout-city-' + id ).prop('required') && city === "") {
199 $( '#dk-speakout-city-' + id ).addClass( 'dk-speakout-error' ); 200 errors ++; 201 } 202 else{ 203 $( '#dk-speakout-city-' + id ).removeClass( 'dk-speakout-error' ); 204 } 205 206 if (document.getElementById('dk-speakout-state-' + id) && $( '#dk-speakout-state-' + id ).prop('required') && state === "") { 207 $( '#dk-speakout-state-' + id ).addClass( 'dk-speakout-error' ); 208 errors ++; 209 } 210 else{ 211 $( '#dk-speakout-state-' + id ).removeClass( 'dk-speakout-error' ); 212 } 213 214 if (document.getElementById('dk-speakout-postcode-' + id) && $( '#dk-speakout-postcode-' + id ).prop('required') && postcode === "") { 215 $( '#dk-speakout-postcode-' + id ).addClass( 'dk-speakout-error' ); 216 errors ++; 217 } 218 else{ 219 $( '#dk-speakout-postcode-' + id ).removeClass( 'dk-speakout-error' ); 220 } 221 222 if (document.getElementById('dk-speakout-country-' + id) && $( '#dk-speakout-country-' + id ).prop('required') && country === "") { 223 $( '#dk-speakout-country-' + id ).addClass( 'dk-speakout-error' ); 224 errors ++; 225 } 226 else{ 227 $( '#dk-speakout-country-' + id ).removeClass( 'dk-speakout-error' ); 228 } 229 230 // if no errors found, submit the data via ajax 231 if ( errors === 0 && $( this ).attr( 'rel' ) !== 'disabled' ) { 232 233 // set rel to disabled as flag to block double clicks 234 $( this ).attr( 'rel', 'disabled' ); 235 236 var data = { 237 action: 'dk_speakout_sendmail', 238 id: id, 239 honorific: honorific, 240 first_name: firstname, 241 last_name: lastname, 242 email: email, 243 street: street, 244 city: city, 245 state: state, 246 postcode: postcode, 247 country: country, 248 custom_field: custom_field, 249 custom_field2: custom_field2, 250 custom_field3: custom_field3, 251 custom_field4: custom_field4, 252 custom_field5: custom_field5, 253 custom_field6: custom_field6, 254 custom_field7: custom_field7, 255 custom_field8: custom_field8, 256 custom_field9: custom_field9, 257 custom_message: custom_message, 258 optin: optin, 259 bcc: bcc, 260 anonymise: anonymise, 261 privacypolicy: privacypolicy, 262 lang: lang, 263 redirect_url: redirect_url, 264 redirect_delay: redirect_delay, 265 petition_fade: petition_fade 266 }; 267 268 // display AJAX loading animation 269 ajaxloader.css({ 'visibility' : 'visible'}); 270 271 // submit form data and handle ajax response 272 $.post( dk_speakout_js.ajaxurl, data, 273 function( response ) { 274 var response_class = 'dk-speakout-response-success'; 275 if ( response.status === 'error' ) { 276 response_class = 'dk-speakout-response-error'; 277 } 278 //if successfully signed and there is a redirect URL in the form 279 if (response.status !== 'error' && redirect_url > ""){ 280 setTimeout(function () { 281 //are we opening in a new window? 282 if(url_target === 0){ 283 window.location.href = redirect_url; 284 } 285 else{ 286 //this triggers blockup blockers :P 287 var redirectWindow = window.open(redirect_url, '_blank'); 288 $.ajax({
289 type: 'POST', 290 url: '/echo/json/', 291 success: function (data) { 292 redirectWindow.location; 293 } 294 }); 295 } 296 }, redirect_delay); //delay redirection by n milliseconds e.g. 5000 = 5 seconds 297 } 298 if(petition_fade=='enabled'){ 299 $( '#dk-speakout-petition-' + id + ' .dk-speakout-petition' ).fadeTo( 400, 0.35 ); 300 } 301 else{ 302 $( '#dk-speakout-petition-' + id + ' .dk-speakout-petition' ).hide(); 303 } 304 $( '#dk-speakout-petition-' + id + ' .dk-speakout-response' ).addClass( response_class ); 305 $( '#dk-speakout-petition-' + id + ' .dk-speakout-response' ).fadeIn().html( response.message ); 306 ajaxloader.css({ 'visibility' : 'hidden'}); 307 308 // advance the total but only if confirmation not required and response status has no error 309 if(requires_confirmation === 0 && response.status !== 'error'){ 310 var total = $( '.dk-speakout-signature-count span' )[0].textContent; 311 $( '.dk-speakout-signature-count span' )[0].textContent = Number(total.replaceAll(',', ''))+1; 312 $( '.dk-speakout-signature-count span' ).effect( 'highlight', {color:'#FFFF00'}, 3000 ); 313 } 314 }, 'json' 315 ); 316 } 317 318 }); 319 320 // launch Facebook sharing window 321 $( '.dk-speakout-facebook' ).click( function( e ) { 322 e.preventDefault(); 323 324 var id = $( this ).attr( 'rel' ), 325 posttitle = $( '#dk-speakout-posttitle-' + id ).val(), 326 share_url = document.URL, 327 facebook_url = 'http://www.facebook.com/sharer.php?u=' + share_url + '&t=' + posttitle; 328 329 window.open( facebook_url, 'facebook', 'height=400,width=550,left
329=100,top=100,resizable=yes,location=no,status=no,toolbar=no' ); 330 }); 331 332 // launch x sharing window 333 $( '.dk-speakout-x' ).click( function( e ) { 334 e.preventDefault(); 335 336 var id = $( this ).attr( 'rel' ), 337 tweet = $( '#dk-speakout-tweet-' + id ).val(), 338 current_url = document.URL, 339 share_url = current_url.split('#')[0], 340 x_url = 'http://x.com/share?url=' + share_url + '&text=' + tweet; 341 342 window.open( x_url, 'x', 'height=400,width=550,left=100,top=100,resizable=yes,location=no,status=no,toolbar=no' ); 343 }); 344 345/* 346------------------------------- 347 Petition reader popup 348------------------------------- 349 */ 350 $('a.dk-speakout-readme').click( function( e ) { 351 e.preventDefault(); 352 353 var id = $( this ).attr( 'rel' ), 354 sourceOffset = $(this).offset(), 355 sourceTop = sourceOffset.top - $(window).scrollTop(), 356 sourceLeft = sourceOffset.left - $(window).scrollLeft(), 357 screenHeight = $( document ).height(), 358 screenWidth = $( window ).width(), 359 windowHeight = $( window ).height(), 360 windowWidth = $( window ).width(), 361 readerHeight = 520, 362 readerWidth = 640, 363 readerTop = ( ( windowHeight / 2 ) - ( readerHeight / 2 ) ), 364 readerLeft = ( ( windowWidth / 2 ) - ( readerWidth / 2 ) ), 365 petitionText = $( 'div#dk-speakout-message-' + id ).html(), 366 reader = '<div id="dk-speakout-reader"><div id="dk-speakout-reader-close"></div><div id="dk-speakout-reader-content"></div></div>'; 367 368 // set this to toggle use of .val() / .text() so that Firefox will read from editable-message textarea as expected 369 $( '#dk-speakout-textval-' + id ).val('text'); 370 371 // use textarea for editable petition messages 372 if ( petitionText === undefined ) { 373 petitionText = $( '#dk-speakout-message-editable-' + id ).html(); 374 } 375 376 $( '#dk-speakout-windowshade' ).css( { 377 'width' : screenWidth, 378 'height' : screenHeight 379 }); 380 $( '#dk-speakout-windowshade' ).fadeTo( 500, 0.8 ); 381 382 if ( $( '#dk-speakout-reader' ).length > 0 ) { 383 $( '#dk-speakout-reader' ).remove(); 384 } 385 386 $( 'body' ).append( reader ); 387 388 $('#dk-speakout-reader').css({ 389 position : 'fixed', 390 left : sourceLeft, 391 top : sourceTop, 392 zIndex : 100002 393 }); 394 395 $('#dk-speakout-reader').animate({ 396 width : readerWidth, 397 height : readerHeight, 398 top : readerTop, 399 left : readerLeft 400 }, 500, function() { 401 $( '#dk-speakout-reader-content' ).html( petitionText ); 402 }); 403 404 /* Close the pop-up petition reader */ 405 // by clicking windowshade area 406 $( '#dk-speakout-windowshade' ).click( function () { 407 $( this ).fadeOut( 'slow' ); 408 // write edited text to form - using .text() because target textarea has display: none 409 $( '.dk-speakout-message-' + id ).text( $( '#dk-speakout-reader textarea' ).val() ); 410 $( '#dk-speakout-reader' ).remove(); 411 }); 412 // or by clicking the close button 413 $( 'body' ).on( 'click', '#dk-speakout-reader-close', function() { 414 $( '#dk-speakout-windowshade' ).fadeOut( 'slow' ); 415 // write edited text to form - using .text() because target textarea has display: none 416 $( '.dk-speakout-message-' + id ).text( $( '#dk-speakout-reader textarea' ).val() ); 417 $( '#dk-speakout-reader' ).remove(); 418 }); 419 // or by pressing ESC 420 $( document ).keyup( function( e ) { 421 if ( e.keyCode === 27 ) { 422 $( '#dk-speakout-windowshade' ).fadeOut( 'slow' ); 423 // write edited text to form - using .text() because target textarea has display: none 424 $( '.dk-speakout-message-' + id ).text( $( '#dk-speakout-reader textarea' ).val() ); 425 $( '#dk-speakout-reader' ).remove(); 426 } 427 }); 428 429 }); 430 431/* 432 Toggle form labels depending on input field focus 433 Leaving this in for now to support older custom themes 434 But it will be removed in future updates 435 */ 436 437 $( '.dk-speakout-petition-wrap input[type=text]' ).focus( function( e ) { 438 var label = $( this ).siblings( 'label' ); 439 if ( $( this ).val() === '' ) { 440 $( this ).siblings( 'label' ).addClass( 'dk-speakout-focus' ).removeClass( 'dk-speakout-blur' ); 441 } 442 $( this ).blur( function(){ 443 if ( this.value === '' ) {
444 label.addClass( 'dk-speakout-blur' ).removeClass( 'dk-speakout-focus' ); 445 } 446 }).focus( function() { 447 label.addClass( 'dk-speakout-focus' ).removeClass( 'dk-speakout-blur' ); 448 }).keydown( function( e ) { 449 label.addClass( 'dk-speakout-focus' ).removeClass( 'dk-speakout-blur' ); 450 $( this ).unbind( e ); 451 }); 452 }); 453 454 // hide labels on filled input fields when page is reloaded 455 $( '.dk-speakout-petition-wrap input[type=text]' ).each( function() { 456 if ( $( this ).val() !== '' ) { 457 $( this ).siblings( 'label' ).addClass( 'dk-speakout-focus' ); 458 } 459 }); 460 461});
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.