Joe Maller.com

Links for April 26, 2005


NAB Small World Moments

Talking to the cabbie during my taxi ride to the airport before leaving Las Vegas, it came up that Ben Maller is my brother. Of course the cab driver listens to Ben’s show.

The day I got back from NAB, my father-in-law called. He was being filmed for something related to USRF, his videographer knew of me, Joe’s Filters, and was even at NAB. And it gets better: The company the videographer was with, Beckman Coulter, was my one of my father’s first jobs out of college when it was Beckman Instruments.

Share |

link: Apr 25, 2005 12:03 am
posted in: Joe's Filters

getSelection() Workaround for Safari 1.3, 2.0 and Firefox 1.0.3

update 2: These workarounds also work with Safari 2.0 in Mac OS X v10.4 .
update: There’s a simpler fix, jump to the bottom.

Yesterday morning I noticed a change to the JavaScript/DOM getSelection() behavior in the new Safari 1.3 (in 10.3.9) and the most recent version of Firefox 1.0.3.

I’ve been using this method for years to pull selected text from web pages for several of my bookmarklets. The one I use most frequently generates a link from whatever text is selected. If nothing is selected, it grabs the document’s title. The change in getSelection() broke that bookmarklet, no selected text was recognized.

After a bit of research, I found Mozilla’s Safely accessing content DOM from chrome page which describes the security fixes behind the modification and detailing other problems the changes had caused. Based on Mozilla bug 290777 and this post by Buzz Anderson, both browsers seem to have problems with the change. Despite those bugs, I managed to find the simple workaround as described below.

What Safari and Firefox now seem to be doing is creating a DOM selection object from getSelection() instead of treating it as a simple string. The result is that getSelection() appear to be a string, but few of the string manipulation functions work without additional considerations.

The following examples are all intended to be tested as bookmarklets, drag them to your bookmarks bar for testing:

  • getSelection() test 1
    javascript:d=window.getSelection();
    alert(d);

    Works as expected in Safari 1.2.4, Safari 1.3 and Firefox 1.03, popping an alert containing the selected text. Trying to measure that returned string fails in Safari 1.3 and Firefox 1.0.3 but works in Safari 1.2.4:

  • getSelection() test 2
    javascript:d=window.getSelection();alert(d.length);

    The older version of Safari returns a character count for the string of selected text. Firefox and Safari 1.3 return “undefined”. There are quite a few other problems:

  • getSelection() test 3
    javascript:d=window.getSelection();
    alert(d.toString());

    Works in Firefox and Safari 1.2.4 but not in Safari 1.3.

  • getSelection() test 4
    javascript:d=window.getSelection();
    alert(d.toString().length);

    Getting the length after toString works in Safari 1.2.4 and Firefox.

Further inconsistencies between Safari 1.3 and Firefox 1.0.3:

  • getSelection() test 5
    javascript:d=window.getSelection();alert(d.type);

    Returns “Range” in Safari with a selection, returns “Caret” or “None” with nothing selected. Fails with “undefined” in Firefox. (I think the Firefox 1.0.3 DHTML regression bug might be preventing it from working in Firefox but I didn’t try any of the recent nightly builds.)

  • getSelection() test 6
    javascript:d=window.getSelection();
    alert(d.getRangeAt(0));

    Fails silently in Safari, returns selected text in Firefox. Safari dumps this into the Console log:
    [5956] :TypeError - Value undefined (result of expression d.getRangeAt) is not object.

  • getSelection() test 7
    javascript:d=window.getSelection();
    alert(d.typeDetail);

    Fails with “undefined” in both.

There is some good news:

  • getSelection() test 8
    javascript:d=window.getSelection();
    alert(d.isCollapsed);

    Works in both Firefox and Safari 1.3; fails in Safari 1.2.4 as “undefined”. This means (finally!) there is a workaround for my problem.

I was using the length property to determine whether a selection was empty or not, then fetching the title of the window if that value was 0. Knowing that length no longer works in Firefox and Safari, isCollapsed can be used as a conditional switch.

  • getSelection() Workaround
    javascript:d=window.getSelection();
    d=(d.isCollapsed||d.length==0)?document.title:d;
    alert(d);

    That will return any selected text or the document title if there is no selection. Tested successfully in Safari 1.2.4, Safari 1.3, Firefox 1.0.3 and presumably Safari 2.0 as well.

Line breaks were added to visible code examples because my style-sheet choked on long lines and I can’t redo the CSS right now…

Update: After working through all of the above, I realized there is a far simpler solution: +''. The Safari problem seems to be that string methods do not work on the returned object from getSelection(). Forcing the result into a string by concatenating with an empty string fixes all of my bookmarklets. Concat() fails because it’s a method of string, use the "+" joining operator and an empty string '' instead.


Links for April 23, 2005


Ugly.

Person A, whom I met at NAB and enjoyed spending time with, tells a very ugly story about the actions of Person B, who I have not met. Having talked at length with Person A, I believed his story. Apple and several other people I trust also believed Person A’s story.

Based on others’ conclusions I made a quick decision to de-link Person B from the FXScript Reference site when I had brief internet access. At the time I wondered if that was the right thing to do, what the repercussions would be and whether or not that was even the right decision having only heard one side of the story. Shortly after I removed the link, Person B wrote me and asked what I’d been told then denied everything in advance.

This sucks.

I only know one person’s story and the other person’s denial of that story. And I want nothing to do with this.

The following four scenarios are all possible:

  1. Person A is telling the truth, Person B is a liar.
  2. Person A is a liar, Person B is telling the truth.
  3. Person A and Person B are both lying.
  4. Neither Person A or Person B are lying.

Conclusions 1 and 2 seem most plausible. Since it seems certain that something bad happened between Persons A and B, I decided the best immediate course was unfortunately to de-link everyone from the FXScript Reference, at least for now.

The question of what to do seems to come down to potentially rewarding someone who doesn’t deserve it. By only de-linking the two people involved, the person in the right is unduly tarred with their accuser. Linking everyone ignores what is obviously a bad situation and rewards whoever is guilty. De-linking everyone seems more fair than either of the two above options though drastic and personally disheartening. This negatively affects all the others who have nothing to do with this, but I just don’t see any other ethical resolution. I am open to suggestions.

Since our session, the remaining panelist was also contacted by Person B. My first impulse is to go completely transparent, post everything and absolve myself of any position. But the charges are very serious and there is an ongoing legal case, so it would be inappropriate for me to represent any information. Since I have already acted once, I will post my reply to person B in it’s entirety:

I am sorry about the de-linking. It was a rash decision made between sessions at NAB with 10 minutes of internet connection. Until I know the full story of this disagreement, I’m taking down all links to everyone but myself. I’m not happy about that, but it seems like the correct thing to do based on limited knowledge.

Since you seem fully aware of what you’re being accused of and who is involved, I would appreciate hearing your side of the story. I do not feel comfortable disclosing anything I was told. I’ve already mistakenly appeared to take sides and I do not want be involved with these accusations in any way.

I have spent a great deal of time trying to create a small community around FXScript and it greatly saddens me to see this happening.

I look forward to your reply,

Joe Maller

As stated in that reply, I have put a lot of energy into building a small community around FXScript. NAB’s third-party plugin session was my idea and something I worked towards for months and helped organize. Since I first published my notes about FXScript at least a half-dozen new products have been created using the language and countless others have added hacks and modifications to their FCP workflows. Many of those people have written to thank me for helping out. That means more to me than I can say and keeps me going in spite of stuff like this.

Share |

link: Apr 22, 2005 8:54 am
posted in: Uncategorized
Tags:

Links for April 21, 2005


NAB update coming

Getting back to NYC was merciless. I’ll post details tomorrow once I’ve had a real night’s rest. Unless I can’t sleep, then I’ll post later tonight…. Overall, a very exciting show. FCP users are the best.

FCPUG raffle licenses have been mailed out. If you won and didn’t receive one please contact me.

Share |

link: Apr 21, 2005 10:05 pm
posted in: Joe's Filters


« Previous PageNext Page »