Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. <div class="hierarchy">
  2. <div class="content-preview">
  3. @for($i = 0; $i < 4; $i++)
  4. <ul class="column">
  5. @for($j = 0; $j <= rand(1,2); $j++)
  6. <?php $size = rand(1,2) ?>
  7. <li class="size-{{$size}}" data-size="{{$size}}">
  8. Content
  9. <div class="row-options">
  10. <span class="js-size-action" data-action="bigger">+</span>
  11. <span class="js-size-action" data-action="smaller">-</span>
  12. </div>
  13. </li>
  14. @endfor
  15. </ul>
  16. @endfor
  17. </div>
  18. </div>
  19.  
  20. <style>
  21. .hierarchy{
  22. margin-top: 20px;
  23. display: block;
  24. }
  25.  
  26. .hierarchy * { box-sizing: border-box; }
  27.  
  28. .content-preview{
  29. border-radius: 4px;
  30. width: 1002px;
  31. background: #ccc;
  32. overflow: hidden;
  33. border: 1px solid #888;
  34. }
  35.  
  36. .content-preview ul{
  37. padding: 0;
  38. margin: 0;
  39. list-style: none;
  40. float: left;
  41. width: 250px;
  42. vertical-align: top;
  43. height: 500px;
  44. border-right: 1px solid #888;
  45. }
  46.  
  47. .content-preview ul:last-child{
  48. border-right: none;
  49. }
  50.  
  51. .content-preview li{
  52. height: 100px;
  53. background: #bbb;
  54. padding: 5px;
  55. margin: 0;
  56. box-shadow: 0 1px 0 red;
  57. position: relative;
  58. }
  59.  
  60. .content-preview li:after{
  61. content: '';
  62. width: 100%;
  63. height: 1px;
  64. background: #888;
  65. left: 0;
  66. position: absolute;
  67. bottom: -1px;
  68. z-index: 2;
  69. }
  70.  
  71. .row-options{
  72. font-size: 24px;
  73. cursor: pointer;
  74. -webkit-touch-callout: none;
  75. -webkit-user-select: none;
  76. -khtml-user-select: none;
  77. -moz-user-select: none;
  78. -ms-user-select: none;
  79. user-select: none;
  80. }
  81.  
  82. .content-preview li.size-2{ height: 200px; }
  83. .content-preview li.size-3{ height: 300px; }
  84. .content-preview li.size-4{ height: 400px; }
  85. .content-preview li.size-5{ height: 500px; }
  86. </style>
  87.  
  88. <script>
  89. (function($){
  90. var maxSize = 5;
  91.  
  92. function updateColumnTotal(){
  93. $('.column').each(function(){
  94. var columnTotal = 0;
  95. $(this).find('li').each(function(){
  96. columnTotal = columnTotal + parseInt($(this).data('size'));
  97. });
  98. $(this).data('total', columnTotal);
  99. console.log(columnTotal)
  100. });
  101. }
  102. updateColumnTotal();
  103.  
  104. $('.js-size-action').click(function(){
  105. var $this = $(this);
  106. var $li = $this.closest('li');
  107. var $column = $this.closest('ul');
  108.  
  109. var action = $this.data('action');
  110. var size = $li.data('size')
  111.  
  112. if(action == 'bigger'){
  113. size++
  114. if($column.data('total') + 1 > maxSize){
  115. alert('Too Big')
  116. return;
  117. }
  118. }
  119.  
  120. if(action == 'smaller'){
  121. size--;
  122. if(size == 0){
  123. alert('Too Small')
  124. return;
  125. }
  126. }
  127.  
  128. $li.data('size', size);
  129. $li.attr('class', '').addClass('size-'+size);
  130. updateColumnTotal();
  131. });
  132. })(jQuery)
  133. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement