Archive

Posts Tagged ‘Javascript’

google calendar service and safari

October 22nd, 2008

 Fixing the “Unsupported Browser. Continue at your own risk” Error from Google Calendar Javascript API, when using Safari. First of all… why are they using alert with a service? And worse why are they using an alert in a method with no error handler? Anyways, Javascript is a nice language so we can silence google using a little script like the one below:

 var falert = window.alert;
 window.alert = function() { /* silence google */ };
 var calService = new google.gdata.calendar.CalendarService("wpng-calendar-plugin-1");
 window.alert = falert;

Software , , ,

conference website

October 7th, 2008

We just finished up our first virtual conference website.  It’s a kind of mix of event signup and confernce registration as well as related content.  The content is provided by the company hosting the conference, SAE.  I think I most enjoyed puting together the Dynamic Lead with the rotating images on the landing page.  I used Prototype UI’s carousel widget.

Dynamic Lead for SAE

Read more…

Software , , , , , ,

HeapSort: Prototype Graphics Framework

October 15th, 2007

I put together a little heap sort demonstration with PGF today… I had to add text support to the VML renderer for IE. The performance in PGF really isn’t that great. I’ve played with standalone SVG examples that were reasonably fast in comparison… Anyways, I think it’s pretty neat that there now exists a pretty capable library that allows anyone to create some pretty cool graphics directly in the browser without requiring any plugins…

Update:

I just noticed the text doesn’t render in mac firefox apparently a bug in the SVG renderer for mac (sighs)

Software , , , ,

DOM.ensure a DOMReady approach

September 27th, 2007
DOM.ensure( function(){
   $("node").observe("click",method1);
});

If we decide that we want to cache that markup and reinsert it back into the DOM later we’re still safe. If we had used the DOMReady approach our code would have needed to be much more complex to track when it’s ok to call the method and when it needs to be called in the event. This method is really away of letting us say we want to ensure that this block of code is not executed until the DOM is really ready.

Here’s a solution I created for implementing DOM.ensure.

DOM = Class.create();
Object.extend(DOM,{
  callQueue: $A([]), // store all calls in this queue
  isReady: false,
  // make sure the DOM may be effected before calling this method
  // if the DOM is ready then the method is called right away, else a timeout is set
  // until the DOM is ready
  ensureDOMIsReady: function(callback)
  { 
    if( DOM.isReady ){
      callback(); // call the method now
    }
    else{ // delay the call until the DOM is ready
      DOM.callQueue.push( callback );
    }
  },
  initialize: function() // call any methods that were queued up to be run when the DOM is ready
  {
    DOM.isReady = true;
    var queue = DOM.callQueue;
    while( queue.length > 0 ){
      queue.pop()();
    }
  }   
}); 
 
// detect DOM ready once for the whole page for each specific browser type
if( Prototype.Browser.IE ){
  document.onreadystatechange = function(){
    if( document.readyState == "complete" ){
      DOM.initialize();
    }
  }   
}   
else if( Prototype.Browser.WebKit ){// safari 2.0
  var _timer = setInterval(function() {
  if (/loaded|complete/.test(document.readyState)) {
    clearInterval(_timer);
    DOM.initialize();
    }
  }, 10);
}
else if( document.addEventListener ){
  document.addEventListener("DOMContentLoaded", DOM.initialize.bind(this), false);
}

Really it’s a change in the calling semantics for a DOMReady to think of it as more of a question of whether or not the DOM is ready for me to manipulate it.

Software ,

SimoHealth 1.2

August 1st, 2006

It was a pretty quiet release, but after many months we’ve release 1.2. It runs on top of XULRunner, the Firefox based runtime environment. We choose to use the XULRunner 1.8 tree instead of the 1.8.0 tree, so that we could make use of some of the new features like nsISAXMLReader.

New features in the product include it’s ability to manage multiple insurance plans per record. Meaning we support splitting a doctors bill between multiple insurance comapies - something our competitors don’t handle. Also, we reduced the footprint to only 6.9 megs from 8.04 megs. The download is free with registration.

Software , , ,

Understanding nsITreeView getCellProperties and getRowProperties

June 18th, 2006

You may have read the following text from xulplanet

An atomized list of properties for a given cell. Each property, x, that the view gives back will cause the pseudoclass :moz-tree-cell-x to be matched on the ::moz-tree-cell pseudoelement.



and start scratching your head wondering what it means. After searching through mozilla source for some examples of how getCellProperties or getRowProperties work, I finally figured it out and have a much greater respect for how the nsITreeView can really be customized. First an example of styling a specific cell and a complete row, assuming you already know how to setup your own nsITreeView:



The getCellProperties in our nsITreeView, checks the status column on a row and sets a property record_closed if the records status is closed:

 getCellProperties: function(row,col,props){
  this._fetchToRow(row);
  var record = this.records[row];
  if( record.status == "Closed" ){
    var aserv=CC["@mozilla.org/atom-service;1"].getService(CI.nsIAtomService);
    props.AppendElement(aserv.getAtom("record_closed"));
    if( col.id == "status_id" ){
      props.AppendElement(aserv.getAtom("record_status_closed"));
    }
  }
}

So, what is this property on the cell ‘record_closed’ and ‘record_status_closed’? It made sense to me once I found this using lxr, and realized I could control the style on the cell using it like this:

treechildren::-moz-tree-cell-text(record_closed,record_status_closed) {
text-decoration:line-through;
font-weight:bold;
}
treechildren::-moz-tree-cell-text(record_closed) {
color:gray;
}

Basically, it works like a CSS attribute selector.

So, now I can style the column that indicates the status as closed with a line through and color each of the cells with a gray font. getRowProperties works the same you just can’t effect the cell fonts, but you can effect the whole row background.

Software , , ,

Using nsISAXXMLReader and my nsIChannel Woes

May 29th, 2006

My first pass was to use nsIIOService to create an nsIChannel. This worked and gave me time to focus on getting my parser methods correct.

function runRestoreFromChannel( urlSpec, progress )
{
 var ioService = CC["@mozilla.org/network/io-service;1"].getService(CI.nsIIOService);
 var reader = CC["@mozilla.org/saxparser/xmlreader;1"].createInstance(CI.nsISAXXMLReader);
 var channel = ioService.newChannel( urlSpec,null,null );
 
 channel.notificationCallbacks = progress;
 reader.contentHandler = new RestoreParser( broker, progress );
 
 reader.parseAsync( null );
 channel.contentType = "text/xml";
 //channel.loadFlags = CI.nsIRequest.LOAD_BACKGROUND;
 channel.asyncOpen( reader, null );
}

This solution has one major flaw. The nsIFileInputStream that’s created reads in very large chunks from the filesystem for performance. The problem is during my parse I do some fairly intensive I/O operations as I read my data in. But since, almost all the data is read in by the nsIInputStream, it means my GUI is locked up while I’m processing the data. To get around this I thought about writing my own nsIStreamListener and controlling how the data is passed to my nsISAXXMLReader. The problem there is I’d either have to buffer all the data or still be stuck in a loop on the main thread blocking the UI. Ideally, I’d be able to run the parser in a background thread at full speed. As a simple workaround I can use nsIInputStreamPump. It works almost identically to using the nsIChannel, except I can specify how much data to read at a time (i.e. the chunk size). There was one minor little problem that can be worked around using a custom nsIStreamListener around the nsISAXXMLReader.

Here’s the code for setting up the parser:

var reader = CC["@mozilla.org/saxparser/xmlreader;1"].createInstance(CI.nsISAXXMLReader);
var filestream = CC["@mozilla.org/network/file-input-stream;1"].createInstance(CI.nsIFileInputStream);
var pump = CC["@mozilla.org/network/input-stream-pump;1"].createInstance(CI.nsIInputStreamPump);
var ioService = CC["@mozilla.org/network/io-service;1"].getService(CI.nsIIOService);
var channel = ioService.newChannel( urlSpec,null,null );
var uri = ioService.newURI( urlSpec, null, null );
 
filestream.init(file, 0x01, 0444, 0);
 
reader.contentHandler = new RestoreParser( broker, progress );
 
reader.parseAsync( null );
 
pump.init( filestream, -1, -1, StreamChunkSize, 1, false );
reader.baseURI = uri;
pump.asyncRead( new StreamListener( reader, progress, channel ), null );

Here’s the code for wrapping the nsIStreamListener:

function StreamListener( reader, progress, channel )
{
 this.reader = reader;
 this.progress = progress;
 this.channel = channel;
}
StreamListener.prototype = {
 reader:null,
 onStartRequest: function( request,context ){
   dump( "starting\n" );
   // XXX: passing channel here to work around bug in nsParser.cpp
   this.reader.onStartRequest( this.channel, context );
 },
 onDataAvailable: function( request, context, input, offset, count ){
   dump( "offset: " + offset + ", count: " + count + "\n" );
   // XXX: passing channel here to work around bug in nsParser.cpp
   this.reader.onDataAvailable( this.channel, context, input, offset, count );
   this.progress.onProgress( request, context, offset, offset + count );
 },
 onStopRequest: function( request, context, status ){
   // XXX: passing channel here to work around bug in nsParser.cpp
   this.reader.onStopRequest( this.channel, context, status );
 }
};

Software , , ,