Current Path : C:/xampp/htdocs/moodle/admin/tool/lp/amd/build/ |
Current File : C:/xampp/htdocs/moodle/admin/tool/lp/amd/build/tree.min.js |
define ("tool_lp/tree",["jquery","core/url","core/log"],function(a,b,c){var d=a("<img alt=\"\" src=\""+b.imageUrl("t/expanded")+"\"/>"),e=a("<img alt=\"\" src=\""+b.imageUrl("t/collapsed")+"\"/>"),f=function(b,c){this.treeRoot=a(b);this.multiSelect="undefined"==typeof c||!0===c;this.items=this.treeRoot.find("li");this.expandAll=20>this.items.length;this.parents=this.treeRoot.find("li:has(ul)");if(c){this.treeRoot.attr("aria-multiselectable","true")}this.items.attr("aria-selected","false");this.visibleItems=null;this.activeItem=null;this.lastActiveItem=null;this.keys={tab:9,enter:13,space:32,pageup:33,pagedown:34,end:35,home:36,left:37,up:38,right:39,down:40,eight:56,asterisk:106};this.init();this.bindEventHandlers()};f.prototype.init=function(){this.parents.attr("aria-expanded","true");this.parents.prepend(d.clone());this.items.attr("role","tree-item");this.items.attr("tabindex","-1");this.parents.attr("role","group");this.treeRoot.attr("role","tree");this.visibleItems=this.treeRoot.find("li");var b=this;if(!this.expandAll){this.parents.each(function(){b.collapseGroup(a(this))});this.expandGroup(this.parents.first())}};f.prototype.expandGroup=function(a){var b=a.children("ul");b.show().attr("aria-hidden","false");a.attr("aria-expanded","true");a.children("img").attr("src",d.attr("src"));this.visibleItems=this.treeRoot.find("li:visible")};f.prototype.collapseGroup=function(a){var b=a.children("ul");b.hide().attr("aria-hidden","true");a.attr("aria-expanded","false");a.children("img").attr("src",e.attr("src"));this.visibleItems=this.treeRoot.find("li:visible")};f.prototype.toggleGroup=function(a){if("true"==a.attr("aria-expanded")){this.collapseGroup(a)}else{this.expandGroup(a)}};f.prototype.triggerChange=function(){var a=this.items.filter("[aria-selected=true]");if(!this.multiSelect){a=a.first()}this.treeRoot.trigger("selectionchanged",{selected:a})};f.prototype.multiSelectItem=function(b){if(!this.multiSelect){this.items.attr("aria-selected","false")}else if(null!==this.lastActiveItem){var c=this.visibleItems.index(this.lastActiveItem),d=this.visibleItems.index(this.activeItem),e=null;while(c<d){e=a(this.visibleItems.get(c));e.attr("aria-selected","true");c++}while(c>d){e=a(this.visibleItems.get(c));e.attr("aria-selected","true");c--}}b.attr("aria-selected","true");this.triggerChange()};f.prototype.selectItem=function(a){var b=a.parent();while("tree"!=b.attr("role")){b=b.parent();if("false"==b.attr("aria-expanded")){this.expandGroup(b)}b=b.parent()}this.items.attr("aria-selected","false");a.attr("aria-selected","true");this.triggerChange()};f.prototype.toggleItem=function(a){if(!this.multiSelect){this.selectItem(a);return}var b=a.attr("aria-selected");if("true"===b){b="false"}else{b="true"}a.attr("aria-selected",b);this.triggerChange()};f.prototype.updateFocus=function(a){this.lastActiveItem=this.activeItem;this.activeItem=a;var b=a.parent();while("tree"!=b.attr("role")){b=b.parent();if("false"==b.attr("aria-expanded")){this.expandGroup(b)}b=b.parent()}this.items.attr("tabindex","-1");a.attr("tabindex",0)};f.prototype.handleKeyDown=function(b,c){var d=this.visibleItems.index(b),e=null,f=c.shiftKey||c.ctrlKey||c.metaKey||c.altKey,g=this;switch(c.keyCode){case this.keys.home:{e=this.parents.first();e.focus();if(c.shiftKey){this.multiSelectItem(e)}else if(!f){this.selectItem(e)}c.stopPropagation();return!1}case this.keys.end:{e=this.visibleItems.last();e.focus();if(c.shiftKey){this.multiSelectItem(e)}else if(!f){this.selectItem(e)}c.stopPropagation();return!1}case this.keys.enter:case this.keys.space:{if(c.shiftKey){this.multiSelectItem(b)}else if(c.metaKey||c.ctrlKey){this.toggleItem(b)}else{this.selectItem(b)}c.stopPropagation();return!1}case this.keys.left:{if(b.has("ul")&&"true"==b.attr("aria-expanded")){this.collapseGroup(b)}else{var h=b.parent(),i=h.parent();if(i.is("li")){i.focus();if(c.shiftKey){this.multiSelectItem(i)}else if(!f){this.selectItem(i)}}}c.stopPropagation();return!1}case this.keys.right:{if(b.has("ul")&&"false"==b.attr("aria-expanded")){this.expandGroup(b)}else{e=b.children("ul").children("li").first();if(0<e.length){e.focus();if(c.shiftKey){this.multiSelectItem(e)}else if(!f){this.selectItem(e)}}}c.stopPropagation();return!1}case this.keys.up:{if(0<d){var j=this.visibleItems.eq(d-1);j.focus();if(c.shiftKey){this.multiSelectItem(j)}else if(!f){this.selectItem(j)}}c.stopPropagation();return!1}case this.keys.down:{if(d<this.visibleItems.length-1){var k=this.visibleItems.eq(d+1);k.focus();if(c.shiftKey){this.multiSelectItem(k)}else if(!f){this.selectItem(k)}}c.stopPropagation();return!1}case this.keys.asterisk:{this.parents.each(function(){g.expandGroup(a(this))});c.stopPropagation();return!1}case this.keys.eight:{if(c.shiftKey){this.parents.each(function(){g.expandGroup(a(this))});c.stopPropagation()}return!1}}return!0};f.prototype.handleKeyPress=function(a,b){if(b.altKey||b.ctrlKey||b.shiftKey||b.metaKey){return!0}switch(b.keyCode){case this.keys.tab:{return!0}case this.keys.enter:case this.keys.home:case this.keys.end:case this.keys.left:case this.keys.right:case this.keys.up:case this.keys.down:{b.stopPropagation();return!1}default:{var c=String.fromCharCode(b.which),d=!1,e=this.visibleItems.index(a),f=this.visibleItems.length,g=e+1;if(g==f){g=0}while(g!=e){var h=this.visibleItems.eq(g),i=h.text().charAt(0);if(h.has("ul")){i=h.find("span").text().charAt(0)}if(i.toLowerCase()==c){d=!0;break}g=g+1;if(g==f){g=0}}if(!0===d){this.updateFocus(this.visibleItems.eq(g))}b.stopPropagation();return!1}}return!0};f.prototype.on=function(a,b){if("selectionchanged"!==a){c.warning("Invalid custom event name for tree. Only \"selectionchanged\" is supported.")}else{this.treeRoot.on(a,b)}};f.prototype.handleDblClick=function(a,b){if(b.altKey||b.ctrlKey||b.shiftKey||b.metaKey){return!0}this.updateFocus(a);this.toggleGroup(a);b.stopPropagation();return!1};f.prototype.handleExpandCollapseClick=function(a,b){this.toggleGroup(a);b.stopPropagation();return!1};f.prototype.handleClick=function(a,b){if(b.shiftKey){this.multiSelectItem(a)}else if(b.metaKey||b.ctrlKey){this.toggleItem(a)}else{this.selectItem(a)}this.updateFocus(a);b.stopPropagation();return!1};f.prototype.handleBlur=function(){return!0};f.prototype.handleFocus=function(a){this.updateFocus(a);return!0};f.prototype.bindEventHandlers=function(){var b=this;this.parents.dblclick(function(c){return b.handleDblClick(a(this),c)});this.items.click(function(c){return b.handleClick(a(this),c)});this.items.children("img").click(function(c){return b.handleExpandCollapseClick(a(this).parent(),c)});this.items.keydown(function(c){return b.handleKeyDown(a(this),c)});this.items.keypress(function(c){return b.handleKeyPress(a(this),c)});this.items.focus(function(c){return b.handleFocus(a(this),c)});this.items.blur(function(c){return b.handleBlur(a(this),c)})};return f}); //# sourceMappingURL=tree.min.js.map