Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14142 > unrolled thread
| Started by | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| First post | 2012-05-25 12:22 +1000 |
| Last post | 2012-05-25 10:26 +0200 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.javascript
Adding to onclick Andrew Poulos <ap_prog@hotmail.com> - 2012-05-25 12:22 +1000
Re: Adding to onclick "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-05-24 20:06 -0700
Re: Adding to onclick "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-25 07:07 +0000
Re: Adding to onclick Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-25 10:10 +0200
Re: Adding to onclick SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-05-25 10:26 +0200
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2012-05-25 12:22 +1000 |
| Subject | Adding to onclick |
| Message-ID | <wf-dnWElyKFmcSPSnZ2dnUVZ_rOdnZ2d@westnet.com.au> |
I have some code that "applies" a transformation to an element. Its
written in such a way that multiple transformations can be applied
simultaneously.
One of the possible triggers includes the onclick event. This works fine
for one transformation:
elem.onclick = function() { //transformation01... };
but for multiple transformations its creating:
elem.onclick = function() { //transformation01... };
elem.onclick = function() { //transformation02... };
elem.onclick = function() { //transformation03... };
...
How can I get subsequent functions to include the code from any previous
function?
Andrew Poulos
[toc] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2012-05-24 20:06 -0700 |
| Message-ID | <9981d776-b1f6-4632-81bb-4396a9d0130c@googlegroups.com> |
| In reply to | #14142 |
On Thursday, May 24, 2012 9:22:43 PM UTC-5, Andrew Poulos wrote:
> I have some code that "applies" a transformation to an element. Its
> written in such a way that multiple transformations can be applied
> simultaneously.
>
> One of the possible triggers includes the onclick event. This works fine
> for one transformation:
>
> elem.onclick = function() { //transformation01... };
>
> but for multiple transformations its creating:
>
> elem.onclick = function() { //transformation01... };
> elem.onclick = function() { //transformation02... };
> elem.onclick = function() { //transformation03... };
> ...
>
> How can I get subsequent functions to include the code from any previous
> function?
Why not use elem.addEventListener?
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exjxw.hannivoort@interxnl.net> |
|---|---|
| Date | 2012-05-25 07:07 +0000 |
| Message-ID | <XnsA05E5CE5C9F22eejj99@194.109.133.133> |
| In reply to | #14143 |
Michael Haufe (TNO) wrote on 25 mei 2012 in comp.lang.javascript:
> On Thursday, May 24, 2012 9:22:43 PM UTC-5, Andrew Poulos wrote:
>> I have some code that "applies" a transformation to an element. Its
>> written in such a way that multiple transformations can be applied
>> simultaneously.
>>
>> One of the possible triggers includes the onclick event. This works
>> fine for one transformation:
>>
>> elem.onclick = function() { //transformation01... };
>>
>> but for multiple transformations its creating:
>>
>> elem.onclick = function() { //transformation01... };
>> elem.onclick = function() { //transformation02... };
>> elem.onclick = function() { //transformation03... };
>> ...
>>
>> How can I get subsequent functions to include the code from any
>> previous function?
>
>
> Why not use elem.addEventListener?
<http://www.javascripter.net/faq/keyboardmouseevents.htm>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2012-05-25 10:10 +0200 |
| Message-ID | <1595535.oMNUckLgyt@PointedEars.de> |
| In reply to | #14142 |
Andrew Poulos wrote:
> I have some code that "applies" a transformation to an element. Its
> written in such a way that multiple transformations can be applied
> simultaneously.
>
> One of the possible triggers includes the onclick event. This works fine
> for one transformation:
>
> elem.onclick = function() { //transformation01... };
>
> but for multiple transformations its creating:
>
> elem.onclick = function() { //transformation01... };
> elem.onclick = function() { //transformation02... };
> elem.onclick = function() { //transformation03... };
> ...
>
> How can I get subsequent functions to include the code from any previous
> function?
Use either elem.addEventListener() or closures if the former is unavailable.
(Do not use elem.attachEvent(); execution order is not guaranteed then.)
jsx.dom.addEventListener() does that for you:
<http://PointedEars.de/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Fdom%2Fevents.js>
<http://PointedEars.de/scripts/dom/events.js> (please copy before use)
PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)
[toc] | [prev] | [next] | [standalone]
| From | SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> |
|---|---|
| Date | 2012-05-25 10:26 +0200 |
| Message-ID | <4fbf4242$0$12506$ba4acef3@reader.news.orange.fr> |
| In reply to | #14142 |
Le 25/05/12 04:22, Andrew Poulos a écrit :
> I have some code that "applies" a transformation to an element. Its
> written in such a way that multiple transformations can be applied
> simultaneously.
successively, no ?
> One of the possible triggers includes the onclick event. This works fine
> for one transformation:
so that function, would have to work on a list, no ?
elem.onclick = function() {
//transformations.thatObject.transformationsList... };
or ... :
elem.onclick = listTransform;
elem.ondbleclick = transformations;
function listTransform() {
if(typeof this.transformationList == 'undefined')
this.transformationList = [];
this.transformationList.push(thatTransformation);
// 'thatTransformation' is a global with the choiced tool
// (and its attributes ?)
}
function transformations() {
var lst = this.transformationsList, n = lst.length;
while(n--) this.transform(list[n]);
}
> How can I get subsequent functions to include the code from any previous
> function?
TNO gave you a way
--
Stéphane Moriaux avec/with iMac-intel
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web