0 people following this project (follow)

Introduction

Newt is a javascript library like jQuery or Prototype that focuses on areas that ASP.NET AJAX does not.

Why Newt?

There is a number of cool javascript libraries such as jQuery, Prototype and Moo Tools to name a few, Newt is just an alternative to this, Newt is small, < 6kb minified and around 2kb zipped.

Newt does things differently when it comes to selecting dom elements, for instance to select all elements by class name you can do this.

var orangeElements = $select().where(function(el) { return el.hasClass('orange'); }).all();
A relatively cool thing about DOM element selection in newt, is that execution is deferred, for instance:

var q = $select().where(function(el) { return el.hasClass('orange'); });
will not be evaluated until a terminating method is called such as all() or first();

As well as DOM nodes, selection also works on arrays.

[1,2,3,4,5,6,7,8].select()
                 .where(function(item) { return item < 5; })
                 .all()
                 .each(function(item, index, length){ alert(item); });
The above example will create a selection from the array literal and filter it where the values are less than 5, resulting in [1,2,3,4] which in turn, all items are alerted.

Currently Newt occupies just 3 globals
  • $() for selecting elements my id ie:- $('mydiv')
  • $select as described above
  • newt object, a namespace for all things newt

Newt, like most javascript libraries allows chainability, the following example creates a new element, sets the style and appends it to the documents body.

newt.create('div')
    .setStyle({
        'width':'100px',
        'height':'100px',
        'border-style':'solid',
        'border-width':'1px',
        'border-color':'#000000'
    }).appendTo(document.body);

Last edited Oct 22 2008 at 9:44 AM by fluxtah, version 22