/** * webtrees: online genealogy * Copyright (C) 2019 webtrees development team * 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 3 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, see . */ 'use strict'; let webtrees = function () { const lang = document.documentElement.lang; /** * Tidy the whitespace in a string. */ function trim(str) { return str.replace(/\s+/g, " ").trim(); } /** * Look for non-latin characters in a string. */ function detectScript(str) { if (str.match(/[\u3400-\u9FCC]/)) { return "cjk"; } else if (str.match(/[\u0370-\u03FF]/)) { return "greek"; } else if (str.match(/[\u0400-\u04FF]/)) { return "cyrillic"; } else if (str.match(/[\u0590-\u05FF]/)) { return "hebrew"; } else if (str.match(/[\u0600-\u06FF]/)) { return "arabic"; } return "latin"; } /** * In some languages, the SURN uses a male/default form, but NAME uses a gender-inflected form. */ function inflectSurname(surname, sex) { if (lang === "pl" && sex === "F") { return surname .replace(/ski$/, "ska") .replace(/cki$/, "cka") .replace(/dzki$/, "dzka") .replace(/żki$/, "żka"); } return surname; } /** * Build a NAME from a NPFX, GIVN, SPFX, SURN and NSFX parts. * * Assumes the language of the document is the same as the language of the name. */ function buildNameFromParts(npfx, givn, spfx, surn, nsfx, sex) { const usesCJK = detectScript(npfx + givn + spfx + givn + surn + nsfx) === "cjk"; const separator = usesCJK ? "" : " "; const surnameFirst = usesCJK || ['hu', 'jp', 'ko', 'vi', 'zh-Hans', 'zh-Hant'].indexOf(lang) !== -1; const patronym = ['is'].indexOf(lang) !== -1; const slash = patronym ? "" : "/"; // GIVN and SURN may be a comma-separated lists. npfx = trim(npfx); givn = trim(givn.replace(",", separator)); spfx = trim(spfx); surn = inflectSurname(trim(surn.replace(",", separator)), sex); nsfx = trim(nsfx); const surname = trim(spfx + separator + surn); const name = surnameFirst ? slash + surname + slash + separator + givn : givn + separator + slash + surname + slash; return trim(npfx + separator + name + separator + nsfx); } // Public methods return { buildNameFromParts: buildNameFromParts, detectScript: detectScript, }; }(); function expand_layer(sid) { $('#' + sid + '_img').toggleClass('icon-plus icon-minus'); $('#' + sid).slideToggle('fast'); $('#' + sid + '-alt').toggle(); // hide something when we show the layer - and vice-versa return false; } // Accept the changes to a record - and reload the page function accept_changes(xref, ged) { $.post( 'index.php?route=accept-changes', { xref: xref, ged: ged, }, function () { document.location.reload(); } ); return false; } // Reject the changes to a record - and reload the page function reject_changes(xref, ged) { $.post( 'index.php?route=reject-changes', { xref: xref, ged: ged, }, function () { document.location.reload(); } ); return false; } // Delete a record - and reload the page function delete_record(xref, gedcom) { $.post( 'index.php?route=delete-record', { xref: xref, ged: gedcom, }, function () { document.location.reload(); } ); return false; } // Delete a fact - and reload the page function delete_fact(message, ged, xref, fact_id) { if (confirm(message)) { $.post( 'index.php?route=delete-fact', { xref: xref, fact_id: fact_id, ged: ged }, function () { document.location.reload(); } ); } return false; } // Copy a fact to the clipboard function copy_fact(ged, xref, fact_id) { $.post( 'index.php?route=copy-fact', { xref: xref, fact_id: fact_id, ged: ged, }, function () { document.location.reload(); } ); return false; } // Paste a fact from the clipboard function paste_fact(ged, xref, element) { $.post( 'index.php?route=paste-fact', { xref: xref, fact_id: $(element).val(), // element is the '; for (i = 1; i < 32; i++) { content += '