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

- old
+ new

@@ -1,35 +1,49 @@ -// -// Note: This file depends on the ExtJS 3.x library. -// +/* + Formalize - version 1.2 + + Note: This file depends on the ExtJS 3.x library. +*/ + +// 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 = Ext.isIE6; - var IE7 = Ext.isIE7; + 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; - } + // FORMALIZE.init.disable_link_button + disable_link_button: function() { + Ext.getBody().on('click', function(ev) { + var el = ev.target; + var is_disabled = el.tagName.toLowerCase() === 'a' && el.className.match('button_disabled'); - // Tweaks for Safari + Chrome. - // <html class="is_webkit"> - Ext.get(document.documentElement).addClass('is_webkit'); + if (is_disabled) { + ev.preventDefault(); + } + }); }, // FORMALIZE.init.full_input_size full_input_size: function() { if (!IE7 || !Ext.query('textarea, input.input_full')) { return; @@ -88,11 +102,15 @@ autofocus: function() { if (AUTOFOCUS_SUPPORTED || !Ext.query('[autofocus]')) { return; } - Ext.query('[autofocus]')[0].focus(); + var el = Ext.query('[autofocus]')[0]; + + if (!el.disabled) { + el.focus(); + } }, // FORMALIZE.init.placeholder placeholder: function() { if (PLACEHOLDER_SUPPORTED || !Ext.query('[placeholder]')) { // Exit if placeholder is supported natively, @@ -101,20 +119,19 @@ } FORMALIZE.misc.add_placeholder(); Ext.each(Ext.query('[placeholder]'), function(el) { + // Placeholder obscured in older browsers, + // so there's no point adding to password. + if (el.type === 'password') { + return; + } + var text = el.getAttribute('placeholder'); var form = Ext.get(el).parent('form'); - function add_placeholder() { - if (!el.value || el.value === text) { - el.value = text; - Ext.get(el).addClass('placeholder_text'); - } - } - Ext.get(el).on('focus', function() { if (el.value === text) { el.value = ''; Ext.get(el).removeClass('placeholder_text'); } @@ -148,9 +165,15 @@ // or if page does not have any placeholder. return; } Ext.each(Ext.query('[placeholder]'), function(el) { + // Placeholder obscured in older browsers, + // so there's no point adding to password. + if (el.type === 'password') { + return; + } + var text = el.getAttribute('placeholder'); if (!el.value || el.value === text) { el.value = text; Ext.get(el).addClass('placeholder_text'); \ No newline at end of file