236 lines
5.5 KiB
JavaScript
236 lines
5.5 KiB
JavaScript
$(document).ready
|
|
(
|
|
function()
|
|
{
|
|
//Add picture
|
|
if(typeof a != 'undefined')
|
|
{
|
|
var $Pic = $('#pic');
|
|
$Pic.css('height', iPicHeight+'px');
|
|
$('.person').css('marginTop', Math.round(($('#header').height() - $Pic.outerHeight())/2));
|
|
$Pic.attr('src', cConfigPage+'?a=pic&s='+s);
|
|
}
|
|
|
|
//Fix IE
|
|
if(typeof bIsIE != 'undefined')
|
|
{
|
|
//IE6 PNG Support
|
|
DD_belatedPNG.fix('.paperclip');
|
|
}
|
|
|
|
//Font modification
|
|
Cufon.now();
|
|
|
|
//Title captions
|
|
$(function() {$('.tip_link').tipsy({gravity: 's'});});
|
|
$(function() {$('.tip_card').tipsy({gravity: 'e'});});
|
|
|
|
//Replace text with Cufons
|
|
Cufon.replace('h1', {fontFamily:'Candara'});
|
|
Cufon.replace('.item h2', {fontFamily:'Puritan 2.0'});
|
|
Cufon.replace('.item h3', {fontFamily:'Puritan 2.0'});
|
|
Cufon.replace('h2.section_name', {fontFamily:'Andika Basic'});
|
|
|
|
//Contact panel events
|
|
$('#contact_me_btn, #contact_me_link').click
|
|
(
|
|
function(e)
|
|
{
|
|
e.preventDefault();
|
|
$('#contact_me_box').slideToggle('slow');
|
|
}
|
|
);
|
|
$('#contact_me_close').click(function(){$('#contact_me_btn').trigger('click');});
|
|
|
|
//Sending contact form
|
|
$("#contact_form").submit
|
|
(
|
|
function()
|
|
{
|
|
$This = $(this);
|
|
var bValid = true;
|
|
$This.find('input[type=text], textarea').each
|
|
(
|
|
function(iId, oItem)
|
|
{
|
|
var $Item = $(oItem);
|
|
sName = $Item.attr('name');
|
|
if(typeof sName != 'undefined' && sName != '')
|
|
{
|
|
var sVal = $Item.val();
|
|
if(sVal=='' || sVal==sName.getDefVal())
|
|
{
|
|
bValid = false;
|
|
}
|
|
}
|
|
}
|
|
);
|
|
if(!bValid)
|
|
{
|
|
addAutoDestroyMsg('#formstatus', 'Some fields are still empty.', 'warning');
|
|
}
|
|
else
|
|
{
|
|
addAutoDestroyMsg('#formstatus', 'Sending...', 'loading', -1);
|
|
ajax('POST', 'mail', $This, function(sMsg)
|
|
{
|
|
console.log('msg='+sMsg);
|
|
var result = '';
|
|
if(sMsg == 'ok')
|
|
{
|
|
addAutoDestroyMsg('#formstatus', 'Your message has been sent. Thank you!', 'success', -1);
|
|
$("#contact_fields, #contact_me_close").fadeOut('fast');
|
|
setTimeout("$('#contact_me_btn').trigger('click');", 3000);
|
|
}
|
|
else
|
|
{
|
|
addAutoDestroyMsg('#formstatus', sMsg, 'error');
|
|
}
|
|
});
|
|
/*var str = $This.serialize();
|
|
$.ajax
|
|
(
|
|
{
|
|
type: "POST",
|
|
url: "includes/send.php",
|
|
data: str,
|
|
success: function(sMsg)
|
|
{
|
|
var result = '';
|
|
if(sMsg == 'ok')
|
|
{
|
|
addAutoDestroyMsg('#formstatus', 'Your message has been sent. Thank you!', 'success', -1);
|
|
$("#contact_fields, #contact_me_close").fadeOut('fast');
|
|
setTimeout("$('#contact_me_btn').trigger('click');", 3000);
|
|
}
|
|
else
|
|
{
|
|
addAutoDestroyMsg('#formstatus', sMsg, 'error');
|
|
}
|
|
}
|
|
}
|
|
);*/
|
|
}
|
|
return false;
|
|
}
|
|
);
|
|
|
|
//Default Form Values
|
|
$('#contact_form input, #contact_form textarea').each
|
|
(
|
|
function()
|
|
{
|
|
var $This = $(this);
|
|
var sName = $This.attr('name');
|
|
if(sName!=undefined && sName!='')
|
|
{
|
|
$This.focus(function(){if($This.val()==sName.getDefVal())$This.val('');});
|
|
$This.blur(function(){if($This.val()=='')$This.val(sName.getDefVal());});
|
|
}
|
|
}
|
|
);
|
|
|
|
//Print
|
|
$('#print').click
|
|
(
|
|
function(e)
|
|
{
|
|
e.preventDefault();
|
|
$('#mail').text('at '+$(location).attr('href').substr(5).replace(/\//g, '').replace('.', '@')+' ');
|
|
window.print();
|
|
$('#mail').text('');
|
|
}
|
|
);
|
|
|
|
//Internal links
|
|
$('a[href^=#]').click(function(e){$(this).jump(e);});
|
|
|
|
//To-the-top Button
|
|
iProfileHeight = $('#presentation').offset().top;
|
|
$(window).scroll
|
|
(
|
|
function()
|
|
{
|
|
$ToTop = $("#to_top");
|
|
if($(this).scrollTop() > iProfileHeight)
|
|
{
|
|
$ToTop.fadeIn('slow');
|
|
}
|
|
else
|
|
{
|
|
$ToTop.fadeOut('slow');
|
|
}
|
|
}
|
|
);
|
|
}
|
|
);
|
|
|
|
//HTTP request
|
|
function ajax(sRequestType, sActionType, sData, fSuccess)
|
|
{
|
|
console.log(sData);
|
|
if(!sData) sData = {};
|
|
sData['t'] = sActionType;
|
|
console.log(sData);
|
|
if(sRequestType == 'POST')
|
|
{
|
|
sData = sData.serialize();
|
|
sData += (sData.length==0?'':'&')+'t='+sActionType;
|
|
}
|
|
else sData['t'] = sActionType;
|
|
console.log(sData);
|
|
$.ajax
|
|
(
|
|
{
|
|
type: sRequestType,
|
|
url: cConfigPage,
|
|
data: sData,
|
|
success: fSuccess,
|
|
dataType: 'text'
|
|
}
|
|
);
|
|
}
|
|
|
|
//Get form default value
|
|
String.prototype.getDefVal = function()
|
|
{
|
|
return this.charAt(0).toUpperCase() + this.slice(1) + '*';
|
|
};
|
|
|
|
//Scroll to an element
|
|
$.prototype.jump = function(e)
|
|
{
|
|
var sElem = this.attr('href');
|
|
if(sElem != '#')
|
|
{
|
|
if($(this).parent().parent().attr('id')!='menu') e.preventDefault();
|
|
else sElem += '_ln';
|
|
|
|
this.blur();
|
|
var $Elem = $(sElem);
|
|
var iOffSet = ($Elem.length>0)?($Elem.offset().top - 15):0;
|
|
$('html, body').animate({scrollTop:iOffSet}, 'slow');
|
|
}
|
|
}
|
|
|
|
//Add a temporary message
|
|
function addAutoDestroyMsg(sContainerId, sMsg, sClass, iTime)
|
|
{
|
|
if(!iTime) iTime = 5000;
|
|
sClass = (!sClass)?'':' '+sClass;
|
|
|
|
//Clear container and add message
|
|
$Container = $(sContainerId);
|
|
$Container.stop(true, false).empty();
|
|
$('<div class="message'+sClass+'">'+sMsg+'</div>').hide().appendTo($Container).slideDown('fast');
|
|
|
|
//Reset schedduler
|
|
if(typeof oTimer != 'undefined')
|
|
{
|
|
clearTimeout(oTimer);
|
|
}
|
|
if(iTime > 0)
|
|
{
|
|
oTimer = setTimeout("$('"+sContainerId+"').find('.message').slideUp(function(){$(this).remove();});", iTime);
|
|
}
|
|
} |