After adding some SmartGWT widgets to our GWT application we're seeing different values in this JavaScript statement, located in our custom JavaScript code: "getSelection().focusNode.parentNode". Without SmartGWT widgets the value is "SPAN". After adding a couple of SmartGWT containers around some of our GWT widgets the value is now "TD". The action that eventually hits this JavaScript comes from a left-click on a GWT HTML widget. Here's a rough diagram of our container hierarchy when using SmartGWT widgets ([SGWT] denotes a SmartGWT widget):
The HStack has setShowResizeBar set to true.
Using Firebug's 3d view to inspect the DOM of the application with and without SmartGWT shows the element we're clicking on as a "SPAN" in both cases (with and without SmartGWT). The outside "TD" element that contains this "SPAN" is the same for both applications.
------------------------------------------------------------------------
The call chain made to get to our "getSelection().focusNode.parentNode JavaScript statement is:
- User Left-clicks on text in the HTML widget
- onClick(ClickEvent event) handler recieves the click event
- Call made to the native JS method "getSelectedChar()" shown below.
The following statment is always false when using SmartGWT widgets, as shown in the above diagram: "if (anchorParent.nodeName != "SPAN")"
------------------------------------------------------------------------
Any idea what we're doing wrong?
SmartGWT version: 4.0d
Browser: Firefox 20.0.1
------------------------------------------------------------------------
function getSelectedChar() in TextSelection.js:
Code:
VLayout [SGWT] HStack [SGWT] ScrollPanel VerticalPanel <our GWT Table widget> HorizontalPanel VerticalPanel HorizontalPanel HorizontalPanel GroupBox GroupBox HorizontalPanel Label ScrollPanel HTML <------------ widget we're clicking on VerticalPanel TreeGrid [SGWT] VerticalPanel
Using Firebug's 3d view to inspect the DOM of the application with and without SmartGWT shows the element we're clicking on as a "SPAN" in both cases (with and without SmartGWT). The outside "TD" element that contains this "SPAN" is the same for both applications.
------------------------------------------------------------------------
The call chain made to get to our "getSelection().focusNode.parentNode JavaScript statement is:
- User Left-clicks on text in the HTML widget
- onClick(ClickEvent event) handler recieves the click event
- Call made to the native JS method "getSelectedChar()" shown below.
The following statment is always false when using SmartGWT widgets, as shown in the above diagram: "if (anchorParent.nodeName != "SPAN")"
------------------------------------------------------------------------
Any idea what we're doing wrong?
SmartGWT version: 4.0d
Browser: Firefox 20.0.1
------------------------------------------------------------------------
function getSelectedChar() in TextSelection.js:
Code:
document.getSelectedChar = function getSelectedChar() { // Make sure that this click wasn't part of a selection var selection = document.getSelection().getRangeAt(0); var length = selection.toString().length; if (length != 0) { return -1; } // Check that the text was selected from left to right var backwards = isSelectionBackwards(); // Get the anchor, focus, and parent nodes if (!backwards) { var anchor = document.getSelection().anchorNode; var anchorOffset = document.getSelection().anchorOffset; var anchorParent = anchor.parentNode; var focus = document.getSelection().focusNode; var focusOffset = document.getSelection().focusOffset; var focusParent = focus.parentNode; } else { var anchor = document.getSelection().focusNode; var anchorOffset = document.getSelection().focusOffset; var anchorParent = anchor.parentNode; var focus = document.getSelection().anchorNode; var focusOffset = document.getSelection().anchorOffset; var focusParent = focus.parentNode; } if (anchorParent.nodeName != "SPAN") { return -1; } var mentionText = anchorParent.textContent; var str = anchor.textContent; str = str.substring(anchorOffset, anchorOffset + 1); document.getSelectedText(true); return endPos; }
Comment