Skip to content

Instantly share code, notes, and snippets.

View shaneriley's full-sized avatar

Shane Riley shaneriley

View GitHub Profile
@shaneriley
shaneriley / gist:3879386
Created October 12, 2012 14:16
jQuery.createPlugin
// Use: passing in an object representing a jQuery plugin. The object is expected to have
// a name attribute (your plugin name in string form, e.g. name: "accordion") and an init
// method. The createPlugin method will take each element in the collection when the
// plugin method is called and initialize the plugin individually, writing a data object
// to the element with the same name as the plugin and storing the plugin object for
// later reference.
(function($) {
$.createPlugin = function(plugin) {
$.fn[plugin.name] = function(opts) {
var $els = this,
@shaneriley
shaneriley / gist:3853159
Created October 8, 2012 15:38
jQuery Exact Contains
// Problem: jQuery's :contains expression does not do an exact match.
// Solution: Exact contains `$("div").filter(":econtains(smart)");`
$.extend($.expr[":"], {
econtains: function(obj, index, meta, stack) {
return (obj.textContent || obj.innerText || $(obj).text() || "").toLowerCase() == meta[3].toLowerCase();
}
});
@shaneriley
shaneriley / gist:3800176
Created September 28, 2012 14:26
Ruby-like iteration in Javascript
var œ = function(number) {
return {
times: {
length: number,
"do": function(fn) {
var len = this.length;
for (var i = 0; i < len; i++) {
fn(i);
}
}
@shaneriley
shaneriley / gist:3798945
Created September 28, 2012 09:56
Storage prototype object getter/setter methods
Storage.prototype.setObject = function(key, value) {
this.setItem(key, JSON.stringify(value));
};
Storage.prototype.getObject = function(key) {
return JSON.parse(this.getItem(key));
};
@shaneriley
shaneriley / gist:3794514
Created September 27, 2012 15:08
CodeMirror extension: Keep track of markers and clear all
var codemirror_overrides = {
setMarker: function(line, gutter_text, line_class) {
if (!this.markers) { this.markers = []; }
this.markers.indexOf(line) === -1 && this.markers.push(line);
this._setMarker(line, gutter_text, line_class);
},
clearMarkers: function(line) {
var e = this;
if (!e.markers) { return; }
if (line) {
@shaneriley
shaneriley / AHHHHHHH
Created August 21, 2012 18:00 — forked from lessallan/AHHHHHHH
@for sass function issue
$colors: lighten(#026dbd, 45%), lighten(#fad52c, 20%), lighten(#f17d32, 20%), lighten(#da1c1c, 25%), lighten(#8266ba, 20%), lighten(#7bb545, 17%)
$i: 1
@each $color in $colors
&:nth-child(#{$i})
background-color: $color
$i: $i + 1
@shaneriley
shaneriley / markup.haml
Created August 15, 2012 14:13
Rating stars
.rating
.current.three
- %w(one two three four five).each do |rating|
= link_to rating, "#", class: rating
@shaneriley
shaneriley / gist:3327530
Created August 11, 2012 22:11
Get rid of iframe ads
Array.prototype.forEach.call(document.querySelectorAll("iframe"), function(el) { el.parentNode.removeChild(el); });
@shaneriley
shaneriley / gist:2655072
Created May 10, 2012 18:50
Updated Sass gradient mixin
= gradient-bg-horizontal($color1, $color2)
background-color: $color2
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#{ie-hex-str($color1)}, endColorstr=#{ie-hex-str($color2)})
-ms-filter: progid:DXImageTransform.Microsoft.gradient(GradientType=1, startColorstr=#{ie-hex-str($color1)}, endColorstr=#{ie-hex-str($color2)})
background-image: -moz-linear-gradient(100% 100% 180deg, $color2, $color1)
background-image: -webkit-gradient(linear, left center, right center, from($color1), to($color2))
@shaneriley
shaneriley / gist:2473083
Created April 23, 2012 19:01
jQuery smartToggle
(function($) {
$.fn.smartToggle = function(bool, prop) {
prop = prop || bool;
return this.each(function() {
var $e = $(this);
if (bool === prop) {
$e.is(":visible") ? $e.hide() : $e.css("display", prop);
}
else {
bool ? $e.css("display", prop) : $e.hide();