Skip to content

Instantly share code, notes, and snippets.

@suissa
Created November 19, 2017 23:11
Show Gist options
  • Select an option

  • Save suissa/fa4e32cec8bbf5ab547205184722042b to your computer and use it in GitHub Desktop.

Select an option

Save suissa/fa4e32cec8bbf5ab547205184722042b to your computer and use it in GitHub Desktop.
const $_get = ( _this, me ) => ( pos = undefined ) =>
( pos === undefined )
? _this.e[ 0 ]
: _this.e[ pos ]
const $_val = ( _this, me ) => ( newval = undefined ) => {
if ( newval === undefined ) return _this.e.value
_this.e.value = newval
return me
}
const $_hide = ( _this, me ) => () => {
_this.e.style.display = 'none'
return me
}
const $_show = ( _this, me ) => () => {
_this.e.style.display = ''
return me
}
const $_text = ( _this, me ) => ( newval = '' ) => {
if ( newval === '' ) return _this.e.innerHTML
_this.e.innerHTML = newval
return me
}
const getBySelector = ( selector, context = document ) =>
Array.prototype.slice.call( context.querySelectorAll( selector ) )
function $$ ( selector ) {
this.e = getBySelector( selector )
me = this
if ( this.e.length === 1 ) this.e = this.e[ 0 ]
this.val = $_val( this, me )
this.get = $_get( this, me )
this.hide = $_hide( this, me )
this.show = $_show( this, me )
this.text = $_text( this, me )
return this // <- Important
}
const $ = ( selector ) => new $$( selector )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment