Skip to content

Instantly share code, notes, and snippets.

@jlbruno
jlbruno / jquery.console.log.js
Created May 11, 2010 16:45
A jQuery 'plugin' to allow you to log to the console the current jQuery object
jQuery.fn.clog = function(msg) {
var txt = msg ? msg : "";
if (console && typeof console.log != "undefined") {
console.log('%o ', this, txt);
}
return this;
}
/*
* use .clog() in the middle of your chain to make sure you have the
* proper object before you continue. it will log the current jquery
@jlbruno
jlbruno / isItScrollableWithoutVisibleScrollbars.js
Created July 22, 2011 18:54
a function to check if a certain element is scrollable, but is NOT showing scrollbars. Useful to use as a test for when you might want to implement another scrolling solution, such as iScroll for iPad.
var isItScrollableWithoutVisibleScrollbars = function(el) {
if (el === null) {
return false;
}
var isScrollable = false;
var hasScrollbars = false;
// first, lets find out if it has scrollable content
isScrollable = el.scrollHeight > el.offsetHeight ? true : false;
// if it's scrollable, let's see if it likely has scrollbars
if (isScrollable) {
@jlbruno
jlbruno / gist:1312723
Created October 25, 2011 13:27
Run a function after jQuery is loaded
var tempTimeout;
(function checkForJquery() {
if (!window.jQuery) {
tempTimeout = setTimeout(checkForJquery, 500);
} else {
myFunction();
clearTimeout(tempTimeout);
}
}());
@jlbruno
jlbruno / ordinal.js
Last active July 28, 2022 14:58
Javascript Ordinal Numbers
// found here http://forums.shopify.com/categories/2/posts/29259
var getOrdinal = function(n) {
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
}
@jlbruno
jlbruno / elementQuery-example.js
Last active September 29, 2015 23:57
elementQuery
// call elementQuery and pass it an object containing the tests.
// also pass it an object containing a 'passed' callback and a 'failed' callback
// you can also pass a bool for whether you want to bind this to be run on resize
$('#torso').elementQuery({ 'min-width' : 910 , 'max-width' : 1155}, {
passed : function() {
$(this).addClass('l-full').removeClass('l-xlarge');
},
failed : function() {
$(this).removeClass('l-full');
@jlbruno
jlbruno / Avatars 1 2.js
Created March 9, 2012 03:57
viclou/Turntable-API/custom code/
//Avatars
bot.on('speak', function (data) {
// console.log('chat', data);
var text = data.text;
var name = data.name;
//PART 1
if (text.match(/^\/closeeyedgirl/)) {
bot.setAvatar ('1');
}
if (text.match(/^\/greengirl/)) {
Turntable Chat Commands
/ Commands:
/up
/down
/me
/seriousface
/monocle
/whatever

I've been finding this little meta[name='tmpl'] pattern useful lately when making template-based decisions in JS, such as when loading a particular file or set of files that are needed only on a particular page of a site.

First, in the HTML of a particular template, like say, a search result page:

<head>
  ...
  <meta name="tmpl" content="searchresult">
</head>
@jlbruno
jlbruno / jquery.searchFieldClear.js
Created March 21, 2013 02:31
function to add the clear functionality to input type="search"
var searchFieldClear = function() {
var public = {};
var clearButtonCss = {
cursor: 'pointer',
margin: '12px 0 0 -16px',
position: 'absolute',
zIndex: 1000
}
var buttonExists = false;
@jlbruno
jlbruno / pre-commit
Created June 26, 2013 18:24
pre-commit hook for checking if someone is committing into a certain folder within a subversion repo, and telling them to move their commits elsewhere.
# Tell everyone to bugger off elsewhere
echo "THIS REPOSITORY HAS MOVED TO BITBUCKET" >&2
echo "https://bitbucket.org/pixelmedia/bdc-website" >&2
exit 1
# OR
# Check where in the repo they are committing, before you tell them to bugger off
LINES=$(svnlook changed $REPOS -t $TXN)
FOLDER_NAME="web-template/"