Skip to content

Instantly share code, notes, and snippets.

@basti1253
Created June 1, 2012 16:55
Show Gist options
  • Select an option

  • Save basti1253/2853576 to your computer and use it in GitHub Desktop.

Select an option

Save basti1253/2853576 to your computer and use it in GitHub Desktop.
lolwtf
<!doctype html>
<html>
<head>
<title>lol wtf</title>
<script src='http://code.jquery.com/jquery-1.7.2.js'></script>
<script>
window.$$ = $.sub();
var wrap = function (type) {
return function () {
var e = $$("<"+type+"/>");
$.each(arguments, function (i, value) {
if ($.isString(value)) {
if (value[0] === '.' || value[0] === '#') {
var s = value.split(' ');
$.each(value.split(' '), function (i, arg) {
switch (arg[0]) {
case '#': e.attr('id', arg.substring(1)); break;
case '.': e.addClass(arg.substring(1)); break;
}
});
} else {
e.text(value);
}
} else if (value instanceof jQuery) {
e.append(value);
} else if ($.isPlainObject(value)) {
$.each(value, function (k, v) {
e.data(k, v);
});
}
});
return e;
};
};
$.each("div h1 ol li".split(' '), function (i, el) {
var fn = wrap(el);
$$[el] = fn;
$$.fn[el] = function () {
var e = fn.apply(this, arguments);
this.append(e);
return this.pushStack(e);
};
});
</script>
<script>
$(function () {
$$.div('#id')
.h1('The Three Stooges').end()
.ol('#stooges .conditions')
.li('Moe Howard').end()
.li('Larry Fine').end()
.li('Curly Howard', { key: 'value' }).end()
.li('lol wtf')
.data('key', 'value')
.hover(function () {
$(this).css('color', 'red');
}, function () {
$(this).css('color', 'black');
})
.end()
.end()
.appendTo('body');
});
$(function jquery_only () {
$("<div/>")
.attr('id', 'id')
.append(
$("<h1/>")
.text('The Three Stooges (jquery only)'),
$("<ol/>")
.attr('id', 'stooges')
.addClass('conditions')
.append(
$("<li/>")
.text('Moe Howard'),
$("<li/>")
.text('Larry Fine'),
$("<li/>")
.text('Curly Howard'),
$("<li/>")
.text('lol wtf')
.hover(function () {
$(this).css('color', 'red');
}, function () {
$(this).css('color', 'black');
})
)
)
.appendTo('body');
});
</script>
</head>
<body>
<div id='id'>
<h1>The Three Stooges (html only)</h1>
<ol id='stooges' class='conditions'>
<li>Moe Howard</li>
<li>Larry Fine</li>
<li>Curly Howard</li>
<li id='KACK_ID'>lol wtf</li>
</ol>
</div>
<script>
$('#KACK_ID').hover(function () {
$(this).css('color', 'red');
}, function () {
$(this).css('color', 'black');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment