Skip to content

Commit 3c55140

Browse files
committed
src & docs : add itemPositionDataEnabled
I think it's ready for v1.1
1 parent e100677 commit 3c55140

File tree

4 files changed

+158
-27
lines changed

4 files changed

+158
-27
lines changed

_posts/docs/2010-12-03-options.mdown

+27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ toc:
1414
- { title: hiddenClass, anchor: hiddenclass }
1515
- { title: hiddenStyle, anchor: hiddenstyle }
1616
- { title: itemClass, anchor: itemclass }
17+
- { title: itemPositionDataEnabled, anchor: itempositiondataenabled }
1718
- { title: itemSelector, anchor: itemselector }
1819
- { title: layoutMode, anchor: layoutmode }
1920
- { title: resizable, anchor: resizable }
@@ -159,6 +160,32 @@ The style applied to item elements hidden by Filtering.
159160

160161
The class applied to item elements.
161162

163+
## itemPositionDataEnabled
164+
165+
<dl class="clearfix">
166+
<dt><code>itemPositionDataEnabled</code></dt>
167+
<dd class="option-type">Boolean</dd>
168+
<dd class="default"><code><span class="kc">false</span></code></dd>
169+
</dl>
170+
171+
When enabled, the position of item elements will exposed as data, which you can retrieve with jQuery's data method with <code><span class="s1">'isotope-item-position'</span></code> name space. Position is return as an object with `x` and `y`;
172+
173+
### Example
174+
175+
{% highlight javascript %}
176+
177+
$('#container').isotope({
178+
itemSelector: '.element',
179+
itemPositionDataEnabled: true
180+
})
181+
// log position of each item
182+
.find('.element').each(function(){
183+
var position = $(this).data('isotope-item-position');
184+
console.log('item position is x: ' + position.x + ', y: ' + position.y );
185+
});
186+
187+
{% endhighlight %}
188+
162189
## itemSelector
163190

164191
<dl class="clearfix">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: item position data01
3+
layout: demo
4+
category: tests
5+
---
6+
7+
<section id="copy">
8+
<p></p>
9+
</section>
10+
11+
<section id="options" class="clearfix">
12+
13+
<h3>Filters</h3>
14+
15+
<ul id="filters" class="option-set floated clearfix">
16+
<li><a href="#show-all" class="selected">show all</a></li>
17+
<li><a href="#metalloid">metalloid</a></li>
18+
<li><a href="#metal">metal</a></li>
19+
<li><a href="#alkali">alkali</a></li>
20+
<li><a href="#alkaline-earth">alkaline-earth</a></li>
21+
<li><a href="#inner-transition">inner-transition</a></li>
22+
<li><a href="#lanthanoid">lanthanoid</a></li>
23+
<li><a href="#actinoid">actinoid</a></li>
24+
<li><a href="#transition">transition</a></li>
25+
<li><a href="#post-transition">post-transition</a></li>
26+
<li><a href="#nonmetal">nonmetal</a></li>
27+
<li><a href="#other">other</a></li>
28+
<li><a href="#halogen">halogen</a></li>
29+
<li><a href="#noble-gas">noble-gas</a></li>
30+
</ul>
31+
32+
{% include sort-buttons.html %}
33+
34+
<h3>Etc</h3>
35+
36+
<ul id="etc" class="floated clearfix">
37+
38+
<li id="toggle-sizes"><a href="#toggle-sizes">Toggle variable sizes</a></li>
39+
</ul>
40+
</section> <!-- #options -->
41+
42+
<div id="container">
43+
{% for element in site.elements limit:40 %}
44+
{% include element-partial.html %}
45+
{% endfor %}
46+
</div> <!-- #container -->
47+
48+
<script src="../{{ site.jquery_js }}"></script>
49+
<script src="../{{ site.isotope_js }}"></script>
50+
<script>
51+
$(function(){
52+
53+
var $container = $('#container');
54+
55+
// hacky way of adding random size classes
56+
$container.find('.element').each(function(){
57+
if ( Math.random() > 0.6 ) {
58+
$(this).addClass('width2');
59+
}
60+
if ( Math.random() > 0.6 ) {
61+
$(this).addClass('height2');
62+
}
63+
});
64+
65+
{% include sort-buttons.js %}
66+
67+
// change size of clicked element
68+
$container.find('.element').live('click', function(){
69+
$(this).toggleClass('large');
70+
$container.isotope('reLayout');
71+
});
72+
73+
$container.isotope({
74+
itemSelector: '.element',
75+
itemPositionDataEnabled: true,
76+
masonry: {
77+
columnWidth : 120
78+
},
79+
getSortData : {
80+
symbol : function( $elem ) {
81+
return $elem.attr('data-symbol');
82+
},
83+
category : function( $elem ) {
84+
return $elem.attr('data-category');
85+
},
86+
number : function( $elem ) {
87+
return parseInt( $elem.find('.number').text(), 10 );
88+
},
89+
weight : function( $elem ) {
90+
return parseFloat( $elem.find('.weight').text().replace( /[\(\)]/g, '') );
91+
},
92+
name : function ( $elem ) {
93+
return $elem.find('.name').text();
94+
}
95+
}
96+
});
97+
98+
});
99+
</script>

jquery.isotope.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Isotope v1.0.110401
2+
* Isotope v1.1.110426
33
* An exquisite jQuery plugin for magical layouts
44
* http://isotope.metafizzy.co
55
*
@@ -357,7 +357,8 @@
357357
sortBy : 'original-order',
358358
sortAscending : true,
359359
resizesContainer : true,
360-
transformsEnabled : true
360+
transformsEnabled : true,
361+
itemPositionDataEnabled: false
361362
},
362363

363364
_filterFind: function( $elems, selector ) {
@@ -600,6 +601,9 @@
600601
_pushPosition : function( $elem, x, y ) {
601602
var position = this.getPositionStyles( x, y );
602603
this.styleQueue.push({ $el: $elem, style: position });
604+
if ( this.options.itemPositionDataEnabled ) {
605+
$elem.data('isotope-item-position', {x: x, y: y} );
606+
}
603607
},
604608

605609

0 commit comments

Comments
 (0)