Snippets code from my daily experience

January 12, 2010

Porting Table2Clipboard to Jetpack

Filed under: jetpack,table2clipboard — dafi @ 7:54 pm

I’ve written many Jepacks to solve little annoying problems mainly related to urls and tabs.

JetColorTab, the 50 Line code contest’s winner born to solve a need without installing full features extensions.

In these days the Mozilla community (and me) has debated about the future of Jetpack and XUL and many people says “a big number of extensions can be written simply using standard DOM and HTML”

This sentence intrigued me so I’ve tried to rewrite Table2Clipboard (T2C) for Jetpack, T2C makes a simple operation, it copies HTML selection also DOMRange to clipboard preserving the format and many other aspects.

After 30 minutes the porting was completed (excluding the UI not yet rewritten) so heavily DOM oriented extensions can be easily ported to Jetpack but some XUL code remains.

Extensions like NoScript or AdBlockPlus today are very hard (impossible??) to move to Jetpack and hopefully this is not necessary because XUL sits near to us for a long time :)

Little fixes to T2C required

  • Jetpack version 0.6.2 doesn’t allow (or at least I’m not able) to use modules so while waiting for CommonJS comes to Jetpack it is necessary to copy all scripts into the main jetpack file
  • HTMLTableElement, HTMLTableCellElement, HTMLTableRowElement are not “visible” so expressions like
    if (a instanceof HTMLTableElement) {}
    

    don’t work but this isn’t a problem because the code can be written more efficiently

    if (a.localName == "TABLE") {}
    
  • gContextMenu.target can be replaced by the standard Jetpack context.node, the parameter context is passed for example to beforeShow()

Where XUL is necessary and improvements required

  • Jetpack allows to obtain the text or HTML selection using jetpack.selection but it doesn’t expose the focusNode so I used jetpack.tabs.focused.contentWindow.getSelection() (i.e. XUL nsISelection)
  • XUL clipboard supports flavors but under Jetpack you can set only one at time, so you can’t add text version plus html version of same content, I think the ‘set’ method should have an ‘add’ mate
  • T2C needs to access to CSS using ownerDocument.defaultView.getComputedStyle
  • T2C uses the inIDOMUtils, it should be great if this interface become available from Jetpack

Jetpack Table2Clipboard can be downloaded from the Jetpack Gallery

December 20, 2009

Contributions, now it’s my turn (Sunday Thought)

Thanks to the contribution platform available at AMO I bought one book and a couple of software licenses (not open sourced).

I can say that the AMO contribution feature is a great success for me, dozen of donors for two ‘not so famous‘ extensions like Table2Clipboard and ViewSourceWith.

Now I’ve a little budget to use to make contributions because NOW it’s my turn!

I’ll contribute to Firefox extensions without forget other open source projects especially the utilities, I love the little time saver applications :P

I chosen low ‘Suggested Donation’ amount for my extensions but this has generated very expensive PayPal fees per transaction so I’ll make fewer contributions but all higher than 5$, I would the software authors take maximum profits from donations.

I hope in my country (Italy) PayPal made available micropayments very soon.

I would like to receive contributions also for my Komodo extensions, strangely the official dafizilla website doesn’t attract donors (I don’t like to fill it with banners and donations messages), I hope rumors about the Add-On Store will be confirmed and the store will host not only browser (i.e. Firefox) extensions and more important it will host also free/open source components.

September 14, 2009

Table2Clipboard 1.0 now preserves styles

Filed under: excel,extension,firefox,openoffice,table2clipboard,xul — dafi @ 6:49 pm

Finally after almost a year I release a new version of Table2Clipboard, one of twelve extensions that won in 2008 the Firefox 2 Contest in the section Runners Up.

What’s new

Until now Table2Clipboard has pasted to clipboard the structure of HTML tables without the styles (colors, borders, fonts) but many users have asked me that the behavior was much more similar to that of Internet Explorer (IE) which indeed maintains many details.

Well, the version 1.0 preserves the styles and in certain cases the result is better than that obtained with IE.

IE inserts also the DOM elements declared “not visible”, for example the table shown in Figure 1  is pasted in Excel as shown in Figure 2.

ie

Figure 1

Table selection on Internet Explorer

excel-from-ie

Figure 2

Copy from Internet Explorer paste to Microsoft Excel

Table2Clipboard discards hidden DOM elements as shown in Figure 3, this makes more sense for me.

Paste from Firefox with Table2Clipboard to Microsoft Excel

Figure 3

Copy from Firefox with Table2Clipboard paste to Microsoft Excel

Other little improvements

Now web links are copied and user can choose to copy images (tag IMG), too.
All defaults settings can be modified from configuration dialog.

The copy of styles on OpenOffice doesn’t work as well as the one on Microsoft products.
The “Paste Special” feature available on OpenOffice doesn’t recognize CSS styles but only deprecated tags like FONT.

I will add support for OpenOffice soon but I prefer the “release early release often” (after a year??? :P) approach so this version has poor styles support on the popular open source office automation suite.

Compatibility issues with Thunderbird 3.x are now fixed.

Table2Clipboard can be installed from AMO or from the project site on dafizilla.

August 1, 2009

Table2Clipboard and clipboard application interoperability

Filed under: calc,clipboard,excel,extension,openoffice,table2clipboard,xul — dafi @ 10:35 am

calc_excel_t2cMany users asked to me to add to the extension Table2Clipboard (T2C for friends) the ability to preserve web links and maintain the styles during tables copy.

Preserving links and other HTML tags was a very easy task, I’ve written the code very quickly and both OpenOffice Calc and Microsoft Excel have handled correctly the pasted content.

When I started to support style preservation I discovered different and ugly results on the two popular office suites making harder to write cross platform XUL code.

Actually T2C pastes to clipboard inserting data in two different formats (flavors), unicode plain text and HTML format.
When users do “Paste Special” the HTML format is pasted and applications (Excel or Calc) render inside the data sheet.

Both Excel and Calc handle only the deprecated FONT tag and a subset of TABLE tag attributes and this represents a great limitation for style preservation from T2C.

If you try to paste from Microsoft Explorer to Microsoft Excel you discover everything is copied, the styles are totally preserved but if you paste from Explorer to OpenOffice Calc all style are lost!!!

Well, Explorer inserts to clipboard also RTF formatted text and Excel works very fine with the barely public RTF file format.

Clipboard application interoperability goes to hell, HTML is not fully supported by the “Paste Special” feature available on both suites, and as usual Microsoft uses semi proprietary data formats to exchange informations between applications.

I think at least OpenOffice should improve its “Paste” feature simply adding support for HTML style attribute.

T2C can preserve correctly styles only implementing platform specific code for OpenOffice and Microsoft Office and I really hate write specific platform.

I’m considering other alternatives but I see only the darkness of C++, OLE and core dump…

April 7, 2008

How to get element style values from XUL (or HTML)

Filed under: css,table2clipboard,xul — dafi @ 8:15 pm

I’m working to my Extend Firefox 2 Runner Up winner Table2Clipboard.

Many users tell me to add a simple feature, exclude cells having style display: none.

The solution is so straightforward that I could not believe after initial implementation.

You can style an element using CSS selectors

.invisible {
display: none;
}

<span id=“invisibleSpan” class=“invisible”>I’m invisible man</span>

or using the attribute style attribute

<span id=“invisibleSpan” style=“display : none”>I’m invisible man</span>

These two ways can both simply handled using getComputedStyle

var spanElement = document.getElementById(“invisibleSpan”);
var style = spanElement.ownerDocument.defaultView.getComputedStyle(spanElement, null);
var displayValue = style.getPropertyValue(“display”);

That’s all folks!!

Obviously you can use any CSS attribute not only display.

Pay attention to ownerDocument.defaultView, you should use window.getComputedStyle() but under XUL this doesn’t return what you expect.

getComputedStyle can be used in normal unprivileged HTML code, too.

getComputedStyle is a W3C standard and is present on Internet Explorer, Opera and Safari, too.

Little things make developer life easier.

February 14, 2008

Extend Firefox 2 Contest and other surprises

Filed under: firefox,mozilla,openkomodo,table2clipboard,Uncategorized — dafi @ 9:06 pm

January and February are very important months for my programming activites.

In January ActiveState guys gave me a KomodoIDE license for my contribution to their OpenKomodo wiki, a great unexpected surprise, the first one.

A couple of days ago Mozilla published the Extend Firefox 2 Contest and I discovered my name on “Runners up” list, a great
unexpected surprise, the second one.
I can figure out ViewSourceWith is the winner, no! The winner is Table2Clipboard my outsider extension, a great unexpected surprise, the third one.

I’m happy that other people appreciates my work.

My feed reader alerts me, LifeHacker has new contents, I take a look and found they speak about Table2Clipboard, a great unexpected surprise, the fourth one.

ActivateState gave me a KomodoIDE license, EF2 prices contain a KomodoIDE license, now I have two KomodoIDE license, another surprise the fifth :D

Mumble mumble… may I sell the unused license?

The Rubric Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.