Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wall.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. function wall(parent, children, style, min) {
  2. var min = min || 2
  3. var b = $(parent+':not(.hidden)').raw()
  4. var bs = $(parent+':not(.hidden) '+children).toArray()
  5. if (!window.getComputedStyle(b).height) {return}
  6. bs.forEach(function(el){el.style.width='';el.style.height=''})
  7. var rows = []
  8. if (typeof(style) === 'number') {
  9. for (var i=0; i<bs.length; i+=style)
  10. rows.push(bs.slice(i,i+style))
  11. } else {
  12. var a = 0
  13. for (i in style) {
  14. rows.push(bs.slice(a, a+style[i]))
  15. a += style[i]
  16. }
  17. }
  18. if (rows.length >= 2 && rows[rows.length-1].length < min) {
  19. var needed = min - rows[rows.length-1].length
  20. if (rows[rows.length-2].length - needed >= min) {
  21. for(i=0; i<needed; i++) {
  22. rows[rows.length-1]=[rows[rows.length-2].pop()].concat(rows[rows.length-1])
  23. }
  24. } else {
  25. rows[rows.length-2] = rows[rows.length-2].concat(rows[rows.length-1])
  26. rows.splice(rows.length-1, 1)
  27. }
  28. }
  29. function getW(e) {
  30. var a = window.getComputedStyle(e).width.match(/[0-9.]+/)
  31. return a ? parseFloat(a[0]) : 0
  32. }
  33. function getH(e) {
  34. var a = window.getComputedStyle(e).height.match(/[0-9.]+/)
  35. return a ? parseFloat(a[0]) : 0
  36. }
  37. for (i in rows) {
  38. for (j in rows[i]) {
  39. rows[i][j].style.width = (getW(rows[i][j]) / getH(rows[i][j]) * 100) + 'px'
  40. rows[i][j].style.height = 100 + 'px'
  41. }
  42. var w = rows[i].reduce(function(x, y) { return x + getW(y) }, 0)
  43. for (j in rows[i]) {
  44. rows[i][j].style.height=(getH(rows[i][j])*(getW(b)-(4*rows[i].length))/w)+'px'
  45. rows[i][j].style.width=(getW(rows[i][j])*(getW(b)-(4*rows[i].length))/w)+'px'
  46. rows[i][j].style.display = 'inline-block'
  47. rows[i][j].style.margin = '1px'
  48. }
  49. }
  50. }