# Copyright (c) 2009 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library 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 GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: ClearOnFocus.pm,v 1.4 2010/03/25 22:40:43 dobbs Exp $ package Bivio::UI::XHTML::Widget::ClearOnFocus; use strict; use Bivio::Base 'XHTMLWidget.Join'; use Bivio::UI::ViewLanguageAUTOLOAD; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.4 $ =~ /\d+/g); sub initialize { my($self) = @_; my($id) = JavaScript()->unique_html_id; $self->put_unless_exists(values => [ Script('b_clear_on_focus'), $self->get('widget')->put( ONFOCUS => Join([ 'b_clear_on_focus(this, "', JavaScriptString($self->get('hint_text')), '")', ]), class => _class($self), id => $id, ), Tag({ tag => 'script', TYPE => 'text/javascript', value => Join([ "var b_clear_on_focus_value = document.getElementById('$id');\n", "if (b_clear_on_focus_value && !b_clear_on_focus_value.value.length)\n", 'b_clear_on_focus_value.value = "', JavaScriptString($self->get('hint_text')), qq{";\n}, ]), }), ]); return shift->SUPER::initialize(@_); } sub internal_new_args { return shift->internal_compute_new_args( [qw(widget hint_text)], \@_); } sub _class { my($self) = @_; my($c) = $self->get('widget')->unsafe_get('class'); return !$c ? 'disabled' : Join([$c, 'disabled'], ' '); } 1;