Skip to content

Instantly share code, notes, and snippets.

View melchoy's full-sized avatar
👩‍💻

Melissa Choy melchoy

👩‍💻
View GitHub Profile
@melchoy
melchoy / application.rb
Created March 30, 2012 07:41 — forked from t2/application.rb
Formatting Rails form elements for Twitter Bootstrap error validation
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
# add nokogiri gem to Gemfile
elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
elements.each do |e|
if e.node_name.eql? 'label'
html = %(<div class="clearfix error">#{e}</div>).html_safe
elsif e.node_name.eql? 'input'
if instance.error_message.kind_of?(Array)
html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
@melchoy
melchoy / bootstrap.rb
Created March 30, 2012 07:31 — forked from jamiepenney/bootstrap.rb
Form builder for Twitter Bootstrap v2 form elements
# This file goes in config/initializers
require 'bootstrap_form_builder'
# Make this the default Form Builder. You can delete this if you don't want form_for to use
# the bootstrap form builder by default
ActionView::Base.default_form_builder = BootstrapFormBuilder::FormBuilder
# Add in our FormHelper methods, so you can use bootstrap_form_for.
ActionView::Base.send :include, BootstrapFormBuilder::FormHelper
@melchoy
melchoy / mobile_site.rb
Created February 16, 2012 07:26
Mobile Subdomains in Rails
module MobileSite
def self.included(base)
base.class_eval do
# Uncomment for JQM Integration
#rescue_from ActionView::MissingTemplate, :with => :view_unavailable
before_filter :set_mobile_preferences
before_filter :redirect_to_mobile_if_applicable
before_filter :set_mobile_view_path
@melchoy
melchoy / gist:267366
Created January 2, 2010 03:20
handleExternalLinks
handleExternalLinks: function() {
var hostName = window.location.hostname;
var links = document.getElementsByTagName("a");
for(var i = 0; i < links.length; i++) {
if(links[i].href.indexOf(hostName) == -1) {
var curTitle = (links[i].getAttribute("title")) ? links[i].getAttribute("title") + " - ": "";
links[i].setAttribute("target", "_blank");
links[i].setAttribute("title", curTitle + "opens in new window");
}
}
@melchoy
melchoy / detectflash.js
Created January 2, 2010 03:15
Flash Player Detection
/**********************************************
* Flash Player Detection (taken from sifr )
**********************************************/
var hasFlash = function(){
var nRequiredVersion = 9;
if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');
@melchoy
melchoy / clickables.js
Created November 18, 2009 11:08
Clickable blocks for link target
/************************************
* Clickables (big block targets)
***********************************/
var Clickables = Class.create({
initialize: function(options) {
selector = $$(options.selector) || $$(".clickables");
this.clickable = options.clickable || "li";
this.hoverclass = options.hoverclass || "over";