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

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