1 2/* 3 * Get Viewport Dimensions 4 * returns object with viewport dimensions to match css in width and height properties 5 * ( source: http://andylangton.co.uk/blog/development/get-viewport-size-width-and-height-javascript ) 6*/ 7function updateViewportDimensions() { 8 var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight; 9 return { width:x,height:y }; 10} 11// setting the viewport width 12var viewport = updateViewportDimensions(); 13 14 15/* 16 * Throttle Resize-triggered Events 17 * Wrap your actions in this function to throttle the frequency of firing them off, for better performance, esp. on mobile. 18 * ( source: http://stackoverflow.com/questions/2854407/javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed ) 19*/ 20var waitForFinalEvent = (function () { 21 var timers = {}; 22 return function (callback, ms, uniqueId) { 23 if (!uniqueId) { uniqueId = "Don't call this twice without a uniqueId"; } 24 if (timers[uniqueId]) { clearTimeout (timers[uniqueId]); } 25 timers[uniqueId] = setTimeout(callback, ms); 26 }; 27})(); 28 29// how long to wait before deciding the resize has stopped, in ms. Around 50-100 should work ok. 30var timeToWaitForLast = 100; 31 32var scroll = window.requestAnimationFrame || 33 function(callback){ window.setTimeout(callback, 1000/60)}; 34var elementsToShow; 35function loop() { 36 //if( elementsToShow){ 37 elementsToShow.each(function (index, element) { 38 if (isElementInViewport(element)) { 39 jQuery(element).addClass('is-visible'); 40 } else { 41 jQuery(element).removeClass('is-visible'); 42 } 43 }); 44 //} 45 46 47 scroll(loop); 48} 49 50// Helper function from: http://stackoverflow.com/a/7557433/274826 51function isElementInViewport(el) { 52 // special bonus for those using jQuery 53 if (typeof jQuery === "function" && el instanceof jQuery) { 54 el = el.get(0); 55 } 56 //console.log(el); 57 var rect = el.getBoundingClientRect(); 58 return ( 59 (rect.top <= 0 60 && rect.bottom >= 0) 61 || 62 (rect.bottom >= (window.innerHeight || document.documentElement.clientHeight) && 63 rect.top <= (window.innerHeight || document.documentElement.clientHeight)) 64 || 65 (rect.top >= 0 && 66 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)) 67 ); 68} 69 70/* 71 * Here's an example so you can see how we're using the above function 72 * 73 * This is commented out so it won't work, but you can copy it and 74 * remove the comments. 75 * 76 * 77 * 78 * If we want to only do it on a certain page, we can setup checks so we do it 79 * as efficient as possible. 80 * 81 * if( typeof is_home === "undefined" ) var is_home = $('body').hasClass('home'); 82 * 83 * This once checks to see if you're on the home page based on the body class 84 * We can then use that check to perform actions on the home page only 85 * 86 * When the window is resized, we perform this function 87 * $(window).resize(function () { 88 * 89 * // if we're on the home page, we wait the set amount (in function above) then fire the function 90 * if( is_home ) { waitForFinalEvent( function() { 91 * 92 * // update the viewport, in case the window size has changed 93 * viewport = updateViewportDimensions(); 94 * 95 * // if we're above or equal to 768 fire this off 96 * if( viewport.width >= 768 ) { 97 * console.log('On home page and window sized to 768 width or more.'); 98 * } else { 99 * // otherwise, let's do this instead 100 * console.log('Not on home page, or window sized to less than 768.'); 101 * } 102 * 103 * }, timeToWaitForLast, "your-function-identifier-string"); } 104 * }); 105 * 106 * Pretty cool huh? You can create functions like this to conditionally load 107 * content and other stuff dependent on the viewport. 108 * Remember that mobile devices and javascript aren't the best of friends. 109 * Keep it light and always make sure the larger viewports are doing the heavy lifting. 110 * 111*/ 112 113/* 114 * We're going to swap out the gravatars. 115 * In the functions.php file, you can see we're not loading the gravatar 116 * images on mobile to save bandwidth. Once we hit an acceptable viewport 117 * then we can swap out those images since they are located in a data attribute. 118*/ 119/* 120function loadGravatars() { 121 // set the viewport using the function above 122 viewport = updateViewportDimensions(); 123 // if the viewport is tablet or larger, we load in the gravatars 124 if (viewport.width >= 768) { 125 jQuery('.comment img[data-gravatar]').each(function(){ 126 jQuery(this).attr('src',jQuery(this).attr('data-gravatar')); 127 }); 128 } 129} // end function 130*/ 131function setUpMobileMenu(){ 132 jQuery("#mobile-menu-activator").click(function(){ 133 jQuery(this).toggleClass("active"); 134 jQuery(".top-nav").toggleClass("active"); 135 jQuery("#main-footer").toggleClass("active"); 136 }); 137} 138function setUpSearch(){ 139 jQuery(".search-box input").attr("placeholder","Search"); 140 jQuery(".search-icon").click(function(e){ 141 console.log("search-icon"); 142 jQuery(".search-box input").attr("placeholder", ""); 143 144 setTimeout(function(){ jQuery(".search-box input").focus(); }, 500); 145 //if(jQuery(".search-box").hasClass("active")){ 146 147 //}else{ 148 jQuery(".search-box").toggleClass("active"); 149 e.preventDefault(); 150 e.stopPropagation(); 151 e.stopImmediatePropagation(); 152 //} 153 154 155 return false;
156 }); 157} 158function setUpDotmail(){ 159 jQuery(".signup-btn").click(function(){ 160 //console.log("hi signup"); 161 jQuery(".dotmail-popup").addClass("active"); 162 }); 163 jQuery(".dotmail-popup .close-btn").click(function(){ 164 jQuery(".dotmail-popup").removeClass("active"); 165 }); 166 jQuery('input#FIRSTNAME, input#LASTNAME, input.email').on('change', function() { 167 var $this = jQuery(this); 168 var value = jQuery.trim($this.val()); 169 170 // toggleClass can be provided a bool value, 171 // If we provide true we add class, if false we remove class 172 $this.toggleClass('filled-background', value.length !== 0); 173 }).change(); 174 175} 176function youtube_parser(url){ 177 var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/; 178 var match = url.match(regExp); 179 return (match&&match[7].length==11)? match[7] : false; 180} 181var firstLoad = false; 182var ratio; 183function setUpGalleries(){ 184 //console.log("hello NTTD"); 185 /* 186 jQuery(".arrow.arrow-right").click(function(){ 187 //console.log("hi lefty"); 188 var gallery = jQuery(this).parent().find(".carousel"); 189 var width = gallery.find("li").first().width()+6.4; 190 gallery.animate({scrollLeft: "+="+width }, 500); 191 }); 192 jQuery(".arrow.arrow-left").click(function(){ 193 //console.log("hi righty"); 194 var gallery = jQuery(this).parent().find(".carousel"); 195 var width = gallery.find("li").first().width()+6.4; 196 gallery.animate({scrollLeft: '-='+width }, 500); 197 }); 198 */ 199 //only on desktop: 200 jQuery("#image_0 img").on('load',function(){ 201 var myImage = jQuery(this); 202 if(!firstLoad){ 203 204 console.log("firstLOad",myImage); 205 var imgHeight = myImage.height(); 206 var imgWidth = myImage.width(); 207 ratio = (imgHeight/imgWidth); 208 console.log("ratio", ratio); 209 //myImage.css({"position":"absolute", "width":"auto"}); 210 //"padding-bottom":ratio+"%", 211 //jQuery(".post_image.carousel-1").css({"height": imgHeight+"px" }); 212 firstLoad = true; 213 }else{ 214 215 //var imgWidth = myImage.width(); 216 //var deltaW = jQuery(".post_image.carousel-1").width() - imgWidth; 217 //var offset = imgWidth/2; 218 //console.log("deltaW", deltaW); 219 220 //myImage.css({ "transform":"translateX(- "+offset+"px)"}); 221 } 222 223 }).each(function(){ 224 if(this.complete) { 225 jQuery(this).trigger('load'); 226 } 227 }); 228 /**/ 229 jQuery(".small-carousel-container .carousel li a").click(function(e){ 230 if (jQuery(window).width() >= 768) { 231 e.preventDefault(); 232 e.stopPropagation() 233 console.log("hi image", jQuery(this).attr("href") ); 234 //set the href on our main image: 235 //first get the height of the image and retain it: 236 var myImage = jQuery("#image_0 img"); 237 //var imgHeight = myImage.height(); 238 239 //height:100%; 240 //max-width:100%; 241 //myImage.attr("style", "max-height:"+imgHeight+"px;max-width:none; min-height:"+imgHeight+"px; width:auto; " ); 242 243 myImage.addClass("is-loading"); 244 var href = jQuery(this).attr("href"); 245 setTimeout(function(){ 246 myImage.attr("src", href); 247 myImage.parent().find('iframe').remove(); 248 if(href.indexOf("youtube")>=0){ 249 myImage.parent().append('<iframe style="width:100%;height:100%;position: absolute; z-index:2;" width="100%" height="100%" src="https://www.youtube.com/embed/'+youtube_parser(href)+'?rel=0&hd=1&wmode=opaque&" frameborder="0" allowfullscreen></iframe>'); 250 251 }else{ 252 253 myImage.on("load",function(){jQuery(this).removeClass("is-loading");}).each(function(){ 254 if(this.complete) { 255 jQuery(this).trigger('load'); 256 } 257 }); 258 } 259 260 }, 250); 261 } 262 263 264 }) 265 266 267} 268function randomIntFromInterval(min, max) { // min and max included 269 return Math.floor(Math.random() * (max - min + 1) + min); 270} 271function getMoreStories(category,tag, posts_per_page, offset, div, allloaded){ 272 if(!allloaded){ 273 var ajaxurl = '/wp-admin/admin-ajax.php'; 274 jQuery.ajax( ajaxurl, { 275 type: 'POST', 276 data: { action: 'get_more_stories', // The name of the WP action 277 'category': category, 278 'tag':tag, 279 'posts_per_page': posts_per_page, 280 'offset': offset, 281 'nonce': more_stories_nonce// the dataVAlues 282 }, 283 dataType: 'json', 284 complete : function ( response ) { 285 jQuery(".btn-more").removeClass('is-loading'); 286 // optionally to develop in any case: success or error 287 //console.log(response); 288 }, 289 success: function ( response ) { // to develop in case of success 290 if ( response.success ) { 291 moreHTML = response.data.html; // Here we get the results of the PHP remote function 292 console.log("more: ", moreHTML); 293 div.append(moreHTML); 294 setUpImages(); 295 //now scoll to the left 296 var width = div.width(); 297 div.animate({scrollLeft: "+="+(width) }, 500); 298 } else { 299 //console.log("no more stories"); 300 } 301 }, 302 error: function ( errorThrown ) { // to develop in case of error 303 //console.log( errorThrown ); 304 }, 305 }); 306 }else{ 307 var width = div.width(); 308 div.animate({scrollLeft: "+="+(width) }, 500); 309 } 310} 311function setUpMoreBtns(){ 312 jQuery(".btn-more").data("clicks", 0); 313 jQuery(".btn-prev").click(function(e){ 314 var div = jQuery(this).parent().find("ul"); 315 var width = div.width(); 316 var targetSL = div.scrollLeft()-width; 317 div.animate({scrollLeft: targetSL }, 500); 318 var btnMore =jQuery(this).parent().find(".btn-more"); 319 btnMore.removeClass("deactivate"); 320 btnMore.data("clicks", btnMore.data("clicks")-1); 321 //if( jQuery(this).data("clicks") <=3){ 322 323 // }
324 if(targetSL<=0){ 325 jQuery(this).removeClass("active"); 326 btnMore.find(".more").removeClass("hide"); 327 } 328 329 }); 330 jQuery(".btn-more").click(function(e){ 331 //get details from the data attribute: 332 if (typeof jQuery(this).data("clicks") == 'undefined') { 333 jQuery(this).data("clicks",0); 334 } 335 jQuery(this).data("clicks", jQuery(this).data("clicks")+1); 336 if( jQuery(this).data("clicks") <=3){ 337 var allLoaded = jQuery(this).data("allloaded"); 338 //show previous: 339 jQuery(this).parent().find(".btn-prev").addClass("active"); 340 //hide "More" 341 jQuery(this).find(".more").addClass("hide"); 342 if(!allLoaded){ 343 jQuery(this).addClass("is-loading"); 344 } 345 346 var category = jQuery(this).data('category'); 347 var tag = jQuery(this).data('tag'); 348 var posts_per_page = jQuery(this).data('posts_per_page')||randomIntFromInterval(2,4);//jQuery(this).data('posts_per_page'); 349 var offset = jQuery(this).data('offset'); 350 //console.log(category, posts_per_page, offset); 351 //do ajax call: 352 getMoreStories(category, tag, posts_per_page, offset,jQuery(this).parent().find("ul"), allLoaded ); 353 jQuery(this).data('offset',offset+posts_per_page ); 354 } 355 if( jQuery(this).data("clicks") ==3){ 356 jQuery(this).data("allloaded", 1); 357 jQuery(this).addClass("deactivate"); 358 } 359 360 361 }) 362} 363function setUpScrollingAnimations(){ 364 elementsToShow = jQuery(".animate-on-scroll"); 365 //console.log("ho",elementsToShow); 366 loop(); 367} 368 369function setUpImages(){ 370 jQuery(".img-container img").on('load', function(){ 371 //console.log("loaded: ", jQuery(this)); 372 jQuery(this).addClass("has-loaded"); 373 }).each(function(){ 374 if(this.complete) { 375 jQuery(this).trigger('load'); 376 } 377 }); 378} 379function setUpSearchSubmission(){ 380 jQuery(".search .search-icon").on("click", function(){ 381 jQuery(".search #searchform").submit(); 382 }) 383} 384function setUpPrettyPhotos(){ 385 var prettyPhotos = jQuery("a[rel^='prettyPhoto']"); 386 if(prettyPhotos.length){ 387 console.log("have pretty photos"); 388 prettyPhotos.swipebox(); 389 } 390} 391/* 392widow animation resize handler to stop animation when resing window 393*/ 394var resizeTimer; 395window.addEventListener("resize", function() { 396 document.body.classList.add("resize-animation-stopper"); 397 clearTimeout(resizeTimer); 398 resizeTimer = setTimeout(function() { 399 document.body.classList.remove("resize-animation-stopper"); 400 }, 400); 401}); 402 403 404 405/* 406 * Put all your regular jQuery in here. 407*/ 408jQuery(document).ready(function($) { 409 //console.log("ready"); 410 //loadGravatars(); 411 setUpMobileMenu(); 412 setUpSearch(); 413 setUpDotmail(); 414 setUpGalleries(); 415 setUpMoreBtns(); 416 setUpScrollingAnimations(); 417 setUpImages(); 418 setUpSearchSubmission(); 419 setUpPrettyPhotos(); 420 421}); /* end of as page load scripts */
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.