Tuesday, January 25, 2011

Customize your Modernizr download (errors on page)

I have tried this web site today and have run ito "lame code" controlling the
checkboxes to customize download:
http://modernizr.github.com/Modernizr/2.0-beta/


 $("a.toggle-group").live('click', function() {
    var group = $(this).closest(".features");
    var checkbox = $(group).find(':checkbox');
    checkbox.each(function(){
      $(this).attr('checked', !$(this).is(':checked'));
    });
    event.preventDefault();
  });


Please fix otherwise we will end with errors like:
Error: event is not defined

Source File: http://modernizr.github.com/Modernizr/2.0-beta/#
Line: 173

Thursday, January 20, 2011

MSIE and incorrect .src and .href (final solution ?)

Could this be a final solution for uri resolving in .src and .href for MSIE ? (blogged before, search..)

function getUriRef(element, attrName) {
    //MSIE sometimes returns unnormalized .src or .href property 
    //for LINK and SCRIPT tags, it has not been observed on a.href
    // example: s.src returns "sss" instead of ptoto://auth/sss
    // this is observable always on "some" pages and "some" elements
    // in case .src does not work -> getAttribute('src',4) works
    // when .src works (returns abs. uri), getAttribute('src',4) does not work and returns (raw)
    // TODO: detect, dont do always, study reason why this happens
    var uri = element[attrName];
    if (uri != null) {
        if (!(/^[A-Z][0-9A-Z+\-\.]*:/i).test(uri)) {
            //TODO: TEST XB for additional param, but i dont expect any normal browser to fail here
            uri = element.getAttribute(attrName, 4);
        };
    }
    return uri;
}

Deadly jQuery Selectors (my naive jQuery programming)

Deadly jQuery Selectors (my naive jQuery programming)


// give me all tags with href or src attribute
*[href],*[src]

//MSIE 8: 20000 ms ;-(
//FF 3.6: 1 ms :-)

// simple fix for this is to use plain old dom:

var uri, uris=[], i, e;
for (es = d().getElementsByTagName("*"), i = es.length; i; ) {
e = es[--i];
uri = e.href || e.src;
if (uri) uris.push(uri);
}
// MSIE 8: 323 ms ;-| not so bad

Tuesday, January 18, 2011

waitFor function

Blind code (not tested)
any comments welcomed


function waitFor(condition, onSuccess, onTimeout, timeout, pollInterval) {
    // TODO: document + testcase
    pollInterval || (pollInterval = 100);
    var endTime = new Date().valueOf() + (timeout || 10000),
  errs, //condition eval errors
        c,    // condition eval result (can be object)  
        check = function () {
            try { c = condition(); }
            catch (ex) { (errs = (errs || [])).push(ex); }
            if (c)
                onSuccess(c);   //receives condition result (ca be {})
            else if (new Date().valueOf() < endTime)
                setTimeout(check, pollInterval);
            else if (onTimeout)
                onTimeout(errs); //receives err result (null or non empty [] of Error)
        };
    check();
};

Wednesday, January 12, 2011

Mobile Perf bookmarklet by @souders (Link of the day)

I have been very pleased by todays tweets
specially @souders compilation of other bookmarklets:

Mobile Perf bookmarklet

I have looked a bit closer to some of them:
First:
DOM Monster
and I have posted two comments to GitHub:

issue/8
and
issue/7
Happy to receive reply:

From: madrobby

You're welcome to submit pull requests/patches. However, I think DOM Monster will grow and change quite a bit so premature micro-optimizations might be a 

might early...

View Issue: https://github.com/madrobby/dom-monster/issues#issue/8/comment/672058

But:
I consider both issues as basic coding practice, not optimization ! (rename to JS Monster ?)
I'm not "skilled" with github (yet) sorry.

I'm willing to contribute, but cannot be forced into how and when.

Some ideas and wishes
from my own unfinished code performing "page analysis".
My code is not only performance based so some may not aplly to DOM Monster.
  • Inline Scripts Detection
  • Standard vs. Quircks mode
  • Empty ULs and others that cannot be empty (semantics)
  • Meta tag "best pracices"
  • Anti-SEO hunter (bad, old SEO practices detection)
  • jSession string and other identifiers in URLs
  • Accessibility checks
  • DHTML event registration
  • Ajax style links (# fragment links)
  • .... more and more

So my bookmarklet is/was mix and
I'm thinking (thanx to @souders)
about splitting it into more categories now
and maybe "reuse" existing code or whole bookmarklet,
once they will comply with minimal "js qualities" ;-)