
javascript default text replace
By: a guest on
Jun 14th, 2012 | syntax:
JavaScript | size: 2.46 KB | hits: 24 | expires: Never
var inject = {};
(function($)
{
//Atribui acoes aos objetos passados
//@author: Pedro Sampaio
inject =
{
input :
{
textcounter: function(obj)
{
if(!obj)
obj = $(this);
obj.maxlength({
maxCharacters: obj.attr('data-length'),
status: true, // True to show status indicator bewlow the element
statusClass: "status", // The class on the status div
statusText: "caracteres restantes",
notificationClass: "cheio",
showAlert: false,
alertText: "Você já chegou no limite de caracteres.",
slider: false
});
},
data_replace: function(obj)
{
if(!obj)
obj = $(this);
obj.each(function()
{
val = $(this).val();
if(!val)
{
$(this).val($(this).attr('data-default'));
}
$(this).focus(function()
{
if($(this).val() == $(this).attr('data-default'))
{
$(this).val('');
}
}).blur(function()
{
if($(this).val() == '')
{
$(this).val($(this).attr('data-default'));
}
});
});
},
form_replace: function(obj)
{
if(!obj)
obj = $(this);
obj.each(function()
{
campos = $(this).find('[data-default]');
count = campos.length;
if(count > 0)
{
$(this).submit(function(e)
{
e.preventDefault();
campos.each(function()
{
if($(this).val() == $(this).attr('data-default'))
{
$(this).val('');
}
});
if($(this).find('[class*=validate]'))
{
if(!$(this).validationEngine('validate'))
return false;
}
this.submit();
});
}
});
}
},
click: function(obj, fn)
{
if(!obj)
obj = $(this);
inject.unbind.click(obj);
obj.on('click', fn);
},
unbind :
{
click :
function(obj)
{
if(!obj)
obj = $(this);
obj.off('click');
},
blur :
function(obj)
{
if(!obj)
obj = $(this);
obj.off('blur');
},
focus :
function(obj)
{
if(!obj)
obj = $(this);
obj.off('focus');
},
submit :
function(obj)
{
if(!obj)
obj = $(this);
obj.off('submit');
}
}
}
})(jQuery);
//
inject.input.data_replace($('[data-default]')); inject.input.form_replace($('form:has("[data-default]")'));