This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.is_iDevice = function() { | |
return $.inArray(navigator.platform, ["iPhone", "iPad", "iPod"]) !== -1; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function interpolate(source, dictionary) { | |
return source.replace(/#{([^{}]*)}/g, function (a, b) { | |
var r = dictionary[b]; | |
return typeof r === 'string' || typeof r === 'number' ? r : a; | |
}); | |
} | |
// interpolate("#{first} #{last}", { first: "Shane", last: "Riley" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $form = $("form"), | |
values = $form.serializeArray(); | |
// jQuery doesn't currently support datetime-local inputs despite a | |
// comment by dmethvin stating the contrary: | |
// http://bugs.jquery.com/ticket/5667 | |
// Manually storing input type until jQuery is patched | |
$form.find("input[type='datetime-local']").each(function() { | |
var $i = $(this); | |
values.push({ name: $i.attr("name"), value: $i.val() }); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "hpricot" | |
require "open-uri" | |
Dir.glob('app/views/ui/*.html.haml').sort.each do |file| | |
route = file.gsub(/(\.html\.haml)|(app\/views)/, "") | |
filename = file.gsub(/(app\/views\/ui)|(\.haml)/, "") | |
unless route.match(/\/index/) | |
dom = Hpricot(open("http://localhost:3000#{route}")) | |
`mkdir static` unless File.directory?("static") | |
output = File.new("static#{filename}", "w") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toSentence = function() { | |
return Array.prototype.join.call(arguments, " ") + "."; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var el_dictionary = { | |
a: "anchor", | |
h1: "heading", | |
h2: "heading", | |
h3: "heading", | |
h4: "heading", | |
h5: "heading", | |
h6: "heading", | |
li: "list item", | |
ul: "list container", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.hasEvent = function(event, fn) { | |
if (!event) { return this; } | |
var has = { | |
event: false, | |
namespace: false, | |
handler: false | |
}, | |
events = this.data("events"), | |
namespace = event.split("."); | |
event = namespace.shift(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/assets/env/test/time.js | |
window.__rails_test_time = Date(); | |
// Or for you CS guys | |
@.__rails_test_time = Date() | |
In your JS that uses a cached Time.now-style date object, use this for assignment: | |
var now = window.__rails_test_time || Date(); | |
Then conditionally include your test JS like so: | |
= javascript_include_tag "env/test/time" if Rails.env.test? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WHY RETURN STATEMENTS IN CONDITIONAL BLOCKS????? | |
# According to http://coffeescript.org/#conditionals the resulting code does NOT have a return statement. | |
$("dl.card :text").change ()-> | |
$e = $(@) | |
val = $e.val() | |
odd = [] | |
even = [] | |
sum = 0 | |
$.each(val.split(""), (i, v)-> | |
# e should be defined as a local var. Instead, we get: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use: | |
// <input type="checkbox" data-accordion=".additional" /> | |
// $(":data(accordion)").change(doSomething); | |
$.extend($.expr[":"], { | |
data: function(el, idx, selector) { | |
var attr = "data-" + selector[selector.length - 1]; | |
return el.hasAttribute(attr); | |
} | |
}); |