Giter VIP home page Giter VIP logo

dom-box's Introduction

dom-box Build StatusDependency StatusCoverage Status

You like jQuery syntax and ES2015 features?

Dom-box is a neat wrapper around DOM APIs with jQuery like syntax. It is designed to fit only your needs. Import just what your app deserves.

Install (coming soon)

$ npm install --save dombox

Usage

import $ from 'dom-box';
import {addClass} from 'dom-box/modules/add_class';

$('.msg', addClass('open'));

Create your own modules

import $ from 'dom-box';
import wizard from 'dom-box/mod_wizard';

const findTheMightyElements = wizard(function findTheMightyElements() {

	const newElements = this.filter(element => {
		return element.tagName === 'MIGHTY';
	});

	return newElements;
});

/*
	<div></div>
	<mighty></mighty>
	<section></section>
*/

$('*', findTheMightyElements()); // [mighty]

Todo

  • on
  • off
  • index
  • prev
  • next
  • prevAll
  • nextAll
  • replaceWith
  • wrap
  • html
  • text
  • val
  • prop
  • attr
  • bind (observer)
  • remove
  • append
  • data

API

fetchElements

index.js:7-33

Finds elements in the given scope, filtered by the given selector

Parameters

  • paramSelector (selector | element) The elements to find
  • paramScope [(selector | element)] The scope to search for the elements (optional, default document)

Returns array A set of elements

addClass

modules/add_class.js:13-21

Adds one or more classes to each of the selected elements.

Parameters

  • cssClass String One or more space separted classes.

Examples

$('div', addClass('foo'));
$('div', addClass('foo bar'));

Returns Array The selected elements.

removeClass

modules/remove_class.js:13-21

Removes one or more classes from each of the selected elements.

Parameters

  • cssClass String One or more space separted classes.

Examples

$('div', removeClass('foo'));
$('div', removeClass('foo bar'));

Returns Array The selected elements.

hasClass

modules/has_class.js:13-19

Checks if at least one element in the current set contains the given class or classes.

Parameters

  • cssClass String One or more space separted classes.

Examples

$('div', addClass('foo'));
$('div', addClass('foo bar'));

Returns Boolean Returns true if there is a match.

first

modules/first.js:17-19

Reduces the current set to the first element in the set.

Examples

//<ul>
// <li class="first"></li>
// <li></li>
//	<li></li>
//</ul>

$('li', 'ul', first()); // ['li.first']

Returns Array The first element.

last

modules/last.js:17-19

Reduces the current set to the last element in the set.

Examples

//<ul>
// <li></li>
// <li></li>
//	<li class="last"></li>
//</ul>

$('li', 'ul', last()); // ['li.last']

Returns Array The last element.

find

modules/find.js:17-25

Finds the descendants in the current set, filtered by the given selector.

Parameters

  • selector String A selector expression.

Examples

//<article>
//	<section></section>
//	<section></section>
//</article>
$('article', find('section')) // ['section', 'section']

Returns Array A set of fetched elements.

val

modules/val.js:16-26

Get the value of the first element or set the value of each element.

Parameters

  • value [(String | Number)] The functions works as setter if this parameter is given.

Examples

// <input type="text" value="foo" />
$('input', val()); // foo
$('input', val('bar')); // <input type="text" value="bar" />

Returns (Array | String) The current set of matched elements if the function is used as setter, or the value of the first element if the function is used as getter.

show

modules/show.js:11-17

Display the selected elements.

Examples

$('div', show());

Returns Array The selected elements.

hide

modules/hide.js:11-17

Hide the selected elements.

Examples

$('div', hide());

Returns Array The selected elements.

License

MIT © Chris Ebert

dom-box's People

Contributors

chrisebert avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.