Vanilla Javascript Helper Functions, Ajax, Effects, DOM manipulation, Styles, Utilities, Without jQuery.
Easy to use Vanilla Javascript Helper Functions Collection, Ajax, Effects, DOM manipulation, Styles, Utilities ...
- Lightweight, No libraries required
- Ajax
- Effects
- DOM manipulation
- Styles
- Utilities
bower install vanilla-helpers
include js/vanillaHelpers.js OR js/vanillaHelpers.min.js
vanillaHelpers.ajaxGet('http://example.com/fa=foo&foo=faa', function(data) {
console.log(data);
});
If server returns json, parse it in callback function
vanillaHelpers.ajaxGet('http://example.com/fa=foo&foo=faa', function(data) {
console.log(JSON.parse(data));
});
vanillaHelpers.ajaxPost('http://example.com/', 'a=b&b=c', function(data) {
console.log(data);
});
You can also pass object as data
vanillaHelpers.ajaxPost('http://example.com/', { a: 'b', b: 'c' }, function(data) {
console.log(data);
});
vanillaHelpers.fadeIn(document.getElementById('test'), 3000);
With Callback
vanillaHelpers.fadeIn(document.getElementById('test'), 3000, function() {
console.log('animation stopped');
});
vanillaHelpers.fadeOut(document.getElementById('test'), 3000);
With Callback
vanillaHelpers.fadeOut(document.getElementById('test'), 3000, function() {
console.log('animation stopped');
});
vanillaHelpers.nextElement(document.getElementById('test'));
vanillaHelpers.previousElement(document.getElementById('test'));
vanillaHelpers.setVendor(document.getElementById('test'), 'Transition', '1s');
Will add next styles
-webkit-transition: 1s;
-moz-transition: 1s;
-ms-transition: 1s;
-o-transition: 1s;
transition: 1s;
vanillaHelpers.randomInt(1, 10);
if url is: http://example.com/faa/foo/boo
vanillaHelpers.urlSegment(2);
Will return foo
vanillaHelpers.hasCls(document.getElementById('test'), 'foo');
vanillaHelpers.addCls(document.getElementById('test'), 'foo');
vanillaHelpers.removeCls(document.getElementById('test'), 'foo');
vanillaHelpers.toggleCls(document.getElementById('test'), 'foo');
vanillaHelpers.matches(document.getElementById('selector'), '#selector');
vanillaHelpers.startsWith('SomeRandomText', 'Some');
vanillaHelpers.endsWith('SomeRandomText', 'Some');
vanillaHelpers.stringBetween('SomeRandomText', 'R', 'T');
vanillaHelpers.inArray(['a', 'b', 'c', 'd'], 'c');
contributions are more than welcome!
See license.txt