science-ation/sfiab.js

106 lines
2.1 KiB
JavaScript
Raw Normal View History

//useful function that we'll be using throughout
function confirmClick(msg)
{
var okay=confirm(msg);
if(okay)
return true;
else
return false;
}
function el(str,domain,name)
{
document.write('<a href="ma'+'il'+'to:' + str + '@' + domain + '">' + name + '</a>');
}
function em(str,domain)
{
document.write('<a href="ma'+'il'+'to:' + str + '@' + domain + '">' + str + '@' + domain + '</a>');
}
var anyFieldHasBeenChanged=false;
function fieldChanged()
{
anyFieldHasBeenChanged=true;
}
function confirmChanges()
{
if(anyFieldHasBeenChanged)
{
var okay=confirm('<?=i18n("You have unsaved changes. Click \"Cancel\" to return so you can save your changes, or press \"OK\" to discard your changes and continue")?>');
if(okay)
return true;
else
return false;
}
else
return true;
}
/* Popups using jQuery */
var popup_current = null;
function popup_open(name)
{
if(popup_current == null) {
var w = document.documentElement.clientWidth;
var h = document.documentElement.clientHeight;
var ph = $("#popup_"+name).height();
var pw = $("#popup_"+name).width();
/* Center the popup */
$("#popup_"+name).css({
"position": "absolute",
"top": (h - ph)/2,
"left": (w - pw)/2
});
/* IE6 hack */
$("#popup_"+name+"_background").css({
"height": h
});
/* Display the popup */
$("#popup_"+name+"_background").css({
"opacity": "0.7"
});
$("#popup_"+name+"_background").fadeIn("fast");
$("#popup_"+name).fadeIn("fast");
popup_current = name;
}
}
function popup_close()
{
//disables popup only if it is enabled
if(popup_current != null){
$("#popup_"+popup_current+"_background").fadeOut("fast");
$("#popup_"+popup_current).fadeOut("fast");
popup_current = null;
}
}
/* Hook ESC to cancel a popup */
$(document).keypress(function(e)
{
if(e.keyCode==27 && popup_current != null) {
popup_close();
}
});
/* Stuff to do after the document loads */
$(document).ready(function()
{
/* Hook close buttons on all popups (which may not be defined
* until the HTML is finished parsing, so we have to do it
* in the document.ready function ) */
$(".popup_close").click(function()
{
popup_close();
});
});