# Yahoo! UI Library

### get 2.5.2

Yahoo! UI Library > get > YAHOO.util.Get

Show Private Show Protected

## Class YAHOO.util.Get

Fetches and inserts one or more script or link nodes into the document

### Properties

#### nidx `- private int`

node index used to generate unique node ids

#### POLL_FREQ `- static int`

The default poll freqency in ms, when needed
Default Value: 10

#### PURGE_THRESH `- static int`

The number of request required before an automatic purge. property PURGE_THRESH
Default Value: 20

#### purging `- private boolean`

interal property used to prevent multiple simultaneous purge processes

#### qidx `- private int`

queue index used to generate transaction ids

#### queues `- private object`

hash of queues to manage multiple requests

#### TIMEOUT `- static int`

The length time to poll for varName when loading a script in Safari 2.x before the transaction fails. property TIMEOUT
Default Value: 2000

### Methods

#### _autoPurge

`private void _autoPurge ( )`
Removes processed queues and corresponding nodes

Returns: `void`

#### _finalize

`private void _finalize ( id )`
Called by the the helper for detecting script load in Safari

Parameters:
  `id <string>` the transaction id

Returns: `void`

#### _finish

`private void _finish ( id )`
The request is complete, so executing the requester's callback

Parameters:
  `id <string>` the id of the request

Returns: `void`

#### _linkNode

`private HTMLElement _linkNode ( url , win )`
Generates a link node

Parameters:
  `url <string>` the url for the css file
  `win <Window>` optional window to create the node in

Returns: `HTMLElement`
  the generated node

#### _next

`private void _next ( id , loaded )`
Loads the next item for a given request

Parameters:
  `id <string>` the id of the request
  `loaded <string>` the url that was just loaded, if any

Returns: `void`

#### _node

`private HTMLElement _node ( type , attr , win )`
Generates an HTML element, this is not appended to a document

Parameters:
  `type <string>` the type of element
  `attr <string>` the attributes
  `win <Window>` optional window to create the element in

Returns: `HTMLElement`
  the generated node

#### _purge

`private void _purge ( )`
Removes the nodes for the specified queue

Returns: `void`

#### _returnData

`private void _returnData ( )`
Returns the data payload for callback functions

Returns: `void`

#### _scriptNode

`private HTMLElement _scriptNode ( url , win )`
Generates a script node

Parameters:
  `url <string>` the url for the script file
  `win <Window>` optional window to create the node in

Returns: `HTMLElement`
  the generated node

#### _track

`private void _track ( type , n , id , url , win , qlength , trackfn )`
Detects when a node has been loaded. In the case of script nodes, this does not guarantee that contained script is ready to use.

Parameters:
  `type <string>` the type of node to track
  `n <HTMLElement>` the node to track
  `id <string>` the id of the request
  `url <string>` the url that is being loaded
  `win <Window>` the targeted window
  `qlength <object>` the number of remaining items in the queue, including this one
  `trackfn <Function>` function to execute when finished the default is _next

Returns: `void`

#### abort

`void abort ( either )`
Abort a transaction

Parameters:
  `either <string|object>` the tId or the object returned from script() or css()

Returns: `void`

#### css

`static tId: string css ( url , opts )`
Fetches and inserts one or more css link nodes into the head of the current document or the document in a specified window.

Parameters:
  `url <string>` the url or urls to the css file(s)
  `opts <object>` Options:
  onSuccess
    callback to execute when the css file(s) are finished loading The callback receives an object back with the following data:
    win
    the window the link nodes(s) were inserted into
  data
    the data object passed in when the request was made
  nodes
    An array containing references to the nodes that were inserted
  purge
    A function that, when executed, will remove the nodes that were inserted
scope
  the execution context for the callbacks
win
  a window other than the one the utility occupies
data
  data that is supplied to the callbacks when the nodes(s) are loaded.
insertBefore
  node or node id that will become the new node's nextSibling
charset
  Node charset, default utf-8

    YAHOO.util.Get.css("http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css");

    YAHOO.util.Get.css(["http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css",
    "http://yui.yahooapis.com/2.3.1/build/logger/assets/skins/sam/logger.css"]);

Returns: `tId: string`
  an object containing info about the transaction

#### queue

`private void queue ( type , url , opts )`
Saves the state for the request and begins loading the requested urls

Parameters:
  `type <string>` the type of node to insert
  `url <string>` the url to load
  `opts <object>` the hash of options for this request

Returns: `void`

#### script

`static tId: string script ( url , opts )`
Fetches and inserts one or more script nodes into the head of the current document or the document in a specified window.

Parameters:
  `url <string|string[]>` the url or urls to the script(s)
  `opts <object>` Options:
  onSuccess
    callback to execute when the script(s) are finished loading The callback receives an object back with the following data:
    win
      the window the script(s) were inserted into
    data
      the data object passed in when the request was made
    nodes
      An array containing references to the nodes that were inserted
    purge
      A function that, when executed, will remove the nodes that were inserted
  onFailure
    callback to execute when the script load operation fails The callback receives an object back with the following data:
    win
      the window the script(s) were inserted into
    data
      the data object passed in when the request was made
    nodes
      An array containing references to the nodes that were inserted successfully
    purge
      A function that, when executed, will remove any nodes that were inserted
  scope
    the execution context for the callbacks
  win
    a window other than the one the utility occupies
  autopurge
    setting to true will let the utilities cleanup routine purge the script once loaded
  data
    data that is supplied to the callback when the script(s) are loaded.
  varName
    variable that should be available when a script is finished loading. Used to help Safari 2.x and below with script load detection. The type of this property should match what was passed into the url parameter: if loading a single url, a string can be supplied. If loading multiple scripts, you must supply an array that contains the variable name for each script.
  insertBefore
    node or node id that will become the new node's nextSibling
charset
  Node charset, default utf-8

    // assumes yahoo, dom, and event are already on the page
      YAHOO.util.Get.script(
      ["http://yui.yahooapis.com/2.3.1/build/dragdrop/dragdrop-min.js",
       "http://yui.yahooapis.com/2.3.1/build/animation/animation-min.js"], {
        onSuccess: function(o) {
          YAHOO.log(o.data); // foo
          new YAHOO.util.DDProxy("dd1"); // also new o.reference("dd1"); would work
          this.log("won't cause error because YAHOO is the scope");
          this.log(o.nodes.length === 2) // true
          // o.purge(); // optionally remove the script nodes immediately
        },
        onFailure: function(o) {
          YAHOO.log("transaction failed");
        },
        data: "foo",
        scope: YAHOO,
        // win: otherframe // target another window/frame
        autopurge: true // allow the utility to choose when to remove the nodes
      });

Returns: `tId: string`
  an object containing info about the transaction

Copyright © 2007 Yahoo! Inc. All rights reserved.