API Documentation

Welcome the XUI documentation. This is generated from inline documentation in the XUI javascript source.

Basics

XUI is available to the entire document as x$. It is a function, that accepts a query selector. The syntax is mostly chainable and should be familiar to anyone who has worked with jQuery.

x$('a.navigation').css({ background:'blue' });

The query selection engine is based on the browser implementation of querySelectorAll so its fast. Real fast. XUI allows for a single expression, an element or an array of elements to be passed

x$(window);                         // The Window
x$(element);                        // An Existing Element  
x$('ul#globalnav li a.selected');   // A CSS3 Selector
x$(['li','div#foo']);               // An Array of Selectors
x$('li','.selected','#some_id');    // A comma list of CSS3 Selectors

Dom

Manipulating the Document Object Model aka the DOM.

For manipulating HTML markup in the DOM.

html

Adds elements or changes the content of an element on a page. This method has shortcut aliases:

syntax:

    x$(window).html( location, html );

or this method will accept just an html fragment with a default behavior of inner..

    x$(window).html( htmlFragment );

arguments:

example:

x$('#foo').html( 'inner',  '<strong>rock and roll</strong>' );
x$('#foo').html( 'outer',  '<p>lock and load</p>' );
x$('#foo').html( 'top',    '<div>bangers and mash</div>');
x$('#foo').html( 'bottom', '<em>mean and clean</em>');
x$('#foo').html( 'remove'  '<h1>first and last</h1>');

or

    x$('#foo').html('<p>sweet as honey</p>'); 

or

    

x$('#foo').inner('<strong>rock and roll</strong>' );
x$('#foo').outer('<p>lock and load</p>' );
x$('#foo').top('<div>bangers and mash</div>');
x$('#foo').bottom('<em>mean and clean</em>');  
x$('#foo ul li').remove(); 

Removes all erronious nodes from the DOM.

Event

A good old fashioned event handling system.

Register callbacks to DOM events.

on

Registers a callback function to a DOM event on the element collection.

This method has shortcut aliases for:

For more information see:

syntax:

    x$('button').on( 'click', function(e){ alert('hey that tickles!') });

or...

    x$('a.save').click(function(e){ alert('tee hee!') });

arguments:

example:

x$(window).load(function(e){
  x$('.save').touchstart( function(evt){ alert('tee hee!') }).css(background:'grey'); 
});

Style

Anything related to how things look. Usually, this is CSS.

Sets a single CSS property to a new value.

setStyle

syntax:

x$(selector).setStyle(property, value);

arguments:

example:

x$('.txt').setStyle('color', '#000');

Retuns a single CSS property. Can also invoke a callback to perform more specific processing tasks related to the property value.

getStyle

syntax:

x$(selector).getStyle(property, callback);

arguments:

example:

x$('ul#nav li.trunk').getStyle('font-size');

x$('a.globalnav').getStyle( 'background', function(prop){ prop == 'blue' ? 'green' : 'blue' });

Adds the classname to all the elements in the collection.

addClass

syntax:

$(selector).addClass(className);

arguments:

example:

$('.foo').addClass('awesome');

Removes the classname from all the elements in the collection.

removeClass

syntax:

x$(selector).removeClass(className);

arguments:

example:

x$('.bar').removeClass('awesome');

Set a number of CSS properties at once.

css

syntax:

x$(selector).css(object);

arguments:

example:

x$('h2.fugly').css({ backgroundColor:'blue', color:'white', border:'2px solid red' });

Fx

Animations, transforms and transitions for getting the most out of hardware accelerated CSS.

Tween is a method for transforming a css property to a new value.

tween

syntax:

x$(selector).tween(obj);

arguments:

example:

x$('#box').tween({ left:100px, backgroundColor:'blue' });

x$('#box').tween([{ left:100px, backgroundColor:'green', duration:.2 }, { right:100px }]);

x$('#box').tween({ left:100px}).tween({ left:100px });

XHR

Remoting methods and utils.

The classic Xml Http Request sometimes also known as the Greek God: Ajax. Not to be confused with AJAX the cleaning agent. This method has a few new tricks. It is always invoked on an element collection. If there no callback is defined the response text will be inserted into the elements in the collection.

xhr

syntax:

    xhr(url, options);

options:

example:

x$('#status').xhr('/status.html');
x$('#left-panel).xhr('/panel', {callback:function(){ alert() }});

Another twist on remoting: lightweight and unobtrusive DOM databinding. Since we are often talking to a server with handy JSON objects we added the convienance the map property which allows you to map JSON nodes to DOM elements.

xhrjson

syntax:

    xhrjson(url, options);

example:

The available options are the same as the xhr method with the addition of map.

    x$('#user').xhrjson( '/users/1.json', {map:{'username':'#name', 'image_url':'img#avatar[@src]'} });