Advertisement
Guest User

Untitled

a guest
Jul 9th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. javascript: function GabeN(ratio, imageurl) {
  2. this.ratio = ratio;
  3. this.imageurl = imageurl
  4. }
  5. var getGabeN = {
  6. init: function(myGabeN) {
  7. this.myGabeN = myGabeN
  8. },
  9. horizontal: function() {
  10. return this.myGabeN.filter(function(myGabeN) {
  11. return myGabeN.ratio === "horizontal"
  12. })
  13. },
  14. vertical: function() {
  15. return this.myGabeN.filter(function(myGabeN) {
  16. return myGabeN.ratio === "vertical"
  17. })
  18. },
  19. square: function() {
  20. return this.myGabeN.filter(function(myGabeN) {
  21. return myGabeN.ratio === "square"
  22. })
  23. }
  24. };
  25.  
  26. function Randomize(images) {
  27. return Math.floor(Math.random() * images.length)
  28. }
  29. 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")];
  30.  
  31. function imageRatio(image) {
  32. var proportion = image.height / image.width;
  33. if (proportion > 1) return "vertical";
  34. else if (proportion === 1) return "square";
  35. else if (proportion < 1) return "horizontal"
  36. }(function(document) {
  37. getGabeN.init(myGabeN);
  38. var images = document.getElementsByTagName("img"),
  39. length = images.length;
  40. for (var i = 0; i < length; i++) {
  41. var ratio = imageRatio(images[i]);
  42. if (ratio === "horizontal") {
  43. var number = Randomize(getGabeN.horizontal());
  44. var img = getGabeN.horizontal()[number];
  45. images[i].src = img.imageurl
  46. } else if (ratio === "square") {
  47. var number = Randomize(getGabeN.square());
  48. var img = getGabeN.square()[number];
  49. images[i].src = img.imageurl
  50. } else if (ratio === "vertical") {
  51. var number = Randomize(getGabeN.vertical());
  52. var img = getGabeN.vertical()[number];
  53. images[i].src = img.imageurl
  54. }
  55. }
  56. })(document);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement