| 1 |
/* jshint asi: true */ |
| 2 |
jQuery( document ).ready( function( $ ) { |
| 3 |
//////////// |
| 4 |
// DEFINE GLOBALS |
| 5 |
//////////// |
| 6 |
var post_ID = $( '#post_ID' ).val() |
| 7 |
console.log (layouts) |
| 8 |
|
| 9 |
var layoutSaves = [] |
| 10 |
|
| 11 |
var targetSelectors = { |
| 12 |
'form-background-color': '[name="fca_eoi[form_background_color]"]', |
| 13 |
'form-border-color': '[name="fca_eoi[form_border_color]"]', |
| 14 |
'headline-font-size': '[name="fca_eoi[headline_font_size]"]', |
| 15 |
'headline-color': '[name="fca_eoi[headline_font_color]"]', |
| 16 |
'headline-background-color': '[name="fca_eoi[headline_background_color]"]', |
| 17 |
'description-font-size': '[name="fca_eoi[description_font_size]"]', |
| 18 |
'description-color': '[name="fca_eoi[description_font_color]"]', |
| 19 |
'name_field-font-size': '[name="fca_eoi[name_font_size]"]', |
| 20 |
'name_field-color': '[name="fca_eoi[name_font_color]"]', |
| 21 |
'name_field-background-color': '[name="fca_eoi[name_background_color]"]', |
| 22 |
'name_field-border-color': '[name="fca_eoi[name_border_color]"]', |
| 23 |
'email_field-font-size': '[name="fca_eoi[email_font_size]"]', |
| 24 |
'email_field-color': '[name="fca_eoi[email_font_color]"]', |
| 25 |
'email_field-background-color': '[name="fca_eoi[email_background_color]"]', |
| 26 |
'email_field-border-color': '[name="fca_eoi[email_border_color]"]', |
| 27 |
'button-font-size': '[name="fca_eoi[button_font_size]"]', |
| 28 |
'button-color': '[name="fca_eoi[button_font_color]"]', |
| 29 |
'button-background-color': '[name="fca_eoi[button_background_color]"]', |
| 30 |
'privacy-font-size': '[name="fca_eoi[privacy_font_size]"]', |
| 31 |
'privacy-color': '[name="fca_eoi[privacy_font_color]"]', |
| 32 |
'fatcatapps-color': '[name="fca_eoi[branding_font_color]"]', |
| 33 |
} |
| 34 |
|
| 35 |
function save_layout( layout_id ) { |
| 36 |
layoutSave = {} |
| 37 |
|
| 38 |
for (var key in targetSelectors ) { |
| 39 |
layoutSave[key] = $(targetSelectors[key]).val() |
| 40 |
} |
| 41 |
layoutSaves[layout_id] = layoutSave |
| 42 |
} |
| 43 |
|
| 44 |
function load_layout( layout_id ) { |
| 45 |
if ( layoutSaves[layout_id] ) { |
| 46 |
this_save = layoutSaves[layout_id] |
| 47 |
for (var key in targetSelectors ) { |
| 48 |
if ( this_save[key] ) { |
| 49 |
$(targetSelectors[key]).val( this_save[key] ) |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
//////////// |
| 57 |
// MAIN EDITOR EVENT HANDLERS |
| 58 |
//////////// |
| 59 |
|
| 60 |
//COLOR PICKERS |
| 61 |
$('.fca-color-picker').wpColorPicker({ |
| 62 |
'change': |
| 63 |
function(event, ui) { |
| 64 |
//$(this).attr( 'value', $(this).val() ) |
| 65 |
var $target = $( $(this).data('css-target') ) |
| 66 |
var layout_id = $('#fca_eoi_layout_select').val() |
| 67 |
|
| 68 |
if ( $(this).attr('name').indexOf('button_background_color') != -1 ){ |
| 69 |
//SPECIAL CASE FOR BUTTONS (AND SPECIAL CASE FOR LAYOUT 1) |
| 70 |
if ( layout_id == 'lightbox_1' || layout_id == 'postbox_1' || layout_id == 'layout_1' ) { |
| 71 |
newColor = ColorLuminance(ui.color.toString(), -0.1) |
| 72 |
} else { |
| 73 |
newColor = ColorLuminance(ui.color.toString(), -0.3) |
| 74 |
} |
| 75 |
|
| 76 |
$('.fca_eoi_layout_submit_button_wrapper').css('background-color', newColor ) |
| 77 |
$('[name="fca_eoi[button_wrapper_background_color]"]').val( newColor ) |
| 78 |
$('.fca_eoi_form_button_element').css('background-color', ui.color.toString() ) |
| 79 |
|
| 80 |
} else if ( $(this).attr('name').indexOf('background') != -1 ) { |
| 81 |
if ( layout_id == 'layout_3' && $(this).attr('name') == 'fca_eoi[headline_background_color]' ) { |
| 82 |
//SPECIAL CASE FOR WIDGET 3 |
| 83 |
$target.css('background-color', ui.color.toString() ) |
| 84 |
$('.fca_eoi_layout_headline_copy_triangle polygon').css('fill', ui.color.toString() ) |
| 85 |
} else if ( $(this).attr('name') == 'fca_eoi[name_background_color]' ) { |
| 86 |
$target = $( $(this).data('css-target') ) |
| 87 |
$target.css('background-color', ui.color.toString() ) |
| 88 |
$('[name="fca_eoi[email_background_color]"]').val(ui.color.toString()) |
| 89 |
$target = $( $('[name="fca_eoi[email_background_color]"]').data('css-target') ) |
| 90 |
$target.css('background-color', ui.color.toString() ) |
| 91 |
|
| 92 |
} else if ( $(this).attr('name') == 'fca_eoi[email_background_color]' ) { |
| 93 |
$target = $( $(this).data('css-target') ) |
| 94 |
$target.css('background-color', ui.color.toString() ) |
| 95 |
$('[name="fca_eoi[name_background_color]"]').val(ui.color.toString()) |
| 96 |
$target = $( $('[name="fca_eoi[name_background_color]"]').data('css-target') ) |
| 97 |
$target.css('background-color', ui.color.toString() ) |
| 98 |
} else { |
| 99 |
$target.css('background-color', ui.color.toString() ) |
| 100 |
} |
| 101 |
} else if ( $(this).attr('name').indexOf('border') != -1 ) { |
| 102 |
if ( $(this).attr('name') == 'fca_eoi[name_border_color]' ) { |
| 103 |
$target = $( $(this).data('css-target') ) |
| 104 |
$target.css('border-color', ui.color.toString() ) |
| 105 |
$('[name="fca_eoi[email_border_color]"]').val(ui.color.toString()) |
| 106 |
$target = $( $('[name="fca_eoi[email_border_color]"]').data('css-target') ) |
| 107 |
$target.css('border-color', ui.color.toString() ) |
| 108 |
|
| 109 |
} else if ( $(this).attr('name') == 'fca_eoi[email_border_color]' ) { |
| 110 |
$target = $( $(this).data('css-target') ) |
| 111 |
$target.css('border-color', ui.color.toString() ) |
| 112 |
$('[name="fca_eoi[name_border_color]"]').val(ui.color.toString()) |
| 113 |
$target = $( $('[name="fca_eoi[name_border_color]"]').data('css-target') ) |
| 114 |
$target.css('border-color', ui.color.toString() ) |
| 115 |
} else { |
| 116 |
$target.css('border-color', ui.color.toString() ) |
| 117 |
} |
| 118 |
|
| 119 |
} else { |
| 120 |
if ( $(this).attr('name') == 'fca_eoi[name_font_color]' ) { |
| 121 |
$target = $( $(this).data('css-target') ) |
| 122 |
$target.css('color', ui.color.toString() ) |
| 123 |
$('[name="fca_eoi[email_font_color]"]').val(ui.color.toString()) |
| 124 |
$target = $( $('[name="fca_eoi[email_font_color]"]').data('css-target') ) |
| 125 |
$target.css('color', ui.color.toString() ) |
| 126 |
|
| 127 |
} else if ( $(this).attr('name') == 'fca_eoi[email_font_color]' ) { |
| 128 |
$target = $( $(this).data('css-target') ) |
| 129 |
$target.css('color', ui.color.toString() ) |
| 130 |
$('[name="fca_eoi[name_font_color]"]').val(ui.color.toString()) |
| 131 |
$target = $( $('[name="fca_eoi[name_font_color]"]').data('css-target') ) |
| 132 |
$target.css('color', ui.color.toString() ) |
| 133 |
} else { |
| 134 |
$target.css('color', ui.color.toString() ) |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
}) |
| 139 |
|
| 140 |
|
| 141 |
$('.fca-color-picker').change( function() { |
| 142 |
var $target = $( $(this).data('css-target') ) |
| 143 |
var layout_id = $('#fca_eoi_layout_select').val() |
| 144 |
|
| 145 |
if ( $(this).attr('name').indexOf('button_background_color') != -1 ){ |
| 146 |
//SPECIAL CASE FOR BUTTONS (AND SPECIAL CASE FOR LAYOUT 1) |
| 147 |
if ( layout_id == 'lightbox_1' || layout_id == 'postbox_1' || layout_id == 'layout_1' ) { |
| 148 |
newColor = ColorLuminance($(this).val(), -0.1) |
| 149 |
} else { |
| 150 |
newColor = ColorLuminance($(this).val(), -0.3) |
| 151 |
} |
| 152 |
$('.fca_eoi_layout_submit_button_wrapper').css('background-color', newColor ) |
| 153 |
$('[name="fca_eoi[button_wrapper_background_color]"]').val( newColor ) |
| 154 |
$('.fca_eoi_form_button_element').css('background-color', $(this).val() ) |
| 155 |
|
| 156 |
} else if ( $(this).attr('name').indexOf('background') != -1 ) { |
| 157 |
if ( layout_id == 'layout_3' && $(this).attr('name') == 'fca_eoi[headline_background_color]' ) { |
| 158 |
//SPECIAL CASE FOR WIDGET 3 |
| 159 |
var value = $(this).val() |
| 160 |
$target.css('background-color', value ) |
| 161 |
$('.fca_eoi_layout_headline_copy_triangle polygon').css('fill', value ) |
| 162 |
} else { |
| 163 |
$target.css('background-color', $(this).val() ) |
| 164 |
} |
| 165 |
} else if ( $(this).attr('name').indexOf('border') != -1 ) { |
| 166 |
$target.css('border-color', $(this).val() ) |
| 167 |
} else { |
| 168 |
$target.css('color', $(this).val() ) |
| 169 |
} |
| 170 |
|
| 171 |
}) |
| 172 |
|
| 173 |
//FONTS SIZE PICKERS |
| 174 |
$('.fca-font-size-picker').change( function() { |
| 175 |
if ( $(this).attr('name') == 'fca_eoi[name_font_size]' ) { |
| 176 |
$target = $( $(this).data('css-target') ) |
| 177 |
$target.css('font-size', $(this).val() ) |
| 178 |
$('[name="fca_eoi[email_font_size]"]').val($(this).val()) |
| 179 |
$target = $( $('[name="fca_eoi[email_font_size]"]').data('css-target') ) |
| 180 |
$target.css('font-size', $(this).val() ) |
| 181 |
|
| 182 |
} else if ( $(this).attr('name') == 'fca_eoi[email_font_size]' ) { |
| 183 |
$target = $( $(this).data('css-target') ) |
| 184 |
$target.css('font-size', $(this).val() ) |
| 185 |
$('[name="fca_eoi[name_font_size]"]').val($(this).val()) |
| 186 |
$target = $( $('[name="fca_eoi[name_font_size]"]').data('css-target') ) |
| 187 |
$target.css('font-size', $(this).val() ) |
| 188 |
} else { |
| 189 |
$target = $( $(this).data('css-target') ) |
| 190 |
$target.css('font-size', $(this).val() ) |
| 191 |
} |
| 192 |
}) |
| 193 |
|
| 194 |
//CHANGE LAYOUT BUTTON CLICK |
| 195 |
$('#fca_eoi_show_setup').click(function() { |
| 196 |
|
| 197 |
hide_tooltips() |
| 198 |
|
| 199 |
var layout_id = $('#fca_eoi_layout_select').val() |
| 200 |
save_layout ( layout_id ) |
| 201 |
// Go back to the layout select tab |
| 202 |
$( '.postbox' ).hide() |
| 203 |
$( '#fca_eoi_meta_box_setup' ).show() |
| 204 |
|
| 205 |
if ( layout_id.indexOf('postbox') != -1 ) { |
| 206 |
$( '#layouts_types_tabs').find('a').eq(1).click() |
| 207 |
} else if ( layout_id.indexOf('lightbox') != -1 ) { |
| 208 |
$( '#layouts_types_tabs').find('a').first().click() |
| 209 |
} else { |
| 210 |
$( '#layouts_types_tabs').find('a').last().click() |
| 211 |
} |
| 212 |
}) |
| 213 |
|
| 214 |
//BUTTON COPY KEYUP HANDLERS |
| 215 |
$('[name="fca_eoi[headline_copy]"]').keyup(function() { |
| 216 |
$('#fca_eoi_preview_headline_copy').html( $(this).val()) |
| 217 |
}) |
| 218 |
//TEXT EDITOR TAB |
| 219 |
$('[name="fca_eoi[description_copy]"]').keyup(function() { |
| 220 |
$('.fca_eoi_layout_description_copy_wrapper div').html( $(this).val()) |
| 221 |
}) |
| 222 |
|
| 223 |
$('[name="fca_eoi[name_placeholder]"]').keyup(function() { |
| 224 |
$('.fca_eoi_layout_name_field_inner').children().first().attr('placeholder', $(this).val()) |
| 225 |
}) |
| 226 |
$('[name="fca_eoi[email_placeholder]"]').keyup(function() { |
| 227 |
$('.fca_eoi_layout_email_field_inner').children().first().attr('placeholder', $(this).val()) |
| 228 |
}) |
| 229 |
$('[name="fca_eoi[button_copy]"]').keyup(function() { |
| 230 |
$('.fca_eoi_form_button_element').val( $(this).val()) |
| 231 |
}) |
| 232 |
$('[name="fca_eoi[privacy_copy]"]').keyup(function() { |
| 233 |
$('.fca_eoi_layout_privacy_copy_wrapper').children().first().html( $(this).val()) |
| 234 |
}) |
| 235 |
|
| 236 |
//BRANDING TOGGLE BUTTON |
| 237 |
$('[name="fca_eoi[show_fatcatapps_link]"]').change(function() { |
| 238 |
$('.fca_eoi_layout_fatcatapps_link_wrapper').toggle(this.checked) |
| 239 |
}) |
| 240 |
//NAME FIELD TOGGLE BUTTON |
| 241 |
$('[name="fca_eoi[show_name_field]').change(function() { |
| 242 |
$('.fca_eoi_layout_name_field_wrapper').toggle(this.checked) |
| 243 |
var layout_id = $('#fca_eoi_layout_select').val() |
| 244 |
if ( (this.checked) && layout_id.indexOf('layout') == -1 ) { |
| 245 |
$('.fca_eoi_layout_email_field_wrapper').css('width', '49%') |
| 246 |
} else { |
| 247 |
$('.fca_eoi_layout_email_field_wrapper').css('width', '100%') |
| 248 |
} |
| 249 |
destroy_tooltips() |
| 250 |
attach_tooltips() |
| 251 |
|
| 252 |
}) |
| 253 |
|
| 254 |
////////////////// |
| 255 |
// LAYOUT STUFF |
| 256 |
////////////////// |
| 257 |
|
| 258 |
//LOADS A LAYOUT OBJECT INTO THE EDITOR FIELDS |
| 259 |
function update_layout ( currentLayout, rebuild ) { |
| 260 |
console.log ("Updating layout...") |
| 261 |
console.log ( currentLayout ) |
| 262 |
|
| 263 |
//ADD NEW HTML |
| 264 |
$('#fca-preview-style').remove() |
| 265 |
$('#fca_eoi_preview_form_container').remove() |
| 266 |
$('#fca_eoi_preview').append(currentLayout.html) |
| 267 |
|
| 268 |
var editables = currentLayout.editables |
| 269 |
var target, value, $selector = '' |
| 270 |
|
| 271 |
//CLEAR EXISTING TARGETS |
| 272 |
for (var key in targetSelectors ) { |
| 273 |
var css_hidden_input = targetSelectors[key].replace(']"]', '_selector]"]') |
| 274 |
$(css_hidden_input).val('') |
| 275 |
} |
| 276 |
|
| 277 |
for (var field in editables ) { |
| 278 |
|
| 279 |
for ( var cssSelector in editables[field] ) { |
| 280 |
|
| 281 |
for ( var attribute in editables[field][cssSelector] ) { |
| 282 |
target = field + '-' + attribute |
| 283 |
$selector = $(targetSelectors[target]) |
| 284 |
value = editables[field][cssSelector][attribute][1] |
| 285 |
|
| 286 |
if ( target.indexOf('font-size') == -1 ) { |
| 287 |
rebuild ? $selector.val(value) : '' |
| 288 |
$selector.data('css-target', cssSelector) |
| 289 |
} else { //Need something different for font size inputs |
| 290 |
rebuild ? $selector.children().filter( function() { |
| 291 |
return $( this ).val() == value |
| 292 |
}).prop('selected', true) : '' |
| 293 |
$selector.data('css-target', cssSelector) |
| 294 |
} |
| 295 |
//Update hidden selector input with target |
| 296 |
var targetString = targetSelectors[target] |
| 297 |
if ( targetString ) { |
| 298 |
css_hidden_input = targetString.replace(']"]', '_selector]"]') |
| 299 |
$(css_hidden_input).val(cssSelector) |
| 300 |
} else { |
| 301 |
console.log("can't find target: " + target) |
| 302 |
} |
| 303 |
} |
| 304 |
} |
| 305 |
} |
| 306 |
//LOAD SAVE IF APPLICABLE |
| 307 |
load_layout ( $( '#fca_eoi_layout_select' ).val() ) |
| 308 |
|
| 309 |
//REFRESH CUSTOMIZATION PICKERS |
| 310 |
$('.fca-color-picker').change() |
| 311 |
$('.fca-font-size-picker').change() |
| 312 |
$('[name="fca_eoi[show_fatcatapps_link]"]').change() |
| 313 |
$('[name="fca_eoi[show_name_field]"]').change() |
| 314 |
|
| 315 |
//TRIGGER THE TEXT INPUT KEYUP TO WRITE SAVED/DEFAULT COPY TO PREVIEWS |
| 316 |
load_default_texts() |
| 317 |
$('[name="fca_eoi[headline_copy]"], [name="fca_eoi[description_copy]"], [name="fca_eoi[name_placeholder]"], [name="fca_eoi[email_placeholder]"], [name="fca_eoi[button_copy]"], [name="fca_eoi[privacy_copy]"]').keyup() |
| 318 |
|
| 319 |
//VARIOUS RESETS |
| 320 |
hide_unused_inputs() |
| 321 |
set_publication() |
| 322 |
|
| 323 |
} |
| 324 |
|
| 325 |
function hide_unused_inputs() { |
| 326 |
|
| 327 |
for ( var key in targetSelectors ) { |
| 328 |
target = targetSelectors[key] |
| 329 |
var css_hidden_input = target.replace(']"]', '_selector]"]') |
| 330 |
|
| 331 |
if ( $(css_hidden_input).val() !== '' ) { |
| 332 |
if ( $(target).hasClass('wp-color-picker') ) { |
| 333 |
$(target).closest('p').show() |
| 334 |
} else { |
| 335 |
$(target).show() |
| 336 |
} |
| 337 |
} else { |
| 338 |
if ( $(target).hasClass('wp-color-picker') ) { |
| 339 |
$(target).closest('p').hide() |
| 340 |
} else { |
| 341 |
$(target).hide() |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
// Switch layout when screenshot clicked |
| 348 |
$( '.fca_eoi_layout' ).click( function( e ) { |
| 349 |
|
| 350 |
// Determine the layout that was clicked |
| 351 |
var old_layout_id = $('#fca_eoi_layout_select').val() |
| 352 |
var layout_id = $( this ).data( 'layout-id' ) |
| 353 |
|
| 354 |
// Mark active |
| 355 |
$( '.fca_eoi_layout' ).removeClass( 'active' ) |
| 356 |
$( this ).addClass( 'active' ) |
| 357 |
|
| 358 |
// Update hidden input value for new layout |
| 359 |
$( '#fca_eoi_layout_select' ).val( layout_id ) |
| 360 |
|
| 361 |
//REBUILD LAYOUT, UNLESS ITS THE SAME ONE, JUST GO BACK |
| 362 |
if ( old_layout_id != layout_id ) { |
| 363 |
update_layout(layouts[layout_id], true) |
| 364 |
} |
| 365 |
|
| 366 |
// Go back to the build tab |
| 367 |
$( '.postbox' ).show() |
| 368 |
$( '#fca_eoi_meta_box_setup' ).hide() |
| 369 |
$( '#fca_eoi_meta_box_build' ).show() |
| 370 |
|
| 371 |
|
| 372 |
//Hide the animations unless the lightbox/popup layout type is selected |
| 373 |
if ( layout_id.indexOf('lightbox') != -1 ) { |
| 374 |
$( '.eoi-custom-animation-form' ).show() |
| 375 |
} else { |
| 376 |
//if there are no others, hide the whole box fca_eoi_meta_box_powerups |
| 377 |
var children = $( '#fca_eoi_meta_box_powerups' ).children(".inside").children() |
| 378 |
if (children.length == 1 && $(children[0]).hasClass('eoi-custom-animation-form') ) { |
| 379 |
$('#fca_eoi_meta_box_powerups').hide() |
| 380 |
}else { |
| 381 |
$( '.eoi-custom-animation-form' ).hide() |
| 382 |
} |
| 383 |
} |
| 384 |
destroy_tooltips() |
| 385 |
attach_tooltips() |
| 386 |
|
| 387 |
}) |
| 388 |
|
| 389 |
function load_default_texts() { |
| 390 |
if ( $('[name="fca_eoi[headline_copy]"]').val() === '' ) { |
| 391 |
$('[name="fca_eoi[headline_copy]"]').val('Free Email Updates') |
| 392 |
} |
| 393 |
if ( $('[name="fca_eoi[description_copy]"]').val() === '' ) { |
| 394 |
$('[name="fca_eoi[description_copy]"]').val('Get the latest content first.') |
| 395 |
} |
| 396 |
if ( $('[name="fca_eoi[name_placeholder]"]').val() === '' ) { |
| 397 |
$('[name="fca_eoi[name_placeholder]"]').val('First Name') |
| 398 |
} |
| 399 |
if ( $('[name="fca_eoi[email_placeholder]"]').val() === '' ) { |
| 400 |
$('[name="fca_eoi[email_placeholder]"]').val('Email') |
| 401 |
} |
| 402 |
if ( $('[name="fca_eoi[button_copy]"]').val() === '' ) { |
| 403 |
$('[name="fca_eoi[button_copy]"]').val('Join Now') |
| 404 |
} |
| 405 |
if ( $('[name="fca_eoi[privacy_copy]"]').val() === '' ) { |
| 406 |
$('[name="fca_eoi[privacy_copy]"]').val('We respect your privacy.') |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
//ACCORDION CLICK HANDLER |
| 411 |
$( '.accordion-section, .accordion-section-title' ).click(function() { |
| 412 |
var $parent = $(this).closest( '[id^="fca_eoi_fieldset_"]' ) |
| 413 |
var field_id = $parent.attr('id') |
| 414 |
|
| 415 |
if ( field_id == 'fca_eoi_fieldset_error_text' && $parent.hasClass('open') ) { |
| 416 |
//error_tooltip.update() |
| 417 |
} else { |
| 418 |
//error_tooltip.hide_all() |
| 419 |
} |
| 420 |
$( '.fca_eoi_highlighted', '#fca_eoi_preview' ).removeClass( 'fca_eoi_highlighted' ) |
| 421 |
// If nothing else was highlighted, highlight the whole form |
| 422 |
if ( $( '.fca_eoi_highlighted' ).length === 0 ) { |
| 423 |
$( '#fca_eoi_preview_form' ).addClass( 'fca_eoi_highlighted' ) |
| 424 |
} |
| 425 |
}) |
| 426 |
|
| 427 |
// Expand working fieldset |
| 428 |
var expand_fieldset = function ( fieldset_id ) { |
| 429 |
$( '#fca_eoi_fieldset_' + fieldset_id + '.accordion-section:not(.open) .accordion-section-title').click() |
| 430 |
} |
| 431 |
|
| 432 |
$( '#fca_eoi_preview' ).click( function( event ) { |
| 433 |
if ( isNaN(event.clientX) ) { |
| 434 |
event.clientX = 0 |
| 435 |
} |
| 436 |
if ( isNaN(event.clientY) ) { |
| 437 |
event.clientY = 0 |
| 438 |
} |
| 439 |
var $element = $( document.elementFromPoint( event.clientX, event.clientY ) ).closest( '[data-fca-eoi-fieldset-id]' ) |
| 440 |
if ( $element.length > 0 ) { |
| 441 |
expand_fieldset( $element.data( 'fca-eoi-fieldset-id' ) ) |
| 442 |
} else { |
| 443 |
expand_fieldset( 'form' ) |
| 444 |
} |
| 445 |
}) |
| 446 |
|
| 447 |
// Highlight current preview element |
| 448 |
$( '#fca_eoi_settings .accordion-section' ).each( function() { |
| 449 |
|
| 450 |
$(this).click( function() { |
| 451 |
$( '.fca_eoi_highlighted', '#fca_eoi_preview' ).removeClass( 'fca_eoi_highlighted' ) |
| 452 |
var $fieldset = $( this ) |
| 453 |
var $fieldset_id = $fieldset.attr( 'id' ).replace( 'fca_eoi_fieldset_', '' ) |
| 454 |
var $element = $( '[data-fca-eoi-fieldset-id=' + $fieldset_id + ']', '#fca_eoi_preview' ) |
| 455 |
|
| 456 |
// Highlight element or closest block level element |
| 457 |
if( $element.is( 'p, div, h1, h2, h3, h4, h5, h6' ) ) { |
| 458 |
$element.addClass( 'fca_eoi_highlighted' ) |
| 459 |
} else { |
| 460 |
$element.closest( 'p, div, h1, h2, h3, h4, h5, h6' ).addClass( 'fca_eoi_highlighted' ) |
| 461 |
} |
| 462 |
// If nothing else was highlighted, highlight the whole form |
| 463 |
if ( $( '.fca_eoi_highlighted' ).length === 0 ) { |
| 464 |
$( '#fca_eoi_preview_form' ).addClass( 'fca_eoi_highlighted' ) |
| 465 |
} |
| 466 |
}) |
| 467 |
}) |
| 468 |
|
| 469 |
///////////////// |
| 470 |
// PROVIDERS |
| 471 |
///////////////// |
| 472 |
|
| 473 |
// Show only the selected provider |
| 474 |
$( '[name="fca_eoi[provider]"]' ).change( function() { |
| 475 |
var provider_id = $( this ).val() |
| 476 |
$( '[id^=fca_eoi_fieldset_form_][id$=_integration]' ).slideUp( 'fast' ) |
| 477 |
if ( provider_id ) { |
| 478 |
$( '#fca_eoi_fieldset_form_' + provider_id + '_integration' ).slideDown( 'fast' ) |
| 479 |
} |
| 480 |
}).change() |
| 481 |
|
| 482 |
////////////////// |
| 483 |
// PUBLICATION METABOX |
| 484 |
////////////////// |
| 485 |
|
| 486 |
function set_publication() { |
| 487 |
$('#fca_eoi_publish_widget, #fca_eoi_publish_postbox, #fca_eoi_publish_lightbox').hide() |
| 488 |
var layout_id = $('#fca_eoi_layout_select').val() |
| 489 |
if ( layout_id.indexOf('postbox') != -1 ) { |
| 490 |
$('#fca_eoi_publish_postbox').show() |
| 491 |
} else if ( layout_id.indexOf('lightbox') != -1 ) { |
| 492 |
$('#fca_eoi_publish_lightbox').show() |
| 493 |
} else { |
| 494 |
$('#fca_eoi_publish_widget').show() |
| 495 |
} |
| 496 |
} |
| 497 |
|
| 498 |
// Show/hide popup publication modes |
| 499 |
$( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).on( 'click change', function() { |
| 500 |
var $this = $( this ) |
| 501 |
var mode = $this.val() |
| 502 |
var $mode = $( '#fca_eoi_publish_lightbox_mode_' + mode ) |
| 503 |
$mode.removeClass( 'hidden' ) |
| 504 |
$( '[id^=fca_eoi_publish_lightbox_mode_]' ).hide( 'fast' ) |
| 505 |
if ( $this.prop( 'checked' ) ) { |
| 506 |
$mode.show( 'fast' ) |
| 507 |
} |
| 508 |
} ) |
| 509 |
|
| 510 |
$( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).filter(':checked').click() |
| 511 |
$( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).unbind('click') |
| 512 |
|
| 513 |
// Update popup link HTML code |
| 514 |
$( 'input[name="fca_eoi[lightbox_cta_text]"]' ).change( function() { |
| 515 |
var link = '<button data-optin-cat="{{post_ID}}">{{text}}</button>' |
| 516 |
$( 'input[name="fca_eoi[lightbox_cta_link]"]' ).val( link.replace( '{{post_ID}}', post_ID ).replace( '{{text}}', $( this ).val() ) ) |
| 517 |
}).change() |
| 518 |
|
| 519 |
////////////////// |
| 520 |
// SAVE BUTTON |
| 521 |
////////////////// |
| 522 |
|
| 523 |
// Change buttons texts |
| 524 |
$('#publish').val('Save') |
| 525 |
|
| 526 |
// Override saving throbber text |
| 527 |
$( '#publish' ).click(function(){ |
| 528 |
postL10n.publish = 'Saving' |
| 529 |
postL10n.update= 'Saving' |
| 530 |
}) |
| 531 |
|
| 532 |
// Duplicate the Save button and add to the button of the page |
| 533 |
$( '#submitdiv' ).clone( true ).appendTo( '#normal-sortables' ) |
| 534 |
|
| 535 |
// Add the Save button to each item |
| 536 |
$('.fca_eoi_layout_info').append( "<button type='button' class='button button-primary button-large fca-layout-button'>Select Layout</button>" ) |
| 537 |
|
| 538 |
//FIX AN ISSUE WITH EMAIL FIELD NEEDING VALIDATION ON FORM SAVING |
| 539 |
$('input[name="save"]').click(function(){ |
| 540 |
$('.fca_eoi_form_input_element').val('') |
| 541 |
}) |
| 542 |
|
| 543 |
////////////////// |
| 544 |
// THANK YOU MODE |
| 545 |
////////////////// |
| 546 |
|
| 547 |
// Show/hide Thank you page modes |
| 548 |
currentThanksSetting = $( 'input[name="fca_eoi[thankyou_page_mode]"]:checked' ).val() |
| 549 |
if (currentThanksSetting == 'ajax') { |
| 550 |
$('#fca_eoi_thankyou_redirect').hide() |
| 551 |
} else { |
| 552 |
$('#fca_eoi_thankyou_ajax_msg').hide() |
| 553 |
} |
| 554 |
|
| 555 |
//Turn on redirect mode as default |
| 556 |
if (currentThanksSetting === undefined) { |
| 557 |
$( 'input[name="fca_eoi[thankyou_page_mode]"]' ).first().prop("checked", true) |
| 558 |
} |
| 559 |
|
| 560 |
$( 'input[name="fca_eoi[thankyou_page_mode]"]' ).on( 'click change', function() { |
| 561 |
var $this = $( this ) |
| 562 |
var mode = $this.val() |
| 563 |
|
| 564 |
if (mode == 'ajax') { |
| 565 |
$('#fca_eoi_thankyou_redirect').hide( 'fast' ) |
| 566 |
$('#fca_eoi_thankyou_ajax_msg').show( 'fast' ) |
| 567 |
} else { |
| 568 |
$('#fca_eoi_thankyou_redirect').show( 'fast' ) |
| 569 |
$('#fca_eoi_thankyou_ajax_msg').hide( 'fast' ) |
| 570 |
} |
| 571 |
}) |
| 572 |
|
| 573 |
// Hide new page link if Thank You Page is set |
| 574 |
$( 'select', '#fca_eoi_meta_box_thanks' ).change( function() { |
| 575 |
var $this = $( this ) |
| 576 |
var $p = $( 'p', '#fca_eoi_meta_box_thanks' ).filter( ':last' ) |
| 577 |
|
| 578 |
if( $this.val() ) { |
| 579 |
$p.hide() |
| 580 |
} else { |
| 581 |
$p.show() |
| 582 |
} |
| 583 |
}).change() |
| 584 |
|
| 585 |
////////////////// |
| 586 |
// ANIMATIONS |
| 587 |
////////////////// |
| 588 |
|
| 589 |
// Show/hide animations checkbox |
| 590 |
if (document.getElementById("fca_eoi_show_animation_checkbox")) { |
| 591 |
if (!($('#fca_eoi_show_animation_checkbox')[0].checked)) { |
| 592 |
$( '#fca_eoi_animations_div' ).hide() |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
// Add toggle to animations checkbox |
| 597 |
$('#fca_eoi_show_animation_checkbox').click(function () { |
| 598 |
$("#fca_eoi_animations_div").toggle('fast') |
| 599 |
}) |
| 600 |
|
| 601 |
//Display change text when you pick a new animation |
| 602 |
$( '#fca_eoi_animations' ).select2().on("select2-open", function() { |
| 603 |
$( "#fca_eoi_animations_choice_text" ).removeClass() |
| 604 |
}) |
| 605 |
|
| 606 |
$( '#fca_eoi_animations' ).select2().on("select2-close", function() { |
| 607 |
if (this.value != 'None') { |
| 608 |
$( "#fca_eoi_animations_choice_text" ).addClass( 'animated ' + this.value ) |
| 609 |
$( "#fca_eoi_animations_choice_text" ).text( "Solid choice! You've selected a great entrance effect.") |
| 610 |
|
| 611 |
}else{ |
| 612 |
$( "#fca_eoi_animations_choice_text" ).text('') |
| 613 |
} |
| 614 |
}) |
| 615 |
|
| 616 |
/////////////// |
| 617 |
// TAB NAVIGATION |
| 618 |
/////////////// |
| 619 |
|
| 620 |
// Use tabs in the main metabox |
| 621 |
$( '.nav-tab-wrapper > a' ).click( function( e ) { |
| 622 |
var target_hash = $( this ).attr( 'href' ) |
| 623 |
|
| 624 |
e.preventDefault() |
| 625 |
$( '.nav-tab-wrapper > a' ).removeClass( 'nav-tab-active' ) |
| 626 |
$( this ).blur().addClass( 'nav-tab-active' ) |
| 627 |
|
| 628 |
$( 'div[id^=fca_eoi_meta_box_]' ).not( '#fca_eoi_meta_box_nav' ).hide() |
| 629 |
$( target_hash ).show() |
| 630 |
|
| 631 |
if( '#fca_eoi_meta_box_build' == target_hash ) { |
| 632 |
$( '#fca_eoi_meta_box_provider' ).show() |
| 633 |
$( '#fca_eoi_meta_box_publish' ).show() |
| 634 |
$( '#fca_eoi_meta_box_thanks' ).show() |
| 635 |
$( '#fca_eoi_meta_box_powerups' ).show() |
| 636 |
} |
| 637 |
}) |
| 638 |
|
| 639 |
// Use smaller tabs for layout types |
| 640 |
$( 'a[href^="#layouts_type_"]' ).click( function( e ) { |
| 641 |
var $this = $( this ) |
| 642 |
e.preventDefault() |
| 643 |
$( 'a[href^="#layouts_type_"]' ).parent().removeClass( 'tabs' ) |
| 644 |
$this.parent().addClass( 'tabs' ) |
| 645 |
$( 'div[id^="layouts_type_"]' ).hide() |
| 646 |
$( $this.attr( 'href' ) ).show() |
| 647 |
$this.blur() |
| 648 |
} ) |
| 649 |
|
| 650 |
/////////////// |
| 651 |
// TOOLTIPS |
| 652 |
/////////////// |
| 653 |
|
| 654 |
// Add default error text if it is empty |
| 655 |
if ( $( '[name="fca_eoi[error_text_field_required]"]' ).val() === '' ) { |
| 656 |
$( '[name="fca_eoi[error_text_field_required]"]' ).val("Error: This field is required.") |
| 657 |
} |
| 658 |
|
| 659 |
if ( $( '[name="fca_eoi[error_text_invalid_email]"]' ).val() === '' ) { |
| 660 |
$( '[name="fca_eoi[error_text_invalid_email]"]' ).val("Error: Please enter a valid email address. For example \"max@domain.com\".") |
| 661 |
} |
| 662 |
|
| 663 |
var name_tooltip = { |
| 664 |
'selector' : '.fca_eoi_layout_name_field_inner input', |
| 665 |
'input' : '[name="fca_eoi[error_text_field_required]"' |
| 666 |
} |
| 667 |
|
| 668 |
var email_tooltip = { |
| 669 |
'selector' : '.fca_eoi_layout_email_field_inner input', |
| 670 |
'input' : '[name="fca_eoi[error_text_invalid_email]"' |
| 671 |
} |
| 672 |
|
| 673 |
// Attach tooltips |
| 674 |
function attach_tooltips () { |
| 675 |
$( name_tooltip.selector ).attr( 'title', $( name_tooltip.input ).val() ) |
| 676 |
$( email_tooltip.selector ).attr( 'title', $( email_tooltip.input ).val() ) |
| 677 |
$( name_tooltip.selector ).tooltipster({ |
| 678 |
contentAsHTML: true, |
| 679 |
fixedWidth: ( $(name_tooltip.selector).outerWidth() * 0.8), |
| 680 |
minWidth: ( $(name_tooltip.selector).outerWidth() * 0.8), |
| 681 |
maxWidth: ( $(name_tooltip.selector).outerWidth() * 0.8), |
| 682 |
trigger: 'click' |
| 683 |
} ) |
| 684 |
$( email_tooltip.selector ).tooltipster({ |
| 685 |
contentAsHTML: true, |
| 686 |
fixedWidth: ( $(email_tooltip.selector).outerWidth() * 0.8), |
| 687 |
minWidth: ( $(email_tooltip.selector).outerWidth() * 0.8), |
| 688 |
maxWidth: ( $(email_tooltip.selector).outerWidth() * 0.8), |
| 689 |
trigger: 'click' |
| 690 |
} ) |
| 691 |
} |
| 692 |
|
| 693 |
function destroy_tooltips() { |
| 694 |
if ( $( name_tooltip.selector ).hasClass('tooltipstered') ) { |
| 695 |
$( name_tooltip.selector ).tooltipster('destroy') |
| 696 |
} |
| 697 |
if ( $( email_tooltip.selector ).hasClass('tooltipstered') ) { |
| 698 |
$( email_tooltip.selector ).tooltipster('destroy') |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
function hide_tooltips() { |
| 703 |
$( name_tooltip.selector ).tooltipster('hide') |
| 704 |
$( email_tooltip.selector ).tooltipster('hide') |
| 705 |
|
| 706 |
} |
| 707 |
|
| 708 |
function show_tooltips() { |
| 709 |
$( name_tooltip.selector+':visible' ).tooltipster('show') |
| 710 |
$( email_tooltip.selector+':visible' ).tooltipster('show') |
| 711 |
} |
| 712 |
|
| 713 |
//KEYUP HANDLERS FOR TOOLTIPS |
| 714 |
$( name_tooltip.input ).change(function(){ |
| 715 |
$( name_tooltip.selector ).tooltipster('content', $(this).val() ) |
| 716 |
}) |
| 717 |
|
| 718 |
$( email_tooltip.input ).change(function(){ |
| 719 |
$( email_tooltip.selector ).tooltipster('content', $(this).val() ) |
| 720 |
}) |
| 721 |
|
| 722 |
$('#fca_eoi_fieldset_error_text').click( show_tooltips ) |
| 723 |
|
| 724 |
//////////// |
| 725 |
// RANDOM STUFF |
| 726 |
//////////// |
| 727 |
|
| 728 |
function ColorLuminance(hex, lum) { |
| 729 |
if ( typeof(hex) != 'string' || hex === '' || isNaN(parseFloat(lum)) ) { |
| 730 |
return false; |
| 731 |
} |
| 732 |
|
| 733 |
// validate hex string |
| 734 |
hex = String(hex).replace(/[^0-9a-f]/gi, ''); |
| 735 |
if (hex.length < 6) { |
| 736 |
hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]; |
| 737 |
} |
| 738 |
lum = lum || 0; |
| 739 |
|
| 740 |
// convert to decimal and change luminosity |
| 741 |
var rgb = "#", c, i; |
| 742 |
for (i = 0; i < 3; i++) { |
| 743 |
c = parseInt(hex.substr(i*2,2), 16); |
| 744 |
c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16); |
| 745 |
rgb += ("00"+c).substr(c.length); |
| 746 |
} |
| 747 |
|
| 748 |
return rgb; |
| 749 |
} |
| 750 |
|
| 751 |
$( document ).on( 'submit', '#post', function () { |
| 752 |
$("#post").attr("enctype", "application/x-www-form-urlencoded") |
| 753 |
$("#post").attr("encoding", "application/x-www-form-urlencoded") |
| 754 |
$( window ).unbind( 'beforeunload' ) |
| 755 |
}) |
| 756 |
|
| 757 |
// Remove FOUC, don't show metaboxes and likes until page is fully loaded |
| 758 |
jQuery( '#poststuff' ).fadeTo( 1, '1' ) |
| 759 |
|
| 760 |
// Apply select2 |
| 761 |
$( 'select.select2' ).select2() |
| 762 |
|
| 763 |
// Disable enter doing accidential save |
| 764 |
$( document ).on( 'keypress', ':input:not(textarea)', function( e ) { |
| 765 |
if (e.keyCode == 13) { |
| 766 |
e.preventDefault() |
| 767 |
} |
| 768 |
}) |
| 769 |
// Disable submit of the preview form |
| 770 |
$( document ).on( 'click', '#fca_eoi_preview input[type=submit]', function( e ) { |
| 771 |
e.preventDefault() |
| 772 |
}) |
| 773 |
|
| 774 |
// Autoselect |
| 775 |
$(".autoselect").bind( 'click focus mouseenter', function() { $( this ).select() } ).mouseup( function( e ) { e.preventDefault } ) |
| 776 |
|
| 777 |
// SET STARTING STATE |
| 778 |
set_publication() |
| 779 |
if ( $('#fca_eoi_layout_select').hasClass('fca-new-layout') ) { |
| 780 |
$('#fca_eoi_show_setup').click() |
| 781 |
$('#fca_eoi_show_setup').removeClass('fca-new-layout') |
| 782 |
} else { |
| 783 |
//BUILD LAYOUT |
| 784 |
var layout_id = $('#fca_eoi_layout_select').val() |
| 785 |
update_layout(layouts[layout_id], false) |
| 786 |
$( '#fca_eoi_meta_box_setup' ).hide() |
| 787 |
$( '#fca_eoi_meta_box_build' ).show() |
| 788 |
} |
| 789 |
|
| 790 |
}) |