From 9e345fb7dd64b06402d063b97182bf0d677fe497 Mon Sep 17 00:00:00 2001 From: Nick Cappadona Date: Fri, 23 Feb 2018 07:50:48 -0500 Subject: [PATCH] Replace .load() with .on() for jQuery 3.x A breaking change in jQuery 3.0 is the removal of `.load()` [1]. Replace with `.on('load', fn)` as recommended. [1] https://jquery.com/upgrade-guide/3.0/#breaking-change-load-unload-and-error-removed --- jquery.stickysort.js | 12 ++++++------ jquery.stickysort.min.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jquery.stickysort.js b/jquery.stickysort.js index 68296a6..687eec2 100644 --- a/jquery.stickysort.js +++ b/jquery.stickysort.js @@ -56,7 +56,7 @@ .find('tbody td').remove(); $stickyInsct.find('table').html(''+$t.find('thead th:first-child').html()+''); - + // Set widths var setWidths = function () { $t @@ -85,7 +85,7 @@ repositionSticky = function () { // Return value of calculated allowance var allowance = calcAllowance(); - + // 1. Deal with positioning of sticky header // Check if wrapper parent is overflowing along the y-axis if($t.height() > $stickyWrap.height()) { @@ -177,10 +177,10 @@ rowHeight += $(this).height(); }); allowance.push(rowHeight); - + // Get height based on viewport allowance.push($w.height()*settings.threshold.viewport) - + // If pixel threshold exists, add it if(settings.threshold.px) { allowance.push(settings.threshold.px); @@ -199,7 +199,7 @@ $t.parent('.sticky-wrap').scroll($.throttle(settings.scrollThrottle, repositionSticky)); $w - .load(setWidths) + .on('load', setWidths) .resize($.debounce(settings.resizeThrottle, function () { setWidths(); repositionSticky(); @@ -325,4 +325,4 @@ // Return to allow chaining return this; }; -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/jquery.stickysort.min.js b/jquery.stickysort.min.js index 904a781..47ec043 100644 --- a/jquery.stickysort.min.js +++ b/jquery.stickysort.min.js @@ -1 +1 @@ -(function(a){a.fn.stickySort=function(c){var b=a.extend(true,{threshold:{rows:3,viewport:0.25,px:false,allowanceEval:"min"},sortable:false,scrollThrottle:15,resizeThrottle:250},c);this.each(function(){if(a(this).is("table")&&a(this).find("thead").length>0&&a(this).find("th").length>0){var f=a(window),i=a(this),j=i.find("thead").clone(),m=i.find("thead, tbody").clone();i.wrap('
').parent().addClass(i.attr("class")).end().addClass("sticky-enabled");if(i.hasClass("overflow-y")){i.removeClass("overflow-y").parent().addClass("overflow-y")}i.after('
');if(i.find("tbody th").length>0){i.after('
')}var g=a(this).siblings(".sticky-thead"),h=a(this).siblings(".sticky-col"),n=a(this).siblings(".sticky-intersect"),k=a(this).parent(".sticky-wrap");g.find("table").append(j);h.find("table").append(m).find("thead th:gt(0)").remove().end().find("tbody td").remove();n.html("");var e=function(){i.find("thead th").each(function(o){g.find("th").eq(o).width(a(this).width())}).end().find("tr").each(function(o){h.find("tr").eq(o).height(a(this).height())});g.width(k.width()).find("table").width(i.width());h.find("th").add(n.find("th")).width(i.find("thead th").width());h.find("table").css({left:k.offset().left})},d=function(){var o=l();if(i.height()>k.height()){if(k.scrollTop()>0){g.add(n).css({opacity:1,"pointer-events":"auto",position:"fixed",top:k.offset().top-f.scrollTop(),left:k.offset().left}).find("table").css({left:-k.scrollLeft()})}else{g.add(n).css({opacity:0,"pointer-events":"none"})}}else{if(f.scrollTop()>i.offset().top&&f.scrollTop()0){h.css({position:"fixed",left:k.offset().left,top:k.offset().top-f.scrollTop(),height:k.height()}).find("table").css({top:-k.scrollTop(),left:0}).end().add(n).css({opacity:1,"pointer-events":"auto"})}else{h.css({opacity:0,"pointer-events":"none"})}},l=function(){var p=0,o=[];i.find("tbody tr:lt("+b.threshold.rows+")").each(function(){p+=a(this).height()});o.push(p);o.push(f.height()*b.threshold.viewport);if(b.threshold.px){o.push(b.threshold.px)}if(b.threshold.allowanceEval=="min"){return Math.min.apply(null,o)}else{return Math.max.apply(null,o)}};e();i.parent(".sticky-wrap").scroll(a.throttle(b.scrollThrottle,d));f.load(e).resize(a.debounce(b.resizeThrottle,function(){e();d()})).scroll(a.throttle(b.scrollThrottle,d));if(b.sortable||(i.data("sortable")!=undefined||i.hasClass("sortable"))){i.find("tbody tr").each(function(o){a(this).attr("data-sortOrder",o)});k.addClass("sortable").find("thead th").addClass("sort-default").data("sortState",1).append('').find(".sort-handle").click(function(o){o.preventDefault()});k.on("click",".sticky-enabled thead th, .sticky-thead thead th, .sticky-col thead th, .sticky-intersect thead th",function(){var q=a(this),p=q.index(),r=k.find("thead th").eq(p),o=a.makeArray(i.find("tbody tr"));if(q.data("sortState")%3==0){o.sort(function(u,t){return parseInt(a(u).attr("data-sortOrder"))-parseInt(a(t).attr("data-sortOrder"))});q.add(r).removeClass().addClass("sort-default")}else{o.sort(function(u,t){var v=A(a(u).children().eq(p).text()),y=A(a(t).children().eq(p).text());function A(F){var I=[],C=0,H=-1,G=0,E,D;while(E=(D=F.charAt(C++)).charCodeAt(0)){var B=(E==46||(E>=48&&E<=57));if(B!==G){I[++H]="";G=B}I[H]+=D}return I}for(x=0;v[x]&&y[x];x++){if(v[x]!==y[x]){var z=Number(v[x]),w=Number(y[x]);if(z==v[x]&&w==y[x]){return z-w}else{return(v[x]>y[x])?1:-1}}}return v.length-y.length});if(q.data("sortState")%3==2){o=o.reverse();q.add(r).removeClass().addClass("sort-desc")}else{q.add(r).removeClass().addClass("sort-asc")}}var s=q.data("sortState")+1;q.add(r).data("sortState",s%3);k.find("table").each(function(t){a(this).find("thead th").not(":eq("+p+")").data("sortState",1).removeClass().addClass("sort-default")});i.find("tbody").html(o);i.find("tbody tr").each(function(t){h.find("tbody tr").eq(t).find("th").html(a(this).find("th").first().html())})})}}});return this}})(jQuery); \ No newline at end of file +!function(t){t.fn.stickySort=function(e){var s=t.extend(!0,{threshold:{rows:3,viewport:.25,px:!1,allowanceEval:"min"},sortable:!1,scrollThrottle:15,resizeThrottle:250},e);return this.each(function(){if(t(this).is("table")&&t(this).find("thead").length>0&&t(this).find("th").length>0){var e=t(window),a=t(this),i=a.find("thead").clone(),d=a.find("thead, tbody").clone();a.wrap('
').parent().addClass(a.attr("class")).end().addClass("sticky-enabled"),a.hasClass("overflow-y")&&a.removeClass("overflow-y").parent().addClass("overflow-y"),a.after('
"+i.find("thead th:first-child").html()+"
'),a.find("tbody th").length>0&&a.after('
');var o=t(this).siblings(".sticky-thead"),n=t(this).siblings(".sticky-col"),r=t(this).siblings(".sticky-intersect"),l=t(this).parent(".sticky-wrap");o.find("table").append(i),n.find("table").append(d).find("thead th:gt(0)").remove().end().find("tbody td").remove(),r.find("table").html("");var h=function(){a.find("thead th").each(function(e){o.find("th").eq(e).width(t(this).width())}).end().find("tr").each(function(e){n.find("tr").eq(e).height(t(this).height())}),o.width(l.width()).find("table").width(a.width()),n.find("th").add(r.find("th")).width(a.find("thead th").first().width()),n.find("table").css({left:l.offset().left})},f=function(){var t=c();a.height()>l.height()?l.scrollTop()>0?(o.add(r).css({opacity:1,"pointer-events":"auto",position:"fixed",top:l.offset().top-e.scrollTop(),left:l.offset().left}),o.find("table").css({left:-l.scrollLeft()})):(o.add(r).css({opacity:0,"pointer-events":"none"}),r.css({position:"absolute",top:0,left:0})):e.scrollTop()>a.offset().top&&e.scrollTop()0?n.css({position:"fixed",left:l.offset().left,top:l.offset().top-e.scrollTop(),height:l.height()}).find("table").css({top:-l.scrollTop(),left:0}).end().add(r).css({opacity:1,"pointer-events":"auto"}):n.css({opacity:0,"pointer-events":"none"})},c=function(){var i=0,d=[];return a.find("tbody tr:lt("+s.threshold.rows+")").each(function(){i+=t(this).height()}),d.push(i),d.push(e.height()*s.threshold.viewport),s.threshold.px&&d.push(s.threshold.px),"min"==s.threshold.allowanceEval?Math.min.apply(null,d):Math.max.apply(null,d)};h(),a.parent(".sticky-wrap").scroll(t.throttle(s.scrollThrottle,f)),e.on("load",h).resize(t.debounce(s.resizeThrottle,function(){h(),f()})).scroll(t.throttle(s.scrollThrottle,f)),(s.sortable||null!=a.data("sortable")||a.hasClass("sortable"))&&(a.find("tbody tr").each(function(e){t(this).attr("data-sortOrder",e)}),l.addClass("sortable").find("thead th").addClass("sort-default").data("sortState",1).wrapInner("
").find("div").css({position:"relative"}).append('').find(".sort-handle").click(function(t){t.preventDefault()}),l.on("click",".sticky-enabled thead th, .sticky-thead thead th, .sticky-col thead th, .sticky-intersect thead th",function(){var e=t(this),s=e.index(),i=l.find("thead th").eq(s),d=t.makeArray(a.find("tbody tr"));e.data("sortState")%3==0?(d.sort(function(e,s){return parseInt(t(e).attr("data-sortOrder"))-parseInt(t(s).attr("data-sortOrder"))}),e.add(i).removeClass().addClass("sort-default")):(d.sort(function(e,a){var i=o(t(e).children().eq(s).text()),d=o(t(a).children().eq(s).text());function o(t){for(var e,s,a=[],i=0,d=-1,o=0;e=(s=t.charAt(i++)).charCodeAt(0);){var n=46==e||e>=48&&e<=57;n!==o&&(a[++d]="",o=n),a[d]+=s}return a}for(x=0;i[x]&&d[x];x++)if(i[x]!==d[x]){var n=Number(i[x]),r=Number(d[x]);return n==i[x]&&r==d[x]?n-r:i[x]>d[x]?1:-1}return i.length-d.length}),e.data("sortState")%3==2?(d=d.reverse(),e.add(i).removeClass().addClass("sort-desc")):e.add(i).removeClass().addClass("sort-asc"));var o=e.data("sortState")+1;e.add(i).data("sortState",o%3),l.find("table").each(function(e){t(this).find("thead th").not(":eq("+s+")").data("sortState",1).removeClass().addClass("sort-default")}),a.find("tbody").html(d),a.find("tbody tr").each(function(e){n.find("tbody tr").eq(e).find("th").html(t(this).find("th").first().html())})}))}}),this}}(jQuery); \ No newline at end of file
"+a.find("thead th:first-child").html()+"