PageSourceSearch

https://chrisdavidmiles.com/wp-content/themes/readme/js/main.js

js chrisdavidmiles.com collected 2026-10-02 05:17:39 UTC 18,186 bytes, 631 lines download raw bytes

1/*
2	Name: readme
3	Description: Responsive HTML5 Template
4	Version: 1.0
5	Author: pixelwars
6*/
7
8(function($) { "use strict"; 
9	
10	/* global variables */
11	var $masonry_container;
12	
13	/* DOCUMENT READY */
14	$(function() {
15
16        
17		// ------------------------------
18        // HEADER SEARCH TOGGLE
19        $('.search-toggle').click(function(e) {
20            e.stopPropagation();
21            $('html').toggleClass('is-search-toggled-on');
22            $('html').removeClass('is-social-toggled-on');
23            if($('html').hasClass('is-search-toggled-on')) {
24                $('.search-container input[type="search"]').trigger('focus');
25            }
26        });
27        $('.search-container *').click(function(e) {
28            e.stopPropagation();
29        });
30
31        // HEADER MENU TOGGLE
32        $('.menu-toggle').click(function(e) {
33            e.stopPropagation();
34            $('html').toggleClass('is-menu-toggled-on');
35            $('html').removeClass('is-search-toggled-on');
36            $('html').removeClass('is-social-toggled-on');
37        });
38
39        // HEADER SOCIAL TOGGLE
40        $('.social-toggle').click(function(e) {
41            e.stopPropagation();
42            $('html').toggleClass('is-social-toggled-on');
43            $('html').removeClass('is-search-toggled-on');
44        });
45        $('.social-container *').click(function(e) {
46            e.stopPropagation();
47        });
48
49        // close on anywhere click
50        $(document).click (function (e) {     
51            $('html').removeClass('is-search-toggled-on');
52            $('html').removeClass('is-social-toggled-on');
53            $('html').removeClass('is-menu-toggled-on');
54        });
55        // ------------------------------
56        
57        
58        
59		// ------------------------------
60		/* SOCIAL FEED WIDGET */
61		var socialFeed = $('.social-feed');
62		if(socialFeed.length) {
63			socialFeed.each(function() {
64				$(this).socialstream({
65					socialnetwork: $(this).data("social-network"),
66					limit: $(this).data("limit"),
67					username: $(this).data("username")
68				})
69			});	
70		}
71		// ------------------------------
72		
73		
74		// ------------------------------
75		// FILL PROGRESS BARS
76		function fillBars() {
77			$('.bar').each(function() {
78				 var bar = $(this);
79                 var percent = bar.attr('data-percent');
80				 bar.find('.progress').css('width', percent + '%' ).html('<span>'+percent+'</span>');
81				});
82		}	
83		// ------------------------------
84		fillBars();
85		
86		// ------------------------------
87		// Rotating Words
88		var rotate_words = $('.rotate-words');
89		if(rotate_words.length) {
90			
91			var next_word_index = 0;
92			
93			if(Modernizr.csstransforms) {
94			
95				rotate_words.each(function(index, element) {
96					$(element).find('span').eq(0).addClass('active');
97					setInterval(function(){
98						next_word_index = $(element).find('.active').next().length ? $(element).find('.active').next().index() : 0;
99						$(element).find('.active').addClass('rotate-out').removeClass('rotate-in active');
100						$(element).find('span').eq(next_word_index).addClass('rotate-in active').removeClass('rotate-out');
101					},3000);
102				});
103	
104			}
105			else {
106				
107				rotate_words.each(function(index, element) {
108					$(element).find('span').eq(0).addClass('active').show();
109					setInterval(function(){
110						next_word_index = $(element).find('.active').next().length ? $(element).find('.active').next().index() : 0;
111						$(element).find('.active').removeClass('active').slideUp(500);
112						$(element).find('span').eq(next_word_index).addClass('active').slideDown(500);
113					},3000);
114				});
115			}
116		}
117		// ------------------------------
118		
119		
120        
121        // ------------------------------
122		// FluidBox : Zoomable Images
123		$('a[rel="lightbox"], .gallery a, .r-gallery-single .media-box a').fluidbox();
124		$('.entry-content > p a, .wp-caption a').each(function(index, element) {
125			
126            if($(this).attr('href') != null) {
127				if($(this).attr('href').match(/\.(jpeg|jpg|gif|png)$/) != null) {
128					$(this).fluidbox();
129					}
130				}
131        });
132        // ------------------------------
133        
134        
135        // ------------------------------
136        // SHARE BUTTON + READING TIME
137		if(!$('html').hasClass("no-canvas")) { //disable on IE8 
138			
139			//Share Button
140			if($('.share').length) {	
141				new Share('.share', {
142					ui: { flyout: "bottom left" },
143					networks: {
144						email: {   
145						  description: window.location.href
146						}
147					}
148				});
149			}
150			
151			 // READING TIME
152			 if($('.read-time').length) {	 
153				 $('article, .read-next').each(function() {
154					
155						$(this).readingTime({
156							readingTimeTarget: $(this).find('.eta'),
157							remotePath: $(this).find('.entry-title a').attr('href'),
158							remoteTarget: 'article .entry-content'
159						});
160						
161					});
162				
163			 
164					 // reading time for blog single with featured image with sidebar
165					 if($('.site-main > .post-thumbnail').length) {	 
166						$('.hentry.post .entry-content').readingTime({
167							readingTimeTarget: $(this).find('.eta'),
168							});
169					 }
170			 }
171			 
172            
173            // Selection Sharer
174            if($('.single').length) {	
175                $('.single .post .entry-content p, .single .post .entry-content blockquote').selectionSharer();
176            }
177			 
178		}
179        // ------------------------------
180        
181        
182	
183        // ------------------------------
184		/* BOOKS */
185		var bookshelf = $('.bookshelf');
186		if(bookshelf.length) {
187			
188			bookshelf.find('figure').each(function(index, element) {
189				
190				var el = $(this);
191				var front = el.find('.front');
192				front.css('background-image', 'url(' + front.find('img').attr('src') + ')');
193				
194				var spine = el.find('.spine');
195				spine.css('background-image', 'url(' + spine.find('img').attr('src') + ')');
196				
197				el.find('.open-details').click(function() {
198					el.addClass('details-open');
199					return false;
200				});
201				
202				el.find('.close-details').click(function() {
203					el.removeClass('details-open');
204				});
205		
206			});	
207			
208		}
209
210		// csstransformspreserve3d check
211		(function(Modernizr, win){
212			Modernizr.addTest('csstransformspreserve3d', function () {
213		
214				var prop = Modernizr.prefixed('transformStyle');
215				var val = 'preserve-3d';
216				var computedStyle;
217				if(!prop) return false;
218		
219				prop = prop.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
220		
221				Modernizr.testStyles('#modernizr{' + prop + ':' + val + ';}', function (el, rule) {
222					computedStyle = win.getComputedStyle ? getComputedStyle(el, null).getPropertyValue(prop) : '';
223				});
224		
225				return (computedStyle === val);
226			});
227		}(Modernizr, window));
228        // ------------------------------
229		
230
231		
232		// ------------------------------
233		// remove click delay on touch devices
234		//FastClick.attach(document.body);  ***not compatible with elastislide on ipad- nav arrows clicks don't work
235		// ------------------------------
236		
237		
238		
239		// ------------------------------
240		// LIGHTBOX
241		setupLigtbox();
242		// ------------------------------
243	
244
245        
246		// ------------------------------
247		// CODE PRETTIFY
248		if($('.prettyprint').length) {
249			window.prettyPrint && prettyPrint();
250		}
251		// ------------------------------
252		
253		
254		
255		// ------------------------------
256		// TABS
257		$('.tabs').each(function() {
258			if(!$(this).find('.tab-titles li a.active').length) {
259				$(this).find('.tab-titles li:first-child a').addClass('active');
260				$(this).find('.tab-content > div:first-child').show();
261			} else {
262				$(this).find('.tab-content > div').eq($(this).find('.tab-titles li a.active').parent().index()).show();	
263			}
264		});
265		
266		$('.tabs .tab-titles li a').click(function() {
267			if($(this).hasClass('active')) { return; }
268			$(this).parent().siblings().find('a').removeClass('active');
269			$(this).addClass('active');
270			$(this).parents('.tabs').find('.tab-content > div').hide().eq($(this).parent().index()).show();
271			return false;
272		});
273		// ------------------------------
274		
275		
276		// ------------------------------
277		// TOGGLES
278		var toggleSpeed = 300;
279		$('.toggle h4.active + .toggle-content').show();
280	
281		$('.toggle h4').click(function() {
282			if($(this).hasClass('active')) { 
283				$(this).removeClass('active');
284				$(this).next('.toggle-content').stop(true,true).slideUp(toggleSpeed);
285			} else {
286				
287				$(this).addClass('active');
288				$(this).next('.toggle-content').stop(true,true).slideDown(toggleSpeed);
289				
290				//accordion
291				if($(this).parents('.toggle-group').hasClass('accordion')) {
292					$(this).parent().siblings().find('h4').removeClass('active');
293					$(this).parent().siblings().find('.toggle-content').stop(true,true).slideUp(toggleSpeed);
294				}
295				
296			}
297			return false;
298		});
299		// ------------------------------
300		
301		
302		
303		// ------------------------------
304		// RESPONSIVE VIDEOS
305		if($('.media-wrap').length) {
306			$(".media-wrap").fitVids();
307		}
308		// ------------------------------
309		
310		
311		
312		// ------------------------------
313		// UNIFORM
314		$("select:not([multiple]), input:checkbox, input:radio, input:file").uniform();
315		var ua = navigator.userAgent.toLowerCase();
316		var isAndroid = ua.indexOf("android") > -1;
317		if(isAndroid) {
318			$('html').addClass('android');
319		}
320		// ------------------------------
321		
322		
323		
324		// ------------------------------
325		/* FLEX SLIDER */
326		var $flexslider = $('.flexslider');
327				
328		if($flexslider.length) {
329		
330			$flexslider.each(function(index, element) {
331							
332				//wait for images
333				$(element).imagesLoaded( function() {
334					
335					//remove loading
336					$(element).find('.loading').remove();
337					
338					//setup slider
339					$(element).flexslider({ 
340						smoothHeight: true,
341						slideshow: $(element).attr('data-autoplay') != "false",
342						slideshowSpeed: $(element).attr('data-interval'), 
343						animationSpeed : $(element).attr('data-animationSpeed'),
344						animation: $(element).attr('data-animation'), 
345						direction : $(element).attr('data-direction'),
346						directionNav : $(element).attr('data-directionNav') != "false",
347						controlNav : $(element).attr('data-controlNav') != "false",
348						randomize : $(element).attr('data-randomize') == "true",
349						startAt : $(element).attr('data-startAt') != null ? parseInt($(element).attr('data-startAt')) : 0,
350						animationLoop : $(element).attr('data-animationLoop') != "false",
351						pauseOnHover : $(element).attr('data-pauseOnHover') != "false",
352						reverse : $(element).attr('data-reverse') == "true",
353						prevText: "",
354						nextText: "",
355						start: function(slider) {
356								$('.slides li').click(function(event){
357									slider.flexAnimate(slider.getTarget("next"));
358								});
359							}
360						});
361					
362				});
363			
364			});
365		}
366		// ------------------------------
367		
368		
369        
370		// ------------------------------
371		/* MEDIAELEMENT.JS - self hosted html5 video and audio player */
372		if($('video,audio').length) {
373			$('video,audio').mediaelementplayer({ audioHeight: 50 });	
374		}
375		// ------------------------------
376		
377        
378		
379		// ------------------------------
380		// FORM VALIDATION
381		// comment form validation fix
382		$('#commentform').addClass('validate-form');
383		$('#commentform').find('input,textarea').each(function(index, element) {
384            if($(this).attr('aria-required') == "true") {
385				$(this).addClass('required');
386			}
387			if($(this).attr('name') == "email") {
388				$(this).addClass('email');
389			}
390		});
391		
392		// validate form
393		if($('.validate-form').length) {
394			$('.validate-form').each(function() {
395					$(this).validate();
396				});
397		}
398		// ------------------------------
399		
400
401
402		// ------------------------------
403		// GOOGLE MAP
404		/*
405			custom map with google api
406			check out the link below for more information about api usage
407			https://developers.google.com/maps/documentation/javascript/examples/marker-simple
408		*/
409		function initializeMap() {
410			if($('.map').length) {
411				var mapCanvas = $('#map-canvas');
412				var myLatlng = new google.maps.LatLng(mapCanvas.data("latitude"),mapCanvas.data("longitude"));
413				var mapOptions = {
414					zoom: mapCanvas.data("zoom"),
415					center: myLatlng
416				}
417				var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
418				
419				var marker = new google.maps.Marker({
420				  position: myLatlng,
421				  map: map
422		  	});
423			}
424		  
425		}
426		if($('.map').length) {
427			google.maps.event.addDomListener(window, 'load', initializeMap);
428		}
429		// ------------------------------
430				
431		
432		
433		// ------------------------------
434		/* jQuery Ajax Mail Send Script */	
435		var contactForm = $( '#contact-form' );
436		var $submit = contactForm.find('.submit');
437		
438		contactForm.submit(function()
439		{
440			if (contactForm.valid())
441			{
442				$submit.addClass("active loading");
443				var formValues = contactForm.serialize();
444				
445				$.post(contactForm.attr('action'), formValues, function(data)
446				{
447					if ( data == 'success' )
448					{
449						setTimeout(function() { 
450							$submit.removeClass("loading").addClass("success"); 
451							contactForm.clearForm();
452						},2000);
453					}
454					else
455					{
456						$submit.removeClass("loading").addClass("error");
457					}
458				});
459			}
460			
461			return false
462		});
463
464		$.fn.clearForm = function() {
465		  return this.each(function() {
466		    var type = this.type, tag = this.tagName.toLowerCase();
467		    if (tag == 'form')
468		      return $(':input',this).clearForm();
469		    if (type == 'text' || type == 'password' || tag == 'textarea')
470		      this.value = '';
471		    else if (type == 'checkbox' || type == 'radio')
472		      this.checked = false;
473		    else if (tag == 'select')
474		      this.selectedIndex = -1;
475		  });
476		};
477		// ------------------------------
478		
479		
480		// ------------------------------
481		// GALLERY MASONRY
482		var $gallery = $('.gallery');
483		if($gallery.length) {
484		
485			$gallery.each(function(index, element) {
486							
487				//wait for images
488				$(element).imagesLoaded( function() {
489					
490					$(element).masonry();
491
492				});
493			
494			});
495		}
496		
497        // ------------------------------
498		
499		
500		
501    });
502    // DOCUMENT READY
503	
504	
505	
506	// WINDOW ONLOAD
507	window.onload = function() {
508		
509		// ------------------------------
510		// MASONRY - ISOTOPE
511		$masonry_container = $('.masonry');
512		if($masonry_container.length) {
513			//$masonry_container.imagesLoaded(function() {
514				$masonry_container.width($masonry_container.parent().width());
515				// initialize isotope
516				$masonry_container.isotope({
517				  itemSelector : '.hentry',
518				  layoutMode : $masonry_container.data('layout')
519				});
520				
521				setMasonry();
522				setTimeout(function() { $masonry_container.isotope(); }, 20);	
523				$(window).resize(function() {
524					// hack : make container width fixed
525					$masonry_container.width($masonry_container.parent().width());
526					setMasonry();					
527				});
528				
529				// filter items when filter link is clicked
530				$('#filters a').click(function(){
531				  var selector = $(this).attr('data-filter');
532				  setMasonry();
533				  $masonry_container.isotope({ filter: selector });
534				  $(this).parent().addClass('current').siblings().removeClass('current');
535				  return false;
536				});
537				
538			//});
539		}
540		// ------------------------------	
541		
542	
543		// ------------------------------
544        // FULL WIDTH IMAGES
545		fullWidthImages();
546		// ------------------------------
547	
548	};
549	// WINDOW ONLOAD	
550	
551	
552	
553	
554	// ------------------------------
555	// ------------------------------
556		// FUNCTIONS
557	// ------------------------------
558	// ------------------------------
559	
560	
561	
562	// ------------------------------
563	// FULL WIDTH IMAGES
564	function fullWidthImages() { 
565		$('.full-width-image').each(function(index, element) {
566            $(element).css("min-height", $(element).find('img').height());
567			$( window ).resize(function() {
568			  $(element).css("min-height", $(element).find('img').height());
569			});
570        });
571	}
572	// ------------------------------
573	
574	
575	// ------------------------------
576	// PORTFOLIO MASONRY LAYOUT : changes the number of masonry columns based on the current container's width
577	function setMasonry() {
578		
579		var itemW = $masonry_container.data('item-width');
580		var containerW = $masonry_container.width();
581		var items = $masonry_container.children('.hentry');
582		var columns = Math.round(containerW/itemW);
583	
584		// set the widths (%) for each of item
585		items.each(function(index, element) {
586			var multiplier = $(this).hasClass('x2') && columns > 1 ? 2 : 1;
587			var itemRealWidth = (Math.floor( containerW / columns ) * 100 / containerW) * multiplier ;
588			$(this).css( 'width', itemRealWidth + '%' );
589		});
590	
591		var columnWidth = Math.floor( containerW / columns );
592		$masonry_container.isotope( 'option', { masonry: { columnWidth: columnWidth } } );
593	}
594	// ------------------------------
595	
596	
597	
598	// ------------------------------
599	// LIGHTBOX
600	function setupLigtbox() {	
601		
602		if($(".lightbox").length) {
603			
604			$('.media-box, .r-gallery-single').each(function(index, element) {
605				var $media_box = $(this);
606				$media_box.magnificPopup({
607					delegate: '.lightbox', // the selector for gallery item
608					gallery: {
609					  enabled: $media_box.find('.lightbox').length > 1 ? true : false
610					},
611					type: 'image',
612					iframe: {
613						 markup: '<div class="mfp-iframe-scaler">'+
614									'<div class="mfp-close"></div>'+
615									'<iframe class="mfp-iframe" frameborder="0" allowfullscreen></iframe>'+
616									'<div class="mfp-title">Some caption</div>'+
617								  '</div>'
618					  },
619					  callbacks: {
620						markupParse: function(template, values, item) {
621						 values.title = item.el.attr('title');
622						},
623				 	}
624				});
625				
626			});
627		}
628	}
629	// ------------------------------	
630	
631})(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.