From: moodler Date: Sat, 23 Sep 2006 14:34:59 +0000 (+0000) Subject: Just tidying up the code X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=354e11303e93ed7ad09fb47193fc02853676187c;p=moodle.git Just tidying up the code --- diff --git a/lib/ajax/section_classes.php b/lib/ajax/section_classes.php index 57cddad47f..4d373077f8 100755 --- a/lib/ajax/section_classes.php +++ b/lib/ajax/section_classes.php @@ -18,436 +18,425 @@ * library for ajaxcourse formats, the classes and related functions for sections and resources * this library requires a 'main' object created in calling document */ - - -function section_class(id,group,config,isDraggable){ + + +function section_class(id,group,config,isDraggable) { this.init_section(id,group,config,isDraggable); } YAHOO.extend(section_class, YAHOO.util.DDProxy); section_class.prototype.debug = false; -section_class.prototype.init_section = function(id, group,config,isDraggable){ - if (!id) { return; } - - this.is = 'section'; - this.sectionId = null; - - - if(!isDraggable){ - this.initTarget(id,group,config); - this.removeFromGroup('sections'); - }else{ - this.init(id,group,config); - this.handle = null; - } - - this.createFrame(); - this.isTarget = true; - - this.resources = []; - this.numberDisplay = null; - this.summary = null; - this.content_td = null; - this.hidden = false; - this.highlighted = false; - this.showOnly = false; - this.resources_ul = null; - this.process_section(); - - this.viewButton = null; - this.highlightButton = null; - this.showOnlyButton = null; - this.init_buttons(); - - if(isDraggable)this.add_handle(); - - if(this.debug)YAHOO.log("init_section "+id+" draggable="+isDraggable); - - - if(YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) - this.toggle_hide(null,null,true); - +section_class.prototype.init_section = function(id, group,config,isDraggable) { + if (!id) { return; } + + this.is = 'section'; + this.sectionId = null; + + + if (!isDraggable) { + this.initTarget(id,group,config); + this.removeFromGroup('sections'); + } else { + this.init(id,group,config); + this.handle = null; } - -section_class.prototype.init_buttons = function(){ - var commandContainer = this.getEl().childNodes[2]; - - //clear all but show only button - var commandContainerCount = commandContainer.childNodes.length; - for(var i=(commandContainerCount-1);i>0;i--) - commandContainer.removeChild(commandContainer.childNodes[i]) - - - if(!this.isWeekFormat){ - var highlightbutton = main.mk_button('div','/pix/i/marker.gif'); - YAHOO.util.Event.addListener(highlightbutton,'click',this.mk_marker,this,true); - commandContainer.appendChild(highlightbutton); - this.highlightButton = highlightbutton; - } - var viewbutton = main.mk_button('div','/pix/i/hide.gif'); - YAHOO.util.Event.addListener(viewbutton,'click',this.toggle_hide,this,true); - commandContainer.appendChild(viewbutton); - this.viewButton = viewbutton; - + + this.createFrame(); + this.isTarget = true; + + this.resources = []; + this.numberDisplay = null; + this.summary = null; + this.content_td = null; + this.hidden = false; + this.highlighted = false; + this.showOnly = false; + this.resources_ul = null; + this.process_section(); + + this.viewButton = null; + this.highlightButton = null; + this.showOnlyButton = null; + this.init_buttons(); + + if (isDraggable)this.add_handle(); + + if (this.debug)YAHOO.log("init_section "+id+" draggable="+isDraggable); + + + if (YAHOO.util.Dom.hasClass(this.getEl(),'hidden')) + this.toggle_hide(null,null,true); + +} + +section_class.prototype.init_buttons = function() { + var commandContainer = this.getEl().childNodes[2]; + + //clear all but show only button + var commandContainerCount = commandContainer.childNodes.length; + for (var i=(commandContainerCount-1);i>0;i--) { + commandContainer.removeChild(commandContainer.childNodes[i]) } + if (!this.isWeekFormat) { + var highlightbutton = main.mk_button('div','/pix/i/marker.gif'); + YAHOO.util.Event.addListener(highlightbutton,'click',this.mk_marker,this,true); + commandContainer.appendChild(highlightbutton); + this.highlightButton = highlightbutton; + } + var viewbutton = main.mk_button('div','/pix/i/hide.gif'); + YAHOO.util.Event.addListener(viewbutton,'click',this.toggle_hide,this,true); + commandContainer.appendChild(viewbutton); + this.viewButton = viewbutton; +} + -section_class.prototype.add_handle = function(){ - var handleRef = main.mk_button('div','/pix/i/move_2d.gif',[['style','cursor:move']]); - YAHOO.util.Dom.generateId(handleRef,'sectionHandle'); +section_class.prototype.add_handle = function() { + var handleRef = main.mk_button('div','/pix/i/move_2d.gif',[['style','cursor:move']]); + YAHOO.util.Dom.generateId(handleRef,'sectionHandle'); + + this.handle = handleRef; + + this.getEl().childNodes[0].appendChild(handleRef); + this.setHandleElId(this.handle.id); +} - this.handle = handleRef; - - this.getEl().childNodes[0].appendChild(handleRef); - this.setHandleElId(this.handle.id); + +section_class.prototype.process_section = function() { + this.content_td = this.getEl().childNodes[1]; + + if (YAHOO.util.Dom.hasClass(this.getEl(),'current')) { + this.highlighted = true; + main.marker = this; } - - -section_class.prototype.process_section = function(){ - this.content_td = this.getEl().childNodes[1]; - - - if(YAHOO.util.Dom.hasClass(this.getEl(),'current')){ - this.highlighted = true; - main.marker = this; - } - - - //create holder for display number for access later - - this.numberDisplay = document.createElement('div'); - this.numberDisplay.innerHTML = this.getEl().childNodes[0].innerHTML; - this.getEl().childNodes[0].innerHTML = ''; - this.getEl().childNodes[0].appendChild(this.numberDisplay); - - this.sectionId = this.numberDisplay.innerHTML; - - if(this.debug)YAHOO.log("Creating section "+this.getEl().id+" in position "+this.sectionId); - //find/edit resources - - this.resources_ul = this.content_td.getElementsByTagName('ul')[0]; - if(this.resources_ul == null){ - this.resources_ul = document.createElement('ul'); - this.resources_ul.className='section'; - this.content_td.insertBefore(this.resources_ul,this.content_td.childNodes[1]); - } - - var resource_count = this.resources_ul.getElementsByTagName('li').length; - - - for(var i=0;i 0 && childIndex < this.resources_ul.childNodes.length) - this.resources_ul.removeChild(this.resources_ul.childNodes[childIndex-1]); - YAHOO.log("removing "+el.getEl().id); - if(el.getEl().parentNode != null) - el.getEl().parentNode.removeChild(el.getEl()); - - this.write_sequence_list(); - - } - -section_class.prototype.insert_resource = function(el,targetel){ - var resourcecount = this.resources.length; - var found = false; - var tempStore = nextStore = null; - - //update in backend - targetId=''; - if(targetel !=null){ - targetId=targetel.id; - } - - main.connect('post','class=resource&field=move',null,'id='+el.id+'&beforeId='+targetId+'§ionId='+this.sectionId); - - - - //if inserting into a hidden resource hide - if(this.hidden){ - el.hiddenStored = el.hidden; - el.toggle_hide(null,null,true,true); - }else{ - if(el.hiddenStored != null){ - el.toggle_hide(null,null,true,el.hiddenStored); - el.hiddenStored = null; - } + } + + + //remove "text" nodes to keep DOM clean + var childIndex = null; + var childrenCount = this.resources_ul.childNodes.length; + for (var i=0;i 0 && childIndex < this.resources_ul.childNodes.length) + this.resources_ul.removeChild(this.resources_ul.childNodes[childIndex-1]); + YAHOO.log("removing "+el.getEl().id); + if (el.getEl().parentNode != null) + el.getEl().parentNode.removeChild(el.getEl()); + + this.write_sequence_list(); + +} + +section_class.prototype.insert_resource = function(el,targetel) { + var resourcecount = this.resources.length; + var found = false; + var tempStore = nextStore = null; + + //update in backend + targetId=''; + if (targetel !=null) { + targetId=targetel.id; + } + + main.connect('post','class=resource&field=move',null,'id='+el.id+'&beforeId='+targetId+'§ionId='+this.sectionId); + + + + //if inserting into a hidden resource hide + if (this.hidden) { + el.hiddenStored = el.hidden; + el.toggle_hide(null,null,true,true); + } else { + if (el.hiddenStored != null) { + el.toggle_hide(null,null,true,el.hiddenStored); + el.hiddenStored = null; } - - //update model - if(targetel == null){ - this.resources[this.resources.length] = el; - }else - for(var i=0;i 2) - this.currentGroup = 0; - - this.groupButton.getElementsByTagName('img')[0].src = main.portal.wwwroot + this.groupImages[this.currentGroup]; - - main.connect('post','class=resource&field=groupmode',null,'value='+this.currentGroup+'&id='+this.id); - } - + + var groupNodeArray = document.getElementById(id).getElementsByTagName('a'); + var groupNode = groupNodeArray[groupNodeArray.length-1]; + + for (var x=0;x 2) + this.currentGroup = 0; + + this.groupButton.getElementsByTagName('img')[0].src = main.portal.wwwroot + this.groupImages[this.currentGroup]; + + main.connect('post','class=resource&field=groupmode',null,'value='+this.currentGroup+'&id='+this.id); +}