PluginProbe
GetResponse Forms by Optin Cat / 2.0.2
GetResponse Forms by Optin Cat v2.0.2
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 2.0.2, at assets/admin/fca-eoi-editor.js

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