| 1 |
jQuery(document).ready(function($) { |
| 2 |
const PhotonicOptions = () => { |
| 3 |
let photonic_submit_button; |
| 4 |
const displayOptionScreen = tabName => { |
| 5 |
const panels = $('.photonic-options-panel'); |
| 6 |
const tabs = $('.photonic-section-tabs a'); |
| 7 |
|
| 8 |
panels.hide(); |
| 9 |
tabs.removeClass('active'); |
| 10 |
|
| 11 |
let currentPanel = $('.photonic-options-panel[id="' + tabName + '"]'); |
| 12 |
let currentTab = $('.photonic-section-tabs a[href="#' + tabName + '"]'); |
| 13 |
|
| 14 |
if (currentPanel.length === 0) { |
| 15 |
currentPanel = panels.eq(0); |
| 16 |
currentTab = tabs.eq(0); |
| 17 |
} |
| 18 |
|
| 19 |
currentPanel.fadeIn(); |
| 20 |
currentTab.addClass('active'); |
| 21 |
}; |
| 22 |
|
| 23 |
const setBackground = (thisId, specificElement, specificColor) => { |
| 24 |
var background = ''; |
| 25 |
var colorField = "#" + thisId + "-bgcolor"; |
| 26 |
|
| 27 |
if (specificElement !== undefined && colorField === '#' + specificElement) { |
| 28 |
background += 'color=' + specificColor + ';'; |
| 29 |
} |
| 30 |
else { |
| 31 |
background += 'color=' + ($(colorField).val() === '' ? $(colorField).data('photonicDefaultColor') : $(colorField).val()) + ';'; |
| 32 |
} |
| 33 |
|
| 34 |
background += 'colortype=' + $("input[name=" + thisId + "-colortype]:checked").val() + ';' + |
| 35 |
'image=' + $("#" + thisId + "-bgimg").val() + ';' + |
| 36 |
'position=' + $("#" + thisId + "-position").val() + ';' + |
| 37 |
'repeat=' + $("#" + thisId + "-repeat").val() + ';' + |
| 38 |
'trans=' + $("#" + thisId + "-trans").val() + ';'; |
| 39 |
|
| 40 |
$('#' + thisId).val(background); |
| 41 |
}; |
| 42 |
|
| 43 |
const setBorderOrBackgroundColor = (element, color) => { |
| 44 |
let thisId = $(element).attr('id'); |
| 45 |
let container = $(element).parents('.photonic-background-options'); |
| 46 |
if (container.length > 0) { // Background |
| 47 |
setBackground(thisId.substring(0, thisId.indexOf('-')), thisId, color); |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
displayOptionScreen(Photonic_Options_JS.category); |
| 52 |
|
| 53 |
$('.photonic-section-tabs a').on('click', function(e) { |
| 54 |
e.preventDefault(); |
| 55 |
const tab = $(this); |
| 56 |
displayOptionScreen(tab.attr('href').substr(1)); |
| 57 |
}); |
| 58 |
|
| 59 |
$(".photonic-options-form :input[type='submit']").click(function() { |
| 60 |
// This is needed, otherwise the event handler cannot figure out which button was clicked. |
| 61 |
photonic_submit_button = $(this); |
| 62 |
}); |
| 63 |
|
| 64 |
$('.photonic-options-form').submit(function(event) { |
| 65 |
var value = photonic_submit_button.val(); |
| 66 |
|
| 67 |
if (value.substring(0, 5) === 'Reset') { |
| 68 |
if (!confirm("This will reset your configurations to the original values!!! Are you sure you want to continue? This is not reversible!")) { |
| 69 |
return false; |
| 70 |
} |
| 71 |
} |
| 72 |
else if (value.substring(0, 6) === 'Delete') { |
| 73 |
if (!confirm("This will delete all your Photonic configuration options!!! Are you sure you want to continue? This is not reversible!")) { |
| 74 |
return false; |
| 75 |
} |
| 76 |
} |
| 77 |
}); |
| 78 |
|
| 79 |
$('.photonic-options-form .color').wpColorPicker({ |
| 80 |
change: function(event, ui) { |
| 81 |
const input = $(event.target); |
| 82 |
setBorderOrBackgroundColor($(input[0]), ui.color.toString()); |
| 83 |
}, |
| 84 |
clear: function(event) { |
| 85 |
const input = $($(event.target).siblings('.wp-color-picker')[0]); |
| 86 |
setBorderOrBackgroundColor($(input[0]), $(input[0]).data('photonicDefaultColor')); |
| 87 |
} |
| 88 |
}); |
| 89 |
|
| 90 |
$('.photonic-background-options input[type="radio"], .photonic-background-options input[type="text"], .photonic-background-options select').change(function(event) { |
| 91 |
const thisName = event.currentTarget.name; |
| 92 |
setBackground(thisName.substring(0, thisName.indexOf('-'))); |
| 93 |
}); |
| 94 |
|
| 95 |
$('div.photonic-checklist input[type="checkbox"]').change(function() { |
| 96 |
var $clicked = $(this); |
| 97 |
var hidden = $clicked.attr('data-photonic-selection-for'); |
| 98 |
var allChecks = $('[data-photonic-selection-for="' + hidden + '"]:checked'); |
| 99 |
var selection = []; |
| 100 |
allChecks.each(function(i, v) { |
| 101 |
selection[selection.length] = $(v).attr('data-photonic-value'); |
| 102 |
}); |
| 103 |
selection = selection.join(); |
| 104 |
$('input[name="photonic_options[' + hidden + ']"]').val(selection); |
| 105 |
}); |
| 106 |
|
| 107 |
$('button.photonic-notice-dismiss').click(function(e){ |
| 108 |
e.preventDefault(); |
| 109 |
var $clicked = $(this); |
| 110 |
var $notice = $clicked.parents('.notice'); |
| 111 |
var dismissible = $clicked.attr('data-photonic-dismissible'); |
| 112 |
var args = { action: 'photonic_dismiss_warning', dismissible: dismissible, _ajax_nonce: $clicked.data('photonicNonce') }; |
| 113 |
$.post(ajaxurl, args, function(data) { |
| 114 |
var response = JSON.parse(data); |
| 115 |
response = Object.keys(response); |
| 116 |
if (response.indexOf(dismissible) > -1) { |
| 117 |
$notice.fadeOut(); |
| 118 |
} |
| 119 |
}); |
| 120 |
}); |
| 121 |
}; |
| 122 |
|
| 123 |
PhotonicOptions(); |
| 124 |
}); |
| 125 |
|