Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
The Wizard of Oz
Feb 7, 2004

I need to determine what the input focus is without touching any elements directly - so no onfocus injection. I also need to do this within an iframe which has arbitrary contents.

The only method I've been able to figure out so far is to inject a style element that has such a condition as:

code:
input:focus { unused: 666; }
Where unused can be anything that's not relevant to the control but is present. Then I window.getComputedStyle anything that seems appropriate and test for my property.

This works and should be portable but I wouldn't want to run it on a massive HTML file or one containing a huge number of focusable elements. AFAICT there is no standard solution. I've found the one that should be in Gecko, and now I mostly want to know if there's one for WebKit.

FateFree posted:

I am a java developer primarily, and my knowledge of javascript is pretty limited. I've come into a requirement for a project that takes a giant chunk of html (mostly text, a few bold, italic, or underline tags, and images are possible), and instead of displaying it in one page with a long scrollbar, the requirement is to paginate it so that the viewers can click a navigation bar on the bottom (first, next, page 1, 2, 3, .. 10, last etc).

Initially, this requirement was only for a chunk of text, so server side my java code would count characters and lines and line breaks, and break the text into several page objects, which were easy to paginate. However it never felt right because it seemed like this was something a browser was meant to do, and now that html is possible, I can't run the same algorithm because I can't compute the size of the images and i'd have to strip out all the tags and whatnot.

Can you think of a way this may be accomplished with javascript, or should I try to do it with java still? One thing that may be an issue is if the browser will know when to break apart the text in order to paginate it correctly. Any ideas?

You don't need to count characters/lines, just walk through at the document.body level testing node.getBoundingClientRect(). Once that exceeds a page, make a note to cut the document at that point and continue. When you've gathered all the pages together, blank the document if it's displayed, transfer nodes into your pages, and then show the first page.

This won't work for everything, and there can't be any general rule because the page could be dynamic or use CSS to break position order. But it'd be easy enough to chase the rabbit down the hole far enough to work for whatever it is you need.

That leads to a second question, is there any god-damned reason to be using offsetLeft/offsetTop/offsetParent when getBoundingClientRect does the same thing without a loop? I only started doing it because I had a page in Gecko flat-out fail when I tried the offset method, and AFAICT it always produces the correct result.

Adbot
ADBOT LOVES YOU

The Wizard of Oz
Feb 7, 2004

Nigglypuff posted:

getBoundingClientRect hasn't always been available in Gecko, iirc. But as long as it's there, you should definitely use it.

You're right, it's Firefox 3, and a port of one of IE's handful of good ideas. So no WebKit. I did find a page which covers all the edge conditions HERE.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply