1 M.block_course_overview = {}
3 M.block_course_overview.add_handles = function(Y) {
4 M.block_course_overview.Y = Y;
10 YUI().use('dd-constrain', 'dd-proxy', 'dd-drop', 'dd-plugin', function(Y) {
12 var goingUp = false, lastY = 0;
14 var list = Y.Node.all('.course_list .coursebox');
15 list.each(function(v, k) {
16 // Replace move link and image with move_2d image.
17 var imagenode = v.one('.course_title .move a img');
18 imagenode.setAttribute('src', M.util.image_url(MOVEICON.pix, MOVEICON.component));
19 imagenode.addClass('cursor');
20 v.one('.course_title .move a').replace(imagenode);
22 var dd = new Y.DD.Drag({
27 }).plug(Y.Plugin.DDProxy, {
29 }).plug(Y.Plugin.DDConstrained, {
30 constrain2node: '.course_list'
32 dd.addHandle('.course_title .move');
35 Y.DD.DDM.on('drag:start', function(e) {
38 //Set some styles here
39 drag.get('node').setStyle('opacity', '.25');
40 drag.get('dragNode').addClass('block_course_overview');
41 drag.get('dragNode').set('innerHTML', drag.get('node').get('innerHTML'));
42 drag.get('dragNode').setStyles({
44 borderColor: drag.get('node').getStyle('borderColor'),
45 backgroundColor: drag.get('node').getStyle('backgroundColor')
49 Y.DD.DDM.on('drag:end', function(e) {
52 drag.get('node').setStyles({
56 M.block_course_overview.save(Y);
59 Y.DD.DDM.on('drag:drag', function(e) {
60 //Get the last y point
61 var y = e.target.lastXY[1];
62 //is it greater than the lastY var?
70 //Cache for next check
74 Y.DD.DDM.on('drop:over', function(e) {
75 //Get a reference to our drag and drop nodes
76 var drag = e.drag.get('node'),
77 drop = e.drop.get('node');
79 //Are we dropping on a li node?
80 if (drop.hasClass('coursebox')) {
81 //Are we not going up?
83 drop = drop.get('nextSibling');
85 //Add the node to this list
86 e.drop.get('node').get('parentNode').insertBefore(drag, drop);
87 //Resize this nodes shim, so we can drop on it later.
92 Y.DD.DDM.on('drag:drophit', function(e) {
93 var drop = e.drop.get('node'),
94 drag = e.drag.get('node');
96 //if we are not on an li, we must have been dropped on a ul
97 if (!drop.hasClass('coursebox')) {
98 if (!drop.contains(drag)) {
99 drop.appendChild(drag);
106 M.block_course_overview.save = function() {
107 var Y = M.block_course_overview.Y;
108 var sortorder = Y.one('.course_list').get('children').getAttribute('id');
109 for (var i = 0; i < sortorder.length; i++) {
110 sortorder[i] = sortorder[i].substring(7);
113 sesskey : M.cfg.sesskey,
114 sortorder : sortorder
116 Y.io(M.cfg.wwwroot+'/blocks/course_overview/save.php', {
118 data: build_querystring(params),
124 * Init a collapsible region, see print_collapsible_region in weblib.php
125 * @param {YUI} Y YUI3 instance with all libraries loaded
126 * @param {String} id the HTML id for the div.
127 * @param {String} userpref the user preference that records the state of this box. false if none.
128 * @param {String} strtooltip
130 M.block_course_overview.collapsible = function(Y, id, userpref, strtooltip) {
132 M.block_course_overview.userpref = true;
134 Y.use('anim', function(Y) {
135 new M.block_course_overview.CollapsibleRegion(Y, id, userpref, strtooltip);
140 * Object to handle a collapsible region : instantiate and forget styled object
144 * @param {YUI} Y YUI3 instance with all libraries loaded
145 * @param {String} id The HTML id for the div.
146 * @param {String} userpref The user preference that records the state of this box. false if none.
147 * @param {String} strtooltip
149 M.block_course_overview.CollapsibleRegion = function(Y, id, userpref, strtooltip) {
150 // Record the pref name
151 this.userpref = userpref;
153 // Find the divs in the document.
154 this.div = Y.one('#'+id);
156 // Get the caption for the collapsible region
157 var caption = this.div.one('#'+id + '_caption');
158 caption.setAttribute('title', strtooltip);
161 var a = Y.Node.create('<a href="#"></a>');
162 // Create a local scoped lamba function to move nodes to a new link
163 var movenode = function(node){
167 // Apply the lamba function on each of the captions child nodes
168 caption.get('children').each(movenode, this);
171 // Get the height of the div at this point before we shrink it if required
172 var height = this.div.get('offsetHeight');
173 if (this.div.hasClass('collapsed')) {
174 // Shrink the div as it is collapsed by default
175 this.div.setStyle('height', caption.get('offsetHeight')+'px');
178 // Create the animation.
179 var animation = new Y.Anim({
182 easing: Y.Easing.easeBoth,
183 to: {height:caption.get('offsetHeight')},
184 from: {height:height}
187 // Handler for the animation finishing.
188 animation.on('end', function() {
189 this.div.toggleClass('collapsed');
192 // Hook up the event handler.
193 caption.on('click', function(e, animation) {
195 // Animate to the appropriate size.
196 if (animation.get('running')) {
199 animation.set('reverse', this.div.hasClass('collapsed'));
200 // Update the user preference.
202 M.util.set_user_preference(this.userpref, !this.div.hasClass('collapsed'));
208 M.block_course_overview.userpref = false;
211 * The user preference that stores the state of this box.
215 M.block_course_overview.CollapsibleRegion.prototype.userpref = null;
218 * The key divs that make up this
222 M.block_course_overview.CollapsibleRegion.prototype.div = null;
225 * The key divs that make up this
229 M.block_course_overview.CollapsibleRegion.prototype.icon = null;