This works great, until a form or input element, is within the element
hierarchy.  It is mainly a problem with the HTML input tag, because
most of the time (especially in ASP.NET) everything is contained
within the form.

<html>
<head>
        <title>Test Page</title>
        <script type="text/javascript" src="prototype.js"></script>
        <script type="text/javascript">
                Object.extend(Element.Methods, {
                        stopObservingNested: function(element) {
                                element.stopObserving();
                                
element.descendants().each(Element.stopObserving);
                        }
                });
                Element.addMethods();

                window.onload = function() {
                        $('testDiv').observe('click', function(event) { 
alert('clicked div'); });
                        $('testSpan').observe('click', function(event) { 
alert('clicked span'); });
                        $('testClear').observe('click', function(event) {
                                var el = $('testDiv');
                                el.stopObservingNested();
                        });
                }
        </script>
</head>
<body>
        <div id="testDiv">
                <!-- Form causes "eventName.include is not a function" 
prototype.js Line: 3942
                <form>
                        <span id="testSpan">
                                Hello World!
                        </span>
                </form>
                &nbsp;-&nbsp;Div Part!
        </div>

        <input id="testClear" type="button" value="Clear Events" />
</body>
</html>

2008/10/3 kangax <[EMAIL PROTECTED]>:
>
> On Oct 3, 7:31 am, "Lea Hayes" <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> Ah right, that's fair enough. When I wrote that post I didn't realize
>> that you could simply pass a function reference into the each method.
>>
>> Personally I prefer to take advantage of the slightly higher level
>> interfaces provided by Prototype to avoid possible difficulties in
>> future releases.
>>
>> I did encounter one problem which was relatively simple to solve. If a
>> form, or input element is nested within the specified element
>> hierarchy, a JavaScript error is reported. By testing for the presence
>> of 'stopObserving' method, it is possible to determine whether that
>> method is appropriate on a per element basis:
>>
>>                 Object.extend(Element.Methods, {
>>                         stopObservingNested: function(element) {
>>                                 element.stopObserving();
>>                                 element.descendants().each(function(element) 
>> {
>>                                         if (element.stopObserving !== 
>> undefined)
>>                                                 element.stopObserving();
>>                                 });
>>                         }
>>                 });
>
> That's weird.
> `descendants` should return an array of extended elements and every
> extended element should have `stopObserving` (among other methods)
> Could you give more details on when this happens?
>
> --
> kangax
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to