dropdown.js
3 years ago
editor-view.js
6 years ago
grunion-admin.js
3 years ago
grunion-frontend.js
6 years ago
grunion.js
6 years ago
tinymce-plugin-form-button.js
6 years ago
grunion.js
1170 lines
| 1 | /* global GrunionFB_i18n: true, FB, ajax_nonce_shortcode, ajax_nonce_json, ajaxurl, postId */ |
| 2 | |
| 3 | if ( ! window.FB ) { |
| 4 | window.FB = {}; |
| 5 | } |
| 6 | |
| 7 | GrunionFB_i18n = jQuery.extend( |
| 8 | { |
| 9 | nameLabel: 'Name', |
| 10 | emailLabel: 'Email', |
| 11 | urlLabel: 'Website', |
| 12 | commentLabel: 'Comment', |
| 13 | newLabel: 'New Field', |
| 14 | optionsLabel: 'Options', |
| 15 | optionLabel: 'Option', |
| 16 | firstOptionLabel: 'First option', |
| 17 | problemGeneratingForm: |
| 18 | "Oops, there was a problem generating your form. You'll likely need to try again.", |
| 19 | moveInstructions: 'Drag up or down\nto re-arrange', |
| 20 | moveLabel: 'move', |
| 21 | editLabel: 'edit', |
| 22 | savedMessage: 'Saved successfully', |
| 23 | requiredLabel: '(required)', |
| 24 | exitConfirmMessage: |
| 25 | 'Are you sure you want to exit the form editor without saving? Any changes you have made will be lost.', |
| 26 | maxNewFields: 5, |
| 27 | invalidEmail: ' is an invalid email address.', |
| 28 | }, |
| 29 | GrunionFB_i18n |
| 30 | ); |
| 31 | |
| 32 | GrunionFB_i18n.moveInstructions = GrunionFB_i18n.moveInstructions.replace( '\n', '<br />' ); |
| 33 | |
| 34 | FB.span = jQuery( '<span>' ); |
| 35 | FB.esc_html = function ( string ) { |
| 36 | return FB.span.text( string ).html(); |
| 37 | }; |
| 38 | |
| 39 | FB.esc_attr = function ( string ) { |
| 40 | string = FB.esc_html( string ); |
| 41 | return string.replace( '"', '"' ).replace( "'", ''' ); |
| 42 | }; |
| 43 | |
| 44 | FB.ContactForm = ( function () { |
| 45 | var fbForm = { |
| 46 | // Main object that generated shortcode via AJAX call |
| 47 | action: 'grunion_shortcode', |
| 48 | _ajax_nonce: ajax_nonce_shortcode, |
| 49 | to: '', |
| 50 | subject: '', |
| 51 | fields: {}, |
| 52 | }; |
| 53 | var defaultFields = { |
| 54 | name: { |
| 55 | label: GrunionFB_i18n.nameLabel, |
| 56 | type: 'name', |
| 57 | required: true, |
| 58 | options: [], |
| 59 | order: '1', |
| 60 | }, |
| 61 | email: { |
| 62 | label: GrunionFB_i18n.emailLabel, |
| 63 | type: 'email', |
| 64 | required: true, |
| 65 | options: [], |
| 66 | order: '2', |
| 67 | }, |
| 68 | url: { |
| 69 | label: GrunionFB_i18n.urlLabel, |
| 70 | type: 'url', |
| 71 | required: false, |
| 72 | options: [], |
| 73 | order: '3', |
| 74 | }, |
| 75 | comment: { |
| 76 | label: GrunionFB_i18n.commentLabel, |
| 77 | type: 'textarea', |
| 78 | required: true, |
| 79 | options: [], |
| 80 | order: '4', |
| 81 | }, |
| 82 | }; |
| 83 | var debug = false; // will print errors to log if true |
| 84 | var grunionNewCount = 0; // increment for new fields |
| 85 | var maxNewFields = GrunionFB_i18n.maxNewFields; // See filter in ../grunion-form-view.php |
| 86 | var optionsCache = {}; |
| 87 | var optionsCount = 0; // increment for options |
| 88 | var shortcode; |
| 89 | |
| 90 | function addField() { |
| 91 | try { |
| 92 | grunionNewCount++; |
| 93 | if ( grunionNewCount <= maxNewFields ) { |
| 94 | // Add to preview |
| 95 | jQuery( '#fb-extra-fields' ).append( |
| 96 | '<div id="fb-new-field' + |
| 97 | grunionNewCount + |
| 98 | '" fieldid="' + |
| 99 | grunionNewCount + |
| 100 | '" class="fb-new-fields"><div class="fb-fields"><div id="' + |
| 101 | grunionNewCount + |
| 102 | '" class="fb-remove"></div><label fieldid="' + |
| 103 | grunionNewCount + |
| 104 | '" for="fb-field' + |
| 105 | grunionNewCount + |
| 106 | '"><span class="label-text">' + |
| 107 | GrunionFB_i18n.newLabel + |
| 108 | '</span> </label><input type="text" id="fb-field' + |
| 109 | grunionNewCount + |
| 110 | '" disabled="disabled" /></div></div>' |
| 111 | ); |
| 112 | // Add to form object |
| 113 | fbForm.fields[ grunionNewCount ] = { |
| 114 | label: GrunionFB_i18n.newLabel, |
| 115 | type: 'text', |
| 116 | required: false, |
| 117 | options: [], |
| 118 | order: '5', |
| 119 | }; |
| 120 | if ( grunionNewCount === maxNewFields ) { |
| 121 | jQuery( '#fb-new-field' ).hide(); |
| 122 | } |
| 123 | // Reset form for this new field |
| 124 | optionsCount = 0; |
| 125 | optionsCache = {}; |
| 126 | jQuery( '#fb-new-options' ).html( |
| 127 | '<label for="fb-option0">' + |
| 128 | GrunionFB_i18n.optionsLabel + |
| 129 | '</label><input type="text" id="fb-option0" optionid="0" value="' + |
| 130 | GrunionFB_i18n.firstOptionLabel + |
| 131 | '" class="fb-options" />' |
| 132 | ); |
| 133 | jQuery( '#fb-options' ).hide(); |
| 134 | jQuery( '#fb-new-label' ).val( GrunionFB_i18n.newLabel ); |
| 135 | jQuery( '#fb-new-type' ).val( 'text' ); |
| 136 | jQuery( '#fb-field-id' ).val( grunionNewCount ); |
| 137 | setTimeout( function () { |
| 138 | jQuery( '#fb-new-label' ).focus().select(); |
| 139 | }, 100 ); |
| 140 | } else { |
| 141 | jQuery( '#fb-new-field' ).hide(); |
| 142 | } |
| 143 | } catch ( e ) { |
| 144 | if ( debug ) { |
| 145 | console.log( 'addField(): ' + e ); |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | function addOption() { |
| 150 | try { |
| 151 | optionsCount = jQuery( '#fb-new-options .fb-options' ).length; |
| 152 | var thisId = jQuery( '#fb-field-id' ).val(); |
| 153 | var thisType = jQuery( '#fb-new-type' ).val(); |
| 154 | if ( thisType === 'radio' ) { |
| 155 | // Add to right col |
| 156 | jQuery( '#fb-new-options' ).append( |
| 157 | '<div id="fb-option-box-' + |
| 158 | optionsCount + |
| 159 | '" class="fb-new-fields"><span optionid="' + |
| 160 | optionsCount + |
| 161 | '" class="fb-remove-option"></span><label></label><input type="text" id="fb-option' + |
| 162 | optionsCount + |
| 163 | '" optionid="' + |
| 164 | optionsCount + |
| 165 | '" value="' + |
| 166 | GrunionFB_i18n.optionLabel + |
| 167 | '" class="fb-options" /><div>' |
| 168 | ); |
| 169 | // Add to preview |
| 170 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).append( |
| 171 | '<div id="fb-radio-' + |
| 172 | thisId + |
| 173 | '-' + |
| 174 | optionsCount + |
| 175 | '"><input type="radio" disabled="disabled" id="fb-field' + |
| 176 | thisId + |
| 177 | '" name="radio-' + |
| 178 | thisId + |
| 179 | '" /><span>' + |
| 180 | GrunionFB_i18n.optionLabel + |
| 181 | '</span><div class="clear"></div></div>' |
| 182 | ); |
| 183 | } else if ( 'checkbox-multiple' === thisType ) { |
| 184 | // Add to right col |
| 185 | jQuery( '#fb-new-options' ).append( |
| 186 | '<div id="fb-option-box-' + |
| 187 | optionsCount + |
| 188 | '" class="fb-new-fields"><span optionid="' + |
| 189 | optionsCount + |
| 190 | '" class="fb-remove-option"></span><label></label><input type="text" id="fb-option' + |
| 191 | optionsCount + |
| 192 | '" optionid="' + |
| 193 | optionsCount + |
| 194 | '" value="' + |
| 195 | GrunionFB_i18n.optionLabel + |
| 196 | '" class="fb-options" /><div>' |
| 197 | ); |
| 198 | // Add to preview |
| 199 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).append( |
| 200 | '<div id="fb-checkbox-multiple-' + |
| 201 | thisId + |
| 202 | '-' + |
| 203 | optionsCount + |
| 204 | '"><input type="checkbox" disabled="disabled" id="fb-field' + |
| 205 | thisId + |
| 206 | '" name="checkbox-multiple-' + |
| 207 | thisId + |
| 208 | '" /><span>' + |
| 209 | GrunionFB_i18n.optionLabel + |
| 210 | '</span><div class="clear"></div></div>' |
| 211 | ); |
| 212 | } else { |
| 213 | // Add to right col |
| 214 | jQuery( '#fb-new-options' ).append( |
| 215 | '<div id="fb-option-box-' + |
| 216 | optionsCount + |
| 217 | '" class="fb-new-fields"><span optionid="' + |
| 218 | optionsCount + |
| 219 | '" class="fb-remove-option"></span><label></label><input type="text" id="fb-option' + |
| 220 | optionsCount + |
| 221 | '" optionid="' + |
| 222 | optionsCount + |
| 223 | '" value="" class="fb-options" /><div>' |
| 224 | ); |
| 225 | // Add to preview |
| 226 | jQuery( '#fb-field' + thisId ).append( |
| 227 | '<option id="fb-' + |
| 228 | thisId + |
| 229 | '-' + |
| 230 | optionsCount + |
| 231 | '" value="' + |
| 232 | thisId + |
| 233 | '-' + |
| 234 | optionsCount + |
| 235 | '"></option>' |
| 236 | ); |
| 237 | } |
| 238 | // Add to fbForm object |
| 239 | fbForm.fields[ thisId ].options[ optionsCount ] = ''; |
| 240 | // Add focus to new field |
| 241 | jQuery( '#fb-option' + optionsCount ) |
| 242 | .focus() |
| 243 | .select(); |
| 244 | } catch ( e ) { |
| 245 | if ( debug ) { |
| 246 | console.log( 'addOption(): ' + e ); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | function buildPreview() { |
| 251 | try { |
| 252 | if ( fbForm.to ) { |
| 253 | jQuery( '#fb-field-my-email' ).val( fbForm.to ); |
| 254 | } |
| 255 | if ( fbForm.subject ) { |
| 256 | jQuery( '#fb-field-subject' ).val( fbForm.subject ); |
| 257 | } |
| 258 | // Loop over and add fields |
| 259 | jQuery.each( fbForm.fields, function ( index, value ) { |
| 260 | jQuery( '#fb-extra-fields' ).before( |
| 261 | '<div class="fb-new-fields ui-state-default" fieldid="' + |
| 262 | index + |
| 263 | '" id="fb-new-field' + |
| 264 | index + |
| 265 | '"><div class="fb-fields"></div></div>' |
| 266 | ); |
| 267 | jQuery( '#fb-field-id' ).val( index ); |
| 268 | optionsCache[ index ] = {}; |
| 269 | optionsCache[ index ].options = []; |
| 270 | if ( |
| 271 | 'radio' === value.type || |
| 272 | 'select' === value.type || |
| 273 | 'checkbox-multiple' === value.type |
| 274 | ) { |
| 275 | jQuery.each( value.options, function ( i, value ) { |
| 276 | optionsCache[ index ].options[ i ] = value; |
| 277 | } ); |
| 278 | } |
| 279 | updateType( value.type, value.label, value.required ); |
| 280 | } ); |
| 281 | } catch ( e ) { |
| 282 | if ( debug ) { |
| 283 | console.log( 'buildPreview(): ' + e ); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | function customOptions( id, thisType ) { |
| 288 | try { |
| 289 | var thisOptions = ''; |
| 290 | for ( var i = 0; i < optionsCache[ id ].options.length; i++ ) { |
| 291 | if ( optionsCache[ id ].options[ i ] !== undefined ) { |
| 292 | if ( thisType === 'radio' ) { |
| 293 | thisOptions = |
| 294 | thisOptions + |
| 295 | '<div id="fb-radio-' + |
| 296 | id + |
| 297 | '-' + |
| 298 | i + |
| 299 | '"><input type="radio" id="fb-field' + |
| 300 | id + |
| 301 | '" name="radio-' + |
| 302 | id + |
| 303 | '" /><span>' + |
| 304 | FB.esc_html( optionsCache[ id ].options[ i ] ) + |
| 305 | '</span><div class="clear"></div></div>'; |
| 306 | } else if ( 'checkbox-multiple' === thisType ) { |
| 307 | thisOptions = |
| 308 | thisOptions + |
| 309 | '<div id="fb-checkbox-multiple-' + |
| 310 | id + |
| 311 | '-' + |
| 312 | i + |
| 313 | '"><input type="checkbox" id="fb-field' + |
| 314 | id + |
| 315 | '" name="checkbox-multiple-' + |
| 316 | id + |
| 317 | '" /><span>' + |
| 318 | FB.esc_html( optionsCache[ id ].options[ i ] ) + |
| 319 | '</span><div class="clear"></div></div>'; |
| 320 | } else { |
| 321 | thisOptions = |
| 322 | thisOptions + |
| 323 | '<option id="fb-' + |
| 324 | id + |
| 325 | '-' + |
| 326 | i + |
| 327 | '" value="' + |
| 328 | id + |
| 329 | '-' + |
| 330 | i + |
| 331 | '">' + |
| 332 | FB.esc_html( optionsCache[ id ].options[ i ] ) + |
| 333 | '</option>'; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | return thisOptions; |
| 338 | } catch ( e ) { |
| 339 | if ( debug ) { |
| 340 | console.log( 'customOptions(): ' + e ); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | function deleteField( that ) { |
| 345 | try { |
| 346 | grunionNewCount--; |
| 347 | var thisId = that.attr( 'id' ); |
| 348 | delete fbForm.fields[ thisId ]; |
| 349 | jQuery( '#' + thisId ) |
| 350 | .parent() |
| 351 | .parent() |
| 352 | .remove(); |
| 353 | if ( grunionNewCount <= maxNewFields ) { |
| 354 | jQuery( '#fb-new-field' ).show(); |
| 355 | } |
| 356 | } catch ( e ) { |
| 357 | if ( debug ) { |
| 358 | console.log( 'deleteField(): ' + e ); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | function editField( that ) { |
| 363 | try { |
| 364 | scroll( 0, 0 ); |
| 365 | setTimeout( function () { |
| 366 | jQuery( '#fb-new-label' ).focus().select(); |
| 367 | }, 100 ); |
| 368 | var thisId = that.parent().attr( 'fieldid' ); |
| 369 | loadFieldEditor( thisId ); |
| 370 | } catch ( e ) { |
| 371 | if ( debug ) { |
| 372 | console.log( 'editField(): ' + e ); |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | function grabShortcode() { |
| 377 | try { |
| 378 | // Takes fbForm object and returns shortcode syntax |
| 379 | jQuery.post( ajaxurl, fbForm, function ( response ) { |
| 380 | shortcode = response; |
| 381 | } ); |
| 382 | } catch ( e ) { |
| 383 | alert( GrunionFB_i18n.problemGeneratingForm ); |
| 384 | if ( debug ) { |
| 385 | console.log( 'grabShortcode(): ' + e ); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | function hideDesc() { |
| 390 | jQuery( '#fb-desc' ).hide(); |
| 391 | jQuery( '#fb-add-field' ).show(); |
| 392 | } |
| 393 | function hidePopup() { |
| 394 | try { |
| 395 | // copied from wp-includes/js/thickbox/thickbox.js |
| 396 | jQuery( '#TB_imageOff', window.parent.document ).unbind( 'click' ); |
| 397 | jQuery( '#TB_closeWindowButton', window.parent.document ).unbind( 'click' ); |
| 398 | jQuery( '#TB_window', window.parent.document ).fadeOut( 'fast' ); |
| 399 | jQuery( 'body', window.parent.document ).removeClass( 'modal-open' ); |
| 400 | jQuery( '#TB_window,#TB_overlay,#TB_HideSelect', window.parent.document ) |
| 401 | .trigger( 'unload' ) |
| 402 | .unbind() |
| 403 | .remove(); |
| 404 | jQuery( '#TB_load', window.parent.document ).remove(); |
| 405 | if ( typeof window.parent.document.body.style.maxHeight === 'undefined' ) { |
| 406 | //if IE 6 |
| 407 | jQuery( 'body', 'html', window.parent.document ).css( { height: 'auto', width: 'auto' } ); |
| 408 | jQuery( 'html', window.parent.document ).css( 'overflow', '' ); |
| 409 | } |
| 410 | window.parent.document.onkeydown = ''; |
| 411 | window.parent.document.onkeyup = ''; |
| 412 | return false; |
| 413 | } catch ( e ) { |
| 414 | if ( debug ) { |
| 415 | console.log( 'hidePopup(): ' + e ); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | function hideShowEditLink( whichType, that ) { |
| 420 | try { |
| 421 | if ( whichType === 'show' ) { |
| 422 | // Prevents showing links twice |
| 423 | if ( jQuery( '.fb-edit-field' ).is( ':visible' ) ) { |
| 424 | jQuery( '.fb-edit-field' ).remove(); |
| 425 | } |
| 426 | that |
| 427 | .find( 'label' ) |
| 428 | .prepend( |
| 429 | '<span class="right fb-edit-field" style="font-weight: normal;"><a href="" class="fb-reorder"><div style="display: none;">' + |
| 430 | GrunionFB_i18n.moveInstructions + |
| 431 | '</div>' + |
| 432 | GrunionFB_i18n.moveLabel + |
| 433 | '</a> <span style="color: #C7D8DE;">|</span> <a href="" class="fb-edit">' + |
| 434 | GrunionFB_i18n.editLabel + |
| 435 | '</a></span>' |
| 436 | ); |
| 437 | } else { |
| 438 | jQuery( '.fb-edit-field' ).remove(); |
| 439 | } |
| 440 | } catch ( e ) { |
| 441 | if ( debug ) { |
| 442 | console.log( 'hideShowEditLink(): ' + e ); |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | function loadFieldEditor( id ) { |
| 447 | try { |
| 448 | var thisType = fbForm.fields[ id ].type; |
| 449 | jQuery( '#fb-options' ).hide(); |
| 450 | // Reset hidden field ID |
| 451 | jQuery( '#fb-field-id' ).val( id ); |
| 452 | // Load label |
| 453 | jQuery( '#fb-new-label' ).val( fbForm.fields[ id ].label ); |
| 454 | // Load type |
| 455 | jQuery( '#fb-new-type' ).val( fbForm.fields[ id ].type ); |
| 456 | // Load required |
| 457 | if ( fbForm.fields[ id ].required ) { |
| 458 | jQuery( '#fb-new-required' ).prop( 'checked', true ); |
| 459 | } else { |
| 460 | jQuery( '#fb-new-required' ).prop( 'checked', false ); |
| 461 | } |
| 462 | // Load options if there are any |
| 463 | if ( 'select' === thisType || 'radio' === thisType || 'checkbox-multiple' === thisType ) { |
| 464 | var thisOptions = fbForm.fields[ id ].options; |
| 465 | jQuery( '#fb-options' ).show(); |
| 466 | jQuery( '#fb-new-options' ).html( '' ); // Clear it all out |
| 467 | for ( var i = 0; i < thisOptions.length; i++ ) { |
| 468 | if ( thisOptions[ i ] !== undefined ) { |
| 469 | if ( thisType === 'radio' ) { |
| 470 | jQuery( '#fb-new-options' ).append( |
| 471 | '<div id="fb-option-box-' + |
| 472 | i + |
| 473 | '" class="fb-new-fields"><span optionid="' + |
| 474 | i + |
| 475 | '" class="fb-remove-option"></span><label></label><input type="text" id="fb-option' + |
| 476 | i + |
| 477 | '" optionid="' + |
| 478 | i + |
| 479 | '" value="' + |
| 480 | FB.esc_attr( fbForm.fields[ id ].options[ i ] ) + |
| 481 | '" class="fb-options" /><div>' |
| 482 | ); |
| 483 | } else { |
| 484 | jQuery( '#fb-new-options' ).append( |
| 485 | '<div id="fb-option-box-' + |
| 486 | i + |
| 487 | '" class="fb-new-fields"><span optionid="' + |
| 488 | i + |
| 489 | '" class="fb-remove-option"></span><label></label><input type="text" id="fb-option' + |
| 490 | i + |
| 491 | '" optionid="' + |
| 492 | i + |
| 493 | '" value="' + |
| 494 | FB.esc_attr( fbForm.fields[ id ].options[ i ] ) + |
| 495 | '" class="fb-options" /><div>' |
| 496 | ); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | // Load editor & hide description |
| 502 | hideDesc(); |
| 503 | } catch ( e ) { |
| 504 | if ( debug ) { |
| 505 | console.log( 'loadFieldEditor(): ' + e ); |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | function parseShortcode( data ) { |
| 510 | try { |
| 511 | // Clean up fields by resetting them |
| 512 | fbForm.fields = {}; |
| 513 | // Add new fields |
| 514 | if ( ! data ) { |
| 515 | fbForm.fields = defaultFields; |
| 516 | } else { |
| 517 | jQuery.each( data.fields, function ( index, value ) { |
| 518 | if ( 1 === parseInt( value.required, 10 ) ) { |
| 519 | value.required = 'true'; |
| 520 | } |
| 521 | fbForm.fields[ index ] = value; |
| 522 | } ); |
| 523 | fbForm.to = data.to; |
| 524 | fbForm.subject = data.subject; |
| 525 | } |
| 526 | } catch ( e ) { |
| 527 | if ( debug ) { |
| 528 | console.log( 'parseShortcode(): ' + e ); |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | function removeOption( optionId ) { |
| 533 | try { |
| 534 | var thisId = jQuery( '#fb-field-id' ).val(); |
| 535 | var thisVal = jQuery( '#fb-option' + optionId ).val(); |
| 536 | var thisType = jQuery( '#fb-new-type' ).val(); |
| 537 | // Remove from right |
| 538 | jQuery( '#fb-option-box-' + optionId ).remove(); |
| 539 | // Remove from preview |
| 540 | if ( thisType === 'radio' ) { |
| 541 | jQuery( '#fb-radio-' + thisId + '-' + optionId ).remove(); |
| 542 | } else if ( 'checkbox-multiple' === thisType ) { |
| 543 | jQuery( '#fb-checkbox-multiple-' + thisId + '-' + optionId ).remove(); |
| 544 | } else { |
| 545 | jQuery( '#fb-' + thisId + '-' + optionId ).remove(); |
| 546 | } |
| 547 | // Remove from fbForm object |
| 548 | var idx = fbForm.fields[ thisId ].options.indexOf( thisVal ); |
| 549 | if ( idx !== -1 ) { |
| 550 | fbForm.fields[ thisId ].options.splice( idx, 1 ); |
| 551 | } |
| 552 | } catch ( e ) { |
| 553 | if ( debug ) { |
| 554 | console.log( 'removeOption(): ' + e ); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | function removeOptions() { |
| 559 | try { |
| 560 | var thisId = jQuery( '#fb-field-id' ).val(); |
| 561 | jQuery( '#fb-options' ).hide(); |
| 562 | if ( optionsCache[ thisId ] === undefined ) { |
| 563 | optionsCache[ thisId ] = {}; |
| 564 | } |
| 565 | optionsCache[ thisId ].options = fbForm.fields[ thisId ].options; // Save options in case they change their mind |
| 566 | fbForm.fields[ thisId ].options = []; // Removes all options |
| 567 | } catch ( e ) { |
| 568 | if ( debug ) { |
| 569 | console.log( 'removeOptions(): ' + e ); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | function sendShortcodeToEditor() { |
| 574 | try { |
| 575 | // Serialize fields |
| 576 | jQuery( 'div#sortable div.fb-new-fields' ).each( function ( index ) { |
| 577 | var thisId = jQuery( this ).attr( 'fieldid' ); |
| 578 | fbForm.fields[ thisId ].order = index; |
| 579 | } ); |
| 580 | // Export to WYSIWYG editor |
| 581 | jQuery.post( ajaxurl, fbForm, function ( response ) { |
| 582 | var isVisual = jQuery( '#edButtonPreview', window.parent.document ).hasClass( 'active' ); |
| 583 | /* WP 3.3+ */ |
| 584 | if ( ! isVisual ) { |
| 585 | isVisual = jQuery( '#wp-content-wrap', window.parent.document ).hasClass( 'tmce-active' ); |
| 586 | } |
| 587 | |
| 588 | var win = window.dialogArguments || opener || parent || top; |
| 589 | var currentCode; |
| 590 | if ( isVisual ) { |
| 591 | currentCode = win.tinyMCE.activeEditor.getContent(); |
| 592 | } else { |
| 593 | currentCode = jQuery( '#editorcontainer textarea', window.parent.document ).val(); |
| 594 | /* WP 3.3+ */ |
| 595 | if ( typeof currentCode !== 'string' ) { |
| 596 | currentCode = jQuery( '.wp-editor-area', window.parent.document ).val(); |
| 597 | } |
| 598 | } |
| 599 | var regexp = new RegExp( |
| 600 | '\\[contact-form\\b.*?\\/?\\](?:[\\s\\S]+?\\[\\/contact-form\\])?' |
| 601 | ); |
| 602 | |
| 603 | // Remove new lines that cause BR tags to show up |
| 604 | response = response.replace( /\n/g, ' ' ); |
| 605 | // Convert characters to comma |
| 606 | response = response.replace( /%26#x002c;/g, ',' ); |
| 607 | |
| 608 | // Add new shortcode |
| 609 | if ( currentCode.match( regexp ) ) { |
| 610 | if ( isVisual ) { |
| 611 | win.tinyMCE.activeEditor.execCommand( |
| 612 | 'mceSetContent', |
| 613 | false, |
| 614 | currentCode.replace( regexp, response ) |
| 615 | ); |
| 616 | } else { |
| 617 | // looks like the visual editor is disabled, |
| 618 | // update the contents of the post directly |
| 619 | jQuery( '#content', window.parent.document ).val( |
| 620 | currentCode.replace( regexp, response ) |
| 621 | ); |
| 622 | } |
| 623 | } else { |
| 624 | try { |
| 625 | win.send_to_editor( response ); |
| 626 | } catch ( e ) { |
| 627 | if ( isVisual ) { |
| 628 | win.tinyMCE.activeEditor.execCommand( 'mceInsertContent', false, response ); |
| 629 | } else { |
| 630 | // looks like the visual editor is disabled, |
| 631 | // update the contents of the post directly |
| 632 | jQuery( '#content', window.parent.document ).val( currentCode + response ); |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | hidePopup(); |
| 637 | } ); |
| 638 | } catch ( e ) { |
| 639 | if ( debug ) { |
| 640 | console.log( 'sendShortcodeToEditor(): ' + e ); |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | function showDesc() { |
| 645 | jQuery( '#fb-desc' ).show(); |
| 646 | jQuery( '#fb-add-field' ).hide(); |
| 647 | } |
| 648 | function showAndHideMessage( message ) { |
| 649 | try { |
| 650 | var newMessage = ! message ? GrunionFB_i18n.savedMessage : message; |
| 651 | jQuery( '#fb-success' ).text( newMessage ); |
| 652 | jQuery( '#fb-success' ).slideDown( 'fast' ); |
| 653 | setTimeout( function () { |
| 654 | jQuery( '#fb-success' ).slideUp( 'fast' ); |
| 655 | }, 2500 ); |
| 656 | } catch ( e ) { |
| 657 | if ( debug ) { |
| 658 | console.log( 'showAndHideMessage(): ' + e ); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | function switchTabs( whichType ) { |
| 663 | try { |
| 664 | if ( whichType === 'preview' ) { |
| 665 | if ( ! validateEmails( jQuery( '#fb-field-my-email' ).val() ) ) { |
| 666 | return; |
| 667 | } |
| 668 | jQuery( '#tab-preview a' ).addClass( 'current' ); |
| 669 | jQuery( '#tab-settings a' ).removeClass( 'current' ); |
| 670 | jQuery( '#fb-preview-form, #fb-desc' ).show(); |
| 671 | jQuery( '#fb-email-settings, #fb-email-desc' ).hide(); |
| 672 | showAndHideMessage( GrunionFB_i18n.savedMessage ); |
| 673 | } else { |
| 674 | jQuery( '#tab-preview a' ).removeClass( 'current' ); |
| 675 | jQuery( '#tab-settings a' ).addClass( 'current' ); |
| 676 | jQuery( '#fb-preview-form, #fb-desc, #fb-add-field' ).hide(); |
| 677 | jQuery( '#fb-email-settings, #fb-email-desc' ).show(); |
| 678 | jQuery( '#fb-field-my-email' ).focus().select(); |
| 679 | } |
| 680 | } catch ( e ) { |
| 681 | if ( debug ) { |
| 682 | console.log( 'switchTabs(): ' + e ); |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | function validateEmails( emails ) { |
| 687 | // Field is allowed to be empty :) |
| 688 | if ( 0 === emails.length ) { |
| 689 | return true; |
| 690 | } |
| 691 | |
| 692 | var $e, |
| 693 | emailList = emails.split( ',' ); |
| 694 | |
| 695 | for ( $e = 0; $e < emailList.length; $e++ ) { |
| 696 | if ( false === validateEmail( emailList[ $e ] ) ) { |
| 697 | alert( emailList[ $e ] + GrunionFB_i18n.invalidEmail ); |
| 698 | return false; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | return true; |
| 703 | } |
| 704 | /* Uses The Official Standard: RFC 5322 -- http://www.regular-expressions.info/email.html */ |
| 705 | function validateEmail( email ) { |
| 706 | var re = /^(?=[a-z0-9@.!#$%&'*+/=?^_`{|}~-]{6,254}$)(?=[a-z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:(?=[a-z0-9-]{1,63}\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?=[a-z0-9-]{1,63}$)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i; |
| 707 | return re.test( email ); |
| 708 | } |
| 709 | function updateLabel() { |
| 710 | try { |
| 711 | var thisId = jQuery( '#fb-field-id' ).val(); |
| 712 | var thisLabel = jQuery( '#fb-new-label' ).val(); |
| 713 | // Update preview |
| 714 | if ( thisLabel.length === 0 ) { |
| 715 | jQuery( '#fb-new-field' + thisId + ' label .label-text' ).text( GrunionFB_i18n.newLabel ); |
| 716 | } else { |
| 717 | jQuery( '#fb-new-field' + thisId + ' label .label-text' ).text( thisLabel ); |
| 718 | } |
| 719 | // Update fbForm object |
| 720 | fbForm.fields[ thisId ].label = thisLabel; |
| 721 | } catch ( e ) { |
| 722 | if ( debug ) { |
| 723 | console.log( 'updateLabel(): ' + e ); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | function updateMyEmail() { |
| 728 | try { |
| 729 | var thisEmail = jQuery( '#fb-field-my-email' ).val(); |
| 730 | fbForm.to = thisEmail; |
| 731 | } catch ( e ) { |
| 732 | if ( debug ) { |
| 733 | console.log( 'updateMyEmail(): ' + e ); |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | function updateOption( that ) { |
| 738 | try { |
| 739 | var thisId = jQuery( '#fb-field-id' ).val(); |
| 740 | var thisOptionid = that.attr( 'optionid' ); |
| 741 | var thisOptionValue = that.val(); |
| 742 | var thisType = jQuery( '#fb-new-type' ).val(); |
| 743 | // Update preview |
| 744 | if ( thisType === 'radio' ) { |
| 745 | jQuery( '#fb-radio-' + thisId + '-' + thisOptionid + ' span' ).text( thisOptionValue ); |
| 746 | } else if ( 'checkbox-multiple' === thisType ) { |
| 747 | jQuery( '#fb-checkbox-multiple-' + thisId + '-' + thisOptionid + ' span' ).text( |
| 748 | thisOptionValue |
| 749 | ); |
| 750 | } else { |
| 751 | jQuery( '#fb-' + thisId + '-' + thisOptionid ).text( thisOptionValue ); |
| 752 | } |
| 753 | // Update fbForm object |
| 754 | fbForm.fields[ thisId ].options[ thisOptionid ] = thisOptionValue; |
| 755 | } catch ( e ) { |
| 756 | if ( debug ) { |
| 757 | console.log( 'updateOption(): ' + e ); |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | function updateRequired() { |
| 762 | try { |
| 763 | var thisId = jQuery( '#fb-field-id' ).val(); |
| 764 | var thisChecked = jQuery( '#fb-new-required' ).is( ':checked' ); |
| 765 | // Update object and preview |
| 766 | if ( thisChecked ) { |
| 767 | fbForm.fields[ thisId ].required = true; |
| 768 | jQuery( '#fb-new-field' + thisId + ' label' ).append( |
| 769 | '<span class="label-required">' + GrunionFB_i18n.requiredLabel + '</span>' |
| 770 | ); |
| 771 | } else { |
| 772 | fbForm.fields[ thisId ].required = false; |
| 773 | jQuery( '#fb-new-field' + thisId + ' label .label-required' ).remove(); |
| 774 | } |
| 775 | } catch ( e ) { |
| 776 | if ( debug ) { |
| 777 | console.log( 'updateRequired(): ' + e ); |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | function updateSubject() { |
| 782 | try { |
| 783 | var thisSubject = jQuery( '#fb-field-subject' ).val(); |
| 784 | fbForm.subject = thisSubject; |
| 785 | } catch ( e ) { |
| 786 | if ( debug ) { |
| 787 | console.log( 'updateSubject(): ' + e ); |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | function updateType( thisType, thisLabelText, thisRequired ) { |
| 792 | try { |
| 793 | var thisId = jQuery( '#fb-field-id' ).val(); |
| 794 | if ( ! thisType ) { |
| 795 | thisType = jQuery( '#fb-new-type' ).val(); |
| 796 | } |
| 797 | if ( ! thisLabelText ) { |
| 798 | thisLabelText = jQuery( '#fb-new-field' + thisId + ' .label-text' ).text(); |
| 799 | } |
| 800 | var isRequired = thisRequired |
| 801 | ? '<span class="label-required">' + GrunionFB_i18n.requiredLabel + '</span>' |
| 802 | : ''; |
| 803 | var thisLabel = |
| 804 | '<label fieldid="' + |
| 805 | thisId + |
| 806 | '" for="fb-field' + |
| 807 | thisId + |
| 808 | '"><span class="label-text">' + |
| 809 | FB.esc_html( thisLabelText ) + |
| 810 | '</span>' + |
| 811 | isRequired + |
| 812 | '</label>'; |
| 813 | var thisRadio = |
| 814 | '<input type="radio" name="radio-' + |
| 815 | thisId + |
| 816 | '" id="fb-field' + |
| 817 | thisId + |
| 818 | ' "disabled="disabled" />'; |
| 819 | var thisRadioLabel = |
| 820 | '<label fieldid="' + |
| 821 | thisId + |
| 822 | '" for="fb-field' + |
| 823 | thisId + |
| 824 | '" class="fb-radio-label"><span class="label-text">' + |
| 825 | FB.esc_html( thisLabelText ) + |
| 826 | '</span>' + |
| 827 | isRequired + |
| 828 | '</label>'; |
| 829 | var thisRadioRemove = '<div class="fb-remove fb-remove-small" id="' + thisId + '"></div>'; |
| 830 | var thisRemove = '<div class="fb-remove" id="' + thisId + '"></div>'; |
| 831 | var thisCheckbox = |
| 832 | '<input type="checkbox" id="fb-field' + thisId + '" "disabled="disabled" />'; |
| 833 | var thisCheckboxMultiple = |
| 834 | '<input type="checkbox" id="fb-field' + thisId + '" "disabled="disabled" />'; |
| 835 | var thisCheckboxMultipleRemove = |
| 836 | '<div class="fb-remove fb-remove-small" id="' + thisId + '"></div>'; |
| 837 | var thisText = '<input type="text" id="fb-field' + thisId + '" "disabled="disabled" />'; |
| 838 | var thisTextarea = '<textarea id="fb-field' + thisId + '" "disabled="disabled"></textarea>'; |
| 839 | var thisClear = '<div class="clear"></div>'; |
| 840 | var thisSelect = |
| 841 | '<select id="fb-field' + |
| 842 | thisId + |
| 843 | '" fieldid="' + |
| 844 | thisId + |
| 845 | '"><option id="fb-' + |
| 846 | thisId + |
| 847 | '-' + |
| 848 | optionsCount + |
| 849 | '" value="' + |
| 850 | thisId + |
| 851 | '-' + |
| 852 | optionsCount + |
| 853 | '">' + |
| 854 | GrunionFB_i18n.firstOptionLabel + |
| 855 | '</option></select>'; |
| 856 | switch ( thisType ) { |
| 857 | case 'checkbox': |
| 858 | removeOptions(); |
| 859 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 860 | thisRadioRemove + thisCheckbox + thisRadioLabel + thisClear |
| 861 | ); |
| 862 | break; |
| 863 | case 'checkbox-multiple': |
| 864 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 865 | thisLabel + |
| 866 | thisCheckboxMultipleRemove + |
| 867 | '<div fieldid="' + |
| 868 | thisId + |
| 869 | '" id="fb-custom-checkbox-multiple' + |
| 870 | thisId + |
| 871 | '"></div>' |
| 872 | ); |
| 873 | if ( |
| 874 | optionsCache[ thisId ] !== undefined && |
| 875 | optionsCache[ thisId ].options.length !== 0 |
| 876 | ) { |
| 877 | fbForm.fields[ thisId ].options = optionsCache[ thisId ].options; |
| 878 | jQuery( '#fb-custom-checkbox-multiple' + thisId ).append( |
| 879 | customOptions( thisId, thisType ) |
| 880 | ); |
| 881 | } else { |
| 882 | jQuery( '#fb-new-options' ).html( |
| 883 | '<label for="fb-option0">' + |
| 884 | GrunionFB_i18n.optionsLabel + |
| 885 | '</label><input type="text" id="fb-option0" optionid="0" value="' + |
| 886 | GrunionFB_i18n.firstOptionLabel + |
| 887 | '" class="fb-options" />' |
| 888 | ); |
| 889 | jQuery( '#fb-custom-checkbox-multiple' + thisId ).append( |
| 890 | '<div id="fb-checkbox-multiple-' + |
| 891 | thisId + |
| 892 | '-0">' + |
| 893 | thisCheckboxMultiple + |
| 894 | '<span>' + |
| 895 | GrunionFB_i18n.firstOptionLabel + |
| 896 | '</span>' + |
| 897 | thisClear + |
| 898 | '</div>' |
| 899 | ); |
| 900 | fbForm.fields[ thisId ].options[ optionsCount ] = GrunionFB_i18n.firstOptionLabel; |
| 901 | } |
| 902 | jQuery( '#fb-options' ).show(); |
| 903 | setTimeout( function () { |
| 904 | jQuery( '#fb-option0' ).focus().select(); |
| 905 | }, 100 ); |
| 906 | break; |
| 907 | case 'email': |
| 908 | removeOptions(); |
| 909 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 910 | thisRemove + thisLabel + thisText |
| 911 | ); |
| 912 | break; |
| 913 | case 'name': |
| 914 | removeOptions(); |
| 915 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 916 | thisRemove + thisLabel + thisText |
| 917 | ); |
| 918 | break; |
| 919 | case 'radio': |
| 920 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 921 | thisLabel + |
| 922 | thisRadioRemove + |
| 923 | '<div fieldid="' + |
| 924 | thisId + |
| 925 | '" id="fb-custom-radio' + |
| 926 | thisId + |
| 927 | '"></div>' |
| 928 | ); |
| 929 | if ( |
| 930 | optionsCache[ thisId ] !== undefined && |
| 931 | optionsCache[ thisId ].options.length !== 0 |
| 932 | ) { |
| 933 | fbForm.fields[ thisId ].options = optionsCache[ thisId ].options; |
| 934 | jQuery( '#fb-custom-radio' + thisId ).append( customOptions( thisId, thisType ) ); |
| 935 | } else { |
| 936 | jQuery( '#fb-new-options' ).html( |
| 937 | '<label for="fb-option0">' + |
| 938 | GrunionFB_i18n.optionsLabel + |
| 939 | '</label><input type="text" id="fb-option0" optionid="0" value="' + |
| 940 | GrunionFB_i18n.firstOptionLabel + |
| 941 | '" class="fb-options" />' |
| 942 | ); |
| 943 | jQuery( '#fb-custom-radio' + thisId ).append( |
| 944 | '<div id="fb-radio-' + |
| 945 | thisId + |
| 946 | '-0">' + |
| 947 | thisRadio + |
| 948 | '<span>' + |
| 949 | GrunionFB_i18n.firstOptionLabel + |
| 950 | '</span>' + |
| 951 | thisClear + |
| 952 | '</div>' |
| 953 | ); |
| 954 | fbForm.fields[ thisId ].options[ optionsCount ] = GrunionFB_i18n.firstOptionLabel; |
| 955 | } |
| 956 | jQuery( '#fb-options' ).show(); |
| 957 | setTimeout( function () { |
| 958 | jQuery( '#fb-option0' ).focus().select(); |
| 959 | }, 100 ); |
| 960 | break; |
| 961 | case 'select': |
| 962 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 963 | thisRemove + thisLabel + thisSelect |
| 964 | ); |
| 965 | if ( |
| 966 | optionsCache[ thisId ] !== undefined && |
| 967 | optionsCache[ thisId ].options.length !== 0 |
| 968 | ) { |
| 969 | fbForm.fields[ thisId ].options = optionsCache[ thisId ].options; |
| 970 | jQuery( '#fb-field' + thisId ).html( customOptions( thisId, thisType ) ); |
| 971 | } else { |
| 972 | jQuery( '#fb-new-options' ).html( |
| 973 | '<label for="fb-option0">' + |
| 974 | GrunionFB_i18n.optionsLabel + |
| 975 | '</label><input type="text" id="fb-option0" optionid="0" value="' + |
| 976 | GrunionFB_i18n.firstOptionLabel + |
| 977 | '" class="fb-options" />' |
| 978 | ); |
| 979 | fbForm.fields[ thisId ].options[ optionsCount ] = GrunionFB_i18n.firstOptionLabel; |
| 980 | } |
| 981 | jQuery( '#fb-options' ).show(); |
| 982 | setTimeout( function () { |
| 983 | jQuery( '#fb-option0' ).focus().select(); |
| 984 | }, 100 ); |
| 985 | break; |
| 986 | case 'text': |
| 987 | removeOptions(); |
| 988 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 989 | thisRemove + thisLabel + thisText |
| 990 | ); |
| 991 | break; |
| 992 | case 'textarea': |
| 993 | removeOptions(); |
| 994 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 995 | thisRemove + thisLabel + thisTextarea |
| 996 | ); |
| 997 | break; |
| 998 | case 'url': |
| 999 | removeOptions(); |
| 1000 | jQuery( '#fb-new-field' + thisId + ' .fb-fields' ).html( |
| 1001 | thisRemove + thisLabel + thisText |
| 1002 | ); |
| 1003 | break; |
| 1004 | } |
| 1005 | // update object |
| 1006 | fbForm.fields[ thisId ].type = thisType; |
| 1007 | } catch ( e ) { |
| 1008 | if ( debug ) { |
| 1009 | console.log( 'updateType(): ' + e ); |
| 1010 | } |
| 1011 | } |
| 1012 | } |
| 1013 | return { |
| 1014 | resizePop: function () { |
| 1015 | try { |
| 1016 | //Thickbox won't resize for some reason, we are manually doing it here |
| 1017 | var totalWidth = jQuery( 'body', window.parent.document ).width(); |
| 1018 | var totalHeight = jQuery( 'body', window.parent.document ).height(); |
| 1019 | var isIE6 = typeof document.body.style.maxHeight === 'undefined'; |
| 1020 | |
| 1021 | jQuery( '#TB_window, #TB_iframeContent', window.parent.document ).css( 'width', '768px' ); |
| 1022 | jQuery( '#TB_window', window.parent.document ).css( { |
| 1023 | left: ( totalWidth - 768 ) / 2 + 'px', |
| 1024 | top: '23px', |
| 1025 | position: 'absolute', |
| 1026 | marginLeft: '0', |
| 1027 | } ); |
| 1028 | if ( ! isIE6 ) { |
| 1029 | // take away IE6 |
| 1030 | jQuery( '#TB_window, #TB_iframeContent', window.parent.document ).css( |
| 1031 | 'height', |
| 1032 | totalHeight - 73 + 'px' |
| 1033 | ); |
| 1034 | } |
| 1035 | } catch ( e ) { |
| 1036 | if ( debug ) { |
| 1037 | console.log( 'resizePop(): ' + e ); |
| 1038 | } |
| 1039 | } |
| 1040 | }, |
| 1041 | init: function () { |
| 1042 | // Scroll to top of page |
| 1043 | window.parent.scroll( 0, 0 ); |
| 1044 | //Check for existing form data |
| 1045 | var contentSource; |
| 1046 | if ( |
| 1047 | jQuery( '#edButtonPreview', window.parent.document ).hasClass( 'active' ) || |
| 1048 | jQuery( '#wp-content-wrap', window.parent.document ).hasClass( 'tmce-active' ) |
| 1049 | ) { |
| 1050 | var win = window.dialogArguments || opener || parent || top; |
| 1051 | contentSource = win.tinyMCE.activeEditor.getContent(); |
| 1052 | } else { |
| 1053 | contentSource = jQuery( '#content', window.parent.document ).val(); |
| 1054 | } |
| 1055 | var data = { |
| 1056 | action: 'grunion_shortcode_to_json', |
| 1057 | _ajax_nonce: ajax_nonce_json, |
| 1058 | post_id: postId, |
| 1059 | content: contentSource, |
| 1060 | }; |
| 1061 | |
| 1062 | var $doc = jQuery( document ); |
| 1063 | |
| 1064 | jQuery.post( ajaxurl, data, function ( response ) { |
| 1065 | // Setup fbForm |
| 1066 | parseShortcode( jQuery.parseJSON( response ) ); |
| 1067 | // Now build out the preview form |
| 1068 | buildPreview(); |
| 1069 | } ); |
| 1070 | // actions |
| 1071 | jQuery( '.fb-add-field' ).click( function () { |
| 1072 | addField(); |
| 1073 | hideDesc(); |
| 1074 | return false; |
| 1075 | } ); |
| 1076 | jQuery( '#fb-new-label' ).keyup( function () { |
| 1077 | updateLabel(); |
| 1078 | } ); |
| 1079 | jQuery( '#fb-new-type' ).change( function () { |
| 1080 | updateType(); |
| 1081 | } ); |
| 1082 | jQuery( '#fb-new-required' ).click( function () { |
| 1083 | updateRequired(); |
| 1084 | } ); |
| 1085 | $doc.on( 'click', '.fb-remove', function () { |
| 1086 | showDesc(); |
| 1087 | deleteField( jQuery( this ) ); |
| 1088 | grabShortcode(); |
| 1089 | } ); |
| 1090 | jQuery( '#fb-preview' ).submit( function () { |
| 1091 | sendShortcodeToEditor(); |
| 1092 | return false; |
| 1093 | } ); |
| 1094 | jQuery( '#TB_overlay, #TB_closeWindowButton', window.parent.document ).mousedown( |
| 1095 | function () { |
| 1096 | if ( confirm( GrunionFB_i18n.exitConfirmMessage ) ) { |
| 1097 | hidePopup(); |
| 1098 | } |
| 1099 | } |
| 1100 | ); |
| 1101 | $doc.on( 'click', '#fb-another-option', function () { |
| 1102 | addOption(); |
| 1103 | } ); |
| 1104 | $doc.on( 'keyup', '.fb-options', function () { |
| 1105 | updateOption( jQuery( this ) ); |
| 1106 | } ); |
| 1107 | $doc.on( 'click', '.fb-remove-option', function () { |
| 1108 | removeOption( jQuery( this ).attr( 'optionid' ) ); |
| 1109 | } ); |
| 1110 | jQuery( '#tab-preview a' ).click( function () { |
| 1111 | switchTabs( 'preview' ); |
| 1112 | return false; |
| 1113 | } ); |
| 1114 | jQuery( '#fb-prev-form' ).click( function () { |
| 1115 | switchTabs( 'preview' ); |
| 1116 | return false; |
| 1117 | } ); |
| 1118 | jQuery( '#tab-settings a' ).click( function () { |
| 1119 | switchTabs(); |
| 1120 | return false; |
| 1121 | } ); |
| 1122 | jQuery( '#fb-field-my-email' ).blur( function () { |
| 1123 | updateMyEmail(); |
| 1124 | } ); |
| 1125 | jQuery( '#fb-field-subject' ).blur( function () { |
| 1126 | updateSubject(); |
| 1127 | } ); |
| 1128 | $doc.on( 'mouseenter', '.fb-form-case .fb-new-fields', function () { |
| 1129 | hideShowEditLink( 'show', jQuery( this ) ); |
| 1130 | } ); |
| 1131 | $doc.on( 'mouseleave', '.fb-form-case .fb-new-fields', function () { |
| 1132 | hideShowEditLink( 'hide' ); |
| 1133 | return false; |
| 1134 | } ); |
| 1135 | $doc.on( 'click', '.fb-edit-field', function () { |
| 1136 | editField( jQuery( this ) ); |
| 1137 | return false; |
| 1138 | } ); |
| 1139 | $doc.on( 'click', '.fb-edit-field .fb-reorder', function () { |
| 1140 | return false; |
| 1141 | } ); |
| 1142 | $doc.on( 'click', '#fb-save-field', function () { |
| 1143 | showDesc(); |
| 1144 | showAndHideMessage(); |
| 1145 | return false; |
| 1146 | } ); |
| 1147 | jQuery( '#fb-feedback' ).click( function () { |
| 1148 | var thisHref = jQuery( this ).attr( 'href' ); |
| 1149 | window.parent.location = thisHref; |
| 1150 | return false; |
| 1151 | } ); |
| 1152 | jQuery( '#sortable' ).sortable( { |
| 1153 | axis: 'y', |
| 1154 | handle: '.fb-reorder', |
| 1155 | revert: true, |
| 1156 | start: function () { |
| 1157 | jQuery( '.fb-edit-field' ).hide(); |
| 1158 | }, |
| 1159 | } ); |
| 1160 | jQuery( '#draggable' ).draggable( { |
| 1161 | axis: 'y', |
| 1162 | handle: '.fb-reorder', |
| 1163 | connectToSortable: '#sortable', |
| 1164 | helper: 'clone', |
| 1165 | revert: 'invalid', |
| 1166 | } ); |
| 1167 | }, |
| 1168 | }; |
| 1169 | } )(); |
| 1170 |