This is fine but what if I wanted to have multiple attached methods for a type of event. removeEvent can remove all events or just one of the methods attached to that type.
By the way, addEvent only attaches methods to the type of event if the function is not presently attached. Same for removeEvent. I like hasEvent, but if you know what you're attaching and removing then there's no point for checking. On Dec 21, 10:33 am, nwhite <[email protected]> wrote: > Native.implement([Element, Window, Document], { > hasEvent: function(type){ > var events = this.retrieve('events', {}); > if (events && events[type]) return true; > else return false; > } > > }); > > if( el.hasEvent('event') ) el.removeEvent('event'); > el.addEvent('event'); > > On Sun, Dec 21, 2008 at 5:58 AM, Oskar Krawczyk > <[email protected]>wrote: > > > > > Thanks Nathan, I'll give this solution a go if I don't figure out any > > simpler way. > > Also, it's not like I don't want to replace the attached event, > > because I do – that's the whole point. > > > @Guillermo, no "beforeunload" is not what I'm looking for – using it > > wouldn't help me in any way I'm afraid. > > > Best, > > Oskar > > > On Dec 21, 4:19 am, nwhite <[email protected]> wrote: > > > What if you had a LinkManager class. Instead of using addEvent you have > > > something like 'register' where you pass the element and your html obj. > > If > > > the element has already been 'registered' in your class, just ignore. > > Else > > > attach whatever you need. > > > > On Sat, Dec 20, 2008 at 11:05 PM, Guillermo Rauch <[email protected]> > > wrote: > > > > Events don't get overwritten, you can add multiple events to the same > > > > element.Plus, I think the beforeunload event is what you're looking > > for. > > > > > window.addEvent('beforeunload', function() { > > > > if(MySite.hasToStop) return 'Your document has not been saved.'; > > > > }); > > > > > On Sat, Dec 20, 2008 at 11:33 PM, Oskar Krawczyk < > > [email protected] > > > > > wrote: > > > > >> Hi Folks, hope you're well! > > > > >> Please consider the scenario below: > > > > >> 1. A user gets a form he might or might not fill. > > > > >> 2. If a user has modified the field, every link on the webpage should > > > >> get an event applied to itself. > > > > >> 3. Clicking on one of the links would display a popup (a html one, not > > > >> the alert() thing) asking for confirmation whether we want to leave > > > >> the page without saving or not. > > > > >> 4. Now, in some cases a link on the page would already have an event > > > >> attached – bummer, it gets overwritten by the new one and we're left > > > >> with out pants down. > > > > >> You can see my pain. I was considering storing the default event – > > > >> this.store('default:event', e) – but that would clearly work only when > > > >> the actual event gets triggered. > > > > >> Maybe it's the late hour but I don't see any easy solution to get > > > >> successfully through the scenario. > > > > >> Any suggestions? > > > > >> Best, > > > >> Oskar > > > > > -- > > > > Guillermo Rauch > > > >http://devthought.com
