github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

mudge / jquery_example

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 51
    • 2
  • Source
  • Commits
  • Network (2)
  • Issues (1)
  • Downloads (11)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (11)
    • v1.4.2
    • v1.4.1
    • v1.4
    • v1.3.4
    • v1.3.3
    • v1.3.2
    • v1.3.1
    • v1.3
    • v1.2.1
    • v1.2
    • v1.1
Sending Request…
Click here to lend your support to: jquery_example and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

jQuery plugin to populate form inputs with example text that disappears on focus. See also http://github.com/mudge/jquery_placeholder — Read more

  cancel

http://plugins.jquery.com/project/example

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Handle change events (as sent by plugins such as UI Datepicker) as well as 
using focus/blur. 
mudge (author)
Sun May 17 12:14:23 -0700 2009
commit  5b425087153acfd8e93250ac10743aaf9a09f225
tree    ba34ea9f75fc579fdeb1c1d4f97e6c713e918505
parent  864188d646a09cc8e97a95a453b731cdfa034016
jquery_example /
name age
history
message
file BSD-LICENSE.txt Sun May 17 12:14:23 -0700 2009 Handle change events (as sent by plugins such a... [mudge]
file GPL-LICENSE.txt Thu Mar 13 04:03:25 -0700 2008 Reduced the number of function calls and improv... [mudge]
file README.markdown Sun May 17 12:14:23 -0700 2009 Handle change events (as sent by plugins such a... [mudge]
file demo.html Mon Oct 06 03:19:52 -0700 2008 Added the demo file (which doubles as a profiler). [mudge]
file jquery.example.js Sun May 17 12:14:23 -0700 2009 Handle change events (as sent by plugins such a... [mudge]
file jquery.example.min.js Sun May 17 12:14:23 -0700 2009 Handle change events (as sent by plugins such a... [mudge]
directory test/ Sun May 17 12:14:23 -0700 2009 Handle change events (as sent by plugins such a... [mudge]
README.markdown

jQuery Form Example Plugin 1.4.2

This is a jQuery plugin to populate form inputs with example text that disappears on focus.

Basic usage revolves around the use of the example function like so:

$('input#name').example('Bob Smith');

This will then put the example text "Bob Smith" into the input with the ID "name". When a user then focuses on this input, the example text will disappear, allowing them to enter their data. If they then click elsewhere without entering any information, the example will re-appear.

By default, example text is given the class example, allowing you to style it with CSS like so:

.example { color: #666; }

If this class name conflicts with one you already use, you can override it with the className option like so:

$('input#name').example('Bob Smith', { className: 'hint' });

The above example would then be given the class hint instead of example.

If you plan to use the same options repeatedly, it is possible to override the plugin's defaults directly:

$.fn.example.defaults.className = 'notExample';

This will cause any uses of the plugin after this point to use the new defaults.

As well as supplying the example text via a string, a callback function can be used instead to determine the value at runtime:

$('input#name').example(function() {
   return $(this).attr('title'); 
});

The above example will set the example text to the title attribute of the input. The callback is executed within the context of the input field so, as in the example above, $(this) will return the input itself.

It is worth noting that the callback is evaluated every time the example text needs to be inserted and is not cached. This makes it possible to dynamically change the example text of a field after page load like so:

$('input#name').example(function() {
    var text = $(this).attr('title');
    $(this).attr('title', 'Not the original title anymore');
    return text;
});

The plugin also supports the jQuery Metadata plugin which allows you to specify metadata in elements themselves. You can specify the example text and any options like so:

<input id="m1" class="{example: 'An example', className: 'abc' }" />

Please note that metadata will be overridden by arguments, e.g.

<input id="m1" class="{example: 'An example'}" />
$('#m1').example('Another example');

The example will be set to "Another example" instead of "An example".

Testing

As of 1.4, this plugin now comes with a QUnit test suite that you can find in the test/ directory and run by opening index.html in your browser.

Compatibility

This plugin has been tested with jQuery 1.1 and newer and should work in all browsers supported by jQuery itself (it has been tested with Safari 4, Google Chrome 0.2.149.29, Mozilla Firefox 3, Opera 9.52 and Internet Explorer 7).

Author

This plugin was written by and is maintained by Paul Mucur aka "mudge". Please do not hesitate to contact me with comments and bug reports through the plugin's official entry on the jQuery Plugins directory: http://plugins.jquery.com/project/example

You can view the latest source code (and fork the entire project if you wish) at http://github.com/mudge/jquery_example

Contributors

The code to support the Metadata plugin was contributed by DeLynn Berry (http://github.com/delynn).

Licensing

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.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server