| 1 |
var WPUltimatePostGrid = WPUltimatePostGrid || {}; |
| 2 |
|
| 3 |
WPUltimatePostGrid.post_type = null; |
| 4 |
WPUltimatePostGrid.filter_possible = false; |
| 5 |
WPUltimatePostGrid.premium_features_used = []; |
| 6 |
|
| 7 |
WPUltimatePostGrid.initForm = function() { |
| 8 |
// General selects |
| 9 |
jQuery('.wpupg-select2').select2wpupg({ |
| 10 |
width: '100%' |
| 11 |
}); |
| 12 |
|
| 13 |
// Multiselect with order |
| 14 |
jQuery('select.wpupg_filter_taxonomy').on('select2wpupg:select', function (evt) { |
| 15 |
var element = evt.params.data.element; |
| 16 |
var $element = jQuery(element); |
| 17 |
|
| 18 |
$element.detach(); |
| 19 |
jQuery(this).append($element); |
| 20 |
jQuery(this).trigger('change'); |
| 21 |
}); |
| 22 |
|
| 23 |
// Datepicker |
| 24 |
jQuery('#wpupg_rules').find('.wpupg-date').datepicker(); |
| 25 |
|
| 26 |
// Sliders |
| 27 |
var slider_args = { |
| 28 |
start: 1, |
| 29 |
step: 1, |
| 30 |
range: { |
| 31 |
'min': 1, |
| 32 |
'max': 500 |
| 33 |
}, |
| 34 |
behaviour: 'tap-drag', |
| 35 |
format: wNumb({ |
| 36 |
decimals: 0 |
| 37 |
}) |
| 38 |
}; |
| 39 |
|
| 40 |
var posts_per_page = jQuery('#wpupg_pagination_pages_posts_per_page'); |
| 41 |
slider_args.start = posts_per_page.val(); |
| 42 |
jQuery('#wpupg_pagination_pages_posts_per_page_slider').noUiSlider(slider_args).Link('lower').to(posts_per_page); |
| 43 |
|
| 44 |
var infinite_posts = jQuery('#wpupg_pagination_infinite_load_initial_posts'); |
| 45 |
slider_args.start = infinite_posts.val(); |
| 46 |
jQuery('#wpupg_pagination_infinite_load_initial_posts_slider').noUiSlider(slider_args).Link('lower').to(infinite_posts); |
| 47 |
|
| 48 |
var posts_on_scroll = jQuery('#wpupg_pagination_infinite_load_posts_on_scroll'); |
| 49 |
slider_args.start = posts_on_scroll.val(); |
| 50 |
jQuery('#wpupg_pagination_infinite_load_posts_on_scroll_slider').noUiSlider(slider_args).Link('lower').to(posts_on_scroll); |
| 51 |
|
| 52 |
var initial_posts = jQuery('#wpupg_pagination_load_more_initial_posts'); |
| 53 |
slider_args.start = initial_posts.val(); |
| 54 |
jQuery('#wpupg_pagination_load_more_initial_posts_slider').noUiSlider(slider_args).Link('lower').to(initial_posts); |
| 55 |
|
| 56 |
var posts_on_click = jQuery('#wpupg_pagination_load_more_posts_on_click'); |
| 57 |
slider_args.start = posts_on_click.val(); |
| 58 |
jQuery('#wpupg_pagination_load_more_posts_on_click_slider').noUiSlider(slider_args).Link('lower').to(posts_on_click); |
| 59 |
|
| 60 |
var initial_posts_filter = jQuery('#wpupg_pagination_load_filter_initial_posts'); |
| 61 |
slider_args.start = initial_posts_filter.val(); |
| 62 |
jQuery('#wpupg_pagination_load_filter_initial_posts_slider').noUiSlider(slider_args).Link('lower').to(initial_posts_filter); |
| 63 |
|
| 64 |
slider_args = { |
| 65 |
start: 0, |
| 66 |
step: 1, |
| 67 |
range: { |
| 68 |
'min': 0, |
| 69 |
'max': 50 |
| 70 |
}, |
| 71 |
behaviour: 'tap-drag', |
| 72 |
format: wNumb({ |
| 73 |
decimals: 0 |
| 74 |
}) |
| 75 |
}; |
| 76 |
|
| 77 |
var isotope_margin_vertical = jQuery('#wpupg_isotope_filter_style_margin_vertical'); |
| 78 |
slider_args.start = isotope_margin_vertical.val(); |
| 79 |
jQuery('#wpupg_isotope_filter_style_margin_vertical_slider').noUiSlider(slider_args).on({ |
| 80 |
slide: function() { |
| 81 |
WPUltimatePostGrid.changedIsotopeFilterStyle(); |
| 82 |
} |
| 83 |
}).Link('lower').to(isotope_margin_vertical); |
| 84 |
|
| 85 |
var isotope_margin_horizontal = jQuery('#wpupg_isotope_filter_style_margin_horizontal'); |
| 86 |
slider_args.start = isotope_margin_horizontal.val(); |
| 87 |
jQuery('#wpupg_isotope_filter_style_margin_horizontal_slider').noUiSlider(slider_args).on({ |
| 88 |
slide: function() { |
| 89 |
WPUltimatePostGrid.changedIsotopeFilterStyle(); |
| 90 |
} |
| 91 |
}).Link('lower').to(isotope_margin_horizontal); |
| 92 |
|
| 93 |
var isotope_padding_vertical = jQuery('#wpupg_isotope_filter_style_padding_vertical'); |
| 94 |
slider_args.start = isotope_padding_vertical.val(); |
| 95 |
jQuery('#wpupg_isotope_filter_style_padding_vertical_slider').noUiSlider(slider_args).on({ |
| 96 |
slide: function() { |
| 97 |
WPUltimatePostGrid.changedIsotopeFilterStyle(); |
| 98 |
} |
| 99 |
}).Link('lower').to(isotope_padding_vertical); |
| 100 |
|
| 101 |
var isotope_padding_horizontal = jQuery('#wpupg_isotope_filter_style_padding_horizontal'); |
| 102 |
slider_args.start = isotope_padding_horizontal.val(); |
| 103 |
jQuery('#wpupg_isotope_filter_style_padding_horizontal_slider').noUiSlider(slider_args).on({ |
| 104 |
slide: function() { |
| 105 |
WPUltimatePostGrid.changedIsotopeFilterStyle(); |
| 106 |
} |
| 107 |
}).Link('lower').to(isotope_padding_horizontal); |
| 108 |
|
| 109 |
var isotope_border_width = jQuery('#wpupg_isotope_filter_style_border_width'); |
| 110 |
slider_args.start = isotope_border_width.val(); |
| 111 |
jQuery('#wpupg_isotope_filter_style_border_width_slider').noUiSlider(slider_args).on({ |
| 112 |
slide: function() { |
| 113 |
WPUltimatePostGrid.changedIsotopeFilterStyle(); |
| 114 |
} |
| 115 |
}).Link('lower').to(isotope_border_width); |
| 116 |
|
| 117 |
|
| 118 |
var pagination_margin_vertical = jQuery('#wpupg_pagination_style_margin_vertical'); |
| 119 |
slider_args.start = pagination_margin_vertical.val(); |
| 120 |
jQuery('#wpupg_pagination_style_margin_vertical_slider').noUiSlider(slider_args).on({ |
| 121 |
slide: function() { |
| 122 |
WPUltimatePostGrid.changedPaginationStyle(); |
| 123 |
} |
| 124 |
}).Link('lower').to(pagination_margin_vertical); |
| 125 |
|
| 126 |
var pagination_margin_horizontal = jQuery('#wpupg_pagination_style_margin_horizontal'); |
| 127 |
slider_args.start = pagination_margin_horizontal.val(); |
| 128 |
jQuery('#wpupg_pagination_style_margin_horizontal_slider').noUiSlider(slider_args).on({ |
| 129 |
slide: function() { |
| 130 |
WPUltimatePostGrid.changedPaginationStyle(); |
| 131 |
} |
| 132 |
}).Link('lower').to(pagination_margin_horizontal); |
| 133 |
|
| 134 |
var pagination_padding_vertical = jQuery('#wpupg_pagination_style_padding_vertical'); |
| 135 |
slider_args.start = pagination_padding_vertical.val(); |
| 136 |
jQuery('#wpupg_pagination_style_padding_vertical_slider').noUiSlider(slider_args).on({ |
| 137 |
slide: function() { |
| 138 |
WPUltimatePostGrid.changedPaginationStyle(); |
| 139 |
} |
| 140 |
}).Link('lower').to(pagination_padding_vertical); |
| 141 |
|
| 142 |
var pagination_padding_horizontal = jQuery('#wpupg_pagination_style_padding_horizontal'); |
| 143 |
slider_args.start = pagination_padding_horizontal.val(); |
| 144 |
jQuery('#wpupg_pagination_style_padding_horizontal_slider').noUiSlider(slider_args).on({ |
| 145 |
slide: function() { |
| 146 |
WPUltimatePostGrid.changedPaginationStyle(); |
| 147 |
} |
| 148 |
}).Link('lower').to(pagination_padding_horizontal); |
| 149 |
|
| 150 |
var pagination_border_width = jQuery('#wpupg_pagination_style_border_width'); |
| 151 |
slider_args.start = pagination_border_width.val(); |
| 152 |
jQuery('#wpupg_pagination_style_border_width_slider').noUiSlider(slider_args).on({ |
| 153 |
slide: function() { |
| 154 |
WPUltimatePostGrid.changedPaginationStyle(); |
| 155 |
} |
| 156 |
}).Link('lower').to(pagination_border_width); |
| 157 |
|
| 158 |
// Color Pickers |
| 159 |
jQuery('#wpupg_isotope_filter_style_background_color').wpColorPicker({ |
| 160 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 161 |
}); |
| 162 |
jQuery('#wpupg_isotope_filter_style_background_active_color').wpColorPicker({ |
| 163 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 164 |
}); |
| 165 |
jQuery('#wpupg_isotope_filter_style_background_hover_color').wpColorPicker({ |
| 166 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 167 |
}); |
| 168 |
jQuery('#wpupg_isotope_filter_style_text_color').wpColorPicker({ |
| 169 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 170 |
}); |
| 171 |
jQuery('#wpupg_isotope_filter_style_text_active_color').wpColorPicker({ |
| 172 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 173 |
}); |
| 174 |
jQuery('#wpupg_isotope_filter_style_text_hover_color').wpColorPicker({ |
| 175 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 176 |
}); |
| 177 |
jQuery('#wpupg_isotope_filter_style_border_color').wpColorPicker({ |
| 178 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 179 |
}); |
| 180 |
jQuery('#wpupg_isotope_filter_style_border_active_color').wpColorPicker({ |
| 181 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 182 |
}); |
| 183 |
jQuery('#wpupg_isotope_filter_style_border_hover_color').wpColorPicker({ |
| 184 |
change: function () { WPUltimatePostGrid.changedIsotopeFilterStyle(); } |
| 185 |
}); |
| 186 |
|
| 187 |
jQuery('#wpupg_pagination_style_background_color').wpColorPicker({ |
| 188 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 189 |
}); |
| 190 |
jQuery('#wpupg_pagination_style_background_active_color').wpColorPicker({ |
| 191 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 192 |
}); |
| 193 |
jQuery('#wpupg_pagination_style_background_hover_color').wpColorPicker({ |
| 194 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 195 |
}); |
| 196 |
jQuery('#wpupg_pagination_style_text_color').wpColorPicker({ |
| 197 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 198 |
}); |
| 199 |
jQuery('#wpupg_pagination_style_text_active_color').wpColorPicker({ |
| 200 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 201 |
}); |
| 202 |
jQuery('#wpupg_pagination_style_text_hover_color').wpColorPicker({ |
| 203 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 204 |
}); |
| 205 |
jQuery('#wpupg_pagination_style_border_color').wpColorPicker({ |
| 206 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 207 |
}); |
| 208 |
jQuery('#wpupg_pagination_style_border_active_color').wpColorPicker({ |
| 209 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 210 |
}); |
| 211 |
jQuery('#wpupg_pagination_style_border_hover_color').wpColorPicker({ |
| 212 |
change: function () { WPUltimatePostGrid.changedPaginationStyle(); } |
| 213 |
}); |
| 214 |
|
| 215 |
// Initial State |
| 216 |
WPUltimatePostGrid.changedType(); |
| 217 |
WPUltimatePostGrid.changedPostType(); |
| 218 |
WPUltimatePostGrid.changedOrderBy(); |
| 219 |
WPUltimatePostGrid.changedLimitPosts(); |
| 220 |
WPUltimatePostGrid.initRules(); |
| 221 |
WPUltimatePostGrid.changedFilterType(); |
| 222 |
WPUltimatePostGrid.changedShowCount(); |
| 223 |
WPUltimatePostGrid.changedMultiselect(); |
| 224 |
WPUltimatePostGrid.changedLimitTerms(); |
| 225 |
WPUltimatePostGrid.changedDropdownLabels(); |
| 226 |
WPUltimatePostGrid.changedIsotopeFilterStyle(); |
| 227 |
WPUltimatePostGrid.changedIsotopeFilterText(); |
| 228 |
WPUltimatePostGrid.changedLayoutMode(); |
| 229 |
WPUltimatePostGrid.changedPaginationStyle(); |
| 230 |
WPUltimatePostGrid.changedPaginationType(); |
| 231 |
WPUltimatePostGrid.changedPaginationText(); |
| 232 |
|
| 233 |
// Events |
| 234 |
jQuery('#wpupg_type').on('change', function() { WPUltimatePostGrid.changedType(); }); |
| 235 |
jQuery('#wpupg_post_types').on('change', function() { WPUltimatePostGrid.changedPostType(); }); |
| 236 |
jQuery('#wpupg_order_by').on('change', function() { WPUltimatePostGrid.changedOrderBy(); }); |
| 237 |
jQuery('#wpupg_limit_posts').on('change', function() { WPUltimatePostGrid.changedLimitPosts(); }); |
| 238 |
jQuery('#wpupg_add_rule').on('click', function(e) { e.preventDefault(); WPUltimatePostGrid.addRule(); }); |
| 239 |
jQuery('.wpupg_rule_delete').on('click', function(e) { e.preventDefault(); WPUltimatePostGrid.removeRule(jQuery(this).parents('tr').attr('data-rule')); }); |
| 240 |
jQuery('.wpupg_rule_field').on('change', function(e) { WPUltimatePostGrid.changedRuleField(jQuery(this).parents('tr').attr('data-rule')); }); |
| 241 |
jQuery('.rule_container_wpupg_general_date').find('select').on('change', function(e) { WPUltimatePostGrid.changedDateRule(jQuery(this).parents('tr').attr('data-rule')); }); |
| 242 |
jQuery('.wpupg-date').on('change', function(e) { WPUltimatePostGrid.changedDateRule(jQuery(this).parents('tr').attr('data-rule')); }); |
| 243 |
jQuery('#wpupg_filter_type').on('change', function() { WPUltimatePostGrid.changedFilterType(); }); |
| 244 |
jQuery('#wpupg_filter_count').on('change', function() { WPUltimatePostGrid.changedShowCount(); }); |
| 245 |
jQuery('#wpupg_filter_multiselect').on('change', function() { WPUltimatePostGrid.changedMultiselect(); }); |
| 246 |
jQuery('.wpupg_filter_taxonomy').on('change', function() { WPUltimatePostGrid.changedLimitTerms(); WPUltimatePostGrid.changedDropdownLabels(); }); |
| 247 |
jQuery('#wpupg_filter_limit').on('change', function() { WPUltimatePostGrid.changedLimitTerms(); }); |
| 248 |
jQuery('#wpupg_layout_mode').on('change', function() { WPUltimatePostGrid.changedLayoutMode(); }); |
| 249 |
jQuery('#wpupg_pagination_type').on('change', function() { WPUltimatePostGrid.changedPaginationType(); }); |
| 250 |
jQuery('#wpupg_pagination_load_more_button_text').on('change keyup', function() { WPUltimatePostGrid.changedPaginationText(); }); |
| 251 |
|
| 252 |
isotope_margin_vertical.on('change', function() { WPUltimatePostGrid.changedIsotopeFilterStyle(); }); |
| 253 |
isotope_margin_horizontal.on('change', function() { WPUltimatePostGrid.changedIsotopeFilterStyle(); }); |
| 254 |
isotope_padding_vertical.on('change', function() { WPUltimatePostGrid.changedIsotopeFilterStyle(); }); |
| 255 |
isotope_padding_horizontal.on('change', function() { WPUltimatePostGrid.changedIsotopeFilterStyle(); }); |
| 256 |
isotope_border_width.on('change', function() { WPUltimatePostGrid.changedIsotopeFilterStyle(); }); |
| 257 |
jQuery('#wpupg_isotope_filter_style_alignment').on('change', function() { WPUltimatePostGrid.changedIsotopeFilterStyle(); }); |
| 258 |
jQuery('#wpupg_isotope_filter_style_all_button_text').on('change keyup', function() { WPUltimatePostGrid.changedIsotopeFilterText(); }); |
| 259 |
|
| 260 |
pagination_margin_vertical.on('change', function() { WPUltimatePostGrid.changedPaginationStyle(); }); |
| 261 |
pagination_margin_horizontal.on('change', function() { WPUltimatePostGrid.changedPaginationStyle(); }); |
| 262 |
pagination_padding_vertical.on('change', function() { WPUltimatePostGrid.changedPaginationStyle(); }); |
| 263 |
pagination_padding_horizontal.on('change', function() { WPUltimatePostGrid.changedPaginationStyle(); }); |
| 264 |
pagination_border_width.on('change', function() { WPUltimatePostGrid.changedPaginationStyle(); }); |
| 265 |
jQuery('#wpupg_pagination_style_alignment').on('change', function() { WPUltimatePostGrid.changedPaginationStyle(); }); |
| 266 |
|
| 267 |
jQuery('.wpupg-filter-isotope-term').hover(function() { |
| 268 |
if(!jQuery(this).hasClass('active')) { |
| 269 |
var background_hover_color = jQuery('#wpupg_isotope_filter_style_background_hover_color').wpColorPicker('color'); |
| 270 |
var text_hover_color = jQuery('#wpupg_isotope_filter_style_text_hover_color').wpColorPicker('color'); |
| 271 |
var border_hover_color = jQuery('#wpupg_isotope_filter_style_border_hover_color').wpColorPicker('color'); |
| 272 |
|
| 273 |
jQuery(this) |
| 274 |
.css('background-color', background_hover_color) |
| 275 |
.css('color', text_hover_color) |
| 276 |
.css('border-color', border_hover_color) |
| 277 |
; |
| 278 |
} |
| 279 |
}, function() { |
| 280 |
if(!jQuery(this).hasClass('active')) { |
| 281 |
var background_color = jQuery('#wpupg_isotope_filter_style_background_color').wpColorPicker('color'); |
| 282 |
var text_color = jQuery('#wpupg_isotope_filter_style_text_color').wpColorPicker('color'); |
| 283 |
var border_color = jQuery('#wpupg_isotope_filter_style_border_color').wpColorPicker('color'); |
| 284 |
|
| 285 |
jQuery(this) |
| 286 |
.css( 'background-color', background_color ) |
| 287 |
.css( 'color', text_color) |
| 288 |
.css( 'border-color', border_color ) |
| 289 |
; |
| 290 |
} |
| 291 |
}); |
| 292 |
|
| 293 |
jQuery('.wpupg-pagination-term').hover(function() { |
| 294 |
if(!jQuery(this).hasClass('active')) { |
| 295 |
var background_hover_color = jQuery('#wpupg_pagination_style_background_hover_color').wpColorPicker('color'); |
| 296 |
var text_hover_color = jQuery('#wpupg_pagination_style_text_hover_color').wpColorPicker('color'); |
| 297 |
var border_hover_color = jQuery('#wpupg_pagination_style_border_hover_color').wpColorPicker('color'); |
| 298 |
|
| 299 |
jQuery(this) |
| 300 |
.css('background-color', background_hover_color) |
| 301 |
.css('color', text_hover_color) |
| 302 |
.css('border-color', border_hover_color) |
| 303 |
; |
| 304 |
} |
| 305 |
}, function() { |
| 306 |
if(!jQuery(this).hasClass('active')) { |
| 307 |
var background_color = jQuery('#wpupg_pagination_style_background_color').wpColorPicker('color'); |
| 308 |
var text_color = jQuery('#wpupg_pagination_style_text_color').wpColorPicker('color'); |
| 309 |
var border_color = jQuery('#wpupg_pagination_style_border_color').wpColorPicker('color'); |
| 310 |
|
| 311 |
jQuery(this) |
| 312 |
.css( 'background-color', background_color ) |
| 313 |
.css( 'color', text_color) |
| 314 |
.css( 'border-color', border_color ) |
| 315 |
; |
| 316 |
} |
| 317 |
}); |
| 318 |
}; |
| 319 |
|
| 320 |
WPUltimatePostGrid.changedType = function() { |
| 321 |
var type = jQuery('#wpupg_type').find(':selected').val(); |
| 322 |
|
| 323 |
if( type == 'terms' ) { |
| 324 |
WPUltimatePostGrid.checkPremiumFeatures('type', true); |
| 325 |
jQuery('#wpupg_meta_box_data_source_terms').show(); |
| 326 |
|
| 327 |
jQuery('#wpupg_meta_box_data_source').hide(); |
| 328 |
jQuery('#wpupg_meta_box_limit_posts').hide(); |
| 329 |
jQuery('#wpupg_meta_box_filter').hide(); |
| 330 |
jQuery('#wpupg_meta_box_isotope_filter').hide(); |
| 331 |
jQuery('#wpupg_meta_box_pagination').hide(); |
| 332 |
jQuery('#wpupg_meta_box_pagination_style').hide(); |
| 333 |
} else { |
| 334 |
WPUltimatePostGrid.checkPremiumFeatures('type', false); |
| 335 |
jQuery('#wpupg_meta_box_data_source_terms').hide(); |
| 336 |
|
| 337 |
jQuery('#wpupg_meta_box_data_source').show(); |
| 338 |
jQuery('#wpupg_meta_box_limit_posts').show(); |
| 339 |
jQuery('#wpupg_meta_box_filter').show(); |
| 340 |
jQuery('#wpupg_meta_box_isotope_filter').show(); |
| 341 |
jQuery('#wpupg_meta_box_pagination').show(); |
| 342 |
jQuery('#wpupg_meta_box_pagination_style').show(); |
| 343 |
|
| 344 |
WPUltimatePostGrid.changedLimitPosts(); |
| 345 |
WPUltimatePostGrid.changedFilterType(); |
| 346 |
WPUltimatePostGrid.changedPaginationType(); |
| 347 |
} |
| 348 |
}; |
| 349 |
|
| 350 |
WPUltimatePostGrid.changedPostType = function() { |
| 351 |
var post_type = jQuery('#wpupg_post_types').find(':selected').val(); |
| 352 |
|
| 353 |
jQuery('.wpupg_filter_taxonomy_container').hide(); |
| 354 |
var container = jQuery('#wpupg_filter_taxonomy_' + post_type + '_container'); |
| 355 |
|
| 356 |
if(container.length > 0) { |
| 357 |
jQuery('#wpupg_no_taxonomies').hide(); |
| 358 |
jQuery('#wpupg_form_filter').show(); |
| 359 |
container.show(); |
| 360 |
WPUltimatePostGrid.filter_possible = true; |
| 361 |
} else { |
| 362 |
jQuery('#wpupg_no_taxonomies').show(); |
| 363 |
jQuery('#wpupg_form_filter').hide(); |
| 364 |
WPUltimatePostGrid.filter_possible = false; |
| 365 |
} |
| 366 |
|
| 367 |
WPUltimatePostGrid.changedFilterType(); |
| 368 |
WPUltimatePostGrid.changedLimitTerms(); |
| 369 |
WPUltimatePostGrid.changedDropdownLabels(); |
| 370 |
}; |
| 371 |
|
| 372 |
WPUltimatePostGrid.changedOrderBy = function() { |
| 373 |
var order_by = jQuery('#wpupg_order_by').find(':selected').val(); |
| 374 |
|
| 375 |
if(order_by == 'custom') { |
| 376 |
WPUltimatePostGrid.checkPremiumFeatures('order_by', true); |
| 377 |
jQuery('.wpupg_order_custom_key_container').show(); |
| 378 |
} else { |
| 379 |
WPUltimatePostGrid.checkPremiumFeatures('order_by', false); |
| 380 |
jQuery('.wpupg_order_custom_key_container').hide(); |
| 381 |
} |
| 382 |
}; |
| 383 |
|
| 384 |
WPUltimatePostGrid.changedLimitPosts = function() { |
| 385 |
if(jQuery('#wpupg_limit_posts').is(':checked')) { |
| 386 |
WPUltimatePostGrid.checkPremiumFeatures('limit_posts', true); |
| 387 |
jQuery('#wpupg_meta_box_limit_posts').show(); |
| 388 |
} else { |
| 389 |
WPUltimatePostGrid.checkPremiumFeatures('limit_posts', false); |
| 390 |
jQuery('#wpupg_meta_box_limit_posts').hide(); |
| 391 |
} |
| 392 |
}; |
| 393 |
|
| 394 |
WPUltimatePostGrid.initRules = function() { |
| 395 |
jQuery('#wpupg_rules').find('tr').each(function() { |
| 396 |
var rule = jQuery(this); |
| 397 |
|
| 398 |
rule |
| 399 |
.find('select') |
| 400 |
.select2wpupg({ |
| 401 |
width: '100%' |
| 402 |
}) |
| 403 |
; |
| 404 |
|
| 405 |
WPUltimatePostGrid.changedRuleField(rule.attr('data-rule')); |
| 406 |
}); |
| 407 |
}; |
| 408 |
|
| 409 |
WPUltimatePostGrid.addRule = function() { |
| 410 |
var rules = jQuery('#wpupg_rules'); |
| 411 |
var rule_id = rules.find('tr:last').attr('data-rule'); |
| 412 |
rule_id = rule_id == undefined ? 1 : parseInt(rule_id) + 1; |
| 413 |
|
| 414 |
var new_rule = jQuery('#wpupg_rule_placeholder').find('tr').first().clone(true); |
| 415 |
|
| 416 |
new_rule |
| 417 |
.appendTo(rules) |
| 418 |
.attr('id', function(index, val) { |
| 419 |
return val.replace(/(\d+)/, rule_id); |
| 420 |
}) |
| 421 |
.attr('data-rule', function(index, val) { |
| 422 |
return val.replace(/(\d+)/, rule_id); |
| 423 |
}) |
| 424 |
.find('select, input') |
| 425 |
.attr('name', function(index, val) { |
| 426 |
return val.replace(/(\d+)/, rule_id); |
| 427 |
}) |
| 428 |
.attr('id', function(index, val) { |
| 429 |
return val.replace(/(\d+)/, rule_id); |
| 430 |
}) |
| 431 |
; |
| 432 |
|
| 433 |
new_rule |
| 434 |
.find('select') |
| 435 |
.select2wpupg({ |
| 436 |
width: '100%' |
| 437 |
}) |
| 438 |
; |
| 439 |
|
| 440 |
new_rule.find('.wpupg-date').datepicker(); |
| 441 |
|
| 442 |
WPUltimatePostGrid.changedRuleField(rule_id); |
| 443 |
WPUltimatePostGrid.changedDateRule(rule_id); |
| 444 |
}; |
| 445 |
|
| 446 |
WPUltimatePostGrid.removeRule = function(id) { |
| 447 |
if(id != '0') { |
| 448 |
jQuery('#wpupg_rule_' + id).remove(); |
| 449 |
} |
| 450 |
}; |
| 451 |
|
| 452 |
WPUltimatePostGrid.changedRuleField = function(id) { |
| 453 |
var row = jQuery('#wpupg_rule_' + id); |
| 454 |
var field = jQuery('#wpupg_limit_posts_rule_field_' + id).val(); |
| 455 |
field = field.replace('|','_'); |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
row.find('.rule_container').hide(); |
| 460 |
row.find('.rule_container_' + field).show(); |
| 461 |
}; |
| 462 |
|
| 463 |
WPUltimatePostGrid.changedDateRule = function(id) { |
| 464 |
var condition = jQuery('#wpupg_limit_posts_rule_values_wpupg_general_date_condition_' + id).find(':selected').val(); |
| 465 |
var date = jQuery('#wpupg_limit_posts_rule_values_wpupg_general_date_date_' + id).val(); |
| 466 |
jQuery('#wpupg_limit_posts_rule_values_wpupg_general_date_' + id).val(condition + ';' + date); |
| 467 |
}; |
| 468 |
|
| 469 |
WPUltimatePostGrid.changedFilterType = function() { |
| 470 |
var filter_type = jQuery('#wpupg_filter_type').find(':selected').val(); |
| 471 |
|
| 472 |
// Hide & Show Filter Settings |
| 473 |
if(filter_type == 'none' || filter_type == 'text') { |
| 474 |
jQuery('#wpupg_form_filter').find('tr').not('.wpupg_no_filter').hide(); |
| 475 |
} else { |
| 476 |
jQuery('#wpupg_form_filter').find('tr').not('.wpupg_no_filter').show(); |
| 477 |
} |
| 478 |
|
| 479 |
// Premium only filters |
| 480 |
if(filter_type == 'dropdown' || filter_type == 'text') { |
| 481 |
WPUltimatePostGrid.checkPremiumFeatures('filter_type', true); |
| 482 |
} else { |
| 483 |
WPUltimatePostGrid.checkPremiumFeatures('filter_type', false); |
| 484 |
} |
| 485 |
|
| 486 |
// Hide & Show Filter Styles |
| 487 |
jQuery('#wpupg_meta_box_isotope_filter').hide(); |
| 488 |
jQuery('#wpupg_meta_box_dropdown_filter').hide(); |
| 489 |
|
| 490 |
if(WPUltimatePostGrid.filter_possible) { |
| 491 |
jQuery('#wpupg_meta_box_' + filter_type + '_filter').show(); |
| 492 |
} |
| 493 |
|
| 494 |
WPUltimatePostGrid.changedLimitTerms(); |
| 495 |
WPUltimatePostGrid.changedDropdownLabels(); |
| 496 |
}; |
| 497 |
|
| 498 |
WPUltimatePostGrid.changedShowCount = function() { |
| 499 |
var show_count = jQuery('#wpupg_filter_count').is(':checked'); |
| 500 |
|
| 501 |
if(show_count) { |
| 502 |
WPUltimatePostGrid.checkPremiumFeatures('show_count', true); |
| 503 |
} else { |
| 504 |
WPUltimatePostGrid.checkPremiumFeatures('show_count', false); |
| 505 |
} |
| 506 |
}; |
| 507 |
|
| 508 |
WPUltimatePostGrid.changedMultiselect = function() { |
| 509 |
var multiselect = jQuery('#wpupg_filter_multiselect').is(':checked'); |
| 510 |
|
| 511 |
if(multiselect) { |
| 512 |
WPUltimatePostGrid.checkPremiumFeatures('multiselect', true); |
| 513 |
jQuery('.wpupg_multiselect').show(); |
| 514 |
} else { |
| 515 |
WPUltimatePostGrid.checkPremiumFeatures('multiselect', false); |
| 516 |
jQuery('.wpupg_multiselect').hide(); |
| 517 |
} |
| 518 |
}; |
| 519 |
|
| 520 |
WPUltimatePostGrid.changedLimitTerms = function() { |
| 521 |
var limit_terms = jQuery('#wpupg_filter_limit').is(':checked'); |
| 522 |
var post_type = jQuery('#wpupg_post_types').find(':selected').val(); |
| 523 |
var taxonomies = jQuery('#wpupg_filter_taxonomy_' + post_type).val(); |
| 524 |
|
| 525 |
if( !jQuery.isArray( taxonomies ) ) { |
| 526 |
taxonomies = [taxonomies]; |
| 527 |
} |
| 528 |
|
| 529 |
if(limit_terms && taxonomies) { |
| 530 |
jQuery('.wpupg_limit_terms').show(); |
| 531 |
jQuery('.wpupg_filter_terms_taxonomy').hide(); |
| 532 |
|
| 533 |
for(var i = 0; i < taxonomies.length; i++) { |
| 534 |
jQuery('#wpupg_filter_terms_taxonomy_' + taxonomies[i]).show(); |
| 535 |
} |
| 536 |
} else { |
| 537 |
jQuery('.wpupg_limit_terms').hide(); |
| 538 |
} |
| 539 |
}; |
| 540 |
|
| 541 |
WPUltimatePostGrid.changedDropdownLabels = function() { |
| 542 |
var filter_type = jQuery('#wpupg_filter_type').find(':selected').val(); |
| 543 |
var post_type = jQuery('#wpupg_post_types').find(':selected').val(); |
| 544 |
var taxonomies = jQuery('#wpupg_filter_taxonomy_' + post_type).val(); |
| 545 |
|
| 546 |
if( !jQuery.isArray( taxonomies ) ) { |
| 547 |
taxonomies = [taxonomies]; |
| 548 |
} |
| 549 |
|
| 550 |
if(filter_type == 'dropdown' && taxonomies) { |
| 551 |
jQuery('.wpupg_dropdown_labels').show(); |
| 552 |
jQuery('.wpupg_filter_dropdown_labels_taxonomy').hide(); |
| 553 |
|
| 554 |
for(var i = 0; i < taxonomies.length; i++) { |
| 555 |
jQuery('#wpupg_filter_dropdown_label_taxonomy_' + taxonomies[i]).show(); |
| 556 |
} |
| 557 |
} else { |
| 558 |
jQuery('.wpupg_dropdown_labels').hide(); |
| 559 |
} |
| 560 |
}; |
| 561 |
|
| 562 |
WPUltimatePostGrid.changedIsotopeFilterStyle = function() { |
| 563 |
var margin_vertical = parseInt(jQuery('#wpupg_isotope_filter_style_margin_vertical').val()); |
| 564 |
var margin_horizontal = parseInt(jQuery('#wpupg_isotope_filter_style_margin_horizontal').val()); |
| 565 |
var padding_vertical = parseInt(jQuery('#wpupg_isotope_filter_style_padding_vertical').val()); |
| 566 |
var padding_horizontal = parseInt(jQuery('#wpupg_isotope_filter_style_padding_horizontal').val()); |
| 567 |
var border_width = parseInt(jQuery('#wpupg_isotope_filter_style_border_width').val()); |
| 568 |
|
| 569 |
var background_color = jQuery('#wpupg_isotope_filter_style_background_color').wpColorPicker('color'); |
| 570 |
var text_color = jQuery('#wpupg_isotope_filter_style_text_color').wpColorPicker('color'); |
| 571 |
var border_color = jQuery('#wpupg_isotope_filter_style_border_color').wpColorPicker('color'); |
| 572 |
|
| 573 |
var alignment = jQuery('#wpupg_isotope_filter_style_alignment').find(':selected').val(); |
| 574 |
jQuery('#wpupg_filter_preview_isotope_filter_style').css('text-align', alignment); |
| 575 |
|
| 576 |
jQuery('.wpupg-filter-isotope-term') |
| 577 |
.css( 'margin', margin_vertical + 'px ' + margin_horizontal + 'px' ) |
| 578 |
.css( 'padding', padding_vertical + 'px ' + padding_horizontal + 'px' ) |
| 579 |
.css( 'background-color', background_color ) |
| 580 |
.css( 'color', text_color ) |
| 581 |
.css( 'border', border_width + 'px solid ' + border_color ) |
| 582 |
; |
| 583 |
|
| 584 |
var background_active_color = jQuery('#wpupg_isotope_filter_style_background_active_color').wpColorPicker('color'); |
| 585 |
var text_active_color = jQuery('#wpupg_isotope_filter_style_text_active_color').wpColorPicker('color'); |
| 586 |
var border_active_color = jQuery('#wpupg_isotope_filter_style_border_active_color').wpColorPicker('color'); |
| 587 |
|
| 588 |
jQuery('.wpupg-filter-isotope-term.active') |
| 589 |
.css( 'background-color', background_active_color ) |
| 590 |
.css( 'color', text_active_color ) |
| 591 |
.css( 'border', border_width + 'px solid ' + border_active_color ) |
| 592 |
; |
| 593 |
}; |
| 594 |
|
| 595 |
WPUltimatePostGrid.changedIsotopeFilterText = function() { |
| 596 |
var text = jQuery('#wpupg_isotope_filter_style_all_button_text').val(); |
| 597 |
|
| 598 |
if(text.length > 0) { |
| 599 |
jQuery('#wpupg_isotope_filter_style_all_button_text_preview').text(text).show(); |
| 600 |
} else { |
| 601 |
jQuery('#wpupg_isotope_filter_style_all_button_text_preview').hide(); |
| 602 |
} |
| 603 |
}; |
| 604 |
|
| 605 |
|
| 606 |
WPUltimatePostGrid.changedLayoutMode = function() { |
| 607 |
var layout_mode = jQuery('#wpupg_layout_mode').find(':selected').val(); |
| 608 |
|
| 609 |
if(layout_mode == 'masonry') { |
| 610 |
jQuery('.wpupg_masonry').show(); |
| 611 |
} else { |
| 612 |
jQuery('.wpupg_masonry').hide(); |
| 613 |
} |
| 614 |
}; |
| 615 |
|
| 616 |
WPUltimatePostGrid.changedPaginationStyle = function() { |
| 617 |
var margin_vertical = parseInt(jQuery('#wpupg_pagination_style_margin_vertical').val()); |
| 618 |
var margin_horizontal = parseInt(jQuery('#wpupg_pagination_style_margin_horizontal').val()); |
| 619 |
var padding_vertical = parseInt(jQuery('#wpupg_pagination_style_padding_vertical').val()); |
| 620 |
var padding_horizontal = parseInt(jQuery('#wpupg_pagination_style_padding_horizontal').val()); |
| 621 |
var border_width = parseInt(jQuery('#wpupg_pagination_style_border_width').val()); |
| 622 |
|
| 623 |
var background_color = jQuery('#wpupg_pagination_style_background_color').wpColorPicker('color'); |
| 624 |
var text_color = jQuery('#wpupg_pagination_style_text_color').wpColorPicker('color'); |
| 625 |
var border_color = jQuery('#wpupg_pagination_style_border_color').wpColorPicker('color'); |
| 626 |
|
| 627 |
var alignment = jQuery('#wpupg_pagination_style_alignment').find(':selected').val(); |
| 628 |
jQuery('.wpupg_filter_preview_pagination_style').css('text-align', alignment); |
| 629 |
|
| 630 |
jQuery('.wpupg-pagination-term') |
| 631 |
.css( 'margin', margin_vertical + 'px ' + margin_horizontal + 'px' ) |
| 632 |
.css( 'padding', padding_vertical + 'px ' + padding_horizontal + 'px' ) |
| 633 |
.css( 'background-color', background_color ) |
| 634 |
.css( 'color', text_color ) |
| 635 |
.css( 'border', border_width + 'px solid ' + border_color ) |
| 636 |
; |
| 637 |
|
| 638 |
var background_active_color = jQuery('#wpupg_pagination_style_background_active_color').wpColorPicker('color'); |
| 639 |
var text_active_color = jQuery('#wpupg_pagination_style_text_active_color').wpColorPicker('color'); |
| 640 |
var border_active_color = jQuery('#wpupg_pagination_style_border_active_color').wpColorPicker('color'); |
| 641 |
|
| 642 |
jQuery('.wpupg-pagination-term.active') |
| 643 |
.css( 'background-color', background_active_color ) |
| 644 |
.css( 'color', text_active_color ) |
| 645 |
.css( 'border', border_width + 'px solid ' + border_active_color ) |
| 646 |
; |
| 647 |
}; |
| 648 |
|
| 649 |
WPUltimatePostGrid.changedPaginationType = function() { |
| 650 |
var pagination_type = jQuery('#wpupg_pagination_type').find(':selected').val(); |
| 651 |
|
| 652 |
// Hide & Show Pagination Settings |
| 653 |
jQuery('#wpupg_form_pagination').find('tbody').not('.wpupg_pagination_' + pagination_type).not('.wpupg_pagination_none').hide(); |
| 654 |
jQuery('#wpupg_form_pagination').find('tbody.wpupg_pagination_' + pagination_type).show(); |
| 655 |
|
| 656 |
// Premium only pagination |
| 657 |
if(pagination_type == 'none' || pagination_type == 'pages') { |
| 658 |
WPUltimatePostGrid.checkPremiumFeatures('pagination_type', false); |
| 659 |
} else { |
| 660 |
WPUltimatePostGrid.checkPremiumFeatures('pagination_type', true); |
| 661 |
} |
| 662 |
|
| 663 |
// Hide & Show Pagination Styles |
| 664 |
if(pagination_type != 'none' && pagination_type != 'infinite_load' && pagination_type != 'load_filter') { |
| 665 |
pagination_type = pagination_type == 'load_more_filter' ? 'load_more' : pagination_type; |
| 666 |
jQuery('#wpupg_meta_box_pagination_style').show().find('.wpupg_filter_preview').hide(); |
| 667 |
jQuery('#wpupg_filter_preview_pagination_style_' + pagination_type).show(); |
| 668 |
} else { |
| 669 |
jQuery('#wpupg_meta_box_pagination_style').hide(); |
| 670 |
} |
| 671 |
}; |
| 672 |
|
| 673 |
WPUltimatePostGrid.changedPaginationText = function() { |
| 674 |
var text = jQuery('#wpupg_pagination_load_more_button_text').val(); |
| 675 |
jQuery('#wpupg_filter_preview_pagination_style_load_more').find('.wpupg-pagination-term').text(text); |
| 676 |
}; |
| 677 |
|
| 678 |
WPUltimatePostGrid.checkPremiumFeatures = function(feature, using) { |
| 679 |
if(using) { |
| 680 |
WPUltimatePostGrid.premium_features_used.push(feature); |
| 681 |
} else { |
| 682 |
// Remove feature from array |
| 683 |
WPUltimatePostGrid.premium_features_used = jQuery.grep(WPUltimatePostGrid.premium_features_used, function(value) { |
| 684 |
return value != feature; |
| 685 |
}); |
| 686 |
} |
| 687 |
|
| 688 |
if(WPUltimatePostGrid.premium_features_used.length > 0) { |
| 689 |
jQuery('#wpupg_meta_box_premium_only').show(); |
| 690 |
} else { |
| 691 |
jQuery('#wpupg_meta_box_premium_only').hide(); |
| 692 |
} |
| 693 |
}; |
| 694 |
|
| 695 |
jQuery(document).ready(function($) { |
| 696 |
if($('#wpupg_meta_box_data_source').length > 0) { |
| 697 |
WPUltimatePostGrid.initForm(); |
| 698 |
} |
| 699 |
}); |