• Stars
    star
    232
  • Rank 172,847 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

💲 Micro-library of shorthands for DOM selection, events, and attribute manipulation

BlingBlingJS

Build Status Total Downloads Latest Release License

like bling.js, but more bling


Getting Started

Installation

npm i blingblingjs

Importing

// import the blingbling y'all
import $ from 'blingblingjs'                // es6 module
const $ = require('blingblingjs')           // commonjs

// or from Pika CDN! https://cdn.pika.dev/blingblingjs/v2

Syntax

Quick Overview

$()        // select nodes in document or pass nodes in
$().on     // add multiple event listeners to multiple nodes
$().off    // remove multiple event listeners from multiple nodes
$().attr   // CRUD attributes on nodes
$().map    // use native array methods

Queries

// get nodes from the document
const btns         = $('button')            // blingbling always returns an array
const [first_btn]  = $('button[primary]')   // destructure shortcut for 1st/only match
const btn_spans    = $('span', btns)        // provide a query context by passing a 2nd param of node/nodes

// cover DOM nodes in bling
const [sugared_single]  = $(document.querySelector('button'))
const sugared_buttons   = $(document.querySelectorAll('button'))

Array Methods

$('button').forEach(...)
$('button').map(...)

const btns = $('button')
btns.filter(...)
btns.reduce(...)
btns.flatMap(...)
...

Events

// single events
first_btn.on('click', ({target}) => console.log(target))
$('button[primary]').on('click', e => console.log(e))

// single events with options
first_btn.on('click', ({target}) => console.log(target), {once: true})
$('button[primary]').on('click', e => console.log(e), true) // useCapture

// multiple events
$('h1').on('click touchend', ({target}) => console.log(target))

// remove events
const log_event = e => console.warn(e) // must have a reference to the original function
main_btn.on('contextmenu', log_event)
main_btn.off('contextmenu', log_event)

Attributes

// set an attribute
$('button.rad').attr('rad', true)

// set multiple attributes
const [rad_btn] = $('button.rad')
rad_btn.attr({
  test: 'foo',
  hi:   'bye',
})

// get an attribute
rad_btn.attr('rad')        // "true"
rad_btn.attr('hi')         // "bye"

// get multiple attributes
$('button').map(btn => ({
  tests:  btn.attr('tests'),
  hi:     btn.attr('hi'),
}))

// remove an attribute
rad_btn.attr('hi', null)   // set to null to remove
rad_btn.attr('hi')         // attribute not found

// remove multiple attributes
btns.attr({
  test:   null,
  hi:     null,
})

Convenience

import {rIC, rAF} from 'blingblingjs'

// requestAnimationFrame
rAF(_ => {
  // animation tick
})

// requestIdleCallback
rIC(_ => {
  // good time to compute
})


What for?

Developer ergonomics! If you agree with any of the following, you may appreciate this micro library:

  • Love vanilla js, want to keep your code close to it
  • Chaining is fun, Arrays are fun, essentially a functional programming fan
  • Hate typing document.querySelector over.. and over..
  • Hate typing addEventListener over.. and over..
  • Really wish document.querySelectorAll had array methods on it..
  • Confused that there is no node.setAttributes({...}) or even better nodeList.setAttributes({...})
  • Liked jQuery selector syntax
Why BlingBling?
  • Minimal at 0.6kb (636 bytes)
  • BlingBling supports ES6 module importing and common module loading
  • Supports chaining
  • Worth it's weight (should save more characters than it loads)
  • Only enhances the nodes you query with it
  • ES6 version of popular bling.js by Paul Irish
  • Tested

More Repositories

1

open-props

CSS custom properties to help accelerate adaptive and consistent design.
HTML
4,744
star
2

gui-challenges

Components from the YouTube show GUI Challenges: accessible, responsive, adaptive and cross browser components.
HTML
2,781
star
3

transition.css

:octocat: Drop-in CSS transitions
CSS
1,831
star
4

ragrid

:octocat: Intrinsic first auto-layout flexbox grid
CSS
252
star
5

morphull

Astro starter powered by MPA view transitions
Astro
223
star
6

conic.css

nice'n simple conic gradients 🎨
JavaScript
209
star
7

shortstack

🥞 minimal Rollup + PostCSS modern syntax starter template
JavaScript
168
star
8

roving-ux

stateful roving index for web ui
JavaScript
129
star
9

scrollyfills

grab and go polyfill functions for web scroll features
JavaScript
102
star
10

ScrollSnapExplainers

89
star
11

slyd

Snappy, responsive, touch optimized, bi-directional presentation framework
CSS
73
star
12

twop

tailwind += open props
TypeScript
51
star
13

vite-postcss-preset-env

HTML
41
star
14

Kung-Fury-Theme

80's dark retro theme for VS Code and Sublime Text
35
star
15

Bolt

⚡ is a fast grunt based, data driven, static site seed project, for rapid web development of PWA's or JAMstack projects
HTML
34
star
16

2022-css-day_oh-snap

Astro
28
star
17

Google-IO-2021-Workshop_User-Adaptive-Interfaces

HTML
27
star
18

chat-ui

💬 rich message handling chat interface for bot projects
JavaScript
19
star
19

snowpack-template-preset-env

babel and postcss at latest with browserlist powered preset-env
JavaScript
18
star
20

slyd-starter

clone and go Slyd starter kit
HTML
17
star
21

css-at-cds

links to demo's and docs from our talk at Chrome Dev Summit 2019
HTML
15
star
22

scrollend-explainer

12
star
23

argyleink

11
star
24

houdini-tabs

WIP: scroll-snap-points + ScrollTimeline + Houdini AnimationWorklet
JavaScript
11
star
25

css-n-js

JavaScript
10
star
26

houdini-static-gradient

a houdini paint worklet with a retro static gradient effect
JavaScript
9
star
27

HTML5-ClearUI

Node, Mongo, Zepto, HTML5
JavaScript
8
star
28

Android-Webapp-Boilerplate

The project code needed to make a single webview android app
7
star
29

coinsafe

PWototype demo for JScamp 2019 presentation
HTML
6
star
30

london-css-2020

CSS 🎉
HTML
5
star
31

jscamp

talk for JScamp 2019 in Barcelona
HTML
5
star
32

NintendoSwitch.tmTheme

🎮 dark theme with bubble gum code highlighting and subdued machine characters for optimal dev focus and nostalgia
4
star
33

JS-Web-App-Starter

Vagrant/Nginx/Express/MySQL/Grunt/Jade/Stylus
CSS
4
star
34

app-img

<app-image> a lazy image loading custom element for considerate user experiences
HTML
4
star
35

Node--Express--and-Socket.io-Starter-Kit

Get started right way with a socket node app. I made this for me, but you can use it too!
JavaScript
4
star
36

iOS-Webview-Boilerplate

Objective-C
3
star
37

browserify-babel

Quickstart for playing with ES6 Babel and Browserify
JavaScript
2
star
38

prefers-reduced-data-explainer

2
star
39

surfin

JavaScript
2
star
40

RxState

💊 Turn any object or array into a reactive store
JavaScript
2
star
41

2021-csscamp-css-color

HTML
2
star
42

Leap-Motion---Finger-Tracking

JavaScript gesture and pointer following mechanism with CSS
JavaScript
1
star
43

DieAntsDie

ActionScript 3.0 port to Lua
Lua
1
star
44

csscamp

HTML
1
star
45

Greensock-Touch-Carousel

JavaScript
1
star
46

jack

repo for local wordpress build
PHP
1
star
47

N-Gon

Virtualized infinite sided cube, touch enabled bi-directional rotation
JavaScript
1
star
48

adobe-dreamweaver-fun-cs6-demo

JavaScript
1
star
49

hd-color-bugs

a stash of issues and bugs found while using new HD color functions in CSS
1
star
50

jQuery-Mobile-Ratio-Boilerplate

JavaScript
1
star
51

Android-Full-Screen-Webview-Seed

Use this for a quick android project that points to your dev environment
Java
1
star
52

affilicats

🐈 Progressive Web App demo that showcases flaky network resilience measures (📶 or 🚫📶).
JavaScript
1
star
53

parcel-cssNext-esNext

⚡️ Hot load CSS and JS with no state loss, build a site with the powers of Jade
CSS
1
star
54

Parallax-JS

Sideways! Parallax page generator from simple HTML & CSS
JavaScript
1
star
55

bash_profile

Shell
1
star
56

jade-cssnext-babel-webpacked

⚡️ Build a multipage site with Jade and Webpack, where each page is created from a bundle entry file
HTML
1
star