forked from mudge/jquery_example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.example.min.js
30 lines (29 loc) · 1.98 KB
/
jquery.example.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* jQuery Form Example Plugin 1.4.3
* Populate form inputs with example text that disappears on focus.
*
* e.g.
* $('input#name').example('Bob Smith');
* $('input[@title]').example(function() {
* return $(this).attr('title');
* });
* $('textarea#message').example('Type your message here', {
* className: 'example_text'
* });
*
* Copyright (c) Paul Mucur (http://mucur.name), 2007-2008.
* Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
* licenses.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*/
(function(a){a.fn.example=function(e,g){var d=a.isFunction(e),f=a.extend({},g,{example:e});return this.each(function(){var c=a(this),b=a.metadata?a.extend({},a.fn.example.defaults,c.metadata(),f):a.extend({},a.fn.example.defaults,f);if(!a.fn.example.boundClassNames[b.className]){a(window).unload(function(){a("."+b.className).val("")});a("form").submit(function(){a(this).find("."+b.className).val("")});a.fn.example.boundClassNames[b.className]=true}if(!c.attr("defaultValue")&&(d||c.val()==b.example))c.val("");
if(c.val()==""&&this!=document.activeElement){c.addClass(b.className);c.val(d?b.example.call(this):b.example)}c.focus(function(){if(a(this).is("."+b.className)){a(this).val("");a(this).removeClass(b.className)}});c.change(function(){a(this).is("."+b.className)&&a(this).removeClass(b.className)});c.blur(function(){if(a(this).val()==""){a(this).addClass(b.className);a(this).val(d?b.example.call(this):b.example)}})})};a.fn.example.defaults={className:"example"};a.fn.example.boundClassNames=[]})(jQuery);