PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 4.1.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v4.1.0
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 4 years ago admin.js 4 years ago mce-button.js 4 years ago post-grid-blocks.js 4 years ago rttpg.js 4 years ago tpg-el-editor.js 4 years ago
admin.js
845 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 if (id == 'tpg_taxonomy') {
8 if (this.checked) {
9 rtTPGTaxonomyListByPostType(postType, $(this));
10 } else {
11 $('.rt-tpg-filter.taxonomy > .taxonomy-field').hide('slow').html('');
12 $('.rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-holder').hide('slow').html('');
13 $('.rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-item-relation').hide('slow');
14 }
15 }
16 if (this.checked) {
17 $(".rt-tpg-filter." + id).show('slow');
18 } else {
19 $(".rt-tpg-filter." + id).hide('slow');
20 }
21 });
22
23 $(".field-holder.pro-field").on('click', '.field', function (e) {
24 e.preventDefault();
25 $('.rt-pro-alert').show();
26 });
27
28 $('.rt-pro-alert-close').on('click', function (e) {
29 e.preventDefault();
30 $('.rt-pro-alert').hide();
31 });
32
33 $('.select2-results__option--highlighted').on('click', function (e) {
34 e.preventDefault();
35 console.log($(this));
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 $("#rt-tpg-sc-isotope-filter").on('change', function () {
246 setDefaultItems();
247 });
248 $("#tgp_filter_taxonomy").on('change', function () {
249 setDefaultItemsForFilter();
250 });
251 $("#ttp_filter-_taxonomy_filter").on('change', function () {
252 taxonomyFilterEffect();
253 });
254
255 $("#featured_image_size").on('change', function () {
256 customImageSize();
257 });
258
259 $("#featured_small_image_size").on('change', function () {
260 customSmallImageSize();
261 });
262
263 $("#tpg_load_script").on('change', function () {
264 //preLoaderEffect();
265 });
266
267 $("#show_acf_details").on('change', function () {
268 tpgEnableACF();
269 });
270
271 function preLoaderEffect() {
272 var preLoader = $("#tpg_load_script_holder input[name='tpg_load_script']:checked").val();
273 if (preLoader) {
274 $("#tpg_enable_preloader_holder").show();
275 } else {
276 $("#tpg_enable_preloader_holder").hide();
277 }
278 }
279
280 function tpgEnableACF() {
281 var tpgACF = $("#show_acf_details_holder input[name='show_acf_details']:checked").val();
282 if (tpgACF) {
283 $("#cf_group_details_holder, #cf_hide_empty_value_details_holder, #cf_show_only_value_details_holder, #cf_hide_group_title_details_holder").fadeIn();
284 } else {
285 $("#cf_group_details_holder, #cf_hide_empty_value_details_holder, #cf_show_only_value_details_holder, #cf_hide_group_title_details_holder").fadeOut();
286 }
287 }
288
289 function customImageSize() {
290 /* custom image size jquery */
291 var fImageSize = $("#featured_image_size").val();
292 if (fImageSize == "rt_custom") {
293 $(".rt-sc-custom-image-size-holder").show();
294 } else {
295 $(".rt-sc-custom-image-size-holder").hide();
296 }
297 }
298
299 function customSmallImageSize() {
300 /* custom image size jquery */
301 var fImageSize = $("#featured_small_image_size").val();
302 if (fImageSize == "rt_custom") {
303 $(".rt-sc-custom-small-image-size-holder").show();
304 } else {
305 $(".rt-sc-custom-small-image-size-holder").hide();
306 }
307 }
308
309 function rtTPGlayoutType() {
310 var $layout = $("#rttpg-layout input[name=layout]:checked"),
311 layoutType = $layout.parent('.radio-image').attr('data-type'),
312 selector = ".rt-tpg-radio-layout." + layoutType;
313
314 $('#rttpg-layout .rt-tpg-radio-layout').hide();
315 $('#layout_holder').hide();
316
317 if (layoutType) {
318 $("#rttpg-layout_type input[id=" + layoutType + "]").prop('checked', true);
319 $('#layout_holder').show();
320 $(selector).show();
321 }
322 }
323
324 function rtTPGSelectedlayoutType() {
325 var layout_type = $("#rttpg-layout_type input[name=layout_type]:checked"),
326 layout_type_value = layout_type.val(),
327 selector = ".rt-tpg-radio-layout." + layout_type_value;
328 $('#rttpg-layout .rt-tpg-radio-layout').hide();
329
330 if (layout_type_value == 'grid_hover') {
331 $('#featured_small_image_size_holder').show();
332 customSmallImageSize();
333 } else {
334 $('#featured_small_image_size_holder').hide();
335 $('.rt-sc-custom-small-image-size-holder').hide();
336 }
337
338 if (!layout_type_value) {
339 var selectChildByValue = $("#rttpg-layout input[name=layout]:checked"),
340 ownParent = selectChildByValue.parent('.radio-image'),
341 parentId = ownParent.attr('data-type');
342
343 $("#rttpg-layout_type input[id=" + parentId + "]").prop('checked', true);
344 selector = ".rt-tpg-radio-layout." + parentId;
345 if (!selectChildByValue.val()) {
346 $('#layout_holder').hide();
347 } else {
348 $('#layout_holder').show();
349 }
350 }
351 $(selector).show();
352 }
353
354 function rtTPGIsotopTaxonomyFilter($this) {
355 var arg = "post_type=" + $this.val();
356 var bindElement = $this;
357 var target = $('#tgp_filter_taxonomy_holder select');
358 tpgAjaxCall(bindElement, 'rtTPGIsotopeFilter', arg, function (data) {
359 if (!data.error) {
360 target.html(data.data);
361 setDefaultItems();
362 setDefaultItemsForFilter();
363 tgpLiveReloadScript();
364 } else {
365 console.log(data.msg);
366 }
367 });
368 }
369
370 function tpgTaxonomyFilterTrigger() {
371 var target = $(".field-holder.sc-tpg-filter");
372 if ($("#tgp_filter-_taxonomy_filter").is(':checked')) {
373 target.show();
374 } else {
375 target.hide();
376 }
377 }
378
379 function rtTPGTaxonomyListByPostType(postType, $this) {
380
381 var arg = "post_type=" + postType;
382 var bindElement = $this;
383
384 $('#post-taxonomy input[name="tpg_taxonomy[]"]:checked').each(function() {
385 arg += '&taxonomy[]=' + this.value;
386 });
387
388 tpgAjaxCall(bindElement, 'rtTPGTaxonomyListByPostType', arg, function (data) {
389 if (!data.error) {
390 $('.rt-tpg-filter.taxonomy > .taxonomy-field').html(data.data).show('slow');
391 } else {
392 console.log(data.msg);
393 }
394 });
395 }
396
397 function tlpShowHideScMeta() {
398 tpgTaxonomyFilterTrigger();
399 //var layout = $("#rt-tpg-sc-layout").val(),
400 var layout_type = $("#rttpg-layout_type input[name=layout_type]:checked"),
401 layout = layout_type.val(),
402 selectedLayout = '',
403 isIsotope = false,
404 isCarousel = false,
405 isWc = false,
406 isWcIsotope = false,
407 isWcCarousel = false,
408 isGrid = false,
409 isList = false,
410 isLOffset = false;
411
412 if ($("#rttpg-layout input[name=layout]").length) {
413 selectedLayout = $("#rttpg-layout input[name=layout]:checked").val();
414 }
415
416 if (layout) {
417 isGrid = layout.match(/^grid/i);
418 isList = layout.match(/^list/i);
419 isCarousel = layout.match(/^carousel/i);
420 isIsotope = layout.match(/^isotope/i);
421 isWc = layout.match(/^wc/i) || layout.match(/^edd/i);
422 isWcIsotope = layout.match(/^wc-isotope/i) || layout.match(/^edd-isotope/i);
423 isWcCarousel = layout.match(/^wc-carousel/i) || layout.match(/^edd-carousel/i);
424 isLOffset = layout.match(/^offset/i);
425 var lArray = ['layout4', 'layout5', 'layout6', 'layout7', 'layout8', 'layout9', 'layout10', 'layout13', 'layout15', 'layout16'];
426 var target = jQuery("#rt-tpg-sc-layout").parent();
427 target.find('.description').remove();
428 if ($.inArray(layout, lArray) >= 0) {
429 target.append("<p class='description' style='color:red'>Default or a feature image is mandatory for this layout</p>");
430 }
431 }
432
433 var plType = $("#posts_loading_type");
434 plType.find("label[for='posts_loading_type-pagination'],label[for='posts_loading_type-pagination_ajax']").show();
435 $("#tgp_layout2_image_column_holder").hide();
436
437 if (isGrid || isList || (isWc && !isWcCarousel && !isWcIsotope)) {
438 $("#tgp_filter_holder").show();
439 taxonomyFilterEffect();
440 if (selectedLayout == "layout2" || selectedLayout == "layout3") {
441 $("#tgp_layout2_image_column_holder").show();
442 }
443 $(".field-holder.isotope-item").hide();
444 } else if (isLOffset) {
445 $("#posts_loading_type_holder,.field-holder.isotope-item").hide();
446 $("#tgp_filter_holder").show();
447 taxonomyFilterEffect();
448 $(".field-holder.offset-column-wrap select").find('option[value="4"]').remove();
449 } else if (isCarousel || isWcCarousel) {
450 $(".field-holder.sc-product-filter,.field-holder.pagination, .field-holder.pagination-item,.field-holder.isotope-item,.field-holder.sc-tpg-grid-filter").hide();
451 $(".field-holder.carousel-item").show();
452 } else if (isIsotope) {
453 $(".field-holder.sc-product-filter,.field-holder.carousel-item,.field-holder.sc-tpg-grid-filter").hide();
454 $(".field-holder.isotope-item,.field-holder.pagination").show();
455 $("#posts_loading_type").find("label[for='posts_loading_type-pagination'],label[for='posts_loading_type-pagination_ajax']").hide();
456 var ltype = $("#posts_loading_type").find("input[name=posts_loading_type]:checked").val();
457 if (ltype == "pagination" || ltype == "pagination_ajax") {
458 $("#posts_loading_type").find("label[for='posts_loading_type-load_more'] input").prop("checked", true);
459 }
460 if ($("#rt-tpg-sc-isotope-filter option:selected").length) {
461 setDefaultItems();
462 }
463 } else if (isWc && !isWcIsotope && !isWcCarousel) {
464 $(".field-holder.isotope-item,.field-holder.carousel-item,.field-holder.sc-product-filter,.field-holder.sc-tpg-grid-filter").hide();
465 $(".field-holder.sc-product-filter,.field-holder.pagination").show();
466 } else if (isWcIsotope) {
467 $(".field-holder.sc-product-filter,.field-holder.carousel-item,.field-holder.sc-tpg-grid-filter").hide();
468 $(".field-holder.isotope-item,.field-holder.pagination").show();
469 $("#posts_loading_type").find("label[for='posts_loading_type-pagination'],label[for='posts_loading_type-pagination_ajax']").hide();
470 var ltype = $("#posts_loading_type").find("input[name=posts_loading_type]:checked").val();
471 if (ltype == "pagination" || ltype == "pagination_ajax") {
472 $("#posts_loading_type").find("label[for='posts_loading_type-load_more'] input").prop("checked", true);
473 }
474 if ($("#rt-tpg-sc-isotope-filter option:selected").length) {
475 setDefaultItems();
476 }
477 } else {
478 $(".field-holder.isotope-item,.field-holder.carousel-item,.field-holder.sc-product-filter,.field-holder.sc-tpg-grid-filter").hide();
479 $(".field-holder.pagination").show();
480 }
481 setDefaultItemsForFilter();
482 tpgOrderByEffect();
483 if ($("#post-taxonomy input[name='tpg_taxonomy[]']").is(":checked")) {
484 $(".rt-tpg-filter-item.term-filter-item").show();
485 } else {
486 $(".rt-tpg-filter-item.term-filter-item").hide();
487 }
488
489 var pagination = $("#rt-tpg-pagination").is(':checked');
490
491 if (pagination && ! (isCarousel || isWc || isWcIsotope || isWcCarousel)) {
492 $(".field-holder.pagination-item").show();
493 } else if (pagination && (isLOffset)) {
494 $(".field-holder.posts-per-page").show();
495 $("#posts_loading_type_holder").hide();
496 } else {
497 $(".field-holder.pagination-item").hide();
498 }
499 }
500
501
502
503 function taxonomyFilterEffect() {
504 if ($("#tgp_filter-_taxonomy_filter").is(':checked')) {
505 $(".field-holder.sc-tpg-grid-filter").show();
506 filterEffectToPagination();
507 } else {
508 $(".field-holder.sc-tpg-grid-filter").not("#tgp_filter_holder").hide();
509 }
510 }
511
512 function filterEffectToPagination() {
513 var plType = $("#posts_loading_type"),
514 lType = plType.find("input[name=posts_loading_type]:checked").val();
515 if ($("#tgp_filter_holder input[name='tgp_filter[]']").is(':checked')) {
516 plType.find("label[for='posts_loading_type-pagination']").hide();
517 if (lType == "pagination") {
518 plType.find("label[for='posts_loading_type-pagination_ajax'] input").prop("checked", true);
519 }
520 } else {
521 plType.find("label[for='posts_loading_type-pagination']").show();
522 }
523 }
524
525 function tpgOrderByEffect() {
526 var Oval = $('#order_by').val(),
527 vList = ['meta_value_num', 'meta_value', 'meta_value_datetime'];
528
529 if ($.inArray(Oval, vList) !== -1) {
530 $('#tpg_meta_key_holder').show();
531 } else {
532 $('#tpg_meta_key_holder').hide();
533 }
534 }
535
536 $('#term_category_holder select').on('change', function (e) {
537 setDefaultItems();
538 if ($("#tgp_filter-_taxonomy_filter").is(':checked')) {
539 setDefaultItemsForFilter();
540 }
541 });
542
543 $('#term_post_tag_holder select').on('change', function (e) {
544 setDefaultItems();
545 if ($("#tgp_filter-_taxonomy_filter").is(':checked')) {
546 setDefaultItemsForFilter();
547 }
548 });
549
550 function setDefaultItems() {
551 var target_from = $("#rt-tpg-sc-isotope-filter"),
552 target = $("#rt-tpg-sc-isotope-default-filter"),
553 $fId = target_from.val();
554
555 var $term = [];
556
557 if ($fId == 'category') {
558 if ($('#term_category_holder').length && $('#post-taxonomy-category')) {
559 var selected_term = $('#term_category_holder select').select2('data');
560 selected_term.forEach(function (element) {
561 $term.push(element.id);
562 });
563 }
564 } else if ($fId == 'post_tag') {
565 $term = [];
566 if ($('#term_post_tag_holder').length && $('#post-taxonomy-post_tag')) {
567 var selected_term = $('#term_post_tag_holder select').select2('data');
568 selected_term.forEach(function (element) {
569 $term.push(element.id);
570 });
571 }
572 }
573
574 if ($fId) {
575 var data = 'action=defaultFilterItem&filter=' + $fId + '&include=' + $term + "&rttpg_nonce=" + rttpg.nonce;
576 $.ajax({
577 type: "post",
578 url: rttpg.ajaxurl,
579 data: data,
580 beforeSend: function () {
581 $("<span class='rt-loading'></span>").insertAfter(target);
582 },
583 success: function (data) {
584 if (!data.error) {
585 var selected = target.data('selected');
586 target.html(data.data);
587 if (selected) {
588 target.val(selected).trigger("change");
589 }
590 } else {
591 console.log(data.msg);
592 }
593 target.parent().find(".rt-loading").remove();
594 },
595 error: function () {
596 target.parent().find(".rt-loading").remove();
597 }
598 });
599 }
600 }
601
602 function setDefaultItemsForFilter() {
603 var target_from = $("#tgp_filter_taxonomy"),
604 target = $('#tgp_default_filter'),
605 $fId = target_from.val();
606
607 var $term = [];
608
609 if ($fId == 'category') {
610 if ($('#term_category_holder').length && $('#post-taxonomy-category')) {
611 var selected_term = $('#term_category_holder select').select2('data');
612 selected_term.forEach(function (element) {
613 $term.push(element.id);
614 });
615 }
616 } else if ($fId == 'post_tag') {
617 $term = [];
618 if ($('#term_post_tag_holder').length && $('#post-taxonomy-post_tag')) {
619 var selected_term = $('#term_post_tag_holder select').select2('data');
620 selected_term.forEach(function (element) {
621 $term.push(element.id);
622 });
623 }
624 }
625
626 if ($fId) {
627 var data = 'action=defaultFilterItem&filter=' + $fId + '&include=' + $term + "&rttpg_nonce=" + rttpg.nonce;
628 $.ajax({
629 type: "post",
630 url: rttpg.ajaxurl,
631 data: data,
632 beforeSend: function () {
633 $("<span class='rt-loading'></span>").insertAfter(target);
634 },
635 success: function (data) {
636 if (!data.error) {
637 var selected = target.data('selected');
638 target.html(data.data);
639 if (selected) {
640 target.val(selected).trigger("change");
641 }
642
643 } else {
644 console.log(data.msg);
645 }
646 target.next(".rt-loading").remove();
647 }
648 });
649 }
650 }
651
652 function rtTPGIsotopeFilter($this) {
653 var arg = "post_type=" + $this.val();
654 var bindElement = $this;
655 var target = jQuery('.field-holder.sc-isotope-filter .field > select');
656 tpgAjaxCall(bindElement, 'rtTPGIsotopeFilter', arg, function (data) {
657 if (!data.error) {
658 target.html(data.data);
659 setDefaultItems();
660 tgpLiveReloadScript();
661 } else {
662 console.log(data.msg);
663 }
664 });
665 }
666
667 function rtTPGTermListByTaxonomy($this) {
668 var term = $this.val();
669 var targetHolder = $('.rt-tpg-filter.taxonomy').children('.rt-tpg-filter-item').children('.field-holder').children('.term-filter-holder');
670 var target = targetHolder.children('.term-filter-item-container.' + term);
671 if ($this.is(':checked')) {
672 var arg = "taxonomy=" + $this.val();
673 var bindElement = $this;
674 tpgAjaxCall(bindElement, 'rtTPGTermListByTaxonomy', arg, function (data) {
675 if (!data.error) {
676 targetHolder.show();
677 $(data.data).prependTo(targetHolder).fadeIn('slow');
678 tgpLiveReloadScript();
679 } else {
680 console.log(data.msg)
681 }
682 });
683 } else {
684 target.hide('slow').html('').remove();
685 }
686
687 var termLength = jQuery('input[name="tpg_taxonomy[]"]:checked').length;
688 if (termLength > 1) {
689 $('.field-holder.term-filter-item-relation ').show('slow');
690 } else {
691 $('.field-holder.term-filter-item-relation ').hide('slow');
692 }
693
694 }
695
696 function detailLinkEffect() {
697 var detailPageLink = $("#link_to_detail_page_holder input[name='link_to_detail_page']:checked").val();
698 if (detailPageLink) {
699 $(".field-holder.detail-page-link-type").show();
700 } else {
701 $(".field-holder.detail-page-link-type,.field-holder.popup-type,.field-holder.tpg-link-target").hide();
702 }
703 linkTypeEffect();
704 }
705
706 function linkTypeEffect() {
707 var linkType = $("#detail_page_link_type_holder input[name='detail_page_link_type']:checked").val(),
708 detailPageLink = $("#link_to_detail_page_holder input[name='link_to_detail_page']:checked").val();
709 if (linkType == "popup" && detailPageLink) {
710 $(".field-holder.popup-type").show();
711 $(".field-holder.tpg-link-target").hide()
712 } else {
713 $(".field-holder.popup-type").hide();
714 $(".field-holder.tpg-link-target").show();
715 }
716 }
717
718 function tpgAjaxCall(element, action, arg, handle) {
719 var data;
720 if (action) data = "action=" + action;
721 if (arg) data = arg + "&action=" + action;
722 if (arg && !action) data = arg;
723
724 var n = data.search(rttpg.nonceID);
725 if (n < 0) {
726 data = data + "&rttpg_nonce=" + rttpg.nonce;
727 }
728 $.ajax({
729 type: "post",
730 url: rttpg.ajaxurl,
731 data: data,
732 beforeSend: function () {
733 $("<span class='rt-loading'></span>").insertAfter(element);
734 },
735 success: function (data) {
736 element.next(".rt-loading").remove();
737 handle(data);
738 },
739 error: function (e) {
740 element.next(".rt-loading").remove();
741 console.log(e);
742 }
743 });
744 }
745
746 $("#rt-tpg-settings-form").on('click', '.rt-licensing-btn', function (e) {
747 e.preventDefault();
748 var self = $(this),
749 type = self.attr('name'),
750 data = 'type=' + type;
751 $("#license_key_holder").find(".rt-licence-msg").remove();
752 tpgAjaxCall(self, 'rtTPGManageLicencing', data, function (data) {
753 if (!data.error) {
754 self.val(data.value);
755 self.attr('name', data.name);
756 self.addClass(data.class);
757 if (data.name == 'license_deactivate') {
758 self.removeClass('button-primary');
759 self.addClass('danger');
760 } else if (data.name == 'license_activate') {
761 self.removeClass('danger');
762 self.addClass('button-primary');
763 }
764 }
765 if (data.msg) {
766 $("<div class='rt-licence-msg'>" + data.msg + "</div>").insertAfter(self);
767 }
768 self.blur();
769 });
770
771 return false;
772 });
773
774 $("#rt-tpg-settings-form").on('click', '.rtSaveButton', function (e) {
775 e.preventDefault();
776 $('.rt-response').hide();
777 var arg = $("#rt-tpg-settings-form").serialize();
778 var bindElement = $('.rtSaveButton');
779 tpgAjaxCall(bindElement, 'rtTPGSettings', arg, function (data) {
780 if (data.error) {
781 $('.rt-response').addClass('error');
782 $('.rt-response').show('slow').text(data.msg);
783 } else {
784 $('.rt-response').addClass('updated');
785 $('.rt-response').removeClass('error');
786 $('.rt-response').show('slow').text(data.msg);
787 var holder = $("#license_key_holder");
788 if (!$(".license-status", holder).length && $("#license_key", holder).val()) {
789 var bindElement = $("#license_key", holder),
790 target = $(".description", holder);
791 target.find(".rt-licence-msg").remove();
792 tpgAjaxCall(bindElement, 'rtTPG_active_Licence', '', function (data) {
793 if (!data.error) {
794 target.append("<span class='license-status'>" + data.html + "</span>");
795 }
796 if (data.msg) {
797 if (target.find(".rt-licence-msg").length) {
798 target.find(".rt-licence-msg").html(data.msg);
799 } else {
800 target.append("<span class='rt-licence-msg'>" + data.msg + "</span>");
801 }
802 if (!data.error) {
803 target.find(".rt-licence-msg").addClass('success');
804 }
805 }
806 });
807 }
808 if (!$("#license_key", holder).val()) {
809 $('.license-status', holder).remove();
810 }
811 }
812 });
813 return false;
814 });
815
816 function rtTgpFilter() {
817 $("#post_filter input[type=checkbox]:checked").each(function () {
818 var id = $(this).val();
819 if (id == 'tpg_taxonomy') {
820 if (this.checked) {
821 rtTPGTaxonomyListByPostType(postType, $(this));
822 } else {
823 $('.rt-tpg-filter.taxonomy > .taxonomy-field').hide('slow').html('');
824 $('.rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-holder').hide('slow').html('');
825 $('.rt-tpg-filter.taxonomy > .rt-tpg-filter-item .term-filter-item-relation').hide('slow');
826 }
827 }
828 $(".rt-tpg-filter." + id).show();
829 });
830
831 $("#post-taxonomy input[type=checkbox]:checked").each(function () {
832 var id = $(this).val();
833 $(".filter-item." + id).show();
834 });
835 }
836
837 function tgpLiveReloadScript() {
838 $("select.rt-select2").select2({
839 theme: "classic",
840 dropdownAutoWidth: true,
841 width: '100%'
842 });
843 }
844
845 })(this, jQuery);