hata

Lightweight JavaScript framework for manipulation dom elements

Stars
4
Committers
1

Hata (this document is deprecated)

Lightweight JavaScript framework for manipulation dom elements.

Releases

Table of content:

Getting started

Save compressed hata framework.

<script src="js/hata.js" type="text/javascript">

Documentation

Before reading

  • selector and context can be string selector, hata object or node.
  • number can be positive or negative number.

Constructor

hata( selector );
hata( selector, context );

DOM is ready

hata.ready(function() {
  // Now DOM is fully loaded
});

hata().get([ number ])

hataObj.get(); // => Array of nodes
hataObj.get( number ); // => One node by index
hata( "div" ).get( -1 ); // => Return last div node

hata().eq( number )

hataObj.eq( number ); // => Hata object of one element
hata( "div" ).eq( 1 ); // => Hata object of second element

hata().each( function )

hataObj.each(function( element, index ) {
  // this => node element
  // element => node element
  // index => index of node element
});

This method returns previous Hata object.

hata().filter( selector )

hataObj.filter( selector ); // => Hata object of elements filtering by `selector`
hata( "div" ).filter( ".tag" ); // => Hata object of divs with class 'tag'

hata().is( selector )

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.

hata().find( selector )

Equivalent to hata( selector, hata() ).

hataObj.find( selector ) // => Find elements inside current collection
hata( "div" ).find( "p" ); // => Return hata( "div p" )

hata().parent()

<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 )

hata().parents( selector )

<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 )

hata().closest( selector )

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"

Utilities

hata.pushUniq( array, element )

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( object )

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( object, function )

hata.each( obj, function( element, key ) {
  // this => value
});

Extending

hata.extend( object, object )

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'

Applications use hata:

  • vkleaner - chrome extension for vk.com that hides unwanted posts. Look at sources for better understand role of Hata.

Contributions

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.