Adding optional Even sizing flag #25

Closed
wants to merge 2 commits into
from
View
14 index.html
@@ -125,13 +125,13 @@
<table>
<tr>
- <td><a href="jquery.sausage.js">Development Version (1.0.0)</a></td>
+ <td><a href="jquery.sausage.js">Development Version (1.0.1)</a></td>
<td><i>11 kb, Uncompressed with Comments</i></td>
</tr>
- <!--<tr>
- <td><a href="jquery.sausage-min.js">Production Version (0.1.0)</a></td>
+ <tr>
+ <td><a href="jquery.sausage.min.js">Production Version (1.0.1)</a></td>
<td><i>3kb, Minified and Gzipped</i></td>
- </tr>-->
+ </tr>
</table>
<p>Sausage depends on both <a href="http://jquery.com">jQuery</a> and the <a href="http://jqueryui.com">jQuery UI</a> widget factory.</p>
@@ -152,11 +152,11 @@
<p>For more advanced usage, refer to the <a href="https://github.com/christophercliff/sausage/tree/master/examples">examples</a> or view the <a href="docs/jquery.sausage.html">annotated source</a>.</p>
</li>
- <!--<li class="section" data-name="Change Log">
+ <li class="section" data-name="Change Log">
<h2>Change Log</h2>
-
- </li>-->
+ <p><strong>1.0.1</strong> - Added optional 'even' flag. When passed as true, all sausages will be equally sized and spaced, regardless of height in the page.</p>
+ </li>
</ol>
<h2 class="footer">Created by <a href="http://christophercliff.com">Christopher Cliff</a></h2>
View
32 jquery.sausage.js
@@ -1,4 +1,4 @@
-// jquery.sausage.js 1.0.0
+// jquery.sausage.js 1.0.1
// (c) 2011 Christopher Cliff
// Freely distributed under the MIT license.
// For all details and documentation:
@@ -44,8 +44,13 @@
//
content: function (i, $page) {
return '<span class="sausage-span">' + (i + 1) + '</span>';
- }
-
+ },
+
+ // ### even 'boolen'
+ //
+ // When passed as true, all sausages will be equally sized and spaced, regardless of height in the page.
+ even: false
+
},
// # Private Methods
@@ -335,7 +340,9 @@
$page,
s = [],
offset_p,
- offset_s;
+ offset_s,
+ even_height,
+ even_top;
self.offsets = [];
self.count = $items.length;
@@ -350,11 +357,18 @@
for (var i = 0; i < self.count; i++)
{
$page = $items.eq(i);
- offset_p = $page.offset();
- offset_s = offset_p.top/h_doc*h_win;
-
- s.push('<div class="sausage' + ((i === self.current) ? ' sausage-current' : '') + '" style="height:' + ($page.outerHeight()/h_doc*h_win) + 'px;top:' + offset_s + 'px;">' + self.options.content(i, $page) + '</div>');
-
+ if (!self.options.even) {
+ offset_p = $page.offset();
+ offset_s = offset_p.top/h_doc*h_win;
+
+ s.push('<div class="sausage' + ((i === self.current) ? ' sausage-current' : '') + '" style="height:' + ($page.outerHeight()/h_doc*h_win) + 'px;top:' + offset_s + 'px;">' + self.options.content(i, $page) + '</div>');
+ } else {
+ even_height = h_win/self.count;
+ even_top = even_height*i;
+ offset_p = $page.offset();
+ s.push('<div class="sausage' + ((i === self.current) ? ' sausage-current' : '') + '" style="height:' + even_height + 'px;top:' + even_top + 'px;">' + self.options.content(i, $page) + '</div>');
+ }
+
// Create `self.offsets` for calculating current sausage.
self.offsets.push(offset_p.top);
}