Forums

This topic is locked

this one's for the DOMologists out there

Posted 26 Jul 2001 23:27:35
1
has voted
26 Jul 2001 23:27:35 Joel Martinez posted:
I'm getting the user's selection as an object by using the <b>dw.offsetsToNode</b> method. I want to wrap that node, in another node.

example.<pre id=code><font face=courier size=2 id=code>if I've got
&lt;td&gt;hello&lt;/td&gt;

I would want to wrap the &lt;td&gt; node in

&lt;tr&gt;&lt;Td&gt;hello&lt;/td&gt;&lt;/tr&gt;</font id=code></pre id=code>

what's the best way to do that... is there a dom method for that?

thanks,

Joel Martinez

----------
Is this thing on?....

Replies

Replied 26 Jul 2001 23:59:13
26 Jul 2001 23:59:13 Bruno Mairlot replied:
I would do that with the two functions :

theDOM.getSelection();
theDOM.setSelection();

getSelection gives you an array of two offsets. So you take the whole text by :

var theDocEl = theDOM.documentElement;
var theWholeDoc = theDocEl.outerHTML;

you get then the text selection with

var selText = theWholeDoc.substring(theSel[0],theSel[1]);

And finally you put your enclosing tag around the selection with this :

theDocEl.outerHTML=theWholeDoc.substring(0,theSel[0]) + "&lt;tr&gt;"+ selText+"&lt;/tr&gt;"+ theWholeDoc.substring(theSel[1]);

Then you set the selection where it was :


theDOM.setSelection(theSel[0],theSel[1]);


BTW, I experienced problem with Preview, so I'm not sure if my text is coherent...<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

I know that it works, because I did this once to enclose the selection into a form or a table. It is very boring that sometimes you design a very nice form then you realize that you forgot the form tag. Or when you want to nest a table into another table...

"First they laugh at you, then they fight you, then you Win..." Ghandi

Edited by - Maehdros on 07/27/2001 00:04:52
Replied 27 Jul 2001 15:21:39
27 Jul 2001 15:21:39 Joel Martinez replied:
that's exactly what I was doing, but I came across an issue. Say you have this text:<pre id=code><font face=courier size=2 id=code>&lt;p&gt;
hello
&lt;/p&gt;
&lt;p&gt;
I am the boogie man
&lt;p&gt;</font id=code></pre id=code>When you select that in the design view, UD will not select the first and last tags, so you're left with this selection:<pre id=code><font face=courier size=2 id=code>hello
&lt;/p&gt;
&lt;p&gt;
I am the boogie man</font id=code></pre id=code>Then UD gives you those horrible yellow "invalid markup" tags.

that's why I was going with the DOM approach, because it will select the whole node... but now I need a way to wrap the node with another.

Joel Martinez

----------
Is this thing on?....
Replied 27 Jul 2001 16:55:19
27 Jul 2001 16:55:19 George Petrov replied:
That is why MM invented this very sneaky function:

<pre id=code><font face=courier size=2 id=code>fixUpSelection(dreamweaver.getDocumentDOM()); </font id=code></pre id=code>

It is declared in Configuration\Shared\UltraDev\Scripts\ssDocmanager.js

Here is the exmplanation of the function:
<pre id=code><font face=courier size=2 id=code>//*-------------------------------------------------------------------
// FUNCTION:
// fixUpSelection
//
// DESCRIPTION:
// Fixes up the selection so that it is "clean", e.g.:
// expands &lt;a href="foo"&gt;[begin selection] some text&lt;/a&gt;[end selection]
// to be [begin selection]&lt;a href="foo"&gt;some text&lt;/a&gt;[end selection]
// Also expands table cell selections of more than one cell to be the entire row,
// and if the selection is not in the body, places cursor at end of body
//
// ARGUMENTS:
// dom - the dom containing the selection to fix
// bLeaveHeadSelection - leave the selection in the head
// bCollapseParagraphs -
// bReturnOffsets - if set to true, the function returns the offsets,
// rather than the selected string
//
// RETURNS:
// the text string of the new and improved balanced selection or, if
// bReturnOffsets is true, returns the offsets of the balanced selection.
//--------------------------------------------------------------------</font id=code></pre id=code>

---------------------------------------
George Petrov - CTO, www.UDzone.com

www.UDzone.com : A Dreamweaver,
Dreamweaver Ultradev and Fireworks site
by developers for developers.
---------------------------------------

Replied 27 Jul 2001 17:23:10
27 Jul 2001 17:23:10 Bruno Mairlot replied:
He He, I came across exactly the same issue, and that was why I never posted my extension, because I hadn't time to polish it.

Indeed this function is very useful...Thanks for the info.

"First they laugh at you, then they fight you, then you Win..." Ghandi
Replied 27 Jul 2001 17:27:41
27 Jul 2001 17:27:41 Joel Martinez replied:
Sweet!!!

man, that's a great function. I looked into the .js file, that is some serious coding...

thanks george

Joel Martinez

----------
Is this thing on?....
Replied 27 Jul 2001 20:56:00
27 Jul 2001 20:56:00 George Petrov replied:
Always glad to be of any help <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

---------------------------------------
George Petrov - CTO, www.UDzone.com

www.UDzone.com : A Dreamweaver,
Dreamweaver Ultradev and Fireworks site
by developers for developers.
---------------------------------------

Reply to this topic