Created
November 14, 2012 19:51
-
-
Save pedrozath/4074332 to your computer and use it in GitHub Desktop.
mconnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var connect = window.connect = new function(){ | |
this.block = false; | |
this.init = function(){ | |
window.setInterval(connect.animateArrow, 300); | |
$("#openhaus_connect .title, .open-connect").click(connect.open); | |
$("#openhaus_connect .title a, .btn-frame").click(connect.tab); | |
$("#black_bg_transparent").click(connect.hide); | |
$("#frame-form").submit(connect.sendForm); | |
}, | |
this.isOpen = function(){ | |
var display = $("#black_bg_transparent").css("display"); | |
if( display != "none" ){ | |
return true; | |
} else { | |
return false; | |
} | |
}, | |
this.open = function(){ | |
if( !connect.isOpen() ){ | |
if( $(this).hasClass("title") ){ | |
$(".frame").hide(); | |
$(".content-contato").show(); | |
} | |
var box = $("#openhaus_connect"); | |
box.find(".title .first").addClass('selecionado'); | |
$("#black_bg_transparent").show().animate({ opacity: 0.5 }, 'slow'); | |
var content = box.find(".content"); | |
var height = content.show().outerHeight(); | |
content.height(0); | |
box.animate({ width : 340 }, 'slow'); | |
content.animate({ height: height }, 500); | |
} else { | |
connect.hide(); | |
} | |
return false; | |
}, | |
this.change = function(frame){ | |
if( frame == 'contato' && !connect.isOpen() ){ | |
$(".frame").hide(); | |
$(".content-contato").show(); | |
connect.open(); | |
} else if( frame == 'telefone' && !connect.isOpen() ){ | |
$(".frame").hide(); | |
$(".content-telefone").show(); | |
connect.open(); | |
} else if( frame == 'contato' && connect.isOpen() ){ | |
$(".frame").hide(); | |
$("#openhaus_connect .content").css("height","auto"); | |
$(".content-contato").show(); | |
} else if( frame == 'telefone' && connect.isOpen() ){ | |
$(".frame").hide(); | |
$("#openhaus_connect .content").css("height","auto"); | |
$(".content-telefone").show(); | |
} else if( frame == 'form' ){ | |
$(".frame").hide(); | |
$("#openhaus_connect .content").css("height","auto"); | |
$(".content-form").show(); | |
} | |
}, | |
this.tab = function(e){ | |
e.stopPropagation(); | |
var frame = $(this).data("frame"); | |
connect.change(frame); | |
$(".selecionado").removeClass("selecionado"); | |
$(this).addClass("selecionado"); | |
return false; | |
}, | |
this.hide = function(){ | |
$(".selecionado").removeClass("selecionado"); | |
$("#black_bg_transparent").animate({ opacity: 0 }, 'slow', function(){ | |
$(this).hide(); | |
}); | |
var box = $("#openhaus_connect"); | |
var content = box.find(".content"); | |
box.animate({ width : 280 }, 'slow').data('show', false); | |
content.animate({ height: 0 }, 500, function(){ | |
$(this).css('height','auto').hide(); | |
}); | |
}, | |
this.animateArrow = function(){ | |
var img = $(".notice img"); | |
var ltr = img.data("ltr"); | |
if( ltr == 'right' || ltr == undefined ){ | |
img.animate({ 'margin-right' : '0' }, 300); | |
img.data("ltr", "left"); | |
} else { | |
img.animate({ 'margin-right' : '15px' }, 300); | |
img.data("ltr", "right"); | |
} | |
}, | |
this.sendForm = function(){ | |
var form = $(this); | |
var erro = false; | |
$(".erro-atendimento").remove(); | |
form.find("input, select, textarea").each(function(){ | |
var val = $(this).val(); | |
if( val == "" ){ | |
erro = true; | |
$(this).parent().append("<div style='display:block' class='erro-atendimento'><span style='color:red;font:11px tahoma;margin:5px;'>Preencha o campo corretamente.</span></div>"); | |
} | |
}); | |
if( !erro ){ | |
form.find("button").hide(); | |
form.find(".ajax-load-form-connect").show(); | |
form.ajaxSubmit({ | |
beforeSubmit: function(){ | |
form.find("textarea, input, select").attr('disabled',true); | |
}, | |
type : 'POST', | |
success: function(callback){ | |
form.find("textarea, input, select").attr('disabled',false); | |
form.find("button").show(); | |
form.find(".ajax-load-form-connect").hide(); | |
form.resetForm(); | |
alert('Mensagem enviada com sucesso.'); | |
} | |
}); | |
} | |
return false; | |
}; | |
} | |
$(document).ready(connect.init); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment