jbone
v1.2.1
Published
Library for DOM manipulation
Downloads
279
Maintainers
Readme
Meet jBone
jBone is very small and fast abstraction for Events and DOM manipulation in modern browsers with identical jQuery interfaces in most cases.
It replaces jQuery for Backbone in web and mobile applications (about 2.5kb gzipped, much faster than jQuery and Zepto).
Why jBone?
The main idea of jBone is to use native JavaScript methods as much as possible in your project.
It is superior solution for applications based on Backbone and running on mobile devices as it is extremely small (2.5kb) and really fast library.
jBone project was created to allow people to use Backbone without jQuery.
See benchmark results here.
Get it
Via bower
$ bower install jbone --save
Via component
component install kupriyanenko/jbone
Via nodejs or browserify
$ npm install jbone --save
Use it
Add a <script>
element for jbone.js
<script src="path/to/jbone/dist/jbone.js"></script>
Or include it like npm module (with nodejs or browserify)
var $ = require('jbone');
And write awesome code:
var $input = $("<input>", {
"class": "name"
}).val("John");
$input.on("click.space", function(e) {
console.log("clicked on", this);
});
$input.trigger("click");
$input.off(".space");
Extend it
jBone.fn.addClass = function(className) {
var i = 0,
length = this.length;
for (; i < length; i++) {
this[i].classList.add(className);
}
return this;
};
$(".header").addClass("loaded");
AJAX, Deferred
This part is not covered in jBone. You can choose one of a huge amount of AJAX implementations as well as standard Promises/A+ implementations.
For example: when, Q, simply-deferred, AJAX.
Example of AJAX connection:
// connect reqwest on your page https://rawgithub.com/ded/reqwest/master/reqwest.min.js
jBone.ajax = reqwest.compat;
$.ajax({
url: "http://example.com"
});
Example of connection with Deferred Object:
// connect simply-deferred on your page https://rawgithub.com/sudhirj/simply-deferred/master/deferred.min.js
Deferred.installInto(jBone);
var deferred = $.Deferred();
$.when(deferred).then(function(response) {
// some code
});
Browser support
- Internet Explorer 11+
- Safari 6+
- iOS 5+ Safari
- Android 2.3+ Browser
- Chrome
- Firefox
API
- jBone(selector[, context])
- jBone(element)
- jBone(elementArray)
- jBone(jBoneObject)
- jBone(html[, attributes])
- .attr(attributeName)
- .attr(attributeName, value)
- .attr(attributes)
- .removeAttr(attributeName)
- .val()
- .val(value)
- .css(propertyName, value)
- .css(properties)
- .addClass(className)
- .removeClass(className)
- .toggleClass(className)
- .toggleClass(className, state)
- .hasClass(className)
- .on(event[, selector, data], handler)
- .one(event[, selector, data], handler)
- .off(event[, selector, handler])
- .trigger(event)
- .find(selector)
- .get(index)
- .eq(index)
- .parent()
- .toArray()
- .add(selector)
- .add(elements)
- .add(html)
- .add(selection)
- .add(selector, context)
- jBone.merge(first, second)
- jBone.contains(container, contained)
- jBone.extend(target[, object1][, objectN])
- jBone.makeArray(obj)
- jBone.unique(array)
- .pop()
- .push()
- .reverse()
- .shift()
- .sort()
- .splice()
- .unshift()
- .concat()
- .join()
- .slice()
- .indexOf()
- .forEach()
- .every()
- .some()
- .filter()
- .map()
- .reduce()
- .reduceRight()
Running the Tests
Node
npm install
npm test
Browsers
bower install
- Open page with tests in browser
test/tests.html