Quick validation jsLint
This commit is contained in:
@@ -1,22 +1,23 @@
|
|||||||
/* JQUERY PREVENT CONFLICT */
|
/* JQUERY PREVENT CONFLICT */
|
||||||
(function($) {
|
(function ($) {
|
||||||
|
|
||||||
/* ------------------------------------------------------------------
|
/* ------------------------------------------------------------------
|
||||||
callback Function -------------------------------------------------- */
|
callback Function -------------------------------------------------- */
|
||||||
var confirmCallback = {
|
var confirmCallback = {
|
||||||
'address.delete': function($elm){
|
'address.delete': function ($elm) {
|
||||||
$.post($elm.attr('href'), function(data){
|
$.post($elm.attr('href'), function (data) {
|
||||||
if(data.success)
|
if (data.success) {
|
||||||
$elm.closest('tr').remove();
|
$elm.closest('tr').remove();
|
||||||
else
|
} else {
|
||||||
bootbox.alert(data.message);
|
bootbox.alert(data.message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------
|
/* ------------------------------------------------------------------
|
||||||
onLoad Function -------------------------------------------------- */
|
onLoad Function -------------------------------------------------- */
|
||||||
$(document).ready(function(){
|
$(document).ready(function () {
|
||||||
|
|
||||||
// Loader
|
// Loader
|
||||||
var $loader = $('<div class="loader"></div>');
|
var $loader = $('<div class="loader"></div>');
|
||||||
@@ -24,32 +25,29 @@
|
|||||||
|
|
||||||
// Display loader if we do ajax call
|
// Display loader if we do ajax call
|
||||||
$(document)
|
$(document)
|
||||||
.ajaxStart(function() { $loader.show(); })
|
.ajaxStart(function () { $loader.show(); })
|
||||||
.ajaxStop(function(){ $loader.hide(); });
|
.ajaxStop(function () { $loader.hide(); });
|
||||||
|
|
||||||
// Main Navigation Hover
|
// Main Navigation Hover
|
||||||
$('.nav-main')
|
$('.nav-main')
|
||||||
.on('click.subnav', '[data-toggle=dropdown]', function(event){
|
.on('click.subnav', '[data-toggle=dropdown]', function (event) {
|
||||||
if($(this).parent().hasClass('open') && $(this).is(event.target))
|
if ($(this).parent().hasClass('open') && $(this).is(event.target)) { return false; }
|
||||||
return false;
|
|
||||||
})
|
})
|
||||||
.on('mouseenter.subnav', '.dropdown', function(event){
|
.on('mouseenter.subnav', '.dropdown', function () {
|
||||||
if($(this).hasClass('open'))
|
if ($(this).hasClass('open')) { return; }
|
||||||
return;
|
|
||||||
|
|
||||||
$(this).addClass('open');
|
$(this).addClass('open');
|
||||||
})
|
})
|
||||||
.on('mouseleave.subnav', '.dropdown', function(){
|
.on('mouseleave.subnav', '.dropdown', function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
|
|
||||||
if(!$this.hasClass('open'))
|
if (!$this.hasClass('open')) { return; }
|
||||||
return;
|
|
||||||
|
|
||||||
//This will check if an input child has focus. If no then remove class open
|
//This will check if an input child has focus. If no then remove class open
|
||||||
if ($this.find(":input:focus").length == 0){
|
if ($this.find(":input:focus").length === 0) {
|
||||||
$this.removeClass('open');
|
$this.removeClass('open');
|
||||||
} else {
|
} else {
|
||||||
$this.find(":input:focus").one('blur', function(){
|
$this.find(":input:focus").one('blur', function () {
|
||||||
$this.trigger('mouseleave.subnav');
|
$this.trigger('mouseleave.subnav');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -61,56 +59,55 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Confirm Dialog
|
// Confirm Dialog
|
||||||
$(document).on('click.confirm', '[data-confirm]', function (e) {
|
$(document).on('click.confirm', '[data-confirm]', function () {
|
||||||
var $this = $(this),
|
var $this = $(this),
|
||||||
href = $this.attr('href'),
|
href = $this.attr('href'),
|
||||||
callback = $this.attr('data-confirm-callback'),
|
callback = $this.attr('data-confirm-callback'),
|
||||||
title = $this.attr('data-confirm') != '' ? $this.attr('data-confirm') : 'Are you sure?';
|
title = $this.attr('data-confirm') !== '' ? $this.attr('data-confirm') : 'Are you sure?';
|
||||||
|
|
||||||
bootbox.confirm(title, function(confirm) {
|
bootbox.confirm(title, function (confirm) {
|
||||||
if(confirm){
|
if (confirm) {
|
||||||
//Check if callback and if it's a function
|
//Check if callback and if it's a function
|
||||||
if (callback && $.isFunction(confirmCallback[callback])) {
|
if (callback && $.isFunction(confirmCallback[callback])) {
|
||||||
confirmCallback[callback]($this);
|
confirmCallback[callback]($this);
|
||||||
|
} else {
|
||||||
|
if (href) {
|
||||||
|
window.location.href = href;
|
||||||
} else {
|
} else {
|
||||||
if(href){
|
// If forms
|
||||||
window.location.href = href;
|
var $form = $this.closest("form");
|
||||||
} else {
|
if ($form.size() > 0) {
|
||||||
// If forms
|
$form.submit();
|
||||||
var $form = $this.closest("form");
|
|
||||||
if($form.size() > 0){
|
|
||||||
$form.submit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Toolbar
|
// Toolbar
|
||||||
var $category_products = $('#category-products');
|
var $category_products = $ ('#category-products');
|
||||||
if($category_products.size() > 0){
|
if ($category_products.size() > 0) {
|
||||||
var $parent = $category_products.parent();
|
var $parent = $category_products.parent();
|
||||||
|
|
||||||
$parent.on('click.view-mode', '[data-toggle=view]', function(){
|
$parent.on('click.view-mode', '[data-toggle=view]', function () {
|
||||||
if( ($(this).hasClass('btn-grid') && $parent.hasClass('grid')) || ($(this).hasClass('btn-list') && $parent.hasClass('list')))
|
if (($(this).hasClass('btn-grid') && $parent.hasClass('grid')) || ($(this).hasClass('btn-list') && $parent.hasClass('list'))) { return; }
|
||||||
return;
|
|
||||||
|
|
||||||
// Add loader effect
|
// Add loader effect
|
||||||
$loader.show();
|
$loader.show();
|
||||||
setTimeout(function(){ $parent.toggleClass('grid').toggleClass('list'); $loader.hide(); }, 400);
|
setTimeout(function () { $parent.toggleClass('grid').toggleClass('list'); $loader.hide(); }, 400);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Login
|
// Login
|
||||||
var $form_login = $('#form-login');
|
var $form_login = $('#form-login');
|
||||||
if($form_login.size() > 0) {
|
if ($form_login.size() > 0) {
|
||||||
$form_login.on('change.account', ':radio', function(){
|
$form_login.on('change.account', ':radio', function () {
|
||||||
if($(this).val() === '0')
|
if ($(this).val() === '0')
|
||||||
$('#password', $form_login).val('').prop('disabled', true); // Disabled (new customer)
|
$('#password', $form_login).val('').prop('disabled', true); // Disabled (new customer)
|
||||||
else
|
else
|
||||||
$('#password', $form_login).prop('disabled', false); // Enabled
|
$('#password', $form_login).prop('disabled', false); // Enabled
|
||||||
@@ -119,19 +116,19 @@
|
|||||||
|
|
||||||
// Mini Newsletter Subscription
|
// Mini Newsletter Subscription
|
||||||
var $form_newsletter = $('#form-newsletter-mini');
|
var $form_newsletter = $('#form-newsletter-mini');
|
||||||
if($form_newsletter.size() > 0) {
|
if ($form_newsletter.size() > 0) {
|
||||||
$form_newsletter.on('submit.newsletter', function(){
|
$form_newsletter.on('submit.newsletter', function () {
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: $(this).attr('action'),
|
url: $(this).attr('action'),
|
||||||
type: $(this).attr('method'),
|
type: $(this).attr('method'),
|
||||||
data: $(this).serialize(),
|
data: $(this).serialize(),
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(json) {
|
success: function (json) {
|
||||||
var $msg = '';
|
var $msg = '';
|
||||||
if(json.success){
|
if (json.success) {
|
||||||
$msg = json.message;
|
$msg = json.message;
|
||||||
}else{
|
} else {
|
||||||
$msg = json.message;
|
$msg = json.message;
|
||||||
}
|
}
|
||||||
bootbox.alert($msg);
|
bootbox.alert($msg);
|
||||||
@@ -153,14 +150,14 @@
|
|||||||
content: function() {
|
content: function() {
|
||||||
return $('#form-forgotpassword').html();
|
return $('#form-forgotpassword').html();
|
||||||
}
|
}
|
||||||
}).on('click.btn-forgot', function(){
|
}).on('click.btn-forgot', function () {
|
||||||
|
|
||||||
$('.btn-forgot').click(function(){
|
$('.btn-forgot').click(function () {
|
||||||
alert('click form');
|
alert('click form');
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.btn-close').click(function(){
|
$('.btn-close').click(function () {
|
||||||
$forgot_password.popover('hide');
|
$forgot_password.popover('hide');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -170,11 +167,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//.Form Filters
|
//.Form Filters
|
||||||
$('#form-filters').each(function(){
|
$('#form-filters').each(function () {
|
||||||
var $form = $(this);
|
var $form = $(this);
|
||||||
|
|
||||||
$form
|
$form
|
||||||
.on('change.filter', ':checkbox', function(){
|
.on('change.filter', ':checkbox', function () {
|
||||||
$loader.show();
|
$loader.show();
|
||||||
$form.submit();
|
$form.submit();
|
||||||
})
|
})
|
||||||
@@ -182,19 +179,18 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Product details Thumbnails
|
// Product details Thumbnails
|
||||||
$('#product-gallery').each(function(){
|
$('#product-gallery').each(function () {
|
||||||
var $item = $('.item', this),
|
var $item = $('.item', this),
|
||||||
$thumbnails = $('.thumbnail', this),
|
$thumbnails = $('.thumbnail', this),
|
||||||
$image = $('.product-image > img', this);
|
$image = $('.product-image > img', this);
|
||||||
|
|
||||||
// Show Carousel control if needed
|
// Show Carousel control if needed
|
||||||
if($item.size() > 1){
|
if ($item.size() > 1) {
|
||||||
$('#product-thumbnails', this).carousel({interval: false}).find('.carousel-control').show();
|
$('#product-thumbnails', this).carousel({interval: false}).find('.carousel-control').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
$(this).on('click.thumbnails', '.thumbnail', function(){
|
$(this).on('click.thumbnails', '.thumbnail', function () {
|
||||||
if($(this).hasClass('active'))
|
if ($(this).hasClass('active')) { return false; }
|
||||||
return false;
|
|
||||||
|
|
||||||
$image.attr('src',$(this).attr('href'));
|
$image.attr('src',$(this).attr('href'));
|
||||||
$thumbnails.removeClass('active');
|
$thumbnails.removeClass('active');
|
||||||
@@ -205,9 +201,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Payment Method
|
// Payment Method
|
||||||
$('#payment-method').each(function(){
|
$('#payment-method').each(function () {
|
||||||
var $label = $('label', this);
|
var $label = $('label', this);
|
||||||
$label.on('change', ':radio', function(){
|
$label.on('change', ':radio', function () {
|
||||||
$label.removeClass('active');
|
$label.removeClass('active');
|
||||||
$label.filter('[for="' + $(this).attr('id') + '"]').addClass('active');
|
$label.filter('[for="' + $(this).attr('id') + '"]').addClass('active');
|
||||||
}).filter(':has(:checked)').addClass('active');
|
}).filter(':has(:checked)').addClass('active');
|
||||||
@@ -215,21 +211,14 @@
|
|||||||
|
|
||||||
// Apply validation
|
// Apply validation
|
||||||
$('#form-contact, #form-register, #form-address').validate({
|
$('#form-contact, #form-register, #form-address').validate({
|
||||||
highlight: function(element) {
|
highlight: function (element) {
|
||||||
$(element).closest('.form-group').addClass('has-error');
|
$(element).closest('.form-group').addClass('has-error');
|
||||||
},
|
},
|
||||||
unhighlight: function(element) {
|
unhighlight: function (element) {
|
||||||
$(element).closest('.form-group').removeClass('has-error');
|
$(element).closest('.form-group').removeClass('has-error');
|
||||||
},
|
},
|
||||||
errorElement: 'span',
|
errorElement: 'span',
|
||||||
errorClass: 'help-block'/*,
|
errorClass: 'help-block'
|
||||||
errorPlacement: function(error, element) {
|
|
||||||
if(element.parent('.input-group').length || element.prop('type') === 'checkbox' || element.prop('type') === 'radio'){
|
|
||||||
error.prepend('<i class="icon-remove"></i> ').insertAfter(element.parent());
|
|
||||||
}else{
|
|
||||||
error.prepend('<i class="icon-remove"></i> ').insertAfter(element);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -253,14 +242,14 @@
|
|||||||
// Switch Quantity in product page
|
// Switch Quantity in product page
|
||||||
$("select", $(".product-options")).change(function(){
|
$("select", $(".product-options")).change(function(){
|
||||||
$select_quantity = $(this).find(":selected").attr("data-quantity");
|
$select_quantity = $(this).find(":selected").attr("data-quantity");
|
||||||
var $old_price = $(this).find(":selected").attr("data-old-price");
|
var $old_price = $(this).find(":selected").attr("data-old-price");
|
||||||
|
|
||||||
var $best_price = $(this).find(":selected").attr("data-price");
|
var $best_price = $(this).find(":selected").attr("data-price");
|
||||||
|
|
||||||
$quantityInput.attr("max", $select_quantity);
|
$quantityInput.attr("max", $select_quantity);
|
||||||
|
|
||||||
// Show Out Of Stock OR In Stock
|
// Show Out Of Stock OR In Stock
|
||||||
if($select_quantity == 0){
|
if ($select_quantity == 0) {
|
||||||
$btnAddToCart.attr("disabled", true);
|
$btnAddToCart.attr("disabled", true);
|
||||||
|
|
||||||
$productMeta.removeClass("in-stock");
|
$productMeta.removeClass("in-stock");
|
||||||
@@ -271,7 +260,7 @@
|
|||||||
$outOfStock.show();
|
$outOfStock.show();
|
||||||
$inStock.hide();
|
$inStock.hide();
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
$btnAddToCart.attr("disabled", false);
|
$btnAddToCart.attr("disabled", false);
|
||||||
|
|
||||||
$productMeta.removeClass("out-of-stock");
|
$productMeta.removeClass("out-of-stock");
|
||||||
@@ -283,38 +272,38 @@
|
|||||||
$outOfStock.hide();
|
$outOfStock.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parseInt($quantityInput.val()) > parseInt($select_quantity)){
|
if (parseInt($quantityInput.val()) > parseInt($select_quantity)) {
|
||||||
$quantityInput.val($select_quantity);
|
$quantityInput.val($select_quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($old_price_container.size() > 0 ){
|
if ($old_price_container.size() > 0) {
|
||||||
$(".price", $old_price_container).html($old_price);
|
$(".price", $old_price_container).html($old_price);
|
||||||
$(".price", $(".special-price")).html($best_price);
|
$(".price", $(".special-price")).html($best_price);
|
||||||
}else{
|
} else {
|
||||||
$(".price", $(".regular-price")).html($best_price);
|
$(".price", $(".regular-price")).html($best_price);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).change();
|
}).change();
|
||||||
|
|
||||||
$quantityInput.focusout(function() {
|
$quantityInput.focusout(function () {
|
||||||
$quantityInput.attr("max", $select_quantity);
|
$quantityInput.attr("max", $select_quantity);
|
||||||
if(parseInt($quantityInput.val()) > parseInt($select_quantity)){
|
if (parseInt($quantityInput.val()) > parseInt($select_quantity)) {
|
||||||
$quantityInput.val($select_quantity);
|
$quantityInput.val($select_quantity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".form-product").submit(function(){
|
$(".form-product").submit(function () {
|
||||||
var url_action = $(this).attr("action");
|
var url_action = $(this).attr("action");
|
||||||
var $cartContainer = $(".cart-container");
|
var $cartContainer = $(".cart-container");
|
||||||
|
|
||||||
$.ajax({type:"POST", data: $(this).serialize(), url:url_action,
|
$.ajax({type: "POST", data: $(this).serialize(), url: url_action,
|
||||||
success: function(data){
|
success: function(data){
|
||||||
|
|
||||||
$cartContainer.html($(data).html());
|
$cartContainer.html($(data).html());
|
||||||
|
|
||||||
$.ajax({url:"ajax/addCartMessage",
|
$.ajax({url:"ajax/addCartMessage",
|
||||||
success: function(data){
|
success: function (data) {
|
||||||
bootbox.dialog({
|
bootbox.dialog({
|
||||||
message : data,
|
message : data,
|
||||||
buttons : {}
|
buttons : {}
|
||||||
@@ -322,7 +311,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error: function(){
|
error: function () {
|
||||||
console.log('Error.');
|
console.log('Error.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -330,11 +319,11 @@
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#limit-top').change(function(e){
|
$('#limit-top').change(function (e) {
|
||||||
window.location = $(this).val()
|
window.location = $(this).val()
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#sortby-top').change(function(e){
|
$('#sortby-top').change(function (e) {
|
||||||
window.location = $(this).val()
|
window.location = $(this).val()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user