| 1 |
jQuery(document).ready(function($) { |
| 2 |
window.photonicManagePanels = function(tabName) { |
| 3 |
var panels = $('.photonic-options-panel'); |
| 4 |
var all_hidden = true; |
| 5 |
panels.each(function() { |
| 6 |
var current = $(this); |
| 7 |
if (current.attr('id') === tabName) { |
| 8 |
current.show(); |
| 9 |
all_hidden = false; |
| 10 |
} |
| 11 |
else { |
| 12 |
current.hide(); |
| 13 |
} |
| 14 |
}); |
| 15 |
if (all_hidden) { |
| 16 |
panels.eq(0).show(); |
| 17 |
} |
| 18 |
}; |
| 19 |
|
| 20 |
window.photonicManageTabs = function(tabName) { |
| 21 |
var tabs = $('.photonic-section-tabs a'); |
| 22 |
var no_active = true; |
| 23 |
$(tabs).each(function() { |
| 24 |
var current = $(this); |
| 25 |
if (current.attr('href').substr(1) === tabName) { |
| 26 |
current.addClass('active'); |
| 27 |
no_active = false; |
| 28 |
} |
| 29 |
else { |
| 30 |
current.removeClass('active'); |
| 31 |
} |
| 32 |
}); |
| 33 |
if (no_active) { |
| 34 |
tabs.eq(0).addClass('active'); |
| 35 |
} |
| 36 |
}; |
| 37 |
|
| 38 |
window.photonicSetBorder = function(thisId, specificElement, specificColor) { |
| 39 |
var edges = ['top', 'right', 'bottom', 'left']; |
| 40 |
var border = ''; |
| 41 |
for (var x in edges) { |
| 42 |
var edge = edges[x]; |
| 43 |
var thisName = thisId + '-' + edge; |
| 44 |
border += edge + '::'; |
| 45 |
var colorField = "#" + thisName + "-color"; |
| 46 |
if (specificElement !== undefined && colorField === '#' + specificElement) { |
| 47 |
border += 'color=' + specificColor + ';'; |
| 48 |
} |
| 49 |
else { |
| 50 |
border += 'color=' + ($(colorField).val() === '' ? $(colorField).data('photonicDefaultColor') : $(colorField).val()) + ';'; |
| 51 |
} |
| 52 |
border += 'colortype=' + $("input[name=" + thisName + "-colortype]:checked").val() + ';' + |
| 53 |
'style=' + $("#" + thisName + "-style").val() + ';' + |
| 54 |
'border-width=' + $("#" + thisName + "-border-width").val() + ';' + |
| 55 |
'border-width-type=' + $("#" + thisName + "-border-width-type").val() + ';'; |
| 56 |
border += '||'; |
| 57 |
} |
| 58 |
$('#' + thisId).val(border); |
| 59 |
}; |
| 60 |
|
| 61 |
window.photonicSetBackground = function(thisId, specificElement, specificColor) { |
| 62 |
var thisName = thisId; |
| 63 |
var background = ''; |
| 64 |
var colorField = "#" + thisName + "-bgcolor"; |
| 65 |
|
| 66 |
if (specificElement !== undefined && colorField === '#' + specificElement) { |
| 67 |
background += 'color=' + specificColor + ';'; |
| 68 |
} |
| 69 |
else { |
| 70 |
background += 'color=' + ($(colorField).val() === '' ? $(colorField).data('photonicDefaultColor') : $(colorField).val()) + ';'; |
| 71 |
} |
| 72 |
|
| 73 |
background += 'colortype=' + $("input[name=" + thisName + "-colortype]:checked").val() + ';' + |
| 74 |
'image=' + $("#" + thisName + "-bgimg").val() + ';' + |
| 75 |
'position=' + $("#" + thisName + "-position").val() + ';' + |
| 76 |
'repeat=' + $("#" + thisName + "-repeat").val() + ';' + |
| 77 |
'trans=' + $("#" + thisName + "-trans").val() + ';'; |
| 78 |
|
| 79 |
$('#' + thisName).val(background); |
| 80 |
}; |
| 81 |
|
| 82 |
window.photonicSetBorderOrBackgroundColor = function(element, color) { |
| 83 |
var thisId = $(element).attr('id'); |
| 84 |
var container = $(element).parents('.photonic-border-options'); |
| 85 |
if (container.length > 0) {// Border |
| 86 |
photonicSetBorder(thisId.substring(0, thisId.indexOf('-')), thisId, color); |
| 87 |
} |
| 88 |
else { |
| 89 |
container = $(element).parents('.photonic-background-options'); |
| 90 |
if (container.length > 0) { // Background |
| 91 |
photonicSetBackground(thisId.substring(0, thisId.indexOf('-')), thisId, color); |
| 92 |
} |
| 93 |
} |
| 94 |
}; |
| 95 |
|
| 96 |
photonicManagePanels(Photonic_Options_JS.category); |
| 97 |
photonicManageTabs(Photonic_Options_JS.category); |
| 98 |
|
| 99 |
$('.photonic-section-tabs a').on('click', function(e) { |
| 100 |
e.preventDefault(); |
| 101 |
var tab = $(this); |
| 102 |
photonicManagePanels(tab.attr('href').substr(1)); |
| 103 |
photonicManageTabs(tab.attr('href').substr(1)); |
| 104 |
}); |
| 105 |
|
| 106 |
$(".photonic-options-form :input[type='submit']").click(function() { |
| 107 |
//This is needed, otherwise the event handler cannot figure out which button was clicked. |
| 108 |
photonic_submit_button = $(this); |
| 109 |
}); |
| 110 |
|
| 111 |
$('.photonic-options-form').submit(function(event) { |
| 112 |
var field = photonic_submit_button; |
| 113 |
var value = field.val(); |
| 114 |
|
| 115 |
if (value.substring(0, 5) === 'Reset') { |
| 116 |
if (!confirm("This will reset your configurations to the original values!!! Are you sure you want to continue? This is not reversible!")) { |
| 117 |
return false; |
| 118 |
} |
| 119 |
} |
| 120 |
else if (value.substring(0, 6) === 'Delete') { |
| 121 |
if (!confirm("This will delete all your Photonic configuration options!!! Are you sure you want to continue? This is not reversible!")) { |
| 122 |
return false; |
| 123 |
} |
| 124 |
} |
| 125 |
}); |
| 126 |
|
| 127 |
$('.photonic-options-form .color').wpColorPicker({ |
| 128 |
change: function(event, ui) { |
| 129 |
var input = $(event.target); |
| 130 |
photonicSetBorderOrBackgroundColor($(input[0]), ui.color.toString()); |
| 131 |
}, |
| 132 |
clear: function(event) { |
| 133 |
var input = $($(event.target).siblings('.wp-color-picker')[0]); |
| 134 |
photonicSetBorderOrBackgroundColor($(input[0]), $(input[0]).data('photonicDefaultColor')); |
| 135 |
} |
| 136 |
}); |
| 137 |
|
| 138 |
$('.photonic-border-options input[type="radio"], .photonic-border-options input[type="text"], .photonic-border-options select').change(function(event) { |
| 139 |
var thisId = event.currentTarget.name; |
| 140 |
photonicSetBorder(thisId.substring(0, thisId.indexOf('-'))); |
| 141 |
}); |
| 142 |
|
| 143 |
$('.photonic-background-options input[type="radio"], .photonic-background-options input[type="text"], .photonic-background-options select').change(function(event) { |
| 144 |
var thisName = event.currentTarget.name; |
| 145 |
photonicSetBackground(thisName.substring(0, thisName.indexOf('-'))); |
| 146 |
}); |
| 147 |
|
| 148 |
$('.photonic-padding-options input[type="text"], .photonic-padding-options select').change(function(event) { |
| 149 |
var thisId = event.currentTarget.id; |
| 150 |
thisId = thisId.substring(0, thisId.indexOf('-')); |
| 151 |
var edges = ['top', 'right', 'bottom', 'left']; |
| 152 |
var padding = ''; |
| 153 |
for (var x in edges) { |
| 154 |
var edge = edges[x]; |
| 155 |
var thisName = thisId + '-' + edge; |
| 156 |
padding += edge + '::'; |
| 157 |
padding += 'padding=' + $("#" + thisName + "-padding").val() + ';' + |
| 158 |
'padding-type=' + $("#" + thisName + "-padding-type").val() + ';'; |
| 159 |
padding += '||'; |
| 160 |
} |
| 161 |
$('#' + thisId).val(padding); |
| 162 |
}); |
| 163 |
|
| 164 |
$('div.photonic-checklist input[type="checkbox"]').change(function() { |
| 165 |
var $clicked = $(this); |
| 166 |
var hidden = $clicked.attr('data-photonic-selection-for'); |
| 167 |
var allChecks = $('[data-photonic-selection-for="' + hidden + '"]:checked'); |
| 168 |
var selection = []; |
| 169 |
allChecks.each(function(i, v) { |
| 170 |
selection[selection.length] = $(v).attr('data-photonic-value'); |
| 171 |
}); |
| 172 |
selection = selection.join(); |
| 173 |
$('input[name="photonic_options[' + hidden + ']"]').val(selection); |
| 174 |
}); |
| 175 |
|
| 176 |
$('button.photonic-notice-dismiss').click(function(e){ |
| 177 |
e.preventDefault(); |
| 178 |
var $clicked = $(this); |
| 179 |
var $notice = $clicked.parents('.notice'); |
| 180 |
var dismissible = $clicked.attr('data-photonic-dismissible'); |
| 181 |
var args = { action: 'photonic_dismiss_warning', dismissible: dismissible }; |
| 182 |
$.post(ajaxurl, args, function(data) { |
| 183 |
var response = JSON.parse(data); |
| 184 |
response = Object.keys(response); |
| 185 |
if (response.indexOf(dismissible) > -1) { |
| 186 |
$notice.fadeOut(); |
| 187 |
} |
| 188 |
}); |
| 189 |
}); |
| 190 |
}); |
| 191 |
|