Skip to content

Instantly share code, notes, and snippets.

View shaneriley's full-sized avatar

Shane Riley shaneriley

View GitHub Profile
@shaneriley
shaneriley / gist:5743328
Created June 9, 2013 12:18
$().serializeObject
$.fn.serializeObject = function() {
var obj = {};
if (!this.is("form")) { return this; }
this.find(":input").not("[disabled], :submit").each(function() {
obj[this.name] = isNaN(+this.value) ? this.value : +this.value;
});
return obj;
};
@shaneriley
shaneriley / gist:6979666
Created October 14, 2013 18:12
Tooltips using jQuery UI position
(function($) {
$.fn.tooltip = function() {
// Grabs its content from the next sibling .tooltip_content element, eg:
// = link_to "Remove", "#", "data-tooltip" => ""
// .tooltip_content
// %p This is my tooltip
// Sets a class of right or left on tooltip based on what edge of the trigger it's using
return this.each(function() {
var $el = $(this),
@shaneriley
shaneriley / gist:7085214
Last active December 26, 2015 03:19
mixins
@import "whitespace-reset"
$prefixes: moz, ms, webkit, khtml, o
@function ie_color_fix($color)
@if $color == #ffffff
$color: #fffffe
@else if $color == #fff
$color: #fffffe
@else if $color == #000000
@shaneriley
shaneriley / mixins.styl
Created October 29, 2013 13:58
Stylus mixins
prefixes = moz, ms, webkit, khtml, o
font-smoothing()
-webkit-font-smoothing: antialiased
image-smoothing()
image-rendering:optimizeSpeed
image-rendering:-webkit-optimize-contrast
image-rendering: -moz-crisp-edges
-ms-interpolation-mode: nearest-neighbor
@shaneriley
shaneriley / gist:7371446
Created November 8, 2013 14:01
Reset search inputs
input[type="search"]
-webkit-appearance: none
-moz-appearance: none
input[type='search']::-webkit-search-decoration,
input[type='search']::-webkit-search-cancel-button,
input[type='search']::-webkit-search-results-button,
input[type='search']::-webkit-search-results-decoration
display: none
@shaneriley
shaneriley / states.haml
Last active January 4, 2016 07:19
States helper
-# Middleman doesn't like options_for_select, have to run through manually
%select(name="state")
- states.each do |name, val|
%option(value="#{val}")= name
-# If we're in Rails land
= select_tag :state, options_for_select(states)
@shaneriley
shaneriley / mixins.jade
Created February 10, 2014 20:10
Jade mixins example
// Writing JS for everything is great and all, but I don't want to see JS
// inline in my Jade templates. Thankfully, there are ways of abstrating it
// into mixins!
// Want some Rails-like helpers?
mixin link_to(name, href)
- href = href || "#"
a(href="#{href}")= name
// How about a single editing point for a class name?
@shaneriley
shaneriley / colors.styl
Last active August 29, 2015 14:00
Color iteration in Stylus? Nope.
// Only one of the strings in the list of colors gets interpolated, thanks
// to Stylus converting the color keywords to hex values.
// Thanks, Stylus!
li
for color in red pink orange yellow green blue purple brown black shit
&.{color}
background: color
// What I had to do instead to make it work. Note that simply wrapping the
@shaneriley
shaneriley / gist:99133ec9811161c2ea50
Created July 15, 2014 18:59
Precompile all Handlebars templates
var templates = (function() {
var o = {};
$("[type=\"text/x-handlebars\"]").each(function() {
o[$(this).attr("data-id")] = Handlebars.compile(this.innerHTML);
});
return o;
})();
@shaneriley
shaneriley / skeleton
Last active August 29, 2015 14:16
HTML Skeleton
<!doctype html>
<html lang="en-US">
<head>
<title></title>
<meta charset="UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
</body>