scripts.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. Bones Scripts File
  3. Author: Eddie Machado
  4. This file should contain any js scripts you want to add to the site.
  5. Instead of calling it in the header or throwing it inside wp-head()
  6. this file will be called automatically in the footer so as not to
  7. slow the page load.
  8. */
  9. // Modernizr.load loading the right scripts only if you need them
  10. Modernizr.load([
  11. {
  12. // Let's see if we need to load selectivizr
  13. test : Modernizr.borderradius,
  14. // Modernizr.load loads selectivizr for IE6-8
  15. nope : ['selectivizr-min.js']
  16. }
  17. ]);
  18. /* imgsizer (flexible images for fluid sites) */
  19. 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%";}
  20. 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;}
  21. 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')"
  22. 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();}
  23. func();}}}}
  24. // as the page loads, cal these scripts
  25. $(document).ready(function() {
  26. // add all your scripts here
  27. }); /* end of as page load scripts */
  28. // HTML5 Fallbacks for older browsers
  29. $(function() {
  30. // check placeholder browser support
  31. if (!Modernizr.input.placeholder) {
  32. // set placeholder values
  33. $(this).find('[placeholder]').each(function() {
  34. $(this).val( $(this).attr('placeholder') );
  35. });
  36. // focus and blur of placeholders
  37. $('[placeholder]').focus(function() {
  38. if ($(this).val() == $(this).attr('placeholder')) {
  39. $(this).val('');
  40. $(this).removeClass('placeholder');
  41. }
  42. }).blur(function() {
  43. if ($(this).val() == '' || $(this).val() == $(this).attr('placeholder')) {
  44. $(this).val($(this).attr('placeholder'));
  45. $(this).addClass('placeholder');
  46. }
  47. });
  48. // remove placeholders on submit
  49. $('[placeholder]').closest('form').submit(function() {
  50. $(this).find('[placeholder]').each(function() {
  51. if ($(this).val() == $(this).attr('placeholder')) {
  52. $(this).val('');
  53. }
  54. });
  55. });
  56. }
  57. });