Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed error with class in hashes

  • Loading branch information...
commit 2823396b2106b95cee8f6d2ff8daa04cd646ec66 1 parent 6300e67
@Omgovich authored
Showing with 44 additions and 21 deletions.
  1. +6 −6 index.html
  2. +38 −15 sources/jquery.splitter.js
View
12 index.html
@@ -12,15 +12,18 @@
<script src="sources/jquery.splitter.js"></script>
<script>
$(function(){
- $('ul').splitter({
- columns: 4
+
+ $('#list').splitter({
+ columns: 10,
+ direction: 'horizontal'
});
+
});
</script>
</head>
<body>
- <ul>
+ <ul id="list">
<li>Element 1</li>
<li>Element 2</li>
<li>Element 3</li>
@@ -32,9 +35,6 @@
<li>Element 9</li>
<li>Element 10</li>
<li>Element 11</li>
- <li>Element 12</li>
- <li>Element 13</li>
- <li>Element 14</li>
</ul>
</body>
View
53 sources/jquery.splitter.js
@@ -12,6 +12,7 @@
// Settings
var settings = $.extend({
columns: 2,
+ direction: 'vertical',
itemsSelector: 'li',
// container
containerTag: 'div',
@@ -25,29 +26,51 @@
// Install splitter for each items
this.each(function(){
-
+
+ // Variables and objects
var $list = $(this),
$items = $list.find(settings.itemsSelector),
- itemsInColumn = Math.ceil($items.length/settings.columns),
+ itemsNumber = $items.length,
+ $column = $('<'+settings.columnTag+'/>', {
+ 'class': settings.columnClass
+ }),
$container = $('<'+settings.containerTag+'/>', {
- class: settings.containerClass
+ 'class': settings.containerClass
+ });
+
+ // Create columns
+ for(var i=0; i<settings.columns; i++) $container.append( $column.clone() );
+ var $columns = $container.children();
+ $columns.first().addClass(settings.columnFirstClass);
+ $columns.last().addClass(settings.columnLastClass);
+
+ // Vertical split
+ function splitVertical(){
+ var itemsInColumn = Math.ceil(itemsNumber/settings.columns),
+ column = 0;
+ for(var i=0; i<itemsNumber; i+=itemsInColumn) {
+ var $columnItems = $items.slice(i, i+itemsInColumn).clone();
+ $columns.eq(column++).append($columnItems);
+ };
+ };
+
+ // Horizontal split
+ function splitHorizontal(){
+ $items.each(function(index){
+ $columns.eq(index%settings.columns).append($(this).clone());
});
+ };
- for(var i=0; i<$items.length; i+=itemsInColumn) {
- var $columnItems = $items.slice(i, i+itemsInColumn).clone(),
- $column = $('<'+settings.columnTag+'/>', {
- class: settings.columnClass
- });
- $column.append($columnItems);
- $container.append($column);
+ // Add items in columns
+ if (settings.direction=='horizontal') {
+ splitHorizontal();
+ } else {
+ splitVertical();
};
-
- $container.find('> :first').addClass(settings.columnFirstClass);
- $container.find('> :last').addClass(settings.columnLastClass);
-
+
+ // Render splitted list
$list.after($container);
-
});
return this;
Please sign in to comment.
Something went wrong with that request. Please try again.