/* * @File: jquery.formLabels1.0.js * @Version: 1.0 * @Author: Andrei Zharau (www.o2v.net) - Senior UX Engineer at LibertyConcepts.com * * @Requires: jQuery v1.4++ & jQueryUI v1.8++ * @Usage: $j.fn.formLabels() * @Options: excludeElts - Excludes certain elements from being 'labelized'. Default: ''. Example: $.fn.formLabels(excludeElts:'#email, .nolabel') * refreshOnResize - whether or not refresh labels on window resize. Default: true * safemode - if enabled the plugin runs in the safemode without using spans and animation. Default: false * labelParent - parentContainer for your 'labels'. Default: 'form' * semantic - puts label before input element. Default: true * @Methods: $.fn.formLabels.refreshLabels() - refresh labels' position. Useful when input positioning has been changed due to DOM modifications, elements resizing, etc. * @Changelog * 1.0 * + depending on which element is a parent element, script creates formLabels either as spans or labels (suggested by Alex Hall) * + new option 'semantic'. If true, then plugin renders label before input box (works only if labelParent:'form') * * 'labelParent' option supports any element on the page, but labelParent: 'form' puts labels into closest form. Default value has been changed to form. (suggested by Ferry Mulyono) * * changed logic for label's background detection * * fixed problem with blur event (formLabel did not disappear on auto-complete) * 1.0RC3 * + fixed probmlems with input events in IE * + Green Hue Opacity bug in FF (thanks to Ionut Staicu) * 1.0RC2 * + plugin supports a new refresh method * + new options: safemode and labelParent * + refresh on window resize is now an option * + slightly updated performance * * Copyright 2010 Liberty Concepts, all rights reserved. * * This source file is free software, under either the GPL v2 license or a * BSD style license, as supplied with this software. * * This source file is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details. */ ; (function($){ var formLabels, opts, elts; $.fn.tagName = function() { return this.get(0).tagName; } formLabels = $.fn.formLabels = function(options) { opts = $.extend({ excludeElts: '', //elements to be excluded refreshOnResize: false, //whether or not refresh labels on 'resize' event for window safemode:false, //enable safe mode without DOM modifications labelParent: 'form', //specifies a block that will store the form labels (body or form) semantic: true //if true, then plugin renders label before input box (works only if labelParent:'form') },options); var spanID = 0; elts = $("textarea, input[type='email'], input[type='text'], input[type='password']").not(opts.excludeElts).filter(":visible[title]"); if (elts.length && !opts.safemode) { elts.each(function(){ var $this = $(this); var spanBg = ''; var $thisBC, //background-color of input box $thisBI, //background-image of input box labelParent, //parent element tagName; //type of the element to be inserted if(this.value == '' && this.title != '') { if (opts.labelParent == 'form') { labelParent = $this.closest('form'); tagName = '