-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.tablecheckbox.min.js
1 lines (1 loc) · 2.04 KB
/
jquery.tablecheckbox.min.js
1
!function(e){e.fn.tablecheckbox=function(t){var c={config:e.extend({selectedRowClass:"warning",checkboxSelector:'td:first-of-type input[type="checkbox"],th:first-of-type input[type="checkbox"]',isChecked:function(e){return e.is(":checked")}},t),registry:{shiftKeyIsPressed:!1},helpers:{selection:window.getSelection?window.getSelection():document.selection?document.selection:null,removeTextSelection:function(){c.helpers.selection&&(c.helpers.selection.empty?c.helpers.selection.empty():c.helpers.selection.removeAllRanges())},hasSelection:function(){return!!c.helpers.selection&&c.helpers.selection.toString().length}}};return e(document).on("keydown.tsc keyup.tsc",function(e){c.registry.shiftKeyIsPressed=e.shiftKey}),this.each(function(){var t=e(this),n=t.find("thead tr "+c.config.checkboxSelector),o=t.find("tr "+c.config.checkboxSelector).not(n),i=[];n.on("change",function(e){var i=t.find("tbody tr");o.prop("checked",c.config.isChecked(n)).trigger("change"),t.trigger(c.config.isChecked(n)?"multirowselect":"multirowdeselect",{$rows:i,$checkboxes:i.find(c.config.checkboxSelector),rowCount:i.length})}),o.each(function(){var n,o,r=e(this),s=r.parents("tr");r.on("change",function(e,l){c.helpers.removeTextSelection(),!l&&c.registry.shiftKeyIsPressed&&i.length&&(n=i.index()<s.index()?s.prevUntil(i):s.nextUntil(i),n.find(c.config.checkboxSelector).prop("checked",c.config.isChecked(r)).trigger("change",[!0]),o=n.add(s,i),t.trigger(c.config.isChecked(r)?"multirowselect":"multirowdeselect",{$rows:o,$checkboxes:o.find(c.config.checkboxSelector),rowCount:o.length})),i=s,s.toggleClass(c.config.selectedRowClass,c.config.isChecked(r)),s.trigger(c.config.isChecked(r)?"rowselect":"rowdeselect",{$row:s,$checkbox:r})}),s.on("click",function(t){c.helpers.hasSelection()||(e.data(s,"tc-timeout")&&window.clearTimeout(e.data(s,"tc-timeout")),e.data(s,"tc-timeout",window.setTimeout(function(){c.helpers.hasSelection()||e(t.target).is("a,input,button")||e(t.target).parents("a,input,button").length||r.prop("checked",!c.config.isChecked(r)).trigger("change")},50)))})})})}}(jQuery);