Re: RDFa API: ondata="javascript: foo();" attribute for <body> element?

Nathan wrote:
> Nathan wrote:
>> Manu Sporny wrote:
>>> I haven't thought this through very well, but was wondering if it would
>>> be advisable to have an ondata attribute for the <body> element? This
>>> would work very much like the onload attribute that is already on the
>>> <body> element.
>>>
>>> I can see a few implementers complaining that the RDFa processing of a
>>> document could take a long time (as in more than 100ms), especially if
>>> certain RDFa profiles take a while to retrieve or timeout.
>>>
>>> The worst case is that a bad implementation of the RDFa API would cause
>>> the document not to render because the RDFa profiles are being
>>> fetched/processed. Ideally, RDFa processing should happen 
>>> asynchronously.
>>
>> Perhaps then all parsing should happen asynchronously.
>>
>> DataStore could implement EventTarget and provide and dispatch the 
>> onload event whenever processing has completed.
>>
>>   var store = document.data.createStore();
>>   store.onload = function(event) {
>>     // triggered when the store is ready
>>     // i.e. once parsing is finished
>>   }
>>   var parser = document.data.createParser("rdfa1.1", store)
>>   parser.parse( somedocument );
>>
>>
>> Actually, thinking about this more, an XMLHttpRequest style readystate 
>> may be needed, ie add the following:
>>
>> interface DataStore : EventTarget {
>>
>>   attribute Function onerror
>>   attribute Function onload
>>   attribute Function onreadystatechange;
>>
>>   const unsigned short EMPTY = 0;
>>   const unsigned short LOADING = 1;
>>   const unsigned short DONE = 2;
>>
>>   readonly attribute unsigned short readyState;
>>
>> }
>>
>> Ack, this brings up a whole host of (sadly unavoidable) questions - 
>> I'll mail them under separate cover - sorry.
> 
> Scratch that, there are no issues :D thanks to:
>  - All instances of the DOM Document interface must implement RDFaDocument.
>  - The RDFa API must be initialized before the Web developer has access 
> to any of the methods that are defined in this specification
> 
> So, carrying on, given the interface above, any developer could simply.
> 
> document.data.store.onload = function(ev) {
>   // start processing when store is ready!
> }
> 
> This would be a very useful addition to the DataStore interface and make 
> async usage much nice - I'd love to see this added.
> 
> Back to the specific issue of adding 'ondata' to the Body element. 
> Provided RDFa data was in the Body of the Document then this would be 
> fine, as the event would bubble from Body to Document (unsure if it 
> would go as far as Window like onload does).
> 
> The name 'ondata' may raise some eyebrows though given the '@data-' 
> attributes in html5, the existing onmessage attribute, and the existing 
> onloadeddata used by media objects (like Audio & Video) which are both 
> already on Document. Thus perhaps a different, more accurate, name 
> should be chosen :)
> 
> Again though, big +1 from me.

Final thought, an additional attribute may not be needed if taking this 
approach, as one could simply

<body onload="javascript:loadProcessor"..

function loadProcessor() {
   if(document.data.store.readyState != DataStore.DONE) {
     document.data.store.onload = process;
     return;
   }
   process();
}

function process() {
   // start working with RDFs data from here..
}

Best,

Nathan

Received on Saturday, 4 September 2010 19:52:29 UTC