Web Info & Tutorials

January 31st, 2007

EVAL’ING WITH IE’S WINDOW.EXECSCRIPT

Plaxo’s Joseph Smarr has been playing with on-demand javascript, i.e. downloading extra JS code after the page has already loaded. When you grab the code via a remote call and eval() it, it doesn’t get into global scope. So here’s how he dealt with it.

Here’s a simplified version of the situation we faced:

function loadMyFuncModule() {
  // imagine this was loaded via XHR/etc
  var code = 'function myFunc() { alert(\"myFunc\"); }';
  return eval(code); // doesn’t work in FF or IE
}
	
function runApp() {
  loadMyFuncModule(); // load extra code “on demand”
  myFunc(); // execute newly loaded code
}

The thing to note above is that just calling eval() doesn’t stick the code in global scope in either browser. Dojo’s loader code solves this in Firefox by creating a dj_global variable that points to the global scope and then calling eval on dj_global if possible:

function loadMyFuncModule() {
  // imagine this was loaded via XHR/etc
  var code = 'function myFunc() { alert(\"myFunc\"); }';
  var dj_global = this; // global scope object
  return dj_global.eval ? dj_global.eval(code) : eval(code);
}

This works in Firefox but not in IE (eval is not an object method in IE). So what to do? The answer turns out to be that you can use a proprietary IE method window.execScript to eval code in the global scope (thanks to Ryan “Roger” Moore on our team for figuring this out). The only thing to note about execScript is that it does NOT return any value (unlike eval). However when we’re just loading code on-demand, we aren’t returning anything so this doesn’t matter.

The final working code looks like this:

function loadMyFuncModule() {
  var dj_global = this; // global scope reference
  if (window.execScript) {
	
    window.execScript(code); // eval in global scope for IE
    return null; // execScript doesn’t return anything
  }
  return dj_global.eval ? dj_global.eval(code) : eval(code);
}
	
function runApp() {
  loadMyFuncModule(); // load extra code “on demand”
  myFunc(); // execute newly loaded code
}

And once again all is well in the world.

January 31st, 2007

SOUND WITH JAVASCRIPT BUT NOT FLASH

Reinier Zwitserloot wanted to see if he could add sound support without embedding a Flash bridge, and shared his research in his article on Sound in Web Browsers without Flash.

Check out his test page for a Sound Check

An example API

JAVASCRIPT:
  1.  
  2.                         function sound2Play() {
  3.                                 if ( !sound2Embed ) {
  4.                                         sound2Embed = document.createElement("embed");
  5.                                         sound2Embed.setAttribute("src", "machinegun.wav");
  6.                                         sound2Embed.setAttribute("hidden", true);
  7.                                         sound2Embed.setAttribute("autostart", true);
  8.                                 } else sound2Stop();
  9.                                 sound2Embed.removed = false;
  10.                                 document.body.appendChild(sound2Embed);
  11.                         }
  12.                        
  13.                         function sound2Stop() {
  14.                                 if ( sound2Embed && !sound2Embed.removed ) {
  15.                                         document.body.removeChild(sound2Embed);
  16.                                         sound2Embed.removed = true;
  17.                                 }
  18.                         }
  19.  
January 31st, 2007

SYNCHRONOUS CALLS AND BROWSER FREEZES

Mark Pruett did whatever experimenting with a hypothesis:

After actuation a coetaneous call, another application windows or tabs module be frozen, and the anachronic calls module not be serviced until the sync call completes.

For my experiment, I unstoppered up a application window, then unstoppered a ordinal application pane using the “New Window” schedule option. This module (hopefully) verify that both windows are conception of the aforementioned application process.

In pane #1, I alluviation my coetaneous effort and move a computer letter with a retard of 60 seconds. In pane #2, I alluviation the anachronic effort with apiece of the fivesome tests ordered to threesome seconds.

The results showed that browsers are activity nicely. Almost. Firefox didn’t time the effort in the underway steady versions, but the nightly physique was after proven and it was happy.

January 31st, 2007

VITAMINS FOR PROTOTYPE

The newborn Devjax library is a assemblage of plugins supported on image accumulation to add more functionality for scriptaculous, law and extends the DOM accumulation of prototype.

An warning of the impact is a WYSIWYG component:

JAVASCRIPT:

  1.  
  2. editor = new Devjax.Editor(‘editor-example’,
  3.         { width: ‘100%’,height: ‘200px’,
  4.         ImagesFolder: ‘/images/editor/’,
  5.         LoadURL: ‘EditorExample’,
  6.         LoadVARS: ‘file=examples/editor/files/index.html’,
  7.         SaveURL: ‘editorsave’,
  8.         OnDemand: true,
  9.         TextColors: [‘red’,‘blue’,‘black’,‘yellow’,‘brown’,‘white’,‘blue’,‘black’,‘yellow’,‘brown’],
  10.         ToolBox:[’save’,‘bold’,‘italic’,‘underline’,
  11.         ‘insertorderedlist’,‘insertunorderedlist’,‘justifyleft’,
  12.         ‘justifycenter’,‘justifyright’,‘font-color’,‘back-color’,‘insertimage’,‘createlink’]
  13. });
  14.  

Features

  • WYSIWYG Ajax Editor
  • Select signaling with CSS styles
  • In locate application for prototype
  • Image Ajax Fader for scriptaculous
  • DOM API extention
  • Rico draggables and droppables extension

The place itself is a single-page app that reloads the important content. This is preventative as it doesn’t hit bookmarkable pages.

January 31st, 2007

MOOTOOLS 1.0 ANNOUNCED

Mootools 1.0 was officially announced to the world.

Big Changes

  • All the MooTools Classes use now Events. No, not element events. Class Events. Right, you can add as many onCompletes as you want, onChange(s), onStart(s).. Well, you get the idea. Options starting with “on” become events, so need to change your code on this one.
  • All the code, plugins, everything now uses element events. With a completely rewritten event system, its now less memory hungry and a whole lot easier to add events to your elements. You wont find another .onclick in MooTools. We’ve also added the ability to fire an event by hand, or remove all of the events from an element, or all of the events of a certain type (ex. click).
  • There are also a number of new “Components”, like Color, to convert colors from HSB to RGB and vice-versa, Hash, to create more flexible javascript objects.
  • New plugins have been added, like SmoothScroll, the Scroller, Slider, Assets and Json.Remote, to make Ajax requests directly with Javascript objects. As always, you decide which components to include, so your own version wont be bloated.
  • Effects are now more powerful than ever, Fx.Style/Styles/Elements now can include colors and shorthand properties. They also support one value start (the starting value will be computed in real time). You have a div with height = 100 and want to go to 200? as easy as start(200). Fx will read your current style.

Read more

Any Mootools users out there? (I know there are). What do you like about it? What made you choose it as your library of choice?

Mootools

January 30th, 2007

THE INTERNET’S FIRST LIVE SHOPPING GAME SHOW.

Jellyfish (previously mentioned here) took their “smack shopping” promo to the next level last week with the introduction of “The Smackwheel”.

Billed as “The Internet’s First Live Shopping Game Show”, the user picking the closest percentage-off to the actual best deal gets a chance to step up and spin. The js wheel is “broadcast live” to the internet audience as the contestant hopes for prizes like (today) the Nintendo Wii - or if they’re really lucky: a rubber chicken.

You’ve got to catch their game at the right point to see it in action yourself… normally this means tuning in sometime shortly after 1PM Eastern. Today there’s a special promotion running “until ???”, so you may still be able to catch it in action over there

JellyFish SmackWheel In Progress

JellyFish SmackWheel Done

January 30th, 2007

JOE HEWITT FIREBUG POWER USER DEMO

Joe Hewitt (Firebug creator) gave a power-user demo of Firebug at the Yahoo! campus to share and explore the Firebug 1.0 release.

The video shows you the subtle features within:

  • Highlighting the DOM that you know your Ajax call will eventually update, and see Firebug showing you what is updated
  • The profiler at work: the difference between time spent only in that function, versus including recursive calls into other functions
  • Tying into the profiler from your code
  • Tips and tricks for the inspector, profiler, network, and more

It is always interesting to see the creator of a tool show you how they use it.

January 30th, 2007

WAML: WEB APPLICATION MARKUP LANGUAGE

Evgenios Skitsanos has created WAML: Web Application Markup Language:

WAML is added move of combine existed AJAX frameworks low azygos Application Markup Language. WAML - Web Application Markup Language. WAML allows you to delimitate your scheme covering attendance and functionality by using ultimate XML same structure integrated with HTML. The intent behindhand WAML is to simplify covering functionality definition and wage pliant admittance to UI objects, accumulation and act services. WAML functionality physique on crowning of existed AJAX frameworks acquirable for open use. After every WAML is dead FREE.

You module belike discern the markup from MXML and others.

Take a countenance at an example as source:

XML:

  1.  
  2. <?xml version=“1.0″ encoding=“utf-8″?>
  3. <wa :Application xmlns=“http://www.w3.org/1999/xhtml” xmlns:wa=“http://grafeio.eu/waml/” title=“Skitsanos WAML Framework”>
  4.         </wa><wa :Imports>
  5.                 <wa :Resource type=“stylesheet” url=“/app.css”/>
  6.         </wa>
  7.         <wa :Module>
  8.                 </wa><wa :Layout id=“ltApplication”>
  9.                         </wa><wa :LayoutPanel initialSize=“35″ location=“north” split=“false”>
  10.                                 <div id=“ApplicationHeader”>WAML Framework</div>
  11.  
  12.                         </wa>
  13.                         <wa :LayoutPanel autoScroll=“true” collapsible=“true” initialSize=“200″ location=“west” split=“true” title=“Actions” titlebar=“true”>
  14.                                 </wa><wa :Accordion id=“acc1″>
  15.                                         <wa :AccordionPanel contentUrl=“/docs/waml-objects.waml” id=“panel1″ title=“Documentation”/>
  16.                                         <wa :AccordionPanel contentUrl=“/docs/waml-samples.waml” id=“panel2″ title=“Samples”/>
  17.                                         <wa :AccordionPanel contentUrl=“/docs/ajax-frameworks.htm” id=“panel3″ title=“Frameworks Used”/>
  18.                                 </wa>
  19.                        
  20.                         <wa :LayoutPanel autoScroll=“true” location=“center”>
  21.  
  22.                                 <div style=“padding: 10px;”>
  23.                                         <wa :Box id=“boxRounded” Corners=“all” CornerType=“smooth” InnerColor=“#888″ OuterColor=“#fff” style=“width:600px; padding: 3px; color: #fff;” contentUrl=“/docs/waml.waml”/>
  24.                                 </div>
  25.                         </wa>
  26.                         <wa :LayoutPanel initialSize=“20″ location=“south” split=“false”>
  27.                                 <div style=“background-color:#c3daf9;”>© 2007, Evgenios Skitsanos. | <a href=“http://www.skitsanos.com” target=“_blank”>http://www.skitsanos.com</a>
  28.                                 </div>
  29.                         </wa>
  30.  
  31.                
  32.        
  33.  
  34.  

and study it to the output that module countenance old to those of you that ingest YUI.

January 30th, 2007

MICROSOFT ASP.NET AJAX CHEATSHEETS

Milan Negovan has a new set of href="http://www.aspnetresources.com/blog/ms_ajax_cheat_sheets_batch2.aspx">cheat sheets for the Microsoft ASP.NET Ajax library.

The existing cheat sheets have been updated for the 1.0 final release, and Milan has added two new ones for DomElement and DomEvent.

Check out the Microsoft Ajax Cheat Sheet

January 30th, 2007

QUIZLET: MOOTOOLS BASED LEARNING TOOL

Andrew soprano fresh launched Quizlet, a place for acquisition vocabulary. It gives you tools to think knowledge text that you enter.

Quizlet is a mootools supported application, and is impalpable in its ingest of the framework.

Quizlet