Javascript questions Re: [Seaside] Textarea and setSelectionRange()
Carl Gundel
carlg at libertybasic.com
Tue Mar 17 15:50:05 UTC 2009
Thanks guys. I used Michel's suggestion by backporting the Seaside
2.8 code back to 2.6. I managed to make something work, but it is
slightly different depending on the browser. I also tried Lukas'
suggestion but with less luck.
I do have an issue with the order of execution of Javascript. For
example I am using Editarea which is an open source code editor in
Javascript. It comes with it's own set selection function which I was
unable to make work. It does work, mind you in their examples and I
think this is because they tie it to a button which is clicked after
the page is all loaded up. I need to make the selection happen
automatically, but I couldn't figure out how to make the call to the
selection method happen as the last thing on the page load. I can
actually see the selection happen really fast and then it gets wiped
out by the actions of other scripts.
How is this done in Seaside? What can I do to specify Javascript that
will be guaranteed to run after some other Javascript code? I am a
beginner in the Javascript realm and I have been spending a lot of
energy trying to figure this out, but the going has been slow. Has
somebody written some details on the use of Javascript with Seaside?
Thanks,
-Carl Gundel
http://www.runbasic.com
http://www.libertybasic.com
On Mar 16, 2009, at 3:26 AM, Bany, Michel wrote:
> Support for this is available in Seaside 2.8.
>
> See #setSelectionFrom:to: and WAStandardFiles>>miscJs.
> See also #renderTextArea: for an example.
>
> HTH,
> Michel
>
>
>
>
>> -----Original Message-----
>> From: seaside-bounces at lists.squeakfoundation.org
>> [mailto:seaside-bounces at lists.squeakfoundation.org] On Behalf
>> Of Lukas Renggli
>> Sent: samedi, 14. mars 2009 17:25
>> To: Seaside - general discussion
>> Subject: Re: [Seaside] Textarea and setSelectionRange()
>>
>>> Has anyone here managed to call the setSelectionRange()
>> method against
>>> a textarea in Seaside? I cannot seem to get this working.
>>
>> Text selection is handled different in IE.
>>
>> There is JavaScript code in the Pier-EditorEnh plugin at
>> <http://source.lukas-renggli.ch/pieraddons> that retrieves
>> and sets the text selection. As far as I know this code works
>> in all web
>> browsers:
>>
>> function getSelection(element) {
>> if (document.selection && document.selection.createRange) {
>> var range = document.selection.createRange();
>> var stored = range.duplicate();
>> stored.moveToElementText(element);
>> stored.setEndPoint("EndToEnd", range);
>> element.selectionStart = stored.text.length -
>> range.text.length;
>> element.selectionEnd = element.selectionStart +
>> range.text.length;
>> }
>> return [element.selectionStart, element.selectionEnd]; }
>>
>> function setSelection(element, range) {
>> element.focus();
>> element.selectionStart = range[0];
>> element.selectionEnd = range[1];
>> if (document.selection && document.selection.createRange) {
>> var range = document.selection.createRange();
>> range.moveStart("character", element.selectionStart);
>> range.moveEnd("character", element.selectionEnd
>> - element.selectionStart);
>> range.select();
>> }
>> }
>>
>> Cheers,
>> Lukas
>>
>> --
>> Lukas Renggli
>> http://www.lukas-renggli.ch
>> _______________________________________________
>> seaside mailing list
>> seaside at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
More information about the seaside
mailing list