PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.42
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.42
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
photonic / include / scripts / admin / flow.js

flow.js in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 2.42, at include/scripts/admin/flow.js

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