replaced placeholder plugin
old one no longer in active dev
This commit is contained in:
parent
34643e237d
commit
d1fbc3b7f1
|
@ -1,5 +1,8 @@
|
|||
jQuery(document).ready(function($) {
|
||||
|
||||
// Placeholder
|
||||
$('.woocommerce textarea[placeholder], .woocommerce-page textarea[placeholder], .woocommerce input[placeholder], .woocommerce-page input[placeholder]').simplePlaceholder();
|
||||
|
||||
// Orderby
|
||||
$(document).on( 'change', 'select.orderby', function() {
|
||||
$(this).closest('form').submit();
|
||||
|
|
|
@ -1 +1 @@
|
|||
jQuery(document).ready(function(e){e(document).on("change","select.orderby",function(){e(this).closest("form").submit()});e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" class="plus" />').prepend('<input type="button" value="-" class="minus" />');e("input.qty:not(.product-quantity input.qty)").each(function(){var t=parseFloat(e(this).attr("min"));t&&t>0&&parseFloat(e(this).val())<t&&e(this).val(t)});e(document).on("click",".plus, .minus",function(){var t=e(this).closest(".quantity").find(".qty"),n=parseFloat(t.val()),r=parseFloat(t.attr("max")),i=parseFloat(t.attr("min")),s=t.attr("step");if(!n||n==""||n=="NaN")n=0;if(r==""||r=="NaN")r="";if(i==""||i=="NaN")i=0;if(s=="any"||s==""||s==undefined||parseFloat(s)=="NaN")s=1;e(this).is(".plus")?r&&(r==n||n>r)?t.val(r):t.val(n+parseFloat(s)):i&&(i==n||n<i)?t.val(i):n>0&&t.val(n-parseFloat(s));t.trigger("change")});var t=woocommerce_params.countries.replace(/"/g,'"'),n=e.parseJSON(t);e("select.country_to_state").change(function(){var t=e(this).val(),r=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state"),i=r.parent(),s=r.attr("name"),o=r.attr("id"),u=r.val(),a=r.attr("placeholder");if(n[t])if(n[t].length==0){r.parent().hide().find(".chzn-container").remove();r.replaceWith('<input type="hidden" class="hidden" name="'+s+'" id="'+o+'" value="" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else{var f="",l=n[t];for(var c in l)f=f+'<option value="'+c+'">'+l[c]+"</option>";r.parent().show();if(r.is("input")){r.replaceWith('<select name="'+s+'" id="'+o+'" class="state_select" placeholder="'+a+'"></select>');r=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")}r.html('<option value="">'+woocommerce_params.i18n_select_state_text+"</option>"+f);r.val(u);e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(r.is("select")){i.show().find(".chzn-container").remove();r.replaceWith('<input type="text" class="input-text" name="'+s+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(r.is(".hidden")){i.show().find(".chzn-container").remove();r.replaceWith('<input type="text" class="input-text" name="'+s+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}e("body").trigger("country_to_state_changing",[t,e(this).closest("div")])})});
|
||||
jQuery(document).ready(function(e){e(".woocommerce textarea[placeholder], .woocommerce-page textarea[placeholder], .woocommerce input[placeholder], .woocommerce-page input[placeholder]").simplePlaceholder();e(document).on("change","select.orderby",function(){e(this).closest("form").submit()});e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" class="plus" />').prepend('<input type="button" value="-" class="minus" />');e("input.qty:not(.product-quantity input.qty)").each(function(){var t=parseFloat(e(this).attr("min"));t&&t>0&&parseFloat(e(this).val())<t&&e(this).val(t)});e(document).on("click",".plus, .minus",function(){var t=e(this).closest(".quantity").find(".qty"),n=parseFloat(t.val()),r=parseFloat(t.attr("max")),i=parseFloat(t.attr("min")),s=t.attr("step");if(!n||n==""||n=="NaN")n=0;if(r==""||r=="NaN")r="";if(i==""||i=="NaN")i=0;if(s=="any"||s==""||s==undefined||parseFloat(s)=="NaN")s=1;e(this).is(".plus")?r&&(r==n||n>r)?t.val(r):t.val(n+parseFloat(s)):i&&(i==n||n<i)?t.val(i):n>0&&t.val(n-parseFloat(s));t.trigger("change")});var t=woocommerce_params.countries.replace(/"/g,'"'),n=e.parseJSON(t);e("select.country_to_state").change(function(){var t=e(this).val(),r=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state"),i=r.parent(),s=r.attr("name"),o=r.attr("id"),u=r.val(),a=r.attr("placeholder");if(n[t])if(n[t].length==0){r.parent().hide().find(".chzn-container").remove();r.replaceWith('<input type="hidden" class="hidden" name="'+s+'" id="'+o+'" value="" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else{var f="",l=n[t];for(var c in l)f=f+'<option value="'+c+'">'+l[c]+"</option>";r.parent().show();if(r.is("input")){r.replaceWith('<select name="'+s+'" id="'+o+'" class="state_select" placeholder="'+a+'"></select>');r=e(this).closest("div").find("#billing_state, #shipping_state, #calc_shipping_state")}r.html('<option value="">'+woocommerce_params.i18n_select_state_text+"</option>"+f);r.val(u);e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(r.is("select")){i.show().find(".chzn-container").remove();r.replaceWith('<input type="text" class="input-text" name="'+s+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}else if(r.is(".hidden")){i.show().find(".chzn-container").remove();r.replaceWith('<input type="text" class="input-text" name="'+s+'" id="'+o+'" placeholder="'+a+'" />');e("body").trigger("country_to_state_changed",[t,e(this).closest("div")])}e("body").trigger("country_to_state_changing",[t,e(this).closest("div")])})});
|
|
@ -1,106 +1,69 @@
|
|||
/*
|
||||
* Placeholder plugin for jQuery
|
||||
* ---
|
||||
* Copyright 2010, Daniel Stocks (http://webcloud.se)
|
||||
* Released under the MIT, BSD, and GPL Licenses.
|
||||
* Simple Placeholder by @marcgg under MIT License
|
||||
* Report bugs or contribute on Gihub: https://github.com/marcgg/Simple-Placeholder
|
||||
*/
|
||||
(function($) {
|
||||
function Placeholder(input) {
|
||||
this.input = input;
|
||||
if (input.attr('type') == 'password') {
|
||||
this.handlePassword();
|
||||
}
|
||||
// Prevent placeholder values from submitting
|
||||
$(input[0].form).submit(function() {
|
||||
if (input.hasClass('placeholder') && input[0].value == input.attr('placeholder')) {
|
||||
input[0].value = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
Placeholder.prototype = {
|
||||
show : function(loading) {
|
||||
// FF and IE saves values when you refresh the page. If the user refreshes the page with
|
||||
// the placeholders showing they will be the default values and the input fields won't be empty.
|
||||
if (this.input[0].value === '' || (loading && this.valueIsPlaceholder())) {
|
||||
if (this.isPassword) {
|
||||
try {
|
||||
this.input[0].setAttribute('type', 'text');
|
||||
} catch (e) {
|
||||
this.input.before(this.fakePassword.show()).hide();
|
||||
}
|
||||
}
|
||||
this.input.addClass('placeholder');
|
||||
this.input[0].value = this.input.attr('placeholder');
|
||||
}
|
||||
},
|
||||
hide : function() {
|
||||
if (this.valueIsPlaceholder() && this.input.hasClass('placeholder')) {
|
||||
this.input.removeClass('placeholder');
|
||||
this.input[0].value = '';
|
||||
if (this.isPassword) {
|
||||
try {
|
||||
this.input[0].setAttribute('type', 'password');
|
||||
} catch (e) { }
|
||||
// Restore focus for Opera and IE
|
||||
this.input.show();
|
||||
this.input[0].focus();
|
||||
}
|
||||
}
|
||||
},
|
||||
valueIsPlaceholder : function() {
|
||||
return this.input[0].value == this.input.attr('placeholder');
|
||||
},
|
||||
handlePassword: function() {
|
||||
var input = this.input;
|
||||
input.attr('realType', 'password');
|
||||
this.isPassword = true;
|
||||
// IE < 9 doesn't allow changing the type of password inputs
|
||||
if ($.browser.msie && input[0].outerHTML) {
|
||||
var fakeHTML = $(input[0].outerHTML.replace(/type=(['"])?password\1/gi, 'type=$1text$1'));
|
||||
this.fakePassword = fakeHTML.val(input.attr('placeholder')).addClass('placeholder').focus(function() {
|
||||
input.trigger('focus');
|
||||
$(this).hide();
|
||||
});
|
||||
$(input[0].form).submit(function() {
|
||||
fakeHTML.remove();
|
||||
input.show()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
var NATIVE_SUPPORT = !!("placeholder" in document.createElement( "input" ));
|
||||
$.fn.placeholder = function() {
|
||||
return NATIVE_SUPPORT ? this : this.each(function() {
|
||||
var input = $(this);
|
||||
var placeholder = new Placeholder(input);
|
||||
placeholder.show(true);
|
||||
input.focus(function() {
|
||||
placeholder.hide();
|
||||
});
|
||||
input.blur(function() {
|
||||
placeholder.show(false);
|
||||
});
|
||||
|
||||
// On page refresh, IE doesn't re-populate user input
|
||||
// until the window.onload event is fired.
|
||||
if ($.browser.msie) {
|
||||
$(window).load(function() {
|
||||
if(input.val()) {
|
||||
input.removeClass("placeholder");
|
||||
}
|
||||
placeholder.show(true);
|
||||
});
|
||||
// What's even worse, the text cursor disappears
|
||||
// when tabbing between text inputs, here's a fix
|
||||
input.focus(function() {
|
||||
if(this.value == "") {
|
||||
var range = this.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveStart('character', 0);
|
||||
range.select();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
(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('');
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
$.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);
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
})(jQuery);
|
|
@ -1,6 +1,4 @@
|
|||
/*
|
||||
* Placeholder plugin for jQuery
|
||||
* ---
|
||||
* Copyright 2010, Daniel Stocks (http://webcloud.se)
|
||||
* Released under the MIT, BSD, and GPL Licenses.
|
||||
*/(function(e){function t(t){this.input=t;t.attr("type")=="password"&&this.handlePassword();e(t[0].form).submit(function(){t.hasClass("placeholder")&&t[0].value==t.attr("placeholder")&&(t[0].value="")})}t.prototype={show:function(e){if(this.input[0].value===""||e&&this.valueIsPlaceholder()){if(this.isPassword)try{this.input[0].setAttribute("type","text")}catch(t){this.input.before(this.fakePassword.show()).hide()}this.input.addClass("placeholder");this.input[0].value=this.input.attr("placeholder")}},hide:function(){if(this.valueIsPlaceholder()&&this.input.hasClass("placeholder")){this.input.removeClass("placeholder");this.input[0].value="";if(this.isPassword){try{this.input[0].setAttribute("type","password")}catch(e){}this.input.show();this.input[0].focus()}}},valueIsPlaceholder:function(){return this.input[0].value==this.input.attr("placeholder")},handlePassword:function(){var t=this.input;t.attr("realType","password");this.isPassword=!0;if(e.browser.msie&&t[0].outerHTML){var n=e(t[0].outerHTML.replace(/type=(['"])?password\1/gi,"type=$1text$1"));this.fakePassword=n.val(t.attr("placeholder")).addClass("placeholder").focus(function(){t.trigger("focus");e(this).hide()});e(t[0].form).submit(function(){n.remove();t.show()})}}};var n="placeholder"in document.createElement("input");e.fn.placeholder=function(){return n?this:this.each(function(){var n=e(this),r=new t(n);r.show(!0);n.focus(function(){r.hide()});n.blur(function(){r.show(!1)});if(e.browser.msie){e(window).load(function(){n.val()&&n.removeClass("placeholder");r.show(!0)});n.focus(function(){if(this.value==""){var e=this.createTextRange();e.collapse(!0);e.moveStart("character",0);e.select()}})}})}})(jQuery);
|
||||
* Simple Placeholder by @marcgg under MIT License
|
||||
* Report bugs or contribute on Gihub: https://github.com/marcgg/Simple-Placeholder
|
||||
*/(function(e){e.simplePlaceholder={placeholderClass:null,hidePlaceholder:function(){var t=e(this);t.val()==t.attr("placeholder")&&t.data(e.simplePlaceholder.placeholderData)&&t.val("").removeClass(e.simplePlaceholder.placeholderClass).data(e.simplePlaceholder.placeholderData,!1)},showPlaceholder:function(){var t=e(this);t.val()==""&&t.val(t.attr("placeholder")).addClass(e.simplePlaceholder.placeholderClass).data(e.simplePlaceholder.placeholderData,!0)},preventPlaceholderSubmit:function(){e(this).find(".simple-placeholder").each(function(t){var n=e(this);n.val()==n.attr("placeholder")&&n.data(e.simplePlaceholder.placeholderData)&&n.val("")});return!0}};e.fn.simplePlaceholder=function(t){if(document.createElement("input").placeholder==undefined){var n={placeholderClass:"placeholding",placeholderData:"simplePlaceholder.placeholding"};t&&e.extend(n,t);e.extend(e.simplePlaceholder,n);this.each(function(){var t=e(this);t.focus(e.simplePlaceholder.hidePlaceholder);t.blur(e.simplePlaceholder.showPlaceholder);t.data(e.simplePlaceholder.placeholderData,!1);if(t.val()==""){t.val(t.attr("placeholder"));t.addClass(e.simplePlaceholder.placeholderClass);t.data(e.simplePlaceholder.placeholderData,!0)}t.addClass("simple-placeholder");e(this.form).submit(e.simplePlaceholder.preventPlaceholderSubmit)})}return this}})(jQuery);
|
Loading…
Reference in New Issue