Tag Archive - operator

Microformat Objects in JavaScript

Unfortunately for everyone out there, when I discover new things in JavaScript, it means I rewrite some parts of Operator, and I am in the middle of that right now. The thing that I discovered is the ability to have custom getters for objects in JavaScript.

One of the things I have wrestled with in the past is that my current model for accessing a microformat in JavaScript is clunky. You have two choices – you can either create the microformat in its entirety:

var hcard = createMicroformat(node, "hCard");

and access the properties like this:

alert(hcard.fn);
alert(hcard.adr.region);

or you can access an individual property like this:

var fn = getMicroformatProperty(node, "hCard", "fn");

The problem with the first approach is that you do a lot of work if you only want part of the microformat, and the problem with the second approach is that there is no caching of the data.

Enter custom getters:

var hcard = new hCard(node);
alert(hcard.fn);

and hcard.fn is not queried until you access it the first time and it is cached.

What I do now is that when the hCard is instantiated, I set the getter for each property to be a function that queries the property and then sets it (getMicroformatPropertyGenerator):

object.__defineGetter__(property, ufJSParser.getMicroformatPropertyGenerator(node, microformat, property, object));

getMicroformatPropertyGenerator looks like this:

getMicroformatPropertyGenerator: function(node, name, property, microformat)
  return function() {
    var result = ufJSParser.getMicroformatProperty(node, name, property);
    if (result) {
      microformat.__defineGetter__(property, function() {return result});
      return result;
    }
  };
}

The result allows for much cleaner code in an action, because the actions are now going to receive the microformat data object directly so they don’t have to worry about DOM nodes and things like that. All an action has to do is access the individual properties. This will also allow for actions that aren’t so dependent on microformats.

I’ll still keep the old way around if people want to use the microformat parser in web pages. If anyone knows of a cross browser way to do what I am doing, or even a better way to do it, please let me know.

Operator 0.7 is available

Operator 0.7 is on addons.mozilla.org. I have a few things I wanted to share about this release. New features will be at the end of this post.

I’m not sure people realize there are other ways to interact with Operator besides the toolbar. Not only can you have Operator on the status bar or as a toolbar button, but you can right click on a microformat on a web page to access Operator functionality (Sometimes you can guess where they are, but if you want to see exactly where the microformats are, you can turn on Highlight Microformats in Options). If you want to access Operator from the status bar, go to Options and check the box that says Display icon in status bar. If you want to acesss Operator as a toolbar button, select View->Toolbars->Customize… There is an Operator toolbar button that can be dragged into the Firefox user inteface. Once you have done either of these, you can go to View->Toolbars and turn off the Operator Toolbar.

This release introduces a basic user interface for installing user scripts. Note that ability to add user scripts has always been there, I’ve just never had a good UI. User scripts can be used to add new microformats and new actions to Operator. As a part of the introduction of this UI, I’m moving some of what I call the non tier 1 microformats out of the core Operator and made them available as user scripts. My decision as to which ones to remove was mainly based on which microformats fit best into the Operator model; that is to say it is easy to provide actions that relate to the microformat. It is very important for you to realize that user scripts have FULL JavaScript privileges. Do NOT install Operator user scripts unless you trust the people that are providing them. I am going to make all my scripts available at http://www.kaply.com/weblog/operator-user-scripts/. If you want to write your own actions or microformats, feel free to look at my scripts, but please be aware that this API is very much in flux. I don’t a good versioning mechanism right now, so at some point your scripts would cease to work. Note that I continue to support the original Operator action model, but not the original Operator microformats model. The microformats model is actually pretty close to final.

When I first created Operator, my stated goal was take the microformats that are on a web page and provide functionality up and above what was available in the web browser. Unfortunately, when I first started creating actions for the microformats, some of the actions I created were just a case of moving browser interaction into the Operator menus. (Go to web page being the best example). With the advent of a user interface for user scripts, I’ve taken the opportunity to move some of the function that shouldn’t have been there in the first place out of the core. Note that no functionality has been removed; it is all available as user scripts. If you have a very strong opinion on this, one way or the other, please let me know.

All that being said, let me outline the new features in Operator.

  • User interface for managing user scripts
  • Operator updated when DOM nodes are added or removed
  • Export All available for contacts and events
  • 30 Boxes support has been greatly improved
  • Interaction problems with McAfee SiteAdvisor are fixed
  • Major performance enhancements
  • Native getElementsByClassName is used on Firefox 3
  • Operator wasn’t working correctly with frames and iframes
  • New tag action for searching for videos on YouTube

In addition to those changes to the core, the following user scripts are now available:

  • Send to Bluetooth (Mac only)
  • hAtom
  • Simple GRDDL RDF export
  • XFN
  • species

Operator and DOM Mutation Events

This is working so well, I have to tell the world.

I just added support for DOM Mutation events to Operator. So now when DOM nodes are added and removed from the document, Operator will update appropriately.

But that’s not the coolest part…

I added support for the DOMAttrModified event. So combined with Firebug, you can actually interactively modify your HTML to add/remove/modify a microformat and Operator will update live based on the changes you make. It’s REALLY sweet.

New version coming soon….

SXSW Wrapup

I’m back to work after an action packed few days.

SXSW Interactive started Friday night and when I got there, the line was outrageous, so I thought I was going to miss the first panel I wanted to attend. After waiting a little bit, I mentioned to a volunteer I was a panelist and he said “What are you waiting in this line for?” and sent me to the panelist check-in. Membership has its privileges :) . After getting my badge, I went to How to Rawk SXSW. This gave me a chance to meet Tantek in person which was cool. Then I grabbed some free food at a party and headed home.

Saturday I skipped SXSW and instead headed with my wife and a couple friends to San Antonio to volunteer at the Dave Ramsey Live Event. Awesome time. It’s actually the fifth time we’ve volunteered. I can’t recommend this event enough (or Dave Ramsey in general) if you are looking to get control of your finances.

Sunday morning I got up a little late and rolled in to SXSW. I missed the 10:00 round, but caught Non-Developers to Open Source Acolytes: Tell Me Why I Care at 11:30 which was a really good session. After a quick lunch, I headed into the show floor to check out the booths, including the Firefox booth. Mary Colvig was there, as well as Rhian and Alex Polvi.

To start the afternoon, I went to Perspectives on Designing for Global Audiences which wasn’t what I expected, but at least I ran into Jonas Sicking. After that session, I went to AJAX or Flash: What’s Right for You? which was a great session about when Flash or Ajax is appropriate. Slides for that session are available at slideshare.net. That was followed up with The Future of JavaScript which convinced me to actually look forward to the sunsetting of Firefox 1.5 so I can use some new JavaScript features in Operator. At 5:00, I attended People-Powered Products where I learned about lulu.com which is a great site where you can publish your own stuff.

Sunday night, I went to the Microsoft party to get some free stuff, didn’t win the XBox 360, then headed over to the web awards for more free food. Then I decided to call it an early night.

Monday I got in a little later, but saw an interesting presentation by Timothy Ferriss on The 4-Hour Workweek. While I don’t agree with his stance on debt and credit, the presentation was very interesting and gave me some interesting things to think about, in particular the concept of selective ignorance. Looking forward to the book. At 11:30, I went to American Cancer Society: Applying Disruptive Technology for the Nonprofit Sector which was an excellent presentation about what the American Cancer Society is doing to embrace new technology. The coolest thing they showed was the Second Life Relay For Life. After the session, I got to talk with a couple guys about developing church websites and maybe got some leads on help for updating our church website.

After that session, It was almost go time for the microformats panel. I went back to the show floor and lost track of time, so I was a little late to the green room, but no one else was there yet, so I was OK. Once everyone showed up, we chatted a little about the order of things and then Tantek put on his T-shirts and we headed over. The room was full, depsite being up against Dan Rather. I thought the panel went great. You can check out some photos or blog posts including Wired. Lots of people came up afterwards with good things to say about Operator, including some folks from Yahoo!, Apple and emurse. Also got a chance to meet Eric Meyer. He made a nice comment about Operator moving forward the semantic web. I also met a guy from developerWorks who wants to put microformats on their website. After the session, I helped a guy from opensoul.org debug a problem in Operator which I fixed, as well as a problem with his site which he fixed.

After the session, I caught the tail end of Warren Spector on The Future of Storytelling and then went to the WaSP Annual Meeting: Takin’ it to the Street.

After the sessions, I was looking forward to the Mozilla Democracy Party, so I headed over. They had some good BBQ but I realized my place was at home with my family, so after eating, I headed out. Here’s some pics of the party.

Tuesday I wanted to be there at ten to catch Browser Wars Retrospective: Past, Present and Future Battlefields. Two very cool things during this panel – first, Arun plugged Operator in one of the questions, and second I realized that I knew Arun from a way previous life when I worked on the OS/2 version of Netscape Navigator out at Netscape. The session as a whole was very interesting. Also very cool is that I ran into Steve Ganz before the session, who I know only because I use his resume for testing hResume :) .

The last session I attended at SXSW was After Bust 2.0: Ten Years Later, Where Will We Be? which was an entertaining session, although not terribly informative. After the session I grabbed a quick lunch at P.F. Chang’s and then realized that the weather was getting bad. I decided to head home early so I didn’t get caught in the rain.

All in all, a great conference although I desperately wish IBM had been there demoing more of our stuff. In particular, we have two products that would have been great to see here, the AJAX Toolkit Framework for developing AJAX applications and our enterprise social software, Lotus Connections.

Incidentally, here’s some cool pictures of the river behind our house before and during the rain (we’re 90 feet up, so we don’t have to worry about it). Unfortunately, we didn’t get a picture when the water was really high, completely covering the area on the left.

Before the rain:

Before The Rain

During the rain:

During The Rain

SXSW – Posting from my Wii (mostly)

If you are going to be at SXSW this year, you can catch me at the microformats panel on Monday at 2. I’ll also be at the Mozilla/Democracy party Monday night.

(Feel free to use Operator to add those events to your calendar – both of those pages use microformats)

Operator Source Code is Finally Available

Update:ufJS and ufJSParser have ended up being integrated into Microformats.js. This will also be the core microformats code in Firefox 3. The API is documented here.

My apologies for taking so long, but the Operator source code is finally on svn.mozilla.org

For now, this includes ufJS and the ufJSParser. I am working on creating a separate project elsewhere to specifically cover the ufJS work, but for now it will be hosted with Mozilla labs.

The code is available under the trilicense.

Obviously I will accept contributions, but there is the potential that the ufJS work will be available under a different license such as the CPL, so contributors need to be aware of that.

The code in SVN corresponds to 0.7a plus hAtom support as well as fixes for the McAfee SiteAdvisor problems.

Enjoy.

Operator 0.7a is available

Operator 0.7a is available. This is an alpha release. Really.

You probably won’t notice anything obvious that has changed, but under the covers, things are very different. Here’s a list of some of the changes:

  • Complete rewrite of parser and actions system
  • Experimental support for species and XFN (These probably won’t be in the official release)
  • More complete support for hCard and hCalendar
  • Exporting a contact or event now gives you the option to save it to disk
  • You can choose to not remove duplicate microformats
  • Various bug fixes
  • Ability to drop in Brian Suda’s X2V transforms to compare results (More info on that later)
  • REMOVED: Ability to have default handlers for a given microformats

The new actions system is in flux right now, so I’m not giving any detail on how to write to it yet. Old handlers will still work, so if you have those, just drop them in.

If you find bugs, please report them as comments to this post.

As per my social contract, all code has been run through JSLint and migration from three versions of Operator have been tested.

Enjoy.

Rearchitecting Operator

Why does it seem that every piece of software needs to be rearchitected at least once or twice?

So after chatting with Andy Mitchell about his Webcards work we decided to collaborate to try to avoid duplicating effort. I’m just about done with phase one of that effort.

The results of this effort include:

  • Moving to a unified non Operator specific, non browser specific microformats parser.
  • Moving to a unified actions architecture (Extension specific right now, but we’re working on that.)
  • Nearly complete support for all included microformats.
  • Ability to use legacy handlers.
  • Ease of adding new microformats (I’ve added XFN and species just for fun).

After much internal struggle, I decided to actually remove one of Operator’s options because I think I was trying to hard. Operator has two modes, Actions and Microformats, and within Microformats, you could choose to have a “default handler” or display all handlers. If you chose not to display all handlers, you would get a similar UI (toolbar buttons), but they would only invoke the default handler. It seemed logical when I wrote it, but this function (if needed) can be emulated by actions. I hope no one complains about my removing this.

Visually, everything else remains the same, except I cleaned up the names of some of the actions. It’s really only the guts that have changed. Obviously there’s the potential for new bugs in this implementation, so I’m trying to get something out this week to start some testing.

If you have written handlers for Operator, please let me know so that I can make sure my legacy code is working. I’m not going to explain how to write to the new action API yet since it is not baked.

Thanks!

Parsing microformats

Update: This code is now contained in Microformats.js.

One of the things I’ve run into with Operator is learning how to parse microformats correctly. Instead of keeping the knowledge I’ve found to myself, I’ve decided to work with Andy Mitchell and create a generic cross browser microformat parser in JavaScript, tentatively called ufParser. That’s the reason I’ve been so quiet.

The parser allows for the creation of definition files for microformats, so that new microformats can be added to the parser easily. So far I have all of the Operator microformats done (hCard, hCalendar, hReview, hResume, geo, xFolk, rel-tag) and I have done XFN.

We’re also investigating the potential to create more generic actions as well (but I’ll maintain compatibility with old style Operator actions).

The next version of Operator will definitely use the new parser, so there might be some regressions here and there. Hopefully we’ll get them solved quickly

Stay tuned. I’m hoping to have something in the next week or so.

Operator 0.6.2 is available

The official release of Operator 0.6.2 is available.

Here’s a full list of new features:

  • Multiple languages available thanks mainly to babelzilla.
  • Fix for the tabbing interaction bugs
  • Options menu added to statusbar and toolbar button menu
  • xFolk support (needs to be added explicitly in Options if you are not a new install)
  • tag support for ma.gnolia.com
  • Improvements to adding calendar entries
  • include-pattern support for hCard and hCalendar
  • Implied “n” optimization for hCards
  • Improved debugging dialogs to use text area instead of alerts so they can handle large data and can be copied
  • When debug mode is on, microformats with invalid items are bolded
  • When debug mode is off, invalid microformat errors are placed in the Error console
  • When you are in microformats mode with all handlers and have debug mode on, you get an additional menutem called “Debug” that displays the source and internal representation of the microformat (no more keystrokes)
  • Selecting an invalid microformat displays error and source in the same window
  • Operator now follows the bookmarks toolbar conventions for opening new windows and tabs. This includes:
    • Opening links in the current window by default
    • Middle click opens in a background tab
    • Shift+click opens in a new window
    • Ctrl/Ctrl+Shift open in a new tab based on the hidden preference browser.tabs.loadBookmarksInBackground (which is the opposite of Select new tabs opened from links – see my previous post)
  • If you right click on a microformat, the microformat handlers show up on the context menu
  • I have added an experimental feature for highlighting microformats that can be turned on in preferences. Not only does it highlight microformats when you hover over them, when you select microformats in any Operator menu, they are highlighted on the page. Please give me feedback on this item.

Here’s my social contract status for this release:

  1. All code was run through JSLint
  2. All handlers were tested
  3. All migrations were tested
  4. This release contains safeguards against leaving in debug messages in
  5. I learned more XPath and was able to use it in more places to improve performance
  6. I made multiple beta versions available before the official release
  7. I fixed every bug that was reported so far

Note the “Extra Extra” tab in Debug is there for a reason – I’ll be posting about that soon.

Thanks for your support!

Page 4 of 6« First...«23456»