This repository has been archived by the owner on Oct 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjquery.treevue.min.js
2 lines (2 loc) · 6.24 KB
/
jquery.treevue.min.js
1
2
/*! jQuery Treevue 2014-07-21 */
!function(a){"use strict";function b(b,c){var d,e=a(c),f=e.attr("value"),g=e.closest(".treevue li").attr("data-treevue-type");return f||(d=a("label[for="+e.context.id+"]"),0===d.length&&(d=e.closest("label")),d&&(f=a.trim(d.text()))),{type:g,value:f,id:e.prop("id")}}function c(a,b){var c=i.clone(),d=h.clone(),e=a.find("li"),f=a.find("ul, ol");b.useAria&&(c.attr(z).find("button").attr("tabindex",-1),d.attr(z)),e.first().prepend(d),f.closest("li").addClass(p).prepend(c)}function d(a){a.attr(n,"tree"),a.find("li").attr(n,"treeitem"),a.find("ul, ol").attr(n,"group").find("."+p).attr(j,!0),a.find("."+q).attr(j,"false").find("ul, ol").first().attr(l,!0),a.find("."+t).attr(m,!0)}function e(a,b){var c=a.find("ul["+l+"=true], "+"ol["+l+"=true]");c.hide().closest("li").find("."+p).andSelf().removeClass(p).addClass(q),a.find(":disabled").closest("li").addClass(t),b.useAria||c.removeAttr(l)}function f(a){a.find(":checkbox").attr("tabindex",-1),a.find("li").attr("tabindex",-1),a.find("> :first-child").attr("tabindex",0).addClass(o)}function g(b,c){b=b.find(":checkbox").each(function(){var b,d=a(this),e=d.closest("li").addClass(s);d.prop("checked")&&d.addClass(r),c.useAria&&e.attr(k,!!d.prop("checked")),d.is('[data-type="subselector"]')&&(b=e.find(":checkbox:not(:first())"),0!==b.length&&d.prop("checked",b.length===b.filter(":checked").length))}),c.useAria&&b.closest(".treevue").attr("aria-multiselectable",!0)}var h,i,j="aria-expanded",k="aria-selected",l="aria-hidden",m="aria-disabled",n="role",o="treevue-focus",p="treevue-expanded",q="treevue-collapsed",r="treevue-selected",s="treevue-selectable",t="treevue-disabled",u="treevue-aria-on",v="Collapse node",w="Expand node",x="Tree view",y={position:"absolute",width:"0",overflow:"hidden"},z={};z[n]="document",z[l]=!0,h=a('<span class="treevue_fallback">'+x+", </span>").css(y),i=a('<span class="treevue_fallback_branch"><button>'+v+"</button></span>").css(y),a.fn.treevue=function(a){return"undefined"==typeof a&&(a={}),"undefined"==typeof a.useAria&&(a.useAria=!0),this.addClass("treevue"),c(this,a),e(this,a),g(this,a),a.useAria&&(this.addClass(u),d(this),f(this)),this},a(function(){function c(b){var c={target:b.context},d=b.find(".treevue_fallback_branch button").first(),e=b.hasClass(p),f=a();b.each(function(){f=f.add(a("ul, ol",this).first())}),b.closest(".treevue").hasClass(u)&&(b.attr(j,!e),f.attr(l,e)),e?(b.addClass(q).removeClass(p).trigger(a.Event("treevue:collapse",c)),d.text(w),f.hide(200)):(b.addClass(p).removeClass(q).trigger(a.Event("treevue:expand",c)),d.text(v),f.show(200))}function d(a){var b=a.closest(".treevue");1===b.length&&b.hasClass(u)&&(b.find("."+o).removeClass(o).attr("tabindex",-1),a.focus().attr("tabindex",0).addClass(o),b.find(".treevue_fallback").detach().prependTo(a))}function e(c){var d=c.closest("."+r),e=c.prop("checked"),f=c.closest(".treevue"),g=c.closest("li");d.closest(".treevue").hasClass(u)&&d.attr(k,e),"subselector"===c.attr("data-type")&&g.find("ul :checkbox, ol :checkbox").not(":disabled").prop("checked",e),g.parentsUntil(f,"li").each(function(){var b,c=a(this),d=a(":checkbox",this).first();d.closest("li").is(c)&&"subselector"===d.attr("data-type")&&(b=c.find("ul :checkbox, ol :checkbox").not(":disabled"),b.length===b.filter(":checked").length?d.prop("checked",!0):e===!1&&d.prop("checked",!1))}),f.trigger(a.Event("treevue:change",{target:f.context,values:f.find(":checked").map(b).get()}))}a("body").on("click",".treevue li."+p+", .treevue li."+q,function(b){if(b.target===this){var e=a(this);b.preventDefault(),c(e),d(e)}}).on("change",".treevue :checkbox",function(){var b=a(this);e(b),d(b.closest("li"))}).on("keydown",".treevue."+u+" li",function(b){var f,g,h=b.keyCode,i=a(this);if(b.target===this){if(f=i.hasClass(p),13===h&&i.hasClass(s))g=i.find(":checkbox").first(),g.is(":not(:disabled)")&&(g.prop("checked",!g.prop("checked")),e(g));else if(40===h)f?d(i.find("ul li, ol li").first()):0===i.next().length?d(i.parentsUntil(".treevue","li").next().first()):d(i.next());else if(38===h)i.prev().hasClass(p)?d(i.prev().find("ul li, ol li").last()):0===i.prev().length?d(i.parent().closest("li")):d(i.prev());else if(37===h)f?c(i):d(i.parent().closest("li"));else if(39===h)i.hasClass(q)?c(i):f&&d(i.find("ul li, ol li").first());else if(36===h)d(i.closest(".treevue").find("li:visible").first());else if(35===h)d(i.closest(".treevue").find("li:visible").last());else{if(106!==h)return;c(i.closest(".treevue").find("li."+q))}return b.preventDefault(),b.stopPropagation(),!1}}).on("click",".treevue_fallback_branch button",function(){c(a(this).closest("li"))}).on("focus",".treevue_fallback_branch",function(){a(this).parent().addClass("treeitem_focus")}).on("blur",".treevue_fallback_branch",function(){a(this).parent().removeClass("treeitem_focus")})})}(jQuery),function(a){"use strict";function b(e){var f,g,h,i=a("<li></li>");return e.type&&i.attr("data-treevue-type",e.type),e.selectable===!0||e.selectable!==!1&&(e.selected||e.disabled||e.subselector)?(g=c+(e.id||"treevue-node-"+(d+=1)),f=a('<input type="checkbox" />').appendTo(i).prop("checked",e.selected).prop("disabled",e.disabled).attr("value",e.value).attr("id",g),e.subselector&&f.attr("data-type","subselector"),a("<label />").text(e.label).attr("for",g).appendTo(i)):i.text(e.label),a.isArray(e.children)&&e.children.length>0&&(h=a("<ul/>").appendTo(i).append(a.map(e.children,b)),e.collapsed&&h.attr("aria-hidden",!0)),i}var c,d=0;a.treevue=function(d,e,f){return c=e?e+"-":"",a("<ul />").append(a.map(d,b)).treevue(f)}}(jQuery),function(a){"use strict";function b(e){var f,g,h,i={};return e=a(e),g=e.find(":checkbox:first()"),f=e.find("ul:first() > li, ol:first() > li"),h=e.attr("data-treevue-type"),h&&(i.type=h),f.length>0&&(i.children=a.map(f,b),e.hasClass(c)&&(i.collapsed=!0)),g.closest("li").is(e)?(/treevue-node-/.test(g.attr("id"))===!1&&(i.id=g.attr("id")),i.selected=g.prop("checked"),a.each({disabled:e.hasClass(d),value:g.attr("value"),subselector:"subselector"===g.attr("data-type"),label:a.trim(e.find("label:first()").text())},function(a,b){b&&(i[a]=b)})):i.label=a.trim(e.clone().find("ul, ol, [aria-hidden]").remove().end().text()),i}var c="treevue-collapsed",d="treevue-disabled";a.fn.treevueJson=function(){if(!this.first().is(".treevue"))throw new Error("This node is not a treevue");return a.map(this.first().children(),b)}}(jQuery);