CSS position relative and Drag and Drop

Jerreck McWilliams asked on March 4, 2014 10:17

I've had an issue with web parts being wildly out of position when I use the drag and drop interface on the design tab in both CMS Desk and Site Manager. I thought it was a conflict with one of my javascript files, but it turns out it was because the container those web parts were in has a CSS position of relative.

Image Text

Apparently, the script Kentico uses for drag and drop just sets a web part's position to absolute, then moves them around the frame based on their original position. Unfortunately, this has the side effect of setting the web parts' position relative to their parent elements' since the parent elements have position: relative and not position: static.

I have a good idea for a fix, but it would require editing the CMS Script for drag and drop behavior. I wanted to check to see if anyone knew of something else I could try before doing this.

Even though technically the CSS is behaving exactly as it should, I'm tagging this as a bug since I don't believe developers should have to alter their CSS to accommodate the Kentico UI.

Recent Answers


Jerreck McWilliams answered on March 4, 2014 10:18

Image Text

0 votesVote for this answer Mark as a Correct answer

Jerreck McWilliams answered on March 4, 2014 12:34 (last edited on March 4, 2014 12:34)

I should also mention that I'm using Bootstrap 3, which uses position: relative on all its column classes. I'm curious if the same effect is occurring in your CMS Desk and Site Manager for the new devnet site since it also appears to be built on top of bootstrap. If not, then what was your fix for it?

1 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on April 5, 2014 03:58

Hi,

Kentico 7 was not that ready for Bootstrap, so you may face these issues and you really have to modify your CSS or do not load them in the edit/design mode. Changing this would require completely rewrite the user interface and the Design mode engine which is not possible within a hotfix. However, we try to keep up with latest technologies - so upcoming versions should be better in this. We are sorry for this inconvenience.

Best regards,
Juraj Ondrus

1 votesVote for this answer Mark as a Correct answer

Niels Kooiman answered on July 10, 2014 04:35

I experienced the same issue in Kentico 8 when using a Flow layout design. (using css properties float:left;clear:both;width:100%;position:relative;)

Drag and drop was not working, because - on drag - the position of the webpart/widget moved relative ~200px to right-bottom.

I managed to fix the issue by letting jQuery resolve the offset. (Instead of the .Net Framework javascript)


Functions that DO NOT work correctly (in this case):

Sys.UI.DomElement.getLocation(element, ...)

Sys.UI.DomElement.setLocation(element, x, y)

Functions that DO work:

jQuery(element).offset()
jQuery(element).offset({ left: x, top: y })

(First create a backup of your file)

Step 1. In file \CMSScripts\DragAndDrop\DragAndDropBehavior.js, add the following on top:

/* Get/Set Location Fix */
function getLocation(element) {
    var offset = jQuery(element).offset();
    return { x: offset.left, y: offset.top };
}

function setLocation(element, x, y) {
    jQuery(element).offset({ left: x, top: y });
}
/* End of Get/Set Location Fix */

Step 2. Uncomment every line containing: 'Sys.UI.DomElement.getLocation', like:

... = /*Sys.UI.DomElement.*/getLocation(...);

Step 3. Uncomment every line containing: 'Sys.UI.DomElement.setLocation', like:

/*Sys.UI.DomElement.*/setLocation(...);

Step 4. Save the file, and Reload the javascript (by using CTRL-F5 and/or CMS Application restart)

OPTIONAL: My DesignMode CSS changes: (Added to my Site.css, NOT REQUIRED FOR THE FIX ABOVE, but completes the flow layout and gives the webpart components the correct height)

.WebPartZone, .WebPartZoneContent {float: left; clear:both; width: 100%; position:relative; }
.WebPartZoneBorder, .WebPartZoneBorderActive { float:left; clear:both;width:100%; }
.WebPartBorder, .WebPartBorderActive { float:left; clear:both;width:100%; }
.WebPartContent {float: left; clear:both; width: 100%;}
.EditorWidget div.WebPartHeader {display:block; /*height:31px;background-color:blue;*/}
.WebPart { /*margin: 10px 0;*/ float: left; clear:both; width: 100%; }
.WebPartZoneCue { margin:-3px; border:3px dotted red; border-radius:10px; float: left; clear:both; width: 100%; }
0 votesVote for this answer Mark as a Correct answer

Jerreck McWilliams answered on July 10, 2014 08:22

Thank you very much for taking the time to create a fix for this. Our team is going to try to find some time in the next couple of weeks to test your solution.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.