Skip to content

Instantly share code, notes, and snippets.

@manticorp
Created May 22, 2013 13:10
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 manticorp/5627427 to your computer and use it in GitHub Desktop.
Save manticorp/5627427 to your computer and use it in GitHub Desktop.
Plot function for JavaScript. Basically a wrapper for settings styles and stuff.
Plot = function (e) {
this.toCenter = function () {
d = Math.min(this.elm.width, this.elm.height);
mLR = Math.floor((document.documentElement.clientWidth - d) / 2);
mTB = Math.floor((document.documentElement.clientHeight - d) / 2);
this.setMargins(mTB, mLR, mTB, mLR);
this.position(Math.floor((document.documentElement.clientWidth - d) / 2), Math.floor((document.documentElement.clientHeight - d) / 2), true)
};
this.setDimensions = function (x, y) {
y = this.checkVar(y, x, false);
if (typeof x == "number") this.width = x;
if (typeof y == "number") this.height = y;
this.elm.style.width = this.checkVar(x);
this.elm.style.height = this.checkVar(y)
};
this.setSize = function (x, y) {
this.setDimensions(x, y)
};
this.setD = function (x, y) {
this.setDimensions(x, y)
};
this.D = function (x, y) {
this.setDimensions(x, y)
};
this.position = function (x, y) {
var a = arguments[2] ? 0 : this.width / 2;
var b = arguments[2] ? 0 : this.height / 2;
this.elm.style.left = this.checkVar(x - a);
this.elm.style.top = this.checkVar(y - b);
this.x = x;
this.y = y
};
this.setPositionStyle = function (a) {
this.elm.style.position = a
};
this.setColor = function (a) {
this.elm.style.color = a
};
this.setBackground = function (a) {
this.elm.style.background = this.checkVar(a, "#FFF")
};
this.setBackgroundImage = function (a) {
a = (typeof a == "undefined") ? "none" : "url('" + a + "')";
this.elm.style.backgroundImage = a
};
this.setBackgroundRepeat = function (a) {
this.elm.style.backgroundRepeat = a
};
this.setBackgroundPosition = function (x, y) {
this.elm.style.backgroundPosition = this.checkVar(x) + " " + this.checkVar(y)
};
this.setBackgroundSize = function (x, y) {
this.elm.style.backgroundSize = this.checkVar(x) + ", " + this.checkVar(y)
};
this.getBackgroundSize = function () {
return this.elm.style.backgroundSize
};
this.setLineHeight = function (x) {
this.elm.style.lineHeight = this.checkVar(x)
};
this.setMargins = function (a, b, c, d) {
this.elm.style.marginTop = this.checkVar(a);
this.elm.style.marginRight = this.checkVar(b, a);
this.elm.style.marginBottom = this.checkVar(c, a);
this.elm.style.marginLeft = this.checkVar(d, a)
};
this.setPadding = function (a, b, c, d) {
this.elm.style.paddingTop = this.checkVar(a);
this.elm.style.paddingRight = this.checkVar(b, a);
this.elm.style.paddingBottom = this.checkVar(c, a);
this.elm.style.paddingLeft = this.checkVar(d, a)
};
this.setId = function (a) {
this.elm.id = a
};
this.rotate = function (a) {
this.elm.style.webkitTransform = this.elm.style.MozTransform = this.elm.style.OTransform = this.elm.style.transform = 'rotate(' + a + ')'
};
this.content = function (a) {
this.elm.innerHTML = a
};
this.display = function (a) {
this.elm.style.display = a
};
this.style = function (a, b) {
this.elm.style[a] = b
};
this.round = function (a) {
this.elm.style.borderRadius = a ? '50%/50%' : ''
};
this.append = function () {
document.body.appendChild(this.elm)
};
this.remove = function () {
document.body.removeChild(this.elm)
};
this.checkVar = function (x, a, b) {
b = (typeof b == "undefined") ? true : b;
a = (typeof a == "undefined") ? 0 : a;
x = (typeof x == "undefined") ? a : x;
if (typeof x == "number" && b) x = (x == 0) ? x : x + "px";
return x
};
this.elm = e
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment