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