PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.0.2
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.0.2
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / assets / js / admin.js
the-post-grid / assets / js Last commit date
admin-preview.js 3 years ago admin.js 3 years ago blocks-placeholder.js 3 years ago editor-el.js 3 years ago mce-button.js 3 years ago post-grid-blocks.js 3 years ago rttpg.js 3 years ago tpg-el-editor.js 3 years ago
admin.js
866 lines
1 (function (global, $) {
2 'use strict';
3
4 var postType = $("#rt-sc-post-type").val();
5 $(document).on('change', '#post_filter input[type=checkbox]', function () {
6 var id = $(this).val();
7 var postType = $("#rt-sc-post-type").val();
8 if (id == 'tpg_taxonomy') {
9 if (this.checked) {
10 rtTPGTaxonomyListByPostType(postType, $(this));
11 } else {
12 $('.rt-tpg-filter.taxonomy > .taxonomy-field').hide('slow').html('');
13 $('.rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-holder').hide('slow').html('');
14 $('.rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-item-relation').hide('slow');
15 }
16 }
17 if (this.checked) {
18 $(".rt-tpg-filter." + id).show('slow');
19 } else {
20 $(".rt-tpg-filter." + id).hide('slow');
21 }
22 });
23
24 $(".field-holder.pro-field").on('click', '.field', function (e) {
25 e.preventDefault();
26 $('.rt-pro-alert').show();
27 });
28
29 $('.rt-pro-alert-close').on('click', function (e) {
30 e.preventDefault();
31 $('.rt-pro-alert').hide();
32 });
33
34 $('.select2-results__option--highlighted').on('click', function (e) {
35 e.preventDefault();
36 });
37
38 $(document).on('change', '#post-taxonomy input[type=checkbox]', function () {
39 tlpShowHideScMeta();
40 rtTPGTermListByTaxonomy($(this));
41 });
42 $(document).on('change', '#tgp_filter input[type=checkbox]', function () {
43 tlpShowHideScMeta();
44 });
45 $("#sc-field-selection").on('change', 'label[for=item-fields-cf] input[type=checkbox]', function () {
46 checkCustomField(true);
47 });
48 $("#popup_fields_holder").on('change', 'label[for=popup-fields-cf] input[type=checkbox]', function () {
49 checkCustomFieldSettings();
50 });
51
52 $("#rt-tpg-pagination").on('change', function () {
53 if (this.checked) {
54 $(".field-holder.pagination-item").show();
55 } else {
56 $(".field-holder.pagination-item").hide();
57 }
58 });
59
60 function checkCustomField() {
61 if ($("#item-fields-cf").is(':checked')) {
62 $(".field-holder.cf-fields").show();
63 } else {
64 $(".field-holder.cf-fields").hide();
65 }
66 }
67
68 function checkCustomFieldSettings() {
69 if ($("#popup-fields-cf").is(':checked')) {
70 $(".field-holder.cfs-fields").show();
71 } else {
72 $(".field-holder.cfs-fields").hide();
73 }
74 }
75
76 function loadCustomField($this) {
77 var post_type = $this.val();
78 if (post_type) {
79 var arg = "post_type=" + post_type;
80 tpgAjaxCall($this, 'getCfGroupListAsField', arg, function (data) {
81 if (!data.error) {
82 $("#cf_group_holder").replaceWith(data.data);
83 checkCustomField();
84 } else {
85 console.log(data.msg)
86 }
87 });
88 }
89 }
90
91 function featureImageEffect() {
92 if ($("#rt-tpg-feature-image").is(':checked')) {
93 $(".field-holder.rt-feature-image-option").hide();
94 } else {
95 $(".field-holder.rt-feature-image-option").show();
96 }
97 }
98
99 $("#rt-tpg-feature-image").on('change', function () {
100 featureImageEffect();
101 });
102
103 $("#tgp_filter-_taxonomy_filter").on('change', function () {
104 tpgTaxonomyFilterTrigger();
105 });
106
107 $("#order_by").on('change', function () {
108 tpgOrderByEffect();
109 });
110
111 $("#rttpg-layout_type input[name=layout_type], #rttpg-layout input[name=layout]").on('change', function () {
112 $('#layout_holder').show();
113 tlpShowHideScMeta();
114 rtTPGSelectedlayoutType();
115 });
116
117 $("#rt-sc-post-type").on("change", function (e) {
118 var postType = $(this).val(),
119 self = $(this);
120 if (postType) {
121 loadCustomField(self);
122 rtTPGIsotopeFilter(self);
123 rtTPGIsotopTaxonomyFilter(self);
124 $('#post_filter input[type=checkbox]').each(function () {
125 $(this).prop('checked', false);
126 });
127 $(".rt-tpg-filter.taxonomy > .taxonomy-field").html('');
128 $(".rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-item-container").remove();
129 $(".rt-tpg-filter.hidden").hide();
130 $(".field-holder.term-filter-item-relation ").hide();
131 }
132
133 });
134
135 $(document).ready(function () {
136 checkCustomFieldSettings();
137 rtTgpFilter();
138 if ($(".rt-select2").length) {
139 tgpLiveReloadScript();
140 }
141 tlpShowHideScMeta();
142 checkCustomField();
143 if ($('.rt-color').length) {
144 $('.rt-color').wpColorPicker();
145 }
146 if ($(".date-range").length) {
147 $(".date-range-start").datepicker({
148 defaultDate: "+1w",
149 changeYear: true,
150 changeMonth: true,
151 dateFormat: "yy-mm-dd",
152 onClose: function (selectedDate) {
153 $(".date-range-end").datepicker("option", "minDate", selectedDate);
154 }
155 });
156 $(".date-range-end").datepicker({
157 defaultDate: "+1w",
158 changeYear: true,
159 changeMonth: true,
160 dateFormat: "yy-mm-dd",
161 onClose: function (selectedDate) {
162 $(".date-range-start").datepicker("option", "maxDate", selectedDate);
163 }
164 });
165 }
166
167 $('.tpg-spacing-field').on('change, keyup', function () {
168 var marginInput = $(this).val();
169 var marginValue = marginInput.replace(/[^\d,]+/g, '');
170 $(this).val(marginValue);
171 });
172
173 if ($("#tpg_image_type").length) {
174 setImageBorderRadius();
175 }
176
177 $('#tpg_image_type').on('change', function () {
178 setImageBorderRadius();
179 });
180
181 });
182
183 function setImageBorderRadius() {
184 var img_type = $("#tpg_image_type input[name='tpg_image_type']:checked").val(),
185 img_border_radius = $("#tpg_image_border_radius").val(),
186 img_border_radius = (img_type == 'circle') ? 50 : img_border_radius;
187 $("#tpg_image_border_radius").val(img_border_radius);
188 }
189
190 function setGetParameter(paramName, paramValue) {
191 let url = window.location.href;
192 let hash = location.hash;
193 url = url.replace(hash, '');
194 if (url.indexOf("?") >= 0) {
195 let params = url.substring(url.indexOf("?") + 1).split("&");
196 let paramFound = false;
197 params.forEach(function (param, index) {
198 let p = param.split("=");
199 if (p[0] == paramName) {
200 params[index] = paramName + "=" + paramValue;
201 paramFound = true;
202 }
203 });
204 if (!paramFound) params.push(paramName + "=" + paramValue);
205 url = url.substring(0, url.indexOf("?") + 1) + params.join("&");
206 } else
207 url += "?" + paramName + "=" + paramValue;
208 return url + hash;
209 }
210
211 $(".rttpg-wrapper .rt-tab-nav li").on('click', 'a', function (e) {
212 e.preventDefault();
213 var container = $(this).parents('.rt-tab-container'),
214 nav = container.children('.rt-tab-nav'),
215 content = container.children(".rt-tab-content"),
216 $this = $(this),
217 $id = $this.attr('href'),
218 _target = $id.replace('#', '');
219 content.hide();
220 nav.find('li').removeClass('active');
221 $this.parent().addClass('active');
222 container.find($id).show();
223 $('#_tpg_last_active_tab').val(_target);
224 if (history.pushState) {
225 var newurl = setGetParameter('section', _target);
226 window.history.pushState({path: newurl}, '', newurl);
227 }
228 });
229
230 rtTPGlayoutType();
231 detailLinkEffect();
232 customImageSize();
233 customSmallImageSize();
234 // preLoaderEffect();
235 tpgEnableACF();
236 featureImageEffect();
237 tpgOrderByEffect();
238 $("#link_to_detail_page_holder").on("change", "input[type='checkbox']", function () {
239 detailLinkEffect();
240 });
241 $("#detail_page_link_type_holder").on("click", "input[type='radio']", function () {
242 linkTypeEffect();
243 });
244
245 $("#posts_loading_type_holder").on("change", "input[type='radio']", function () {
246 loadMoreButtonVisibility($(this).val());
247 });
248
249 $("#rt-tpg-sc-isotope-filter").on('change', function () {
250 setDefaultItems();
251 });
252 $("#tgp_filter_taxonomy").on('change', function () {
253 setDefaultItemsForFilter();
254 });
255 $("#ttp_filter-_taxonomy_filter").on('change', function () {
256 taxonomyFilterEffect();
257 });
258
259 $("#featured_image_size").on('change', function () {
260 customImageSize();
261 });
262
263 $("#featured_small_image_size").on('change', function () {
264 customSmallImageSize();
265 });
266
267 $("#tpg_load_script").on('change', function () {
268 //preLoaderEffect();
269 });
270
271 $("#show_acf_details").on('change', function () {
272 tpgEnableACF();
273 });
274
275 function preLoaderEffect() {
276 var preLoader = $("#tpg_load_script_holder input[name='tpg_load_script']:checked").val();
277 if (preLoader) {
278 $("#tpg_enable_preloader_holder").show();
279 } else {
280 $("#tpg_enable_preloader_holder").hide();
281 }
282 }
283
284 function tpgEnableACF() {
285 var tpgACF = $("#show_acf_details_holder input[name='show_acf_details']:checked").val();
286 if (tpgACF) {
287 $("#cf_group_details_holder, #cf_hide_empty_value_details_holder, #cf_show_only_value_details_holder, #cf_hide_group_title_details_holder").fadeIn();
288 } else {
289 $("#cf_group_details_holder, #cf_hide_empty_value_details_holder, #cf_show_only_value_details_holder, #cf_hide_group_title_details_holder").fadeOut();
290 }
291 }
292
293 function customImageSize() {
294 /* custom image size jquery */
295 var fImageSize = $("#featured_image_size").val();
296 if (fImageSize == "rt_custom") {
297 $(".rt-sc-custom-image-size-holder").show();
298 } else {
299 $(".rt-sc-custom-image-size-holder").hide();
300 }
301 }
302
303 function customSmallImageSize() {
304 /* custom image size jquery */
305 var fImageSize = $("#featured_small_image_size").val();
306 if (fImageSize == "rt_custom") {
307 $(".rt-sc-custom-small-image-size-holder").show();
308 } else {
309 $(".rt-sc-custom-small-image-size-holder").hide();
310 }
311 }
312
313 function rtTPGlayoutType() {
314 var $layout = $("#rttpg-layout input[name=layout]:checked"),
315 layoutType = $layout.parent('.radio-image').attr('data-type'),
316 selector = ".rt-tpg-radio-layout." + layoutType;
317
318 $('#rttpg-layout .rt-tpg-radio-layout').hide();
319 $('#layout_holder').hide();
320
321 if (layoutType) {
322 $("#rttpg-layout_type input[id=" + layoutType + "]").prop('checked', true);
323 $('#layout_holder').show();
324 $(selector).show();
325 }
326 }
327
328 function rtTPGSelectedlayoutType() {
329 var layout_type = $("#rttpg-layout_type input[name=layout_type]:checked"),
330 layout_type_value = layout_type.val(),
331 selector = ".rt-tpg-radio-layout." + layout_type_value;
332 $('#rttpg-layout .rt-tpg-radio-layout').hide();
333
334 if (layout_type_value == 'grid_hover') {
335 $('#featured_small_image_size_holder').show();
336 customSmallImageSize();
337 } else {
338 $('#featured_small_image_size_holder').hide();
339 $('.rt-sc-custom-small-image-size-holder').hide();
340 }
341
342 if (!layout_type_value) {
343 var selectChildByValue = $("#rttpg-layout input[name=layout]:checked"),
344 ownParent = selectChildByValue.parent('.radio-image'),
345 parentId = ownParent.attr('data-type');
346
347 $("#rttpg-layout_type input[id=" + parentId + "]").prop('checked', true);
348 selector = ".rt-tpg-radio-layout." + parentId;
349 if (!selectChildByValue.val()) {
350 $('#layout_holder').hide();
351 } else {
352 $('#layout_holder').show();
353 }
354 }
355 $(selector).show();
356 }
357
358 function rtTPGIsotopTaxonomyFilter($this) {
359 var arg = "post_type=" + $this.val();
360 var bindElement = $this;
361 var target = $('#tgp_filter_taxonomy_holder select');
362 tpgAjaxCall(bindElement, 'rtTPGIsotopeFilter', arg, function (data) {
363 if (!data.error) {
364 target.html(data.data);
365 setDefaultItems();
366 setDefaultItemsForFilter();
367 tgpLiveReloadScript();
368 } else {
369 console.log(data.msg);
370 }
371 });
372 }
373
374 function tpgTaxonomyFilterTrigger() {
375 var target = $(".field-holder.sc-tpg-filter");
376 if ($("#tgp_filter-_taxonomy_filter").is(':checked')) {
377 target.show();
378 } else {
379 target.hide();
380 }
381 }
382
383 function rtTPGTaxonomyListByPostType(postType, $this) {
384
385 var arg = "post_type=" + postType;
386 var bindElement = $this;
387
388 $('#post-taxonomy input[name="tpg_taxonomy[]"]:checked').each(function () {
389 arg += '&taxonomy[]=' + this.value;
390 });
391
392 tpgAjaxCall(bindElement, 'rtTPGTaxonomyListByPostType', arg, function (data) {
393 if (!data.error) {
394 $('.rt-tpg-filter.taxonomy > .taxonomy-field').html(data.data).show('slow');
395 } else {
396 console.log(data.msg);
397 }
398 });
399 }
400
401 function tlpShowHideScMeta() {
402 tpgTaxonomyFilterTrigger();
403 //var layout = $("#rt-tpg-sc-layout").val(),
404 var layout_type = $("#rttpg-layout_type input[name=layout_type]:checked"),
405 layout = layout_type.val(),
406 selectedLayout = '',
407 isIsotope = false,
408 isCarousel = false,
409 isWc = false,
410 isEdd = false,
411 isWcIsotope = false,
412 isWcCarousel = false,
413 isGrid = false,
414 isList = false,
415 isLOffset = false;
416
417 if ($("#rttpg-layout input[name=layout]").length) {
418 selectedLayout = $("#rttpg-layout input[name=layout]:checked").val();
419 }
420
421 if (layout) {
422 isGrid = layout.match(/^grid/i);
423 isList = layout.match(/^list/i);
424 isCarousel = layout.match(/^carousel/i);
425 isIsotope = layout.match(/^isotope/i);
426 isWc = layout.match(/^wc/i) || layout.match(/^edd/i);
427 isEdd = layout.match(/^edd/i);
428 isWcIsotope = layout.match(/^wc-isotope/i) || layout.match(/^edd-isotope/i);
429 isWcCarousel = layout.match(/^wc-carousel/i) || layout.match(/^edd-carousel/i);
430 isLOffset = layout.match(/^offset/i);
431 var lArray = ['layout4', 'layout5', 'layout6', 'layout7', 'layout8', 'layout9', 'layout10', 'layout13', 'layout15', 'layout16'];
432 var target = jQuery("#rt-tpg-sc-layout").parent();
433 target.find('.description').remove();
434 if ($.inArray(layout, lArray) >= 0) {
435 target.append("<p class='description' style='color:red'>Default or a feature image is mandatory for this layout</p>");
436 }
437 }
438
439 var plType = $("#posts_loading_type");
440 plType.find("label[for='posts_loading_type-pagination'],label[for='posts_loading_type-pagination_ajax']").show();
441 $("#tgp_layout2_image_column_holder").hide();
442
443 if (isGrid || isList || (isWc && !isWcCarousel && !isWcIsotope)) {
444 $("#tgp_filter_holder").show();
445 taxonomyFilterEffect();
446 if (selectedLayout == "layout2" || selectedLayout == "layout3") {
447 $("#tgp_layout2_image_column_holder").show();
448 }
449 $(".field-holder.isotope-item").hide();
450 } else if (isLOffset) {
451 $("#posts_loading_type_holder,.field-holder.isotope-item").hide();
452 $("#tgp_filter_holder").show();
453 taxonomyFilterEffect();
454 $(".field-holder.offset-column-wrap select").find('option[value="4"]').remove();
455 } else if (isCarousel || isWcCarousel) {
456 $(".field-holder.sc-product-filter,.field-holder.pagination, .field-holder.pagination-item,.field-holder.isotope-item,.field-holder.sc-tpg-grid-filter").hide();
457 $(".field-holder.carousel-item").show();
458 } else if (isIsotope) {
459 $(".field-holder.sc-product-filter,.field-holder.carousel-item,.field-holder.sc-tpg-grid-filter").hide();
460 $(".field-holder.isotope-item,.field-holder.pagination").show();
461 $("#posts_loading_type").find("label[for='posts_loading_type-pagination'],label[for='posts_loading_type-pagination_ajax']").hide();
462 var ltype = $("#posts_loading_type").find("input[name=posts_loading_type]:checked").val();
463 if (ltype == "pagination" || ltype == "pagination_ajax") {
464 $("#posts_loading_type").find("label[for='posts_loading_type-load_more'] input").prop("checked", true);
465 }
466 if ($("#rt-tpg-sc-isotope-filter option:selected").length) {
467 setDefaultItems();
468 }
469 } else if (isWc && !isWcIsotope && !isWcCarousel) {
470 $(".field-holder.isotope-item,.field-holder.carousel-item,.field-holder.sc-product-filter,.field-holder.sc-tpg-grid-filter").hide();
471 $(".field-holder.sc-product-filter,.field-holder.pagination").show();
472 } else if (isWcIsotope) {
473 $(".field-holder.sc-product-filter,.field-holder.carousel-item,.field-holder.sc-tpg-grid-filter").hide();
474 $(".field-holder.isotope-item,.field-holder.pagination").show();
475 $("#posts_loading_type").find("label[for='posts_loading_type-pagination'],label[for='posts_loading_type-pagination_ajax']").hide();
476 var ltype = $("#posts_loading_type").find("input[name=posts_loading_type]:checked").val();
477 if (ltype == "pagination" || ltype == "pagination_ajax") {
478 $("#posts_loading_type").find("label[for='posts_loading_type-load_more'] input").prop("checked", true);
479 }
480 if ($("#rt-tpg-sc-isotope-filter option:selected").length) {
481 setDefaultItems();
482 }
483 } else {
484 $(".field-holder.isotope-item,.field-holder.carousel-item,.field-holder.sc-product-filter,.field-holder.sc-tpg-grid-filter").hide();
485 $(".field-holder.pagination").show();
486 }
487 setDefaultItemsForFilter();
488 tpgOrderByEffect();
489 if ($("#post-taxonomy input[name='tpg_taxonomy[]']").is(":checked")) {
490 $(".rt-tpg-filter-item.term-filter-item").show();
491 } else {
492 $(".rt-tpg-filter-item.term-filter-item").hide();
493 }
494
495 var pagination = $("#rt-tpg-pagination").is(':checked');
496 var isLoadMore = $("#posts_loading_type_holder #posts_loading_type-load_more").is(':checked');
497
498 if (pagination && !(isCarousel || isWc || isWcIsotope || isWcCarousel)) {
499 $(".field-holder.pagination-item").show();
500
501 } else if (pagination && (isLOffset)) {
502 $(".field-holder.posts-per-page").show();
503 $("#posts_loading_type_holder").hide();
504 } else {
505 $(".field-holder.pagination-item").hide();
506 }
507
508 if ((isLoadMore && pagination) && !(isCarousel || isEdd)) {
509 $('.field-holder.pagination-load-more-label').show();
510 } else {
511 $('.field-holder.pagination-load-more-label').hide();
512 }
513 }
514
515 function taxonomyFilterEffect() {
516 if ($("#tgp_filter-_taxonomy_filter").is(':checked')) {
517 $(".field-holder.sc-tpg-grid-filter").show();
518 filterEffectToPagination();
519 } else {
520 $(".field-holder.sc-tpg-grid-filter").not("#tgp_filter_holder").hide();
521 }
522 }
523
524 function filterEffectToPagination() {
525 var plType = $("#posts_loading_type"),
526 lType = plType.find("input[name=posts_loading_type]:checked").val();
527 if ($("#tgp_filter_holder input[name='tgp_filter[]']").is(':checked')) {
528 plType.find("label[for='posts_loading_type-pagination']").hide();
529 if (lType == "pagination") {
530 plType.find("label[for='posts_loading_type-pagination_ajax'] input").prop("checked", true);
531 }
532 } else {
533 plType.find("label[for='posts_loading_type-pagination']").show();
534 }
535 }
536
537 function tpgOrderByEffect() {
538 var Oval = $('#order_by').val(),
539 vList = ['meta_value_num', 'meta_value', 'meta_value_datetime'];
540
541 if ($.inArray(Oval, vList) !== -1) {
542 $('#tpg_meta_key_holder').show();
543 } else {
544 $('#tpg_meta_key_holder').hide();
545 }
546 }
547
548 $('#term_category_holder select').on('change', function (e) {
549 setDefaultItems();
550 if ($("#tgp_filter-_taxonomy_filter").is(':checked')) {
551 setDefaultItemsForFilter();
552 }
553 });
554
555 $('#term_post_tag_holder select').on('change', function (e) {
556 setDefaultItems();
557 if ($("#tgp_filter-_taxonomy_filter").is(':checked')) {
558 setDefaultItemsForFilter();
559 }
560 });
561
562 function setDefaultItems() {
563 var target_from = $("#rt-tpg-sc-isotope-filter"),
564 target = $("#rt-tpg-sc-isotope-default-filter"),
565 $fId = target_from.val();
566
567 var $term = [];
568
569 if ($fId == 'category') {
570 if ($('#term_category_holder').length && $('#post-taxonomy-category')) {
571 var selected_term = $('#term_category_holder select').select2('data');
572 selected_term.forEach(function (element) {
573 $term.push(element.id);
574 });
575 }
576 } else if ($fId == 'post_tag') {
577 $term = [];
578 if ($('#term_post_tag_holder').length && $('#post-taxonomy-post_tag')) {
579 var selected_term = $('#term_post_tag_holder select').select2('data');
580 selected_term.forEach(function (element) {
581 $term.push(element.id);
582 });
583 }
584 }
585
586 if ($fId) {
587 var data = 'action=defaultFilterItem&filter=' + $fId + '&include=' + $term + "&rttpg_nonce=" + rttpg.nonce;
588 $.ajax({
589 type: "post",
590 url: rttpg.ajaxurl,
591 data: data,
592 beforeSend: function () {
593 $("<span class='rt-loading'></span>").insertAfter(target);
594 },
595 success: function (data) {
596 if (!data.error) {
597 var selected = target.data('selected');
598 target.html(data.data);
599 if (selected) {
600 target.val(selected).trigger("change");
601 }
602 } else {
603 console.log(data.msg);
604 }
605 target.parent().find(".rt-loading").remove();
606 },
607 error: function () {
608 target.parent().find(".rt-loading").remove();
609 }
610 });
611 }
612 }
613
614 function setDefaultItemsForFilter() {
615 var target_from = $("#tgp_filter_taxonomy"),
616 target = $('#tgp_default_filter'),
617 $fId = target_from.val();
618
619 var $term = [];
620
621 if ($fId == 'category') {
622 if ($('#term_category_holder').length && $('#post-taxonomy-category')) {
623 var selected_term = $('#term_category_holder select').select2('data');
624 selected_term.forEach(function (element) {
625 $term.push(element.id);
626 });
627 }
628 } else if ($fId == 'post_tag') {
629 $term = [];
630 if ($('#term_post_tag_holder').length && $('#post-taxonomy-post_tag')) {
631 var selected_term = $('#term_post_tag_holder select').select2('data');
632 selected_term.forEach(function (element) {
633 $term.push(element.id);
634 });
635 }
636 }
637
638 if ($fId) {
639 var data = 'action=defaultFilterItem&filter=' + $fId + '&include=' + $term + "&rttpg_nonce=" + rttpg.nonce;
640 $.ajax({
641 type: "post",
642 url: rttpg.ajaxurl,
643 data: data,
644 beforeSend: function () {
645 $("<span class='rt-loading'></span>").insertAfter(target);
646 },
647 success: function (data) {
648 if (!data.error) {
649 var selected = target.data('selected');
650 target.html(data.data);
651 if (selected) {
652 target.val(selected).trigger("change");
653 }
654
655 } else {
656 console.log(data.msg);
657 }
658 target.next(".rt-loading").remove();
659 }
660 });
661 }
662 }
663
664 function rtTPGIsotopeFilter($this) {
665 var arg = "post_type=" + $this.val();
666 var bindElement = $this;
667 var target = jQuery('.field-holder.sc-isotope-filter .field > select');
668 tpgAjaxCall(bindElement, 'rtTPGIsotopeFilter', arg, function (data) {
669 if (!data.error) {
670 target.html(data.data);
671 setDefaultItems();
672 tgpLiveReloadScript();
673 } else {
674 console.log(data.msg);
675 }
676 });
677 }
678
679 function rtTPGTermListByTaxonomy($this) {
680 var term = $this.val();
681 var targetHolder = $('.rt-tpg-filter.taxonomy').children('.rt-tpg-filter-item').children('.field-holder').children('.term-filter-holder');
682 var target = targetHolder.children('.term-filter-item-container.' + term);
683 if ($this.is(':checked')) {
684 var arg = "taxonomy=" + $this.val();
685 var bindElement = $this;
686 tpgAjaxCall(bindElement, 'rtTPGTermListByTaxonomy', arg, function (data) {
687 if (!data.error) {
688 targetHolder.show();
689 $(data.data).prependTo(targetHolder).fadeIn('slow');
690 tgpLiveReloadScript();
691 } else {
692 console.log(data.msg)
693 }
694 });
695 } else {
696 target.hide('slow').html('').remove();
697 }
698
699 var termLength = jQuery('input[name="tpg_taxonomy[]"]:checked').length;
700 if (termLength > 1) {
701 $('.field-holder.term-filter-item-relation ').show('slow');
702 } else {
703 $('.field-holder.term-filter-item-relation ').hide('slow');
704 }
705
706 }
707
708 function detailLinkEffect() {
709 var detailPageLink = $("#link_to_detail_page_holder input[name='link_to_detail_page']:checked").val();
710 if (detailPageLink) {
711 $(".field-holder.detail-page-link-type").show();
712 } else {
713 $(".field-holder.detail-page-link-type,.field-holder.popup-type,.field-holder.tpg-link-target").hide();
714 }
715 linkTypeEffect();
716 }
717
718 function linkTypeEffect() {
719 var linkType = $("#detail_page_link_type_holder input[name='detail_page_link_type']:checked").val(),
720 detailPageLink = $("#link_to_detail_page_holder input[name='link_to_detail_page']:checked").val();
721 if (linkType == "popup" && detailPageLink) {
722 $(".field-holder.popup-type").show();
723 $(".field-holder.tpg-link-target").hide()
724 } else {
725 $(".field-holder.popup-type").hide();
726 $(".field-holder.tpg-link-target").show();
727 }
728 }
729
730 function loadMoreButtonVisibility(value) {
731 if ('load_more' === value) {
732 $('.field-holder.pagination-load-more-label').show();
733 } else {
734 $('.field-holder.pagination-load-more-label').hide();
735 }
736
737 }
738
739 function tpgAjaxCall(element, action, arg, handle) {
740 var data;
741 if (action) data = "action=" + action;
742 if (arg) data = arg + "&action=" + action;
743 if (arg && !action) data = arg;
744
745 var n = data.search(rttpg.nonceID);
746 if (n < 0) {
747 data = data + "&rttpg_nonce=" + rttpg.nonce;
748 }
749 $.ajax({
750 type: "post",
751 url: rttpg.ajaxurl,
752 data: data,
753 beforeSend: function () {
754 $("<span class='rt-loading'></span>").insertAfter(element);
755 },
756 success: function (data) {
757 element.next(".rt-loading").remove();
758 handle(data);
759 },
760 error: function (e) {
761 element.next(".rt-loading").remove();
762 }
763 });
764 }
765
766 $("#rt-tpg-settings-form").on('click', '.rt-licensing-btn', function (e) {
767 e.preventDefault();
768 var self = $(this),
769 type = self.attr('name'),
770 data = 'type=' + type;
771 $("#license_key_holder").find(".rt-licence-msg").remove();
772 tpgAjaxCall(self, 'rtTPGManageLicencing', data, function (data) {
773 if (!data.error) {
774 self.val(data.value);
775 self.attr('name', data.name);
776 self.addClass(data.class);
777 if (data.name == 'license_deactivate') {
778 self.removeClass('button-primary');
779 self.addClass('danger');
780 } else if (data.name == 'license_activate') {
781 self.removeClass('danger');
782 self.addClass('button-primary');
783 }
784 }
785 if (data.msg) {
786 $("<div class='rt-licence-msg'>" + data.msg + "</div>").insertAfter(self);
787 }
788 self.blur();
789 });
790
791 return false;
792 });
793
794 $("#rt-tpg-settings-form").on('click', '.rtSaveButton', function (e) {
795 e.preventDefault();
796 $('.rt-response').hide();
797 var arg = $("#rt-tpg-settings-form").serialize();
798 var bindElement = $('.rtSaveButton');
799 tpgAjaxCall(bindElement, 'rtTPGSettings', arg, function (data) {
800 if (data.error) {
801 $('.rt-response').addClass('error');
802 $('.rt-response').show('slow').text(data.msg);
803 } else {
804 $('.rt-response').addClass('updated');
805 $('.rt-response').removeClass('error');
806 $('.rt-response').show('slow').text(data.msg);
807 var holder = $("#license_key_holder");
808 if (!$(".license-status", holder).length && $("#license_key", holder).val()) {
809 var bindElement = $("#license_key", holder),
810 target = $(".description", holder);
811 target.find(".rt-licence-msg").remove();
812 tpgAjaxCall(bindElement, 'rtTPG_active_Licence', '', function (data) {
813 if (!data.error) {
814 target.append("<span class='license-status'>" + data.html + "</span>");
815 }
816 if (data.msg) {
817 if (target.find(".rt-licence-msg").length) {
818 target.find(".rt-licence-msg").html(data.msg);
819 } else {
820 target.append("<span class='rt-licence-msg'>" + data.msg + "</span>");
821 }
822 if (!data.error) {
823 target.find(".rt-licence-msg").addClass('success');
824 }
825 }
826 });
827 }
828 if (!$("#license_key", holder).val()) {
829 $('.license-status', holder).remove();
830 }
831 }
832 });
833 return false;
834 });
835
836 function rtTgpFilter() {
837 $("#post_filter input[type=checkbox]:checked").each(function () {
838 var id = $(this).val();
839 if (id == 'tpg_taxonomy') {
840 if (this.checked) {
841 rtTPGTaxonomyListByPostType(postType, $(this));
842 } else {
843 $('.rt-tpg-filter.taxonomy > .taxonomy-field').hide('slow').html('');
844 $('.rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-holder').hide('slow').html('');
845 $('.rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-item-relation').hide('slow');
846 }
847 }
848 $(".rt-tpg-filter." + id).show();
849 });
850
851 $("#post-taxonomy input[type=checkbox]:checked").each(function () {
852 var id = $(this).val();
853 $(".filter-item." + id).show();
854 });
855 }
856
857 function tgpLiveReloadScript() {
858 $("select.rt-select2").select2({
859 theme: "classic",
860 dropdownAutoWidth: true,
861 width: '100%'
862 });
863 }
864
865 })(this, jQuery);
866