Skip to content

Instantly share code, notes, and snippets.

@tkafka
Forked from wheresrhys/gist:5823198
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkafka/1bccde7e15588521f614 to your computer and use it in GitHub Desktop.
Save tkafka/1bccde7e15588521f614 to your computer and use it in GitHub Desktop.
(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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment