/* YUI 3.7.3 (build 5687) Copyright 2012 Yahoo! Inc. All rights reserved. Licensed under the BSD License. http://yuilibrary.com/license/ */ YUI.add("attribute-core",function(e,t){function E(e,t,n){this._initAttrHost(e,t,n)}e.State=function(){this.data={}},e.State.prototype={add:function(e,t,n){var r=this.data[e];r||(r=this.data[e]={}),r[t]=n},addAll:function(e,t){var n=this.data[e],r;n||(n=this.data[e]={});for(r in t)t.hasOwnProperty(r)&&(n[r]=t[r])},remove:function(e,t){var n=this.data[e];n&&delete n[t]},removeAll:function(t,n){var r;n?e.each(n,function(e,n){this.remove(t,typeof n=="string"?n:e)},this):(r=this.data,t in r&&delete r[t])},get:function(e,t){var n=this.data[e];if(n)return n[t]},getAll:function(e,t){var n=this.data[e],r,i;if(t)i=n;else if(n){i={};for(r in n)n.hasOwnProperty(r)&&(i[r]=n[r])}return i}};var n=e.Object,r=e.Lang,i=".",s="getter",o="setter",u="readOnly",a="writeOnce",f="initOnly",l="validator",c="value",h="valueFn",p="lazyAdd",d="added",v="_bypassProxy",m="initializing",g="initValue",y="lazy",b="isLazyAdd",w;E.INVALID_VALUE={},w=E.INVALID_VALUE,E._ATTR_CFG=[o,s,l,c,h,a,u,p,v],E.prototype={_initAttrHost:function(t,n,r){this._state=new e.State,this._initAttrs(t,n,r)},addAttr:function(e,t,n){var r=this,i=r._state,s,o;t=t||{},n=p in t?t[p]:n;if(n&&!r.attrAdded(e))i.addAll(e,{lazy:t,added:!0});else if(!r.attrAdded(e)||i.get(e,b))o=c in t,o&&(s=t.value,delete t.value),t.added=!0,t.initializing=!0,i.addAll(e,t),o&&r.set(e,s),i.remove(e,m);return r},attrAdded:function(e){return!!this._state.get(e,d)},get:function(e){return this._getAttr(e)},_isLazyAttr:function(e){return this._state.get(e,y)},_addLazyAttr:function(e,t){var n=this._state,r=n.get(e,y);n.add(e,b,!0),n.remove(e,y),this.addAttr(e,r)},set:function(e,t){return this._setAttr(e,t)},_set:function(e,t){return this._setAttr(e,t,null,!0)},_setAttr:function(t,r,s,o){var u=!0,a=this._state,l=this._stateProxy,h,p,d,v,m,g,y;return t.indexOf(i)!==-1&&(d=t,v=t.split(i),t=v.shift()),this._isLazyAttr(t)&&this._addLazyAttr(t),h=a.getAll(t,!0)||{},p=!(c in h),l&&t in l&&!h._bypassProxy&&(p=!1),g=h.writeOnce,y=h.initializing,!p&&!o&&(g&&(u=!1),h.readOnly&&(u=!1)),!y&&!o&&g===f&&(u=!1),u&&(p||(m=this.get(t)),v&&(r=n.setValue(e.clone(m),v,r),r===undefined&&(u=!1)),u&&(!this._fireAttrChange||y?this._setAttrVal(t,d,m,r):this._fireAttrChange(t,d,m,r,s))),this},_getAttr:function(e){var t=this,r=e,o=t._state,u,a,f,l;return e.indexOf(i)!==-1&&(u=e.split(i),e=u.shift()),t._tCfgs&&t._tCfgs[e]&&(l={},l[e]=t._tCfgs[e],delete t._tCfgs[e],t._addAttrs(l,t._tVals)),t._isLazyAttr(e)&&t._addLazyAttr(e),f=t._getStateVal(e),a=o.get(e,s),a&&!a.call&&(a=this[a]),f=a?a.call(t,f,r):f,f=u?n.getValue(f,u):f,f},_getStateVal:function(e){var t=this._stateProxy;return t&&e in t&&!this._state.get(e,v)?t[e]:this._state.get(e,c)},_setStateVal:function(e,t){var n=this._stateProxy;n&&e in n&&!this._state.get(e,v)?n[e]=t:this._state.add(e,c,t)},_setAttrVal:function(e,t,n,i){var s=this,o=!0,u=this._state.getAll(e,!0)||{},a=u.validator,f=u.setter,l=u.initializing,c=this._getStateVal(e),h=t||e,p,d;return a&&(a.call||(a=this[a]),a&&(d=a.call(s,i,h),!d&&l&&(i=u.defaultValue,d=!0))),!a||d?(f&&(f.call||(f=this[f]),f&&(p=f.call(s,i,h),p===w?o=!1:p!==undefined&&(i=p))),o&&(!t&&i===c&&!r.isObject(i)?o=!1:(g in u||(u.initValue=i),s._setStateVal(e,i)))):o=!1,o},setAttrs:function(e){return this._setAttrs(e)},_setAttrs:function(e){var t;for(t in e)e.hasOwnProperty(t)&&this.set(t,e[t]);return this},getAttrs:function(e){return this._getAttrs(e)},_getAttrs:function(e){var t={},r,i,s,o=e===!0;if(!e||o)e=n.keys(this._state.data);for(i=0,s=e.length;i=0;--v){o=t[v];for(s in o)o.hasOwnProperty(s)&&(u=d({},o[s],g),h=u.value,m=u.cloneDefaultValue,h&&(m===undefined&&(f===h.constructor||r.isArray(h))||m===l||m===!0?u.value=e.clone(h):m===c&&(u.value=e.merge(h))),p=null,s.indexOf(i)!==-1&&(p=s.split(i),s=p.shift()),y=b[s],p&&y&&y.value?n.setValue(y.value,p,h):p||(y?(y.valueFn&&a in u&&(y.valueFn=null),d(y,u,g)):b[s]=u))}return b},_initHierarchy:function(e){var t=this._lazyAddAttrs,n,r,i,s,o,a,f,l=this._getClasses(),c=this._getAttrCfgs(),h=l.length-1;for(i=h;i>=0;i--){n=l[i],r=n.prototype,f=n._yuibuild&&n._yuibuild.exts;if(f)for(s=0,o=f.length;s=0;--s)if(n[s].sub===t){n.splice(s,1);break}n.length||(delete i[this.key],e.Object.size(i)||delete r[this.domkey])},detachAll:function(){var e=this.handles,t=e.length;while(--t>=0)e[t].detach()}},e.mix(p,{Notifier:c,SynthRegistry:h,getRegistry:function(t,n,i){var s=t._node,o=e.stamp(s),u="event:"+o+n+"_synth",a=r[o];return i&&(a||(a=r[o]={}),a[u]||(a[u]=new h(s,o,u))),a&&a[u]||null},_deleteSub:function(e){if(e&&e.fn){var t=this.eventDef,r=e.filter?"detachDelegate":"detach";this._subscribers=[],n.keepDeprecatedSubs&&(this.subscribers={}),t[r](e.node,e,this.notifier,e.filter),this.registry.unregister(e),delete e.fn,delete e.node,delete e.context}},prototype:{constructor:p,_init:function(){var e=this.publishConfig||(this.publishConfig={});this.emitFacade="emitFacade"in e?e.emitFacade:!0,e.emitFacade=!1},processArgs:l,on:l,detach:l,delegate:l,detachDelegate:l,_on:function(t,n){var r=[],s=t.slice(),o=this.processArgs(t,n),a=t[2],l=n?"delegate":"on",c,h;return c=u(a)?f(a):i(a||e.one(e.config.win)),!c.length&&u(a)?(h=e.on("available",function(){e.mix(h,e[l].apply(e,s),!0)},a),h):(e.Array.each(c,function(i){var s=t.slice(),u;i=e.one(i),i&&(n&&(u=s.splice(3,1)[0]),s.splice(0,4,s[1],s[3]),(!this.preventDups||!this.getSubs(i,t,null,!0))&&r.push(this._subscribe(i,l,s,o,u)))},this),r.length===1?r[0]:new e.EventHandle(r))},_subscribe:function(t,n,r,i,s){var o=new e.CustomEvent(this.type,this.publishConfig),u=o.on.apply(o,r),a=new c(u,this.emitFacade),f=p.getRegistry(t,this.type,!0),l=u.sub;return l.node=t,l.filter=s,i&&this.applyArgExtras(i,l),e.mix(o,{eventDef:this,notifier:a,host:t,currentTarget:t,target:t,el:t._node,_delete:p._deleteSub},!0),u.notifier=a,f.register(u),this[n](t,l,a,s),u},applyArgExtras:function(e,t){t._extra=e},_detach:function(t){var n=t[2],r=u(n)?f(n):i(n),s,o,a,l,c;t.splice(2,1);for(o=0,a=r.length;o=0;--c)l[c].detach()}}},getSubs:function(e,t,n,r){var i=p.getRegistry(e,this.type),s=[],o,u,a,f;if(i){o=i.handles,n||(n=this.subMatch);for(u=0,a=o.length;u 0)); } if (config.overrides !== null) { // Construct from the provided xml for (var i in config.overrides) { this.set(i, config.overrides[i]); } } // Get the node for this branch this.node = Y.one('#', this.get('id')); // Now check whether the branch is not expandable because of the expansionlimit var expansionlimit = this.get('tree').get('expansionlimit'); var type = this.get('type'); if (expansionlimit != EXPANSIONLIMIT_EVERYTHING && type >= expansionlimit && type <= EXPANSIONLIMIT_ACTIVITY) { this.set('expandable', false); this.set('haschildren', false); } }, /** * Draws the branch within the tree. * * This function creates a DOM structure for the branch and then injects * it into the navigation tree at the correct point. */ draw : function(element) { var isbranch = (this.get('expandable') || this.get('haschildren')); var branchli = Y.Node.create('
  • '); var link = this.get('link'); var branchp = Y.Node.create('

    ').setAttribute('id', this.get('id')); if (!link) { //add tab focus if not link (so still one focus per menu node). // it was suggested to have 2 foci. one for the node and one for the link in MDL-27428. branchp.setAttribute('tabindex', '0'); } if (isbranch) { branchli.addClass('collapsed').addClass('contains_branch'); branchli.set('aria-expanded', false); branchp.addClass('branch'); } // Prepare the icon, should be an object representing a pix_icon var branchicon = false; var icon = this.get('icon'); if (icon && (!isbranch || this.get('type') == NODETYPE.ACTIVITY)) { branchicon = Y.Node.create(''); branchicon.setAttribute('src', M.util.image_url(icon.pix, icon.component)); branchli.addClass('item_with_icon'); if (icon.alt) { branchicon.setAttribute('alt', icon.alt); } if (icon.title) { branchicon.setAttribute('title', icon.title); } if (icon.classes) { for (var i in icon.classes) { branchicon.addClass(icon.classes[i]); } } } if (!link) { if (branchicon) { branchp.appendChild(branchicon); } branchp.append(this.get('name')); } else { var branchlink = Y.Node.create(''); if (branchicon) { branchlink.appendChild(branchicon); } branchlink.append(this.get('name')); if (this.get('hidden')) { branchlink.addClass('dimmed'); } branchp.appendChild(branchlink); } branchli.appendChild(branchp); element.appendChild(branchli); this.node = branchp; return this; }, /** * Attaches required events to the branch structure. */ wire : function() { this.node = this.node || Y.one('#'+this.get('id')); if (!this.node) { return false; } if (this.get('expandable')) { this.event_ajaxload = this.node.on('ajaxload|click', this.ajaxLoad, this); this.event_ajaxload_actionkey = this.node.on('actionkey', this.ajaxLoad, this); } return this; }, /** * Gets the UL element that children for this branch should be inserted into. */ getChildrenUL : function() { var ul = this.node.next('ul'); if (!ul) { ul = Y.Node.create('
      '); this.node.ancestor().append(ul); } return ul; }, /** * Load the content of the branch via AJAX. * * This function calls ajaxProcessResponse with the result of the AJAX * request made here. */ ajaxLoad : function(e) { if (e.type == 'actionkey' && e.action != 'enter') { e.halt(); } else { e.stopPropagation(); } if (e.type = 'actionkey' && e.action == 'enter' && e.target.test('A')) { this.event_ajaxload_actionkey.detach(); this.event_ajaxload.detach(); return true; // no ajaxLoad for enter } if (this.node.hasClass('loadingbranch')) { return true; } this.node.addClass('loadingbranch'); var params = { elementid : this.get('id'), id : this.get('key'), type : this.get('type'), sesskey : M.cfg.sesskey, instance : this.get('tree').get('instance') }; Y.io(M.cfg.wwwroot+'/lib/ajax/getnavbranch.php', { method:'POST', data: build_querystring(params), on: { complete: this.ajaxProcessResponse }, context:this }); return true; }, /** * Processes an AJAX request to load the content of this branch through * AJAX. */ ajaxProcessResponse : function(tid, outcome) { this.node.removeClass('loadingbranch'); this.event_ajaxload.detach(); this.event_ajaxload_actionkey.detach(); try { var object = Y.JSON.parse(outcome.responseText); if (object.children && object.children.length > 0) { var coursecount = 0; for (var i in object.children) { if (typeof(object.children[i])=='object') { if (object.children[i].type == NODETYPE.COURSE) { coursecount++; } this.addChild(object.children[i]); } } if ((this.get('type') == NODETYPE.CATEGORY || this.get('type') == NODETYPE.ROOTNODE) && coursecount >= M.block_navigation.courselimit) { this.addViewAllCoursesChild(this); } this.get('tree').toggleExpansion({target:this.node}); return true; } } catch (ex) { // If we got here then there was an error parsing the result } // The branch is empty so class it accordingly this.node.replaceClass('branch', 'emptybranch'); return true; }, /** * Turns the branch object passed to the method into a proper branch object * and then adds it as a child of this branch. */ addChild : function(branchobj) { // Make the new branch into an object var branch = new BRANCH({tree:this.get('tree'), branchobj:branchobj}); if (branch.draw(this.getChildrenUL())) { branch.wire(); var count = 0, i, children = branch.get('children'); for (i in children) { // Add each branch to the tree if (children[i].type == NODETYPE.COURSE) { count++; } if (typeof(children[i])=='object') { branch.addChild(children[i]); } } if (branch.get('type') == NODETYPE.CATEGORY && count >= M.block_navigation.courselimit) { this.addViewAllCoursesChild(branch); } } return true; }, /** * Add a link to view all courses in a category */ addViewAllCoursesChild: function(branch) { var url = null; if (branch.get('type') == NODETYPE.ROOTNODE) { if (branch.get('key') === 'mycourses') { url = M.cfg.wwwroot + '/my'; } else { url = M.cfg.wwwroot + '/course/index.php'; } } else { url = M.cfg.wwwroot+'/course/category.php?id=' + branch.get('key'); } branch.addChild({ name : M.str.moodle.viewallcourses, title : M.str.moodle.viewallcourses, link : url, haschildren : false, icon : {'pix':"i/navigationitem",'component':'moodle'} }); } } Y.extend(BRANCH, Y.Base, BRANCH.prototype, { NAME : 'navigation-branch', ATTRS : { tree : { validator : Y.Lang.isObject }, name : { value : '', validator : Y.Lang.isString, setter : function(val) { return val.replace(/\n/g, '
      '); } }, title : { value : '', validator : Y.Lang.isString }, id : { value : '', validator : Y.Lang.isString, getter : function(val) { if (val == '') { val = 'expandable_branch_'+M.block_navigation.expandablebranchcount; M.block_navigation.expandablebranchcount++; } return val; } }, key : { value : null }, type : { value : null }, link : { value : false }, icon : { value : false, validator : Y.Lang.isObject }, expandable : { value : false, validator : Y.Lang.isBool }, hidden : { value : false, validator : Y.Lang.isBool }, haschildren : { value : false, validator : Y.Lang.isBool }, children : { value : [], validator : Y.Lang.isArray } } }); /** * This namespace will contain all of the contents of the navigation blocks * global navigation and settings. * @namespace */ M.block_navigation = M.block_navigation || { /** The number of expandable branches in existence */ expandablebranchcount:1, courselimit : 20, instance : null, /** * Add new instance of navigation tree to tree collection */ init_add_tree:function(properties) { if (properties.courselimit) { this.courselimit = properties.courselimit; } if (M.core_dock) { M.core_dock.init(Y); } new TREE(properties); } }; }, '@VERSION@', {requires:['base', 'core_dock', 'io-base', 'node', 'dom', 'event-custom', 'event-delegate', 'json-parse']});