File: /web/data/www.tbbprovision.com/static/js/site.js
/**
* author : liaoyaping
* createTime : 2017/3/10 17:39
* description : 全局函数
*/
var global = {
onblur:function(obj){
if(obj.value == ''){
obj.value = obj.defaultValue;
}
},
onfocus:function(obj){
if(obj.value == obj.defaultValue){
obj.value = '';
}
},
index:function(){
global.banner_slide();
},
banner_slide:function(){
var offset_left = 0;
setTimeout(function(){
$('.carousel .slides').height($('.slide.actived').innerHeight());
offset_left = $('html').width() ;
offset_left = offset_left<940?940:offset_left;
$('.slide').each(function(){
$(this).css({'position':"absolute"});
if(!$(this).hasClass('actived')){
$(this).css({'left':offset_left});
}
});
},1000);
$(window).resize(function(){
$('.carousel .slides').height($('.slide.actived').innerHeight());
offset_left = $('html').width();
offset_left = offset_left<940?940:offset_left;
$('.slide').each(function(){
$(this).css({'position':"absolute"});
if(!$(this).hasClass('actived')){
$(this).css({'left':offset_left});
}
})
});
var index = 0;
var next_index = 1;
var length = $('.slide').length; // 3
var timer ;
timer = setInterval(function(){
if(index<(length-1)){
next_index = index+1;
}else if(index == (length - 1)){
next_index = 0 ;
}else{
next_index = length - 1;
index = 0;
}
console.log('index:'+index + "; next_index:"+next_index);
$('.slide').eq(index).stop(true,false).animate({'left':"-"+offset_left},500,function(){
$(this).removeClass('actived').css('left',offset_left);
});
$('.slide').eq(next_index).stop(true,false).animate({'left':"0px"},500,function(){
$(this).addClass('actived');
});
if(index==length-1){
index=0;
}else{
index+=1;
}
},5000);
$('.carousel .controls a').click(function(){
//left
if($(this).hasClass('previous')){
clearInterval(timer);
if(index == 0){
next_index = length - 1;
}else{
next_index = index - 1;
}
$('.slide').eq(index).stop(true,false).animate({'left':offset_left},500,function(){
$(this).removeClass('actived').css('left',offset_left);
});
$('.slide').eq(next_index).css('left',"-"+offset_left).stop(true,false).animate({'left':"0px"},500,function(){
$(this).addClass('actived');
});
index = next_index;
timer = setInterval(function(){
if(index<(length-1)){
next_index = index+1;
}else if(index == (length - 1)){
next_index = 0 ;
}else{
next_index = length - 1;
index = 0;
}
$('.slide').eq(index).stop(true,false).animate({'left':"-"+offset_left},500,function(){
$(this).removeClass('actived').css('left',offset_left);
});
$('.slide').eq(next_index).stop(true,false).animate({'left':"0px"},500,function(){
$(this).addClass('actived');
});
if(index==length-1){
index=0;
}else{
index+=1;
}
},5000);
}else{
//right
clearInterval(timer);
if(index<(length-1)){
next_index = index+1;
}else if(index == (length - 1)){
next_index = 0 ;
}else{
next_index = length - 1;
index = 0;
}
console.log('index:'+index + "; next_index:"+next_index);
$('.slide').eq(index).stop(true,false).animate({'left':"-"+offset_left},500,function(){
$(this).removeClass('actived').css('left',offset_left);
});
$('.slide').eq(next_index).stop(true,false).animate({'left':"0px"},500,function(){
$(this).addClass('actived');
});
if(index==length-1){
index=0;
}else{
index+=1;
}
timer = setInterval(function(){
if(index<(length-1)){
next_index = index+1;
}else if(index == (length - 1)){
next_index = 0 ;
}else{
next_index = length - 1;
index = 0;
}
console.log('index:'+index + "; next_index:"+next_index);
$('.slide').eq(index).stop(true,false).animate({'left':"-"+offset_left},500,function(){
$(this).removeClass('actived').css('left',offset_left);
});
$('.slide').eq(next_index).stop(true,false).animate({'left':"0px"},500,function(){
$(this).addClass('actived');
});
if(index==length-1){
index=0;
}else{
index+=1;
}
},5000);
}
});
},
pro_detail:function(){
$('.small-box a').mouseover(function(){
var that = $(this);
that.parent('dd').siblings('dt').children('img').attr('src',that.children('img').attr('src'));
});
$('.pro-detail-contents.tabs-tool li').click(function(){
var that = $(this);
that.addClass('cur').siblings('li').removeClass('cur');
that.parent('ul').siblings('.pro-contents').hide();
$(that.attr('data-toggle')).removeClass('hide').show();
});
$.ajax({
method:'get',
url: '/products/update_views/'+$('input[name=proid]').val()+'/'+$('input[name=old_views]').val(),
timeout: 5000
});
},
loading: function(destory){
if(destory != 'destory') {
$('body').find('.loading-customer').remove();
var html = '<div class="loading-customer" style="width:100%;height:100%;position:fixed;z-index:10000;background:rgba(0,0,0,.5)"><div style="width:100%;height:100%;background:url(/static/img/loading-1.gif) center center no-repeat;"></div> ';
html += '</div>';
$('body').prepend(html);
}else{
$('body').find('.loading-customer').remove();
}
},
errorMessage:function(str){
if(typeof str == 'undefined' || str == ''){
return "Please Try Again";
}else{
return str;
}
},
newsletter_header: function(){
$('#newsletter').validate({
onfocusout: false,
onkeyup : false,
showErrors: function(errorMap,errorList){
var errorHtml = '';
for(var i=0; i < errorList.length;i++){
errorHtml += errorList[i]['message']+"\r\n";
}
if(errorHtml != '') {
swal({
title: "",
text: errorHtml,
type: 'warning'
});
}
},
submitHandler:function(){
var $form = $('#newsletter');
$.ajax({
url: $form.attr('action'),
method: 'post',
data: $form.serialize(),
timeout:5000,
dataType: 'json',
beforeSend:function(){
global.loading();
},
success:function(xhrData){
swal("Success", xhrData.response_content, "success");
},
error:function(xhrData){
global.loading('destory');
swal({
title: '',
text: global.errorMessage(xhrData.responseText),
type: 'info'
});
},
complete:function(xhrData){
global.loading('destory');
}
});
}
});
},
newsletter: function(){
$('#footer-newsletter').validate({
onfocusout: false,
onkeyup : false,
showErrors: function(errorMap,errorList){
var errorHtml = '';
for(var i=0; i < errorList.length;i++){
errorHtml += errorList[i]['message']+"\r\n";
}
if(errorHtml != '') {
swal({
title: "",
text: errorHtml,
type: 'warning'
});
}
},
submitHandler:function(){
var $form = $('#footer-newsletter');
$.ajax({
url: $form.attr('action'),
method: 'post',
data: $form.serialize(),
timeout:5000,
dataType: 'json',
beforeSend:function(){
global.loading();
},
success:function(xhrData){
swal("Success", xhrData.response_content, "success");
},
error:function(xhrData){
global.loading('destory');
swal({
title: '',
text: global.errorMessage(xhrData.responseText),
type: 'info'
});
},
complete:function(xhrData){
global.loading('destory');
}
});
}
});
},
purchase: function(){
$('#recharge-form').validate({
messages:{
'message':'Query information cannot be empty',
'email' : { required: 'Email is required. ' },
'name' : { required: 'Name is required. ' }
},
onfocusout: false,
onkeyup : false,
showErrors: function(errorMap,errorList){
var errorHtml = '';
for(var i=0; i < errorList.length;i++){
errorHtml += errorList[i]['message']+"\r\n";
}
if(errorHtml != '') {
swal({
title: "",
text: errorHtml,
type: 'warning'
});
}
},
submitHandler:function(){
$.ajax({
url: '/ajax/purchase/',
timeout: 10000,
method: "post",
data: $('#recharge-form').serialize(),
dataType: 'json',
beforeSend:function(){
console.log('fdsafads');
global.loading();
},
error:function(xhrData){
swal({
title: "",
text: global.errorMessage(xhrData.responseText),
type: 'warning'
});
global.loading('destory');
},
success:function(xhrData){
$('#recharge-form')[0].reset();
global.loading('destory');
swal({
title: "",
text: global.errorMessage(xhrData.response_content),
type: 'success'
});
}
});
return false;
}
});
},
support: function(){
$('li h2').click(function(){
var $this = $(this);
var li = $this.parent('li');
if(li.hasClass('active')){
return false;
}
li.siblings('li.active').children('div').slideUp();
li.addClass('active').siblings('li').removeClass('active');
li.children('div').slideDown();
});
$('#support-form').validate({
messages:{
'message':'Query information cannot be empty',
'email' : { required: 'Email is required. ' }
},
onfocusout: false,
onkeyup : false,
showErrors: function(errorMap,errorList){
var errorHtml = '';
for(var i=0; i < errorList.length;i++){
errorHtml += (i+1) + " : " +errorList[i]['message']+"\r\n";
}
if(errorHtml != '') {
swal({
title: "",
text: errorHtml,
type: 'warning'
});
}
},
submitHandler:function(){
$.ajax({
url: '/ajax/support/',
timeout: 10000,
method: "post",
data: $('#support-form').serialize(),
dataType: 'json',
beforeSend:function(){
console.log('fdsafads');
global.loading();
},
error:function(xhrData){
swal({
title: "",
text: global.errorMessage(xhrData.responseText),
type: 'warning'
});
global.loading('destory');
},
success:function(xhrData){
$('#support-form')[0].reset();
global.loading('destory');
swal({
title: "",
text: global.errorMessage(xhrData.response_content),
type: 'success'
});
}
});
return false;
}
});
},
click_statis: function(){
$('.click_statis').click(function(){
$.post('/ajax/click_statis/','click_type='+$(this).attr('data-id'));
});
},
fixed_purchase: function(){
$('.fixed-purchase-title').click(function(){
var $this = $(this);
var $toggle = $this.attr('toggle');
if($toggle=='open'){
$('.fixed-purchase').removeClass('close').addClass('open');
}else if($toggle=='close'){
$('.fixed-purchase').removeClass('open').addClass('close');
}
});
$('#fixed-recharge-form').validate({
messages:{
'message':'Query information cannot be empty',
'email' : {
required: 'Email is required. '
}
},
onfocusout: false,
onkeyup : false,
showErrors: function(errorMap,errorList){
var errorHtml = '';
for(var i=0; i < errorList.length;i++){
errorHtml += errorList[i]['message']+"\r\n";
}
if(errorHtml != '') {
swal({
title: "",
text: errorHtml,
type: 'warning'
});
}
}
});
},
fixed_form_chat: function(){
$('.fixed-purchase-title').click(function(){
$('.fixed-form').attr('id','open');
});
$('.fixed-form .title').click(function(){
$('.fixed-form').attr('id',$(this).attr('data-toggle'));
});
$('#fixed-purchase-form').validate({
messages:{
'message':'Query information cannot be empty',
'name' : { required: 'Name is required. ' },
'email' : { required: 'Email is required. ' }
},
onfocusout: false,
onkeyup : false,
showErrors: function(errorMap,errorList){
var errorHtml = '';
for(var i=0; i < errorList.length;i++){
errorHtml += (i+1) + " : " +errorList[i]['message']+"\r\n";
}
if(errorHtml != '') {
swal({
title: "",
text: errorHtml,
type: 'warning'
});
}
},
submitHandler:function(){
$.ajax({
url: '/ajax/purchase/',
timeout: 10000,
method: "post",
data: $('#fixed-purchase-form').serialize(),
dataType: 'json',
beforeSend:function(){
console.log('fdsafads');
global.loading();
},
error:function(xhrData){
swal({
title: "",
text: global.errorMessage(xhrData.responseText),
type: 'warning'
});
global.loading('destory');
},
success:function(xhrData){
$('#fixed-purchase-form')[0].reset();
global.loading('destory');
swal({
title: "",
text: global.errorMessage(xhrData.response_content),
type: 'success'
});
}
});
return false;
}
});
},
contact_us: function(){
$('#contact-form').validate({
messages:{
'message':'Query information cannot be empty',
'name' : {
required: 'Name is required. '
}
},
onfocusout: false,
onkeyup : false,
showErrors: function(errorMap,errorList){
var errorHtml = '';
for(var i=0; i < errorList.length;i++){
errorHtml += (i+1) + " : " +errorList[i]['message']+"\r\n";
}
if(errorHtml != '') {
swal({
title: "",
text: errorHtml,
type: 'warning'
});
}
},
submitHandler:function(){
$.ajax({
url: '/ajax/contact_us/',
timeout: 10000,
method: "post",
data: $('#contact-form').serialize(),
dataType: 'json',
beforeSend:function(){
console.log('fdsafads');
global.loading();
},
error:function(xhrData){
swal({
title: "",
text: global.errorMessage(xhrData.responseText),
type: 'warning'
});
global.loading('destory');
},
success:function(xhrData){
$('#contact-form')[0].reset();
global.loading('destory');
swal({
title: "",
text: global.errorMessage(xhrData.response_content),
type: 'success'
});
}
});
return false;
}
});
}
};