You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Great script.
One thing I thought could use some improvements is hyperlinks. Currently,
clicking the hyperlink toolbar without a range does nothing. To completely
remove a hyperlink, the range must be perfectly selected on the including a
hyperlink can ... otherwise there's potential for some leftovers. And
editing hyperlinks is ... rather difficult.
I've improved this as follows:
Revised the hyperlink code under the widgToolbarAction function.
Now it loops through parent nodes until the A is found. The range is then
expanded to include the entire anchor, the HREF is grabbed and
pre-populates the prompt. If user clears the URL, this will remove
hyperlink; otherwise the link is updated.
case "link":
if (theIframe.contentWindow.document.selection)
{ /*IE ranges */
theRange = theIframe.contentWindow.document.selection.createRange()
theSelection = theRange.text;
theParentNode = theRange.parentElement();
}
else
{ /* mozilla ranges */
theSelection = theIframe.contentWindow.getSelection();
theRange = theSelection.getRangeAt(0)
theParentNode = theRange.commonAncestorContainer;
}
// previous function set the toolbar icon if hyperlink or not
if (!this.parentNode.className.classExists("on")){
if (theSelection == "")
{
alert("Please select the text you wish to hyperlink.");
break;
}
var theURL = prompt("Enter the URL for this link:", "http://");
theIframe.contentWindow.document.execCommand("CreateLink", false, theURL);
theWidgEditor.theToolbar.setState("Link", "on");
}
else {
var p = theParentNode;
while(p.nodeName.toLowerCase()!="a" ){ p = p.parentNode }
if( theWidgEditor.IE )
{
theRange.moveToElementText( p );
theRange.select();
}
else
{
theRange.selectNode( p );
}
var theURL = prompt("Update the URL for this link:", p.href);
if( theURL == null ) break; // cancel cancels
// always remove
theIframe.contentWindow.document.execCommand("Unlink", false, null);
theWidgEditor.theToolbar.setState("Link", "off");
if( theURL != "" )
{ // if url was specified, set it up
theIframe.contentWindow.document.execCommand("CreateLink", false, theURL);
theWidgEditor.theToolbar.setState("Link", "on");
}
break;
}
break;
Original issue reported on code.google.com by tyler.wa...@gmail.com on 20 Feb 2009 at 11:52
The text was updated successfully, but these errors were encountered:
Oh, i just noticed ... forgot to have an unlink call in the top-section. Ensure
Unlink is always called on the selection:
"
var theURL = prompt("Enter the URL for this link:", "http://);
theIframe.contentWindow.document.execCommand("Unlink", false, null);
theIframe.contentWindow.document.execCommand("CreateLink", false, theURL);
theWidgEditor.theToolbar.setState("Link", "on");
"
Original comment by tyler.wa...@gmail.com on 21 Feb 2009 at 2:25
Original issue reported on code.google.com by
tyler.wa...@gmail.com
on 20 Feb 2009 at 11:52The text was updated successfully, but these errors were encountered: