// Common javascript functions
//
// webtrees: Web based Family History software
// Copyright (C) 2014 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// Specifications for various types of popup edit window.
// Choose positions to center in the smallest (1000x800) target screen
var edit_window_specs='width=650,height=600,left=175,top=100,resizable=1,scrollbars=1'; // edit_interface.php, add_media.php, gedrecord.php
var indx_window_specs='width=600,height=500,left=200,top=150,resizable=1,scrollbars=1'; // index_edit.php, module configuration
var news_window_specs='width=740,height=650,left=200,top=150,resizable=1,scrollbars=1'; // edit_news.php
var help_window_specs='width=500,height=400,left=250,top=200,resizable=1,scrollbars=1'; // help.php
var find_window_specs='width=550,height=600,left=250,top=150,resizable=1,scrollbars=1'; // find.php, inverse_link.php
var mesg_window_specs='width=500,height=600,left=250,top=100,resizable=1,scrollbars=1'; // message.php
var chan_window_specs='width=500,height=600,left=250,top=100,resizable=1,scrollbars=1'; // edit_changes.php
var mord_window_specs='width=500,height=600,left=250,top=100,resizable=1,scrollbars=1'; // edit_interface.php, media reorder
var assist_window_specs='width=900,height=800,left=70,top=70,resizable=1,scrollbars=1'; // edit_interface.php, used for census assistant
var gmap_window_specs='width=650,height=600,left=200,top=150,resizable=1,scrollbars=1'; // googlemap module place editing
var fam_nav_specs='width=300,height=600,left=817,top=150,resizable=1,scrollbars=1'; // media_0_inverselink.php
// TODO: This function loads help_text.php twice. It should only load it once.
function helpDialog(which, mod) {
var url='help_text.php?help='+which+'&mod='+mod;
dialog=jQuery('
')
.load(url+' .helpcontent')
.dialog({
modal: true,
width: 500,
closeText: ""
});
jQuery(".ui-widget-overlay").on("click", function () {
jQuery("div:ui-dialog:visible").dialog("close");
});
jQuery('.ui-dialog-title').load(url+' .helpheader');
return false;
}
// Create a modal dialog, fetching the contents from a URL
function modalDialog(url, title) {
jQuery(document).ajaxComplete(function() {
jQuery('.ui-dialog').before('');
});
dialog=jQuery('')
.load(url)
.dialog({
modal: false,
width: 700,
closeText: "",
close: function(event, ui) {
jQuery(this).remove();
jQuery('.ui-widget-overlay').remove();
}
});
// Close the window when we click outside it.
jQuery(".ui-widget-overlay").on("click", function () {
jQuery("div:ui-dialog:visible").dialog("close");
jQuery(this).remove();
});
return false;
}
// Create a modal dialog to display notes
function modalNotes(content, title) {
dialog=jQuery('')
.html(content)
.dialog({
modal: true,
width: 500,
closeText: "",
close: function(event, ui) { jQuery(this).remove(); }
});
// Close the window when we click outside it.
jQuery(".ui-widget-overlay").on("click", function () {
jQuery("div:ui-dialog:visible").dialog("close");
});
return false;
}
// For a dialog containing a form, submit the form via AJAX
// (to save the data), then reload the page (to display it).
function modalDialogSubmitAjax(form) {
jQuery.ajax({
type: 'POST',
url: jQuery(form).attr('action'),
data: jQuery(form).serialize(),
success: function(response) { window.location.reload(); }
});
return false;
}
function closePopupAndReloadParent(url) {
if (parent.opener) {
if (!url) {
parent.opener.location.reload();
} else {
parent.opener.location=url;
}
}
window.close();
}
// variables to hold mouse x-y pos.s
var msX = 0;
var msY = 0;
// the following javascript function is for the positioning and hide/show of
// DIV layers used in the display of the pedigree chart.
function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-3); i+=4) {
if ((obj=document.getElementById(args[i])) !== null) {
if (obj.style) {
div=obj; // unused?
obj=obj.style;
}
v=args[i+2];
if (v=='toggle') {
if (obj.visibility.indexOf('hid')!=-1) {
v='show';
} else {
v='hide';
}
}
v=(v=='show')?'visible':(v=='hide')?'hidden':v;
obj.visibility=v;
if (args[i+1]=='followmouse') {
var pobj = document.getElementById(args[i+3]);
if (pobj !== null) {
if (pobj.style.top!="auto" && args[i+3]!="relatives") {
obj.top=5+msY-parseInt(pobj.style.top)+'px';
if (textDirection=="ltr") obj.left=5+msX-parseInt(pobj.style.left)+'px';
if (textDirection=="rtl") obj.right=5+msX-parseInt(pobj.style.right)+'px';
} else {
obj.top="auto";
var pagewidth = document.documentElement.offsetWidth+document.documentElement.scrollLeft;
if (textDirection=="rtl") pagewidth -= document.documentElement.scrollLeft;
if (msX > pagewidth-160) msX = msX-150-pobj.offsetLeft;
var contentdiv = document.getElementById("content");
msX = msX - contentdiv.offsetLeft;
if (textDirection=="ltr") obj.left=(5+msX)+'px';
obj.zIndex=1000;
}
} else {
var Xadjust;
if (WT_SCRIPT_NAME.indexOf("fanchart")>0) {
obj.top=(msY-20)+'px';
obj.left=(msX-20)+'px';
} else if (WT_SCRIPT_NAME.indexOf("index.php")==-1) {
Xadjust = document.getElementById('content').offsetLeft;
obj.left=(5+(msX-Xadjust))+'px';
obj.top="auto";
} else {
Xadjust = document.getElementById('content').offsetLeft;
obj.top=(msY-50)+'px';
obj.left=(10+(msX-Xadjust))+'px';
}
obj.zIndex=1000;
}
}
}
}
}
var show = false;
function togglechildrenbox(pid) {
if (!pid) pid='';
else pid = '.'+pid;
if (show) {
MM_showHideLayers('childbox'+pid, ' ', 'hide',' ');
show=false;
} else {
MM_showHideLayers('childbox'+pid, ' ', 'show', ' ');
show=true;
}
return false;
}
var lastfamilybox = "";
var popupopen = 0;
function show_family_box(boxid, pboxid) {
popupopen = 1;
lastfamilybox=boxid;
if (pboxid=='relatives') MM_showHideLayers('I'+boxid+'links', 'followmouse', 'show',''+pboxid);
else {
famlinks = document.getElementById("I"+boxid+"links");
divbox = document.getElementById("out-"+boxid);
parentbox = document.getElementById("box"+boxid);
if (famlinks && divbox && parentbox) {
famlinks.style.top = "0px";
if (textDirection=="ltr") famleft = parseInt(divbox.style.width)+15;
else famleft = 0;
if (isNaN(famleft)) {
famleft = 0;
famlinks.style.top = parentbox.offsetTop+"px";
}
pagewidth = document.documentElement.offsetWidth+document.documentElement.scrollLeft;
if (textDirection=="rtl") pagewidth -= document.documentElement.scrollLeft;
if (famleft+parseInt(parentbox.style.left) > pagewidth-100) famleft=25;
famlinks.style.left = famleft + "px";
if (WT_SCRIPT_NAME.indexOf("index.php")!=-1) famlinks.style.left = "100%";
MM_showHideLayers('I'+boxid+'links', ' ', 'show',''+pboxid);
return;
}
MM_showHideLayers('I'+boxid+'links', 'followmouse', 'show',''+pboxid);
}
}
function hide_family_box(boxid) {
MM_showHideLayers('I'+boxid+'links', '', 'hide','');
popupopen = 0;
lastfamilybox="";
}
var timeouts = [];
function family_box_timeout(boxid) {
timeouts[boxid] = setTimeout("hide_family_box('"+boxid+"')", 2500);
}
function clear_family_box_timeout(boxid) {
clearTimeout(timeouts[boxid]);
}
function expand_layer(sid) {
if (jQuery("#"+sid+"_img").hasClass("icon-plus")) {
jQuery('#'+sid+"_img").removeClass("icon-plus").addClass("icon-minus");
jQuery('#'+sid).slideDown("fast");
} else {
jQuery('#'+sid+"_img").removeClass("icon-minus").addClass("icon-plus");
jQuery('#'+sid).slideUp("fast");
}
return false;
}
// Open the "edit interface" popup window
function edit_interface(params, windowspecs, pastefield) {
var features = windowspecs || edit_window_specs;
var url = 'edit_interface.php?' + jQuery.param(params) + '&ged=' + WT_GEDCOM;
window.open(url, '_blank', features);
return false;
}
function edit_record(xref, fact_id) {
return edit_interface({
"action": "edit",
"xref": xref,
"fact_id": fact_id
});
}
function add_fact(xref, fact) {
return edit_interface({
"action": "add",
"xref": xref,
"fact": fact
});
}
function edit_raw(xref) {
return edit_interface({
"action": "editraw",
"xref": xref
});
}
function edit_note(xref) {
return edit_interface({
"action": "editnote",
"xref": xref
});
}
function add_record(xref, fact_field) {
var fact = jQuery('#' + fact_field).val();
if (fact) {
if (fact == "OBJE") {
window.open('addmedia.php?action=showmediaform&linkid=' + encodeURIComponent(xref) + '&ged=' + encodeURIComponent(WT_GEDCOM), '_blank', edit_window_specs);
} else {
return add_fact(xref, fact);
}
}
return false;
}
function reorder_media(xref) {
return edit_interface({
"action": "reorder_media",
"xref": xref
}, mord_window_specs);
}
function add_new_record(xref, fact) {
return edit_interface({
"action": "add",
"xref": xref,
"fact": fact
});
}
// Add a new child to an existing family
function add_child_to_family(xref, gender) {
return edit_interface({
"action": "add_child_to_family",
"gender": gender,
"xref": xref
});
}
// Add a new child to an existing individual (creating a one-parent family)
function add_child_to_individual(xref, gender) {
return edit_interface({
"action": "add_child_to_individual",
"gender": gender,
"xref": xref
});
}
// Add a new parent to an existing individual (creating a one-parent family)
function add_parent_to_individual(xref, gender) {
return edit_interface({
"action": "add_parent_to_individual",
"xref": xref,
"gender": gender
});
}
// Add a new spouse to an existing family
function add_spouse_to_family(xref, famtag) {
return edit_interface({
"action": "add_spouse_to_family",
"xref": xref,
"famtag": famtag
});
}
function add_unlinked_indi() {
return edit_interface({
"action": "add_unlinked_indi"
});
}
// Add a new spouse to an existing individual (creating a new family)
function add_spouse_to_individual(xref, famtag) {
return edit_interface({
"action": "add_spouse_to_individual",
"xref": xref,
"famtag": famtag
});
}
function linkspouse(xref, famtag) {
return edit_interface({
"action": "linkspouse",
"xref": xref,
"famtag": famtag,
"famid": "new"
});
}
function add_famc(xref) {
return edit_interface({
"action": "addfamlink",
"xref": xref
});
}
function edit_name(xref, fact_id) {
return edit_interface({
"action": "editname",
"xref": xref,
"fact_id": fact_id
});
}
function add_name(xref) {
return edit_interface({
"action": "addname",
"xref": xref
});
}
// Accept the changes to a record - and reload the page
function accept_changes(xref) {
jQuery.post('action.php', {
action: 'accept-changes',
xref: xref,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
return false;
}
// Reject the changes to a record - and reload the page
function reject_changes(xref) {
jQuery.post('action.php', {
action: 'reject-changes',
xref: xref,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
return false;
}
// Delete a family - and reload the page
function delete_family(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-family',
xref: xref,
ged: typeof gedcom == 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete an individual - and reload the page
function delete_individual(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-individual',
xref: xref,
ged: typeof gedcom == 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a media object - and reload the page
function delete_media(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-media',
xref: xref,
ged: typeof gedcom == 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a note object - and reload the page
function delete_note(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-note',
xref: xref,
ged: typeof gedcom == 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a repository - and reload the page
function delete_repository(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-repository',
xref: xref,
ged: typeof gedcom == 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a source - and reload the page
function delete_source(message, xref, gedcom) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-source',
xref: xref,
ged: typeof gedcom == 'undefined' ? WT_GEDCOM : gedcom,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Delete a fact - and reload the page
function delete_fact(message, xref, fact_id) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'delete-fact',
xref: xref,
fact_id: fact_id,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Remove links from one record to another - and reload the page
function unlink_media(message, source, target) {
if (confirm(message)) {
jQuery.post('action.php', {
action: 'unlink-media',
source: source,
target: target,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
}
return false;
}
// Copy a fact to the clipboard
function copy_fact(xref, fact_id) {
jQuery.post('action.php', {
action: 'copy-fact',
xref: xref,
fact_id: fact_id,
ged: WT_GEDCOM,
csrf: WT_CSRF_TOKEN
},
function(){
location.reload();
});
return false;
}
// Paste a fact from the clipboard
function paste_fact(xref, element) {
jQuery.post('action.php', {
action: 'paste-fact',
xref: xref,
fact_id: jQuery(element).val(), // element is the