diff --git a/jquery.tree-multiselect.min.css b/jquery.tree-multiselect.min.css index 2df76e7..73b0c81 100644 --- a/jquery.tree-multiselect.min.css +++ b/jquery.tree-multiselect.min.css @@ -1,2 +1,2 @@ -/* jQuery Tree Multiselect v1.12.1 | (c) Patrick Tsai | MIT Licensed */ +/* jQuery Tree Multiselect v1.12.2 | (c) Patrick Tsai | MIT Licensed */ div.tree-multiselect div.title:hover,div.tree-multiselect input[type=checkbox]:hover{cursor:pointer}div.tree-multiselect{border:2px solid #D8D8D8;border-radius:5px;display:table;height:inherit;width:100%}div.tree-multiselect>div.selected,div.tree-multiselect>div.selections{vertical-align:top;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;display:table-cell;padding:1%;width:50%}div.tree-multiselect>div.selections{border-right:solid 2px #D8D8D8}div.tree-multiselect div.section>div.item,div.tree-multiselect div.section>div.section{padding-left:20px}div.tree-multiselect div.item,div.tree-multiselect div.title{margin-bottom:2px}div.tree-multiselect div.title{background:#767676;color:#fff;padding:2px}div.tree-multiselect div.title>*{display:inline-block}div.tree-multiselect div.title>span.collapse-section{margin:0 3px;width:8px}div.tree-multiselect input[type=checkbox]{margin-right:5px}div.tree-multiselect>div.selections div.item{margin-left:16px}div.tree-multiselect>div.selected>div.item{padding:2px 5px;border-radius:2px;background:#EAEAEA}div.tree-multiselect>div.selected.ui-sortable>div.item:hover{cursor:move}div.tree-multiselect span.description,div.tree-multiselect span.remove-selected{padding:0 3px;margin-right:5px;background:#777;color:#fff;border-radius:2px}div.tree-multiselect span.remove-selected:hover{cursor:pointer}div.tree-multiselect span.description:hover{cursor:help}div.tree-multiselect div.temp-description-popup{background:#FAFAFA;padding:5px;border:2px solid #676767;border-radius:3px}div.tree-multiselect span.selectedSectionName{float:right;font-style:italic} \ No newline at end of file diff --git a/jquery.tree-multiselect.min.js b/jquery.tree-multiselect.min.js index cafdeef..e21c498 100644 --- a/jquery.tree-multiselect.min.js +++ b/jquery.tree-multiselect.min.js @@ -1,2 +1,2 @@ -/* jQuery Tree Multiselect v1.12.1 | (c) Patrick Tsai | MIT Licensed */ -!function(a){function b(b){return a(b).clone().children().remove().end().text()}function c(b){var c={allowBatchSelection:!0,sortable:!1,collapsible:!0,sectionDelimiter:"/",showSectionOnSelected:!0,startCollapsed:!1};return a.extend({},c,b)}function d(b,c){function d(b,c){for(var d=f,e=0;e option").each(function(){var b=a(this).attr("data-section").split(o.sectionDelimiter),c=a(this).val(),e=a(this).text(),f=a(this).attr("data-description"),g=a(this).attr("data-index"),h=new q(c,e,f,g);d(b,h)}),e.call(c,f)}function e(b){function c(b){var c=document.createElement("div");c.className="section";var d=document.createElement("div");return d.className="title",d.innerHTML=b,a(c).append(d),a(this).append(c),c}function d(b){var c=b.text,d=b.value,e=b.description,f=b.index,g=document.createElement("div");g.className="item",a(g).text(c||d).attr({"data-value":d,"data-description":e,"data-index":f}),a(this).append(g)}if(b.constructor==q)d.call(this,b);else if(a.isArray(b))for(var f=0;f?"),d=a(b).find("div.item[data-description!=''][data-description]");c.prependTo(d),a("div.item > span.description").unbind().mouseenter(function(){var b=a(this).parent(),c=b.attr("data-description"),d=document.createElement("div");d.className="temp-description-popup",d.innerHTML=c,d.style.position="absolute",b.append(d)}).mouseleave(function(){a("div.temp-description-popup").remove()})}function g(b){var c=a("",{type:"checkbox"}),d=null;d=o.allowBatchSelection?a(b).find("div.title, div.item"):a(b).find("div.item"),c.prependTo(d),a(b).find("input[type=checkbox]").click(function(a){a.stopPropagation()})}function h(b,c){var d=a(b).val();if(d)for(var e=0;e input[type=checkbox]").prop("checked",!0)}}function i(b){var c=a(b).find("div.title > input[type=checkbox]");c.change(function(){var b=a(this).closest("div.section"),c=b.find("input[type=checkbox]"),d=a(this).is(":checked");c.prop("checked",d)})}function j(b){var c=a(b).find("input[type=checkbox]");c.change(function(){if(!a(this).is(":checked")){var c=a(this).parentsUntil(b,"div.section");c.find("> div.title > input[type=checkbox]").prop("checked",!1)}})}function k(b){function c(){var c=a(b).find("div.section");c.each(function(){var b=a(this),c=b.find("div.item"),d=c.filter(function(){var b=a(this).find("> input[type=checkbox]");return!b.is(":checked")});if(0===d.length){var e=a(this).find("> div.title > input[type=checkbox]");e.prop("checked",!0)}})}var d=a(b).find("div.item > input[type=checkbox]");d.change(function(){c()}),c()}function l(b){var c="-",d="+",e=a(b).find("div.title"),f=document.createElement("span");f.className="collapse-section",o.startCollapsed?(a(f).text(d),e.siblings().toggle()):a(f).text(c),e.prepend(f),a("span.collapse-section").unbind().click(function(b){b.stopPropagation();var e=a(this).text();a(this).text(e==c?d:c);var f=a(this).parent();f.siblings().toggle()}),e.click(function(){a(this).find("> span.collapse-section").trigger("click")})}function m(c,d,e){function f(b){var c=b.text,e=b.value,f=b.sectionName,g=document.createElement("div");g.className="item",g.innerHTML=c,o.showSectionOnSelected&&a(g).append(""+f+""),a(g).attr("data-value",e).prepend("×").appendTo(d)}function g(e){var g=[];a(d).find("div.item").each(function(){g.push(b(this))});var h=e.filter(function(a){return-1==g.indexOf(a.text)});h.forEach(function(a){f(a)}),n(c,d)}function h(c){var e=[];c.forEach(function(a){e.push(a.text)}),a(d).find("div.item").each(function(){var c=b(this);-1==e.indexOf(c)&&a(this).remove()})}function i(){var b=a(e),c=[];a(d).find("div.item").each(function(){c.push(a(this).attr("data-value"))}),b.val(c),a(e).html(a(e).find("option").sort(function(b,d){var e=c.indexOf(a(b).attr("value")),f=c.indexOf(a(d).attr("value"));return e>f?1:f>e?-1:0}))}function j(){var e=a(c).find("div.item").has("> input[type=checkbox]:checked"),f=[];if(e.each(function(d){var e=b(this),g=a(this).attr("data-value"),h=a(this).attr("data-index");a(this).attr("data-index",void 0);var i=a.map(a(this).parentsUntil(c,"div.section").get().reverse(),function(c){return b(a(c).find("> div.title"))}).join("/");f.push({text:e,value:g,index:h,sectionName:i})}),f.sort(function(a,b){return a.index>b.index?1:a.index input[type=checkbox]");e.prop("checked",!1),e.trigger("change")})}var o;a.fn.treeMultiselect=function(b){return o=c(b),this.each(function(){var b=a(this);b.attr("multiple","").css("display","none");var c=new p;c.build(b);var e=c.selections;d(b,e),f(e),g(e),h(b,e),o.allowBatchSelection&&(i(e),j(e),k(e)),o.collapsible&&l(e);var q=c.selected;m(e,q,b),n(e,q)}),this};var p=function(){};p.prototype.build=function(b){var c=document.createElement("div");c.className="tree-multiselect",a(b).after(c);var d=document.createElement("div");d.className="selections",a(c).append(d);var e=document.createElement("div");e.className="selected",a(c).append(e),this.tree=c,this.selections=d,this.selected=e};var q=function(a,b,c,d){this.value=a,this.text=b,this.description=c,this.index=d}}(jQuery); \ No newline at end of file +/* jQuery Tree Multiselect v1.12.2 | (c) Patrick Tsai | MIT Licensed */ +!function(a){function b(b){return a(b).clone().children().remove().end().text()}function c(b){var c={allowBatchSelection:!0,sortable:!1,collapsible:!0,sectionDelimiter:"/",showSectionOnSelected:!0,startCollapsed:!1};return a.extend({},c,b)}function d(b,c){function d(b,c){for(var d=f,e=0;e option").each(function(){var b=a(this).attr("data-section").split(o.sectionDelimiter),c=a(this).val(),e=a(this).text(),f=a(this).attr("data-description"),g=a(this).attr("data-index"),h=new q(c,e,f,g);d(b,h)}),e.call(c,f)}function e(b){function c(b){var c=document.createElement("div");c.className="section";var d=document.createElement("div");return d.className="title",d.innerHTML=b,a(c).append(d),a(this).append(c),c}function d(b){var c=b.text,d=b.value,e=b.description,f=b.index,g=document.createElement("div");g.className="item",a(g).text(c||d).attr({"data-value":d,"data-description":e,"data-index":f}),a(this).append(g)}if(b.constructor==q)d.call(this,b);else if(a.isArray(b))for(var f=0;f?"),d=a(b).find("div.item[data-description!=''][data-description]");c.prependTo(d),a("div.item > span.description").unbind().mouseenter(function(){var b=a(this).parent(),c=b.attr("data-description"),d=document.createElement("div");d.className="temp-description-popup",d.innerHTML=c,d.style.position="absolute",b.append(d)}).mouseleave(function(){a("div.temp-description-popup").remove()})}function g(b){var c=a("",{type:"checkbox"}),d=null;d=o.allowBatchSelection?a(b).find("div.title, div.item"):a(b).find("div.item"),c.prependTo(d),a(b).find("input[type=checkbox]").click(function(a){a.stopPropagation()})}function h(b,c){var d=a(b).val();if(d)for(var e=0;e input[type=checkbox]").prop("checked",!0)}}function i(b){var c=a(b).find("div.title > input[type=checkbox]");c.change(function(){var b=a(this).closest("div.section"),c=b.find("input[type=checkbox]"),d=a(this).is(":checked");c.prop("checked",d)})}function j(b){var c=a(b).find("input[type=checkbox]");c.change(function(){if(!a(this).is(":checked")){var c=a(this).parentsUntil(b,"div.section");c.find("> div.title > input[type=checkbox]").prop("checked",!1)}})}function k(b){function c(){var c=a(b).find("div.section");c.each(function(){var b=a(this),c=b.find("div.item"),d=c.filter(function(){var b=a(this).find("> input[type=checkbox]");return!b.is(":checked")});if(0===d.length){var e=a(this).find("> div.title > input[type=checkbox]");e.prop("checked",!0)}})}var d=a(b).find("input[type=checkbox]");d.change(function(){c()}),c()}function l(b){var c="-",d="+",e=a(b).find("div.title"),f=document.createElement("span");f.className="collapse-section",o.startCollapsed?(a(f).text(d),e.siblings().toggle()):a(f).text(c),e.prepend(f),a("span.collapse-section").unbind().click(function(b){b.stopPropagation();var e=a(this).text();a(this).text(e==c?d:c);var f=a(this).parent();f.siblings().toggle()}),e.click(function(){a(this).find("> span.collapse-section").trigger("click")})}function m(c,d,e){function f(b){var c=b.text,e=b.value,f=b.sectionName,g=document.createElement("div");g.className="item",g.innerHTML=c,o.showSectionOnSelected&&a(g).append(""+f+""),a(g).attr("data-value",e).prepend("×").appendTo(d)}function g(e){var g=[];a(d).find("div.item").each(function(){g.push(b(this))});var h=e.filter(function(a){return-1==g.indexOf(a.text)});h.forEach(function(a){f(a)}),n(c,d)}function h(c){var e=[];c.forEach(function(a){e.push(a.text)}),a(d).find("div.item").each(function(){var c=b(this);-1==e.indexOf(c)&&a(this).remove()})}function i(){var b=a(e),c=[];a(d).find("div.item").each(function(){c.push(a(this).attr("data-value"))}),b.val(c),a(e).html(a(e).find("option").sort(function(b,d){var e=c.indexOf(a(b).attr("value")),f=c.indexOf(a(d).attr("value"));return e>f?1:f>e?-1:0}))}function j(){var e=a(c).find("div.item").has("> input[type=checkbox]:checked"),f=[];if(e.each(function(d){var e=b(this),g=a(this).attr("data-value"),h=a(this).attr("data-index");a(this).attr("data-index",void 0);var i=a.map(a(this).parentsUntil(c,"div.section").get().reverse(),function(c){return b(a(c).find("> div.title"))}).join("/");f.push({text:e,value:g,index:h,sectionName:i})}),f.sort(function(a,b){return a.index>b.index?1:a.index input[type=checkbox]");e.prop("checked",!1),e.trigger("change")})}var o;a.fn.treeMultiselect=function(b){return o=c(b),this.each(function(){var b=a(this);b.attr("multiple","").css("display","none");var c=new p;c.build(b);var e=c.selections;d(b,e),f(e),g(e),h(b,e),o.allowBatchSelection&&(i(e),j(e),k(e)),o.collapsible&&l(e);var q=c.selected;m(e,q,b),n(e,q)}),this};var p=function(){};p.prototype.build=function(b){var c=document.createElement("div");c.className="tree-multiselect",a(b).after(c);var d=document.createElement("div");d.className="selections",a(c).append(d);var e=document.createElement("div");e.className="selected",a(c).append(e),this.tree=c,this.selections=d,this.selected=e};var q=function(a,b,c,d){this.value=a,this.text=b,this.description=c,this.index=d}}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 99ce8ef..801b590 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery.tree-multiselect.js", - "version": "1.12.1", + "version": "1.12.2", "description": "jQuery multiple select with nested options", "main": "jquery.tree-multiselect.min.js", "scripts": { diff --git a/src/jquery.tree-multiselect.css b/src/jquery.tree-multiselect.css index f988e5a..61d4489 100644 --- a/src/jquery.tree-multiselect.css +++ b/src/jquery.tree-multiselect.css @@ -1,6 +1,6 @@ /* * jQuery Tree Multiselect - * v1.12.1 + * v1.12.2 * * (c) Patrick Tsai * MIT Licensed diff --git a/src/jquery.tree-multiselect.js b/src/jquery.tree-multiselect.js index 6be9472..3b7f889 100644 --- a/src/jquery.tree-multiselect.js +++ b/src/jquery.tree-multiselect.js @@ -1,6 +1,6 @@ /* * jQuery Tree Multiselect - * v1.12.1 + * v1.12.2 * * (c) Patrick Tsai * MIT Licensed @@ -267,7 +267,7 @@ }); } - var checkboxes = $(selectionContainer).find("div.item > input[type=checkbox]"); + var checkboxes = $(selectionContainer).find("input[type=checkbox]"); checkboxes.change(function() { check(); }); diff --git a/test/integration/title-autochecking.js b/test/integration/title-autochecking.js index d2ad6e5..2269387 100644 --- a/test/integration/title-autochecking.js +++ b/test/integration/title-autochecking.js @@ -72,3 +72,19 @@ QUnit.test("titles should unselect when a child is unselected", function(assert) assert.ok(!($("div.title > input[type=checkbox]").is(":checked")), "title should not be checked now"); }); + +QUnit.test("nested titles should all be checked if a title is batch selected", function(assert) { + $("select").append(""); + $("select").treeMultiselect(); + + assert.equal($("input[type=checkbox]").length, 4, "there should be four checkboxes"); + assert.equal($("input[type=checkbox]:checked").length, 0, "no checkboxes should be checked"); + + var middleSection = $("div.section").filter(function() { + return textOf($(this).find("> div.title")) == 'middle'; + }); + + middleSection.find("> div.title > input[type=checkbox]").prop('checked', true).trigger('change'); + + assert.equal($("input[type=checkbox]:checked").length, 4, "all checkboxes should be checked"); +});