MediaWiki:JQuery.Column.js

/* Column v1.0

*

* Copyright (c) 2011 Martijn W. van der Lee

* Licensed under the MIT.

*

* Emulate CSS3 style column on browsers that don't support it.

*/

String.prototype.indexOfRegExp==null&&(String.prototype.indexOfRegExp=function(a,b){var c=new RegExp(a,b),d=c.exec(this.valueOf);return d==null?-1:d.index}),function(a){a.fn.column=function(b){function e(a){var b=jQuery(' ').appendTo(a),c=b.height/10;return b.remove,c}function f(a){var b=jQuery(' ').appendTo("body"),c=b.outerHeight/2;return b.remove,c}function h(b){var d=new Array;return a(b).contents.each(function(a,b){b.nodeType==3?d=d.concat(g[c.split](b)):d.push(b)}),d}var c={width:"auto",count:"auto",gap:"normal",rule_color:"",rule_style:"none",rule_width:"medium",split:"word"},d={thin:f("thin"),medium:f("medium"),thick:f("thick")},g={word:function(a){var b=new Array;do{b.push(a);if(split=a.nodeValue.indexOfRegExp("\\s+")+1)a=a.splitText(split)}while(split);return b},sentence:function(a){var b=new Array;do{b.push(a);if(split=a.nodeValue.indexOfRegExp("[.:!?]+")+1)a=a.splitText(split)}while(split);return b}};return this.each(function{function k{a(f).empty;var b=c.gap==parseFloat(c.gap)?c.gap:j;if(c.rule_style!="none"){var e=c.rule_color?c.rule_color:a(f).css("color"),h=c.rule_width==parseFloat(c.rule_width)?c.rule_width:d[c.rule_width];b-=h}if(c.width!="auto")var k=Math.floor((a(f).width+h)/(c.width+b));else{if(c.count=="auto")return;var k=c.count}var l=a(f).width-(k-1)*b,m=Math.floor(l/k),n=0;for(var o=0;o0?"left:"+n+"px;":"")+"width:"+m+"px;"+(o>0?"padding-left:"+Math.ceil(b/2)+"px;":"")+(o0&&c.rule_style!="none"&&(p+="border-left:"+h+"px "+c.rule_style+" "+e+";",n+=h),a(f).append(' ')}var q=a("div",f).first,r=q.html(g).height;q.empty;var s=Math.ceil(r/k),t=i.length,u=0,v=0;for(var o=0;o<k;++o){var w=a("div",f).eq(o);if(o<k-1){while(v<t&&w.height<=s)w.append(i[v++]);var x=w.height;while(v<t&&w.height==x)w.append(i[v++]);w.contents.last.remove,--v}else while(v<t)w.append(i[v++]);u=Math.max(u,w.height)}a("div",f).css("height",u),a(f).css("height",u)}b&&a.extend(c,b);var f=this,g=a(this).html,i=h(this),j=e(this);k,a(window).resize(k).load(k)})}}(jQuery)