PageSourceSearch

https://jamiebartlettdesign.com/wp-content/plugins/cavalier-shortcodes/js/ing-shortcodes.js

js jamiebartlettdesign.com collected 2026-10-09 18:13:50 UTC 12,594 bytes, 351 lines download raw bytes

1// =============================================================================
2// JS/ING-SHORTCODES.JS
3// -----------------------------------------------------------------------------
4// Custom shortcode scripts for the Cavalier Shortcodes plugin.
5// =============================================================================
6
7jQuery(document).ready(function($) {
8
9  //
10  // Parallax effect.
11  //
12
13  var windowObj    = $(window);
14  var windowHeight = windowObj.height();
15  var body         = $('body');
16  var thisObj      = $(this);
17
18  windowObj.resize(function () {
19    windowHeight = windowObj.height();
20  });
21
22  $.fn.parallaxContentBand = function(xAxis, parallaxSpeed) {
23    var thisObj = $(this);
24    var contentBandFirstTop;
25
26    thisObj.each(function(){
27      contentBandFirstTop = thisObj.offset().top;
28    });
29
30    windowObj.resize(function(){
31      thisObj.each(function(){
32        contentBandFirstTop = thisObj.offset().top;
33      });
34    });
35
36    function windowUpdate(){
37      var windowPosition = windowObj.scrollTop();
38
39      thisObj.each(function(){
40        var contentBandOffsetTop = thisObj.offset().top;
41        var contentBandHeight    = thisObj.outerHeight();
42
43        if (contentBandOffsetTop + contentBandHeight < windowPosition || contentBandOffsetTop > windowPosition + windowHeight) {
44          return;
45        }
46
47        thisObj.css('background-position', xAxis + ' ' + Math.floor((contentBandFirstTop - windowPosition) * parallaxSpeed) + 'px');
48      });
49    }
50
51    windowObj.bind('scroll', windowUpdate).resize(windowUpdate);
52    windowUpdate();
53  };
54
55  if (Modernizr.touch) {
56    $('.cavalier-content-band.bg-image.parallax, .cavalier-content-band.bg-pattern.parallax').css('background-attachment', 'scroll');
57  } else {
58    $('.cavalier-content-band.bg-image.parallax').each(function(){
59       var id = $(this).attr('id');
60       $('#' + id + ".parallax").parallaxContentBand('50%', 0.1);
61    });
62    $('.cavalier-content-band.bg-pattern.parallax').each(function(){
63       var id = $(this).attr('id');
64       $('#' + id + ".parallax").parallaxContentBand('50%', 0.3);
65    });
66  }
67
68
69  //
70  // Waypoint: fade.
71  //
72
73  $('.cavalier-column[data-fade="true"]').each(function() {
74    $(this).waypoint(function() {
75      if ($(this).attr('data-fade-animation') === 'in-from-top') {
76        $(this).animate({
77          'opacity' : '1',
78          'top'     : '0'
79        }, 750, 'easeOutExpo');
80      } else if ($(this).attr('data-fade-animation') === 'in-from-left') {
81        $(this).animate({
82          'opacity' : '1',
83          'left'    : '0'
84        }, 750, 'easeOutExpo');
85      } else if ($(this).attr('data-fade-animation') === 'in-from-right') {
86        $(this).animate({
87          'opacity' : '1',
88          'right'   : '0'
89        }, 750, 'easeOutExpo');
90      } else if ($(this).attr('data-fade-animation') === 'in-from-bottom') {
91        $(this).animate({
92          'opacity' : '1',
93          'bottom'  : '0'
94        }, 750, 'easeOutExpo');
95      } else {
96        $(this).animate({ 'opacity' : '1' }, 750, 'easeOutExpo');
97      }
98    }, { offset: '65%' });
99  });
100
101
102  //
103  // Waypoint: recent posts.
104  //
105
106  $('.cavalier-recent-posts[data-fade="true"]').each(function() {
107    $(this).waypoint(function() {
108      $(this).find('a').each(function(i) {
109        $(this).delay(i * 90).animate({ 'opacity' : '1' }, 750, 'easeOutExpo');
110      });
111      setTimeout(function() {
112        $(this).addClass('complete');
113      }, ($(this).find('a').length * 90) + 400);
114    }, { offset: '75%' });
115  });
116
117
118  //
119  // Waypoint: skill bar.
120  //
121
122  $('.cavalier-skill-bar').each(function(){
123    $(this).waypoint(function() {
124      var percent = $(this).attr('data-percentage');
125      $(this).find('.bar').animate({'width': percent + '%'}, 1000, 'easeInOutExpo');
126    }, { offset: '100%' });
127  });
128
129
130  //
131  // Ensure accordion collapse class.
132  //
133
134  $('.cavalier-accordion-toggle[data-parent]').click(function(){
135    $(this).closest('.cavalier-accordion').find('.cavalier-accordion-toggle:not(.collapsed)').addClass('collapsed');
136  });
137
138});
139
140(function($) {
141    $.fn.countTo = function(options) {
142        // merge the default plugin settings with the custom options
143        options = $.extend({}, $.fn.countTo.defaults, options || {});
144
145        // how many times to update the value, and how much to increment the value on each update
146        var loops = Math.ceil(options.speed / options.refreshInterval),
147            increment = (options.to - options.from) / loops;
148
149        return $(this).each(function() {
150            var _this = this,
151                loopCount = 0,
152                value = options.from,
153                interval = setInterval(updateTimer, options.refreshInterval);
154
155            function updateTimer() {
156                value += increment;
157                loopCount++;
158                $(_this).html(value.toFixed(options.decimals));
159
160                if (typeof(options.onUpdate) == 'function') {
161                    options.onUpdate.call(_this, value);
162                }
163
164                if (loopCount >= loops) {
165                    clearInterval(interval);
166                    value = options.to;
167
168                    if (typeof(options.onComplete) == 'function') {
169                        options.onComplete.call(_this, value);
170                    }
171                }
172            }
173        });
174    };
175
176    $.fn.countTo.defaults = {
177        from: 0,  // the number the element should start at
178        to: 100,  // the number the element should end at
179        speed: 1000,  // how long it should take to count between the target numbers
180        refreshInterval: 100,  // how often the element should be updated
181        decimals: 0,  // the number of decimal places to show
182        onUpdate: null,  // callback method for every time the element is updated,
183        onComplete: null,  // callback method for when the element finishes updating
184    };
185})(jQuery);
186
187
188
189jQuery(document).ready(function($) {
190	var galleryItems = $('.cavalier-variable-product>.products').children('div');
191	$('.img-preview-slider').each(function(){
192	    $(this).find('li').eq(0).addClass('selected');
193		$(this).find('li').eq(1).addClass('move-right');
194	});
195
196	galleryItems.each(function(){
197		var container = $(this),
198			// create slider dots
199			sliderDots = createSliderDots(container);
200		//check if item is on sale
201		updatePrice(container, 0);
202		productPreview(container, 0);
203
204		// update slider when user clicks one of the dots
205		sliderDots.on('click', function(){
206			var selectedDot = $(this);
207			if(!selectedDot.hasClass('selected')) {
208				var selectedPosition = selectedDot.index(),
209					activePosition = container.find('.img-preview-slider .selected').index();
210				if( activePosition < selectedPosition) {
211					nextSlide(container, sliderDots, selectedPosition);
212				} else {
213					prevSlide(container, sliderDots, selectedPosition);
214				}
215
216				updatePrice(container, selectedPosition);
217				productPreview(container, selectedPosition);
218			}
219		});
220
221		// update slider on swipeleft
222		container.find('.img-preview-slider').on('swipeleft', function(){
223			var wrapper = $(this);
224			if( !wrapper.find('.selected').is(':last-child') ) {
225				var selectedPosition = container.find('.img-preview-slider .selected').index() + 1;
226				nextSlide(container, sliderDots);
227				updatePrice(container, selectedPosition);
228				productPreview(container, selectedPosition);
229			}
230		});
231
232		// update slider on swiperight
233		container.find('.img-preview-slider').on('swiperight', function(){
234			var wrapper = $(this);
235			if( !wrapper.find('.selected').is(':first-child') ) {
236				var selectedPosition = container.find('.img-preview-slider .selected').index() - 1;
237				prevSlide(container, sliderDots);
238				updatePrice(container, selectedPosition);
239				productPreview(container, selectedPosition);
240			}
241		});
242
243		// preview image hover effect - desktop only
244		container.on('mouseover', '.move-right, .move-left', function(event){
245			hoverItem($(this), true);
246		});
247		container.on('mouseleave', '.move-right, .move-left', function(event){
248			hoverItem($(this), false);
249		});
250
251		// update slider when user clicks on the preview images
252		container.on('click', '.move-right, .move-left', function(event){
253			event.preventDefault();
254			if ( $(this).hasClass('move-right') ) {
255				var selectedPosition = container.find('.img-preview-slider .selected').index() + 1;
256				nextSlide(container, sliderDots);
257			} else {
258				var selectedPosition = container.find('.img-preview-slider .selected').index() - 1;
259				prevSlide(container, sliderDots);
260			}
261			updatePrice(container, selectedPosition);
262			productPreview(container, selectedPosition);
263		});
264	});
265
266	function createSliderDots(container){
267		var dotsWrapper = $('<ol class="nav-dots"></ol>').insertAfter(container.find('.img-preview-slider'));
268		container.find('.img-preview-slider li').each(function(index){
269			var dotWrapper = (index == 0) ? $('<li class="selected"></li>') : $('<li></li>'),
270				dot = $('<a href="#"></a>').appendTo(dotWrapper);
271			dotWrapper.appendTo(dotsWrapper);
272			dot.text(index+1);
273		});
274		return dotsWrapper.children('li');
275	}
276
277	function hoverItem(item, bool) {
278		( item.hasClass('move-right') )
279			? item.toggleClass('hover', bool).siblings('.selected, .move-left').toggleClass('focus-on-right', bool)
280			: item.toggleClass('hover', bool).siblings('.selected, .move-right').toggleClass('focus-on-left', bool);
281	}
282
283	function nextSlide(container, dots, n){
284		var visibleSlide = container.find('.img-preview-slider .selected'),
285			navigationDot = container.find('.nav-dots .selected');
286		if(typeof n === 'undefined') n = visibleSlide.index() + 1;
287		visibleSlide.removeClass('selected');
288		container.find('.img-preview-slider li').eq(n).addClass('selected').removeClass('move-right hover').prevAll().removeClass('move-right move-left focus-on-right').addClass('hide-left').end().prev().removeClass('hide-left').addClass('move-left').end().next().addClass('move-right');
289		navigationDot.removeClass('selected')
290		dots.eq(n).addClass('selected');
291	}
292
293	function prevSlide(container, dots, n){
294		var visibleSlide = container.find('.img-preview-slider .selected'),
295			navigationDot = container.find('.nav-dots .selected');
296		if(typeof n === 'undefined') n = visibleSlide.index() - 1;
297		visibleSlide.removeClass('selected focus-on-left');
298		container.find('.img-preview-slider li').eq(n).addClass('selected').removeClass('move-left hide-left hover').nextAll().removeClass('hide-left move-right move-left focus-on-left').end().next().addClass('move-right').end().prev().removeClass('hide-left').addClass('move-left');
299		navigationDot.removeClass('selected');
300		dots.eq(n).addClass('selected');
301	}
302
303	function updatePrice(container, n) {
304		var selectedItem = container.find('.img-preview-slider li').eq(n);
305		var priceTag = 	selectedItem.find('.current-variable-price');
306			var $price = priceTag.html();
307			selectedItem.closest('.product').find('.price').html($price);
308
309	}
310
311	function productPreview(container, n) {
312	    container.find('.img-preview-slider li').find('img').unbind('click');
313		var selectedItem = container.find('.img-preview-slider li').eq(n).find('img');
314		selectedItem.click(function(e) {
315				e.preventDefault();
316				$('body').append('<div id="product-preview-wrap" class="woocommerce"></div>');
317				var url = $(this).closest('a').attr('href');
318				jQuery.ajax({
319					type: "GET",
320					url: url,
321					cache: false,
322					data: 'html',
323					success: function(data){
324						var title = $(data).find('.product_title').html();
325						var images = $(data).find('.images').find('a').map(function(){return $(this).attr('href')}).get();
326						var newImages = [];
327						for (var i = 0; i < images.length; i++) {
328						    newImages.push('<div class="prod-item"><img src="' + images[i] + '" alt=""></div>');
329						}
330						var summary = $(data).find('.summary.entry-summary').html();
331						$('#product-preview-wrap').append('<div class="product-preview-inner"><div class="preview-images"><div class="preview-images-inner">
331'+newImages.join("")+'</div></div><div class="preview-summary"><h1 class="product_title entry-title">'+title+'</h1>'+summary+'<a href="'+url+'" class="learn-more cavalier-btn">Learn More</a></div><a href="#" class="preview-close">Close</a></div>');
332					},
333					error: function(){ },
334					complete: function(){
335						$('.preview-images-inner').slick({
336							fade: true,
337							infinite: false,
338							dots:false
339						});
340						$('.preview-close').click(function(){
341							$('#product-preview-wrap').remove();
342							return false;
343						});
344					}
345				});
346			selectedItem.unbind('click');
347			return false;
348		});
349
350	}
351});

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.