Hi all! I''m a total newbie with javascript''s object programming (but not new on object programming on python and several other languages) and I don''t know how to deal with this: I have some dl elements on my page I have a javascript class who extends the dl features When the page loads I create an object from my class and associates the dl element with it For now all is ok and it works properly (3 hurras for the this!) But now I try to implement some keyboard accelerators (cursor, add and so on) but the keyboard event is attached to the document object (I have no idea how to attach it to the object because it lost the focus and some kind of thinks like these) Well, let''s attach them to the document, no problem! I have a dl who is the selected one and it is the one who affects the accelerators (if I press the cursor down I want to select the next object about the first one for example) But the only way I figure to know who is the selected one is by query for the class Seleccionado (like $$(''Seleccionado'')) This is my question: How can I associate the javascript objects to its html entities? Thanks and sorry if you don''t understand so much because my english is so poor --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
var DefinitionList = Class.create({ initialize: function(element) { this.element = $(element); this.listElements = element.select(''dd''); this.initObservers(); }, initObservers: function(){ this.listElements.invoke(''observe'', ''click'', this.onClick.bind(this)) }, onClick: function(e) { e.stop(); alert(''dd element was clicked''); } }); ... <dl id="faq"> ... </dl> ... var myList = new DefinitionList(''faq''); // myList.element; <= your dl#faq element // myList.listElements; <= dd elements inside dl with already attached observers Does this example make sense? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry but the click event is not the problem. The problem is about the keypress or keydown event I don''t know how to deal with this events What I''m trying to do is to control a tree-like structure and I want to control the arrow keys, for example, to move by the tree Some clues? Thanks! On 4 nov, 17:15, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> var DefinitionList = Class.create({ > initialize: function(element) { > this.element = $(element); > this.listElements = element.select(''dd''); > this.initObservers(); > }, > initObservers: function(){ > this.listElements.invoke(''observe'', ''click'', > this.onClick.bind(this)) > }, > onClick: function(e) { > e.stop(); > alert(''dd element was clicked''); > }}); > > ... > <dl id="faq"> > ... > </dl> > ... > var myList = new DefinitionList(''faq''); > > // myList.element; <= your dl#faq element > // myList.listElements; <= dd elements inside dl with already attached > observers > > Does this example make sense?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
what''s wrong with observe(''keypress'', function() { ... }) ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Well, if I try to attach the event to the object (dl) the event is never raised or I can''t focus the object That''s the problem with the keyboard event: the focused element What do you think about? Thanks! On 4 nov, 19:13, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> what''s wrong with observe(''keypress'', function() { ... }) ?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
You will probably have to observe the window element and then manually check focus i guess. I think that will work. kangax can correct me if i''m wrong :) On 11/5/07, Garito <garito-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Well, if I try to attach the event to the object (dl) the event is > never raised or I can''t focus the object > > That''s the problem with the keyboard event: the focused element > > What do you think about? > > Thanks! > > On 4 nov, 19:13, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > what''s wrong with observe(''keypress'', function() { ... }) ? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
That''s what I assume but then the problem is how to get the javascript object When the keypress event is raised I can get the focused html object not the javascript one The question is when I create the javascript object how can attach it to the html object? Perhaps: htmlObject.setAttribute(''nodo'', javascriptObject) ? On 5 nov, 04:04, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You will probably have to observe the window element and then manually check > focus i guess. > I think that will work. > kangax can correct me if i''m wrong :) > > On 11/5/07, Garito <gar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Well, if I try to attach the event to the object (dl) the event is > > never raised or I can''t focus the object > > > That''s the problem with the keyboard event: the focused element > > > What do you think about? > > > Thanks! > > > On 4 nov, 19:13, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > what''s wrong with observe(''keypress'', function() { ... }) ?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 5, 1:48 am, Garito <gar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all! > I''m a total newbie with javascript''s object programming (but not new > on object programming on python and several other languages) and I > don''t know how to deal with this: > > I have some dl elements on my page > I have a javascript class who extends the dl features > When the page loads I create an object from my class and associates > the dl element with it > > For now all is ok and it works properly (3 hurras for the this!) > > But now I try to implement some keyboard accelerators (cursor, add and > so on) but the keyboard event is attached to the document object (I > have no idea how to attach it to the object because it lost the focus > and some kind of thinks like these) > > Well, let''s attach them to the document, no problem! > > I have a dl who is the selected one and it is the one who affects the > accelerators (if I press the cursor down I want to select the next > object about the first one for example)Keyboard events bubble up the DOM just like other events, so you can catch them at any point. DL elements have an onkeypress, onkeydown and onkeyup intrinsic events so they will respond to those events in appropriate circumstances: <URL: http://www.w3.org/TR/html4/struct/lists.html#edef-DL > However, keyboard events are only associated with elements that accept keyboard input (there may be exceptions to that for some elements in some browsers), which can be summarised as those that have a focus method. The HTMLDListElement doesn''t have a focus method, nor does it inherit it from anywhere: <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-52368974 > Play with the following: <dl onkeypress="alert( (event.srcElement||event.target).id);"> <dt id="dt_0">Try to focus me <dt id="dt_1"><input id="inp_0" value="press keys in me"> </dl> You can put an onkeypress handler on the body element that will catch all keypresses, however you will need to sort out whether to ignore them (they may be related to form controls) or do something with them. If the keypress is not related to an element that has a focus method, the event object''s target or srcElement attribute will likely be a reference to the HTML or body element (depending on browser). That will not help you to work out where the event came from, but maybe you don''t care. It will tell you that no element had focus when the event occured. You will also have to work out or remember which element is "selected", the DOM will no give you much help with that, and what to do if you decide to respond to the keypress. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
That''s exactly what I found in my code, Rob To select the object a attach a onMouseOver event to the dl. When it''s fired I search for the old selected object and I remove the class "Selected" and then I put it to the dl who receives the onMouseOver To control the keyboard events I attach the event to document and I found the selected object with $$("Selected") but now I would like to access to the javascript object I generated when the dl is created Is a bad idea to put the javascript object to the html object with setAttribute? Something like: htmlObject.setAttribute(''nodo'', javascriptObject) On 5 nov, 04:16, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On Nov 5, 1:48 am, Garito <gar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi all! > > I''m a total newbie with javascript''s object programming (but not new > > on object programming on python and several other languages) and I > > don''t know how to deal with this: > > > I have some dl elements on my page > > I have a javascript class who extends the dl features > > When the page loads I create an object from my class and associates > > the dl element with it > > > For now all is ok and it works properly (3 hurras for the this!) > > > But now I try to implement some keyboard accelerators (cursor, add and > > so on) but the keyboard event is attached to the document object (I > > have no idea how to attach it to the object because it lost the focus > > and some kind of thinks like these) > > > Well, let''s attach them to the document, no problem! > > > I have a dl who is the selected one and it is the one who affects the > > accelerators (if I press the cursor down I want to select the next > > object about the first one for example) > > Keyboard events bubble up the DOM just like other events, so you can > catch them at any point. DL elements have an onkeypress, onkeydown and > onkeyup intrinsic events so they will respond to those events in > appropriate circumstances: > > <URL:http://www.w3.org/TR/html4/struct/lists.html#edef-DL> > > However, keyboard events are only associated with elements that accept > keyboard input (there may be exceptions to that for some elements in > some browsers), which can be summarised as those that have a focus > method. The HTMLDListElement doesn''t have a focus method, nor does it > inherit it from anywhere: > > <URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-52368974> > > Play with the following: > > <dl onkeypress="alert( (event.srcElement||event.target).id);"> > <dt id="dt_0">Try to focus me > <dt id="dt_1"><input id="inp_0" value="press keys in me"> > </dl> > > You can put an onkeypress handler on the body element that will catch > all keypresses, however you will need to sort out whether to ignore > them (they may be related to form controls) or do something with > them. If the keypress is not related to an element that has a focus > method, the event object''s target or srcElement attribute will likely > be a reference to the HTML or body element (depending on browser). > That will not help you to work out where the event came from, but > maybe you don''t care. It will tell you that no element had focus when > the event occured. > > You will also have to work out or remember which element is > "selected", the DOM will no give you much help with that, and what to > do if you decide to respond to the keypress. > > -- > Rob--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 5, 1:23 pm, Garito <gar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That''s exactly what I found in my code, Rob > To select the object a attach a onMouseOver event to the dl. When it''s > fired I search for the old selected object and I remove the class > "Selected" and then I put it to the dl who receives the onMouseOver > > To control the keyboard events I attach the event to document and I > found the selected object with $$("Selected") but now I would like to > access to the javascript object I generated when the dl is created > > Is a bad idea to put the javascript object to the html object with > setAttribute? Something like:It depends. There''s nothing in the W3C DOM specs that say you can add any random attribute you like to a DOM object, however I don''t know of any browser that won''t let you. It is a little problematic if they are added to the HTML, but for getting or setting via script, I think you are fine.> > htmlObject.setAttribute(''nodo'', javascriptObject)setAttribute is more appropriate to use with HTML attributes (though its use is usually completely unnecessary), what you are adding is an object property, so: htmlObject.nodo = javascriptObject; will do the job and avoid the various issues with setAttribute. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah! That work''s Rob! Thank you so much! On 5 nov, 05:00, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On Nov 5, 1:23 pm, Garito <gar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > That''s exactly what I found in my code, Rob > > To select the object a attach a onMouseOver event to the dl. When it''s > > fired I search for the old selected object and I remove the class > > "Selected" and then I put it to the dl who receives the onMouseOver > > > To control the keyboard events I attach the event to document and I > > found the selected object with $$("Selected") but now I would like to > > access to the javascript object I generated when the dl is created > > > Is a bad idea to put the javascript object to the html object with > > setAttribute? Something like: > > It depends. There''s nothing in the W3C DOM specs that say you can add > any random attribute you like to a DOM object, however I don''t know of > any browser that won''t let you. It is a little problematic if they > are added to the HTML, but for getting or setting via script, I think > you are fine. > > > > > htmlObject.setAttribute(''nodo'', javascriptObject) > > setAttribute is more appropriate to use with HTML attributes (though > its use is usually completely unnecessary), what you are adding is an > object property, so: > > htmlObject.nodo = javascriptObject; > > will do the job and avoid the various issues with setAttribute. > > -- > Rob--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---