Explorar o código

removed Modernizr load example

removed imgsizer (this is now in Modernizr)
cleaned up js so it doesn't give errors with JSLint
added some responsive js fun
html5 placeholder fallback function
eddiemachado %!s(int64=13) %!d(string=hai) anos
pai
achega
ab49f3825d
Modificáronse 1 ficheiros con 94 adicións e 25 borrados
  1. 94 25
      library/js/scripts.js

+ 94 - 25
library/js/scripts.js

@@ -4,38 +4,51 @@ Author: Eddie Machado
 
 This file should contain any js scripts you want to add to the site.
 Instead of calling it in the header or throwing it inside wp-head()
-this file will be called automatically in the footer so as not to 
+this file will be called automatically in the footer so as not to
 slow the page load.
 
 */
 
-// Modernizr.load loading the right scripts only if you need them
-Modernizr.load([
-	{
-    // Let's see if we need to load selectivizr
-    test : Modernizr.borderradius,
-    // Modernizr.load loads selectivizr for IE6-8
-    nope : ['selectivizr-min.js']
-	}
-]);
-
-/* imgsizer (flexible images for fluid sites) */
-var imgSizer={Config:{imgCache:[],spacer:"/path/to/your/spacer.gif"},collate:function(aScope){var isOldIE=(document.all&&!window.opera&&!window.XDomainRequest)?1:0;if(isOldIE&&document.getElementsByTagName){var c=imgSizer;var imgCache=c.Config.imgCache;var images=(aScope&&aScope.length)?aScope:document.getElementsByTagName("img");for(var i=0;i<images.length;i++){images[i].origWidth=images[i].offsetWidth;images[i].origHeight=images[i].offsetHeight;imgCache.push(images[i]);c.ieAlpha(images[i]);images[i].style.width="100%";}
-if(imgCache.length){c.resize(function(){for(var i=0;i<imgCache.length;i++){var ratio=(imgCache[i].offsetWidth/imgCache[i].origWidth);imgCache[i].style.height=(imgCache[i].origHeight*ratio)+"px";}});}}},ieAlpha:function(img){var c=imgSizer;if(img.oldSrc){img.src=img.oldSrc;}
-var src=img.src;img.style.width=img.offsetWidth+"px";img.style.height=img.offsetHeight+"px";img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')"
-img.oldSrc=src;img.src=c.Config.spacer;},resize:function(func){var oldonresize=window.onresize;if(typeof window.onresize!='function'){window.onresize=func;}else{window.onresize=function(){if(oldonresize){oldonresize();}
-func();}}}}
+// as the page loads, call these scripts
+jQuery(document).ready(function($) {
 
-// as the page loads, cal these scripts
-$(document).ready(function() {
-
-	
+    /******** RESPONSIVE GOODNESS *********/
+    
+    /* getting viewport width */
+    var responsive_viewport = $(window).width();
+    
+    /* if is below 481px */
+    if (responsive_viewport < 481) {
+    
+    } /* end smallest screen */
+    
+    /* if is larger than 481px */
+    if (responsive_viewport > 481) {
+        
+    } /* end larger than 481px */
+    
+    /* if is above 768px */
+    if (responsive_viewport > 768) {
+    
+        /* load gravatars */
+        $('.comment img[data-gravatar]').each(function(){
+            $(this).attr('src',$(this).attr('data-gravatar'));
+        });
+        
+    }
+    
+    /* off the bat large screen actions */
+    if (responsive_viewport > 1030) {
+        
+    }
+    
 	
 	// add all your scripts here
-
+	
  
 }); /* end of as page load scripts */
 
+
 // HTML5 Fallbacks for older browsers
 $(function() {
     // check placeholder browser support
@@ -47,12 +60,12 @@ $(function() {
  
         // focus and blur of placeholders
         $('[placeholder]').focus(function() {
-            if ($(this).val() == $(this).attr('placeholder')) {
+            if ($(this).val() === $(this).attr('placeholder')) {
                 $(this).val('');
                 $(this).removeClass('placeholder');
             }
         }).blur(function() {
-            if ($(this).val() == '' || $(this).val() == $(this).attr('placeholder')) {
+            if ($(this).val() === '' || $(this).val() === $(this).attr('placeholder')) {
                 $(this).val($(this).attr('placeholder'));
                 $(this).addClass('placeholder');
             }
@@ -61,7 +74,7 @@ $(function() {
         // remove placeholders on submit
         $('[placeholder]').closest('form').submit(function() {
             $(this).find('[placeholder]').each(function() {
-                if ($(this).val() == $(this).attr('placeholder')) {
+                if ($(this).val() === $(this).attr('placeholder')) {
                     $(this).val('');
                 }
             });
@@ -69,3 +82,59 @@ $(function() {
     }
 });
 
+
+/*! A fix for the iOS orientationchange zoom bug.
+ Script by @scottjehl, rebound by @wilto.
+ MIT License.
+*/
+(function(w){
+	
+	// This fix addresses an iOS bug, so return early if the UA claims it's something else.
+	if( !( /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1 ) ){
+		return;
+	}
+	
+    var doc = w.document;
+
+    if( !doc.querySelector ){ return; }
+
+    var meta = doc.querySelector( "meta[name=viewport]" ),
+        initialContent = meta && meta.getAttribute( "content" ),
+        disabledZoom = initialContent + ",maximum-scale=1",
+        enabledZoom = initialContent + ",maximum-scale=10",
+        enabled = true,
+		x, y, z, aig;
+
+    if( !meta ){ return; }
+
+    function restoreZoom(){
+        meta.setAttribute( "content", enabledZoom );
+        enabled = true;
+    }
+
+    function disableZoom(){
+        meta.setAttribute( "content", disabledZoom );
+        enabled = false;
+    }
+	
+    function checkTilt( e ){
+		aig = e.accelerationIncludingGravity;
+		x = Math.abs( aig.x );
+		y = Math.abs( aig.y );
+		z = Math.abs( aig.z );
+				
+		// If portrait orientation and in one of the danger zones
+        if( !w.orientation && ( x > 7 || ( ( z > 6 && y < 8 || z < 8 && y > 6 ) && x > 5 ) ) ){
+			if( enabled ){
+				disableZoom();
+			}
+        }
+		else if( !enabled ){
+			restoreZoom();
+        }
+    }
+	
+	w.addEventListener( "orientationchange", restoreZoom, false );
+	w.addEventListener( "devicemotion", checkTilt, false );
+
+})( this );