/* YUI 3.4.1 (build 4118) Copyright 2011 Yahoo! Inc. All rights reserved. Licensed under the BSD License. http://yuilibrary.com/license/ */ YUI.add("attribute-base",function(c){c.State=function(){this.data={};};c.State.prototype={add:function(B,C,E){var D=this.data;D[C]=D[C]||{};D[C][B]=E;},addAll:function(B,D){var C;for(C in D){if(D.hasOwnProperty(C)){this.add(B,C,D[C]);}}},remove:function(B,C){var D=this.data;if(D[C]&&(B in D[C])){delete D[C][B];}},removeAll:function(B,D){var C=this.data;c.each(D||C,function(F,E){if(c.Lang.isString(E)){this.remove(B,E);}else{this.remove(B,F);}},this);},get:function(B,C){var D=this.data;return(D[C]&&B in D[C])?D[C][B]:undefined;},getAll:function(B){var D=this.data,C;c.each(D,function(F,E){if(B in D[E]){C=C||{};C[E]=F[B];}},this);return C;}};var k=c.Object,f=c.Lang,l=c.EventTarget,w=".",t="Change",n="getter",m="setter",o="readOnly",x="writeOnce",u="initOnly",A="validator",h="value",p="valueFn",e="broadcast",r="lazyAdd",j="_bypassProxy",z="added",b="initializing",i="initValue",v="published",s="defaultValue",a="lazy",q="isLazyAdd",g,y={};y[o]=1;y[x]=1;y[n]=1;y[e]=1;function d(C,B,D){var E=this;E._ATTR_E_FACADE={};l.call(E,{emitFacade:true});E._conf=E._state=new c.State();E._stateProxy=E._stateProxy||null;E._requireAddAttr=E._requireAddAttr||false;this._initAttrs(C,B,D);}d.INVALID_VALUE={};g=d.INVALID_VALUE;d._ATTR_CFG=[m,n,A,h,p,x,o,r,e,j];d.prototype={addAttr:function(C,B,E){var F=this,H=F._state,G,D;E=(r in B)?B[r]:E;if(E&&!F.attrAdded(C)){H.add(C,a,B||{});H.add(C,z,true);}else{if(!F.attrAdded(C)||H.get(C,q)){B=B||{};D=(h in B);if(D){G=B.value;delete B.value;}B.added=true;B.initializing=true;H.addAll(C,B);if(D){F.set(C,G);}H.remove(C,b);}}return F;},attrAdded:function(B){return !!this._state.get(B,z);},modifyAttr:function(C,B){var D=this,F,E;if(D.attrAdded(C)){if(D._isLazyAttr(C)){D._addLazyAttr(C);}E=D._state;for(F in B){if(y[F]&&B.hasOwnProperty(F)){E.add(C,F,B[F]);if(F===e){E.remove(C,v);}}}}},removeAttr:function(B){this._state.removeAll(B);},get:function(B){return this._getAttr(B);},_isLazyAttr:function(B){return this._state.get(B,a);},_addLazyAttr:function(C){var D=this._state,B=D.get(C,a);D.add(C,q,true);D.remove(C,a);this.addAttr(C,B);},set:function(B,D,C){return this._setAttr(B,D,C);},reset:function(B){var D=this,C;if(B){if(D._isLazyAttr(B)){D._addLazyAttr(B);}D.set(B,D._state.get(B,i));}else{C=D._state.data.added;c.each(C,function(E,F){D.reset(F);},D);}return D;},_set:function(B,D,C){return this._setAttr(B,D,C,true);},_getAttr:function(D){var E=this,I=D,F=E._state,G,B,H,C;if(D.indexOf(w)!==-1){G=D.split(w);D=G.shift();}if(E._tCfgs&&E._tCfgs[D]){C={};C[D]=E._tCfgs[D];delete E._tCfgs[D];E._addAttrs(C,E._tVals);}if(E._isLazyAttr(D)){E._addLazyAttr(D);}H=E._getStateVal(D);B=F.get(D,n);if(B&&!B.call){B=this[B];}H=(B)?B.call(E,H,I):H;H=(G)?k.getValue(H,G):H;return H;},_setAttr:function(D,G,B,E){var K=true,C=this._state,H=this._stateProxy,M=C.data,J,N,O,F,I,L;if(D.indexOf(w)!==-1){N=D;O=D.split(w);D=O.shift();}if(this._isLazyAttr(D)){this._addLazyAttr(D);}J=(!M.value||!(D in M.value));if(H&&D in H&&!this._state.get(D,j)){J=false;}if(this._requireAddAttr&&!this.attrAdded(D)){}else{I=C.get(D,x);L=C.get(D,b);if(!J&&!E){if(I){K=false;}if(C.get(D,o)){K=false;}}if(!L&&!E&&I===u){K=false;}if(K){if(!J){F=this.get(D);}if(O){G=k.setValue(c.clone(F),O,G);if(G===undefined){K=false;}}if(K){if(L){this._setAttrVal(D,N,F,G);}else{this._fireAttrChange(D,N,F,G,B);}}}}return this;},_fireAttrChange:function(H,G,E,D,B){var J=this,F=H+t,C=J._state,I;if(!C.get(H,v)){J.publish(F,{queuable:false,defaultTargetOnly:true,defaultFn:J._defAttrChangeFn,silent:true,broadcast:C.get(H,e)});C.add(H,v,true);}I=(B)?c.merge(B):J._ATTR_E_FACADE;I.attrName=H;I.subAttrName=G;I.prevVal=E;I.newVal=D;J.fire(F,I);},_defAttrChangeFn:function(B){if(!this._setAttrVal(B.attrName,B.subAttrName,B.prevVal,B.newVal)){B.stopImmediatePropagation();}else{B.newVal=this.get(B.attrName);}},_getStateVal:function(B){var C=this._stateProxy;return C&&(B in C)&&!this._state.get(B,j)?C[B]:this._state.get(B,h);},_setStateVal:function(B,D){var C=this._stateProxy;if(C&&(B in C)&&!this._state.get(B,j)){C[B]=D;}else{this._state.add(B,h,D);}},_setAttrVal:function(M,L,I,G){var O=this,J=true,D=O._state,E=D.get(M,A),H=D.get(M,m),K=D.get(M,b),N=this._getStateVal(M),C=L||M,F,B;if(E){if(!E.call){E=this[E];}if(E){B=E.call(O,G,C);if(!B&&K){G=D.get(M,s);B=true;}}}if(!E||B){if(H){if(!H.call){H=this[H];}if(H){F=H.call(O,G,C);if(F===g){J=false;}else{if(F!==undefined){G=F;}}}}if(J){if(!L&&(G===N)&&!f.isObject(G)){J=false;}else{if(D.get(M,i)===undefined){D.add(M,i,G);}O._setStateVal(M,G);}}}else{J=false;}return J;},setAttrs:function(B,C){return this._setAttrs(B,C);},_setAttrs:function(C,D){for(var B in C){if(C.hasOwnProperty(B)){this.set(B,C[B]);}}return this;},getAttrs:function(B){return this._getAttrs(B);},_getAttrs:function(E){var G=this,I={},F,C,B,H,D=(E===true);E=(E&&!D)?E:k.keys(G._state.data.added);for(F=0,C=E.length;F=0;--t){A=z[t];for(v in A){if(A.hasOwnProperty(v)){u=l({},A[v],x);s=u.value;y=u.cloneDefaultValue;if(s){if((y===undefined&&(a===s.constructor||h.isArray(s)))||y===c||y===true){u.value=d.clone(s);}else{if(y===p){u.value=d.merge(s);}}}B=null;if(v.indexOf(o)!==-1){B=v.split(o);v=B.shift();}if(B&&w[v]&&w[v].value){g.setValue(w[v].value,B,s);}else{if(!B){if(!w[v]){w[v]=u;}else{l(w[v],u,x);}}}}}}}return w;},_initHierarchy:function(y){var u=this._lazyAddAttrs,z,A,C,w,t,B,x,v=this._getClasses(),s=this._getAttrCfgs();for(C=v.length-1;C>=0;C--){z=v[C];A=z.prototype;x=z._yuibuild&&z._yuibuild.exts;if(x){for(w=0,t=x.length;w=0;--m){if(o[m].sub===p){o.splice(m,1);break;}}if(!o.length){delete n[this.key];if(!b.Object.size(n)){delete j[this.domkey];}}},detachAll:function(){var n=this.handles,m=n.length;while(--m>=0){n[m].detach();}}};function a(){this._init.apply(this,arguments);}b.mix(a,{Notifier:h,SynthRegistry:f,getRegistry:function(s,r,p){var q=s._node,o=b.stamp(q),n="event:"+o+r+"_synth",m=j[o];if(p){if(!m){m=j[o]={};}if(!m[n]){m[n]=new f(q,o,n);}}return(m&&m[n])||null;},_deleteSub:function(n){if(n&&n.fn){var m=this.eventDef,o=(n.filter)?"detachDelegate":"detach";this.subscribers={};this.subCount=0;m[o](n.node,n,this.notifier,n.filter);this.registry.unregister(n);delete n.fn;delete n.node;delete n.context;}},prototype:{constructor:a,_init:function(){var m=this.publishConfig||(this.publishConfig={});this.emitFacade=("emitFacade" in m)?m.emitFacade:true;m.emitFacade=false;},processArgs:k,on:k,detach:k,delegate:k,detachDelegate:k,_on:function(s,t){var u=[],o=s.slice(),p=this.processArgs(s,t),q=s[2],m=t?"delegate":"on",n,r;n=(c(q))?g(q):d(q||b.one(b.config.win));if(!n.length&&c(q)){r=b.on("available",function(){b.mix(r,b[m].apply(b,o),true);},q);return r;}b.Array.each(n,function(w){var x=s.slice(),v;w=b.one(w);if(w){if(t){v=x.splice(3,1)[0];}x.splice(0,4,x[1],x[3]);if(!this.preventDups||!this.getSubs(w,s,null,true)){u.push(this._subscribe(w,m,x,p,v));}}},this);return(u.length===1)?u[0]:new b.EventHandle(u);},_subscribe:function(q,o,t,r,p){var v=new b.CustomEvent(this.type,this.publishConfig),s=v.on.apply(v,t),u=new h(s,this.emitFacade),n=a.getRegistry(q,this.type,true),m=s.sub;m.node=q;m.filter=p;if(r){this.applyArgExtras(r,m);}b.mix(v,{eventDef:this,notifier:u,host:q,currentTarget:q,target:q,el:q._node,_delete:a._deleteSub},true);s.notifier=u;n.register(s);this[o](q,m,u,p);return s;},applyArgExtras:function(m,n){n._extra=m;},_detach:function(o){var t=o[2],r=(c(t))?g(t):d(t),s,q,m,p,n;o.splice(2,1);for(q=0,m=r.length;q=0;--n){p[n].detach();}}}}},getSubs:function(o,u,n,q){var m=a.getRegistry(o,this.type),v=[],t,p,s,r;if(m){t=m.handles;if(!n){n=this.subMatch;}for(p=0,s=t.length;p 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'); 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') == 40)) { 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 == 20) { coursecount++; } this.addChild(object.children[i]); } } if (this.get('type') == 10 && 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 == 20) { count++; } if (typeof(children[i])=='object') { branch.addChild(children[i]); } } if (branch.get('type') == 10 && count >= M.block_navigation.courselimit) { this.addViewAllCoursesChild(branch); } } return true; }, /** * Add a link to view all courses in a category */ addViewAllCoursesChild: function(branch) { branch.addChild({ name : M.str.moodle.viewallcourses, title : M.str.moodle.viewallcourses, link : M.cfg.wwwroot+'/course/category.php?id='+branch.get('key'), 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', 'node', 'dom', 'event-custom', 'event-delegate', 'json-parse']});