Lightweight JavaScript framework for manipulation dom elements.
Save compressed hata framework.
<script src="js/hata.js" type="text/javascript">
selector
and context
can be string selector, hata object or node.number
can be positive or negative number.hata( selector );
hata( selector, context );
hata.ready(function() {
// Now DOM is fully loaded
});
hataObj.get(); // => Array of nodes
hataObj.get( number ); // => One node by index
hata( "div" ).get( -1 ); // => Return last div node
hataObj.eq( number ); // => Hata object of one element
hata( "div" ).eq( 1 ); // => Hata object of second element
hataObj.each(function( element, index ) {
// this => node element
// element => node element
// index => index of node element
});
This method returns previous Hata object.
hataObj.filter( selector ); // => Hata object of elements filtering by `selector`
hata( "div" ).filter( ".tag" ); // => Hata object of divs with class 'tag'
hataObj.is( selector ) // => true if hataObj is matched to selector
hata( "div" ).is( ".tag" ); // => True is there are divs with class "tag"
This method returns true or false.
Equivalent to hata( selector, hata() ).
hataObj.find( selector ) // => Find elements inside current collection
hata( "div" ).find( "p" ); // => Return hata( "div p" )
<body>
<section>
<div class="tag">tag</div>
</section>
</body>
hataObj.parent(); // => Return parents
hata( ".tag" ).parent(); // => Return hata( "section" )
hata( "section" ).parent(); // => Return hata( body )
<body>
<section>
<div class="tag">tag</div>
</section>
</body>
hataObj.parents( selector ); // => Return parents which satisfies the 'selector'
hata( ".tag" ).parents( "body" ); // => Return hata( "body" )
hata( "section" ).parents( ".tag" ); // => Return hata( document )
hataObj.closest( selector ); // => First parents by `selector` or this elements if it is `selector`
hata( "div" ).closest( ".tag" ); // => Return hata( "div" ) is there is div with class "tag"
hata( "div" ).closest( ".tag" ); // => Works like .parents() if divs without class "tag"
hata.pushUniq( arr, element ); // => Add an element to the array if it is unique
hata.pushUniq( [1, 2], 1 ); // => [1, 2]
hata.pushUniq( [1, 2], 3 ); // => [1, 2, 3]
This method returns array.
hata.toArray( obj ); // => Convert something into an array
hata.toArray(); // => []
hata.toArray( "string" ); // => [ "string" ]
hata.toArray( document.querySelectorAll( "div" ) ); // => Array of divs
This method returns array.
hata.each( obj, function( element, key ) {
// this => value
});
If you want to add hata methods:
hata.extend( hata.fn, {
ping: function() {
return 'pong';
}
});
// or
hata.fn.ping = function() {
return 'pong';
}
elements.ping(); // => 'pong'
If you want to extend some objects:
var someObject = {};
hata.extend( someObject, {
ping: function() {
return 'pong';
}
});
someObject.ping(); // => 'pong'
Contribuitions always are welcome. Hata is written according to jQuery Core Style Guide and:
// Good
if ( condition ) return some;
if ( condition ) break;
Feel free to fork and pull request changes.