Skip to content

Commit e05cccf

Browse files
committed
first try for prefixing css classes
1 parent 18372ce commit e05cccf

File tree

3 files changed

+126
-27
lines changed

3 files changed

+126
-27
lines changed

samples/sample14.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<script src="../src/jquery.columnizer.js" type="text/javascript" charset="utf-8"></script>
2626
<script>
2727
$(function(){
28-
$('#hidden-wrapper a').click(function(){ alert("boo!"); });
28+
$('#hidden-wrapper h1').addClass("dontend");
2929
$('#hidden-wrapper').columnize({
3030
width:1,
3131
height:1,

samples/sample15.html

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2+
"http://www.w3.org/TR/html4/loose.dtd">
3+
4+
<html lang="en">
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7+
<title>Columnizer JQuery Plugin sample page 3</title>
8+
<meta name="generator" content="TextMate http://macromates.com/">
9+
<meta name="author" content="Matt Wilson">
10+
<!-- Date: 2008-07-12 -->
11+
<style>
12+
.column *{ padding: 5px; }
13+
14+
15+
body { font-size: 9pt; }
16+
#hidden-wrapper { display: none; }
17+
#target { margin: 0px 100px; }
18+
.wide, .thin { clear:both; }
19+
img{ float: left; padding:5px;}
20+
blockquote { font-style: italic; margin-left: 10px; border-left:2px solid #EFEFEF; padding-left: 8px;}
21+
span.columnbreak { display:block; border-bottom:1px dashed black; height:4px; margin: 0 30%; }
22+
23+
</style>
24+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
25+
<script src="../src/jquery.columnizer.js" type="text/javascript" charset="utf-8"></script>
26+
<script>
27+
$(function(){
28+
$('#hidden-wrapper h1').addClass("dontend");
29+
$('#hidden-wrapper').columnize({
30+
width:1,
31+
height:1,
32+
columns:1000,
33+
manualBreaks:true,
34+
target: "#target"
35+
36+
});
37+
});
38+
</script>
39+
</head>
40+
<body>
41+
<div id="target">
42+
</div>
43+
<div id="hidden-wrapper">
44+
<h1>column break inside dontsplit</h1>
45+
<p>This example shows columns breaking when the columnbreak is inside of a dontsplit item. This will only create as many columns as there are breaks. Bonorum has. His ut cibo quas tantas, vis ut probo adhuc definiebas, has at meis debet vulputate. No sed velit essent suavitate, in pro decore <a href='javascript:;'>ceteros temporibus</a>, usu in odio offendit theophrastus. Mel labore indoctum cu, ad soleat admodum delicatissimi sed, mei viris tritani ullamcorper eu. Ut vim simul aperiam.</p>
46+
<p><span class='columnbreak'></span></p>
47+
<p>Eu eleifend repudiandae has. Mea eu ridens aliquam. <img src='painting1.jpg'> Nisl aeque sit ut, posse dolor utinam cum in. Ad timeam sapientem eos, et eripuit inermis nam. Eos integre voluptaria ne, iriure concludaturque ut eum.</p>
48+
<p>Vis erant intellegat in. Soleat legere no ius, usu ex laoreet molestie. Sit <a href='javascript:;'>eu sint inermis</a>. Ea zzril scribentur pro.</p>
49+
<h1>Tempor essent appetere</h1>
50+
<p>Ius mutat commune expetendis in. Nam et quas sensibus <a href='javascript:;'>reprimique</a>, vix no erat soluta suavitate. At mel eius dictas latine. Corrumpit inciderint reformidans sed no, no usu omnis utinam noluisse.</p>
51+
<p>Sit et, an ius nihil apeirian. Eu posse tempor iuvaret cum. No diam dolor sea, postea mnesarchum ne ius, vel no utinam ignota dolores. Malis suscipit accusamus his ne, utinam assentior prodesset ea eam, facer partem antiopam et cum.</p>
52+
<blockquote><p>Probo debet quaestio an eos, no mel assum <a href='javascript:;'>iracundia delicatissimi</a>, rebum facete utroque sed ex. Eu melius invidunt repudiandae vix, eu paulo reformidans deterruisset duo, solum voluptaria efficiantur ea mel. Qui summo zzril alienum et. Eu est ferri iuvaret, mazim epicurei sententiae ut cum, modo reque intellegat ex vix. Vim eu tibique accusamus, quot electram at qui.</p></blockquote>
53+
<p>Ex iisque eleifend periculis has. Sit aeterno virtute partiendo ei, eam nonumy bonorum adolescens ad. Ut nec suas vocent ornatus, cetero legendos <a href='javascript:;'>constituam mea ea</a>, pri cu delenit iracundia. Mundi decore nec te.</p>
54+
<h1>Soleat civibus in pri</h1>
55+
<p>In petentium erroribus percipitur per. Takimata accommodare ius ut, eam no postulant urbanitas. Qui ei tantas consectetuer, quis dictas euripidis duo ei. Quaeque democritum concludaturque has ne.</p>
56+
<p>Blandit insolens constituto vix an. Has diam wisi in, eum unum repudiare no. Sit at virtute rationibus, qui vitae explicari cu. <img src='painting2.jpg'> Vim ne singulis voluptatum, sed puto accusata salutandi ei. Ad mel civibus adversarium.</p>
57+
<p>Per ne solum vivendo, fabulas dolorem vivendo in pro. Nec duis ignota cotidieque no, an per possit nostrum. Pro detraxit definitionem eu. Vivendo officiis no nam, eu has reque maiestatis percipitur, dolore reprimique accommodare cum ad. No utinam voluptua oportere pri, augue sonet dicant ei sea.</p>
58+
<p>Sit et, an ius nihil apeirian. Eu posse tempor iuvaret cum. No diam dolor sea, postea mnesarchum ne ius, vel no utinam ignota dolores. Malis suscipit accusamus his ne, utinam assentior prodesset ea eam, facer partem antiopam et cum.</p>
59+
<h1>Lorem ipsum ne justo</h1>
60+
<p>Bonorum has. His ut cibo quas tantas, vis ut probo adhuc definiebas, has at meis debet vulputate. No sed velit essent suavitate, in pro decore <a href='javascript:;'>ceteros temporibus</a>, usu in odio offendit theophrastus. Mel labore indoctum cu, ad soleat admodum delicatissimi sed, mei viris tritani ullamcorper eu. Ut vim simul aperiam.</p>
61+
<p class='dontsplit'>Test Eu eleifend repudiandae has. Mea eu ridens aliquam. Nisl aeque sit ut, posse dolor utinam cum in. Ad timeam sapientem eos, et eripuit inermis nam. Eos integre voluptaria ne, iriure concludaturque ut eum.
62+
<span class='columnbreak'></span>
63+
Eu eleifend repudiandae has. Mea eu ridens aliquam. Nisl aeque sit ut, posse dolor utinam cum in. Ad timeam sapientem eos, et eripuit inermis nam. Eos integre voluptaria ne, iriure concludaturque ut eum. Test</p>
64+
<p>Vis erant intellegat in. Soleat legere no ius, usu ex laoreet molestie. Sit <a href='javascript:;'>eu sint inermis</a>. Ea zzril scribentur pro.</p>
65+
<h1>Tempor essent appetere</h1>
66+
<p>Ius mutat commune expetendis in. Nam et quas sensibus <a href='javascript:;'>reprimique</a>, vix no erat soluta suavitate. At mel eius dictas latine. Corrumpit inciderint reformidans sed no, no usu omnis utinam noluisse.</p>
67+
<p>Sit et, an ius nihil apeirian. Eu posse tempor iuvaret cum. No diam dolor sea, postea mnesarchum ne ius, vel no utinam ignota dolores. Malis suscipit accusamus his ne, utinam assentior prodesset ea eam, facer partem antiopam et cum.</p>
68+
<blockquote><p>Probo debet quaestio an eos, no mel assum <a href='javascript:;'>iracundia delicatissimi</a>, rebum facete utroque sed ex. Eu melius invidunt repudiandae vix, eu paulo reformidans deterruisset duo, solum voluptaria efficiantur ea mel. Qui summo zzril alienum et. Eu est ferri iuvaret, mazim epicurei sententiae ut cum, modo reque intellegat ex vix. Vim eu tibique accusamus, quot electram at qui.</p></blockquote>
69+
<p>Ex iisque eleifend periculis has. Sit aeterno virtute partiendo ei, eam nonumy bonorum adolescens ad. Ut nec suas vocent ornatus, cetero legendos <a href='javascript:;'>constituam mea ea</a>, pri cu delenit iracundia. Mundi decore nec te.</p>
70+
<h1>Soleat civibus in pri</h1>
71+
<p>In petentium erroribus percipitur per. Takimata accommodare ius ut, eam no postulant urbanitas. Qui ei tantas consectetuer, quis dictas euripidis duo ei. Quaeque democritum concludaturque has ne.</p>
72+
<p>Blandit insolens constituto vix an. Has diam wisi in, eum unum repudiare no. Sit at virtute rationibus, qui vitae explicari cu. <img src='painting2.jpg'> Vim ne singulis voluptatum, sed puto accusata salutandi ei. Ad mel civibus adversarium.</p>
73+
<p>Per ne solum vivendo, fabulas dolorem vivendo in pro. Nec duis ignota cotidieque no, an per possit nostrum. Pro detraxit definitionem eu. Vivendo officiis no nam, eu has reque maiestatis percipitur, dolore reprimique accommodare cum ad. No utinam voluptua oportere pri, augue sonet dicant ei sea.</p>
74+
<p>Sit et, an ius nihil apeirian. Eu posse tempor iuvaret cum. No diam dolor sea, postea mnesarchum ne ius, vel no utinam ignota dolores. Malis suscipit accusamus his ne, utinam assentior prodesset ea eam, facer partem antiopam et cum.</p>
75+
</div>
76+
</body>
77+
</html>

src/jquery.columnizer.js

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
// column widths, but will take slightly longer
3636
accuracy : false,
3737
// don't automatically layout columns, only use manual columnbreak
38-
manualBreaks : false
38+
manualBreaks : false,
39+
// previx for all the CSS classes used by this plugin
40+
// default to empty string for backwards compatibility
41+
cssClassPrefix : ""
3942
};
4043
var options = $.extend(defaults, options);
4144

@@ -53,6 +56,11 @@
5356
var lastWidth = 0;
5457
var columnizing = false;
5558
var manualBreaks = options.manualBreaks;
59+
var cssClassPrefix = defaults.cssClassPrefix;
60+
if(typeof(options.cssClassPrefix) == "string"){
61+
cssClassPrefix = options.cssClassPrefix;
62+
}
63+
5664

5765
var adjustment = 0;
5866

@@ -99,6 +107,15 @@
99107
}
100108
});
101109
}
110+
111+
function prefixTheClassName(className, withDot){
112+
var dot = withDot ? "." : "";
113+
if(cssClassPrefix.length){
114+
return dot + cssClassPrefix + "-" + className;
115+
}
116+
return dot + className;
117+
}
118+
102119

103120
/**
104121
* this fuction builds as much of a column as it can without
@@ -126,12 +143,12 @@
126143
//
127144
// Because we're not cloning, jquery will actually move the element"
128145
// http://welcome.totheinter.net/2009/03/19/the-undocumented-life-of-jquerys-append/
129-
if($(node).find(".columnbreak").length){
146+
if($(node).find(prefixTheClassName("columnbreak", true)).length){
130147
//
131148
// our column is on a column break, so just end here
132149
return;
133150
}
134-
if($(node).hasClass("columnbreak")){
151+
if($(node).hasClass(prefixTheClassName("columnbreak"))){
135152
//
136153
// our column is on a column break, so just end here
137154
return;
@@ -199,12 +216,12 @@
199216
* two copies of the element with it's contents divided between each
200217
*/
201218
function split($putInHere, $pullOutHere, $parentColumn, targetHeight){
202-
if($putInHere.contents(":last").find(".columnbreak").length){
219+
if($putInHere.contents(":last").find(prefixTheClassName("columnbreak", true)).length){
203220
//
204221
// our column is on a column break, so just end here
205222
return;
206223
}
207-
if($putInHere.contents(":last").hasClass("columnbreak")){
224+
if($putInHere.contents(":last").hasClass(prefixTheClassName("columnbreak"))){
208225
//
209226
// our column is on a column break, so just end here
210227
return;
@@ -221,7 +238,7 @@
221238
//
222239
// need to support both .prop and .attr if .prop doesn't exist.
223240
// this is for backwards compatibility with older versions of jquery.
224-
if($cloneMe.hasClass("columnbreak")){
241+
if($cloneMe.hasClass(prefixTheClassName("columnbreak"))){
225242
//
226243
// ok, we have a columnbreak, so add it into
227244
// the column and exit
@@ -231,19 +248,19 @@
231248
// keep adding until we hit a manual break
232249
$putInHere.append($clone);
233250
$cloneMe.remove();
234-
}else if($clone.get(0).nodeType == 1 && !$clone.hasClass("dontend")){
251+
}else if($clone.get(0).nodeType == 1 && !$clone.hasClass(prefixTheClassName("dontend"))){
235252
$putInHere.append($clone);
236253
if($clone.is("img") && $parentColumn.height() < targetHeight + 20){
237254
//
238255
// we can't split an img in half, so just add it
239256
// to the column and remove it from the pullOutHere section
240257
$cloneMe.remove();
241-
}else if(!$cloneMe.hasClass("dontsplit") && $parentColumn.height() < targetHeight + 20){
258+
}else if(!$cloneMe.hasClass(prefixTheClassName("dontsplit")) && $parentColumn.height() < targetHeight + 20){
242259
//
243260
// pretty close fit, and we're not allowed to split it, so just
244261
// add it to the column, remove from pullOutHere, and be done
245262
$cloneMe.remove();
246-
}else if($clone.is("img") || $cloneMe.hasClass("dontsplit")){
263+
}else if($clone.is("img") || $cloneMe.hasClass(prefixTheClassName("dontsplit"))){
247264
//
248265
// it's either an image that's too tall, or an unsplittable node
249266
// that's too tall. leave it in the pullOutHere and we'll add it to the
@@ -258,14 +275,14 @@
258275
if(!columnize($clone, $cloneMe, $parentColumn, targetHeight)){
259276
// this node still has non-text nodes to split
260277
// add the split class and then recur
261-
$cloneMe.addClass("split");
278+
$cloneMe.addClass(prefixTheClassName("split"));
262279
if($cloneMe.children().length){
263280
split($clone, $cloneMe, $parentColumn, targetHeight);
264281
}
265282
}else{
266283
// this node only has text node children left, add the
267284
// split class and move on.
268-
$cloneMe.addClass("split");
285+
$cloneMe.addClass(prefixTheClassName("split"));
269286
}
270287
if($clone.get(0).childNodes.length == 0){
271288
// it was split, but nothing is in it :(
@@ -285,14 +302,18 @@
285302
$inBox.data("columnizing", true);
286303

287304
$inBox.empty();
288-
$inBox.append($("<div class='first last column' style='width:100%; float: " + options.columnFloat + ";'></div>")); //"
305+
$inBox.append($("<div class='"
306+
+ prefixTheClassName("first") + " "
307+
+ prefixTheClassName("last") + " "
308+
+ prefixTheClassName("column") + " "
309+
+ "' style='width:100%; float: " + options.columnFloat + ";'></div>")); //"
289310
$col = $inBox.children().eq($inBox.children().length-1);
290311
$destroyable = $cache.clone(true);
291312
if(options.overflow){
292313
targetHeight = options.overflow.height;
293314
columnize($col, $destroyable, $col, targetHeight);
294315
// make sure that the last item in the column isn't a "dontend"
295-
if(!$destroyable.contents().find(":first-child").hasClass("dontend")){
316+
if(!$destroyable.contents().find(":first-child").hasClass(prefixTheClassName("dontend"))){
296317
split($col, $destroyable, $col, targetHeight);
297318
}
298319

@@ -351,7 +372,7 @@
351372
return false;
352373
}
353374
if(dom.nodeType != 1) return false;
354-
if($(dom).hasClass("dontend")) return true;
375+
if($(dom).hasClass(prefixTheClassName("dontend"))) return true;
355376
if(dom.childNodes.length == 0) return false;
356377
return checkDontEndColumn(dom.childNodes[dom.childNodes.length-1]);
357378
}
@@ -369,7 +390,7 @@
369390
var optionHeight = options.height;
370391
if(options.columns) numCols = options.columns;
371392
if(manualBreaks){
372-
numCols = $cache.find(".columnbreak").length + 1;
393+
numCols = $cache.find(prefixTheClassName("columnbreak", true)).length + 1;
373394
optionWidth = false;
374395
}
375396

@@ -420,8 +441,9 @@
420441
// create the columns
421442
for (var i = 0; i < numCols; i++) {
422443
/* create column */
423-
var className = (i == 0) ? "first column" : "column";
424-
var className = (i == numCols - 1) ? ("last " + className) : className;
444+
var className = (i == 0) ? prefixTheClassName("first") : "";
445+
className += " " + prefixTheClassName("column");
446+
var className = (i == numCols - 1) ? (prefixTheClassName("last") + " " + className) : className;
425447
$inBox.append($("<div class='" + className + "' style='width:" + (Math.floor(100 / numCols))+ "%; float: " + options.columnFloat + ";'></div>")); //"
426448
}
427449

@@ -435,7 +457,7 @@
435457
var $col = $inBox.children().eq(i);
436458
columnize($col, $destroyable, $col, targetHeight);
437459
// make sure that the last item in the column isn't a "dontend"
438-
if(!$destroyable.contents().find(":first-child").hasClass("dontend")){
460+
if(!$destroyable.contents().find(":first-child").hasClass(prefixTheClassName("dontend"))){
439461
split($col, $destroyable, $col, targetHeight);
440462
}else{
441463
// alert("not splitting a dontend");
@@ -473,7 +495,7 @@
473495
//
474496
// if $destroyable still has columnbreak nodes in it, then we need to keep
475497
// looping and creating more columns.
476-
if($destroyable.find(".columnbreak").length){
498+
if($destroyable.find(prefixTheClassName("columnbreak", true)).length){
477499
numCols ++;
478500
}
479501
}
@@ -514,7 +536,7 @@
514536
var numberOfColumnsThatDontEndInAColumnBreak = 0;
515537
$inBox.children().each(function($inBox){ return function($item){
516538
var $col = $inBox.children().eq($item);
517-
var endsInBreak = $col.children(":last").find(".columnbreak").length;
539+
var endsInBreak = $col.children(":last").find(prefixTheClassName("columnbreak", true)).length;
518540
if(!endsInBreak){
519541
var h = $col.height();
520542
lastIsMax = false;
@@ -561,20 +583,20 @@
561583
$col = $inBox.children().eq(i);
562584
$col.width(optionWidth + "px");
563585
if(i==0){
564-
$col.addClass("first");
586+
$col.addClass(prefixTheClassName("first"));
565587
}else if(i==$inBox.children().length-1){
566-
$col.addClass("last");
588+
$col.addClass(prefixTheClassName("last"));
567589
}else{
568-
$col.removeClass("first");
569-
$col.removeClass("last");
590+
$col.removeClass(prefixTheClassName("first"));
591+
$col.removeClass(prefixTheClassName("last"));
570592
}
571593
});
572594
$inBox.width($inBox.children().length * optionWidth + "px");
573595
}
574596
$inBox.append($("<br style='clear:both;'>"));
575597
}
576-
$inBox.find('.column').find(':first.removeiffirst').remove();
577-
$inBox.find('.column').find(':last.removeiflast').remove();
598+
$inBox.find(prefixTheClassName("column", true)).find(":first" + prefixTheClassName("removeiffirst", true)).remove();
599+
$inBox.find(prefixTheClassName("column", true)).find(':last' + prefixTheClassName("removeiflast", true)).remove();
578600
$inBox.data("columnizing", false);
579601

580602
if(options.overflow){

0 commit comments

Comments
 (0)