Skip to content

Instantly share code, notes, and snippets.

@mayuki
Created May 4, 2010 10:21
Show Gist options
  • Select an option

  • Save mayuki/389236 to your computer and use it in GitHub Desktop.

Select an option

Save mayuki/389236 to your computer and use it in GitHub Desktop.
/*
* 90年代のWebをjQueryに。
*
* License: Public Domain
*
* Example:
* $('span').fontcolor('red')
* .fontsize(10)
* .blink()
* .big()
* .link('http://www.google.com/');
*/
(function ($) {
var methods = [
['bold', 'b']
, ['italics', 'i']
, ['fixed', 'tt']
, ['big', 'big']
, ['small', 'small']
, ['blink', 'blink']
, ['strike', 's']
, ['sup', 'sup']
, ['sub', 'sub']
, ['fontcolor', 'font', 'color']
, ['fontsize', 'font', 'size']
, ['anchor', 'a', 'name']
, ['link', 'a', 'href']
];
function createGenericMethod(methodInfo) {
return function () {
var e = $("<" + methodInfo[1] + " />");
if (methodInfo.length > 0 && arguments.length == methodInfo.length - 2) {
for (var j = 0, m = arguments.length; j < m; j++) {
e.attr(methodInfo[2 + j], arguments[j].toString());
}
}
return this.wrap(e);
};
}
for (var i = 0, n = methods.length; i < n; i++) {
jQuery.fn[methods[i][0]] = createGenericMethod(methods[i]);
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment