Ajax and Ajax Frameworks

I have been a developer for nearly 20 years and a web developer for about 10 years. Over the years, I have considered creating a blog to share the things I have learned (and am learning) about web design and development, but I never seemed to have the time. When I began learning about web development using Ajax and Ajax Frameworks, I decided to take the time to create this blog.

My intention for this blog is to focus primarily on Ajax Frameworks, but since web development requires knowledge of many technologies, I will occasionally write about things such as CSS, Javascript, PHP, MySQL, Flash, etc.

Lately, I have been using JQuery as my primary Ajax tool. Although I have used other Ajax Frameworks in the past (Dojo Toolkit, Yahoo! User Interface Library, Scriptaculous/Prototype), JQuery has thus far been the easiest to learn. In my first few posts I will discuss some of the JQuery Plugins that I have created. Some of these include: a plugin for Google Maps (jquery.imGoogleMaps), Form validation and submission  (jquery.imValidateForm), Page Populater (jquery.imPagePopulate), and a plugin to create lists (jquery.imList).

While I am still learning about some of the other Ajax Frameworks, I hope that what I have learned will be helpful to others. Just remember, “When you can pull the pebbles from my hand…”

YAHOO.util.Dom.batch

Friday, March 27th, 2009

I have been trying to find a YUI method that is similar to the JQuery $.each method, but the closest thing I could find for the current version of YUI is YAHOO.util.Dom.batch (YUI 3 has an ‘each’ method, but I haven’t explored it thoroughly). While this method is not as powerful as JQuery’s $.each (see example), it is still a very good replacement for a Javascript ‘for’ loop when iterating over a DOM collection.

In Javascript, to iterate over a Dom collection, I would do the following:

?View Code JAVASCRIPT
this.getFormValues = function(form, fncName) {
     var str = "";
     var fn = eval("this."+fncName);
     var nL = form.elements.length;
     for (var i = 0; i < nL; i++) {
          if (fn) {
               if (this.canSubmit) {
                    this.canSubmit = fn (form.elements[i]);
               } else {
                    break;
               }
          }
          if ((form.elements[i].type == 'radio') || (form.elements[i].type == 'checkbox')) {
               if (form.elements[i].checked) {
                    str += form.elements[i].name + "=" + escape(form.elements[i].value) + "&";
               }
          } else {
               str += form.elements[i].name + "=" + escape(form.elements[i].value) + "&";
          }
     }
     return str;
}

With the YAHOO.util.Dom.batch, I can do the following:

this.getFormValues = function(form, fncName) {
var str = "";
var fn = eval("this."+fncName);
YAHOO.util.Dom.batch(form.elements, function(el) {
if (fn) {
if (this.canSubmit) {
this.canSubmit = fn (el);
} else {
break;
}
}
if ((el.type == 'radio') || (el.type == 'checkbox')) {
if (el.checked) {
str += el.name + "=" + escape(el.value) + "&";
}
} else {
str += el.name + "=" + escape(el.value) + "&";
}
}
return str;
}

Although YAHOO.util.Dom.batch is not as versatile as JQuery’s $.each method, it is still a very powerful method.

Related posts

One Response to “YAHOO.util.Dom.batch”

  • Fabien Says:


    I found a good script in jquery to Highlight arbitrary terms : http://johannburkard.de/resources/Johann/jquery.highlight-3.js

    And, I would like convert this script in YUI, is it possible ? Some functionality are not in yui like (each, find, normalize(), end()).
    I think, I can use batch (similar to each).

    Can you help me to convert this script in YUI format ? (I’m learning javascript)
    Thanks

CommentLuv Enabled