From af149272458d7376d698df87a6fb8002b9029e6f Mon Sep 17 00:00:00 2001 From: Misha Koryak Date: Fri, 21 Mar 2014 18:04:26 -0400 Subject: [PATCH 1/2] fixes for #62, #65, #66 --- bower.json | 5 ++--- dist/jquery.floatThead-slim.js | 23 +++++++++++++++++++---- dist/jquery.floatThead-slim.min.js | 4 ++-- dist/jquery.floatThead.js | 23 +++++++++++++++++++---- dist/jquery.floatThead.min.js | 4 ++-- jquery.floatThead.js | 23 +++++++++++++++++++---- package.json | 2 +- 7 files changed, 64 insertions(+), 20 deletions(-) diff --git a/bower.json b/bower.json index 52baf22..54c862c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.floatThead", - "version": "1.2.4", + "version": "1.2.5", "homepage": "http://mkoryak.github.io/floatThead/", "authors": [ "Misha Koryak" @@ -16,8 +16,7 @@ "node_modules", "bower_components", "test", - "demo", - "USED_BY.md" + "demo" ], "dependencies": { "jquery": ">= 1.9.0" diff --git a/dist/jquery.floatThead-slim.js b/dist/jquery.floatThead-slim.js index d7b4677..c0d1e25 100644 --- a/dist/jquery.floatThead-slim.js +++ b/dist/jquery.floatThead-slim.js @@ -1,4 +1,4 @@ -// @preserve jQuery.floatThead 1.2.4 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak +// @preserve jQuery.floatThead 1.2.5 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak // @license Licensed under http://creativecommons.org/licenses/by-sa/4.0/ /* @author Misha Koryak @@ -66,7 +66,19 @@ */ function windowResize(debounceMs, cb){ - $window.bind('resize.floatTHead', util.debounce(cb, debounceMs)); //TODO: check if resize bug is gone in IE8 + + if(ieVersion == 8){ //ie8 is crap: https://github.com/mkoryak/floatThead/issues/65 + var winWidth = $window.width(); + var debouncedCb = util.debounce(function(){ + var winWidthNew = $window.width(); + if(winWidth != winWidthNew){ + winWidth = winWidthNew; + cb(); + } + }, debounceMs); + $window.bind('resize.floatTHead', debouncedCb); + } else { + $window.bind('resize.floatTHead', util.debounce(cb, debounceMs)); + } } @@ -144,7 +156,7 @@ } var opts = $.extend({}, $.floatThead.defaults || {}, map); - $.each(map, function(val, key){ + $.each(map, function(key, val){ if((!(key in $.floatThead.defaults)) && opts.debug){ debug("jQuery.floatThead: used ["+key+"] key to init plugin, but that param is not an option for the plugin. Valid options are: "+ (util.keys($.floatThead.defaults)).join(', ')); } @@ -256,7 +268,10 @@ var originalTableWidth = $table[0].style.width || "auto"; function setHeaderHeight(){ - var headerHeight = $header.find(opts.cellTag).outerHeight(true); + var headerHeight = 0; + $header.find("tr").each(function(){ + headerHeight += $(this).outerHeight(true); + }); $sizerRow.outerHeight(headerHeight); $sizerCells.outerHeight(headerHeight); } diff --git a/dist/jquery.floatThead-slim.min.js b/dist/jquery.floatThead-slim.min.js index fc11a8a..9f8f5bb 100644 --- a/dist/jquery.floatThead-slim.min.js +++ b/dist/jquery.floatThead-slim.min.js @@ -1,3 +1,3 @@ -// @preserve jQuery.floatThead 1.2.4 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak +// @preserve jQuery.floatThead 1.2.5 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak // @license Licensed under http://creativecommons.org/licenses/by-sa/4.0/ -!function(a){function b(a,b){j.bind("resize.floatTHead",f.debounce(b,a))}function c(a){window.console&&window.console&&window.console.log&&window.console.log(a)}function d(){var b=a('
');a("body").append(b);var c=b.innerWidth(),d=a("div",b).innerWidth();return b.remove(),c-d}function e(a){if(a.dataTableSettings)for(var b=0;btd")},floatTableClass:"floatThead-table",floatWrapperClass:"floatThead-wrapper",floatContainerClass:"floatThead-container",copyTableClass:!0,debug:!1};var f=window._,g=function(){for(var a=3,b=document.createElement("b"),c=b.all||[];a=1+a,b.innerHTML="",c[0];);return a>4?a:document.documentMode}(),h=null,i=function(){if(g)return!1;var b=a("
");a("body").append(b);var c=b.find("col").width();return b.remove(),0==c},j=a(window),k=0;a.fn.floatThead=function(l){if(l=l||{},!f&&(f=window._||a.floatThead._,!f))throw new Error("jquery.floatThead-slim.js requires underscore. You should use the non-lite version since you do not have underscore.");if(8>g)return this;if(null==h&&(h=i(),h&&(document.createElement("fthtr"),document.createElement("fthtd"),document.createElement("fthfoot"))),f.isString(l)){var m=l,n=this;return this.filter("table").each(function(){var b=a(this).data("floatThead-attached");if(b&&f.isFunction(b[m])){var c=b[m]();"undefined"!=typeof c&&(n=c)}}),n}var o=a.extend({},a.floatThead.defaults||{},l);return a.each(l,function(b,d){d in a.floatThead.defaults||!o.debug||c("jQuery.floatThead: used ["+d+"] key to init plugin, but that param is not an option for the plugin. Valid options are: "+f.keys(a.floatThead.defaults).join(", "))}),this.filter(":not(."+o.floatTableClass+")").each(function(){function c(){var a=x.find(o.cellTag).outerHeight(!0);V.outerHeight(a),W.outerHeight(a)}function i(){var a=w.outerWidth(),b=F.width()||a;if(T.width(b-C.vertical),L){var c=100*a/(b-C.vertical);P.css("width",c+"%")}else P.outerWidth(a)}function l(){z=(f.isFunction(o.scrollingTop)?o.scrollingTop(w):o.scrollingTop)||0,A=(f.isFunction(o.scrollingBottom)?o.scrollingBottom(w):o.scrollingBottom)||0}function m(){var b=x.find("tr:first>"+o.cellTag),c=0;if(b.each(function(){c+=parseInt(a(this).attr("colspan")||1,10)}),c!=E){E=c;for(var d=[],e=[],f=[],g=0;c>g;g++)d.push(''),e.push(""),f.push("");e=e.join(""),d=d.join(""),h&&(f=f.join(""),S.html(f),Z=S.find("fthtd")),V.html(d),W=V.find("th"),R.html(e),X=R.find("col"),Q.html(e),Y=Q.find("col")}return c}function n(){if(!B){if(B=!0,G){var a=w.width(),b=N.width();a>b&&w.css("minWidth",a)}w.css(_),P.css(_),P.append(x),y.before(U),c()}}function p(){B&&(B=!1,G&&w.width(bb),U.detach(),w.prepend(x),w.css(ab),P.css(ab))}function q(a){G!=a&&(G=a,T.css({position:G?"absolute":"fixed"}))}function r(a,b,c,d){return h?c:d?o.getSizingRow(a,b,c):b}function s(){var a,b=m();return function(){var d=r(w,X,Z,g);if(d.length==b&&b>0){for(p(),a=0;b>a;a++){var e=d.get(a),f=e.offsetWidth;Y.eq(a).width(f),X.eq(a).width(f)}n()}else P.append(x),w.css(ab),P.css(ab),c()}}function t(){var a,b=F.scrollTop(),c=0,d=I?H.outerHeight(!0):0,e=J?d:-d,f=T.height(),g=w.offset();if(L){var i=F.offset();c=g.top-i.top+b,I&&J&&(c+=d)}else a=g.top-z-f+A+C.horizontal;var k=j.scrollTop(),l=j.scrollLeft(),m=F.scrollLeft();return b=F.scrollTop(),function(i){if("windowScroll"==i?(k=j.scrollTop(),l=j.scrollLeft()):"containerScroll"==i?(b=F.scrollTop(),m=F.scrollLeft()):"init"!=i&&(k=j.scrollTop(),l=j.scrollLeft(),b=F.scrollTop(),m=F.scrollLeft()),!h||!(0>k||0>l)){if(O)"windowScrollDone"==i?q(!0):q(!1);else if("windowScrollDone"==i)return null;g=w.offset(),I&&J&&(g.top+=d);var o,r,s;if(L&&G){if(c>=b){var t=c-b;t=t>0?t:0,o=t}else o=M?0:b;r=0}else!L&&G?(s=w.outerHeight(),k>a+s+e?o=s-f+e:g.top>k+z?(o=0,p()):(o=z+k-g.top+c+(J?d:0),n()),r=0):L&&!G?(c>b?(o=g.top-k,p()):(o=g.top+b-k-c,n()),r=g.left+m-l):L||G||(s=w.outerHeight(),k>a+s+e?o=s+z-k+a+e:g.top>k+z?(o=g.top-k,n()):o=z,r=g.left-l);return{top:o,left:r}}}}function u(){var a=null,b=null,d=null;return function(e,f,g){null==e||a==e.top&&b==e.left||(T.css({top:e.top,left:e.left}),a=e.top,b=e.left),f&&i(),g&&c();var h=F.scrollLeft();d!=h&&(T.scrollLeft(h),d=h)}}function v(){F.length&&(C.horizontal=F.width() element");var z,A,B=!1,C={vertical:0,horizontal:0},D=d(),E=0,F=o.scrollContainer(w)||a([]),G=o.useAbsolutePositioning;null==G&&(G=o.scrollContainer(w).length);var H=w.find("caption"),I=1==H.length;if(I)var J="top"===(H.css("caption-side")||H.attr("align")||"top");var K=a(''),L=F.length>0,M=!1,N=a([]),O=9>=g&&!L&&G,P=a(""),Q=a(""),R=a(""),S=a(''),T=a('
'),U=a("
"),V=a(''),W=a([]),X=a([]),Y=a([]),Z=a([]);if(U.append(V),w.prepend(R),h&&(K.append(S),w.append(K)),P.append(Q),T.append(P),o.copyTableClass&&P.attr("class",w.attr("class")),P.attr({cellpadding:w.attr("cellpadding"),cellspacing:w.attr("cellspacing"),border:w.attr("border")}),P.addClass(o.floatTableClass).css("margin",0),G){var $=function(a,b){var c=a.css("position"),d="relative"==c||"absolute"==c;if(!d||b){var e={paddingLeft:a.css("paddingLeft"),paddingRight:a.css("paddingRight")};T.css(e),a=a.wrap("
").parent(),M=!0}return a};L?(N=$(F,!0),N.append(T)):(N=$(w),w.after(T))}else w.after(T);T.css({position:G?"absolute":"fixed",marginTop:0,top:G?0:"auto",zIndex:o.zIndex}),T.addClass(o.floatContainerClass),l();var _={"table-layout":"fixed"},ab={"table-layout":w.css("tableLayout")||"auto"},bb=w[0].style.width||"auto";v();var cb,db=function(){(cb=s())()};db();var eb=t(),fb=u();fb(eb("init"),!0);var gb=f.debounce(function(){fb(eb("windowScrollDone"),!1)},300),hb=function(){fb(eb("windowScroll"),!1),gb()},ib=function(){fb(eb("containerScroll"),!1)},jb=function(){l(),v(),db(),eb=t(),(fb=u())(eb("resize"),!0,!0)},kb=f.debounce(function(){v(),l(),db(),eb=t(),fb(eb("reflow"),!0)},1);L?G?F.bind("scroll.floatTHead",ib):(F.bind("scroll.floatTHead",ib),j.bind("scroll.floatTHead",hb)):j.bind("scroll.floatTHead",hb),j.bind("load.floatTHead",kb),b(o.debounceResizeMs,jb),w.bind("reflow",kb),e(w)&&w.bind("filter",kb).bind("sort",kb).bind("page",kb),w.data("floatThead-attached",{destroy:function(){p(),w.css(ab),R.remove(),h&&K.remove(),U.parent().length&&U.replaceWith(x),w.unbind("reflow"),kb=jb=ib=hb=function(){},F.unbind("scroll.floatTHead"),T.remove(),w.data("floatThead-attached",!1),k--,0==k&&(j.unbind("scroll.floatTHead"),j.unbind("resize.floatTHead"),j.unbind("load.floatTHead"))},reflow:function(){kb()},setHeaderHeight:function(){c()},getFloatContainer:function(){return T},getRowGroups:function(){return B?T.find("thead").add(w.find("tbody,tfoot")):w.find("thead,tbody,tfoot")}}),k++}),this}}(jQuery); \ No newline at end of file +!function(a){function b(a,b){if(8==g){var c=j.width(),d=f.debounce(function(){var a=j.width();c!=a&&(c=a,b())},a);j.bind("resize.floatTHead",d)}else j.bind("resize.floatTHead",f.debounce(b,a))}function c(a){window.console&&window.console&&window.console.log&&window.console.log(a)}function d(){var b=a('
');a("body").append(b);var c=b.innerWidth(),d=a("div",b).innerWidth();return b.remove(),c-d}function e(a){if(a.dataTableSettings)for(var b=0;btd")},floatTableClass:"floatThead-table",floatWrapperClass:"floatThead-wrapper",floatContainerClass:"floatThead-container",copyTableClass:!0,debug:!1};var f=window._,g=function(){for(var a=3,b=document.createElement("b"),c=b.all||[];a=1+a,b.innerHTML="",c[0];);return a>4?a:document.documentMode}(),h=null,i=function(){if(g)return!1;var b=a("
");a("body").append(b);var c=b.find("col").width();return b.remove(),0==c},j=a(window),k=0;a.fn.floatThead=function(l){if(l=l||{},!f&&(f=window._||a.floatThead._,!f))throw new Error("jquery.floatThead-slim.js requires underscore. You should use the non-lite version since you do not have underscore.");if(8>g)return this;if(null==h&&(h=i(),h&&(document.createElement("fthtr"),document.createElement("fthtd"),document.createElement("fthfoot"))),f.isString(l)){var m=l,n=this;return this.filter("table").each(function(){var b=a(this).data("floatThead-attached");if(b&&f.isFunction(b[m])){var c=b[m]();"undefined"!=typeof c&&(n=c)}}),n}var o=a.extend({},a.floatThead.defaults||{},l);return a.each(l,function(b){b in a.floatThead.defaults||!o.debug||c("jQuery.floatThead: used ["+b+"] key to init plugin, but that param is not an option for the plugin. Valid options are: "+f.keys(a.floatThead.defaults).join(", "))}),this.filter(":not(."+o.floatTableClass+")").each(function(){function c(){var b=0;x.find("tr").each(function(){b+=a(this).outerHeight(!0)}),V.outerHeight(b),W.outerHeight(b)}function i(){var a=w.outerWidth(),b=F.width()||a;if(T.width(b-C.vertical),L){var c=100*a/(b-C.vertical);P.css("width",c+"%")}else P.outerWidth(a)}function l(){z=(f.isFunction(o.scrollingTop)?o.scrollingTop(w):o.scrollingTop)||0,A=(f.isFunction(o.scrollingBottom)?o.scrollingBottom(w):o.scrollingBottom)||0}function m(){var b=x.find("tr:first>"+o.cellTag),c=0;if(b.each(function(){c+=parseInt(a(this).attr("colspan")||1,10)}),c!=E){E=c;for(var d=[],e=[],f=[],g=0;c>g;g++)d.push(''),e.push(""),f.push("");e=e.join(""),d=d.join(""),h&&(f=f.join(""),S.html(f),Z=S.find("fthtd")),V.html(d),W=V.find("th"),R.html(e),X=R.find("col"),Q.html(e),Y=Q.find("col")}return c}function n(){if(!B){if(B=!0,G){var a=w.width(),b=N.width();a>b&&w.css("minWidth",a)}w.css(_),P.css(_),P.append(x),y.before(U),c()}}function p(){B&&(B=!1,G&&w.width(bb),U.detach(),w.prepend(x),w.css(ab),P.css(ab))}function q(a){G!=a&&(G=a,T.css({position:G?"absolute":"fixed"}))}function r(a,b,c,d){return h?c:d?o.getSizingRow(a,b,c):b}function s(){var a,b=m();return function(){var d=r(w,X,Z,g);if(d.length==b&&b>0){for(p(),a=0;b>a;a++){var e=d.get(a),f=e.offsetWidth;Y.eq(a).width(f),X.eq(a).width(f)}n()}else P.append(x),w.css(ab),P.css(ab),c()}}function t(){var a,b=F.scrollTop(),c=0,d=I?H.outerHeight(!0):0,e=J?d:-d,f=T.height(),g=w.offset();if(L){var i=F.offset();c=g.top-i.top+b,I&&J&&(c+=d)}else a=g.top-z-f+A+C.horizontal;var k=j.scrollTop(),l=j.scrollLeft(),m=F.scrollLeft();return b=F.scrollTop(),function(i){if("windowScroll"==i?(k=j.scrollTop(),l=j.scrollLeft()):"containerScroll"==i?(b=F.scrollTop(),m=F.scrollLeft()):"init"!=i&&(k=j.scrollTop(),l=j.scrollLeft(),b=F.scrollTop(),m=F.scrollLeft()),!h||!(0>k||0>l)){if(O)"windowScrollDone"==i?q(!0):q(!1);else if("windowScrollDone"==i)return null;g=w.offset(),I&&J&&(g.top+=d);var o,r,s;if(L&&G){if(c>=b){var t=c-b;t=t>0?t:0,o=t}else o=M?0:b;r=0}else!L&&G?(s=w.outerHeight(),k>a+s+e?o=s-f+e:g.top>k+z?(o=0,p()):(o=z+k-g.top+c+(J?d:0),n()),r=0):L&&!G?(c>b?(o=g.top-k,p()):(o=g.top+b-k-c,n()),r=g.left+m-l):L||G||(s=w.outerHeight(),k>a+s+e?o=s+z-k+a+e:g.top>k+z?(o=g.top-k,n()):o=z,r=g.left-l);return{top:o,left:r}}}}function u(){var a=null,b=null,d=null;return function(e,f,g){null==e||a==e.top&&b==e.left||(T.css({top:e.top,left:e.left}),a=e.top,b=e.left),f&&i(),g&&c();var h=F.scrollLeft();d!=h&&(T.scrollLeft(h),d=h)}}function v(){F.length&&(C.horizontal=F.width() element");var z,A,B=!1,C={vertical:0,horizontal:0},D=d(),E=0,F=o.scrollContainer(w)||a([]),G=o.useAbsolutePositioning;null==G&&(G=o.scrollContainer(w).length);var H=w.find("caption"),I=1==H.length;if(I)var J="top"===(H.css("caption-side")||H.attr("align")||"top");var K=a(''),L=F.length>0,M=!1,N=a([]),O=9>=g&&!L&&G,P=a(""),Q=a(""),R=a(""),S=a(''),T=a('
'),U=a("
"),V=a(''),W=a([]),X=a([]),Y=a([]),Z=a([]);if(U.append(V),w.prepend(R),h&&(K.append(S),w.append(K)),P.append(Q),T.append(P),o.copyTableClass&&P.attr("class",w.attr("class")),P.attr({cellpadding:w.attr("cellpadding"),cellspacing:w.attr("cellspacing"),border:w.attr("border")}),P.addClass(o.floatTableClass).css("margin",0),G){var $=function(a,b){var c=a.css("position"),d="relative"==c||"absolute"==c;if(!d||b){var e={paddingLeft:a.css("paddingLeft"),paddingRight:a.css("paddingRight")};T.css(e),a=a.wrap("
").parent(),M=!0}return a};L?(N=$(F,!0),N.append(T)):(N=$(w),w.after(T))}else w.after(T);T.css({position:G?"absolute":"fixed",marginTop:0,top:G?0:"auto",zIndex:o.zIndex}),T.addClass(o.floatContainerClass),l();var _={"table-layout":"fixed"},ab={"table-layout":w.css("tableLayout")||"auto"},bb=w[0].style.width||"auto";v();var cb,db=function(){(cb=s())()};db();var eb=t(),fb=u();fb(eb("init"),!0);var gb=f.debounce(function(){fb(eb("windowScrollDone"),!1)},300),hb=function(){fb(eb("windowScroll"),!1),gb()},ib=function(){fb(eb("containerScroll"),!1)},jb=function(){l(),v(),db(),eb=t(),(fb=u())(eb("resize"),!0,!0)},kb=f.debounce(function(){v(),l(),db(),eb=t(),fb(eb("reflow"),!0)},1);L?G?F.bind("scroll.floatTHead",ib):(F.bind("scroll.floatTHead",ib),j.bind("scroll.floatTHead",hb)):j.bind("scroll.floatTHead",hb),j.bind("load.floatTHead",kb),b(o.debounceResizeMs,jb),w.bind("reflow",kb),e(w)&&w.bind("filter",kb).bind("sort",kb).bind("page",kb),w.data("floatThead-attached",{destroy:function(){p(),w.css(ab),R.remove(),h&&K.remove(),U.parent().length&&U.replaceWith(x),w.unbind("reflow"),kb=jb=ib=hb=function(){},F.unbind("scroll.floatTHead"),T.remove(),w.data("floatThead-attached",!1),k--,0==k&&(j.unbind("scroll.floatTHead"),j.unbind("resize.floatTHead"),j.unbind("load.floatTHead"))},reflow:function(){kb()},setHeaderHeight:function(){c()},getFloatContainer:function(){return T},getRowGroups:function(){return B?T.find("thead").add(w.find("tbody,tfoot")):w.find("thead,tbody,tfoot")}}),k++}),this}}(jQuery); \ No newline at end of file diff --git a/dist/jquery.floatThead.js b/dist/jquery.floatThead.js index 3b0edbf..30bda01 100644 --- a/dist/jquery.floatThead.js +++ b/dist/jquery.floatThead.js @@ -1,4 +1,4 @@ -// @preserve jQuery.floatThead 1.2.4 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak +// @preserve jQuery.floatThead 1.2.5 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak // @license Licensed under http://creativecommons.org/licenses/by-sa/4.0/ /* @author Misha Koryak @@ -66,7 +66,19 @@ */ function windowResize(debounceMs, cb){ - $window.bind('resize.floatTHead', util.debounce(cb, debounceMs)); //TODO: check if resize bug is gone in IE8 + + if(ieVersion == 8){ //ie8 is crap: https://github.com/mkoryak/floatThead/issues/65 + var winWidth = $window.width(); + var debouncedCb = util.debounce(function(){ + var winWidthNew = $window.width(); + if(winWidth != winWidthNew){ + winWidth = winWidthNew; + cb(); + } + }, debounceMs); + $window.bind('resize.floatTHead', debouncedCb); + } else { + $window.bind('resize.floatTHead', util.debounce(cb, debounceMs)); + } } @@ -144,7 +156,7 @@ } var opts = $.extend({}, $.floatThead.defaults || {}, map); - $.each(map, function(val, key){ + $.each(map, function(key, val){ if((!(key in $.floatThead.defaults)) && opts.debug){ debug("jQuery.floatThead: used ["+key+"] key to init plugin, but that param is not an option for the plugin. Valid options are: "+ (util.keys($.floatThead.defaults)).join(', ')); } @@ -256,7 +268,10 @@ var originalTableWidth = $table[0].style.width || "auto"; function setHeaderHeight(){ - var headerHeight = $header.find(opts.cellTag).outerHeight(true); + var headerHeight = 0; + $header.find("tr").each(function(){ + headerHeight += $(this).outerHeight(true); + }); $sizerRow.outerHeight(headerHeight); $sizerCells.outerHeight(headerHeight); } diff --git a/dist/jquery.floatThead.min.js b/dist/jquery.floatThead.min.js index 42abe3b..0833b50 100644 --- a/dist/jquery.floatThead.min.js +++ b/dist/jquery.floatThead.min.js @@ -1,3 +1,3 @@ -// @preserve jQuery.floatThead 1.2.4 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak +// @preserve jQuery.floatThead 1.2.5 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak // @license Licensed under http://creativecommons.org/licenses/by-sa/4.0/ -!function(a){function b(a,b){j.bind("resize.floatTHead",f.debounce(b,a))}function c(a){window.console&&window.console&&window.console.log&&window.console.log(a)}function d(){var b=a('
');a("body").append(b);var c=b.innerWidth(),d=a("div",b).innerWidth();return b.remove(),c-d}function e(a){if(a.dataTableSettings)for(var b=0;btd")},floatTableClass:"floatThead-table",floatWrapperClass:"floatThead-wrapper",floatContainerClass:"floatThead-container",copyTableClass:!0,debug:!1};var f=window._,g=function(){for(var a=3,b=document.createElement("b"),c=b.all||[];a=1+a,b.innerHTML="",c[0];);return a>4?a:document.documentMode}(),h=null,i=function(){if(g)return!1;var b=a("
");a("body").append(b);var c=b.find("col").width();return b.remove(),0==c},j=a(window),k=0;a.fn.floatThead=function(l){if(l=l||{},!f&&(f=window._||a.floatThead._,!f))throw new Error("jquery.floatThead-slim.js requires underscore. You should use the non-lite version since you do not have underscore.");if(8>g)return this;if(null==h&&(h=i(),h&&(document.createElement("fthtr"),document.createElement("fthtd"),document.createElement("fthfoot"))),f.isString(l)){var m=l,n=this;return this.filter("table").each(function(){var b=a(this).data("floatThead-attached");if(b&&f.isFunction(b[m])){var c=b[m]();"undefined"!=typeof c&&(n=c)}}),n}var o=a.extend({},a.floatThead.defaults||{},l);return a.each(l,function(b,d){d in a.floatThead.defaults||!o.debug||c("jQuery.floatThead: used ["+d+"] key to init plugin, but that param is not an option for the plugin. Valid options are: "+f.keys(a.floatThead.defaults).join(", "))}),this.filter(":not(."+o.floatTableClass+")").each(function(){function c(){var a=x.find(o.cellTag).outerHeight(!0);V.outerHeight(a),W.outerHeight(a)}function i(){var a=w.outerWidth(),b=F.width()||a;if(T.width(b-C.vertical),L){var c=100*a/(b-C.vertical);P.css("width",c+"%")}else P.outerWidth(a)}function l(){z=(f.isFunction(o.scrollingTop)?o.scrollingTop(w):o.scrollingTop)||0,A=(f.isFunction(o.scrollingBottom)?o.scrollingBottom(w):o.scrollingBottom)||0}function m(){var b=x.find("tr:first>"+o.cellTag),c=0;if(b.each(function(){c+=parseInt(a(this).attr("colspan")||1,10)}),c!=E){E=c;for(var d=[],e=[],f=[],g=0;c>g;g++)d.push(''),e.push(""),f.push("");e=e.join(""),d=d.join(""),h&&(f=f.join(""),S.html(f),Z=S.find("fthtd")),V.html(d),W=V.find("th"),R.html(e),X=R.find("col"),Q.html(e),Y=Q.find("col")}return c}function n(){if(!B){if(B=!0,G){var a=w.width(),b=N.width();a>b&&w.css("minWidth",a)}w.css(_),P.css(_),P.append(x),y.before(U),c()}}function p(){B&&(B=!1,G&&w.width(bb),U.detach(),w.prepend(x),w.css(ab),P.css(ab))}function q(a){G!=a&&(G=a,T.css({position:G?"absolute":"fixed"}))}function r(a,b,c,d){return h?c:d?o.getSizingRow(a,b,c):b}function s(){var a,b=m();return function(){var d=r(w,X,Z,g);if(d.length==b&&b>0){for(p(),a=0;b>a;a++){var e=d.get(a),f=e.offsetWidth;Y.eq(a).width(f),X.eq(a).width(f)}n()}else P.append(x),w.css(ab),P.css(ab),c()}}function t(){var a,b=F.scrollTop(),c=0,d=I?H.outerHeight(!0):0,e=J?d:-d,f=T.height(),g=w.offset();if(L){var i=F.offset();c=g.top-i.top+b,I&&J&&(c+=d)}else a=g.top-z-f+A+C.horizontal;var k=j.scrollTop(),l=j.scrollLeft(),m=F.scrollLeft();return b=F.scrollTop(),function(i){if("windowScroll"==i?(k=j.scrollTop(),l=j.scrollLeft()):"containerScroll"==i?(b=F.scrollTop(),m=F.scrollLeft()):"init"!=i&&(k=j.scrollTop(),l=j.scrollLeft(),b=F.scrollTop(),m=F.scrollLeft()),!h||!(0>k||0>l)){if(O)"windowScrollDone"==i?q(!0):q(!1);else if("windowScrollDone"==i)return null;g=w.offset(),I&&J&&(g.top+=d);var o,r,s;if(L&&G){if(c>=b){var t=c-b;t=t>0?t:0,o=t}else o=M?0:b;r=0}else!L&&G?(s=w.outerHeight(),k>a+s+e?o=s-f+e:g.top>k+z?(o=0,p()):(o=z+k-g.top+c+(J?d:0),n()),r=0):L&&!G?(c>b?(o=g.top-k,p()):(o=g.top+b-k-c,n()),r=g.left+m-l):L||G||(s=w.outerHeight(),k>a+s+e?o=s+z-k+a+e:g.top>k+z?(o=g.top-k,n()):o=z,r=g.left-l);return{top:o,left:r}}}}function u(){var a=null,b=null,d=null;return function(e,f,g){null==e||a==e.top&&b==e.left||(T.css({top:e.top,left:e.left}),a=e.top,b=e.left),f&&i(),g&&c();var h=F.scrollLeft();d!=h&&(T.scrollLeft(h),d=h)}}function v(){F.length&&(C.horizontal=F.width() element");var z,A,B=!1,C={vertical:0,horizontal:0},D=d(),E=0,F=o.scrollContainer(w)||a([]),G=o.useAbsolutePositioning;null==G&&(G=o.scrollContainer(w).length);var H=w.find("caption"),I=1==H.length;if(I)var J="top"===(H.css("caption-side")||H.attr("align")||"top");var K=a(''),L=F.length>0,M=!1,N=a([]),O=9>=g&&!L&&G,P=a(""),Q=a(""),R=a(""),S=a(''),T=a('
'),U=a("
"),V=a(''),W=a([]),X=a([]),Y=a([]),Z=a([]);if(U.append(V),w.prepend(R),h&&(K.append(S),w.append(K)),P.append(Q),T.append(P),o.copyTableClass&&P.attr("class",w.attr("class")),P.attr({cellpadding:w.attr("cellpadding"),cellspacing:w.attr("cellspacing"),border:w.attr("border")}),P.addClass(o.floatTableClass).css("margin",0),G){var $=function(a,b){var c=a.css("position"),d="relative"==c||"absolute"==c;if(!d||b){var e={paddingLeft:a.css("paddingLeft"),paddingRight:a.css("paddingRight")};T.css(e),a=a.wrap("
").parent(),M=!0}return a};L?(N=$(F,!0),N.append(T)):(N=$(w),w.after(T))}else w.after(T);T.css({position:G?"absolute":"fixed",marginTop:0,top:G?0:"auto",zIndex:o.zIndex}),T.addClass(o.floatContainerClass),l();var _={"table-layout":"fixed"},ab={"table-layout":w.css("tableLayout")||"auto"},bb=w[0].style.width||"auto";v();var cb,db=function(){(cb=s())()};db();var eb=t(),fb=u();fb(eb("init"),!0);var gb=f.debounce(function(){fb(eb("windowScrollDone"),!1)},300),hb=function(){fb(eb("windowScroll"),!1),gb()},ib=function(){fb(eb("containerScroll"),!1)},jb=function(){l(),v(),db(),eb=t(),(fb=u())(eb("resize"),!0,!0)},kb=f.debounce(function(){v(),l(),db(),eb=t(),fb(eb("reflow"),!0)},1);L?G?F.bind("scroll.floatTHead",ib):(F.bind("scroll.floatTHead",ib),j.bind("scroll.floatTHead",hb)):j.bind("scroll.floatTHead",hb),j.bind("load.floatTHead",kb),b(o.debounceResizeMs,jb),w.bind("reflow",kb),e(w)&&w.bind("filter",kb).bind("sort",kb).bind("page",kb),w.data("floatThead-attached",{destroy:function(){p(),w.css(ab),R.remove(),h&&K.remove(),U.parent().length&&U.replaceWith(x),w.unbind("reflow"),kb=jb=ib=hb=function(){},F.unbind("scroll.floatTHead"),T.remove(),w.data("floatThead-attached",!1),k--,0==k&&(j.unbind("scroll.floatTHead"),j.unbind("resize.floatTHead"),j.unbind("load.floatTHead"))},reflow:function(){kb()},setHeaderHeight:function(){c()},getFloatContainer:function(){return T},getRowGroups:function(){return B?T.find("thead").add(w.find("tbody,tfoot")):w.find("thead,tbody,tfoot")}}),k++}),this}}(jQuery),function(){$.floatThead=$.floatThead||{},$.floatThead._=window._||function(){var a={},b=Object.prototype.hasOwnProperty,c=["Arguments","Function","String","Number","Date","RegExp"];return a.has=function(a,c){return b.call(a,c)},a.keys=function(b){if(b!==Object(b))throw new TypeError("Invalid object");var c=[];for(var d in b)a.has(b,d)&&c.push(d);return c},$.each(c,function(){var b=this;a["is"+b]=function(a){return Object.prototype.toString.call(a)=="[object "+b+"]"}}),a.debounce=function(a,b,c){var d,e,f,g,h;return function(){f=this,e=arguments,g=new Date;var i=function(){var j=new Date-g;b>j?d=setTimeout(i,b-j):(d=null,c||(h=a.apply(f,e)))},j=c&&!d;return d||(d=setTimeout(i,b)),j&&(h=a.apply(f,e)),h}},a}()}(); \ No newline at end of file +!function(a){function b(a,b){if(8==g){var c=j.width(),d=f.debounce(function(){var a=j.width();c!=a&&(c=a,b())},a);j.bind("resize.floatTHead",d)}else j.bind("resize.floatTHead",f.debounce(b,a))}function c(a){window.console&&window.console&&window.console.log&&window.console.log(a)}function d(){var b=a('
');a("body").append(b);var c=b.innerWidth(),d=a("div",b).innerWidth();return b.remove(),c-d}function e(a){if(a.dataTableSettings)for(var b=0;btd")},floatTableClass:"floatThead-table",floatWrapperClass:"floatThead-wrapper",floatContainerClass:"floatThead-container",copyTableClass:!0,debug:!1};var f=window._,g=function(){for(var a=3,b=document.createElement("b"),c=b.all||[];a=1+a,b.innerHTML="",c[0];);return a>4?a:document.documentMode}(),h=null,i=function(){if(g)return!1;var b=a("
");a("body").append(b);var c=b.find("col").width();return b.remove(),0==c},j=a(window),k=0;a.fn.floatThead=function(l){if(l=l||{},!f&&(f=window._||a.floatThead._,!f))throw new Error("jquery.floatThead-slim.js requires underscore. You should use the non-lite version since you do not have underscore.");if(8>g)return this;if(null==h&&(h=i(),h&&(document.createElement("fthtr"),document.createElement("fthtd"),document.createElement("fthfoot"))),f.isString(l)){var m=l,n=this;return this.filter("table").each(function(){var b=a(this).data("floatThead-attached");if(b&&f.isFunction(b[m])){var c=b[m]();"undefined"!=typeof c&&(n=c)}}),n}var o=a.extend({},a.floatThead.defaults||{},l);return a.each(l,function(b){b in a.floatThead.defaults||!o.debug||c("jQuery.floatThead: used ["+b+"] key to init plugin, but that param is not an option for the plugin. Valid options are: "+f.keys(a.floatThead.defaults).join(", "))}),this.filter(":not(."+o.floatTableClass+")").each(function(){function c(){var b=0;x.find("tr").each(function(){b+=a(this).outerHeight(!0)}),V.outerHeight(b),W.outerHeight(b)}function i(){var a=w.outerWidth(),b=F.width()||a;if(T.width(b-C.vertical),L){var c=100*a/(b-C.vertical);P.css("width",c+"%")}else P.outerWidth(a)}function l(){z=(f.isFunction(o.scrollingTop)?o.scrollingTop(w):o.scrollingTop)||0,A=(f.isFunction(o.scrollingBottom)?o.scrollingBottom(w):o.scrollingBottom)||0}function m(){var b=x.find("tr:first>"+o.cellTag),c=0;if(b.each(function(){c+=parseInt(a(this).attr("colspan")||1,10)}),c!=E){E=c;for(var d=[],e=[],f=[],g=0;c>g;g++)d.push(''),e.push(""),f.push("");e=e.join(""),d=d.join(""),h&&(f=f.join(""),S.html(f),Z=S.find("fthtd")),V.html(d),W=V.find("th"),R.html(e),X=R.find("col"),Q.html(e),Y=Q.find("col")}return c}function n(){if(!B){if(B=!0,G){var a=w.width(),b=N.width();a>b&&w.css("minWidth",a)}w.css(_),P.css(_),P.append(x),y.before(U),c()}}function p(){B&&(B=!1,G&&w.width(bb),U.detach(),w.prepend(x),w.css(ab),P.css(ab))}function q(a){G!=a&&(G=a,T.css({position:G?"absolute":"fixed"}))}function r(a,b,c,d){return h?c:d?o.getSizingRow(a,b,c):b}function s(){var a,b=m();return function(){var d=r(w,X,Z,g);if(d.length==b&&b>0){for(p(),a=0;b>a;a++){var e=d.get(a),f=e.offsetWidth;Y.eq(a).width(f),X.eq(a).width(f)}n()}else P.append(x),w.css(ab),P.css(ab),c()}}function t(){var a,b=F.scrollTop(),c=0,d=I?H.outerHeight(!0):0,e=J?d:-d,f=T.height(),g=w.offset();if(L){var i=F.offset();c=g.top-i.top+b,I&&J&&(c+=d)}else a=g.top-z-f+A+C.horizontal;var k=j.scrollTop(),l=j.scrollLeft(),m=F.scrollLeft();return b=F.scrollTop(),function(i){if("windowScroll"==i?(k=j.scrollTop(),l=j.scrollLeft()):"containerScroll"==i?(b=F.scrollTop(),m=F.scrollLeft()):"init"!=i&&(k=j.scrollTop(),l=j.scrollLeft(),b=F.scrollTop(),m=F.scrollLeft()),!h||!(0>k||0>l)){if(O)"windowScrollDone"==i?q(!0):q(!1);else if("windowScrollDone"==i)return null;g=w.offset(),I&&J&&(g.top+=d);var o,r,s;if(L&&G){if(c>=b){var t=c-b;t=t>0?t:0,o=t}else o=M?0:b;r=0}else!L&&G?(s=w.outerHeight(),k>a+s+e?o=s-f+e:g.top>k+z?(o=0,p()):(o=z+k-g.top+c+(J?d:0),n()),r=0):L&&!G?(c>b?(o=g.top-k,p()):(o=g.top+b-k-c,n()),r=g.left+m-l):L||G||(s=w.outerHeight(),k>a+s+e?o=s+z-k+a+e:g.top>k+z?(o=g.top-k,n()):o=z,r=g.left-l);return{top:o,left:r}}}}function u(){var a=null,b=null,d=null;return function(e,f,g){null==e||a==e.top&&b==e.left||(T.css({top:e.top,left:e.left}),a=e.top,b=e.left),f&&i(),g&&c();var h=F.scrollLeft();d!=h&&(T.scrollLeft(h),d=h)}}function v(){F.length&&(C.horizontal=F.width() element");var z,A,B=!1,C={vertical:0,horizontal:0},D=d(),E=0,F=o.scrollContainer(w)||a([]),G=o.useAbsolutePositioning;null==G&&(G=o.scrollContainer(w).length);var H=w.find("caption"),I=1==H.length;if(I)var J="top"===(H.css("caption-side")||H.attr("align")||"top");var K=a(''),L=F.length>0,M=!1,N=a([]),O=9>=g&&!L&&G,P=a(""),Q=a(""),R=a(""),S=a(''),T=a('
'),U=a("
"),V=a(''),W=a([]),X=a([]),Y=a([]),Z=a([]);if(U.append(V),w.prepend(R),h&&(K.append(S),w.append(K)),P.append(Q),T.append(P),o.copyTableClass&&P.attr("class",w.attr("class")),P.attr({cellpadding:w.attr("cellpadding"),cellspacing:w.attr("cellspacing"),border:w.attr("border")}),P.addClass(o.floatTableClass).css("margin",0),G){var $=function(a,b){var c=a.css("position"),d="relative"==c||"absolute"==c;if(!d||b){var e={paddingLeft:a.css("paddingLeft"),paddingRight:a.css("paddingRight")};T.css(e),a=a.wrap("
").parent(),M=!0}return a};L?(N=$(F,!0),N.append(T)):(N=$(w),w.after(T))}else w.after(T);T.css({position:G?"absolute":"fixed",marginTop:0,top:G?0:"auto",zIndex:o.zIndex}),T.addClass(o.floatContainerClass),l();var _={"table-layout":"fixed"},ab={"table-layout":w.css("tableLayout")||"auto"},bb=w[0].style.width||"auto";v();var cb,db=function(){(cb=s())()};db();var eb=t(),fb=u();fb(eb("init"),!0);var gb=f.debounce(function(){fb(eb("windowScrollDone"),!1)},300),hb=function(){fb(eb("windowScroll"),!1),gb()},ib=function(){fb(eb("containerScroll"),!1)},jb=function(){l(),v(),db(),eb=t(),(fb=u())(eb("resize"),!0,!0)},kb=f.debounce(function(){v(),l(),db(),eb=t(),fb(eb("reflow"),!0)},1);L?G?F.bind("scroll.floatTHead",ib):(F.bind("scroll.floatTHead",ib),j.bind("scroll.floatTHead",hb)):j.bind("scroll.floatTHead",hb),j.bind("load.floatTHead",kb),b(o.debounceResizeMs,jb),w.bind("reflow",kb),e(w)&&w.bind("filter",kb).bind("sort",kb).bind("page",kb),w.data("floatThead-attached",{destroy:function(){p(),w.css(ab),R.remove(),h&&K.remove(),U.parent().length&&U.replaceWith(x),w.unbind("reflow"),kb=jb=ib=hb=function(){},F.unbind("scroll.floatTHead"),T.remove(),w.data("floatThead-attached",!1),k--,0==k&&(j.unbind("scroll.floatTHead"),j.unbind("resize.floatTHead"),j.unbind("load.floatTHead"))},reflow:function(){kb()},setHeaderHeight:function(){c()},getFloatContainer:function(){return T},getRowGroups:function(){return B?T.find("thead").add(w.find("tbody,tfoot")):w.find("thead,tbody,tfoot")}}),k++}),this}}(jQuery),function(){$.floatThead=$.floatThead||{},$.floatThead._=window._||function(){var a={},b=Object.prototype.hasOwnProperty,c=["Arguments","Function","String","Number","Date","RegExp"];return a.has=function(a,c){return b.call(a,c)},a.keys=function(b){if(b!==Object(b))throw new TypeError("Invalid object");var c=[];for(var d in b)a.has(b,d)&&c.push(d);return c},$.each(c,function(){var b=this;a["is"+b]=function(a){return Object.prototype.toString.call(a)=="[object "+b+"]"}}),a.debounce=function(a,b,c){var d,e,f,g,h;return function(){f=this,e=arguments,g=new Date;var i=function(){var j=new Date-g;b>j?d=setTimeout(i,b-j):(d=null,c||(h=a.apply(f,e)))},j=c&&!d;return d||(d=setTimeout(i,b)),j&&(h=a.apply(f,e)),h}},a}()}(); \ No newline at end of file diff --git a/jquery.floatThead.js b/jquery.floatThead.js index d7b4677..c0d1e25 100644 --- a/jquery.floatThead.js +++ b/jquery.floatThead.js @@ -1,4 +1,4 @@ -// @preserve jQuery.floatThead 1.2.4 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak +// @preserve jQuery.floatThead 1.2.5 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak // @license Licensed under http://creativecommons.org/licenses/by-sa/4.0/ /* @author Misha Koryak @@ -66,7 +66,19 @@ */ function windowResize(debounceMs, cb){ - $window.bind('resize.floatTHead', util.debounce(cb, debounceMs)); //TODO: check if resize bug is gone in IE8 + + if(ieVersion == 8){ //ie8 is crap: https://github.com/mkoryak/floatThead/issues/65 + var winWidth = $window.width(); + var debouncedCb = util.debounce(function(){ + var winWidthNew = $window.width(); + if(winWidth != winWidthNew){ + winWidth = winWidthNew; + cb(); + } + }, debounceMs); + $window.bind('resize.floatTHead', debouncedCb); + } else { + $window.bind('resize.floatTHead', util.debounce(cb, debounceMs)); + } } @@ -144,7 +156,7 @@ } var opts = $.extend({}, $.floatThead.defaults || {}, map); - $.each(map, function(val, key){ + $.each(map, function(key, val){ if((!(key in $.floatThead.defaults)) && opts.debug){ debug("jQuery.floatThead: used ["+key+"] key to init plugin, but that param is not an option for the plugin. Valid options are: "+ (util.keys($.floatThead.defaults)).join(', ')); } @@ -256,7 +268,10 @@ var originalTableWidth = $table[0].style.width || "auto"; function setHeaderHeight(){ - var headerHeight = $header.find(opts.cellTag).outerHeight(true); + var headerHeight = 0; + $header.find("tr").each(function(){ + headerHeight += $(this).outerHeight(true); + }); $sizerRow.outerHeight(headerHeight); $sizerCells.outerHeight(headerHeight); } diff --git a/package.json b/package.json index 30c12e4..a94190e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "floatthead", - "version": "1.2.4", + "version": "1.2.5", "description": "locking table headers without special css", "filename": "jquery.floatThead.js", "dependencies": {}, From 6d3bcd13156a867047a10255125d4ce0c60ca62b Mon Sep 17 00:00:00 2001 From: Misha Koryak Date: Mon, 24 Mar 2014 12:36:34 -0400 Subject: [PATCH 2/2] update readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02b05ac..7525181 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -jquery.floatThead v1.2.4 +jquery.floatThead v1.2.5 ================= Float the table header without special css. This plugin assumes nothing about your table markup and "just works" without losing your events or styles. Supports floating the header while scrolling within the window or while scrolling within a container with overflow. @@ -80,6 +80,11 @@ Watch for it. Change Log ---------- +### 1.2.5 +- bug fixes: +- https://github.com/mkoryak/floatThead/issues/66 +- https://github.com/mkoryak/floatThead/issues/65 +- https://github.com/mkoryak/floatThead/issues/62 ### 1.2.4 - better support for really really wide tables