[84] | 1 | /** |
---|
| 2 | * XML Web generátor – program na generování webových stránek |
---|
| 3 | * Copyright © 2012 František Kučera (frantovo.cz) |
---|
| 4 | * |
---|
| 5 | * This program is free software: you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
[136] | 7 | * the Free Software Foundation, version 3 of the License. |
---|
[84] | 8 | * |
---|
| 9 | * This program is distributed in the hope that it will be useful, |
---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | * GNU General Public License for more details. |
---|
| 13 | * |
---|
| 14 | * You should have received a copy of the GNU General Public License |
---|
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | */ |
---|
[11] | 17 | |
---|
[84] | 18 | /** |
---|
| 19 | * XML Web generátor – jmenný prostor |
---|
| 20 | */ |
---|
| 21 | var xwg = { |
---|
| 22 | /** |
---|
| 23 | * Zašifruje/dešifruje obsah elementu pomocí Rot13. |
---|
| 24 | * @param id ID elementu, jehož text chceme změnit. |
---|
| 25 | */ |
---|
| 26 | rot13: function(id) { |
---|
| 27 | var e = document.getElementById(id); |
---|
| 28 | e.textContent = e.textContent.rot13(); |
---|
[93] | 29 | }, |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * Vloží klikatelný odkaz. |
---|
| 33 | * @param id ID span elementu obsahujícího data |
---|
| 34 | */ |
---|
| 35 | odkazNaElektronickouPoštu: function(id) { |
---|
| 36 | var spanČesky = document.getElementById(id); |
---|
| 37 | var spanObsah = document.getElementById(id + "b"); |
---|
| 38 | var česky = spanČesky.innerHTML; |
---|
[125] | 39 | var adresa = česky |
---|
| 40 | .replace(new RegExp(" zavináč ", "g"), "@") |
---|
| 41 | .replace(new RegExp(" tečka ", "g"),"."); |
---|
[93] | 42 | |
---|
| 43 | var odkaz = document.createElement("a"); |
---|
| 44 | odkaz.href = "mailto:" + adresa; |
---|
| 45 | if (spanObsah.innerHTML.length > 0) { |
---|
| 46 | odkaz.innerHTML = spanObsah.innerHTML; |
---|
| 47 | } else { |
---|
| 48 | odkaz.innerHTML = adresa; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | spanČesky.parentNode.insertBefore(odkaz, spanČesky); |
---|
| 52 | spanČesky.parentNode.removeChild(spanČesky); |
---|
| 53 | spanObsah.parentNode.removeChild(spanObsah); |
---|
| 54 | }, |
---|
| 55 | |
---|
[84] | 56 | }; |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * Vrací hodnotu textového řetězce zašifrovanou/dešifrovanou algoritmem Rot13 |
---|
| 60 | */ |
---|
| 61 | String.prototype.rot13 = function() { |
---|
| 62 | return this.replace(/[a-zA-Z]/g, function(z) { |
---|
| 63 | return String.fromCharCode((z <= "Z" ? 90 : 122) >= (z = z.charCodeAt(0) + 13) ? z : z - 26); |
---|
| 64 | }); |
---|
| 65 | }; |
---|
| 66 | |
---|