woocommerce/assets/js/jquery-placeholder/jquery.placeholder.js

69 lines
2.1 KiB
JavaScript
Raw Normal View History

2012-10-17 13:32:25 +00:00
/*
* Simple Placeholder by @marcgg under MIT License
* Report bugs or contribute on Gihub: https://github.com/marcgg/Simple-Placeholder
2012-10-17 13:32:25 +00:00
*/
2012-10-17 13:32:25 +00:00
(function($) {
$.simplePlaceholder = {
placeholderClass: null,
hidePlaceholder: function(){
var $this = $(this);
if($this.val() == $this.attr('placeholder') && $this.data($.simplePlaceholder.placeholderData)){
$this
.val("")
.removeClass($.simplePlaceholder.placeholderClass)
.data($.simplePlaceholder.placeholderData, false);
}
},
showPlaceholder: function(){
var $this = $(this);
if($this.val() == ""){
$this
.val($this.attr('placeholder'))
.addClass($.simplePlaceholder.placeholderClass)
.data($.simplePlaceholder.placeholderData, true);
}
},
preventPlaceholderSubmit: function(){
$(this).find(".simple-placeholder").each(function(e){
var $this = $(this);
if($this.val() == $this.attr('placeholder') && $this.data($.simplePlaceholder.placeholderData)){
$this.val('');
2012-10-17 13:32:25 +00:00
}
});
return true;
2012-10-17 13:32:25 +00:00
}
};
2012-10-17 13:32:25 +00:00
$.fn.simplePlaceholder = function(options) {
if(document.createElement('input').placeholder == undefined){
var config = {
placeholderClass : 'placeholding',
placeholderData : 'simplePlaceholder.placeholding'
};
if(options) $.extend(config, options);
$.extend($.simplePlaceholder, config);
this.each(function() {
var $this = $(this);
$this.focus($.simplePlaceholder.hidePlaceholder);
$this.blur($.simplePlaceholder.showPlaceholder);
$this.data($.simplePlaceholder.placeholderData, false);
if($this.val() == '') {
$this.val($this.attr("placeholder"));
$this.addClass($.simplePlaceholder.placeholderClass);
$this.data($.simplePlaceholder.placeholderData, true);
}
$this.addClass("simple-placeholder");
$(this.form).submit($.simplePlaceholder.preventPlaceholderSubmit);
});
2012-10-17 13:32:25 +00:00
}
return this;
};
2012-10-17 13:32:25 +00:00
})(jQuery);