Skip to content

Custom classes naming and short cleaning of the code #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions samples/columnizer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.columnized .column {
width: 24%;
float: left;
margin: 0 .5%;
}

.clear {
clear: both;
}
2 changes: 2 additions & 0 deletions samples/sample1.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Columnizer JQuery Plugin sample page</title>
<meta name="author" content="Adam Wulf, Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column p, .column h1{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample10.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Columnizer JQuery Plugin sample page</title>
<meta name="author" content="Adam Wulf, Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
body { font-size: 9pt; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample101.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<meta name="Generator" content="iceline webkit 0.6" />
<meta name="Author" content="Owen Beresford" />
<meta name="Description" content="This is list of things at I have changed in this site" />
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">

<script type="text/javascript" src="../src/jquery.js" ></script>
<script type="text/javascript" src="../src/jquery.columnizer.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions samples/sample102.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<meta name="Generator" content="iceline webkit 0.6" />
<meta name="Author" content="Owen Beresford" />
<meta name="Description" content="This is list of things at I have changed in this site" />
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css" />

<script type="text/javascript" src="../src/jquery.js" ></script>
<script type="text/javascript" src="../src/jquery.columnizer.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions samples/sample103.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<meta name="Generator" content="iceline webkit 0.6" />
<meta name="Author" content="Owen Beresford" />
<meta name="Description" content="This is list of things at I have changed in this site" />
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">

<script type="text/javascript" src="../src/jquery.js" ></script>
<script type="text/javascript" src="../src/jquery.columnizer.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions samples/sample11.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Columnizer JQuery Plugin sample page</title>
<meta name="author" content="Adam Wulf, Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
body { font-size: 9pt; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample12.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<title>Columnizer JQuery Plugin sample page 3</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column *{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample13.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<title>Columnizer JQuery Plugin sample page 3</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column *{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample14.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<title>Columnizer JQuery Plugin sample page 3</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column *{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample15.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<title>Columnizer JQuery Plugin sample page 3</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column *{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample2.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<title>Columnizer JQuery Plugin sample page 2</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column > *{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample3.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Columnizer JQuery Plugin sample page</title>
<meta name="author" content="Adam Wulf, Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column p, .column h1{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample4.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Columnizer JQuery Plugin sample page</title>
<meta name="author" content="Adam Wulf, Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column p, .column h1{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample5.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Columnizer JQuery Plugin sample page</title>
<meta name="author" content="Adam Wulf, Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column *{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample6.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<title>Columnizer JQuery Plugin sample page 3</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column *{ padding: 5px; }
Expand Down
2 changes: 2 additions & 0 deletions samples/sample7.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Columnizer JQuery Plugin sample page</title>
<meta name="author" content="Adam Wulf, Matt Wilson">
<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<!-- Date: 2008-07-12 -->
<style>
.column *{ padding: 5px; }
Expand Down
3 changes: 2 additions & 1 deletion samples/sample8.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
}
.enclosure {border:1px dashed black}
</style>

<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="../src/jquery.columnizer.js" type="text/javascript" charset="utf-8"></script>
<script>
Expand Down
3 changes: 2 additions & 1 deletion samples/sample9.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

.enclosure {border:1px dashed black}
</style>

<!-- Date: 2015-11-04 -->
<link rel="stylesheet" type="text/css" href="columnizer.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="../src/jquery.columnizer.js" type="text/javascript" charset="utf-8"></script>
<script>
Expand Down
91 changes: 49 additions & 42 deletions src/jquery.columnizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
// previx for all the CSS classes used by this plugin
// default to empty string for backwards compatibility
cssClassPrefix : "",
cssClassClear : "clear",
cssClassCol : "column",
elipsisText:'...',
debug:0
};
Expand Down Expand Up @@ -96,19 +98,25 @@
}

return this.each(function() {
var $inBox = options.target ? $(options.target) : $(this);
var maxHeight = $(this).height();
var $cache = $('<div></div>'); // this is where we'll put the real content
var lastWidth = 0;
var columnizing = false;
var manualBreaks = options.manualBreaks;
var cssClassPrefix = defaults.cssClassPrefix;
var $inBox = options.target ? $(options.target) : $(this),
maxHeight = $(this).height(),
$cache = $('<div></div>'), // this is where we'll put the real content
lastWidth = adjustment = 0,
columnizing = false,
manualBreaks = options.manualBreaks,
cssClassPrefix = defaults.cssClassPrefix,
cssClassClear = defaults.cssClassClear,
cssClassCol = defaults.cssClassCol;

if(typeof(options.cssClassPrefix) == "string"){
cssClassPrefix = options.cssClassPrefix;
}


var adjustment = 0;
if(typeof(options.cssClassClear) == "string"){
cssClassClear = options.cssClassClear;
}
if(typeof(options.cssClassCol) == "string"){
cssClassCol = options.cssClassCol;
}

appendSafe($cache, $(this).contents().clone(true));

Expand Down Expand Up @@ -136,7 +144,7 @@
}
}

$inBox.empty();
$inBox.empty().addClass('columnized');

columnizeIt();

Expand Down Expand Up @@ -200,21 +208,22 @@
if($putInHere[0].childNodes.length === 0) return;

// now we're too tall, so undo the last one
var kids = $putInHere[0].childNodes;
var lastKid = kids[kids.length-1];
var kids = $putInHere[0].childNodes,
lastKid = kids[kids.length-1];
$putInHere[0].removeChild(lastKid);
var $item = $(lastKid);

// now lets try to split that last node
// to fit as much of it as we can into this column
if($item[0].nodeType == 3){
// it's a text node, split it up
var oText = $item[0].nodeValue;
var counter2 = options.width / 18;
if(options.accuracy)
counter2 = options.accuracy;
var columnText;
var latestTextNode = null;
var oText = $item[0].nodeValue,
counter2 = options.width / 18,
columnText,
latestTextNode = null;

if(options.accuracy) counter2 = options.accuracy;

while($parentColumn.height() < targetHeight && oText.length){
//
// it's been brought up that this won't work for chinese
Expand Down Expand Up @@ -374,8 +383,8 @@
$inBox.append($("<div class='"
+ prefixTheClassName("first") + " "
+ prefixTheClassName("last") + " "
+ prefixTheClassName("column") + " "
+ "' style='width:100%; float: " + options.columnFloat + ";'></div>")); //"
+ prefixTheClassName(cssClassCol) + " "
+ "'></div>")); //"
$col = $inBox.children().eq($inBox.children().length-1);
$destroyable = $cache.clone(true);
if(options.overflow){
Expand All @@ -392,8 +401,8 @@
$destroyable.prepend($lastKid);
}

var html = "";
var div = document.createElement('DIV');
var html = "",
div = document.createElement('DIV');
while($destroyable[0].childNodes.length > 0){
var kid = $destroyable[0].childNodes[0];
if(kid.attributes){
Expand Down Expand Up @@ -478,10 +487,10 @@
maxHeight = $col.height();
$inBox.empty();

var targetHeight = maxHeight / numCols;
var firstTime = true;
var maxLoops = 3;
var scrollHorizontally = false;
var targetHeight = maxHeight / numCols,
firstTime = true,
maxLoops = 3,
scrollHorizontally = false;
if(options.overflow){
maxLoops = 1;
targetHeight = options.overflow.height;
Expand Down Expand Up @@ -513,17 +522,17 @@
for (var i = 0; i < numCols; i++) {
/* create column */
className = (i === 0) ? prefixTheClassName("first") : "";
className += " " + prefixTheClassName("column");
className += (className != "" ? " " : "") + prefixTheClassName(cssClassCol);
className = (i == numCols - 1) ? (prefixTheClassName("last") + " " + className) : className;
$inBox.append($("<div class='" + className + "' style='width:" + options.setWidth(numCols) + "%; float: " + options.columnFloat + ";'></div>")); //"
$inBox.append($("<div class='" + className + "'></div>")); //"
}

// fill all but the last column (unless overflowing)
i = 0;
while(i < numCols - (options.overflow ? 0 : 1) || scrollHorizontally && $destroyable.contents().length){
if($inBox.children().length <= i){
// we ran out of columns, make another
$inBox.append($("<div class='" + className + "' style='width:" + options.setWidth(numCols) + "%; float: " + options.columnFloat + ";'></div>")); //"
$inBox.append($("<div class='" + className + "'></div>")); //"
}
$col = $inBox.children().eq(i);
if(scrollHorizontally){
Expand Down Expand Up @@ -579,8 +588,8 @@
@*/
var IE7 = (document.all) && (navigator.appVersion.indexOf("MSIE 7.") != -1);
if(IE6 || IE7){
var html = "";
var div = document.createElement('DIV');
var html = "",
div = document.createElement('DIV');
while($destroyable[0].childNodes.length > 0){
var kid = $destroyable[0].childNodes[0];
for(i=0;i<kid.attributes.length;i++){
Expand All @@ -603,13 +612,11 @@
$destroyable.contents().each( function() {
$col.append( $(this) );
});
var afterH = $col.height();
var diff = afterH - targetHeight;
var totalH = 0;
var min = 10000000;
var max = 0;
var lastIsMax = false;
var numberOfColumnsThatDontEndInAColumnBreak = 0;
var afterH = $col.height(),
diff = afterH - targetHeight,
min = 10000000,
totalH = max = numberOfColumnsThatDontEndInAColumnBreak = 0,
lastIsMax = false;
$inBox.children().each(function($inBox){ return function($item){
var $col = $inBox.children().eq($item);
var endsInBreak = $col.children(":last").find(prefixTheClassName("columnbreak", true)).length;
Expand Down Expand Up @@ -671,10 +678,10 @@
});
$inBox.width($inBox.children().length * optionWidth + "px");
}
$inBox.append($("<br style='clear:both;'>"));
$inBox.append($("<div class='" + cssClassClear + "' />"));
}
$inBox.find(prefixTheClassName("column", true)).find(":first" + prefixTheClassName("removeiffirst", true)).remove();
$inBox.find(prefixTheClassName("column", true)).find(':last' + prefixTheClassName("removeiflast", true)).remove();
$inBox.find(prefixTheClassName(cssClassCol, true)).find(":first" + prefixTheClassName("removeiffirst", true)).remove();
$inBox.find(prefixTheClassName(cssClassCol, true)).find(':last' + prefixTheClassName("removeiflast", true)).remove();
$inBox.find(prefixTheClassName("split", true)).find(":first" + prefixTheClassName("removeiffirst", true)).remove();
$inBox.find(prefixTheClassName("split", true)).find(':last' + prefixTheClassName("removeiflast", true)).remove();
$inBox.data("columnizing", false);
Expand Down
Loading