templates/jquery/jquery.formalize.js in compass_formalize-0.0.4 vs templates/jquery/jquery.formalize.js in compass_formalize-0.0.5

- old
+ new

@@ -1,38 +1,44 @@ -// -// Note: This file depends on the jQuery library. -// +/* + Formalize - version 1.2 + Note: This file depends on the jQuery library. +*/ + // Module pattern: -// http://yuiblog.com/blog/2007/06/12/module-pattern/ +// http://yuiblog.com/blog/2007/06/12/module-pattern var FORMALIZE = (function($, window, document, undefined) { + // Internet Explorer detection. + function IE(version) { + var b = document.createElement('b'); + b.innerHTML = '<!--[if IE ' + version + ']><br><![endif]-->'; + return !!b.getElementsByTagName('br').length; + } + // Private constants. var PLACEHOLDER_SUPPORTED = 'placeholder' in document.createElement('input'); var AUTOFOCUS_SUPPORTED = 'autofocus' in document.createElement('input'); - var WEBKIT = 'webkitAppearance' in document.createElement('select').style; - var IE6 = !!($.browser.msie && parseInt($.browser.version, 10) === 6); - var IE7 = !!($.browser.msie && parseInt($.browser.version, 10) === 7); + var IE6 = IE(6); + var IE7 = IE(7); // Expose innards of FORMALIZE. return { // FORMALIZE.go go: function() { - for (var i in FORMALIZE.init) { - FORMALIZE.init[i](); + var i, j = this.init; + + for (i in j) { + j.hasOwnProperty(i) && j[i](); } }, // FORMALIZE.init init: { - // FORMALIZE.init.detect_webkit - detect_webkit: function() { - if (!WEBKIT) { - return; - } - - // Tweaks for Safari + Chrome. - // <html class="is_webkit"> - $(document.documentElement).addClass('is_webkit'); + // FORMALIZE.init.disable_link_button + disable_link_button: function() { + $(document.documentElement).on('click', 'a.button_disabled', function() { + return false; + }); }, // FORMALIZE.init.full_input_size full_input_size: function() { if (!IE7 || !$('textarea, input.input_full').length) { return; @@ -91,11 +97,15 @@ autofocus: function() { if (AUTOFOCUS_SUPPORTED || !$(':input[autofocus]').length) { return; } - $(':input[autofocus]:visible:first').focus(); + var el = $('[autofocus]')[0]; + + if (!el.disabled) { + el.focus(); + } }, // FORMALIZE.init.placeholder placeholder: function() { if (PLACEHOLDER_SUPPORTED || !$(':input[placeholder]').length) { // Exit if placeholder is supported natively, @@ -104,10 +114,16 @@ } FORMALIZE.misc.add_placeholder(); $(':input[placeholder]').each(function() { + // Placeholder obscured in older browsers, + // so there's no point adding to password. + if (this.type === 'password') { + return; + } + var el = $(this); var text = el.attr('placeholder'); el.focus(function() { if (el.val() === text) { @@ -121,11 +137,11 @@ // submitting the placeholder text. el.closest('form').submit(function() { if (el.val() === text) { el.val('').removeClass('placeholder_text'); } - }).bind('reset', function() { + }).on('reset', function() { setTimeout(FORMALIZE.misc.add_placeholder, 50); }); }); } }, @@ -138,9 +154,15 @@ // or if page does not have any placeholder. return; } $(':input[placeholder]').each(function() { + // Placeholder obscured in older browsers, + // so there's no point adding to password. + if (this.type === 'password') { + return; + } + var el = $(this); var text = el.attr('placeholder'); if (!el.val() || el.val() === text) { el.val(text).addClass('placeholder_text'); \ No newline at end of file