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