<\/p>');\n var id = node.id || node.key + '_tree_item';\n var icon = null;\n var isBranch = (node.expandable || node.haschildren) ? true : false;\n\n p.addClass('tree_item');\n p.attr('id', id);\n p.attr('role', 'treeitem');\n \/\/ Negative tab index to allow it to receive focus.\n p.attr('tabindex', '-1');\n\n if (node.requiresajaxloading) {\n p.attr('data-requires-ajax', true);\n p.attr('data-node-id', node.id);\n p.attr('data-node-key', node.key);\n p.attr('data-node-type', node.type);\n }\n\n if (isBranch) {\n li.addClass('collapsed contains_branch');\n p.attr('aria-expanded', false);\n p.addClass('branch');\n }\n\n var eleToAddIcon = null;\n if (node.link) {\n var link = $('<\/a>');\n\n eleToAddIcon = link;\n link.append('' + node.name + '<\/span>');\n\n if (node.hidden) {\n link.addClass('dimmed');\n }\n\n p.append(link);\n } else {\n var span = $('<\/span>');\n\n eleToAddIcon = span;\n span.append('' + node.name + '<\/span>');\n\n if (node.hidden) {\n span.addClass('dimmed');\n }\n\n p.append(span);\n }\n\n if (node.icon && (!isBranch || node.type === NODETYPE.ACTIVITY || node.type === NODETYPE.RESOURCE)) {\n li.addClass('item_with_icon');\n p.addClass('hasicon');\n\n if (node.type === NODETYPE.ACTIVITY || node.type === NODETYPE.RESOURCE) {\n icon = $('');\n icon.attr('alt', node.icon.alt);\n icon.attr('title', node.icon.title);\n icon.attr('src', Url.imageUrl(node.icon.pix, node.icon.component));\n $.each(node.icon.classes, function(index, className) {\n icon.addClass(className);\n });\n eleToAddIcon.prepend(icon);\n } else {\n if (node.icon.component == 'moodle') {\n node.icon.component = 'core';\n }\n Templates.renderPix(node.icon.pix, node.icon.component, node.icon.title).then(function(html) {\n \/\/ Prepend.\n eleToAddIcon.prepend(html);\n return;\n }).catch(Notification.exception);\n }\n }\n\n li.append(p);\n ul.append(li);\n\n if (node.children && node.children.length) {\n buildDOM(p, node.children);\n } else if (isBranch && !node.requiresajaxloading) {\n li.removeClass('contains_branch');\n p.addClass('emptybranch');\n }\n });\n\n rootElement.parent().append(ul);\n var id = rootElement.attr('id') + '_group';\n ul.attr('id', id);\n rootElement.attr('aria-owns', id);\n rootElement.attr('role', 'treeitem');\n }\n\n return {\n render: function(element, nodes) {\n \/\/ The first element of the response is the existing node so we start with processing the children.\n if (nodes.children && nodes.children.length) {\n buildDOM(element, nodes.children);\n\n var item = element.children(\"[role='treeitem']\").first();\n var group = element.find('#' + item.attr('aria-owns'));\n\n item.attr('aria-expanded', true);\n group.attr('aria-hidden', false);\n } else {\n if (element.parent().hasClass('contains_branch')) {\n element.parent().removeClass('contains_branch');\n element.addClass('emptybranch');\n }\n }\n }\n };\n});\n"],"names":["define","$","Templates","Notification","Url","NODETYPE","buildDOM","rootElement","nodes","ul","attr","each","index","node","_typeof","li","p","id","key","icon","isBranch","expandable","haschildren","addClass","requiresajaxloading","type","eleToAddIcon","link","title","append","name","hidden","span","alt","imageUrl","pix","component","classes","className","prepend","renderPix","then","html","catch","exception","children","length","removeClass","parent","render","element","item","first","group","find","hasClass"],"mappings":";;;;;;;;;IAwBAA,iDAAO,CAAC,SAAU,iBAAkB,oBAAqB,aAAa,SAASC,EAAGC,UAAWC,aAAcC,SAInGC,kBAEU,GAFVA,kBAIU,YAULC,SAASC,YAAaC,WACvBC,GAAKR,EAAE,aACXQ,GAAGC,KAAK,OAAQ,SAChBD,GAAGC,KAAK,eAAe,GAEvBT,EAAEU,KAAKH,OAAO,SAASI,MAAOC,SACN,WAAhBC,QAAOD,WAIPE,GAAKd,EAAE,aACPe,EAAIf,EAAE,WACNgB,GAAKJ,KAAKI,IAAMJ,KAAKK,IAAM,aAC3BC,KAAO,KACPC,YAAYP,KAAKQ,aAAcR,KAAKS,aAExCN,EAAEO,SAAS,aACXP,EAAEN,KAAK,KAAMO,IACbD,EAAEN,KAAK,OAAQ,YAEfM,EAAEN,KAAK,WAAY,MAEfG,KAAKW,sBACLR,EAAEN,KAAK,sBAAsB,GAC7BM,EAAEN,KAAK,eAAgBG,KAAKI,IAC5BD,EAAEN,KAAK,gBAAiBG,KAAKK,KA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