PDA

View Full Version : Adding JavaScript to an element in IE(8)



mazukas
9 Aug 2012, 12:09 PM
I have an interesting problem that I can' seem to be able to get around. I need to be able to add DnD (or at least get the drag to start) to a tab in a tab panel. I've been able to get it to work in FF but not IE (specifically IE8). Since the TabItem does not handle DnD out of the box in EXT GWT 2 (or GXT 3) I had to do some DOM manipulation. I created my own tab class by extending the TabItem class and then after it was rendered I execute the following code:

setText("Draggable Tab");
HeaderItem h = getHeader();
//Through inspecting the DOM in both IE and FF we know the first <span> found is the one that wraps the title/text of the tab
Element draggableAreaElement = h.getElement().getElementsByTagName("span").getItem(0);

draggableAreaElement.setDraggable(Element.DRAGGABLE_TRUE);
draggableAreaElement.setAttribute("ondragstart", "onTagDrag('docId')");

As stated before, in FF the onTagDrag() function will be called if a user tries to click and drag the tab. In IE the function never gets called even though when I inspect the DOM it has been added. I also tried something simple like:
draggableAreaElement.setAttribute("onclick", "alert('Hello World')");
to see if I could get any JavaScript event to fire in IE and even with that I had no luck (again, even though it was added to the DOM).

Does anyone have any idea why this is happening and how I can get around it and if not then possibly a better way to implement DnD for tabs. Thanks.