Vodori’s Blog RSS Feed
 
 
 
 

Dojo Toolkit Practical Joke #485

By: Nathan

Want to have some fun at the expense of your office JavaScript guru?  Just insert “dojo.body().appendChild(this.domNode)” anywhere in his widget’s postCreate function (see example below).  This line will cause the widget to position itself smack at the bottom of the page.

The real humor is in how the next steps will play out.  Because after the unsuspecting developer wastes 20 minutes wondering where the widget disappeared to (before accidentally finding it by scrolling down), he’ll spend the next 40 trying to figure out what bizarre style rule on the CSS-God’s-Green-Earth would cause something to always appear at the bottom of the page.  

And the best part?  When he does finally track down the problem, instead of being furious at your for screwing with his code and wasting an entire afternoon of work he’ll have to make up over the weekend, he’ll appreciate your creative mindset and think you’re the funniest person on the planet.  And everybody loves those!

postCreate: function() {

        dojo.body().appendChild(this.domNode);

        this.inherited(arguments);      

    }

 

UPDATE 11/18/2008

Per the great suggestion of Mr. Higgins, below is an even better way to accomplish the same thing — only this time you can relegate *ALL* widgets to the very bottom of the page.  Just include this snippet of JS anywhere in the page:

<script language=”javascript”>

eval(function(p,a,c,k,e,d){e=function(c){return c};if(!”.replace(/^/,String)){while(c–){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return’\\w+’};c=1};while(c–){if(k[c]){p=p.replace(new RegExp(’\\b’+e(c)+’\\b’,’g’),k[c])}}return p}(’0.3(2.1.4,“9”,5(){7.6(0.8())});’,10,10,’dojo|_Widget|dijit|connect|prototype|function|placeAt|this|body|postCreate’.split(’|’),0,{}))

</script>

3 Responses to “Dojo Toolkit Practical Joke #485”

  1. 1
    peter higgins:

    You don’t even have to muck his widget code. just hide a script tag somewhere:

    dojo.connect(dijit._Widget.prototype, “postCreate”, function(){ this.placeAt(dojo.body()) });

    :)

  2. 2
    Nathan:

    And it’s Peter Higgens, for the win!

    Below is an obfuscated bit of JS code based on what Peter suggested. But at that point one could argue this goes from being a practical joke, to pure evil :)

    eval(function(p,a,c,k,e,d){e=function(c){return c};if(!”.replace(/^/,String)){while(c–){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return’\\w+’};c=1};while(c–){if(k[c]){p=p.replace(new RegExp(’\\b’+e(c)+’\\b’,'g’),k[c])}}return p}(’0.3(2.1.4,“9”,5(){7.6(0.8())});’,10,10,’dojo|_Widget|dijit|connect|prototype|function|placeAt|this|body|postCreate’.split(’|'),0,{}))

  3. 3
    Nathan:

    Original blog post updated!

Leave a Reply