Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#9300 closed bug (notabug)

Draggable element after body re-appended to parent on drag start

Reported by: jaredjacobs Owned by:
Priority: minor Milestone: none
Component: ui.draggable Version: 1.10.3
Keywords: Cc:
Blocked by: Blocking:

Description

A draggable element that is a direct child of the <html> element (not in the <body>) and that has no drag helper gets re-appended to its parent, making it the last child, when a drag begins.

http://jsfiddle.net/KZFNK/

One could argue that draggable elements should always be descendants of <body>, but in practice, browsers render elements after the body, and it's sometime useful to inject content into a page as direct children of <html> (e.g. in a browser extension). Doing so allows a Chrome or Firefox extension to add content to a <frameset> document (which has no <body>), for example.

Change History (7)

comment:1 Changed 7 years ago by jaredjacobs

Pull request with one-line fix: https://github.com/jquery/jquery-ui/pull/987

comment:2 Changed 7 years ago by Scott González

Resolution: notabug
Status: newclosed

Whether you find this useful or not, it's invalid HTML.

comment:3 Changed 7 years ago by jaredjacobs

Hi Scott. Thanks for taking the time to evaluate this issue.

You're correct, of course, that content after the <body> is not valid HTML. Still, I'd ask you to please take a look at my tiny pull request (+4 bytes, -4 bytes). It doesn't introduce any code to the jQuery UI library that generates invalid HTML. It doesn't break the draggable library for any valid HTML documents. What's the harm, exactly?

Feel free to leave this ticket closed as notabug. I'm not claiming that there is a fault or defect in the library. I do believe, however, that pull request 987 will make jQuery UI more broadly useful. (I'm not aware of a jQuery team mandate to force HTML conformance on its users. It generally treats that as a user responsibility.)

Please take a moment to look at the pull request and respond to it either here or there. Thanks!

comment:4 Changed 7 years ago by Scott González

What's the harm, exactly?

The harm is unbelievably large. Someone needs to write the code. Someone needs to review the code. Someone needs to write tests to verify the behavior. Everyone needs to ensure that we never regress. Having a test means we're encouraging bad practices. Multiply this by the millions of invalid things people do all the time. That's a LOT of time and energy wasted on invalid use cases. Not to mention all the bytes that add up over time, purely for invalid edge cases.

Please take a moment to look at the pull request and respond to it either here or there.

This is part of the harm. I've already spent too much time discussing something that you know is invalid.

Last edited 7 years ago by Scott González (previous) (diff)

comment:5 Changed 7 years ago by jaredjacobs

You and I agree that the relevant HTML is non-conforming. However, I don't agree that the use case is invalid. There's a difference. Users often want to do things to documents written by one author using third-party scripts written by a different author. The third-party script authors don't have control over the global structure of the HTML document. Users don't care; they just want the third-party script to work.

Take a look at the list of "intended scenarios" for using jQuery 2.0 (under How to Use It at http://blog.jquery.com/2013/04/18/jquery-2-0-released/). Browser extensions and add-ons are clearly listed. They are third-party script scenarios.

You're in charge. If you'd like me to add a test to my pull request, I'd be happy to. If you just want me to go away, well, I can do that too. And if you're finding working on jQuery too demanding or stressful, well... it might be time to consider something new. http://www.42go.com/join_us.html Cheers!

Version 0, edited 7 years ago by jaredjacobs (next)

comment:6 Changed 7 years ago by dmethvin

Hey Jared, I wrote that blog post and can assure you that making invalid code/markup work is not anywhere in the jQuery 2.0 charter. Perhaps you can use jQuery to correct the document, for example to move the markup into the body. But as Scott says, we've already spent too much time on this.

Also, say "hi" to Greg.

comment:7 Changed 7 years ago by jaredjacobs

Can't change a <frameset> to a <body> with script, unfortunately, but thanks for taking the time to reply.

Note: See TracTickets for help on using tickets.