Rob Kinyon - DOM.Insert-0.02

Documentation | Source

NAME

DOM.Insert

DESCRIPTION

This provides the basis for a powerful way to insert arbitrary HTML into an arbitrary point in a DOM tree.

STATIC CLASSES

These are classes that are not instantiable, but instead provide a useful set of operations. (In Javascript terms, they do not provide a prototype member, so you cannot call new() upon them.)

DOM.Insert

This is the base class for the DOM.Insert.* hierarchy. It provides an intialize() method ithat does all the useful work, using attributes and methods provided by the inheriting class. This class is NOT instantiable directly!

The constructor takes two parameters:

  • element
  • This value will be passed to $() (from DOM.Utils).

  • content
  • This is the HTML that will be inserted in the proper place.

The constructor expects that any child class will implement the following attributes and methods:

  • Attribute: adjacency
  • This is an optional attribute. If set and if the element passed into the constructor provides the insertAdjacentHTML() method, it will use this value for the first parameter to that method.

  • Method: initializeRange()
  • This is an optional method. If set, it will be called if the adjacency option fails. When called, this.range will be set to this.element.ownerDocument.createRange()

  • Method: insertContent()
  • This is a required method. If the adjacency option fails, this method will be called. It can assume that the following attributes will be set:

    • element
    • This is passed in from the constructor.

    • content
    • This is passed in from the constructor.

    • range
    • This will be set to this.element.ownerDocument.createRange()

    • fragment
    • This will be set to this.range.createContextualFragment(this.content)

DEPENDENCIES

This requires JSAN, Class, and DOM.Utils to be installed.

SUPPORT

Currently, there is no mailing list or IRC channel. Please send bug reports and patches to the author.

AUTHOR

Rob Kinyon (rob.kinyon@iinteractive.com)

Originally written by Sam Stephenson (sam@conio.net)

My time is generously donated by Infinity Interactive, Inc. http://www.iinteractive.com

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 65:

=back doesn't take any parameters, but you said =back 4

/*

*/

try {
    // If a jsan variable has already been defined, use that, as in the case of tests.
    JSAN.use( 'Class' )
    JSAN.use( 'DOM.Utils' )
} catch (e) {
    throw "DOM.Insert requires JSAN to be loaded";
}

if ( typeof DOM == 'undefined' )
    DOM = {};

/*

*/

/*

*/

DOM.Insert = Class.create( 'DOM.Insert', Object, {
    initialize: function(element, content) {
        this.element = $(element);
        this.content = content;
    
        if (this.adjacency && this.element.insertAdjacentHTML) {
            this.element.insertAdjacentHTML(this.adjacency, this.content);
        }
        else {
            this.range = this.element.ownerDocument.createRange();
            if (this.initializeRange) this.initializeRange();
            this.fragment = this.range.createContextualFragment(this.content);
            this.insertContent();
        }
    }
});

/*

*/