1.0.3 • Published 8 years ago

rb-strawberry v1.0.3

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

#redBus strawberry

This is a small utility library which allows to add and remove events , classes and a few other DOM related stuff.

##Install

npm install rb-strawberry
var strawberry = require('rb-strawberry')

##Usage

  • getElementOffset

    var offset = strawberry.getElementOffset(elem);
    /* offset = {
     top : topOffset,
     left : leftOffset,
     bottom : bottomOffset,
     right : rightOffset
    }*/
  • normalizeEvent

    var normalizedEvent = strawberry.normalizeEvent(oldEvent);

    This produces an event object that is simliar across all browsers.

  • addClass

     strawberry.addClass(elem , 'classToBeAdded');

    This adds the class to the element.

  • removeClass

     strawberry.removeClass(elem , 'classToBeRemoved');

    This removes the class from the element.

  • hasClass

     var isClass = strawberry.hasClass(elem , 'classToBeChecked');

    returns true if the element has the class else returns false.

  • addEvent

     strawberry.addEvent(elem , type , func , useCapture);
     //elem is the element on which the event is to be bound
     //type is the type of event e.g. 'click'
     //func is the callback for the event
     //useCapture is boolean for using event capture 
  • removeEvent

     strawberry.removeEvent(elem , type , func , useCapture);
     //elem is the element on which the event is to be unbound
     //type is the type of event e.g. 'click'
     //func is the callback for the event
     //useCapture is boolean for using event capture 
  • isChildOf

     var test = strawberry.idChildOf(elem, parent);
     // returns true if elem inside of the parent element else returns false
  • removeEvents

     strawberry.removeEvents(elem);
     // removes all the events bound to the element
  • debounce

     strawberry.debounce(func , wait);
     //func is a function that will be called after wait number of milliseconds
     //e.g.
     strawberry.debounce(function (){console.log('called from debounce')},500);
  • mouseCoords

     var mousePos = strawberry.mouseCoords(event);
     /*
     mousePos = {
       x : xPositionOfMouse,
       y : yPositionOfMouse
     };
     */

    This function returns the position of the mouse including the scroll position

  • emptyElem

     strawberry.emptyElem(elem); 

    Removes all the children of the element