| 1 |
jQuery(document).ready(function($) { |
| 2 |
var wpActiveEditor; |
| 3 |
var photonicLastActiveScreen = 1; |
| 4 |
var photonicNativeWPMediaLibrary; |
| 5 |
var photonicMustPost = false; |
| 6 |
var photonicPermittedGalleries = ['wp', 'default', 'flickr', 'smugmug', 'picasa', 'google', 'zenfolio', 'instagram']; |
| 7 |
|
| 8 |
window.photonicAddTBClass = function() { |
| 9 |
var tb = $('#TB_window', window.parent.document); |
| 10 |
tb.addClass('photonic-tb'); |
| 11 |
}; |
| 12 |
photonicAddTBClass(); |
| 13 |
|
| 14 |
window.photonicGetSelectedText = function() { |
| 15 |
var $textArea = $('textarea#content', window.parent.document); |
| 16 |
var start = $textArea.prop('selectionStart'); |
| 17 |
var end = $textArea.prop('selectionEnd'); |
| 18 |
if (start !== undefined && end !== undefined) { |
| 19 |
return $textArea.val().substring(start, end); |
| 20 |
} |
| 21 |
return ''; |
| 22 |
}; |
| 23 |
|
| 24 |
window.photonicPostFlowData = function(activeScreen, nextScreen, $activeScreenElement, screenParameters, parameters) { |
| 25 |
var $waiting = $('.photonic-waiting'); |
| 26 |
$.post(Photonic_Flow_JS.ajaxurl, parameters, function(data){ |
| 27 |
console.log(data); |
| 28 |
if ($(data).hasClass('photonic-flow-error')) { |
| 29 |
$('.photonic-flow-error').remove(); |
| 30 |
$('.photonic-flow-screen[data-screen="' + activeScreen + '"]').before(data); |
| 31 |
$activeScreenElement.attr('data-submitted', ''); |
| 32 |
} |
| 33 |
else { |
| 34 |
$('.photonic-flow-error').hide(); |
| 35 |
var $forceScreen = $('<div></div>').append(data).find('input[name="force_next_screen"]'); |
| 36 |
if ($forceScreen.length > 0 && parseInt($($forceScreen[0]).val()) > -1) { |
| 37 |
nextScreen = $($forceScreen[0]).val(); |
| 38 |
} |
| 39 |
|
| 40 |
$('.photonic-flow-screen[data-screen="' + nextScreen + '"]').empty().append(data); |
| 41 |
photonicFlowLogic(nextScreen); |
| 42 |
if (nextScreen <= 3) { |
| 43 |
var existing = $('input[name="existing_selection"]').val(); |
| 44 |
var $selection = $('input[name="selected_data"]'); |
| 45 |
var $passworded = $('input[name="selection_passworded"]'); |
| 46 |
if (existing !== undefined && existing !== '') { |
| 47 |
$selection.val(existing); |
| 48 |
} |
| 49 |
else { |
| 50 |
$selection.val(''); |
| 51 |
$passworded.val(''); |
| 52 |
} |
| 53 |
} |
| 54 |
photonicLastActiveScreen = nextScreen; |
| 55 |
$activeScreenElement.attr('data-submitted', screenParameters); |
| 56 |
photonicMustPost = false; |
| 57 |
} |
| 58 |
$waiting.hide(); |
| 59 |
}); |
| 60 |
}; |
| 61 |
|
| 62 |
window.photonicInitializeWPMediaLibrary = function(activeScreen, nextScreen, $activeScreenElement, screenParameters) { |
| 63 |
if (top.wp !== undefined) { |
| 64 |
var mode = $('select[name="display_type"]').val(); |
| 65 |
if (mode === '') { |
| 66 |
alert(Photonic_Flow_JS.error_mandatory); |
| 67 |
} |
| 68 |
else { |
| 69 |
mode = mode === 'single-photo' ? 'single' : 'add'; |
| 70 |
photonicNativeWPMediaLibrary = top.wp.media({ |
| 71 |
multiple: mode, |
| 72 |
title: Photonic_Flow_JS.media_library_title, |
| 73 |
library: {type: 'image'}, |
| 74 |
button: {text: Photonic_Flow_JS.media_library_button} |
| 75 |
}); |
| 76 |
|
| 77 |
photonicNativeWPMediaLibrary.on('select', function() { |
| 78 |
var $waiting = $('.photonic-waiting'); |
| 79 |
$waiting.show(); |
| 80 |
|
| 81 |
var selection = photonicNativeWPMediaLibrary.state().get('selection'); |
| 82 |
var selected_data = ''; |
| 83 |
selection.map(function(attachment) { |
| 84 |
attachment = attachment.toJSON(); |
| 85 |
selected_data += attachment.id + ','; |
| 86 |
}); |
| 87 |
selected_data = selected_data.replace(/^,+|,+$/g, ''); |
| 88 |
$('input[name="selected_data"]').val(selected_data); |
| 89 |
|
| 90 |
var $form = $('#photonic-flow'); |
| 91 |
var parameters = $form.serialize(); |
| 92 |
parameters += ((parameters === '') ? '' : '&') + 'action=photonic_flow_next_screen&screen=' + (activeScreen); |
| 93 |
photonicPostFlowData(activeScreen, nextScreen, $activeScreenElement, screenParameters, parameters); |
| 94 |
|
| 95 |
if (selected_data !== '') { |
| 96 |
photonicFlowLogic(nextScreen); |
| 97 |
} |
| 98 |
}); |
| 99 |
|
| 100 |
photonicNativeWPMediaLibrary.on('open',function() { |
| 101 |
var selection = photonicNativeWPMediaLibrary.state().get('selection'); |
| 102 |
var ids = $('input[name="selected_data"]').val(); |
| 103 |
|
| 104 |
var editor_selection = photonicGetSelectedText(); |
| 105 |
var shortcode, attrs, win = window.dialogArguments || opener || parent || top; |
| 106 |
if (editor_selection !== '' && top.wp !== undefined && top.wp.shortcode !== undefined) { |
| 107 |
shortcode = top.wp.shortcode.next(Photonic_Flow_JS.shortcode, editor_selection); |
| 108 |
attrs = shortcode.shortcode.attrs.named; |
| 109 |
} |
| 110 |
else if (editor_selection === '' && top.wp !== undefined && top.wp.data !== undefined && top.wp.data.select !== undefined && |
| 111 |
win.photonicBlockProperties !== undefined && win.photonicBlockProperties.attributes !== undefined && win.photonicBlockProperties.attributes.shortcode !== undefined) { // Gutenberg |
| 112 |
shortcode = win.photonicBlockProperties.attributes.shortcode; |
| 113 |
attrs = JSON.parse(shortcode); |
| 114 |
} |
| 115 |
|
| 116 |
if (ids === '' && attrs !== undefined) { |
| 117 |
if (attrs.ids !== undefined) { |
| 118 |
ids = attrs.ids; |
| 119 |
} |
| 120 |
else if (attrs.include !== undefined) { |
| 121 |
ids = attrs.include; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
ids = ids.split(','); |
| 127 |
ids.forEach(function(id) { |
| 128 |
var attachment = top.wp.media.attachment(id); |
| 129 |
attachment.fetch(); |
| 130 |
selection.add( attachment ? [ attachment ] : [] ); |
| 131 |
}); |
| 132 |
}); |
| 133 |
} |
| 134 |
} |
| 135 |
}; |
| 136 |
|
| 137 |
window.photonicCheckCondition = function(conditions) { |
| 138 |
var conditionMet = true; |
| 139 |
$(conditions).each(function(cidx, condition) { |
| 140 |
var keys = Object.keys(condition); |
| 141 |
$(keys).each(function(kidx, key){ |
| 142 |
var keyValue = $('input[type="radio"][name="' + this + '"]:checked').val() || $('select[name="' + this + '"]').val() || $('input[type="text"][name="' + this + '"]').val() || $('input[type="hidden"][name="' + this + '"]').val(); |
| 143 |
conditionMet = conditionMet && ($.inArray(keyValue, condition[key]) !== -1); |
| 144 |
}); |
| 145 |
}); |
| 146 |
return conditionMet; |
| 147 |
}; |
| 148 |
|
| 149 |
window.photonicUpdateSelection = function(clicked) { |
| 150 |
var $parent = $(clicked.parents('.photonic-flow-selector-container')[0]); |
| 151 |
var selection = []; |
| 152 |
$parent.find('.photonic-flow-selector.selected .photonic-flow-selector-inner').each(function() { |
| 153 |
selection[selection.length] = $(this).attr('data-photonic-selection-id'); |
| 154 |
}); |
| 155 |
selection = selection.join(); |
| 156 |
var selectorFor = $parent.attr('data-photonic-flow-selector-for'); |
| 157 |
photonicMustPost = true; |
| 158 |
$('input[name="' + selectorFor + '"]').val(selection); |
| 159 |
}; |
| 160 |
|
| 161 |
function photonicShowConditionalFieldValues(sibling) { |
| 162 |
var $siblingFieldValues = $(sibling).find('input[type="radio"], option'); |
| 163 |
$siblingFieldValues.each(function (sfidx, siblingFieldValue) { |
| 164 |
if ($(siblingFieldValue).attr('data-photonic-option-condition') !== undefined) { |
| 165 |
var conditionMet = photonicCheckCondition(JSON.parse($(siblingFieldValue).attr('data-photonic-option-condition'))); |
| 166 |
if (conditionMet) { |
| 167 |
if (siblingFieldValue.type === 'radio') { |
| 168 |
$(siblingFieldValue).parents('.photonic-flow-field-radio').show(); |
| 169 |
} |
| 170 |
else { |
| 171 |
$(siblingFieldValue).show(); |
| 172 |
} |
| 173 |
} |
| 174 |
else { |
| 175 |
if (siblingFieldValue.type === 'radio') { |
| 176 |
siblingFieldValue.checked = false; |
| 177 |
$(siblingFieldValue).parents('.photonic-flow-field-radio').hide(); |
| 178 |
} |
| 179 |
else { |
| 180 |
$(siblingFieldValue).hide(); |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
}); |
| 185 |
} |
| 186 |
|
| 187 |
window.photonicFlowLogic = function(screen) { |
| 188 |
var existing = $('input[name="photonic-editor-shortcode"]').val(); |
| 189 |
var existingBlock = $('input[name="photonic-editor-json"]').val(); |
| 190 |
if (screen === 1) { |
| 191 |
if (existing === undefined || existing === null || existing === '') { |
| 192 |
var shortcode, attributes, type, win = window.dialogArguments || opener || parent || top; |
| 193 |
var selection = photonicGetSelectedText(); |
| 194 |
if (selection !== '' && top.wp !== undefined && top.wp.shortcode !== undefined) { |
| 195 |
shortcode = top.wp.shortcode.next(Photonic_Flow_JS.shortcode, selection.trim()); |
| 196 |
var moreShortcode = top.wp.shortcode.next(Photonic_Flow_JS.shortcode, selection.trim(), 1); // Only one shortcode at a time |
| 197 |
|
| 198 |
if (shortcode !== undefined && moreShortcode === undefined && shortcode.content.length === selection.trim().length) { |
| 199 |
var scParameter = window.btoa(JSON.stringify(shortcode)); |
| 200 |
scParameter = scParameter.replace(/^=+|=+$/g, ''); |
| 201 |
attributes = shortcode.shortcode.attrs.named; |
| 202 |
if (attributes['type'] !== undefined && photonicPermittedGalleries.indexOf(attributes['type']) !== -1) { |
| 203 |
type = attributes['type']; |
| 204 |
} |
| 205 |
else if (attributes['style'] !== undefined) { |
| 206 |
type = 'wp'; |
| 207 |
} |
| 208 |
|
| 209 |
if (type !== undefined) { |
| 210 |
$('[name="photonic-editor-shortcode-raw"]').val(scParameter); |
| 211 |
$('[name="photonic-editor-shortcode"]').val(shortcode.content); |
| 212 |
$('[data-photonic-selection-id="' + type + '"]').click(); |
| 213 |
$('.photonic-editor-info').empty(); |
| 214 |
} |
| 215 |
else { |
| 216 |
$('.photonic-editor-info').html('<div>' + Photonic_Flow_JS.info_editor_not_shortcode + '</div>'); |
| 217 |
} |
| 218 |
} |
| 219 |
else { |
| 220 |
$('.photonic-editor-info').html('<div>' + Photonic_Flow_JS.info_editor_not_shortcode + '</div>'); |
| 221 |
} |
| 222 |
} |
| 223 |
else if (selection === '' && top.wp !== undefined && top.wp.data !== undefined && top.wp.data.select !== undefined && |
| 224 |
win.photonicBlockProperties !== undefined && win.photonicBlockProperties.attributes !== undefined) { // Gutenberg |
| 225 |
$('[name="photonic-gutenberg-active"]').val(1); |
| 226 |
if (win.photonicBlockProperties.attributes.shortcode !== undefined) { |
| 227 |
shortcode = win.photonicBlockProperties.attributes.shortcode; |
| 228 |
attributes = JSON.parse(shortcode); |
| 229 |
|
| 230 |
if (attributes.type !== undefined && photonicPermittedGalleries.indexOf(attributes.type) !== -1) { |
| 231 |
type = attributes.type; |
| 232 |
} |
| 233 |
else if (attributes.style !== undefined) { |
| 234 |
type = 'wp'; |
| 235 |
} |
| 236 |
|
| 237 |
if (type !== undefined) { |
| 238 |
$('[name="photonic-editor-json"]').val(shortcode); |
| 239 |
$('[data-photonic-selection-id="' + type + '"]').click(); |
| 240 |
$('.photonic-editor-info').empty(); |
| 241 |
} |
| 242 |
} |
| 243 |
else { |
| 244 |
$('.photonic-editor-info').html('<div>' + Photonic_Flow_JS.info_editor_block_select + '</div>'); |
| 245 |
} |
| 246 |
} |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
if (screen === 6) { |
| 251 |
if ((existing === undefined || existing === '') && (existingBlock === undefined || existingBlock === '')) { |
| 252 |
$('#photonic-nav-next').html(Photonic_Flow_JS.insert_gallery); |
| 253 |
} |
| 254 |
else { |
| 255 |
$('#photonic-nav-next').html(Photonic_Flow_JS.update_gallery); |
| 256 |
} |
| 257 |
} |
| 258 |
else { |
| 259 |
$('#photonic-nav-next').html('Next'); |
| 260 |
} |
| 261 |
|
| 262 |
$('.photonic-flow-screen').hide(); |
| 263 |
var $activeScreen = $('.photonic-flow-screen[data-screen="' + screen + '"]'); |
| 264 |
var fieldSequences = $activeScreen.find('.photonic-flow-field[data-photonic-flow-sequence="1"]'); |
| 265 |
var displayType = $activeScreen.find('select[name="display_type"]'); |
| 266 |
$(fieldSequences).each(function(i, v) { |
| 267 |
var group = $(v).attr('data-photonic-flow-sequence-group'); |
| 268 |
$('.photonic-flow-field[data-photonic-flow-sequence-group="' + group +'"]').each(function(idx, fieldContainer) { |
| 269 |
var $field = $(fieldContainer).find('input, select'); |
| 270 |
var fieldName = $field.attr('name'); |
| 271 |
var fieldValue = $('input[type="radio"][name="' + fieldName + '"]:checked').val() || $('input[type="text"][name="' + fieldName + '"], select[name="' + fieldName + '"]').val(); |
| 272 |
|
| 273 |
if (idx !== 0 && (fieldValue === '' || fieldValue === undefined)) { |
| 274 |
$(fieldContainer).hide(); |
| 275 |
} |
| 276 |
|
| 277 |
var siblings = $(fieldContainer).siblings(); |
| 278 |
var sequence = parseInt($(fieldContainer).attr('data-photonic-flow-sequence')); |
| 279 |
$field.on('change', function() { |
| 280 |
$('.photonic-flow-error').hide(); |
| 281 |
if ($field.val() !== '') { |
| 282 |
$(siblings).each(function (sidx, sibling) { |
| 283 |
if ($(sibling).attr('data-photonic-flow-sequence') > sequence) { |
| 284 |
if ($(sibling).attr('data-photonic-condition') !== undefined) { |
| 285 |
var conditionMet = photonicCheckCondition(JSON.parse($(sibling).attr('data-photonic-condition'))); |
| 286 |
if (conditionMet) { |
| 287 |
$(sibling).show(); |
| 288 |
} |
| 289 |
else { |
| 290 |
$(sibling).hide(); |
| 291 |
} |
| 292 |
} |
| 293 |
else { |
| 294 |
$(sibling).fadeIn(); |
| 295 |
} |
| 296 |
photonicShowConditionalFieldValues(sibling); |
| 297 |
} |
| 298 |
}); |
| 299 |
} |
| 300 |
else { |
| 301 |
$(siblings).each(function(sidx, sibling){ |
| 302 |
if ($(sibling).attr('data-photonic-flow-sequence') > sequence) { |
| 303 |
$(sibling).fadeOut(); |
| 304 |
} |
| 305 |
}); |
| 306 |
} |
| 307 |
}); |
| 308 |
}); |
| 309 |
}); |
| 310 |
|
| 311 |
$activeScreen.find('[data-photonic-condition] input, [data-photonic-condition] select').each(function(i, v) { |
| 312 |
var $field = $(v).parents('.photonic-flow-field'); |
| 313 |
var $sequences = $(v).parents('[data-photonic-flow-sequence]'); |
| 314 |
if ($field.length !== 0 && $sequences.length === 0) { |
| 315 |
$field = $($field[0]); |
| 316 |
if ($field.data('photonicCondition') !== undefined && $field.data('photonicCondition') !== '') { |
| 317 |
var conditionMet = photonicCheckCondition($field.data('photonicCondition')); |
| 318 |
if (conditionMet) { |
| 319 |
$field.show(); |
| 320 |
} |
| 321 |
else { |
| 322 |
$field.hide(); |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
}); |
| 327 |
|
| 328 |
if (screen === 2) { |
| 329 |
// One exception to the above ... |
| 330 |
if (displayType.length > 0 && $(displayType[0]).val() !== '') { |
| 331 |
var fieldContainer = $('[name="for"]').parents('.photonic-flow-field'); |
| 332 |
photonicShowConditionalFieldValues(fieldContainer); |
| 333 |
fieldContainer.fadeIn(); |
| 334 |
} |
| 335 |
} |
| 336 |
$activeScreen.show(); |
| 337 |
if (screen === 1) { |
| 338 |
$('.photonic-flow-navigation a.previous').addClass('disabled'); |
| 339 |
} |
| 340 |
else { |
| 341 |
$('.photonic-flow-navigation a.previous').removeClass('disabled'); |
| 342 |
} |
| 343 |
}; |
| 344 |
|
| 345 |
$('.photonic-flow-navigation a.disabled').click(function(e) { |
| 346 |
e.preventDefault(); |
| 347 |
}); |
| 348 |
|
| 349 |
$('.photonic-flow-navigation a').on('click', function(e) { |
| 350 |
if (!$(this).hasClass('disabled')) { |
| 351 |
e.preventDefault(); |
| 352 |
var $waiting = $('.photonic-waiting'); |
| 353 |
$waiting.show(); |
| 354 |
var activeScreen = $('.photonic-flow-screen:visible').data('screen'); |
| 355 |
var nextScreen = activeScreen + 1; |
| 356 |
var previousScreen = activeScreen - 1; |
| 357 |
var $form = $('#photonic-flow'); |
| 358 |
var parameters = $form.serialize(); |
| 359 |
|
| 360 |
var $activeScreenElement = $('.photonic-flow-screen[data-screen="' + activeScreen + '"]'); |
| 361 |
if ($(this).hasClass('next')) { |
| 362 |
var shortcode = $activeScreenElement.find('#photonic_shortcode'); |
| 363 |
var screenParameters = $activeScreenElement.find('input, select, textarea').serialize(); |
| 364 |
var submission = $activeScreenElement.attr('data-submitted'); |
| 365 |
|
| 366 |
parameters += ((parameters === '') ? '' : '&') + 'action=photonic_flow_next_screen&screen=' + activeScreen; |
| 367 |
// Make AJAX call if we are on the last screen, or if the current screen's parameters have changed since the last time. |
| 368 |
// Otherwise just get the previously fetched screen. This saves a server call, and also helps preserve screen changes not sent to the back-end. |
| 369 |
if (shortcode.length > 0) { |
| 370 |
var win = window.dialogArguments || opener || parent || top; |
| 371 |
var editor, hasTinymce = typeof win.tinymce !== 'undefined'; |
| 372 |
if (top.wp !== undefined && top.wp.data !== undefined && top.wp.data.select !== undefined) { // Gutenberg |
| 373 |
editor = top.wp.data.select('core/editor'); |
| 374 |
} |
| 375 |
else if (!wpActiveEditor ) { // TinyMCE, activating |
| 376 |
if (hasTinymce && win.tinymce.activeEditor ) { |
| 377 |
editor = win.tinymce.activeEditor; |
| 378 |
wpActiveEditor = editor.id; |
| 379 |
} |
| 380 |
} |
| 381 |
else if ( hasTinymce ) { // TinyMCE, activated |
| 382 |
editor = win.tinymce.get( wpActiveEditor ); |
| 383 |
} |
| 384 |
|
| 385 |
if (editor !== undefined && editor && editor.isHidden !== undefined && !editor.isHidden() && win.photonicClickedNode !== undefined) { // TinyMCE Editor |
| 386 |
var node = win.photonicClickedNode; |
| 387 |
$(node).attr('data-wpview-text', encodeURIComponent($(shortcode[0]).html())); |
| 388 |
tb_close(); |
| 389 |
} |
| 390 |
else if (editor !== undefined && editor && editor.isHidden === undefined && editor.getSelectedBlock !== undefined) { // Gutenberg |
| 391 |
win.photonicBlockProperties.setAttributes({ shortcode: $(shortcode).val() }); |
| 392 |
tb_close(); |
| 393 |
} |
| 394 |
else { |
| 395 |
win.send_to_editor($(shortcode[0]).html()); |
| 396 |
} |
| 397 |
} |
| 398 |
else if (activeScreen === 2 && $('input[name="provider"]').val() === 'wp' && $('select[name="display_type"]').val() === 'multi-photo') { |
| 399 |
photonicInitializeWPMediaLibrary(activeScreen, nextScreen, $activeScreenElement, screenParameters); |
| 400 |
if (photonicNativeWPMediaLibrary !== undefined) { |
| 401 |
photonicNativeWPMediaLibrary.open(); |
| 402 |
} |
| 403 |
$waiting.hide(); |
| 404 |
} |
| 405 |
else if (activeScreen === photonicLastActiveScreen || submission !== screenParameters || photonicMustPost) { |
| 406 |
photonicPostFlowData(activeScreen, nextScreen, $activeScreenElement, screenParameters, parameters); |
| 407 |
} |
| 408 |
else { |
| 409 |
photonicFlowLogic(nextScreen); |
| 410 |
$waiting.hide(); |
| 411 |
} |
| 412 |
} |
| 413 |
else if ($(this).hasClass('previous')) { |
| 414 |
var $forceScreen = $activeScreenElement.find('input[name="force_previous_screen"]'); |
| 415 |
if ($forceScreen.length > 0 && $($forceScreen[0]).val() > -1) { |
| 416 |
previousScreen = $($forceScreen[0]).val(); |
| 417 |
} |
| 418 |
photonicFlowLogic(previousScreen); |
| 419 |
$waiting.hide(); |
| 420 |
} |
| 421 |
} |
| 422 |
}); |
| 423 |
|
| 424 |
$('.photonic-gallery a').click(function(e) { |
| 425 |
e.preventDefault(); |
| 426 |
$('.photonic-gallery a').removeClass('selected'); |
| 427 |
var $clicked = $(this); |
| 428 |
$clicked.addClass('selected'); |
| 429 |
$('#provider').val($clicked.data('provider')); |
| 430 |
}); |
| 431 |
|
| 432 |
$(document).on('click', '.photonic-flow-selector', function(e) { |
| 433 |
e.preventDefault(); |
| 434 |
var $clicked = $(this); |
| 435 |
var $container = $($clicked.parents('.photonic-flow-selector-container')[0]); |
| 436 |
var selectionMode = $container.attr('data-photonic-flow-selector-mode'); |
| 437 |
if (selectionMode === 'none') { |
| 438 |
return; |
| 439 |
} |
| 440 |
else if (selectionMode === 'single' || selectionMode === 'single-no-plus') { |
| 441 |
$container.find('.photonic-flow-selector').removeClass('selected'); |
| 442 |
$container.find('.photonic-flow-selector .dashicons').remove(); |
| 443 |
if ($container.attr('data-photonic-flow-selector-for') === 'selected_data') { |
| 444 |
var $selection_passworded = $('input[name="selection_passworded"]'); |
| 445 |
if ($clicked.hasClass('passworded')) { |
| 446 |
if ($selection_passworded.val() === '') { |
| 447 |
photonicMustPost = true; |
| 448 |
} |
| 449 |
$selection_passworded.val('1'); |
| 450 |
} |
| 451 |
else { |
| 452 |
if ($selection_passworded.val() === '1' || $selection_passworded.val() === 1) { |
| 453 |
photonicMustPost = true; |
| 454 |
} |
| 455 |
$selection_passworded.val(''); |
| 456 |
} |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
if (selectionMode === 'multi') { |
| 461 |
$clicked.addClass('selected'); |
| 462 |
$clicked.append('<a class="dashicons dashicons-plus" href="#"></a>'); |
| 463 |
} |
| 464 |
else if (selectionMode === 'single-no-plus' || selectionMode === 'single') { |
| 465 |
$clicked.addClass('selected'); |
| 466 |
} |
| 467 |
photonicUpdateSelection($clicked); |
| 468 |
}); |
| 469 |
|
| 470 |
$(document).on('mouseenter', '.photonic-flow-selector-container[data-photonic-flow-selector-mode="multi"] .dashicons', function() { |
| 471 |
$(this).toggleClass('dashicons-plus'); |
| 472 |
$(this).toggleClass('dashicons-minus'); |
| 473 |
}); |
| 474 |
|
| 475 |
$(document).on('mouseleave', '.photonic-flow-selector-container[data-photonic-flow-selector-mode="multi"] .dashicons', function() { |
| 476 |
$(this).toggleClass('dashicons-plus'); |
| 477 |
$(this).toggleClass('dashicons-minus'); |
| 478 |
}); |
| 479 |
|
| 480 |
$(document).on('click', '.photonic-mark', function(e) { |
| 481 |
e.preventDefault(); |
| 482 |
var $clicked = $(this); |
| 483 |
var markFor = $clicked.data('photonicMarkFor'); |
| 484 |
var $thumbnails = $('.photonic-flow-selector-container[data-photonic-flow-selector-for="' + markFor + '"]').find('.photonic-flow-selector'); |
| 485 |
var selection = ''; |
| 486 |
$thumbnails.each(function(i, o) { |
| 487 |
if ($clicked.hasClass('photonic-mark-all') && !$(o).hasClass('selected')) { |
| 488 |
$(o).addClass('selected'); |
| 489 |
$(o).append('<a class="dashicons dashicons-plus" href="#"></a>'); |
| 490 |
selection += $(o).children('.photonic-flow-selector-inner').data('photonicSelectionId') + ','; |
| 491 |
} |
| 492 |
else if ($clicked.hasClass('photonic-mark-none')) { |
| 493 |
$(o).removeClass('selected'); |
| 494 |
$(o).find('.dashicons').remove(); |
| 495 |
} |
| 496 |
}); |
| 497 |
if (selection !== '') { |
| 498 |
selection = selection.replace(/^,+|,+$/g, ''); |
| 499 |
} |
| 500 |
$('input[name="' + markFor + '"]').val(selection); |
| 501 |
}); |
| 502 |
|
| 503 |
$(document).on('click', '.photonic-flow-selector-container[data-photonic-flow-selector-mode="multi"] .dashicons', function(e) { |
| 504 |
e.preventDefault(); |
| 505 |
e.stopPropagation(); |
| 506 |
var $selector = $(this).parents('.photonic-flow-selector'); |
| 507 |
$selector.removeClass('selected'); |
| 508 |
$(this).remove(); |
| 509 |
photonicUpdateSelection($selector); |
| 510 |
}); |
| 511 |
|
| 512 |
$(document).on('click', 'a.photonic-add-date-filter', function(e) { |
| 513 |
e.preventDefault(); |
| 514 |
var dateFilterField = $(this).data('photonicAddDate'); |
| 515 |
var list = $('ol[data-photonic-date-filter="' + dateFilterField + '"]'); |
| 516 |
var dateFilterCount = list.data('photonicFilterCount'); |
| 517 |
var currentCount = list.children().length; |
| 518 |
var listItem = $('<li></li>'); |
| 519 |
var parts = ['Year', 'Month', 'Date']; |
| 520 |
var texts = ['Year (0 - 9999)', 'Month (0 - 12)', 'Date (0 - 31)']; |
| 521 |
var div = $('<div class="photonic-single-date"></div>'); |
| 522 |
$(parts).each(function(j, part) { |
| 523 |
div.append( |
| 524 |
"<label class='photonic-date-filter'>" + |
| 525 |
part.substr(0, 1) + |
| 526 |
"<input type='text' class='photonic-date-" + part.toLowerCase() + "' name='" + dateFilterField + "_" + part.toLowerCase() + "[]' aria-describedby='"+ dateFilterField + "_" + currentCount + "_" + part.toLowerCase() + "-hint'/>" + |
| 527 |
"<div class='photonic-flow-hint' role='tooltip' id='date_filter_" + dateFilterField + "_" + currentCount + "_" + part.toLowerCase() + "-hint'>" + texts[j] + "</div>" + |
| 528 |
"</label>" |
| 529 |
); |
| 530 |
}); |
| 531 |
listItem.append(div); |
| 532 |
listItem.append("<a href='#' class='photonic-remove-date-filter' title='Remove filter'><span class=\"dashicons dashicons-no\"> </span></a>"); |
| 533 |
list.append(listItem); |
| 534 |
if (list.children().length === dateFilterCount) { |
| 535 |
$(this).hide(); |
| 536 |
} |
| 537 |
}); |
| 538 |
|
| 539 |
$(document).on('click', 'a.photonic-add-date-range-filter', function(e) { |
| 540 |
e.preventDefault(); |
| 541 |
var dateFilterField = $(this).data('photonicAddDateRange'); |
| 542 |
var list = $('ol[data-photonic-date-range-filter="' + dateFilterField + '"]'); |
| 543 |
var dateFilterCount = list.data('photonicFilterCount'); |
| 544 |
var currentCount = list.children().length; |
| 545 |
var listItem = $('<li></li>'); |
| 546 |
var parts = ['Year', 'Month', 'Date']; |
| 547 |
var range_parts = ['start', 'finish']; |
| 548 |
var texts = ['Year (0 - 9999)', 'Month (0 - 12)', 'Date (0 - 31)']; |
| 549 |
$(range_parts).each(function(i, range_part) { |
| 550 |
var div = $('<div class="photonic-single-date"></div>'); |
| 551 |
$(parts).each(function(j, part) { |
| 552 |
div.append( |
| 553 |
"<label class='photonic-date-filter'>" + |
| 554 |
part.substr(0, 1) + |
| 555 |
"<input type='text' class='photonic-date-" + part.toLowerCase() + "' name='" + dateFilterField + "_" + range_part + "_" + part.toLowerCase() + "[]' aria-describedby='"+ dateFilterField + "_" + currentCount + "_" + range_part + "_" + part.toLowerCase() + "-hint'/>" + |
| 556 |
"<div class='photonic-flow-hint' role='tooltip' id='date_filter_" + dateFilterField + "_" + currentCount + "_" + range_part + "_" + part.toLowerCase() + "-hint'>" + texts[j] + "</div>" + |
| 557 |
"</label>" |
| 558 |
); |
| 559 |
}); |
| 560 |
listItem.append(div); |
| 561 |
}); |
| 562 |
|
| 563 |
listItem.append("<a href='#' class='photonic-remove-date-range-filter' title='Remove filter'><span class=\"dashicons dashicons-no\"> </span></a>"); |
| 564 |
list.append(listItem); |
| 565 |
if (list.children().length === dateFilterCount) { |
| 566 |
$(this).hide(); |
| 567 |
} |
| 568 |
}); |
| 569 |
|
| 570 |
$(document).on('click', 'a.photonic-remove-date-filter', function(e) { |
| 571 |
e.preventDefault(); |
| 572 |
var listItem = $($(this).parents('li')[0]); |
| 573 |
var list = $(listItem.parent()); |
| 574 |
var dateFilterField = list.data('photonicDateFilter'); |
| 575 |
var dateFilterCount = list.data('photonicFilterCount'); |
| 576 |
var addButton = $("a[data-photonic-add-date='" + dateFilterField + "']"); |
| 577 |
if (addButton.length === 0) { |
| 578 |
addButton = $("<a href='#' class='photonic-add-date-filter' data-photonic-add-date='" + dateFilterField + "'><span class=\"dashicons dashicons-plus-alt\"> </span> Add filter</a>\n"); |
| 579 |
addButton.insertAfter(list).hide(); |
| 580 |
} |
| 581 |
$(listItem).remove(); |
| 582 |
if (list.children().length < dateFilterCount) { |
| 583 |
addButton.show(); |
| 584 |
} |
| 585 |
}); |
| 586 |
|
| 587 |
$(document).on('click', 'a.photonic-remove-date-range-filter', function(e) { |
| 588 |
e.preventDefault(); |
| 589 |
var listItem = $($(this).parents('li')[0]); |
| 590 |
var list = $(listItem.parent()); |
| 591 |
var dateFilterField = list.data('photonicDateRangeFilter'); |
| 592 |
var dateFilterCount = list.data('photonicFilterCount'); |
| 593 |
var addButton = $("a[data-photonic-add-date-range='" + dateFilterField + "']"); |
| 594 |
if (addButton.length === 0) { |
| 595 |
addButton = $("<a href='#' class='photonic-add-date-range-filter' data-photonic-add-date-range='" + dateFilterField + "'><span class=\"dashicons dashicons-plus-alt\"> </span> Add filter</a>\n"); |
| 596 |
addButton.insertAfter(list).hide(); |
| 597 |
} |
| 598 |
$(listItem).remove(); |
| 599 |
if (list.children().length < dateFilterCount) { |
| 600 |
addButton.show(); |
| 601 |
} |
| 602 |
}); |
| 603 |
|
| 604 |
$(document).on('change', 'input[class^=photonic-date-]', function() { |
| 605 |
var $changed = $(this); |
| 606 |
var $container = $changed.parents('ol'); |
| 607 |
if ($container.length > 0) { |
| 608 |
$container = $($container[0]); |
| 609 |
var range = $container.attr('data-photonic-date-range-filter') !== undefined; |
| 610 |
var $dates = $container.children('li'); |
| 611 |
var listMerge = []; |
| 612 |
$dates.each(function(li, v) { |
| 613 |
var itemMerge = []; |
| 614 |
var $dateFields = $(v).find('input'); |
| 615 |
if ($dateFields.length > 0) { |
| 616 |
itemMerge[itemMerge.length] = []; |
| 617 |
} |
| 618 |
if ($dateFields.length > 3) { |
| 619 |
itemMerge[itemMerge.length] = []; |
| 620 |
} |
| 621 |
$dateFields.each(function(i, d) { |
| 622 |
var mod = Math.floor(i/3); |
| 623 |
var div = i % 3; |
| 624 |
itemMerge[mod][div] = $(d).val() === '' ? 0 : $(d).val(); |
| 625 |
}); |
| 626 |
$(itemMerge).each(function(i,d) { |
| 627 |
itemMerge[i] = d.join('/'); |
| 628 |
}); |
| 629 |
listMerge[listMerge.length] = itemMerge.join('-'); |
| 630 |
}); |
| 631 |
listMerge = listMerge.join(); |
| 632 |
if (range) { |
| 633 |
$('input[name="' + $container.attr('data-photonic-date-range-filter') + '"]').val(listMerge); |
| 634 |
} |
| 635 |
else { |
| 636 |
$('input[name="' + $container.attr('data-photonic-date-filter') + '"]').val(listMerge); |
| 637 |
} |
| 638 |
} |
| 639 |
}); |
| 640 |
|
| 641 |
$(document).on('click', 'a.photonic-flow-more', function(e) { |
| 642 |
e.preventDefault(); |
| 643 |
var $waiting = $('.photonic-waiting'); |
| 644 |
var $clicked = $(this); |
| 645 |
var link = $clicked.data('photonicMoreLink'); |
| 646 |
if (link !== undefined && link !== '') { |
| 647 |
$waiting.show(); |
| 648 |
var parameters = []; |
| 649 |
parameters['action'] = 'photonic_flow_more'; |
| 650 |
parameters['provider'] = $clicked.data('photonicProvider'); |
| 651 |
parameters['display_type'] = $clicked.data('photonicDisplayType'); |
| 652 |
parameters['url'] = encodeURIComponent($clicked.data('photonicMoreLink')); |
| 653 |
parameters = 'action=photonic_flow_more&provider=' + $clicked.data('photonicProvider') + '&display_type=' + $clicked.data('photonicDisplayType') + '&url=' + btoa($clicked.data('photonicMoreLink')); |
| 654 |
$.post(Photonic_Flow_JS.ajaxurl, parameters, function(data){ |
| 655 |
$clicked.hide().remove(); |
| 656 |
$(data).insertAfter('.photonic-flow-selector:last'); |
| 657 |
var $search = $('#thumb-search'); |
| 658 |
$search.focus().blur(); |
| 659 |
$search.trigger('input'); |
| 660 |
$waiting.hide(); |
| 661 |
}); |
| 662 |
} |
| 663 |
}); |
| 664 |
|
| 665 |
$(document).on('mouseenter', 'input, select', function() { |
| 666 |
//clearTimeout($(this).data('timeoutId')); |
| 667 |
var $tooltip = $('#' + $(this).attr('aria-describedby')); |
| 668 |
$tooltip.attr('aria-hidden', false); |
| 669 |
$tooltip.css({ display: 'block' }); |
| 670 |
$tooltip.fadeIn(); |
| 671 |
}); |
| 672 |
|
| 673 |
$(document).on('mouseleave', 'input, select', function() { |
| 674 |
var tooltipId = '#' + $(this).attr('aria-describedby'); |
| 675 |
var $tooltip = $(tooltipId); |
| 676 |
if ($(tooltipId + ':hover').length === 0) { |
| 677 |
$tooltip.attr('aria-hidden', true); |
| 678 |
$tooltip.css({ display: 'none' }); |
| 679 |
} |
| 680 |
}); |
| 681 |
|
| 682 |
$(document).on('mouseleave', '.photonic-flow-hint', function() { |
| 683 |
var $tooltip = $(this); |
| 684 |
var tooltipId = $tooltip.attr('id'); |
| 685 |
if ($('[aria-describedby="' + tooltipId + '"]:hover').length === 0) { |
| 686 |
$tooltip.attr('aria-hidden', true); |
| 687 |
$tooltip.css({ display: 'none' }); |
| 688 |
} |
| 689 |
}); |
| 690 |
|
| 691 |
$(document).on('focus', '#thumb-search', function(e) { |
| 692 |
var $search = $(this); |
| 693 |
var $imgs = $('.photonic-flow-selector-container img'); |
| 694 |
var cache = []; |
| 695 |
|
| 696 |
$imgs.each(function() { |
| 697 |
cache.push({ |
| 698 |
element: this, |
| 699 |
text: this.alt.trim().toLowerCase() |
| 700 |
}) |
| 701 |
}); |
| 702 |
|
| 703 |
function filter() { |
| 704 |
var query = this.value.trim().toLowerCase(); |
| 705 |
cache.forEach(function(img) { |
| 706 |
var index = 0; |
| 707 |
if (query) { |
| 708 |
index = img.text.indexOf(query); |
| 709 |
} |
| 710 |
if (index === -1) { |
| 711 |
$(img.element).parents('.photonic-flow-selector').css({ display: 'none' }); |
| 712 |
} |
| 713 |
else { |
| 714 |
$(img.element).parents('.photonic-flow-selector').css({ display: 'inline-block' }); |
| 715 |
} |
| 716 |
}); |
| 717 |
} |
| 718 |
|
| 719 |
if ('oninput' in $search[0]) { |
| 720 |
$search.on('input', filter); |
| 721 |
} |
| 722 |
else { |
| 723 |
$search.on('keyup', filter); |
| 724 |
} |
| 725 |
}); |
| 726 |
|
| 727 |
$('[name="selected_data"],[name="selection_passworded"]').on('change', function(){ |
| 728 |
photonicMustPost = true; |
| 729 |
}); |
| 730 |
|
| 731 |
photonicFlowLogic(1); |
| 732 |
}); |
| 733 |
|