Skip to content

Instantly share code, notes, and snippets.

@deepsweet
Forked from 140bytes/LICENSE.txt
Created May 26, 2011 20:33
Show Gist options
  • Save deepsweet/994016 to your computer and use it in GitHub Desktop.
Save deepsweet/994016 to your computer and use it in GitHub Desktop.
$$ yocto framework
//var $$ =
function(
a, // selector -> static nodeList -> element
b, // object with element properties and/or methods
c, // loop
d, // shortcut
e, // loop
f // shortcut
){
a = document.querySelectorAll(a); // get a static nodeList
for(c = a.length; c--;) { // and loop through it
d = a[c]; // shortcut to shave some bytes
for(e in b) // loop through properties and/or methods
f = b[e], // shortcut to shave some bytes
Array.isArray(f) ? // if method
d[e].apply(d, f) : // then call it with params array
d[e] = f // else just assing
}
}
// $$('.test', {
// className: 'test',
// setAttribute: ['title', 'test'],
// appendChild: [document.createElement('div')],
// onclick: function() { alert(1) }
// })
function(a,b,c,d,e,f){a=document.querySelectorAll(a);for(c=a.length;c--;){d=a[c];for(e in b)f=b[e],Array.isArray(f)?d[e].apply(d,f):d[e]=f}}
Copyright (c) 2011 Kir Belevich, http://soulshine.in
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "$$",
"keywords": ["$$","selector","yocto","framework"]
}
@jed
Copy link

jed commented May 26, 2011

are you sure this works? it seems you're losing the nodeList you're iterating on when you assign a=a[c].

@deepsweet
Copy link
Author

fixed

@deepsweet
Copy link
Author

looks like we can already use something like this:

[].slice.call(document.querySelectorAll('.test')).forEach(function(i) {
  with(i)
    className = 'test',
    setAttribute('title', 'test')
})

but anyway that was fun :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment