-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
240 lines (237 loc) · 8.89 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta content='IE=Edge,chrome=1' http-equiv='X-UA-Compatible'>
<meta content='width=device-width, initial-scale=1.0, user-scalable=no' name='viewport'>
<title>heaps.js by sillylogger</title>
<!--[if lt IE 9]>
<script src='//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js'></script>
<![endif]-->
<script src='javascripts/scale.fix.js'></script>
<script src='javascripts/jquery.js'></script>
<script src='javascripts/jquery.heaps.js'></script>
<link href='stylesheets/styles.css' rel='stylesheet'>
<link href='stylesheets/pygment_trac.css' rel='stylesheet'>
<link href='stylesheets/heaps.css' rel='stylesheet'>
</head>
<body class='wrapper'>
<header>
<h1>heaps.js</h1>
<p class='view'>
<a href='https://github.com/sillylogger/heaps'>
View the Project on GitHub
<small>sillylogger/heaps</small>
</a>
</p>
<ul>
<li>
<a href='https://github.com/sillylogger/heaps/zipball/master'>
Download
<strong>ZIP File</strong>
</a>
</li>
<li>
<a href='https://github.com/sillylogger/heaps/tarball/master'>
Download
<strong>TAR Ball</strong>
</a>
</li>
<li>
<a href='https://github.com/sillylogger/heaps'>
View on
<strong>GitHub</strong>
</a>
</li>
</ul>
</header>
<section>
<p>This is a jQuery plugin to layout a bunch of elements into a heap or any pattern can describe with a function.</p>
<pre>$('ul#ball-of-images').heapify('li')</pre>
<p>Uses the defaults and looks like this:</p>
<ul class='thumbnails' id='ball-of-images'>
<li>
<a class='thumbnail size12' href='images/belgium-brussels.jpg'>
<img src='images/belgium-brussels.jpg'>
</a>
</li>
<li>
<a class='thumbnail size11' href='images/cambodia-penom-phen-s-21.jpg'>
<img src='images/cambodia-penom-phen-s-21.jpg'>
</a>
</li>
<li>
<a class='thumbnail size10' href='images/cambodia-siem-reap-angkor-wat.jpg'>
<img src='images/cambodia-siem-reap-angkor-wat.jpg'>
</a>
</li>
<li>
<a class='thumbnail size9' href='images/cambodia-siem-reap-field.jpg'>
<img src='images/cambodia-siem-reap-field.jpg'>
</a>
</li>
<li>
<a class='thumbnail size8' href='images/cambodia-siem-reap-market.jpg'>
<img src='images/cambodia-siem-reap-market.jpg'>
</a>
</li>
<li>
<a class='thumbnail size7' href='images/ireland-cork.jpg'>
<img src='images/ireland-cork.jpg'>
</a>
</li>
<li>
<a class='thumbnail size6' href='images/ireland-howth.jpg'>
<img src='images/ireland-howth.jpg'>
</a>
</li>
<li>
<a class='thumbnail size5' href='images/malaysia-kuala-lumpur-islamic-museum.jpg'>
<img src='images/malaysia-kuala-lumpur-islamic-museum.jpg'>
</a>
</li>
<li>
<a class='thumbnail size4' href='images/malaysia-putrajaya.jpg'>
<img src='images/malaysia-putrajaya.jpg'>
</a>
</li>
<li>
<a class='thumbnail size3' href='images/netherlands-amsterdam.jpg'>
<img src='images/netherlands-amsterdam.jpg'>
</a>
</li>
<li>
<a class='thumbnail size2' href='images/singapore-marina-barrage.jpg'>
<img src='images/singapore-marina-barrage.jpg'>
</a>
</li>
<li>
<a class='thumbnail size1' href='images/usa-san-antonio.jpg'>
<img src='images/usa-san-antonio.jpg'>
</a>
</li>
</ul>
<p>You can specify a different scoring function to layout the images. The default is distance from center, but what if you pass a <code>scoring</code> option of:</p>
<pre class='concat-bottom'>$('ul#demo').heapify('li', { scoring:</pre>
<textarea class='concat code' id='function'>function(coordinate) {
 return -1 * Math.abs(coordinate[1] - this.center[1]);
}</textarea>
<pre class='concat-top'>});</pre>
<button class='btn btn-inverse' id='function-runner'>Evaluate</button>
<script>
//<![CDATA[
$('#function-runner').click(function(){
eval("var userGeneratedFunction = " + $('textarea#function').val());
var demo = $('ul#demo');
demo.data('heap', null);
demo.heapify('li', {
scoring: userGeneratedFunction
});
});
//]]>
</script>
<p>then you'll get something like this:</p>
<ul class='thumbnails' id='demo'>
<li>
<a class='thumbnail size12' href='images/belgium-brussels.jpg'>
<img src='images/belgium-brussels.jpg'>
</a>
</li>
<li>
<a class='thumbnail size11' href='images/cambodia-penom-phen-s-21.jpg'>
<img src='images/cambodia-penom-phen-s-21.jpg'>
</a>
</li>
<li>
<a class='thumbnail size10' href='images/cambodia-siem-reap-angkor-wat.jpg'>
<img src='images/cambodia-siem-reap-angkor-wat.jpg'>
</a>
</li>
<li>
<a class='thumbnail size9' href='images/cambodia-siem-reap-field.jpg'>
<img src='images/cambodia-siem-reap-field.jpg'>
</a>
</li>
<li>
<a class='thumbnail size8' href='images/cambodia-siem-reap-market.jpg'>
<img src='images/cambodia-siem-reap-market.jpg'>
</a>
</li>
<li>
<a class='thumbnail size7' href='images/ireland-cork.jpg'>
<img src='images/ireland-cork.jpg'>
</a>
</li>
<li>
<a class='thumbnail size6' href='images/ireland-howth.jpg'>
<img src='images/ireland-howth.jpg'>
</a>
</li>
<li>
<a class='thumbnail size5' href='images/malaysia-kuala-lumpur-islamic-museum.jpg'>
<img src='images/malaysia-kuala-lumpur-islamic-museum.jpg'>
</a>
</li>
<li>
<a class='thumbnail size4' href='images/malaysia-putrajaya.jpg'>
<img src='images/malaysia-putrajaya.jpg'>
</a>
</li>
<li>
<a class='thumbnail size3' href='images/netherlands-amsterdam.jpg'>
<img src='images/netherlands-amsterdam.jpg'>
</a>
</li>
<li>
<a class='thumbnail size2' href='images/singapore-marina-barrage.jpg'>
<img src='images/singapore-marina-barrage.jpg'>
</a>
</li>
<li>
<a class='thumbnail size1' href='images/usa-san-antonio.jpg'>
<img src='images/usa-san-antonio.jpg'>
</a>
</li>
</ul>
<hr>
<h2>$(parent).heapify(selector, options)</h2>
<h3>parent</h3>
<p>Some DOM element with a width & height.</p>
<h3>selector</h3>
<p>A CSS selector of items to be absolutely positioned within the parent.</p>
<h3>options</h3>
<dl>
<dt class='code'>options.step = 10</dt>
<dd>The granularity of item positioning. <code>1px</code> granularity is computationally intensive, thus the default step is <code>10px</code> until the algorithm is improved significantly.</dd>
<dt class='code'>options.scoring = function(coordinate) { }</dt>
<dd>This function is used to score each coordinate within the <code>parent</code>. This each coordinate is a pair of <code>[x,y]</code>. The function is called within the scope of the heap and thus has access to <code>this.center</code> (a coordinate), <code>this.width</code>, and <code>this.height</code>.</dd>
<dt class='code'>options.sort = false</dt>
<dd>This flag will cause <code>heapify</code> to sort the selected elements by area – placing the larger element in the highest priority spots.</dd>
</dl>
</section>
<footer>
<p>
This project is maintained by
<a href='https://github.com/sillylogger'>sillylogger</a>
</p>
<p>
<small>
Hosted on GitHub Pages — Theme by
<a href='https://github.com/orderedlist'>orderedlist</a>
</small>
</p>
</footer>
<script>
//<![CDATA[
$(window).load(function(){
var step = 10;
// normalize all images so fit on a 10x10 grid
$('.thumbnail').each(function(i, el) {
var $el = $(el);
var height = $el.height();
$el.css({ height: height - (height % step) + 'px' });
});
$('#ball-of-images').heapify('li', { step: step });
});
//]]>
</script>
</body>
</html>