Permalink
Browse files

MDL-11131 - fixed the weight of sticky blocks as it moved around.

  • Loading branch information...
1 parent e3fb0b7 commit 1833b24abb2d713a8b3fc7366e0e8fde2d14bcd0 Rossiani Wijaya committed Jan 20, 2010
Showing with 121 additions and 86 deletions.
  1. +3 −1 course/rest.php
  2. +50 −39 lib/ajax/block_classes.js
  3. +68 −46 lib/blocklib.php
View
@@ -21,6 +21,8 @@
$sequence = optional_param('sequence', '', PARAM_SEQUENCE);
$visible = optional_param('visible', 0, PARAM_INT);
$pageaction = optional_param('action', '', PARAM_ALPHA); // Used to simulate a DELETE command
+$positiontoinsert = optional_param('positiontoinsert', '', PARAM_ALPHA);
+$positiontoinsertid = optional_param('positiontoinsertid', '', PARAM_RAW);
// Authorise the user and verify some incoming data
if (!$course = get_record('course', 'id', $courseid)) {
@@ -234,7 +236,7 @@
case 'DELETE':
switch ($class) {
case 'block':
- blocks_execute_action($PAGE, $pageblocks, 'delete', $blockinstance);
+ blocks_execute_action($PAGE, $pageblocks, 'delete', $blockinstance, false, false);
break;
case 'resource':
@@ -68,8 +68,8 @@ block_class.prototype.startDrag = function(x, y) {
var dragEl = this.getDragEl();
var clickEl = this.getEl();
- dragEl.innerHTML = clickEl.innerHTML;
- dragEl.className = clickEl.className;
+ dragEl.innerHTML = clickEl.innerHTML;
+ dragEl.className = clickEl.className;
dragEl.style.color = this.DDM.getStyle(clickEl, "color");;
dragEl.style.backgroundColor = this.DDM.getStyle(clickEl, "backgroundColor");
dragEl.style.border = '0px';
@@ -83,14 +83,14 @@ block_class.prototype.startDrag = function(x, y) {
//restyle side boxes to highlight
for (var i=0; i<targets.length; i++) {
-
+
var targetEl = targets[i].getEl();
targetEl.style.background = "#fefff0";
targetEl.opacity = .3;
targetEl.filter = "alpha(opacity=30)";
}
- }
+}
block_class.prototype.endDrag = function() {
// reset the linked element styles
@@ -110,31 +110,31 @@ block_class.prototype.onDragDrop = function(e, id) {
} else {
oDD = YAHOO.util.DDM.getBestMatch(id);
}
-
- var el = this.getEl();
+ var el = this.getEl();
+
if (this.debug) {
YAHOO.log("id="+id+" el="+e+" x="+YAHOO.util.Dom.getXY(this.getDragEl()));
}
//var collisions = this.find_collisions(e,id);
this.move_block(id);
//YAHOO.util.DDM.moveToEl(el, oDD.getEl());
-
+
this.resetTargets();
}
block_class.prototype.find_target = function(column){
var collisions = column.find_sub_collision(YAHOO.util.Region.getRegion(this.getDragEl()));
-
+
//determine position
var insertbefore = null;
if(collisions.length == 0)
return;
insertbefore = column.blocks[collisions[0][0]];
-
+
return insertbefore;
}
@@ -145,7 +145,7 @@ block_class.prototype.resetTargets = function() {
var targetEl = targets[i].getEl();
targetEl.style.background = "";
targetEl.opacity = 1;
- targetEl.filter = "alpha(opacity=100)";
+ targetEl.filter = "alpha(opacity=100)";
}
}
@@ -156,47 +156,58 @@ block_class.prototype.move_block = function(columnid){
var inserttarget = this.find_target(column);
if(this.debug && inserttarget != null)YAHOO.log("moving "+this.getEl().id+" before "+inserttarget.getEl().id+" - parentNode="+this.getEl().parentNode.id);
-
- if(this == inserttarget){
+
+ if (this.getEl() == inserttarget) {
if(this.debug)YAHOO.log("Dropping on self, resetting");
this.endDrag();
return;
}
-
- //remove from document
- if(this.getEl().parentNode != null)
- this.getEl().parentNode.removeChild(this.getEl());
-
+
+ //remove from document
+ if (this.getEl().parentNode != null) {
+ this.getEl().parentNode.removeChild(this.getEl());
+ }
//insert into correct place
- if(inserttarget != null ){
- inserttarget.getEl().parentNode.insertBefore(this.getEl(),inserttarget.getEl());
-
- }else if(column == main.rightcolumn){//if right side insert before admin block
- column.getEl().insertBefore(this.getEl(),main.adminBlock);
+ if (inserttarget != null && inserttarget.getEl().parentNode != null) {
+ inserttarget.getEl().parentNode.insertBefore(this.getEl(),inserttarget.getEl());
+ positiontoinsert = "before";
+ if (inserttarget.getEl().id != 'rinst0' || inserttarget.getEl().id == 'rinst0'){
+ positiontoinsertid = inserttarget.getEl().id;
+ } else if (main.adminBlock.parentNode.nextSibling != null) {
+ positiontoinsertid = main.adminBlock.parentNode.nextSibling.id;
+ } else {
+ positiontoinsertid = inserttarget.getEl().id;
+ }
- }else{
- column.getEl().appendChild(this.getEl());
+ } else if (column == main.rightcolumn && column.getEl() != null ) {//if right side insert before admin block
+ column.getEl().insertBefore(this.getEl(),main.tempBlock.childNode);
+ positiontoinsert = "after";
+ positiontoinsertid = main.tempBlock.parentNode;
+ } else {
+ column.getEl().appendChild(this.getEl());
+ positiontoinsert = "after";
+ positiontoinsertid = column.getEl().id;
}
this.reset_regions();
//remove block from current array
- if(main.rightcolumn.has_block(this))
+ if (main.rightcolumn.has_block(this)) {
main.rightcolumn.remove_block(this);
-
- else if(main.leftcolumn.has_block(this))
+ } else if (main.leftcolumn.has_block(this)) {
main.leftcolumn.remove_block(this);
+ }
//insert into new array
column.insert_block(this,inserttarget);
-
- }
+
+}
block_class.prototype.reset_regions = function() {
- var blockcount = main.blocks.length;
+ var blockcount = main.blocks.length;
for (i=0; i<blockcount; i++) {
- main.blocks[i].region = YAHOO.util.Region.getRegion(main.blocks[i].getEl());
+ main.blocks[i].region = YAHOO.util.Region.getRegion(main.blocks[i].getEl());
}
}
@@ -247,13 +258,13 @@ block_class.prototype.toggle_hide = function(e, target, isCosmetic) {
}
-block_class.prototype.delete_button = function() {
+block_class.prototype.delete_button = function() {
// Remove from local model.
if (main.rightcolumn.has_block(this)) {
main.rightcolumn.remove_block(this);
} else if (main.leftcolumn.has_block(this)) {
main.leftcolumn.remove_block(this);
- }
+ }
// Remove block from the drag and drop group in YUI.
this.removeFromGroup('blocks');
@@ -271,8 +282,8 @@ block_class.prototype.delete_button = function() {
block_class.prototype.updatePosition = function(index, columnId) {
- //update the db for the position
- main.connectQueue_add('POST', 'class=block&field=position', null,
+ //update the db for the position
+ main.connectQueue_add('POST', 'class=block&field=position&positiontoinsert='+positiontoinsert +'&positiontoinsertid='+positiontoinsertid, null,
'value='+index+'&column='+columnId+'&instanceId='+this.instanceId);
if (this.debug) {
@@ -305,10 +316,10 @@ column_class.prototype.init_column = function(id, group,config,ident){
}
-column_class.prototype.find_sub_collision = function(dragRegion){
+column_class.prototype.find_sub_collision = function(dragRegion){
if(this.debug)YAHOO.log("Finding Collisions on "+this.getEl().id+" with "+this.blocks.length+" blocks");
- //find collisions with sub_elements(blocks), return array of collisions with regions of collision
- var collisions = new Array();
+ //find collisions with sub_elements(blocks), return array of collisions with regions of collision
+ var collisions = new Array();
for(i=0;i<this.blocks.length;i++){
if(this.debug)YAHOO.log("testing region "+this.blocks[i].region+" against" + dragRegion + "intersect ="+this.blocks[i].region.intersect(dragRegion));
var intersect = this.blocks[i].region.intersect(dragRegion);
@@ -332,7 +343,7 @@ column_class.prototype.insert_block = function(el,targetel){
var found = -1;
var tempStore = nextStore = null;
for(var i=0;i<blockcount;i++){
- if(found > 0){
+ if (found >= 0) {
tempStore = this.blocks[i];
this.blocks[i] = nextStore;
nextStore = tempStore;
Oops, something went wrong.

0 comments on commit 1833b24

Please sign in to comment.