I think there is more that is needed here. Can someone please comment on it?
What I need is to add some common functions to check if an element exists.
// Common functions
$(document).ready(function() {
/*
Function for creating different styling checkbox, radio input, and select
*/
// Create pretty checkboxes and inputs
if ($('.iCheck').length){
$('.iCheck').iCheck({
checkboxClass: 'icheckbox_minimal-blue',
radioClass: 'iradio_minimal-blue',
increaseArea: '20%' // optional
});
}
// Create pretty selects and multiselect
if(!$("html").hasClass("ie8")){
if ($('select').length){
$('select').attr('data-width', '100%').selectpicker();
}
};
/*
Preloader
*/
var targetPreloader = $('[data-overlay-text]');
targetPreloader.click(function() {
var text = $(this).attr("data-overlay-text");
$('.preloader-text').text(text);
$('.preloader-window').show().fadeIn();
});
/*
Fix for showing SVG
*/
svgeezy.init('nothing', 'png');
/*
Form validation using Jquery validate
*/
$('form').validate({
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
});
if ($('select')) { }
and ummif ($('.iCheck').hasOwnProperty('iCheck') { }
\$\endgroup\$