Permalink
Browse files

more meh

  • Loading branch information...
1 parent f3eaef8 commit 765fbea4c6bbaec34c2ba57ef6ce4d1ad23dab42 @adeelejaz committed Mar 26, 2013
Showing with 53 additions and 122 deletions.
  1. +0 −69 jquery.ae.image.resize.js
  2. +53 −53 src/jquery.ae.image.resize.js
View
@@ -1,69 +0,0 @@
-;(function( $ ) {
-
- $.fn.aeImageResize = function( params ) {
-
- var aspectRatio = 0;
-
- // We cannot do much unless we have one of these
- if ( !params.height && !params.width ) {
- return this;
- }
-
- // Calculate aspect ratio now, if possible
- if ( params.height && params.width ) {
- aspectRatio = params.width / params.height;
- }
-
- // Attach handler to load
- // Handler is executed just once per element
- // Load event required for Webkit browsers
- return this.one( "load", function() {
-
- // Remove all attributes and CSS rules
- this.removeAttribute( "height" );
- this.removeAttribute( "width" );
- this.style.height = this.style.width = "";
-
- var imgHeight = this.height
- , imgWidth = this.width
- , imgAspectRatio = imgWidth / imgHeight
- , bxHeight = params.height
- , bxWidth = params.width
- , bxAspectRatio = aspectRatio;
-
- // Work the magic!
- // If one parameter is missing, we just force calculate it
- if ( !bxAspectRatio ) {
- if ( bxHeight ) {
- bxAspectRatio = imgAspectRatio + 1;
- } else {
- bxAspectRatio = imgAspectRatio - 1;
- }
- }
-
- // Only resize the images that need resizing
- if ( (bxHeight && imgHeight > bxHeight) || (bxWidth && imgWidth > bxWidth) ) {
-
- if ( imgAspectRatio > bxAspectRatio ) {
- bxHeight = ~~ ( imgHeight / imgWidth * bxWidth );
- } else {
- bxWidth = ~~ ( imgWidth / imgHeight * bxHeight );
- }
-
- this.height = bxHeight;
- this.width = bxWidth;
- }
- })
- .each(function() {
-
- // Trigger load event (for Gecko and MSIE)
- if ( this.complete ) {
- $( this ).trigger( "load" );
- }
-
- // This fixes IE9 issue
- this.src = this.src;
- });
- };
-
-})( jQuery );
@@ -1,69 +1,69 @@
;(function( $ ) {
- $.fn.aeImageResize = function( params ) {
+ $.fn.aeImageResize = function( params ) {
- var aspectRatio = 0;
+ var aspectRatio = 0;
- // We cannot do much unless we have one of these
- if ( !params.height && !params.width ) {
- return this;
- }
+ // We cannot do much unless we have one of these
+ if ( !params.height && !params.width ) {
+ return this;
+ }
- // Calculate aspect ratio now, if possible
- if ( params.height && params.width ) {
- aspectRatio = params.width / params.height;
- }
+ // Calculate aspect ratio now, if possible
+ if ( params.height && params.width ) {
+ aspectRatio = params.width / params.height;
+ }
- // Attach handler to load
- // Handler is executed just once per element
- // Load event required for Webkit browsers
- return this.one( "load", function() {
+ // Attach handler to load
+ // Handler is executed just once per element
+ // Load event required for Webkit browsers
+ return this.one( "load", function() {
- // Remove all attributes and CSS rules
- this.removeAttribute( "height" );
- this.removeAttribute( "width" );
- this.style.height = this.style.width = "";
+ // Remove all attributes and CSS rules
+ this.removeAttribute( "height" );
+ this.removeAttribute( "width" );
+ this.style.height = this.style.width = "";
- var imgHeight = this.height
- , imgWidth = this.width
- , imgAspectRatio = imgWidth / imgHeight
- , bxHeight = params.height
- , bxWidth = params.width
- , bxAspectRatio = aspectRatio;
+ var imgHeight = this.height
+ , imgWidth = this.width
+ , imgAspectRatio = imgWidth / imgHeight
+ , bxHeight = params.height
+ , bxWidth = params.width
+ , bxAspectRatio = aspectRatio;
- // Work the magic!
- // If one parameter is missing, we just force calculate it
- if ( !bxAspectRatio ) {
- if ( bxHeight ) {
- bxAspectRatio = imgAspectRatio + 1;
- } else {
- bxAspectRatio = imgAspectRatio - 1;
- }
- }
+ // Work the magic!
+ // If one parameter is missing, we just force calculate it
+ if ( !bxAspectRatio ) {
+ if ( bxHeight ) {
+ bxAspectRatio = imgAspectRatio + 1;
+ } else {
+ bxAspectRatio = imgAspectRatio - 1;
+ }
+ }
- // Only resize the images that need resizing
- if ( (bxHeight && imgHeight > bxHeight) || (bxWidth && imgWidth > bxWidth) ) {
+ // Only resize the images that need resizing
+ if ( (bxHeight && imgHeight > bxHeight) || (bxWidth && imgWidth > bxWidth) ) {
- if ( imgAspectRatio > bxAspectRatio ) {
- bxHeight = ~~ ( imgHeight / imgWidth * bxWidth );
- } else {
- bxWidth = ~~ ( imgWidth / imgHeight * bxHeight );
- }
+ if ( imgAspectRatio > bxAspectRatio ) {
+ bxHeight = ~~ ( imgHeight / imgWidth * bxWidth );
+ } else {
+ bxWidth = ~~ ( imgWidth / imgHeight * bxHeight );
+ }
- this.height = bxHeight;
- this.width = bxWidth;
- }
- })
- .each(function() {
+ this.height = bxHeight;
+ this.width = bxWidth;
+ }
+ })
+ .each(function() {
- // Trigger load event (for Gecko and MSIE)
- if ( this.complete ) {
- $( this ).trigger( "load" );
- }
+ // Trigger load event (for Gecko and MSIE)
+ if ( this.complete ) {
+ $( this ).trigger( "load" );
+ }
- // This fixes IE9 issue
- this.src = this.src;
- });
- };
+ // This fixes IE9 issue
+ this.src = this.src;
+ });
+ };
})( jQuery );

0 comments on commit 765fbea

Please sign in to comment.