|
1 --- |
|
2 title: Spine align |
|
3 layout: default |
|
4 category: custom-layout-modes |
|
5 --- |
|
6 |
|
7 <section id="copy"> |
|
8 <p><a href="../docs/extending-isotope.html">Custom layout mode</a> that aligns items to the center, placing them either left or right of the spine. <code>gutterWidth</code> option available.</p> |
|
9 |
|
10 {% highlight javascript %} |
|
11 |
|
12 $container.isotope({ |
|
13 layoutMode: 'spineAlign', |
|
14 spineAlign: { |
|
15 gutterWidth: 20 |
|
16 }, |
|
17 // options... |
|
18 }); |
|
19 |
|
20 {% endhighlight %} |
|
21 |
|
22 <p>To use this layout mode, grab the <code>$.Isotope.prototype</code> methods from the script at the bottom of this page's source.</p> |
|
23 |
|
24 </section> |
|
25 |
|
26 <section id="options" class="clearfix"> |
|
27 |
|
28 {% include filter-buttons.html %} |
|
29 |
|
30 {% include sort-buttons.html %} |
|
31 |
|
32 <h3>Etc</h3> |
|
33 |
|
34 <ul id="etc" class="clearfix"> |
|
35 <li id="toggle-sizes"><a href="#toggle-sizes">Toggle variable sizes</a></li> |
|
36 <li id="insert"><a href="#insert">Insert new elements</a></li> |
|
37 <li id="append"><a href='#append'>Append new elements</a></li> |
|
38 <li id="shuffle"><a href='#shuffle'>Shuffle</a></li> |
|
39 </ul> |
|
40 |
|
41 </section> <!-- #options --> |
|
42 |
|
43 <div id="container" class="clickable variable-sizes clearfix"> |
|
44 {% for elem_number in site.best_of_order %} |
|
45 {% assign element = site.elements[elem_number] %} |
|
46 {% include element-partial.html %} |
|
47 {% endfor %} |
|
48 </div> <!-- #container --> |
|
49 |
|
50 |
|
51 <script src="../{{ site.jquery_js }}"></script> |
|
52 <script src="../{{ site.isotope_js }}"></script> |
|
53 <script src="../js/fake-element.js"></script> |
|
54 <script> |
|
55 |
|
56 // custom layout mode spineAlign |
|
57 $.Isotope.prototype._spineAlignReset = function() { |
|
58 this.spineAlign = { |
|
59 colA: 0, |
|
60 colB: 0 |
|
61 }; |
|
62 }; |
|
63 |
|
64 $.Isotope.prototype._spineAlignLayout = function( $elems ) { |
|
65 var instance = this, |
|
66 props = this.spineAlign, |
|
67 gutterWidth = Math.round( this.options.spineAlign && this.options.spineAlign.gutterWidth ) || 0, |
|
68 centerX = Math.round(this.element.width() / 2); |
|
69 |
|
70 $elems.each(function(){ |
|
71 var $this = $(this), |
|
72 isColA = props.colB > props.colA, |
|
73 x = isColA ? |
|
74 centerX - ( $this.outerWidth(true) + gutterWidth / 2 ) : // left side |
|
75 centerX + gutterWidth / 2, // right side |
|
76 y = isColA ? props.colA : props.colB; |
|
77 instance._pushPosition( $this, x, y ); |
|
78 props[( isColA ? 'colA' : 'colB' )] += $this.outerHeight(true); |
|
79 }); |
|
80 }; |
|
81 |
|
82 $.Isotope.prototype._spineAlignGetContainerSize = function() { |
|
83 var size = {}; |
|
84 size.height = this.spineAlign[( this.spineAlign.colB > this.spineAlign.colA ? 'colB' : 'colA' )]; |
|
85 return size; |
|
86 }; |
|
87 |
|
88 $.Isotope.prototype._spineAlignResizeChanged = function() { |
|
89 return true; |
|
90 }; |
|
91 |
|
92 |
|
93 $(function(){ |
|
94 |
|
95 var $container = $('#container'); |
|
96 |
|
97 {% include random-sizes.js %} |
|
98 |
|
99 $container.isotope({ |
|
100 itemSelector : '.element', |
|
101 layoutMode: 'spineAlign', |
|
102 spineAlign: { |
|
103 gutterWidth: 20 |
|
104 }, |
|
105 getSortData : { |
|
106 symbol : function( $elem ) { |
|
107 return $elem.attr('data-symbol'); |
|
108 }, |
|
109 category : function( $elem ) { |
|
110 return $elem.attr('data-category'); |
|
111 }, |
|
112 number : function( $elem ) { |
|
113 return parseInt( $elem.find('.number').text(), 10 ); |
|
114 }, |
|
115 weight : function( $elem ) { |
|
116 return parseFloat( $elem.find('.weight').text().replace( /[\(\)]/g, '') ); |
|
117 }, |
|
118 name : function ( $elem ) { |
|
119 return $elem.find('.name').text(); |
|
120 } |
|
121 } |
|
122 }); |
|
123 |
|
124 {% include option-set-buttons.js %} |
|
125 |
|
126 {% include add-buttons.js %} |
|
127 |
|
128 {% include change-sizes.js %} |
|
129 |
|
130 var $sortBy = $('#sort-by'); |
|
131 $('#shuffle a').click(function(){ |
|
132 $container.isotope('shuffle'); |
|
133 $sortBy.find('.selected').removeClass('selected'); |
|
134 $sortBy.find('[data-option-value="random"]').addClass('selected'); |
|
135 return false; |
|
136 }); |
|
137 |
|
138 }); |
|
139 </script> |