mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-51957 cbe: Use a jquery 'change' event instead of passing callbacks
This commit is contained in:
parent
60bf8bb0aa
commit
85dbaf91ba
9 changed files with 27 additions and 23 deletions
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
define(["jquery","core/notification","core/ajax","core/templates","tool_lp/dialogue","core/str","tool_lp/tree"],function(a,b,c,d,e,f,g){var h,i=function(b,c,d){h=this,h._eventNode=a("<div></div>"),h._frameworks=[],h._reset(),h._pageContextId=b,h._pageContextIncludes=d||"children",c&&(h._frameworkId=c,h._singleFramework=!0)};return i.prototype._competencies=null,i.prototype._disallowedCompetencyIDs=null,i.prototype._eventNode=null,i.prototype._frameworks=null,i.prototype._frameworkId=null,i.prototype._pageContextId=null,i.prototype._pageContextIncludes=null,i.prototype._popup=null,i.prototype._searchText="",i.prototype._selectedCompetency=null,i.prototype._singleFramework=!1,i.prototype._afterRender=function(){new g(h._find("[data-enhance=linktree]"),function(b){var c=b.data("id"),d=!0;a.each(h._disallowedCompetencyIDs,function(a,b){return b==c?(d=!1,!1):void 0}),h._selectedCompetency=null,d&&(h._selectedCompetency=c),h._selectedCompetency?h._find('[data-region="competencylinktree"] [data-action="add"]').removeAttr("disabled"):h._find('[data-region="competencylinktree"] [data-action="add"]').attr("disabled","disabled")}),h._singleFramework||h._find('[data-action="chooseframework"]').change(function(b){h._frameworkId=a(b.target).val(),h._loadCompetencies().then(h._refresh)}),h._find('[data-region="filtercompetencies"] button').click(function(b){return b.preventDefault(),a(b.target).attr("disabled","disabled"),h._searchText=h._find('[data-region="filtercompetencies"] input').val()||"",h._refresh().always(function(){a(b.target).removeAttr("disabled")})}),h._find('[data-region="competencylinktree"] [data-action="cancel"]').click(function(a){a.preventDefault(),h.close()}),h._find('[data-region="competencylinktree"] [data-action="add"]').click(function(a){a.preventDefault(),h._selectedCompetency&&(h._trigger("save",{competencyId:h._selectedCompetency}),h.close())})},i.prototype.close=function(){h._popup.close(),h._reset()},i.prototype.display=function(){return h._render().done(function(a){return f.get_string("competencypicker","tool_lp").done(function(b){h._popup=new e(b,a,h._afterRender.bind(h))})}).fail(b.exception)},i.prototype._fetchCompetencies=function(a,d){return c.call([{methodname:"tool_lp_search_competencies",args:{searchtext:d,competencyframeworkid:a}}])[0].done(function(a){function b(a,c){for(var d=0;d<c.length;d++)c[d].parentid==a.id&&(a.haschildren=!0,c[d].children=[],c[d].haschildren=!1,a.children[a.children.length]=c[d],b(c[d],c))}var c,d,e=[];for(c=0;c<a.length;c++)d=a[c],"0"==d.parentid&&(d.children=[],d.haschildren=0,e[e.length]=d,b(d,a));h._competencies=e}).fail(b.exception)},i.prototype._find=function(b){return a(h._popup.getContent()).find(b)},i.prototype._getFramework=function(b){var c;return a.each(h._frameworks,function(a,d){return d.id==b?(c=d,!1):void 0}),c},i.prototype._loadCompetencies=function(){return h._fetchCompetencies(h._frameworkId,h._searchText)},i.prototype._loadFrameworks=function(){var d;return h._frameworks.length>0?a.when():(d=h._singleFramework?c.call([{methodname:"tool_lp_read_competency_framework",args:{id:this._frameworkId}}])[0].then(function(a){return[a]}):c.call([{methodname:"tool_lp_list_competency_frameworks",args:{sort:"shortname",context:{contextid:h._pageContextId},includes:h._pageContextIncludes}}])[0],d.done(function(a){h._frameworks=a}).fail(b.exception))},i.prototype.on=function(a,b){h._eventNode.on(a,b)},i.prototype._preRender=function(){return h._loadFrameworks().then(function(){return!h._frameworkId&&h._frameworks.length>0&&(h._frameworkId=h._frameworks[0].id),h._frameworkId?h._loadCompetencies():(h._frameworks=[],a.when())})},i.prototype._refresh=function(){return h._render().then(function(a){h._find('[data-region="competencylinktree"]').replaceWith(a),h._afterRender()})},i.prototype._render=function(){return h._preRender().then(function(){h._singleFramework||a.each(h._frameworks,function(a,b){b.id==h._frameworkId?b.selected=!0:b.selected=!1});var b={competencies:h._competencies,framework:h._getFramework(h._frameworkId),frameworks:h._frameworks,search:h._searchText,singleFramework:h._singleFramework};return d.render("tool_lp/competency_picker",b)})},i.prototype._reset=function(){h._competencies=[],h._disallowedCompetencyIDs=[],h._popup=null,h._searchText="",h._selectedCompetency=null},i.prototype.setDisallowedCompetencyIDs=function(a){h._disallowedCompetencyIDs=a},i.prototype._trigger=function(a,b){h._eventNode.trigger(a,[b])},i});
|
||||
define(["jquery","core/notification","core/ajax","core/templates","tool_lp/dialogue","core/str","tool_lp/tree"],function(a,b,c,d,e,f,g){var h,i=function(b,c,d){h=this,h._eventNode=a("<div></div>"),h._frameworks=[],h._reset(),h._pageContextId=b,h._pageContextIncludes=d||"children",c&&(h._frameworkId=c,h._singleFramework=!0)};return i.prototype._competencies=null,i.prototype._disallowedCompetencyIDs=null,i.prototype._eventNode=null,i.prototype._frameworks=null,i.prototype._frameworkId=null,i.prototype._pageContextId=null,i.prototype._pageContextIncludes=null,i.prototype._popup=null,i.prototype._searchText="",i.prototype._selectedCompetency=null,i.prototype._singleFramework=!1,i.prototype._afterRender=function(){new g(h._find("[data-enhance=linktree]")),h._find("[data-enhance=linktree]").on("change",function(b,c){var d=c.data("id"),e=!0;b.preventDefault(),a.each(h._disallowedCompetencyIDs,function(a,b){return b==d?(e=!1,!1):void 0}),h._selectedCompetency=null,e&&(h._selectedCompetency=d),h._selectedCompetency?h._find('[data-region="competencylinktree"] [data-action="add"]').removeAttr("disabled"):h._find('[data-region="competencylinktree"] [data-action="add"]').attr("disabled","disabled")}),h._singleFramework||h._find('[data-action="chooseframework"]').change(function(b){h._frameworkId=a(b.target).val(),h._loadCompetencies().then(h._refresh)}),h._find('[data-region="filtercompetencies"] button').click(function(b){return b.preventDefault(),a(b.target).attr("disabled","disabled"),h._searchText=h._find('[data-region="filtercompetencies"] input').val()||"",h._refresh().always(function(){a(b.target).removeAttr("disabled")})}),h._find('[data-region="competencylinktree"] [data-action="cancel"]').click(function(a){a.preventDefault(),h.close()}),h._find('[data-region="competencylinktree"] [data-action="add"]').click(function(a){a.preventDefault(),h._selectedCompetency&&(h._trigger("save",{competencyId:h._selectedCompetency}),h.close())})},i.prototype.close=function(){h._popup.close(),h._reset()},i.prototype.display=function(){return h._render().done(function(a){return f.get_string("competencypicker","tool_lp").done(function(b){h._popup=new e(b,a,h._afterRender.bind(h))})}).fail(b.exception)},i.prototype._fetchCompetencies=function(a,d){return c.call([{methodname:"tool_lp_search_competencies",args:{searchtext:d,competencyframeworkid:a}}])[0].done(function(a){function b(a,c){for(var d=0;d<c.length;d++)c[d].parentid==a.id&&(a.haschildren=!0,c[d].children=[],c[d].haschildren=!1,a.children[a.children.length]=c[d],b(c[d],c))}var c,d,e=[];for(c=0;c<a.length;c++)d=a[c],"0"==d.parentid&&(d.children=[],d.haschildren=0,e[e.length]=d,b(d,a));h._competencies=e}).fail(b.exception)},i.prototype._find=function(b){return a(h._popup.getContent()).find(b)},i.prototype._getFramework=function(b){var c;return a.each(h._frameworks,function(a,d){return d.id==b?(c=d,!1):void 0}),c},i.prototype._loadCompetencies=function(){return h._fetchCompetencies(h._frameworkId,h._searchText)},i.prototype._loadFrameworks=function(){var d;return h._frameworks.length>0?a.when():(d=h._singleFramework?c.call([{methodname:"tool_lp_read_competency_framework",args:{id:this._frameworkId}}])[0].then(function(a){return[a]}):c.call([{methodname:"tool_lp_list_competency_frameworks",args:{sort:"shortname",context:{contextid:h._pageContextId},includes:h._pageContextIncludes}}])[0],d.done(function(a){h._frameworks=a}).fail(b.exception))},i.prototype.on=function(a,b){h._eventNode.on(a,b)},i.prototype._preRender=function(){return h._loadFrameworks().then(function(){return!h._frameworkId&&h._frameworks.length>0&&(h._frameworkId=h._frameworks[0].id),h._frameworkId?h._loadCompetencies():(h._frameworks=[],a.when())})},i.prototype._refresh=function(){return h._render().then(function(a){h._find('[data-region="competencylinktree"]').replaceWith(a),h._afterRender()})},i.prototype._render=function(){return h._preRender().then(function(){h._singleFramework||a.each(h._frameworks,function(a,b){b.id==h._frameworkId?b.selected=!0:b.selected=!1});var b={competencies:h._competencies,framework:h._getFramework(h._frameworkId),frameworks:h._frameworks,search:h._searchText,singleFramework:h._singleFramework};return d.render("tool_lp/competency_picker",b)})},i.prototype._reset=function(){h._competencies=[],h._disallowedCompetencyIDs=[],h._popup=null,h._searchText="",h._selectedCompetency=null},i.prototype.setDisallowedCompetencyIDs=function(a){h._disallowedCompetencyIDs=a},i.prototype._trigger=function(a,b){h._eventNode.trigger(a,[b])},i});
|
|
@ -1 +1 @@
|
|||
define(["core/ajax","core/notification","core/templates","tool_lp/tree","jquery"],function(a,b,c,d,e){var f=[],g=0,h="",i="",j=!1,k=function(a,b){var c=0,d=!1;for(a.haschildren=!1,a.children=[],c=0;c<b.length;c++)d=b[c],d.parentid==a.id&&(a.haschildren=!0,a.children.push(d),k(d,b))},l=function(l){var m=e.Deferred(),n=a.call([{methodname:"tool_lp_search_competencies",args:{searchtext:l,competencyframeworkid:g,includerelated:!0}}]);return n[0].done(function(a){f=[];var g=0;for(g=0;g<a.length;g++)f[a[g].id]=a[g];var l=[],n=!1;for(g=0;g<a.length;g++)n=a[g],0===parseInt(n.parentid,10)&&(l.push(n),k(n,a));var o={shortname:h,competencies:l};c.render("tool_lp/competencies_tree_root",o).done(function(a,b){c.replaceNode(e(i),a,b),new d(i,j),m.resolve(f)}).fail(b.exception)}).fail(function(a){m.reject(a)}),m.promise()};return{init:function(a,c,d,e,f){g=a,h=c,i=e,j=f,l(d).fail(b.exception)},getCompetencyFrameworkId:function(){return g},getCompetency:function(a){return f[a]},getCompetencyLevel:function(a){var b=this.getCompetency(a),c=b.path.replace(/^\/|\/$/g,"").split("/").length;return c},reloadCompetencies:function(){return l("").fail(b.exception)},listCompetencies:function(){return f}}});
|
||||
define(["core/ajax","core/notification","core/templates","tool_lp/tree","jquery"],function(a,b,c,d,e){var f=[],g=0,h="",i="",j=function(a,b){var c=0,d=!1;for(a.haschildren=!1,a.children=[],c=0;c<b.length;c++)d=b[c],d.parentid==a.id&&(a.haschildren=!0,a.children.push(d),j(d,b))},k=function(k){var l=e.Deferred(),m=a.call([{methodname:"tool_lp_search_competencies",args:{searchtext:k,competencyframeworkid:g,includerelated:!0}}]);return m[0].done(function(a){f=[];var g=0;for(g=0;g<a.length;g++)f[a[g].id]=a[g];var k=[],m=!1;for(g=0;g<a.length;g++)m=a[g],0===parseInt(m.parentid,10)&&(k.push(m),j(m,a));var n={shortname:h,competencies:k};c.render("tool_lp/competencies_tree_root",n).done(function(a,b){c.replaceNodeContents(e(i),e(a).html(),b),new d(i),l.resolve(f)}).fail(b.exception)}).fail(function(a){l.reject(a)}),l.promise()};return{init:function(a,c,d,e){g=a,h=c,i=e,k(d).fail(b.exception)},getCompetencyFrameworkId:function(){return g},getCompetency:function(a){return f[a]},getCompetencyLevel:function(a){var b=this.getCompetency(a),c=b.path.replace(/^\/|\/$/g,"").split("/").length;return c},reloadCompetencies:function(){return k("").fail(b.exception)},listCompetencies:function(){return f}}});
|
2
admin/tool/lp/amd/build/tree.min.js
vendored
2
admin/tool/lp/amd/build/tree.min.js
vendored
|
@ -1 +1 @@
|
|||
define(["jquery","core/url"],function(a,b){var c=a('<img alt="" src="'+b.imageUrl("t/expanded")+'"/>'),d=a('<img alt="" src="'+b.imageUrl("t/collapsed")+'"/>'),e=function(b,c){this.treeRoot=a(b),this.items=this.treeRoot.find("li"),this.parents=this.treeRoot.find("li:has(ul)"),this.visibleItems=null,this.activeItem=null,this.selectCallback=c,this.keys={tab:9,enter:13,space:32,pageup:33,pagedown:34,end:35,home:36,left:37,up:38,right:39,down:40,asterisk:106},this.init(),this.bindEventHandlers()};return e.prototype.init=function(){this.parents.attr("aria-expanded","true"),this.parents.prepend(c.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")},e.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",c.attr("src")),this.visibleItems=this.treeRoot.find("li:visible")},e.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",d.attr("src")),this.visibleItems=this.treeRoot.find("li:visible")},e.prototype.toggleGroup=function(a){"true"==a.attr("aria-expanded")?this.collapseGroup(a):this.expandGroup(a)},e.prototype.updateFocus=function(a){this.items.attr("aria-selected","false").attr("tabindex","-1"),a.attr("aria-selected","true").attr("tabindex",0),this.selectCallback(a)},e.prototype.handleKeyDown=function(b,c){var d=this.visibleItems.index(b);if(c.altKey||c.ctrlKey||c.shiftKey&&c.keyCode!=this.keys.tab)return!0;switch(c.keyCode){case this.keys.home:return this.activeItem=this.parents.first(),this.activeItem.focus(),c.stopPropagation(),!1;case this.keys.end:return this.activeItem=this.visibleItems.last(),this.activeItem.focus(),c.stopPropagation(),!1;case this.keys.enter:case this.keys.space:return b.has("ul")&&this.toggleGroup(b,!0),c.stopPropagation(),!1;case this.keys.left:if(b.has("ul")&&"true"==b.attr("aria-expanded"))this.collapseGroup(b);else{var e=b.parent(),f=e.parent();this.activeItem=f,this.activeItem.focus()}return c.stopPropagation(),!1;case this.keys.right:return b.has("ul")&&"false"==b.attr("aria-expanded")?this.expandGroup(b):(this.activeItem=b.children("ul").children("li").first(),this.activeItem.focus()),c.stopPropagation(),!1;case this.keys.up:if(d>0){var g=this.visibleItems.eq(d-1);this.activeItem=g,g.focus()}return c.stopPropagation(),!1;case this.keys.down:if(d<this.visibleItems.length-1){var h=this.visibleItems.eq(d+1);this.activeItem=h,h.focus()}return c.stopPropagation(),!1;case this.keys.asterisk:var i=this;return this.parents.each(function(){i.expandGroup(a(this))}),c.stopPropagation(),!1}return!0},e.prototype.handleKeyPress=function(a,b){if(b.altKey||b.ctrlKey||b.shiftKey)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:return b.stopPropagation(),!1;default:var c=String.fromCharCode(b.which),d=!1,e=this.visibleItems.index(a),f=this.visibleItems.length,g=e+1;for(g==f&&(g=0);g!=e;){var h=this.visibleItems.eq(g),i=h.text().charAt(0);if(h.has("ul")&&(i=h.find("span").text().charAt(0)),i.toLowerCase()==c){d=!0;break}g+=1,g==f&&(g=0)}return d===!0&&(this.activeItem=this.visibleItems.eq(g),this.activeItem.focus()),b.stopPropagation(),!1}return!0},e.prototype.handleDblClick=function(a,b){return b.altKey||b.ctrlKey||b.shiftKey?!0:(this.activeItem=a,this.updateFocus(a),this.toggleGroup(a),b.stopPropagation(),!1)},e.prototype.handleClick=function(a,b){return b.altKey||b.ctrlKey||b.shiftKey?!0:(this.activeItem=a,this.updateFocus(a),b.stopPropagation(),!1)},e.prototype.handleBlur=function(){return!0},e.prototype.handleFocus=function(a){return null===this.activeItem&&(this.activeItem=a),this.updateFocus(this.activeItem),!0},e.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.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)})},e});
|
||||
define(["jquery","core/url"],function(a,b){var c=a('<img alt="" src="'+b.imageUrl("t/expanded")+'"/>'),d=a('<img alt="" src="'+b.imageUrl("t/collapsed")+'"/>'),e=function(b){this.treeRoot=a(b),this.items=this.treeRoot.find("li"),this.parents=this.treeRoot.find("li:has(ul)"),this.visibleItems=null,this.activeItem=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,asterisk:106},this.init(),this.bindEventHandlers()};return e.prototype.init=function(){this.parents.attr("aria-expanded","true"),this.parents.prepend(c.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")},e.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",c.attr("src")),this.visibleItems=this.treeRoot.find("li:visible")},e.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",d.attr("src")),this.visibleItems=this.treeRoot.find("li:visible")},e.prototype.toggleGroup=function(a){"true"==a.attr("aria-expanded")?this.collapseGroup(a):this.expandGroup(a)},e.prototype.updateFocus=function(a){this.items.attr("aria-selected","false").attr("tabindex","-1"),a.attr("aria-selected","true").attr("tabindex",0),this.treeRoot.trigger("change",[a])},e.prototype.handleKeyDown=function(b,c){var d=this.visibleItems.index(b);if(c.altKey||c.ctrlKey||c.shiftKey&&c.keyCode!=this.keys.tab)return!0;switch(c.keyCode){case this.keys.home:return this.activeItem=this.parents.first(),this.activeItem.focus(),c.stopPropagation(),!1;case this.keys.end:return this.activeItem=this.visibleItems.last(),this.activeItem.focus(),c.stopPropagation(),!1;case this.keys.enter:case this.keys.space:return b.has("ul")&&this.toggleGroup(b,!0),c.stopPropagation(),!1;case this.keys.left:if(b.has("ul")&&"true"==b.attr("aria-expanded"))this.collapseGroup(b);else{var e=b.parent(),f=e.parent();this.activeItem=f,this.activeItem.focus()}return c.stopPropagation(),!1;case this.keys.right:return b.has("ul")&&"false"==b.attr("aria-expanded")?this.expandGroup(b):(this.activeItem=b.children("ul").children("li").first(),this.activeItem.focus()),c.stopPropagation(),!1;case this.keys.up:if(d>0){var g=this.visibleItems.eq(d-1);this.activeItem=g,g.focus()}return c.stopPropagation(),!1;case this.keys.down:if(d<this.visibleItems.length-1){var h=this.visibleItems.eq(d+1);this.activeItem=h,h.focus()}return c.stopPropagation(),!1;case this.keys.asterisk:var i=this;return this.parents.each(function(){i.expandGroup(a(this))}),c.stopPropagation(),!1}return!0},e.prototype.handleKeyPress=function(a,b){if(b.altKey||b.ctrlKey||b.shiftKey)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:return b.stopPropagation(),!1;default:var c=String.fromCharCode(b.which),d=!1,e=this.visibleItems.index(a),f=this.visibleItems.length,g=e+1;for(g==f&&(g=0);g!=e;){var h=this.visibleItems.eq(g),i=h.text().charAt(0);if(h.has("ul")&&(i=h.find("span").text().charAt(0)),i.toLowerCase()==c){d=!0;break}g+=1,g==f&&(g=0)}return d===!0&&(this.activeItem=this.visibleItems.eq(g),this.activeItem.focus()),b.stopPropagation(),!1}return!0},e.prototype.handleDblClick=function(a,b){return b.altKey||b.ctrlKey||b.shiftKey?!0:(this.activeItem=a,this.updateFocus(a),this.toggleGroup(a),b.stopPropagation(),!1)},e.prototype.handleClick=function(a,b){return b.altKey||b.ctrlKey||b.shiftKey?!0:(this.activeItem=a,this.updateFocus(a),b.stopPropagation(),!1)},e.prototype.handleBlur=function(){return!0},e.prototype.handleFocus=function(a){return null===this.activeItem&&(this.activeItem=a),this.updateFocus(this.activeItem),!0},e.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.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)})},e});
|
|
@ -573,7 +573,7 @@ define(['jquery',
|
|||
* Handler when a node in the aria tree is selected.
|
||||
* @method selectionChanged
|
||||
*/
|
||||
selectionChanged: function(node) {
|
||||
selectionChanged: function(evt, node) {
|
||||
var id = $(node).data('id'),
|
||||
btn = $('[data-region="competencyactions"] [data-action="add"]'),
|
||||
actionMenu = $('[data-region="competencyactionsmenu"]'),
|
||||
|
@ -625,6 +625,9 @@ define(['jquery',
|
|||
.text(str);
|
||||
});
|
||||
}
|
||||
// We handled this event so consume it.
|
||||
evt.preventDefault();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
@ -82,10 +82,14 @@ define(['jquery',
|
|||
Picker.prototype._afterRender = function() {
|
||||
|
||||
// Initialise the tree.
|
||||
new Tree(self._find('[data-enhance=linktree]'), function(target) {
|
||||
new Tree(self._find('[data-enhance=linktree]'));
|
||||
|
||||
self._find('[data-enhance=linktree]').on('change', function(evt, target) {
|
||||
var compId = target.data('id'),
|
||||
valid = true;
|
||||
|
||||
evt.preventDefault();
|
||||
|
||||
$.each(self._disallowedCompetencyIDs, function(i, id) {
|
||||
if (id == compId) {
|
||||
valid = false;
|
||||
|
|
|
@ -37,9 +37,6 @@ define(['core/ajax', 'core/notification', 'core/templates', 'tool_lp/tree', 'jqu
|
|||
/** @var {String} treeSelector - The selector for the root of the tree. */
|
||||
var treeSelector = '';
|
||||
|
||||
/** @var {Function} changeCallback - Handler for selection changed events. */
|
||||
var changeCallback = false;
|
||||
|
||||
/**
|
||||
* Build a tree from the flat list of competencies.
|
||||
* @param {Object} parent The parent competency.
|
||||
|
@ -96,8 +93,8 @@ define(['core/ajax', 'core/notification', 'core/templates', 'tool_lp/tree', 'jqu
|
|||
competencies: children
|
||||
};
|
||||
templates.render('tool_lp/competencies_tree_root', context).done(function(html, js) {
|
||||
templates.replaceNode($(treeSelector), html, js);
|
||||
new Ariatree(treeSelector, changeCallback);
|
||||
templates.replaceNodeContents($(treeSelector), $(html).html(), js);
|
||||
new Ariatree(treeSelector);
|
||||
deferred.resolve(competencies);
|
||||
}).fail(notification.exception);
|
||||
|
||||
|
@ -118,13 +115,11 @@ define(['core/ajax', 'core/notification', 'core/templates', 'tool_lp/tree', 'jqu
|
|||
* @param {String} shortname The framework shortname
|
||||
* @param {String} search The current search string
|
||||
* @param {String} selector The selector for the tree div
|
||||
* @param {Function} changeHandler The handler to call when the selection changes.
|
||||
*/
|
||||
init: function(id, shortname, search, selector, changeHandler) {
|
||||
init: function(id, shortname, search, selector) {
|
||||
competencyFrameworkId = id;
|
||||
competencyFrameworkShortName = shortname;
|
||||
treeSelector = selector;
|
||||
changeCallback = changeHandler;
|
||||
loadCompetencies(search).fail(notification.exception);
|
||||
},
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
* Implement an accessible aria tree widget, from a nested unordered list.
|
||||
* Based on http://oaa-accessibility.org/example/41/
|
||||
*
|
||||
* To respond to selection changed events - listen to "change" events on the root of the tree.
|
||||
*
|
||||
* @module tool_lp/tree
|
||||
* @package core
|
||||
* @copyright 2015 Damyon Wiese <damyon@moodle.com>
|
||||
|
@ -33,9 +35,8 @@ define(['jquery', 'core/url'], function($, url) {
|
|||
* Constructor
|
||||
*
|
||||
* @param {String} selector
|
||||
* @param {function} selectCallback Called when the active node is changed.
|
||||
*/
|
||||
var Tree = function(selector, selectCallback) {
|
||||
var Tree = function(selector) {
|
||||
this.treeRoot = $(selector);
|
||||
|
||||
this.items = this.treeRoot.find('li');
|
||||
|
@ -43,7 +44,6 @@ define(['jquery', 'core/url'], function($, url) {
|
|||
|
||||
this.visibleItems = null;
|
||||
this.activeItem = null;
|
||||
this.selectCallback = selectCallback;
|
||||
|
||||
this.keys = {
|
||||
tab: 9,
|
||||
|
@ -146,7 +146,7 @@ define(['jquery', 'core/url'], function($, url) {
|
|||
Tree.prototype.updateFocus = function(item) {
|
||||
this.items.attr('aria-selected', 'false').attr('tabindex', '-1');
|
||||
item.attr('aria-selected', 'true').attr('tabindex', 0);
|
||||
this.selectCallback(item);
|
||||
this.treeRoot.trigger('change', [item]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
<button>{{#pix}}a/search, , {{#str}}search{{/str}}{{/pix}}</button>
|
||||
</form>
|
||||
</p>
|
||||
<div data-enhance="tree">
|
||||
</div>
|
||||
<ul data-enhance="tree">
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="span6 well">
|
||||
|
@ -104,13 +104,15 @@
|
|||
|
||||
{{#js}}
|
||||
// Initialise the JS.
|
||||
require(['tool_lp/tree', 'tool_lp/competencytree', 'tool_lp/competencyactions' ], function(ariatree, treeModel, actions) {
|
||||
require(['tool_lp/tree', 'tool_lp/competencytree', 'tool_lp/competencyactions', 'jquery'],
|
||||
function(ariatree, treeModel, actions, $) {
|
||||
|
||||
treeModel.init({{framework.id}},
|
||||
'{{framework.shortname}}',
|
||||
'{{search}}',
|
||||
'[data-enhance=tree]',
|
||||
actions.selectionChanged);
|
||||
'[data-enhance=tree]');
|
||||
// Listen to the custom event triggered by the aria tree.
|
||||
$('[data-enhance=tree]').on('change', actions.selectionChanged);
|
||||
|
||||
actions.init(treeModel, {{pagecontextid}}, {{{framework.taxonomies}}});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue