Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($){
- $.fn.extend({
- entry: function (options) {
- // entry adds default text to an element and removes it if selected
- var defaults = {
- expand: false,
- submit: false,
- };
- var options = $.extend(defaults, options);
- return this.each(function () {
- $(this).click(function() {
- // the title attribute contains the default text for the input/textarea upon creation
- // if this value exists in the input field, it is recognised as untouched
- if($(this).val() == $(this)[0].title) {
- // text contents are cleared for user entry
- $(this).val("");
- // the previously lighter text is replaced with darker
- $(this).css('color', '#333');
- // the input field will also increase in padding for aesthetics, but only if expand is enabled
- if(options.expand)
- $(this).css('padding-bottom', '10px');
- if(options.submit)
- $(this).next().show();
- }
- });
- $(this).blur(function() {
- if($(this).val() == "") {
- $(this).val($(this)[0].title); // reset text contents to default
- $(this).css('color', '#999');
- $(this).css('padding-bottom', '0px');
- if(options.submit)
- $(this).next().hide();
- }
- });
- return false;
- });
- }
- });
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement