Skip to content

Instantly share code, notes, and snippets.

@phantamanta44
Last active August 29, 2015 14:24
Show Gist options
  • Save phantamanta44/79c42337a9b41720a5b4 to your computer and use it in GitHub Desktop.
Save phantamanta44/79c42337a9b41720a5b4 to your computer and use it in GitHub Desktop.
Too lazy to do proper formatting in droidedit
function GabeN(ratio, imageurl) {
this.ratio = ratio;
this.imageurl = imageurl
}
var getGabeN = {
init: function(myGabeN) {
this.myGabeN = myGabeN
},
horizontal: function() {
return this.myGabeN.filter(function(myGabeN) {
return myGabeN.ratio === "horizontal"
})
},
vertical: function() {
return this.myGabeN.filter(function(myGabeN) {
return myGabeN.ratio === "vertical"
})
},
square: function() {
return this.myGabeN.filter(function(myGabeN) {
return myGabeN.ratio === "square"
})
}
};
function Randomize(images) {
return Math.floor(Math.random() * images.length)
}
var myGabeN = [new GabeN("horizontal", "http://i.imgur.com/uLMbKmj.jpg"), new GabeN("horizontal", "http://i.imgur.com/5DXQ7tx.jpg"), new GabeN("horizontal", "http://i.imgur.com/dldrXOf.jpg"), new GabeN("horizontal", "http://i.imgur.com/8uH9TQb.jpg"), new GabeN("horizontal", "http://i.imgur.com/7wU40jQ.jpg"), new GabeN("horizontal", "http://i.imgur.com/ajxvdWo.jpg"), new GabeN("vertical", "http://i.imgur.com/aRCPVmX.jpg"), new GabeN("vertical", "http://i.imgur.com/FU2unZO.jpg"), new GabeN("vertical", "http://i.imgur.com/3brJDRx.jpg"), new GabeN("vertical", "http://i.imgur.com/j9KOnWm.jpg"), new GabeN("square", "http://i.imgur.com/sWCcEwV.jpg"), new GabeN("square", "http://i.imgur.com/ecbdpfL.jpg"), new GabeN("square", "http://i.imgur.com/lDkMf5P.jpg"), new GabeN("square", "http://i.imgur.com/qkcP48v.jpg")];
function imageRatio(image) {
var proportion = image.height() / image.width();
if (proportion > 1) return "vertical";
else if (proportion === 1) return "square";
else if (proportion < 1) return "horizontal"
}
function getAGabe(ratio) {
if (ratio === "horizontal") {
var number = Randomize(getGabeN.horizontal());
var img = getGabeN.horizontal()[number];
return img.imageurl;
} else if (ratio === "square") {
var number = Randomize(getGabeN.square());
var img = getGabeN.square()[number];
return img.imageurl;
} else if (ratio === "vertical") {
var number = Randomize(getGabeN.vertical());
var img = getGabeN.vertical()[number];
return img.imageurl;
}
}
function randomRatio() {
var num = Math.floor(Math.random() * 3);
return num === 0 ? "square" : (num === 1 ? "horizontal" : "vertical");
}
(function(document) {
getGabeN.init(myGabeN);
$('*').each(function(i, val) {
var obj = $(val);
if (obj.is("img"))
obj.attr("src", getAGabe(imageRatio(obj)));
else if (!!obj.css("background-image") && obj.css("background-image") != "none")
obj.css("background-image", 'url(' + getAGabe(randomRatio()) + ')');
});
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment