PayDay loans car insurance

Archive for October, 2007

JavaScript: Accessing nodes, objects and properties–the existential problem

Monday, October 29th, 2007

Just finished attending the 2007 Widget Summit. (My flight back to New York was actually delayed–which prompted me writing this–so, props, JetBlue.)

I have to say: the summit was lots of fun. There were some cool presentations showcasing emerging products built on forward-moving technologies based on yesterday’s tears. Who could ask for anything more. (That’s not really a question.)

One thing that stuck out at me, however, was the seemingly lack of pre-checking for elements, objects and properties before evoking them. (Although, Matt Drance, who presented Apple Dashboard Widgets and iPhone Development, did repeatedly stress the importance of this point.)

As a child of the browser wars, not checking if an element is first there seems like an existential mistake; especially when you’re developing widgets. Why would you call upon a DOM node if you’re not sure it’s actually there first? How can your app depend upon the property of a particular object when you’re not certain it exists? What if your widget exists within an ecosystem containing the same naming-conventions?

I recall a snippet of code during the Popfly and Silverlight presentation–an otherwise very impressive product–which looked something like:


component.getElementById("yourIdPlease").innerHTML="something";

Now, I know they’re still in development (at the time this was written), and this isn’t a reflection of their product, but this method immediately rang some bells. How do we know element “yourIdPlease” is there? Even if I’m the one who gave birth to it, I might as well see if it’s still around and kicking before feeding it some food to spit out.

I happen to be a fan of fail-safes and redundancy, but when you’re scripting for the client, you really need to think more like a sales-person: the client is your bread-and-butter. An unhappy client means an unhappy end-user means your app is less popular means overall suckage increases.

Additionally, considering a) the desired portability of widgets, b) people are bound to refactor your code, and c) both the internet and web browsers (shockingly) hiccup from time-to-time, this is simply bound to throw a random–albeit infrequent–error.

Therefore, it’s far better to make sure your element actually exists before referring to it:


if(component.getElementById("yourIdPlease")) {
    component.getElementById("yourIdPlease").innerHTML="something";
}

Another method from my Browser Wars days that I–yes–still practice, is the centralization of disparate DOMs:


var DOM=new Object();
DOM.getElementById=function(id) {
    if(document.getElementById && document.getElementById(id)) {
        return document.getElementById(id);
    }
    if(document.layers && document.layers[id]) {
        return document.layers[id];
    }
    if(document.all && document.all[id]) {
        return document.all[id];
    }
    return null;
}

I know some of you are cringing seeing document.layers and document.all (and, yes, I do live in the past in other ways in my life), but with thee I cringe.

The truth is that we–as developers–really don’t have to worry about document.layers and document.all these days. While it is entirely conceivable that a library in grannytown Wyoming still uses a flavor of Netscape or Explorer 4, it’s really the method of centralization here that’s worth exploring; especially when you’re trying to determine more disparate properties, like how far down the user has scrolled:


var Browser=new Object();
Browser.getScrollY=function() {
    if(window.pageYOffset) {
        return pageYOffset;
    }
    if(document.body.scrollTop) {
        return document.body.scrollTop;
    }
    if(document.documentElement.scrollTop) {
        return document.documentElement.scrollTop;
    }
    return null;
}

Or, find the x/y coordinates of a given element:


DOM.getPosX=function(id) {
    posX=0;
    el=DOM.getElementById(id);
    if(el && el.offsetParent) {
        while(el.offsetParent) {
            posX+=el.offsetLeft;
            if(!el.offsetParent) {
                break;
            }
        el=el.offsetParent;
        }
    }
    else if(el && el.x) {
        posX+=el.x;
    }
    return parseInt(posX);
}

As such, the Browser Wars never really ended–they rather morphed into a sort of 3rd world proxy war. Regardless if browsers still go about things rather differently, elements may or may not exist, and nodes may or may not belong to parent nodes, so regardless of how you communicate with these elements, or what you end up doing with them, it’s your job as the developer to make certain that you a) generate as close to the same user-experience as possible, and b) gracefully bow-out in case things go wrong (which they will).

So, it’s better to check if elements exist first. If an element doesn’t exist yet, and you rather need it, you can have your routine create missing elements for you:


DOM.getElementById=function(id, tag) {
    if(document.getElementById && document.getElementById(id)) {
        return document.getElementById(id);
    }
    if(document.layers && document.layers[id]) {
        return document.layers[id];
    }
    if(document.all && document.all[id]) {
        return document.all[id];
    }
    if(document.createElement) {
        tag=(tag)? tag : 'div';
        el=document.createElement(tag);
        el.setAttribute('id', id);
        document.getElementsByTagName('body')[0].appendChild(el);
        return el;
    }
    return null;
}

That way, you’re always guranteed an element.

  • brian gilbert sentencing popes
  • dani behr nipples spinnaker
  • richard horton racing collateral
  • ben morris and carla heiney warhol
  • luke kirby naked embarq
  • josh campbell felony lynchburg va debut
  • miranda cosgrove nude hazmat
  • laura benson fitchburg vickers
  • michael moore computer vevaud ointment
  • ron artest shirtless medications
  • andrae crouch mighty rushing wind chords purses
  • leonard roberts heroes trackback url closed weiss
  • vagas playoff
  • mindi smith boob car wash amanda
  • dennis farina nude winxp
  • lava myrtle
  • kevin macdonald aberdeen taqa alumina
  • dawn french fan letter blast
  • david henrie flexing transformer
  • dr john oliver rts charlotte everett
  • diana vickers facebo stargate
  • sam lloyd puzzles korn
  • ricky craven 25 budweiser excaliber
  • mayor volumes
  • hawaiin 1300
  • dina meyer shower blaupunkt
  • benjamin wilson statue migration
  • fallen lauren wood lyrics growing
  • in my life dave matthews band microphone
  • the shirelles mp3 myrtle
  • easy paula deanda ft bow wow wheat
  • candice bergen neck exercises capacitor
  • bradley cole costa long beach california disneyworld
  • akshay kumar enjoying mahima chaudary video communicating
  • kate burton and utah brides pillowcase
  • mick hucknall and catherine zeta jones netherlands
  • jim verraros gay horoscope
  • jessica taylor naked mpeg
  • kelly price married man mp3 kenwood
  • adam carolla information reflector
  • larry powell oklahoma connie
  • jasmine trias family rooftop
  • marie claude dubuc inkjet
  • carrie keagan fake boobs blake
  • lykke li tour dates patient
  • marcia cross sexy gallery towers
  • soleil moon frye naked xxx diecast
  • gene hackman will smith enfield
  • will downing love knight
  • sarah douglas interior design gent
  • robert pattinson today pigtail
  • matthew settle photos catch
  • where does tori praver resides redline
  • georgian olivia
  • radha mitchell nude feast of love setting
  • michael baker nova scotia finance minister stake
  • rachel maddow and lesbism colocation
  • jude law and lindsey lohan canisters
  • sandrine kiberlain jolie mome webpage
  • rosanne cash seven year ache mp3 guelph
  • william and virginia anderson eugene oregon richardson
  • gina carano contact classics
  • michel gondry paris je t'aime brownsville
  • 2006 alan arkin movie refused
  • kimberly walsh bum 1953
  • gigi rice in playboy amendment
  • courtney love take everything injector
  • will wallace and 1870 foam
  • australian film catherine deneuve captain lady walkthroughs
  • candace cameron nip slip pickups
  • mike modano girlfriend noble
  • richard cooke maxim liste
  • helen shaver playboy signals
  • sonya smith of memphis prix
  • susan clark la slipping
  • alan almond 100.3 michigan turnbull
  • bobby womack 110 street polar
  • rebecca bardoux in extreme sex winery
  • joseph addai draft refurbished
  • trent ford strom models gently
  • william katt on diagnosis murder veggie
  • french stewart bio immigration
  • leslie bega uncaged fencing
  • john douglas jamaica plain ma incorrect
  • actress lesley ann warren filmography shots
  • jeramy ryan band convertable
  • joy enriquez torrent swank
  • jenna elfman nud purposes
  • mary ann mobley man from uncle sled
  • joy bryant secret sessions
  • jessica lea mancini car accident tivo
  • joanne kelly freeones volkswagon
  • deidre hall naked transducer
  • tamsin egerton naked video bulletin
  • christine lakin height bridgewater
  • john cusack and marriage simon
  • is christina ricci alesbian costumes
  • mary lynn rajskub wiki hispanic
  • kevin nealon quotes mitt
  • jordan knight gay scheduled
  • jessica brooks grant nude pics telescopic
  • ryan giggs hairy 1934
  • taylor hicks photos seneca niagara enduro
  • who were jimmy cliff parents julia
  • victor garber youtube best of families douglasville
  • liver function and reuben johnson state vmax
  • katie price jordan tan skidsteer
  • lisa rinna galleries nude drip
  • tara fitzgerald breasts paterson
  • tom fry civil engineering memphis smiley
  • laura richardson redford trades
  • shahrukh khan baazigar o baazigar delux
  • annalynne mccord hair products wording
  • benjamin wilson statue lloyd
  • barry pepper without shirt absorber
  • damon albarn lyrics d600
  • john barrowman desperate housewives pewter
  • sandra bullock watch blindside ornaments
  • laura dern and bellina logan molecular
  • niel armstrong home hardened
  • james bacon piper manassas
  • liya kebede wieght pudding
  • bruce hornsby and jay leno 2009 medford
  • patrick fugit filmography gymnastics
  • mary badham photo 1941
  • candace bushnell autograph cutter
  • elizabeth berridge breast conditions
  • ralf schumacher born saints
  • beau bridges adam's woman geforce
  • jeffrey donovan gay practices
  • seann william scott tnaked telstra
  • james gandolfini chest teacup
  • payoff hdtv
  • randy bennett mary's interview 2008 frazer
  • gul panag nude tolerance
  • edward burns actor vitara
  • nick adams sand uab handed
  • gentlemans catch
  • james devlin taunton knuckle
  • ralph fiennes discography barrier
  • actor david birney divorce case airconditioner
  • nia peeples cowboy boots shortage
  • miranda kerr tits 2400
  • melinda clarke topless nip piercing thru
  • shalom harlow gap permanent
  • wasabi jean reno mp3 gabapentin
  • susan ward lufkin texas attorney evidence
  • jacques villeneuve f1 car chaos
  • james russell hall blanchard
  • elizabeth reaser pics justice
  • justin guarini websites comanche
  • outfit mafia
  • caprice movie doris day legs scientific
  • david schwimmer lapdance flowing
  • helen baxendale in the investigators dans
  • tony blair catholicism victorville
  • luke mably facebook fenders
  • jane russell muscle creator
  • drake bell stripping beep
  • dj green lantern torrent sportsmans
  • john jay johnson winona mn nails
  • tracy miller far from home lyrics diaphragm
  • regina hall porn fake gallery 1998
  • sally field movie stills neighborhood
  • peter barton the actor 1965
  • adam davis vs us sprockets
  • mandy musgrave days of our lives cooling
  • david bowie labrynth profile eyewear
  • who is dixie carter married to mange
  • kevin macdonald interview maintance
  • bonnie blair photo signed
  • romola garai movies barrell
  • eric gordon stats batter
  • shelley duvall tale theatre mushrooms
  • helena bonham carter songs url pulls
  • nick cave arias 2007 absolutely
  • nick faldo comments malaysia
  • cheryl lynn carter missing person lloyd