Skip to content

Instantly share code, notes, and snippets.

@SergXIIIth
Created March 9, 2011 15:27
Show Gist options
  • Save SergXIIIth/862391 to your computer and use it in GitHub Desktop.
Save SergXIIIth/862391 to your computer and use it in GitHub Desktop.
js help functions
window.log = (obj) -> if window.console then window.console.log(obj)
// usage
// var x = 42;
// var map = function (x) { return eval(x); };
// alert(f("x $x", map));
window.f = function (s, map) {
return s.replace(/\$(\w+)/g, function (dummy, v) { return map(v);} );
};
jQuery.fn.blank = -> this.size() == 0
jQuery.fn.present = -> this.size() > 0
jQuery.fn.trim = -> $.trim(this.val())
jQuery.fn.texts = ->
texts = @.map -> $.trim($(@).text())
texts = texts.get()
texts.join(" ")
jQuery.fn.ids = ->
ids = @.map -> $(@).attr("data-id")
$.unique(ids.get())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment