spine-align.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Spine align &middot; Isotope </title>
  6. <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
  7. <link rel="stylesheet" href="../css/style.css" />
  8. <!-- scripts at bottom of page -->
  9. </head>
  10. <body class="custom-layout-modes ">
  11. <nav id="site-nav">
  12. <h1><a href="../index.html">Isotope</a></h1>
  13. <h2>Docs</h2>
  14. <ul>
  15. <li><a href="../docs/introduction.html">Introduction</a>
  16. <li><a href="../docs/options.html">Options</a>
  17. <li><a href="../docs/methods.html">Methods</a>
  18. <li><a href="../docs/layout-modes.html">Layout modes</a>
  19. <li><a href="../docs/filtering.html">Filtering</a>
  20. <li><a href="../docs/sorting.html">Sorting</a>
  21. <li><a href="../docs/animating.html">Animating</a>
  22. <li><a href="../docs/adding-items.html">Adding items</a>
  23. <li><a href="../docs/extending-isotope.html">Extending Isotope</a>
  24. <li><a href="../docs/hash-history-jquery-bbq.html">Hash history with jQuery BBQ</a>
  25. <li><a href="../docs/help.html">Help</a>
  26. <li><a href="../docs/license.html">License</a>
  27. </ul>
  28. <h2>Demos</h2>
  29. <ul>
  30. <li><a href="../demos/basic.html">Basic</a>
  31. <li><a href="../demos/elements-complete.html">Elements Complete</a>
  32. <li><a href="../demos/elements-partial.html">Elements Partial</a>
  33. <li><a href="../demos/layout-modes.html">Layout modes</a>
  34. <li><a href="../demos/filtering.html">Filtering</a>
  35. <li><a href="../demos/sorting.html">Sorting</a>
  36. <li><a href="../demos/relayout.html">reLayout</a>
  37. <li><a href="../demos/adding-items.html">Adding items</a>
  38. <li><a href="../demos/infinite-scroll.html">Infinite Scroll</a>
  39. <li><a href="../demos/images.html">Images</a>
  40. <li><a href="../demos/combination-filters.html">Combination filters</a>
  41. <li><a href="../demos/hash-history.html">Hash history</a>
  42. <li><a href="../demos/fluid-responsive.html">Fluid / responsive</a>
  43. </ul>
  44. <h2>Custom layout modes</h2>
  45. <ul>
  46. <li><a href="../custom-layout-modes/centered-masonry.html">Centered Masonry</a>
  47. <li><a href="../custom-layout-modes/category-rows.html">Category rows</a>
  48. <li><a href="../custom-layout-modes/masonry-corner-stamp.html">Masonry corner stamp</a>
  49. <li><a href="../custom-layout-modes/masonry-gutters.html">Masonry gutters</a>
  50. <li class="current"><a href="#content">Spine align</a></li>
  51. </ul>
  52. <h2><a href="../tests/index.html">Tests</a></h2>
  53. </nav> <!-- #site-nav -->
  54. <section id="content">
  55. <h1>Spine align</h1>
  56. <section id="copy">
  57. <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>
  58. <div class="highlight"><pre><code class="javascript"><span class="nx">$container</span><span class="p">.</span><span class="nx">isotope</span><span class="p">({</span>
  59. <span class="nx">layoutMode</span><span class="o">:</span> <span class="s1">&#39;spineAlign&#39;</span><span class="p">,</span>
  60. <span class="nx">spineAlign</span><span class="o">:</span> <span class="p">{</span>
  61. <span class="nx">gutterWidth</span><span class="o">:</span> <span class="mi">20</span>
  62. <span class="p">},</span>
  63. <span class="c1">// options...</span>
  64. <span class="p">});</span>
  65. </code></pre>
  66. </div>
  67. <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>
  68. </section>
  69. <section id="options" class="clearfix">
  70. <h3>Filters</h3>
  71. <ul id="filters" class="option-set clearfix" data-option-key="filter">
  72. <li><a href="#filter" data-option-value="*" class="selected">show all</a></li>
  73. <li><a href="#filter" data-option-value=".metal">metal</a></li>
  74. <li><a href="#filter" data-option-value=".transition">transition</a></li>
  75. <li><a href="#filter" data-option-value=".post-transition">post-transition</a></li>
  76. <li><a href="#filter" data-option-value=".nonmetal">nonmetal</a></li>
  77. <li><a href="#filter" data-option-value=".inner-transition">inner-transition</a></li>
  78. <li><a href="#filter" data-option-value=".alkali, .alkaline-earth">alkali and alkaline-earth</a></li>
  79. <li><a href="#filter" data-option-value=":not(.transition)">not transition</a></li>
  80. <li><a href="#filter" data-option-value=".metal:not(.transition)">metal but not transition</a></li>
  81. </ul>
  82. <h3>Sort</h3>
  83. <ul id="sort-by" class="option-set clearfix" data-option-key="sortBy">
  84. <li><a href="#sortBy=original-order" data-option-value="original-order" class="selected" data>original-order</a></li>
  85. <li><a href="#sortBy=name" data-option-value="name">name</a></li>
  86. <li><a href="#sortBy=symbol" data-option-value="symbol">symbol</a></li>
  87. <li><a href="#sortBy=number" data-option-value="number">number</a></li>
  88. <li><a href="#sortBy=weight" data-option-value="weight">weight</a></li>
  89. <li><a href="#sortBy=category" data-option-value="category">category</a></li>
  90. <li><a href="#sortBy=random" data-option-value="random">random</a></li>
  91. </ul>
  92. <h3>Sort direction</h3>
  93. <ul id="sort-direction" class="option-set clearfix" data-option-key="sortAscending">
  94. <li><a href="#sortAscending=true" data-option-value="true" class="selected">sort ascending</a></li>
  95. <li><a href="#sortAscending=false" data-option-value="false">sort descending</a></li>
  96. </ul>
  97. <h3>Etc</h3>
  98. <ul id="etc" class="clearfix">
  99. <li id="toggle-sizes"><a href="#toggle-sizes">Toggle variable sizes</a></li>
  100. <li id="insert"><a href="#insert">Insert new elements</a></li>
  101. <li id="append"><a href='#append'>Append new elements</a></li>
  102. <li id="shuffle"><a href='#shuffle'>Shuffle</a></li>
  103. </ul>
  104. </section> <!-- #options -->
  105. <div id="container" class="clickable variable-sizes clearfix">
  106. <div class="element transition metal " data-symbol="Hg" data-category="transition">
  107. <p class="number">80</p>
  108. <h3 class="symbol">Hg</h3>
  109. <h2 class="name">Mercury</h2>
  110. <p class="weight">200.59</p>
  111. </div>
  112. <div class="element metalloid " data-symbol="Te" data-category="metalloid">
  113. <p class="number">52</p>
  114. <h3 class="symbol">Te</h3>
  115. <h2 class="name">Tellurium</h2>
  116. <p class="weight">127.6</p>
  117. </div>
  118. <div class="element post-transition metal " data-symbol="Bi" data-category="post-transition">
  119. <p class="number">83</p>
  120. <h3 class="symbol">Bi</h3>
  121. <h2 class="name">Bismuth</h2>
  122. <p class="weight">208.9804</p>
  123. </div>
  124. <div class="element transition metal " data-symbol="Cd" data-category="transition">
  125. <p class="number">48</p>
  126. <h3 class="symbol">Cd</h3>
  127. <h2 class="name">Cadmium</h2>
  128. <p class="weight">112.411</p>
  129. </div>
  130. <div class="element alkaline-earth metal " data-symbol="Ca" data-category="alkaline-earth">
  131. <p class="number">20</p>
  132. <h3 class="symbol">Ca</h3>
  133. <h2 class="name">Calcium</h2>
  134. <p class="weight">40.078</p>
  135. </div>
  136. <div class="element transition metal " data-symbol="Re" data-category="transition">
  137. <p class="number">75</p>
  138. <h3 class="symbol">Re</h3>
  139. <h2 class="name">Rhenium</h2>
  140. <p class="weight">186.207</p>
  141. </div>
  142. <div class="element post-transition metal " data-symbol="Tl" data-category="post-transition">
  143. <p class="number">81</p>
  144. <h3 class="symbol">Tl</h3>
  145. <h2 class="name">Thallium</h2>
  146. <p class="weight">204.3833</p>
  147. </div>
  148. <div class="element metalloid " data-symbol="Sb" data-category="metalloid">
  149. <p class="number">51</p>
  150. <h3 class="symbol">Sb</h3>
  151. <h2 class="name">Antimony</h2>
  152. <p class="weight">121.76</p>
  153. </div>
  154. <div class="element transition metal " data-symbol="Co" data-category="transition">
  155. <p class="number">27</p>
  156. <h3 class="symbol">Co</h3>
  157. <h2 class="name">Cobalt</h2>
  158. <p class="weight">58.933195</p>
  159. </div>
  160. <div class="element lanthanoid metal inner-transition " data-symbol="Lu" data-category="lanthanoid">
  161. <p class="number">71</p>
  162. <h3 class="symbol">Lu</h3>
  163. <h2 class="name">Lutetium</h2>
  164. <p class="weight">174.9668</p>
  165. </div>
  166. <div class="element noble-gas nonmetal " data-symbol="Ar" data-category="noble-gas">
  167. <p class="number">18</p>
  168. <h3 class="symbol">Ar</h3>
  169. <h2 class="name">Argon</h2>
  170. <p class="weight">39.948</p>
  171. </div>
  172. <div class="element alkali metal " data-symbol="Rb" data-category="alkali">
  173. <p class="number">37</p>
  174. <h3 class="symbol">Rb</h3>
  175. <h2 class="name">Rubidium</h2>
  176. <p class="weight">85.4678</p>
  177. </div>
  178. <div class="element other nonmetal " data-symbol="N" data-category="other">
  179. <p class="number">7</p>
  180. <h3 class="symbol">N</h3>
  181. <h2 class="name">Nitrogen</h2>
  182. <p class="weight">14.0067</p>
  183. </div>
  184. <div class="element actinoid metal inner-transition " data-symbol="Np" data-category="actinoid">
  185. <p class="number">93</p>
  186. <h3 class="symbol">Np</h3>
  187. <h2 class="name">Neptunium</h2>
  188. <p class="weight">(237)</p>
  189. </div>
  190. <div class="element actinoid metal inner-transition " data-symbol="Ac" data-category="actinoid">
  191. <p class="number">89</p>
  192. <h3 class="symbol">Ac</h3>
  193. <h2 class="name">Actinium</h2>
  194. <p class="weight">(227)</p>
  195. </div>
  196. </div> <!-- #container -->
  197. <script src="../js/jquery-1.6.4.min.js"></script>
  198. <script src="../jquery.isotope.min.js"></script>
  199. <script src="../js/fake-element.js"></script>
  200. <script>
  201. // custom layout mode spineAlign
  202. $.Isotope.prototype._spineAlignReset = function() {
  203. this.spineAlign = {
  204. colA: 0,
  205. colB: 0
  206. };
  207. };
  208. $.Isotope.prototype._spineAlignLayout = function( $elems ) {
  209. var instance = this,
  210. props = this.spineAlign,
  211. gutterWidth = Math.round( this.options.spineAlign && this.options.spineAlign.gutterWidth ) || 0,
  212. centerX = Math.round(this.element.width() / 2);
  213. $elems.each(function(){
  214. var $this = $(this),
  215. isColA = props.colB > props.colA,
  216. x = isColA ?
  217. centerX - ( $this.outerWidth(true) + gutterWidth / 2 ) : // left side
  218. centerX + gutterWidth / 2, // right side
  219. y = isColA ? props.colA : props.colB;
  220. instance._pushPosition( $this, x, y );
  221. props[( isColA ? 'colA' : 'colB' )] += $this.outerHeight(true);
  222. });
  223. };
  224. $.Isotope.prototype._spineAlignGetContainerSize = function() {
  225. var size = {};
  226. size.height = this.spineAlign[( this.spineAlign.colB > this.spineAlign.colA ? 'colB' : 'colA' )];
  227. return size;
  228. };
  229. $.Isotope.prototype._spineAlignResizeChanged = function() {
  230. return true;
  231. };
  232. $(function(){
  233. var $container = $('#container');
  234. // add randomish size classes
  235. $container.find('.element').each(function(){
  236. var $this = $(this),
  237. number = parseInt( $this.find('.number').text(), 10 );
  238. if ( number % 7 % 2 === 1 ) {
  239. $this.addClass('width2');
  240. }
  241. if ( number % 3 === 0 ) {
  242. $this.addClass('height2');
  243. }
  244. });
  245. $container.isotope({
  246. itemSelector : '.element',
  247. layoutMode: 'spineAlign',
  248. spineAlign: {
  249. gutterWidth: 20
  250. },
  251. getSortData : {
  252. symbol : function( $elem ) {
  253. return $elem.attr('data-symbol');
  254. },
  255. category : function( $elem ) {
  256. return $elem.attr('data-category');
  257. },
  258. number : function( $elem ) {
  259. return parseInt( $elem.find('.number').text(), 10 );
  260. },
  261. weight : function( $elem ) {
  262. return parseFloat( $elem.find('.weight').text().replace( /[\(\)]/g, '') );
  263. },
  264. name : function ( $elem ) {
  265. return $elem.find('.name').text();
  266. }
  267. }
  268. });
  269. var $optionSets = $('#options .option-set'),
  270. $optionLinks = $optionSets.find('a');
  271. $optionLinks.click(function(){
  272. var $this = $(this);
  273. // don't proceed if already selected
  274. if ( $this.hasClass('selected') ) {
  275. return false;
  276. }
  277. var $optionSet = $this.parents('.option-set');
  278. $optionSet.find('.selected').removeClass('selected');
  279. $this.addClass('selected');
  280. // make option object dynamically, i.e. { filter: '.my-filter-class' }
  281. var options = {},
  282. key = $optionSet.attr('data-option-key'),
  283. value = $this.attr('data-option-value');
  284. // parse 'false' as false boolean
  285. value = value === 'false' ? false : value;
  286. options[ key ] = value;
  287. if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
  288. // changes in layout modes need extra logic
  289. changeLayoutMode( $this, options )
  290. } else {
  291. // otherwise, apply new options
  292. $container.isotope( options );
  293. }
  294. return false;
  295. });
  296. $('#insert a').click(function(){
  297. var $newEls = $( fakeElement.getGroup() );
  298. $container.isotope( 'insert', $newEls );
  299. return false;
  300. });
  301. $('#append a').click(function(){
  302. var $newEls = $( fakeElement.getGroup() );
  303. $container.append( $newEls ).isotope( 'appended', $newEls );
  304. return false;
  305. });
  306. // change size of clicked element
  307. $container.delegate( '.element', 'click', function(){
  308. $(this).toggleClass('large');
  309. $container.isotope('reLayout');
  310. });
  311. // toggle variable sizes of all elements
  312. $('#toggle-sizes').find('a').click(function(){
  313. $container
  314. .toggleClass('variable-sizes')
  315. .isotope('reLayout');
  316. return false;
  317. });
  318. var $sortBy = $('#sort-by');
  319. $('#shuffle a').click(function(){
  320. $container.isotope('shuffle');
  321. $sortBy.find('.selected').removeClass('selected');
  322. $sortBy.find('[data-option-value="random"]').addClass('selected');
  323. return false;
  324. });
  325. });
  326. </script>
  327. <footer>
  328. Isotope by <a href="http://desandro.com">David DeSandro</a> / <a href="http://metafizzy.co">Metafizzy</a>
  329. </footer>
  330. </section> <!-- #content -->
  331. </body>
  332. </html>