PluginProbe
GetResponse Forms by Optin Cat / trunk
GetResponse Forms by Optin Cat vtrunk
1.3.4 1.3.5 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 2.0.0 All 36 releases
getresponse / assets / admin / fca-eoi-editor.js

fca-eoi-editor.js in GetResponse Forms by Optin Cat trunk, at assets/admin/fca-eoi-editor.js

1,128 lines 40.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* jshint asi: true */
2
3 //PREVENT ANNOYING SCREEN SCROLL ON FOCUS()
4 jQuery('body').bind('focus', function(e){
5 e.preventDefault()
6 })
7
8 jQuery( document ).ready( function( $ ) {
9
10 ////////////////
11 // MEDIA UPLOAD
12 ////////////////
13
14 function attach_image_upload_handlers() {
15 var $ = jQuery
16 //ACTION WHEN CLICKING IMAGE UPLOAD
17 $('.fca_eoi_image').attr('src', $('#image_input').val() )
18 $('.fca_eoi_image_wrapper').css('cursor', 'pointer')
19 if ( $('#image_input').val() === '' ) {
20 $('.fca_eoi_image_wrapper').addClass('placeholder')
21 }
22 $('.fca_eoi_image_wrapper').unbind( 'click' )
23 //HANDLER FOR RESULTS AND META IMAGES
24 $('.fca_eoi_image_wrapper').click(function(e) {
25 var image = wp.media({
26 multiple: false
27 }).open()
28 .on('select', function(){
29 // This will return the selected image from the Media Uploader, the result is an object
30 var uploaded_image = image.state().get('selection').first()
31
32 var image_url = uploaded_image.toJSON().url
33 // Assign the url value to the input field
34
35 $('#image_input').val( image_url )
36 $('.fca_eoi_image').attr( 'src', image_url )
37 if ( image_url ) {
38 $('.fca_eoi_image_wrapper').removeClass('placeholder')
39 }
40 })
41 })
42
43
44 }
45
46 //ORDER THE LAYOUTS
47 $('.fca_eoi_layout').parent().html( $('.fca_eoi_layout').sort( function( a, b ) {
48 return $(a).data('layout-order') - $(b).data('layout-order')
49 }) )
50
51
52 // Remove FOUC, don't show metaboxes and likes until page is fully loaded
53 jQuery( '#post' ).addClass('loaded')
54 jQuery( '#poststuff' ).show()
55
56 ////////////
57 // DEFINE GLOBALS
58 ////////////
59 var post_ID = $( '#post_ID' ).val()
60 //console.log ( fcaEoiLayouts )
61
62 //MAP OF SETTINGS TO LOAD / SAVE
63 var targetSelectors = {
64 'form-background-color': '[name="fca_eoi[form_background_color]"]',
65 'form-bottom-color': '[name="fca_eoi[form_bottom_color]"]',
66 'form-border-color': '[name="fca_eoi[form_border_color]"]',
67 'form-width': '[name="fca_eoi[form_width]"]',
68 'form-text-align': '[name="fca_eoi[form_alignment]"]',
69 'headline-font-size': '[name="fca_eoi[headline_font_size]"]',
70 'headline-color': '[name="fca_eoi[headline_font_color]"]',
71 'headline-fill': '[name="fca_eoi[headline_fill_color]"]',
72 'headline-background-color': '[name="fca_eoi[headline_background_color]"]',
73 'description-font-size': '[name="fca_eoi[description_font_size]"]',
74 'description-color': '[name="fca_eoi[description_font_color]"]',
75 'name_field-font-size': '[name="fca_eoi[name_font_size]"]',
76 'name_field-color': '[name="fca_eoi[name_font_color]"]',
77 'name_field-background-color': '[name="fca_eoi[name_background_color]"]',
78 'name_field-border-color': '[name="fca_eoi[name_border_color]"]',
79 'name_field-width': '[name="fca_eoi[name_width]"]',
80 // 'name_field-text-align': '[name="fca_eoi[name_alignment]"]',
81 'email_field-font-size': '[name="fca_eoi[email_font_size]"]',
82 'email_field-color': '[name="fca_eoi[email_font_color]"]',
83 'email_field-background-color': '[name="fca_eoi[email_background_color]"]',
84 'email_field-border-color': '[name="fca_eoi[email_border_color]"]',
85 'email_field-width': '[name="fca_eoi[email_width]"]',
86 // 'email_field-text-align': '[name="fca_eoi[email_alignment]"]',
87 'button-font-size': '[name="fca_eoi[button_font_size]"]',
88 'button-color': '[name="fca_eoi[button_font_color]"]',
89 'button-hover-color': '[name="fca_eoi[button_hover_color]"]',
90 'button-background-color': '[name="fca_eoi[button_background_color]"]',
91 'button-border-bottom-color': '[name="fca_eoi[button_wrapper_background_color]"]',
92 'button-border-color': '[name="fca_eoi[button_border_color]"]',
93 'button-width': '[name="fca_eoi[button_width]"]',
94 // 'button-text-align': '[name="fca_eoi[button_alignment]"]',
95 'privacy-font-size': '[name="fca_eoi[privacy_font_size]"]',
96 'privacy-color': '[name="fca_eoi[privacy_font_color]"]',
97 'fatcatapps-color': '[name="fca_eoi[branding_font_color]"]',
98 }
99
100 var layoutSaves = []
101
102 function save_layout( layout_id ) {
103 layoutSave = {}
104
105 for ( var key in targetSelectors ) {
106 layoutSave[key] = $(targetSelectors[key]).val()
107 }
108 layoutSaves[layout_id] = layoutSave
109 }
110
111 function load_layout( layout_id ) {
112 if ( layoutSaves[layout_id] ) {
113 this_save = layoutSaves[layout_id]
114 for ( var key in targetSelectors ) {
115 if ( this_save[key] ) {
116 $(targetSelectors[key]).val( this_save[key] )
117 }
118 }
119 }
120 }
121
122
123 ////////////
124 // MAIN EDITOR EVENT HANDLERS
125 ////////////
126
127 //COLOR PICKERS
128 $('.fca-color-picker').wpColorPicker({
129 palettes: [ '#000', '#fff', '#42d0e1', '#fdd01f', '#ecf0f1', '#0ff1a3', '#ffe26e', '#99d7d9', '#e74c3c' ],
130 'change':
131 function(event, ui) {
132 //$(this).attr( 'value', $(this).val() )
133 var $target = $( $(this).data('css-target') )
134 var layout_id = $('#fca_eoi_layout_select').val()
135 var layout_name = $('.fca_eoi_layout.active').find('.fca_eoi_layout_info h3').html()
136
137 if ( $(this).attr('name').indexOf('button_background_color') != -1 ){
138 $('.fca_eoi_form_button_element').css('background-color', ui.color.toString() )
139
140 } else if ( $(this).attr('name').indexOf('button_wrapper_background_color') != -1 ) {
141 $('.fca_eoi_layout_submit_button_wrapper').css('background-color', ui.color.toString() )
142 $('[name="fca_eoi[button_wrapper_background_color]"]').val( ui.color.toString() )
143
144 } else if ( $(this).attr('name').indexOf('button_hover_color') != -1 ) {
145 hover_color_css ( ui.color.toString(), 'background-color')
146 $('[name="fca_eoi[button_hover_color]"]').val( ui.color.toString() )
147
148 } else if ( $(this).attr('name').indexOf('background') != -1 ) {
149 if ( $(this).attr('name') == 'fca_eoi[headline_background_color]' ) {
150 $target.css('background-color', ui.color.toString() )
151 //SPECIAL CASE FOR WIDGET 3
152 if ( layout_id == 'layout_3' ) {
153 $('.fca_eoi_layout_headline_copy_triangle polygon').css('fill', ui.color.toString() )
154 }
155 } else if ( $(this).attr('name') == 'fca_eoi[name_background_color]' ) {
156 $target = $( $(this).data('css-target') )
157 $target.css('background-color', ui.color.toString() )
158 $('[name="fca_eoi[email_background_color]"]').val(ui.color.toString())
159 $target = $( $('[name="fca_eoi[email_background_color]"]').data('css-target') )
160 $target.css('background-color', ui.color.toString() )
161
162 } else if ( $(this).attr('name') == 'fca_eoi[email_background_color]' ) {
163 $target = $( $(this).data('css-target') )
164 $target.css('background-color', ui.color.toString() )
165 $('[name="fca_eoi[name_background_color]"]').val(ui.color.toString())
166 $target = $( $('[name="fca_eoi[name_background_color]"]').data('css-target') )
167 $target.css('background-color', ui.color.toString() )
168 } else if ( $(this).attr('name') == 'fca_eoi[form_background_color]' ) {
169 if ( layout_name === 'Image' ){
170 $target = $('div.fca_eoi_top_wrapper')
171 }
172 $target.css('background-color', ui.color.toString() )
173 }
174
175 } else if ( $(this).attr('name').indexOf('form_bottom_color') != -1 ) {
176 $target = $('div.fca_eoi_layout_inputs_wrapper')
177 $target.css('background-color', ui.color.toString() )
178
179 } else if ( $(this).attr('name').indexOf('border') != -1 ) {
180 if ( $(this).attr('name') == 'fca_eoi[name_border_color]' ) {
181 $target = $( $(this).data('css-target') )
182 $target.css('border-color', ui.color.toString() )
183 $('[name="fca_eoi[email_border_color]"]').val(ui.color.toString())
184 $target = $( $('[name="fca_eoi[email_border_color]"]').data('css-target') )
185 $target.css('border-color', ui.color.toString() )
186
187 } else if ( $(this).attr('name') == 'fca_eoi[email_border_color]' ) {
188 $target = $( $(this).data('css-target') )
189 $target.css('border-color', ui.color.toString() )
190 $('[name="fca_eoi[name_border_color]"]').val(ui.color.toString())
191 $target = $( $('[name="fca_eoi[name_border_color]"]').data('css-target') )
192 $target.css('border-color', ui.color.toString() )
193 } else {
194 $target.css('border-color', ui.color.toString() )
195 }
196
197 } else {
198 if ( $(this).attr('name') == 'fca_eoi[name_font_color]' ) {
199 $target = $( $(this).data('css-target') )
200 $target.css('color', ui.color.toString() )
201 $('[name="fca_eoi[email_font_color]"]').val(ui.color.toString())
202 $target = $( $('[name="fca_eoi[email_font_color]"]').data('css-target') )
203 $target.css('color', ui.color.toString() )
204 placeholder_color_css ( ui.color.toString() )
205
206 } else if ( $(this).attr('name') == 'fca_eoi[email_font_color]' ) {
207 $target = $( $(this).data('css-target') )
208 $target.css('color', ui.color.toString() )
209 $('[name="fca_eoi[name_font_color]"]').val(ui.color.toString())
210 $target = $( $('[name="fca_eoi[name_font_color]"]').data('css-target') )
211 $target.css('color', ui.color.toString() )
212 placeholder_color_css ( ui.color.toString() )
213 } else {
214 $target.css('color', ui.color.toString() )
215 }
216 }
217 }
218 })
219
220 $('.fca-color-picker').change( function() {
221 var $target = $( $(this).data('css-target') )
222 var layout_id = $('#fca_eoi_layout_select').val()
223 var layout_name = $('.fca_eoi_layout.active').find('.fca_eoi_layout_info h3').html()
224 var special_layouts = ["Flat","Padded Image","Image","Wide Image","Content Upgrade","Content Upgrade - Image", "Content Upgrade - Wide Image"]
225
226 if ( $(this).attr('name').indexOf('button_background_color') != -1 ){
227 $('.fca_eoi_form_button_element').css('background-color', $(this).val() )
228
229 } else if ( $(this).attr('name').indexOf('button_hover_color') != -1 ) {
230 hover_color_css ( $(this).val(), 'background-color')
231 $('[name="fca_eoi[button_hover_color]"]').val( $(this).val() )
232
233 } else if ( $(this).attr('name').indexOf('button_wrapper_background_color') != -1 ) {
234 $('.fca_eoi_layout_submit_button_wrapper').css('background-color', $(this).val() )
235 $('[name="fca_eoi[button_wrapper_background_color]"]').val( $(this).val() )
236
237 } else if ( $(this).attr('name').indexOf('form_bottom_color') != -1 ) {
238 if ( special_layouts.includes(layout_name) ) {
239 $('div.fca_eoi_layout_inputs_wrapper').css('background-color', $(this).val() )
240 $('[name="fca_eoi[form_bottom_color]"]').val( $(this).val() )
241 } else {
242 $('div.fca_eoi_layout_inputs_wrapper').css('background-color', 'unset' )
243 $('[name="fca_eoi[form_bottom_color]"]').val( 'unset' )
244 }
245
246 } else if ( $(this).attr('name').indexOf('background') != -1 ) {
247 if ( $(this).attr('name') == 'fca_eoi[headline_background_color]' ) {
248 var value = $(this).val()
249 $target.css('background-color', value )
250 //SPECIAL CASE FOR WIDGET 3
251 if ( layout_id == 'layout_3' ) {
252 $('.fca_eoi_layout_headline_copy_triangle polygon').css('fill', value )
253 }
254 } else if ( $(this).attr('name') === 'fca_eoi[name_background_color]' ) {
255 var value = $(this).val()
256 $target.css('background-color', value )
257 } else if ( $(this).attr('name') === 'fca_eoi[email_background_color]' ) {
258 var value = $(this).val()
259 $target.css('background-color', value )
260 } else if ( $(this).attr('name') === 'fca_eoi[form_background_color]' ) {
261 if ( layout_name === 'Image' ){
262 $('div.fca_eoi_top_wrapper').css('background-color', $(this).val() + ' !important' )
263 } else {
264 var value = $(this).val()
265 $target.css('background-color', value )
266 }
267 }
268 } else if ( $(this).attr('name').indexOf('border') != -1 ) {
269 $target.css('border-color', $(this).val() )
270 } else if ( $(this).attr('name').indexOf('name_font_color') != -1 || $(this).attr('name').indexOf('email_font_color') != -1 ){
271 $target.css('color', $(this).val() )
272 placeholder_color_css ( $(this).val() )
273 } else {
274 $target.css('color', $(this).val() )
275 }
276
277 })
278
279 //WIDTH SELECT PICKERS
280 $('.fca_eoi_width_input').on('change input', function() {
281 var $target = $( $(this).data('cssTarget') )
282 var units = $(this).next().val()
283 if ( units === '%' && $(this).val() > 100 ) {
284 $(this).val(100)
285 }
286 $target.css('max-width', $(this).val() + units )
287 })
288
289 $('.fca_eoi_width_units_select').change( function() {
290 $(this).prev().change()
291 })
292
293 //ALIGNMENT SELECT
294 $('.fca-eoi-align-button').click(function(){
295 var $target = $( $(this).siblings('.fca_eoi_alignment_input').data('cssTarget') )
296 $(this).siblings('.fca-eoi-align-button').removeClass('fca-alignment-selected')
297 $(this).addClass('fca-alignment-selected')
298 $(this).siblings('.fca_eoi_alignment_input').val( $(this).data('value') )
299 $target.css('text-align', $(this).data('value') )
300 })
301
302 //FONTS SIZE PICKERS
303 $('.fca-font-size-picker').change( function() {
304 if ( $(this).attr('name') == 'fca_eoi[name_font_size]' ) {
305 $target = $( $(this).data('css-target') )
306 $target.css('font-size', $(this).val() )
307 $('[name="fca_eoi[email_font_size]"]').val($(this).val())
308 $target = $( $('[name="fca_eoi[email_font_size]"]').data('css-target') )
309 $target.css('font-size', $(this).val() )
310
311 } else if ( $(this).attr('name') == 'fca_eoi[email_font_size]' ) {
312 $target = $( $(this).data('css-target') )
313 $target.css('font-size', $(this).val() )
314 $('[name="fca_eoi[name_font_size]"]').val($(this).val())
315 $target = $( $('[name="fca_eoi[name_font_size]"]').data('css-target') )
316 $target.css('font-size', $(this).val() )
317 } else {
318 $target = $( $(this).data('css-target') )
319 $target.css('font-size', $(this).val() )
320 }
321 })
322
323 //CHANGE LAYOUT BUTTON CLICK
324 $('#fca_eoi_layout_select_button').click(function() {
325
326 var layout_id = $('#fca_eoi_layout_select').val()
327 save_layout ( layout_id )
328 // Go back to the layout select tab
329 $( '.postbox' ).hide()
330 $( '#fca_eoi_meta_box_setup' ).show()
331
332 if ( layout_id.indexOf('lightbox') !== -1 ) {
333 $( '#layouts_types_tabs li').eq(0).click()
334 } else if ( layout_id.indexOf('postbox') !== -1 ) {
335 $( '#layouts_types_tabs li').eq(1).click()
336 } else if ( layout_id.indexOf('banner') !== -1 ) {
337 $( '#layouts_types_tabs li').eq(3).click()
338 } else if ( layout_id.indexOf('overlay') !== -1 ) {
339 $( '#layouts_types_tabs li').eq(4).click()
340 } else {
341 $( '#layouts_types_tabs li').eq(2).click()
342 }
343 })
344
345 var max_character_count = 16
346 var hidden_icon = '<span class="dashicons dashicons-hidden"></span>'
347
348 //BUTTON COPY KEYUP HANDLERS
349 $('[name="fca_eoi[headline_copy]"]').keyup(function() {
350 $('#fca_eoi_preview_headline_copy').html( $(this).val())
351 $('#accordion-info-headline').html( trim_str( $(this).val(), max_character_count ) )
352 })
353 //TEXT EDITOR TAB
354 $('[name="fca_eoi[description_copy]"]').keyup(function() {
355 $('.fca_eoi_layout_description_copy_wrapper div').html( $(this).val() )
356 $('#accordion-info-description').html( trim_str( $(this).val(), max_character_count ) )
357 })
358
359 $('[name="fca_eoi[name_placeholder]"]').keyup(function() {
360 $('.fca_eoi_layout_name_field_inner').children().first().attr('placeholder', $(this).val())
361 $('#accordion-info-name_field').html( trim_str( $(this).val(), max_character_count ) )
362 })
363 $('[name="fca_eoi[email_placeholder]"]').keyup(function() {
364 $('.fca_eoi_layout_email_field_inner').children().first().attr('placeholder', $(this).val())
365 $('#accordion-info-email_field').html( trim_str( $(this).val(), max_character_count ) )
366 })
367 $('[name="fca_eoi[button_copy]"]').keyup(function() {
368 $('.fca_eoi_form_button_element').val( $(this).val())
369 $('#accordion-info-button').html( trim_str( $(this).val(), max_character_count ) )
370 })
371 $('[name="fca_eoi[privacy_copy]"]').keyup(function() {
372 $('.fca_eoi_layout_privacy_copy_wrapper').children().first().html( $(this).val())
373 $('#accordion-info-after_button_area').html( trim_str( $(this).val(), max_character_count ) )
374 })
375
376 //BRANDING TOGGLE BUTTON
377 $('[name="fca_eoi[show_fatcatapps_link]"]').change(function() {
378 $('.fca_eoi_layout_fatcatapps_link_wrapper').toggle(this.checked)
379 if ( !this.checked ) {
380 $('#accordion-info-branding').html( hidden_icon )
381 } else {
382 $('#accordion-info-branding').html( '' )
383 }
384 })
385
386 //NAME FIELD TOGGLE BUTTON
387 $('[name="fca_eoi[show_name_field]"]').change(function() {
388 $('.fca_eoi_layout_name_field_wrapper').toggle(this.checked)
389 var layout_id = $('#fca_eoi_layout_select').val()
390
391 if ( this.checked ) {
392 $('#fca_eoi_name_field').show()
393 $('[name="fca_eoi[name_placeholder]"]').keyup()
394 }
395 else {
396 $('#fca_eoi_name_field').hide()
397 }
398 })
399
400 //HEADLINE FIELD TOGGLE BUTTON
401 $('[name="fca_eoi[show_headline_field]"]').change(function() {
402 $('.fca_eoi_layout_headline_copy_wrapper').toggle(this.checked)
403 if ( !this.checked ) {
404 $('#accordion-info-headline').html( hidden_icon )
405 } else {
406 $('[name="fca_eoi[headline_copy]"]').keyup()
407 }
408
409 })
410
411 //DESCRIPTION FIELD TOGGLE BUTTON
412 $('[name="fca_eoi[show_description_field]"]').change(function() {
413 $('.fca_eoi_layout_description_copy_wrapper').toggle(this.checked)
414 if ( !this.checked ) {
415 $('#accordion-info-description').html( hidden_icon )
416 } else {
417 $('[name="fca_eoi[description_copy]"]').keyup()
418 }
419 })
420
421 //PRIVACY / AFTER-BUTTON FIELD TOGGLE BUTTON
422 $('[name="fca_eoi[show_privacy_field]"]').change(function() {
423 $('.fca_eoi_layout_privacy_copy_wrapper').toggle(this.checked)
424 if ( !this.checked ) {
425 $('#accordion-info-after_button_area').html( hidden_icon )
426 } else {
427 $('[name="fca_eoi[privacy_copy]"]').keyup()
428 }
429 })
430
431 //SHOW CLOSE ICON TOGGLE BUTTON
432 $('[name="fca_eoi[show_close]"]').change(function() {
433 $('.fca_eoi_banner_close_btn').toggle(this.checked)
434 })
435
436 //LAYOUT POSITION TOGGLE BUTTON
437 $('[name="fca_eoi[toggle_overlay_position]"]').change(function() {
438 var layout_id = $( '#fca_eoi_layout_select' ).val()
439 if ( layout_id.indexOf('banner') !== -1 ) {
440 if ( this.checked ) {
441 $('#fca_eoi_preview_form').css('margin-top', 170 )
442 } else {
443 $('#fca_eoi_preview_form').css('margin-top', -20)
444 }
445 }
446
447 if ( layout_id.indexOf('overlay') !== -1 ) {
448 if ( this.checked ) {
449 $('#fca_eoi_preview_form').css('margin-left', 5 )
450 $('#fca_eoi_preview_form').css('margin-right', 'auto' )
451 } else {
452 $('#fca_eoi_preview_form').css('margin-right', 5 )
453 $('#fca_eoi_preview_form').css('margin-left', 'auto' )
454 }
455
456 }
457 $('[name="fca_eoi[offset]"]').change()
458 })
459
460 //OFFSET
461 $('[name="fca_eoi[offset]"]').on( 'input change', function() {
462 var layout_id = $( '#fca_eoi_layout_select' ).val()
463 var value = parseInt ( $(this).val() )
464 if ( layout_id.indexOf('banner') !== -1 ) {
465 if ( $('[name="fca_eoi[toggle_overlay_position]"]').prop('checked') ) {
466 $('#fca_eoi_offset_p').find('.control-title').html('Margin Bottom')
467 $('#fca_eoi_preview_form').css('margin-top', 170 - value )
468 $('#fca_eoi_push_page_p').find('.control-title').html('Push Page Up')
469
470 } else {
471 $('#fca_eoi_preview_form').css('margin-top', value - 20 )
472 $('#fca_eoi_offset_p').find('.control-title').html('Margin Top')
473 $('#fca_eoi_push_page_p').find('.control-title').html('Push Page Down')
474 }
475 }
476 if ( layout_id.indexOf('overlay') !== -1 ) {
477 if ( $('[name="fca_eoi[toggle_overlay_position]"]').prop('checked') ) {
478 $('#fca_eoi_preview_form').css('margin-left', value )
479 $('#fca_eoi_offset_p').find('.control-title').html('Margin Left')
480 } else {
481 $('#fca_eoi_preview_form').css('margin-right', value )
482 $('#fca_eoi_offset_p').find('.control-title').html('Margin Right')
483 }
484
485 }
486 })
487
488 //////////////////
489 // LAYOUT STUFF
490 //////////////////
491
492 //LOADS A LAYOUT OBJECT INTO THE EDITOR FIELDS
493 function update_layout ( currentLayout, rebuild ) {
494 console.log ("Updating layout...")
495 //console.log ( currentLayout )
496
497 $( '#fca_eoi_layout_revert_button' ).show()
498
499 //ADD NEW HTML
500 $('#fca-preview-style').remove()
501 $('#fca_eoi_preview_form_container').remove()
502 $('#fca_eoi_preview').append(currentLayout.html)
503
504 $( '#accordion-info-layout' ).html( $('.fca_eoi_layout.active').find('.fca_eoi_layout_info h3').html() )
505
506 var editables = currentLayout.editables
507 var target, value, $selector = ''
508
509 //CLEAR EXISTING TARGETS
510 for (var key in targetSelectors ) {
511 var css_hidden_input = targetSelectors[key].replace(']"]', '_selector]"]')
512 $(css_hidden_input).val('')
513 }
514
515 //SETS DATA CSS-TARGETS & HIDDEN CSS TARGET INPUT INPUT AND LOADS INPUTS
516 for (var field in editables ) {
517
518 for ( var cssSelector in editables[field] ) {
519
520 for ( var attribute in editables[field][cssSelector] ) {
521
522 target = field + '-' + attribute
523 $selector = $(targetSelectors[target])
524 value = editables[field][cssSelector][attribute][1]
525
526 if ( target.indexOf('font-size') !== -1 ) {
527 //Need something different for font size inputs
528 rebuild ? $selector.children().filter( function() {
529 return $( this ).val() == value
530 }).prop('selected', true) : ''
531 $selector.data('css-target', cssSelector)
532
533 } else if ( target.indexOf('width') !== -1 ) {
534 if ( rebuild ) {
535 value.indexOf('px') > 0 ? $selector.next().val('px') : $selector.next().val('%')
536 $selector.val( parseInt(value) )
537 }
538 $selector.data('css-target', cssSelector)
539
540 } else {
541 rebuild ? $selector.val(value) : ''
542 $selector.data('css-target', cssSelector)
543 }
544 //Update hidden selector input with target
545 var targetString = targetSelectors[target]
546 if ( targetString ) {
547 var css_hidden_input = targetString.replace(']"]', '_selector]"]')
548 $(css_hidden_input).val(cssSelector)
549 } else {
550 console.log("can't find target: " + target)
551 }
552 }
553 }
554 }
555
556 //LOAD SAVE IF APPLICABLE
557 load_layout ( $( '#fca_eoi_layout_select' ).val() )
558
559 //REFRESH CUSTOMIZATION PICKERS
560 $('.fca-color-picker').change()
561
562 $('.fca-font-size-picker').change()
563
564 $('.fca_eoi_width_units_select').change()
565
566 load_default_texts( $( '#fca_eoi_layout_select' ).val() )
567
568 set_form_defaults( $( '#fca_eoi_layout_select' ).val() )
569
570
571 //TRIGGER INPUTS
572 $('[name="fca_eoi[email_placeholder]"], [name="fca_eoi[button_copy]"]').keyup()
573 $('[name="fca_eoi[show_name_field]"], [name="fca_eoi[show_headline_field]"], [name="fca_eoi[show_description_field]"], [name="fca_eoi[show_privacy_field]"], [name="fca_eoi[toggle_overlay_position]"], [name="fca_eoi[show_close]"] ').change()
574
575 //VARIOUS RESETS
576 hide_unused_inputs( $( '#fca_eoi_layout_select' ).val() )
577 set_publication()
578 attach_image_upload_handlers()
579
580 //OVERRIDE BANNER CLOSE BUTTON CLICK
581 $('.fca_eoi_banner_close_btn, .fca_eoi_scrollbox_close_btn').unbind('click').click(function(e){ $(this.parentNode).show() } )
582
583 }
584
585 var setInitialDefault = false
586 function set_form_defaults( layout_id ) {
587
588 if ( layout_id.indexOf('banner') !== -1 || layout_id.indexOf('overlay') !== -1) {
589 $( '[name="fca_eoi[show_privacy_field]"]' ).attr('checked', false )
590 $( '#fca_eoi_fieldset_privacy' ).hide()
591 $( '#fca_eoi_overlay_position_p' ).find('.switch-label').attr('data-on', 'Left').attr('data-off', 'Right')
592 $( '#fca_eoi_overlay_position_p' ).show()
593 $( '#fca_eoi_offset_p' ).show()
594
595 } else {
596 $( '#fca_eoi_fieldset_privacy' ).show()
597 $( '#fca_eoi_overlay_position_p' ).hide()
598 $( '#fca_eoi_offset_p' ).hide()
599 }
600
601 if ( layout_id.indexOf('overlay') !== -1 ) {
602 $('#fca_eoi_preview_form').css('margin-top', 111 )
603 } else {
604 $('#fca_eoi_preview_form').css('margin-top', 0 )
605 }
606
607 if ( layout_id.indexOf('banner') !== -1 ) {
608 $( '#fca_eoi_close_button_p' ).show()
609 $( '#fca_eoi_overlay_position_p' ).find('.switch-label').attr('data-on', 'Bot.').attr('data-off', 'Top')
610 } else {
611 $(' #fca_eoi_preview_form' ).css( 'overflow-wrap', 'break-word' )
612 $( '#fca_eoi_close_button_p' ).hide()
613 }
614 if ( location.search.indexOf('action=edit') === -1 && layout_id.indexOf('lightbox') !== -1 && !setInitialDefault ) {
615 setInitialDefault = true
616 $('[name="fca_eoi[publish_lightbox][devices]"]').val('desktop')
617 }
618
619 }
620
621 function hide_unused_inputs( layout_id ) {
622
623 //HIDE FATCAT APPS LINK FOR PREMIUM
624 if ( $('[name="fca_eoi[show_fatcatapps_link]"]').length === 0 ) {
625 $('.fca_eoi_layout_fatcatapps_link_wrapper').hide()
626 } else {
627 $('[name="fca_eoi[show_fatcatapps_link]"]').change()
628 }
629
630 //HIDE THE ANIMATIONS UNLESS THE LIGHTBOX/POPUP LAYOUT TYPE IS SELECTED
631 if ( layout_id.indexOf('lightbox') !== -1 || layout_id.indexOf('banner') !== -1 || layout_id.indexOf('overlay') !== -1) {
632 $( '.eoi-custom-animation-form' ).show()
633 } else {
634 //if there are no others, hide the whole box fca_eoi_meta_box_powerups
635 var children = $( '#fca_eoi_meta_box_powerups' ).children(".inside").children()
636 $( '#fca_eoi_show_animation_checkbox_label' ).attr('checked', false)
637 if (children.length == 1 && $(children[0]).hasClass('eoi-custom-animation-form') ) {
638 $( '#fca_eoi_meta_box_powerups' ).hide()
639 } else {
640 $( '.eoi-custom-animation-form' ).hide()
641 }
642 }
643
644 //HIDE ACCORDITION INPUTS IF THE FORM DOESN'T HAVE THAT SETTING
645 for ( var key in targetSelectors ) {
646 target = targetSelectors[key]
647 var css_hidden_input = target.replace(']"]', '_selector]"]')
648 if ( key.indexOf('name_field') !== -1 ) {
649 $(target).closest('p').hide()
650 } else if ( $(css_hidden_input).val() !== '' ) {
651 if ( $(target).hasClass('wp-color-picker') || $(target).hasClass('fca_eoi_width_input') ) {
652 $(target).closest('p').show()
653 } else {
654 $(target).show()
655 }
656 } else {
657 if ( $(target).hasClass('wp-color-picker') || $(target).hasClass('fca_eoi_width_input') ) {
658 $(target).closest('p').hide()
659 } else {
660 $(target).hide()
661 }
662 }
663 }
664
665 if ( layout_id.indexOf('banner') !== -1 ) {
666 $( '#fca_eoi_fieldset_description' ).hide()
667 $( '#fca_eoi_push_page_p' ).show()
668 } else {
669 $( '#fca_eoi_fieldset_description' ).show()
670 $( '#fca_eoi_push_page_p' ).hide()
671 }
672
673 }
674
675 $( '#fca_eoi_layout_revert_button' ).click( function( e ) {
676 var old_layout_id = $('#fca_eoi_layout_select').val()
677 $( '[data-layout-id="' + old_layout_id + '"]' ).click()
678 })
679
680 // Switch layout when screenshot clicked
681 $( '.fca_eoi_layout' ).click( function( e ) {
682
683 if ( $(this).hasClass('layout-disabled') ) {
684 window.open( $(this).find('.upgrade-link').attr('href'), '_blank');
685 return false
686 }
687
688 // Determine the layout that was clicked
689 var old_layout_id = $('#fca_eoi_layout_select').val()
690 var layout_id = $( this ).data( 'layout-id' )
691
692 // Mark active
693 $( '.fca_eoi_layout' ).removeClass( 'active' )
694 $( this ).addClass( 'active' )
695
696 // Update hidden input value for new layout
697 $( '#fca_eoi_layout_select' ).val( layout_id )
698
699 //REBUILD LAYOUT, UNLESS ITS THE SAME ONE, JUST GO BACK
700 if ( old_layout_id !== layout_id ) {
701 update_layout( fcaEoiLayouts[layout_id], true )
702 }
703
704 // Go back to the build tab
705 $( '.postbox' ).show()
706 $( '#fca_eoi_meta_box_setup' ).hide()
707 $( '#fca_eoi_meta_box_build, #fca_eoi_meta_box_provider, #fca_eoi_meta_box_thanks, #fca_eoi_meta_box_publish' ).show()
708 $(window).scrollTop(0) //GO BACK TO TOP
709
710 })
711
712 function load_default_texts( layout_id ) {
713 //LAYOUTS WITH ALTERNATE TEXT
714 var content_upgrade = [ 'lightbox_17', 'lightbox_21', 'lightbox_22', 'postbox_17', 'postbox_21', 'postbox_22', 'layout_17', 'layout_22' ]
715 var headline_text = 'Free Email Updates'
716
717 if ( content_upgrade.indexOf( layout_id ) !== -1 ) {
718 headline_text = 'Almost done: complete this form and click the button to gain instant access.'
719 }
720 if ( $('[name="fca_eoi[headline_copy]"]').val() === '' ) {
721 $('[name="fca_eoi[headline_copy]"]').val( headline_text )
722 }
723 if ( $('[name="fca_eoi[description_copy]"]').val() === '' ) {
724 $('[name="fca_eoi[description_copy]"]').val('Get the latest content first.')
725 }
726 if ( $('[name="fca_eoi[name_placeholder]"]').val() === '' ) {
727 $('[name="fca_eoi[name_placeholder]"]').val('First Name')
728 }
729 if ( $('[name="fca_eoi[email_placeholder]"]').val() === '' ) {
730 $('[name="fca_eoi[email_placeholder]"]').val('Email')
731 }
732 if ( $('[name="fca_eoi[button_copy]"]').val() === '' ) {
733 $('[name="fca_eoi[button_copy]"]').val('Join Now')
734 }
735 if ( $('[name="fca_eoi[privacy_copy]"]').val() === '' ) {
736 $('[name="fca_eoi[privacy_copy]"]').val('We respect your privacy.')
737 }
738 }
739
740 //ACCORDION CLICK HANDLER
741 $( '.accordion-section-title' ).click(function() {
742 accordionSwitch( $( this ) )
743 var $parent = $(this).closest( '[id^="fca_eoi_fieldset_"]' )
744 var field_id = $parent.attr('id')
745
746 $( '.fca_eoi_highlighted', '#fca_eoi_preview' ).removeClass( 'fca_eoi_highlighted' )
747 // If nothing else was highlighted, highlight the whole form
748 if ( $( '.fca_eoi_highlighted' ).length === 0 ) {
749 $( '#fca_eoi_preview_form' ).addClass( 'fca_eoi_highlighted' )
750 }
751 })
752
753 // Expand working fieldset
754 var expand_fieldset = function ( fieldset_id ) {
755 if ( fieldset_id === 'name_field' ) {
756 $( '#fca_eoi_fieldset_email_field.accordion-section:not(.open) .accordion-section-title').click()
757 } else {
758 $( '#fca_eoi_fieldset_' + fieldset_id + '.accordion-section:not(.open) .accordion-section-title').click()
759 }
760 $('.wp-editor-area:visible').focus()
761 $( '#fca_eoi_fieldset_' + fieldset_id ).find('.fca_eoi_text_input').focus()
762 }
763
764 if ( $('.fca_eoi_custom_css_textbox').length > 0 ) {
765 wp.codeEditor.initialize( $( '.fca_eoi_custom_css_textbox' ) )
766 }
767
768 $( '#fca_eoi_preview' ).click( function( event ) {
769 if ( isNaN(event.clientX) ) {
770 event.clientX = 0
771 }
772 if ( isNaN(event.clientY) ) {
773 event.clientY = 0
774 }
775 var $element = $( document.elementFromPoint( event.clientX, event.clientY ) ).closest( '[data-fca-eoi-fieldset-id]' )
776 if ( $element.length > 0 ) {
777 expand_fieldset( $element.data( 'fca-eoi-fieldset-id' ) )
778 } else {
779 expand_fieldset( 'form' )
780 }
781 })
782
783 // Highlight current preview element
784 $( '#fca_eoi_settings .accordion-section' ).each( function() {
785
786 $(this).click( function() {
787 $( '.fca_eoi_highlighted', '#fca_eoi_preview' ).removeClass( 'fca_eoi_highlighted' )
788 var $fieldset = $( this )
789 var $fieldset_id = $fieldset.attr( 'id' ).replace( 'fca_eoi_fieldset_', '' )
790 var $element = $( '[data-fca-eoi-fieldset-id=' + $fieldset_id + ']', '#fca_eoi_preview' )
791 if ( $fieldset_id === 'email_field' ){
792 var $element2 = $( '[data-fca-eoi-fieldset-id=name_field]', '#fca_eoi_preview' )
793 }
794
795 // Highlight element or closest block level element
796 if( $element.is( 'p, div, h1, h2, h3, h4, h5, h6' ) ) {
797 $element.addClass( 'fca_eoi_highlighted' )
798 if ( $element2 ){
799 $element2.addClass( 'fca_eoi_highlighted' )
800 }
801 } else {
802 $element.closest( 'p, div, h1, h2, h3, h4, h5, h6' ).addClass( 'fca_eoi_highlighted' )
803 }
804 // If nothing else was highlighted, highlight the whole form
805 if ( $( '.fca_eoi_highlighted' ).length === 0 ) {
806 $( '#fca_eoi_preview_form' ).addClass( 'fca_eoi_highlighted' )
807 }
808 })
809 })
810
811 /////////////////
812 // PROVIDERS
813 /////////////////
814
815 // Show only the selected provider
816 $( '[name="fca_eoi[provider]"]' ).change( function() {
817 var provider_id = $( this ).val()
818 $( '[id^=fca_eoi_fieldset_form_][id$=_integration]' ).slideUp( 'fast' )
819 if ( provider_id ) {
820 $( '#fca_eoi_fieldset_form_' + provider_id + '_integration' ).slideDown( 'fast' )
821 }
822 }).change()
823
824 //////////////////
825 // PUBLICATION METABOX
826 //////////////////
827
828 function set_publication() {
829 $('#fca_eoi_publish_widget, #fca_eoi_publish_postbox, #fca_eoi_publish_lightbox').hide()
830 var layout_id = $('#fca_eoi_layout_select').val()
831
832 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).eq(0).closest('p').show()
833 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).eq(1).closest('p').show()
834
835 if ( layout_id.indexOf('postbox') !== -1 ) {
836 $('#fca_eoi_publish_postbox').show()
837 } else if ( layout_id.indexOf('lightbox') !== -1 ) {
838 $('#fca_eoi_publish_lightbox').show()
839 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).eq(0).closest('p').show()
840 } else if ( layout_id.indexOf('banner') !== -1 || layout_id.indexOf('overlay') !== -1 ) {
841 $('#fca_eoi_publish_lightbox').show()
842 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).eq(0).closest('p').hide()
843 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).eq(1).closest('p').hide()
844 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).eq(1).prop( 'checked', true )
845 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).eq(1).trigger('change')
846 } else {
847 $('#fca_eoi_publish_widget').show()
848 }
849 }
850
851 // Show/hide popup publication modes
852 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).on( 'click change', function() {
853 var $this = $( this )
854 var mode = $this.val()
855 var $mode = $( '#fca_eoi_publish_lightbox_mode_' + mode )
856 $mode.removeClass( 'hidden' )
857 $( '[id^=fca_eoi_publish_lightbox_mode_]' ).hide( 'fast' )
858 if ( $this.prop( 'checked' ) ) {
859 $mode.show( 'fast' )
860 }
861 })
862
863 if ( $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).length === 1 ) {
864 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).click().hide()
865 } else if ( $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).filter(':checked').length > 0 ) {
866 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).filter(':checked').click()
867 } else {
868 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).eq(1).click()
869 }
870
871 $( 'input[name="fca_eoi[publish_lightbox_mode]"]' ).unbind('click')
872
873 // Update popup link HTML code
874 $( 'input[name="fca_eoi[lightbox_cta_text]"]' ).change( function() {
875 var link = '<button data-optin-cat="{{post_ID}}">{{text}}</button>'
876 $( 'input[name="fca_eoi[lightbox_cta_link]"]' ).val( link.replace( '{{post_ID}}', post_ID ).replace( '{{text}}', $( this ).val() ) )
877 }).change()
878
879 //////////////////
880 // SAVE BUTTON
881 //////////////////
882
883 // Change buttons texts
884 $('#publish').val('Save')
885
886 // Override saving throbber text
887 $( '#publish' ).click(function(){
888 postL10n.publish = 'Saving'
889 postL10n.update= 'Saving'
890 })
891
892 // Duplicate the Save button and add to the button of the page
893 $( '#submitdiv' ).clone( true ).appendTo( '#normal-sortables' )
894
895 //FIX AN ISSUE WITH EMAIL FIELD NEEDING VALIDATION ON FORM SAVING
896 $('input[name="save"]').click(function(){
897 $('.fca_eoi_form_input_element').val('')
898 })
899
900 //////////////////
901 // THANK YOU MODE
902 //////////////////
903
904 // Show/hide Thank you page modes
905 $( 'input[name="fca_eoi[thankyou_page_mode]"]' ).on( 'click change', function() {
906 if ( !this.checked ) {
907 $('#fca_eoi_thankyou_ajax_msg').show( 'fast' )
908 $('#fca_eoi_thankyou_redirect').hide()
909 $('#fca_eoi_thank_you_text_color').show( 'fast' )
910 $('#fca_eoi_thank_you_bg_color').show( 'fast' )
911
912 } else {
913 $('#fca_eoi_thankyou_ajax_msg').hide()
914 $('#fca_eoi_thank_you_text_color').hide()
915 $('#fca_eoi_thank_you_bg_color').hide()
916 $('#fca_eoi_thankyou_redirect').show( 'fast' )
917 }
918 }).change()
919
920
921 //REDIRECT MODE TOGGLE
922 $( '[name="fca_eoi[redirect_page_mode]"]' ).on( 'change', function() {
923 if ( $(this).val() === 'page' ) {
924 $( '#fca_eoi_redirect_url_span' ).hide()
925 $( '#fca_eoi_redirect_page_span' ).show()
926 } else {
927 $( '#fca_eoi_redirect_page_span' ).hide()
928 $( '#fca_eoi_redirect_url_span' ).show()
929 }
930 }).change()
931
932 //////////////////
933 // ANIMATIONS
934 //////////////////
935
936 // Show/hide animations checkbox
937 if (document.getElementById("fca_eoi_show_animation_checkbox")) {
938 if (!($('#fca_eoi_show_animation_checkbox')[0].checked)) {
939 $( '#fca_eoi_animations_div' ).hide()
940 }
941 }
942
943 // Add toggle to animations checkbox
944 $('#fca_eoi_show_animation_checkbox').click(function () {
945 $("#fca_eoi_animations_div").toggle('fast')
946 })
947
948 //Display change text when you pick a new animation
949 $( '#fca_eoi_animations' ).select2().on("select2-open", function() {
950 $( "#fca_eoi_animations_choice_text" ).removeClass()
951 })
952
953 $( '#fca_eoi_animations' ).select2().on("select2-close", function() {
954 if (this.value != 'None') {
955 $( "#fca_eoi_animations_choice_text" ).addClass( 'animated ' + this.value )
956 $( "#fca_eoi_animations_choice_text" ).text( "Solid choice! You've selected a great entrance effect.")
957
958 }else{
959 $( "#fca_eoi_animations_choice_text" ).text('')
960 }
961 })
962
963 ///////////////
964 // TAB NAVIGATION
965 ///////////////
966
967 // Use tabs in the main metabox
968 $( '#layouts_types_tabs li' ).click( function( e ) {
969
970 $( '#layouts_types_tabs li.active' ).removeClass( 'active' )
971
972 $( this ).addClass( 'active' ).blur()
973
974 $( '.fca_eoi_layout' ).hide()
975
976 var target = $( this ).data( 'target' )
977 $('[data-layout-type="' + target + '"]').show()
978
979 })
980
981 ////////////
982 // RANDOM STUFF
983 ////////////
984
985 //TOOLTIPS
986 $('.fca_eoi_tooltip').tooltipster({
987 "trigger": "hover",
988 "side": "right",
989 "arrow": false,
990 "theme": ['tooltipster-borderless', 'tooltipster-optin-cat-admin']
991 })
992
993 function hover_color_css ( colorStr ) {
994
995 var css = '.fca_eoi_layout_submit_button_wrapper input:hover, .fca_eoi_layout_submit_button_wrapper:hover { background-color:' + colorStr + '!important}'
996
997 $('.fca_eoi_css_hover_shim' ).remove()
998
999 var div = $('<div />', {
1000 html: '<style>' + css + '</style>'
1001 }).appendTo("body").addClass('fca_eoi_css_hover_shim' )
1002
1003 }
1004
1005 function placeholder_color_css ( colorStr ) {
1006 var css = '.fca_eoi_form_input_element::-webkit-input-placeholder {opacity: 0.6; color:' + colorStr + '}' +
1007 '.fca_eoi_form_input_element::-moz-placeholder {opacity: 0.6; color:' + colorStr + '}' +
1008 '.fca_eoi_form_input_element:-ms-input-placeholder {opacity: 0.6; color:' + colorStr + '}' +
1009 '.fca_eoi_form_input_element:-moz-placeholder {opacity: 0.6; color:' + colorStr + '}'
1010
1011 $('.fca_eoi_css_placeholder_shim').remove()
1012
1013 var div = $('<div />', {
1014 html: '<style>' + css + '</style>'
1015 }).appendTo("body").addClass('fca_eoi_css_placeholder_shim')
1016
1017 }
1018
1019 function trim_str ( string, maxLength ) {
1020
1021 if ( string.trim().length > maxLength ) {
1022 return string.trim().substring(0,maxLength) + '..'
1023 } else {
1024 return string.trim()
1025 }
1026
1027 }
1028
1029 function ColorLuminance(hex, lum) {
1030 if ( typeof(hex) != 'string' || hex === '' || isNaN(parseFloat(lum)) ) {
1031 return false;
1032 }
1033
1034 // validate hex string
1035 hex = String(hex).replace(/[^0-9a-f]/gi, '');
1036 if (hex.length < 6) {
1037 hex = hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];
1038 }
1039 lum = lum || 0;
1040
1041 // convert to decimal and change luminosity
1042 var rgb = "#", c, i;
1043 for (i = 0; i < 3; i++) {
1044 c = parseInt(hex.substr(i*2,2), 16);
1045 c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16);
1046 rgb += ("00"+c).substr(c.length);
1047 }
1048
1049 return rgb;
1050 }
1051
1052 $( document ).on( 'submit', '#post', function () {
1053 $("#post").attr("enctype", "application/x-www-form-urlencoded")
1054 $("#post").attr("encoding", "application/x-www-form-urlencoded")
1055 $( window ).unbind( 'beforeunload' )
1056 })
1057
1058 // Apply select2
1059 $( 'select.select2' ).select2()
1060
1061 // Disable enter doing accidential save
1062 $( document ).on( 'keypress', ':input:not(textarea)', function( e ) {
1063 if (e.keyCode == 13) {
1064 e.preventDefault()
1065 }
1066 })
1067 // Disable submit of the preview form
1068 $( document ).on( 'click', '#fca_eoi_preview input[type=submit]', function( e ) {
1069 e.preventDefault()
1070 })
1071
1072 // Autoselect
1073 $(".autoselect").bind( 'click focus mouseenter', function(){ $( this ).select() }).mouseup( function(e){ e.preventDefault } )
1074
1075 // SET STARTING STATE
1076 set_publication()
1077
1078 if ( $('#fca_eoi_layout_select').hasClass('fca-new-layout') ) {
1079 $('#fca_eoi_layout_select_button').click()
1080 $('#fca_eoi_layout_select').removeClass('fca-new-layout')
1081 } else {
1082 //BUILD LAYOUT
1083 var layout_id = $('#fca_eoi_layout_select').val()
1084 //GIVE LAYOUT "ACTIVE" CLASS
1085 $( '[data-layout-id="' + layout_id + '"]' ).addClass( 'active' )
1086 update_layout(fcaEoiLayouts[layout_id], false)
1087 $( '#fca_eoi_meta_box_setup' ).hide()
1088 $( '#fca_eoi_meta_box_build' ).show()
1089 }
1090
1091 function accordionSwitch ( el ) {
1092 var section = el.closest( '.accordion-section' ),
1093 container = section.closest( '.accordion-container' ),
1094 siblings = container.find( '.open' ),
1095 siblingsToggleControl = siblings.find( '[aria-expanded]' ).first(),
1096 content = section.find( '.accordion-section-content' );
1097
1098 // This section has no content and cannot be expanded.
1099 if ( section.hasClass( 'cannot-expand' ) ) {
1100 return;
1101 }
1102
1103 // Add a class to the container to let us know something is happening inside.
1104 // This helps in cases such as hiding a scrollbar while animations are executing.
1105 container.addClass( 'opening' );
1106
1107 if ( section.hasClass( 'open' ) ) {
1108 section.toggleClass( 'open' );
1109 content.toggle( true ).slideToggle( 150 );
1110 } else {
1111 siblingsToggleControl.attr( 'aria-expanded', 'false' );
1112 siblings.removeClass( 'open' );
1113 siblings.find( '.accordion-section-content' ).show().slideUp( 150 );
1114 content.toggle( false ).slideToggle( 150 );
1115 section.toggleClass( 'open' );
1116 }
1117
1118 // We have to wait for the animations to finish.
1119 setTimeout(function(){
1120 container.removeClass( 'opening' );
1121 }, 150);
1122
1123 // If there's an element with an aria-expanded attribute, assume it's a toggle control and toggle the aria-expanded value.
1124 if ( el ) {
1125 el.attr( 'aria-expanded', String( el.attr( 'aria-expanded' ) === 'false' ) );
1126 }
1127 }
1128 })