PageSourceSearch

https://getreadytorock.me.uk/blog/wp-content/plugins/pt-content-views-pro/public/assets/js/public.js?ver=1.6.3

js getreadytorock.me.uk collected 2026-09-24 09:51:51 UTC 13,306 bytes, 495 lines download raw bytes

1/**
2 * Main scripts for Front-end
3 *
4 * @package   PT_Content_Views_Pro
5 * @author    PT Guy <[email protected]>
6 * @license   GPL-2.0+
7 * @link      http://www.contentviewspro.com/
8 * @copyright 2014 PT Guy
9 */
10
11( function ($) {
12	"use strict";
13
14	$.PT_CV_Public_Pro = $.PT_CV_Public_Pro || { };
15
16	$.PT_CV_Public_Pro = function (options) {
17		this.options = $.extend({
18			_autoload: 1
19		}, options);
20
21		// Autoload all registered functions
22		if (this.options._autoload !== 0) {
23			this.animation();
24			this.pagination();
25			this.openin_window();
26			this.openin_lightbox();
27			this.grid_same_height();
28			this.open_in();
29
30			// Run after images are loaded
31			var $this = this;
32			$(window).load(function () {
33				$this.quicksand_filter();
34			});
35		}
36	};
37
38	$.PT_CV_Public_Pro.prototype = {
39
40		/**
41		 * Open in
42		 *
43		 * @returns {undefined}
44		 */
45		open_in: function () {
46			var _prefix = this.options._prefix;
47
48			// No link, no action
49			$('.' + _prefix + 'none').click(function (e) {
50				e.preventDefault();
51			});
52		},
53
54		/**
55		 * Set same height for each type of fields (Title, Content...) across items
56		 * @returns {undefined}
57		 */
58		grid_same_height: function () {
59			var _prefix = this.options._prefix;
60
61			var grid_ = '.' + _prefix + 'same-height .pt-cv-row';
62			var grid_title = '.' + _prefix + 'title';
63			var grid_content = '.' + _prefix + 'content';
64			var grid_readmore = '.' + _prefix + 'readmore';
65
66			// Process each Row
67			$(grid_).each(function () {
68				var $titles = $(this).find(grid_title);
69				var $contents = $(this).find(grid_content);
70
71				// Height of Title
72				var heights_title = $titles.map(function () {
73					return $(this).height();
74				}).get(),
75				// Height of Content
76				heights_content = $contents.map(function () {
77					return $(this).height();
78				}).get();
79
80				// Get max Height
81				var maxHeightTitle = Math.max.apply(null, heights_title),
82					maxHeightContent = Math.max.apply(null, heights_content);
83
84				// Set max Height for all fields
85				$titles.height(maxHeightTitle);
86				$contents.height(maxHeightContent);
87
88				// Stick Readmore button to bottom of Grid
89				$(this).find(grid_readmore).css({'position': 'absolute', 'bottom': '20px'});
90			});
91		},
92
93		/**
94		 * Animation actions
95		 * @returns {undefined}
96		 */
97		animation: function () {
98			var _prefix = this.options._prefix;
99
100			// Do it when images are loaded
101			$(window).load(function () {
102				$('.' + _prefix + 'content-hover').each(function () {
103					// Process row by row
104					$(this).find('.row').each(function () {
105
106						// Get height of the first thumbnail
107						var thumb_height = $(this).find('.' + _prefix + 'thumbnail').first().height();
108
109						// Set height for content block
110						$(this).find('.' + _prefix + 'content').each(function () {
111							$(this).css('height', thumb_height);
112						});
113					});
114				});
115			});
116		},
117
118		/**
119		 * Load more pagination
120		 * @returns {undefined}
121		 */
122		pagination: function () {
123			this._pagination_loadmore();
124			this._pagination_infinite();
125		},
126
127		/**
128		 * Pagination handle
129		 *
130		 * @param {type} this_
131		 * @returns {undefined}
132		 */
133		_pagination_handle: function (this_) {
134			var $self = this;
135
136			// Prevent duplicate processing
137			if ($self.doing) {
138				return;
139			} else {
140				$self.doing = 1;
141			}
142
143			// Reset status
144			var _fn_reset = function () {
145				$self.doing = 0;
146			};
147
148			// Get next page
149			var selected_page = parseInt(this_.attr('data-nextpages'));
150
151			if (!selected_page) {
152				_fn_reset();
153				return;
154			}
155
156			var $pt_cv_public_js = new $.PT_CV_Public();
157
158			$pt_cv_public_js._setup_pagination(this_, selected_page, function () {
159				_fn_reset();
160
161				// Update data-nextpages Or hide load more
162				var nextpage = selected_page + 1;
163				if (nextpage <= parseInt(this_.attr('data-totalpages'))) {
164					this_.attr('data-nextpages', nextpage);
165				} else {
166					this_.remove();
167				}
168			});
169		},
170
171		/**
172		 * Loadmore button pagination
173		 */
174		_pagination_loadmore: function () {
175			var $self = this;
176			var _prefix = $self.options._prefix;
177
178			// Load more button
179			$('body').on('click', '.' + _prefix + 'more', function () {
180				var this_ = $(this);
181
182				$self._pagination_handle(this_);
183			});
184		},
185
186		/**
187		 * Infinite loading
188		 */
189		_pagination_infinite: function () {
190			var $self = this;
191			var _prefix = $self.options._prefix;
192			var timer;
193
194			$(window).scroll(function () {
195
196				if (timer) {
197					// Clear Pending Timers
198					clearTimeout(timer);
199				}
200
201				// Set Timer For
202				timer = setTimeout(function(){
203					if ($self._scrollTo('.' + _prefix + 'pagination-wrapper')) {
204						var this_ = $('.' + _prefix + 'infinite-load').next('.' + _prefix + 'pagination-wrapper').find('.' + _prefix + 'more');
205						$self._pagination_handle(this_);
206					}
207				}, 500);
208			});
209		},
210
211		/**
212		 * Is scroll to this element
213		 *
214		 * @param {type} elem
215		 * @returns {Boolean}
216		 */
217		_scrollTo: function (elem) {
218			if ($(elem).length === 0) {
219				return false;
220			}
221
222			var docViewTop = $(window).scrollTop();
223			var docViewBottom = docViewTop + $(window).height();
224
225			var elemTop = $(elem).offset().top;
226			var elemBottom = elemTop + $(elem).height();
227
228			return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
229		},
230
231		/**
232		 * Open in New window
233		 *
234		 * @returns {undefined}
235		 */
236		openin_window: function () {
237			var _prefix = PT_CV_PUBLIC._prefix;
238
239			$('body').on('click', '.' + _prefix + 'window', function (e) {
240				e.preventDefault();
241
242				var this_ = $(this);
243
244				var href = this_.attr('href');
245				var width = this_.attr('data-width');
246				var height = this_.attr('data-height');
247				var left = (window.screen.width / 2) - (width / 2);
248				var top = (window.screen.height / 2) - (height / 2);
249
250				var settings = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, ';
251				window.open(href, "_blank", settings + ' top=' + top + ', left=' + left + ', width=' + width + ', height=' + height);
252			});
253		},
254
255		/**
256		 * Open in Lightbox
257		 *
258		 * @returns {undefined}
259		 */
260		openin_lightbox : function () {
261			var _prefix = this.options._prefix;
262
263			$('body').on('click', '.' + _prefix + 'lightbox', function (e) {
264				e.preventDefault();
265
266				var this_ = $(this);
267
268				var width = this_.attr('data-width');
269				var height = this_.attr('data-height');
270				var content_selector = this_.attr('data-content-selector');
271
272				// If Mobile, fix width, height
273				if (PT_CV_PUBLIC.is_mobile) {
274					width = height = 75;
275				}
276
277				// If has not set Content selector, get default Lightbox
278				if (!content_selector) {
279					$(this).colorbox({iframe: true, width: width + "%", height: height + "%"});
280				} else {
281					// Create/Get custom overlay object
282					var overlay_id = _prefix + 'overlay';
283					var $overlay = $('#' + overlay_id).length ? $('#' + overlay_id) : $("<div/>", { id: _prefix + 'overlay' }).css({
284						background: "#000",
285						opacity   : 0.9,
286						position  : "fixed",
287						width     : "100%",
288						height    : "100%",
289						left      : 0,
290						top       : 0,
291						zIndex    : 1000000
292					}).appendTo('body');
293
294					// Show custom overlay
295					$overlay.show();
296					$('body').css('cursor', 'progress');
297
298					// Create/Get object to hold content of post
299					var content_id = _prefix + 'lightbox-content';
300					var $container = $('#' + content_id).length ? $('#' + content_id) : $("<div/>", { id: content_id }).hide().appendTo('body');
301
302					// Load content of post to $container
303					$container.load(this_.attr('href') + ' ' + content_selector, function (response, status, xhr) {
304						// Hide custom overlay
305						$overlay.hide();
306						$('body').css('cursor', 'default');
307
308						if (status !== "error") {
309							$(this).colorbox({
310								open      : true,
311								fixed     : true,
312								className : _prefix + 'lightbox-dialog',
313								width     : width + "%",
314								height    : height + "%",
315								html      : $container.html(),
316								onComplete: function () {
317									$('body').trigger(_prefix + 'lightbox-loaded');
318								}
319							});
320						}
321					});
322				}
323			});
324		},
325		/**
326		 * Script to filter item when click on filter option
327		 * @returns {undefined}
328		 */
329		quicksand_filter: function () {
330			var _prefix = this.options._prefix;
331
332			var $filter_bar = $('.' + _prefix + 'filter-bar');
333			var $itemsHolder = $filter_bar.next('.' + _prefix + 'view').first();
334			if ($itemsHolder.children('.' + _prefix + 'page').length >= 0) {
335				$itemsHolder = $itemsHolder.children('.' + _prefix + 'page').first();
336			}
337
338			// Add height for all items under filter options
339			this._quicksand_fix_height($itemsHolder, _prefix);
340
341			var $itemsClone = $itemsHolder.clone();
342			var $filterClass = "";
343			var $filterItem = '.' + _prefix + 'content-item';
344
345			// Filter by single Taxonomy
346			$('body').off('click', '.' + _prefix + 'filter-option').on('click', '.' + _prefix + 'filter-option', function (e) {
347				e.preventDefault();
348
349				var $filters;
350
351				$filterClass = $(this).attr('data-value');
352				if ($filterClass === 'all') {
353					$filters = $itemsClone.find($filterItem);
354				} else {
355					$filters = $itemsClone.find($filterItem + '[data-type~=' + $filterClass + ']');
356				}
357
358				$itemsHolder.quicksand($filters, { adjustWidth: 'dynamic' });
359			});
360
361			// Style handle when click on filter options
362			this._quicksand_filter_style(_prefix);
363
364			// Filter by multiple Taxonomies
365			$('body').off('click', '.' + _prefix + 'filter-group a').on('click', '.' + _prefix + 'filter-group a', function (e) {
366				e.preventDefault();
367
368				// Style handle when click on filter options
369				if (!$(this).hasClass('selected')) {
370					// Unselect all
371					$(this).closest('ul').find('.selected').removeClass('selected');
372					// Select this
373					$(this).addClass('selected');
374				} else {
375					return;
376				}
377
378				var $filters, $final_filters, $selected_terms = [], $filter_group = $('.' + _prefix + 'filter-group');
379
380				$filter_group.find('.selected').each(function () {
381					$filterClass = $(this).attr('data-value');
382					if ($filterClass !== 'all') {
383						var $matched_items = $itemsClone.find($filterItem + '[data-type~=' + $filterClass + ']');
384						if (typeof $filters === 'undefined') {
385							$filters = $matched_items;
386						} else {
387							$filters = $filters.add($matched_items);
388						}
389
390						// Add this term to selected group
391						$selected_terms.push($filterClass);
392					}
393				});
394
395				// Get items which has all selected terms
396				var length = parseInt($selected_terms.length);
397
398				if (length) {
399					$filters.each(function (i, object) {
400						var types = $(object).attr('data-type');
401						var found = 0;
402
403						$.each($selected_terms, function (j, term) {
404							var regex = new RegExp("\\b" + term + "\\b", "gi");
405							if (types.match(regex)) {
406								found += 1;
407							}
408						});
409
410						// If this items contains all selected terms
411						if (found === length) {
412							if (typeof $final_filters === 'undefined') {
413								$final_filters = $(object);
414							} else {
415								$final_filters = $final_filters.add($(object));
416							}
417						}
418					});
419				} else {
420					// If no terms selected, get all items
421					$final_filters = $itemsClone.find($filterItem);
422				}
423
424				$itemsHolder.quicksand($final_filters, { adjustWidth: 'dynamic' });
425			});
426		},
427
428		/**
429		 * Add height for all items under filter options
430		 *
431		 * @param {type} $itemsHolder
432		 * @returns {undefined}
433		 */
434		_quicksand_fix_height: function ($itemsHolder, _prefix) {
435			var $images = $itemsHolder.find('.wp-post-image');
436
437			// Height of Title
438			var height_images = $images.map(function () {
439				return $(this).closest('.' + _prefix + 'content-item').outerHeight();
440			}).get();
441
442			// Get max Height
443			var maxHeight = Math.max.apply(null, height_images);
444
445			// Assign that height for other items
446			$itemsHolder.find('.' + _prefix + 'content-item').css('height', maxHeight + 'px');
447		},
448
449		/**
450		 * Style handle when click on filter options
451		 *
452		 * @param {type} _prefix
453		 * @returns {undefined}
454		 */
455		_quicksand_filter_style: function (_prefix) {
456			// Dropdown filter click
457			$('body').on('click', '.' + _prefix + 'filter-bar .dropdown-menu li a', function (e) {
458				// Add active class
459				$(this).closest('.dropdown-menu').children('.active').removeClass('active');
460				$(this).parent().addClass('active');
461
462				// Update Text
463				var selText = $(this).text();
464				$(this).parents('.btn-group').find('.dropdown-toggle').html(selText + ' <span class="caret"></span>');
465			});
466
467			// Button filter click
468			$('body').on('click', '.' + _prefix + 'filter-bar button', function (e) {
469				// Add active class
470				$(this).parent().children('.active').removeClass('active');
471				$(this).addClass('active');
472			});
473
474			// Breadcrumb filter click
475			$('body').on('click', '.breadcrumb.' + _prefix + 'filter-bar a', function (e) {
476				// Add active class
477				$(this).closest('.breadcrumb').children('.active').removeClass('active');
478				$(this).parent().addClass('active');
479			});
480		}
481	},
482
483		$(function () {
484			var _prefix = PT_CV_PUBLIC._prefix;
485
486			// Run at page load
487			var $pt_cv_public_js_pro = new $.PT_CV_Public_Pro({ _prefix: _prefix });
488
489			// Recall when preview/pagination finished
490			$('body').bind(_prefix + 'custom-trigger', function () {
491				$pt_cv_public_js_pro.grid_same_height();
492			});
493		});
494
495}(jQuery) );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.