Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit b13a9ecb571f874ef227c1a0a246e8d461b475f3 @iain committed May 30, 2011
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in formalize-rails.gemspec
+gemspec
@@ -0,0 +1,24 @@
+# Formalize Rails
+
+This gem vendors Formalize to the asset pipeline. Therefore, this gem requires Rails 3.1 and
+greater.
+
+Add this gem to your gemfile:
+
+ gem 'formalize-rails'
+
+And add `app/assets/stylesheets/application.css`:
+
+ //= require formalize
+
+And add one of these lines to `app/assets/javascripts/application.js`, depending on which javascript
+framework you are using:
+
+ //= dojo.formalize
+ //= extjs.formalize
+ //= jquery.formalize
+ //= mootools.formalize
+ //= prototype.formalize
+ //= yui.formalize
+
+See [formalize.me](http://formalize.me) for more information.
@@ -0,0 +1 @@
+require 'bundler/gem_tasks'
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "formalize/rails/version"
+
+Gem::Specification.new do |s|
+ s.name = "formalize-rails"
+ s.version = Formalize::Rails::VERSION
+ s.authors = ["Iain Hecker"]
+ s.email = ["iain@iain.nl"]
+ s.homepage = "https://github.com/iain/formalize-rails"
+ s.summary = %q{Use Formalize with the asset pipeline}
+ s.description = %q{This gem provides the assets for the formalize form styling, for easy usage with the Rails 3.1 asset pipeline.}
+
+ s.rubyforge_project = "formalize-rails"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_dependency "railties", "~> 3.1.0.rc1"
+end
@@ -0,0 +1 @@
+require 'formalize/rails'
@@ -0,0 +1,7 @@
+require 'formalize/rails/engine'
+
+module Formalize
+ module Rails
+
+ end
+end
@@ -0,0 +1,6 @@
+module Formalize
+ module Rails
+ class Engine < ::Rails::Engine
+ end
+ end
+end
@@ -0,0 +1,5 @@
+module Formalize
+ module Rails
+ VERSION = "0.0.1"
+ end
+end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,166 @@
+/*
+ Formalize - version 1.1
+
+ Note: This file depends on the Dojo library.
+*/
+
+// Module pattern:
+// http://yuiblog.com/blog/2007/06/12/module-pattern
+var FORMALIZE = (function(window, document, undefined) {
+ // Private constants.
+ var PLACEHOLDER_SUPPORTED = 'placeholder' in document.createElement('input');
+ var AUTOFOCUS_SUPPORTED = 'autofocus' in document.createElement('input');
+ var IE6 = parseInt(dojo.isIE, 10) === 6;
+ var IE7 = parseInt(dojo.isIE, 10) === 7;
+
+ // Expose innards of FORMALIZE.
+ return {
+ // FORMALIZE.go
+ go: function() {
+ for (var i in FORMALIZE.init) {
+ FORMALIZE.init[i]();
+ }
+ },
+ // FORMALIZE.init
+ init: {
+ // FORMALIZE.init.full_input_size
+ full_input_size: function() {
+ if (!IE7 || !dojo.query('textarea, input.input_full').length) {
+ return;
+ }
+
+ // This fixes width: 100% on <textarea> and class="input_full".
+ // It ensures that form elements don't go wider than container.
+ dojo.query('textarea, input.input_full').forEach(function(el) {
+ var new_el = el.cloneNode(false);
+ var span = document.createElement('span');
+
+ span.className = 'input_full_wrap';
+ span.appendChild(new_el);
+ el.parentNode.replaceChild(span, el);
+ });
+ },
+ // FORMALIZE.init.ie6_skin_inputs
+ ie6_skin_inputs: function() {
+ // Test for Internet Explorer 6.
+ if (!IE6 || !dojo.query('input, select, textarea').length) {
+ // Exit if the browser is not IE6,
+ // or if no form elements exist.
+ return;
+ }
+
+ // For <input type="submit" />, etc.
+ var button_regex = /button|submit|reset/;
+
+ // For <input type="text" />, etc.
+ var type_regex = /date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;
+
+ dojo.query('input').forEach(function(el) {
+ // Is it a button?
+ if (el.getAttribute('type').match(button_regex)) {
+ dojo.addClass(el, 'ie6_button');
+
+ /* Is it disabled? */
+ if (el.disabled) {
+ dojo.addClass(el, 'ie6_button_disabled');
+ }
+ }
+ // Or is it a textual input?
+ else if (el.getAttribute('type').match(type_regex)) {
+ dojo.addClass(el, 'ie6_input');
+
+ /* Is it disabled? */
+ if (el.disabled) {
+ dojo.addClass(el, 'ie6_input_disabled');
+ }
+ }
+ });
+
+ dojo.query('textarea, select').forEach(function(el) {
+ /* Is it disabled? */
+ if (el.disabled) {
+ dojo.addClass(el, 'ie6_input_disabled');
+ }
+ });
+ },
+ // FORMALIZE.init.autofocus
+ autofocus: function() {
+ if (AUTOFOCUS_SUPPORTED || !dojo.query('[autofocus]').length) {
+ return;
+ }
+
+ dojo.query('[autofocus]')[0].focus();
+ },
+ // FORMALIZE.init.placeholder
+ placeholder: function() {
+ if (PLACEHOLDER_SUPPORTED || !dojo.query('[placeholder]').length) {
+ // Exit if placeholder is supported natively,
+ // or if page does not have any placeholder.
+ return;
+ }
+
+ FORMALIZE.misc.add_placeholder();
+
+ dojo.query('[placeholder]').forEach(function(el) {
+ dojo.connect(el, 'onfocus', function() {
+ var text = el.getAttribute('placeholder');
+
+ if (el.value === text) {
+ el.value = '';
+ dojo.removeClass(el, 'placeholder_text');
+ }
+ });
+
+ dojo.connect(el, 'onblur', function() {
+ FORMALIZE.misc.add_placeholder();
+ });
+ });
+
+ // Prevent <form> from accidentally
+ // submitting the placeholder text.
+ dojo.query('form').forEach(function(form) {
+ dojo.connect(form, 'onsubmit', function() {
+ dojo.query('[placeholder]', form).forEach(function(el) {
+ var text = el.getAttribute('placeholder');
+
+ if (el.value === text) {
+ el.value = '';
+ dojo.removeClass(el, 'placeholder_text');
+ }
+ });
+ });
+
+ dojo.connect(form, 'onreset', function() {
+ setTimeout(FORMALIZE.misc.add_placeholder, 50);
+ });
+ });
+ }
+ },
+ // FORMALIZE.misc
+ misc: {
+ // FORMALIZE.misc.add_placeholder
+ add_placeholder: function() {
+ if (PLACEHOLDER_SUPPORTED || !dojo.query('[placeholder]').length) {
+ // Exit if placeholder is supported natively,
+ // or if page does not have any placeholder.
+ return;
+ }
+
+ dojo.query('[placeholder]').forEach(function(el) {
+ var text = el.getAttribute('placeholder');
+
+ if (!el.value || el.value === text) {
+ el.value = text;
+ dojo.addClass(el, 'placeholder_text');
+ }
+ });
+ }
+ }
+ };
+// Alias window, document.
+})(this, this.document);
+
+// Automatically calls all functions in FORMALIZE.init
+dojo.addOnLoad(function() {
+ FORMALIZE.go();
+});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit b13a9ec

Please sign in to comment.