Skip to content
atk edited this page Jun 18, 2011 · 4 revisions

Plugins

tiny.js is easily extendable, because there are 4 easy entry points for plugins:

  • Append any function to "t" not to spam the global scope
  • Selectors can be inserted in the selector object t.cf
  • Selector methods can be put inside t._
  • Normalisation filters for CSS and Attributes can be added to t._.nf

Available plugins

ATM, the following plugins are available:

tiny-classname

This triple-usage Selector method can be called from any Selection through the shortcall "C":

t('ul#nav').C('open'); // returns true/false depending on whether ul#nav has className "open"
t('ul#nav').C(1, 'init'); // set className "init"
t('ul#nav').C(0, 'open'); // remove className "open"

If only a string is given, it tests the first selected node for the given classname. Other than that, depending on the truthyness of the first argument, the classname given in the second argument will be either set or removed.

tiny-cookie

Will get/set cookies based on arguments. If a string is given, it will be used as cookie name, while a cookie object with "date" (storing either a Date object or the remaining time in ms) instead of expires can be used to set a cookie.

t.c('test') // returns cookie "test"
t.c({name: 'test', value: '123', expires: 6e6, domain: '.mydomain.test', path: '/'}) // sets corresponding cookie

tiny-elementready

Will start a callback once a selector matches. The callback will have this set to the scope of the successful selection.

t.er('#footer', seoFooterLinks); // seoFooterLinks will be called with t('#footer') set to this

tiny-outerhtml

If the nonstandard outerHTML property is not available, add a normalisation to the .a()-Method:

t('h1').a('outerHTML'); // will return nothing e.g. in Firefox, unless this plugin is loaded
Clone this wiki locally