[jawsscripts] Re: Finding DOM element at the virtual cursor

  • From: jaws tech <jawsmaster@xxxxxxxxx>
  • To: jawsscripts@xxxxxxxxxxxxx
  • Date: Wed, 11 Aug 2010 19:34:39 -0400

O.K. guys.  Here is what I came up with. It works for what I wanted and that
was a quick way to jump into
the DOM for wherever the virtual cursor is located.  It was a little tricky
going between the output from the JAWS
GetTagIndex() function (only returns visible elements) and the collection
returned in the DOM (includes both visible and hidden elements) but it was
only a couple lines of code to deal with that.
Thanks for all your input.



Object Function GetCurrentElement ()

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This function returns an object pointer to the element at the virtual
cursor's current position ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

var
string tagname,
int jawstagindex,
object oIE,
object oElement,
object oTags,
int i,
int iIndex

PCCursor()
If Not IsVirtualPCCursor () then
    TurnOffFormsMode()
endif
let oIE=IEGetCurrentDocument () ;; document object
let tagname=StringSegment(GetElementDescription (1, TRUE),"\n",1)
let oTags=oIE.body.GetElementsByTagName(tagname) ;;collection of elements
with common tagname (includes hidden elements)
let jawstagindex=GetTagIndex (tagname) ;; index of current element within
collection of visible elements of same tag
let iIndex=0

;;;;;; Loop through collection of all elements (including hidden) to find
the one that corresponds to the index
;;;;;; returned by GetTagIndex() function (only visible elements). Also
corrects for fact that DOM collection is
;;;;;; zero-based

For i=0 to oTags.length-1
   If stringcompare(oTags(i).type,"hidden") then ;; a visible element
      let iIndex=iIndex+1
   endif
   If iIndex==jawstagindex then
      oElement=oTags(i)
   endif
EndFor
Return oElement

EndFunction


On Wed, Aug 11, 2010 at 12:44 PM, Homme, James <james.homme@xxxxxxxxxxxx>wrote:

> Hi Travis,
> You are right about the line number thing. It reflects the number of lines
> in the virtual buffer. It has nothing to do with the document structure,
> unless the document forces the virtual buffer to display a new line.
>
> Jim
>
> Jim Homme,
> Usability Services,
> Phone: 412-544-1810. Skype: jim.homme
> Internal recipients,  Read my accessibility blog. Discuss accessibility
> here. Accessibility Wiki: Breaking news and accessibility advice
>
> -----Original Message-----
> From: jawsscripts-bounce@xxxxxxxxxxxxx [mailto:
> jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Travis Roth
> Sent: Wednesday, August 11, 2010 9:08 AM
> To: jawsscripts@xxxxxxxxxxxxx
> Subject: [jawsscripts] Re: Finding DOM element at the virtual cursor
>
> If the GetTag functions return an index which represents the number of the
> tag as it occurs in the document, perhaps you can loop through until you
> find the element of that number in the document?
> I don't know if that's how the index works... But it seems a better chance
> than the column and row count which I think is just a JAWS thing. I suspect
> if you use the verbosity settings to change the line length of the virtual
> buffr you will find those numbers change which would indicate its just a
> JAWS stat.
>
> So that'd leave hoping a tag index works. Or doing some serious hacking
> such
> as with GreaseMonkey scripts in Firefox to add an ID to every element...
>
>
> -----Original Message-----
> From: jawsscripts-bounce@xxxxxxxxxxxxx
> [mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of jaws tech
> Sent: Tuesday, August 10, 2010 10:48 PM
> To: jawsscripts@xxxxxxxxxxxxx
> Subject: [jawsscripts] Re: Finding DOM element at the virtual cursor
>
> I need a generic way to do this because the element that I am on may not
> have unique id or name information.  In fact the only thing that may come
> up
> for the elements I'm after are colspan=1 and one other one that I don't
> remember.  But those are not unique values.
> The GetTag functions only return an index not an object reference to an
> element.  I need to get an element as an object variable so I can then work
> within DOM functions.  Something like:
>
> oElement=insert code that I'm looking for
> saystring(oElement.innertext) (or some other DOM method/property)
>
> Like I said I prefer working in the DOM.  It is much more powerful/flexible
> than working with the JAWS functions.
>
> I was originally thinking of using the virtual cursor column position if
> that were in fact the sourceindex and then use code such as:
>
> iCol=GetCursorcol()
> oIE=IEGetCurrentDocument()
> oElement=oIE.all(iCol)
>
> But this wasn't working for some reason.  In fact, I don't even think I was
> succeeding in getting the "all" collection.  And as I alluded to in my
> original post, I don't know if the virtual cursor column represents the
> sourceindex of the document or not.
>
> Any other ideas??
>
>
>
> On Tue, Aug 10, 2010 at 9:53 PM, Chad Foster <chad.foster@xxxxxxxxxx>
> wrote:
>
> > Check out the GetTag functions. They can help you locate tags and
> > corresponding indices.
> >
> > On 8/10/10, Travis Roth <travis@xxxxxxxxxxxxxx> wrote:
> > > I've not tried it, but I'd suggest looking at the
> > > GetElementDescription() function and seeing if you can parse out the ID
> or name attribute.
> > > If an element doesn't have either of those its going to be difficult
> > > to
> > find
> > > in the DOM with JavaScript...
> > >
> > >
> > > -----Original Message-----
> > > From: jawsscripts-bounce@xxxxxxxxxxxxx
> > > [mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of jaws tech
> > > Sent: Tuesday, August 10, 2010 5:45 PM
> > > To: jawsscripts@xxxxxxxxxxxxx
> > > Subject: [jawsscripts] Finding DOM element at the virtual cursor
> > >
> > > Hi All.
> > > I would like to find a reliable way to find the DOM element
> > > corresponding
> > to
> > > the current virtual cursor position.  I like to jump into the DOM
> > > when
> > doing
> > > IE scripting instead of the JAWS functions and I need a way to grab
> > > the current element.  As most of you already know the
> > > GetFocusedElement() functions just grab wherever the PC cursor is
> > > and have nothing to do with JAWS'
> > > virtual buffer.  Also, can someone explain the significance of the
> > > row
> > and
> > > column output of the Virtual cursor's position.  The column position
> > seems
> > > to correspond to the source index but I'm not sure what the row
> > > might represent??  Understanding this might shed some light on
> > > getting into the DOM.
> > >
> > > Thanks
> > >
> > >
> > > __________�
> > >
> > > View the list's information and change your settings at
> > > //www.freelists.org/list/jawsscripts
> > >
> > >
> > > __________�
> > >
> > > View the list's information and change your settings at
> > > //www.freelists.org/list/jawsscripts
> > >
> > >
> >
> >
> > --
> > Chad Foster
> > Access Technology Solutions
> > Leveling The Playing Field Through Technology 
> > http://www.GO-ATS.net<http://www.go-ats.net/>
> > __________�
> >
> > View the list's information and change your settings at
> > //www.freelists.org/list/jawsscripts
> >
> >
>
> __________�
>
> View the list's information and change your settings at
> //www.freelists.org/list/jawsscripts
>
>
> __________�
> O
> View the list's information and change your settings at
> //www.freelists.org/list/jawsscripts
>
>
> This e-mail and any attachments to it are confidential and are intended
> solely for use of the individual or entity to whom they are addressed.  If
> you have received this e-mail in error, please notify the sender immediately
> and then delete it.  If you are not the intended recipient, you must not
> keep, use, disclose, copy or distribute this e-mail without the author's
> prior permission.  The views expressed in this e-mail message do not
> necessarily represent the views of Highmark Inc., its subsidiaries, or
> affiliates.
>  __________�
>
> View the list's information and change your settings at
> //www.freelists.org/list/jawsscripts
>
>

__________�

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts: