Loading ...
Sorry, an error occurred while loading the content.

YUI Dom and YUI Element

Expand Messages
  • foxxtrot713
    It appears that much of the functionality exposed by YAHOO.util.Dom does not support YAHOO.util.Element as it s element argument. Is this by design? Or a
    Message 1 of 2 , Jul 1 8:59 AM
    • 0 Attachment
      It appears that much of the functionality exposed by YAHOO.util.Dom
      does not support YAHOO.util.Element as it's element argument. Is this
      by design? Or a symptom of YAHOO.util.Element still being in Beta?
      Is anyone working on adding this functionality?

      Admittidetly, it's not hard to simply do a el.get('element') to get
      the HTMLElement object, but for API completeness it seems that the Dom
      utility should accept taking YUI Element's arguments.

      Jeff 'foxxtrot' Craig
    • foxxtrot713
      ... After looking at the dom-debug.js file for a bit, I realized this would be a really, really easy fix, so I went ahead and did it. At runtime, I now run
      Message 2 of 2 , Jul 1 12:03 PM
      • 0 Attachment
        --- In ydn-javascript@yahoogroups.com, "foxxtrot713" <foxxtrot@...> wrote:
        >
        > It appears that much of the functionality exposed by YAHOO.util.Dom
        > does not support YAHOO.util.Element as it's element argument. Is this
        > by design? Or a symptom of YAHOO.util.Element still being in Beta?
        > Is anyone working on adding this functionality?
        >

        After looking at the dom-debug.js file for a bit, I realized this would be a really, really easy fix, so I went ahead and did it.  At runtime, I now run the following:


        YAHOO.util.Dom.batch = function(el, method, o, override) {
            el = (el && (el.tagName || el.item || el.DOM_EVENTS)) ? el : Y.Dom.get(el); // skip get() when possible
        
            if (!el || !method) {
                YAHOO.log('batch failed: invalid arguments', 'error', 'Dom');
                return false;
            } 
            var scope = (override) ? o : window;
            
            if (el.length === undefined) { // Not array like
              if (el.tagName) { // element
                  return method.call(scope, el, o);
              }
              
              if (el.DOM_EVENTS) { // YUI Element
              		return method.call(scope, el.get('element'), o);
              }
            }
        
            var collection = [];
            
            for (var i = 0, len = el.length; i < len; ++i) {
                collection[collection.length] = method.call(scope, el[i], o);
            }
            
            return collection;
        }


        I think that this (or a variant of this) belongs in the Dom Utility to provide a more consistent API.

        Jeff 'foxxtrot' Craig
      Your message has been successfully submitted and would be delivered to recipients shortly.