Skip to content

Commit

Permalink
Create polyfill-jquery.js
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonrt committed Oct 11, 2015
1 parent 10cf9b8 commit 4739d91
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/polyfill-jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(function($) {
// Add inner and outer width to zepto (adapted from https://gist.github.com/alanhogan/3935463)
var ioDim = function(dimension, includeBorder) {
return function (includeMargin) {
var sides, size, elem;
if (this) {
elem = this;
size = elem[dimension]();
sides = {
width: ["left", "right"],
height: ["top", "bottom"]
};
sides[dimension].forEach(function(side) {
size += parseInt(elem.css("padding-" + side), 10);
if (includeBorder) {
size += parseInt(elem.css("border-" + side + "-width"), 10);
}
if (includeMargin) {
size += parseInt(elem.css("margin-" + side), 10);
}
});
return size;
} else {
return null;
}
}
};
["width", "height"].forEach(function(dimension) {
var Dimension = dimension.substr(0,1).toUpperCase() + dimension.substr(1);
$.fn["inner" + Dimension] = ioDim(dimension, false);
$.fn["outer" + Dimension] = ioDim(dimension, true);
});
})(Zepto);

0 comments on commit 4739d91

Please sign in to comment.