All Projects → finom → Bala

finom / Bala

Licence: mit
A function for elements selection

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Bala

Photobooth
A photobooth Web-Application for raspberry pi with gphoto2
Stars: ✭ 188 (-11.74%)
Mutual labels:  jquery
Bridge
♠️ C# to JavaScript compiler. Write modern mobile and web apps in C#. Run anywhere with Bridge.NET.
Stars: ✭ 2,216 (+940.38%)
Mutual labels:  jquery
Jcf
Advanced form elements customization using CSS/JS
Stars: ✭ 203 (-4.69%)
Mutual labels:  jquery
Feedek
FeedEk jQuery RSS/ATOM Feed Plugin
Stars: ✭ 190 (-10.8%)
Mutual labels:  jquery
Javascript
刘宾的博客->前端相关。
Stars: ✭ 195 (-8.45%)
Mutual labels:  jquery
Jquery Easy Ticker
jQuery easy ticker is a news ticker like plugin, which scrolls the list infinitely. It is highly customizable, flexible with lot of features and works in all browsers.
Stars: ✭ 196 (-7.98%)
Mutual labels:  jquery
Eslint Plugin Jquery
Disallow jQuery functions with native equivalents.
Stars: ✭ 188 (-11.74%)
Mutual labels:  jquery
Kendo Ui Core
An HTML5, jQuery-based widget library for building modern web apps.
Stars: ✭ 2,394 (+1023.94%)
Mutual labels:  jquery
Gentelella Rtl
Free RTL Bootstrap 3 Admin Template
Stars: ✭ 194 (-8.92%)
Mutual labels:  jquery
Hc Offcanvas Nav
JavaScript library for creating toggled off-canvas multi-level navigations, allowing endless nesting of submenu elements, supporting swipe gestures, keyboard interactions and ARIA attributes.
Stars: ✭ 201 (-5.63%)
Mutual labels:  jquery
Calx.js
jQuery Calx - a jQuery plugin for creating formula-based calculation form
Stars: ✭ 190 (-10.8%)
Mutual labels:  jquery
Laravel Datatables Buttons
jQuery DataTables Buttons Plugin for Laravel.
Stars: ✭ 192 (-9.86%)
Mutual labels:  jquery
Uniform
A jQuery plugin to make your form controls look how you want them to. Now with HTML-5 attributes!
Stars: ✭ 2,219 (+941.78%)
Mutual labels:  jquery
Phantomas
Headless Chromium-based web performance metrics collector and monitoring tool
Stars: ✭ 2,191 (+928.64%)
Mutual labels:  jquery
Jquery Aniview
A jQuery plugin that works in harmony with animate.css in order to enable animations only when content comes into view.
Stars: ✭ 205 (-3.76%)
Mutual labels:  jquery
Laravel Datatables Html
Laravel DataTables HTML Builder Plugin
Stars: ✭ 188 (-11.74%)
Mutual labels:  jquery
100 Days Of Code Frontend
Curriculum for learning front-end development during #100DaysOfCode.
Stars: ✭ 2,419 (+1035.68%)
Mutual labels:  jquery
Hass Configurator
Configuration UI for Home Assistant
Stars: ✭ 211 (-0.94%)
Mutual labels:  jquery
Civitas
Civitas is an empire-building game written in Javascript with the help of the jQuery library.
Stars: ✭ 207 (-2.82%)
Mutual labels:  jquery
Cms
GleezCMS - A Light, Simple, Flexible Content Management System
Stars: ✭ 200 (-6.1%)
Mutual labels:  jquery

bala.js npm version

A function for elements selection in 251 ASCII chars (less than ¼ KB)!

bala.js is a function that allows you to select elements on a web page and get rid of jQuery in most of cases. Think of it as of document.querySelectorAll on steroids.

const buttons = $('.button');

You can use it as a global variable

<script>
$=((a,b,c)=>(c=(d,e,f=Object.create(c.fn))=>(d&&f.push(...(d.dispatchEvent?[d]:""+d===d?/</.test(d)?((e=a.createElement(e)).innerHTML=d,e.children):e?(e=c(e)[0])?e[b](d):f:a[b](d):d)),f),c.fn=[],c.one=(a,b)=>c(a,b)[0],c))(document,"querySelectorAll");
</script>

If you don't want to use $ variable just rename it.

foo=...
// instead of
$=...

And you can use it as a local variable in a script you make

((win, $) => {
    // your code starts here
    const divs = $('div');
    console.log(divs);
    // your code ends here
})(window, ((a,b,c)=>(c=(d,e,f=Object.create(c.fn))=>(d&&f.push(...(d.dispatchEvent?[d]:""+d===d?/</.test(d)?((e=a.createElement(e)).innerHTML=d,e.children):e?(e=c(e)[0])?e[b](d):f:a[b](d):d)),f),c.fn=[],c.one=(a,b)=>c(a,b)[0],c))(document,"querySelectorAll"));

The function is also published on NPM

npm install balajs

bala.js is inherited from Array.prototype which means it has the same set of methods as the native array has.

More features?

Various types support

bala accepts many kinds of first argument and converts everything into bala instance

$('.one, #two')
$(document.querySelectorAll('.selector'));
$(document.body);
$(element.children);
$(jQuery('.selector'));
$([document.querySelector('.one'), document.querySelector('.two')])

That means when you make your own library (VanillaJS "plugin") you can use bala in case if you don't know which arg type will be passed by a programmer.

const myCoolLibrary = (el) => {
  el = $(el);
  // ...
};

$.one

Getting zero-indexed element in DOM libraries is annoying. bala has one little static method called $.one which selects only one element.

$.one('.button');
//vs
$('.button')[0];

This function is also created to get rid of extra variables (usually DOM libraries make two vars: $$ and $). It means you can import bala nicely via module system.

AMD

require(['path/to/bala/umd/bala.umd.js'], ($) => {
	// ...
});

CommonJS

const $ = require('path/to/bala/bala.umd.js');

CommonJS + NPM

const $ = require('balajs');

ECMAScript 2015

import $ from 'balajs';

Find elements inside another element

const elements = $('.my-selector', someParent);
// or
const element = $.one('.my-selector', someParent);

Parse HTML

Simple parsing.

const div = $('<div><span class="yeah"></span></div>');

Contextual HTML parsing

In case if you need to parse HTML which contains contextual elements (td, tr, option) you can pass a context tag name as a second argument.

const cells = $('<td>foo</td><td>bar</td>', 'tr')

Plugins

You can extend bala as easily as you do it with jQuery or Zepto. Use fn property to define your own plugin.

$.fn.toggle = function (boolean) {
    for(let node of this) {
        node.hidden = boolean;
    }
};

$('.button').toggle(false); // hides all buttons

I need more examples!

Add style

for(let element of $('.my-selector')) {
    element.style.color = 'red';
}

In case if you need to set style only for one element you can use $.one.

$.one('.my-selector').style.color = 'red';

Events delegation

for(let element of $('.my-selector')) {
    element.addEventListener('click', function ({ target }) {
        if (this.contains(target.closest('.delegated-selector'))) {
            alert('yep!');
        }
    });
}

Or

$.one('.my-selector').addEventListener('click', function ({ target }) {
    if (this.contains(target.closest('.delegated-selector'))) {
        alert('yep!');
    }
});

Elements removal

for(let element of $('.my-selector')) {
    element.remove();
}

Or

$.one('.my-selector').remove();

Animations

Use element.animate for smooth GPU-accelerated animations. You may need polyfill for Web Animations API.

$.one('.my-selector').animate({
    opacity: [0.5, 1],
    transform: ['scale(0.5)', 'scale(1)'],
}, {
    direction: 'alternate',
    duration: 500,
    iterations: Infinity,
});

Do you still need jQuery?

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].