PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 2.26
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v2.26
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.26, at include/scripts/admin/flow.js

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