אונטערשייד צווישן ווערסיעס פון "באַניצער:תנא קמא/tanachLinks.js"

test
אין תקציר עריכה
צייכן: אַנולירונג
(test)
צייכן: צוריקגעשטעלט
שורה 1: שורה 1:
mw.loader.using(['mediawiki.util', 'jquery'], function () {
mw.loader.using(['mediawiki.util', 'jquery'], function () {
     $(document).ready(function () {
     $(document).ready(function () {
        // Define favicon URLs
         var sefariaFavicon = 'https://www.sefaria.org/static/icons/favicon.ico';
         var sefariaFavicon = 'https://www.sefaria.org/static/icons/favicon.ico';
         var alHaTorahFavicon = 'https://mg.alhatorah.org/favicon.ico';
         var alHaTorahFavicon = 'https://mg.alhatorah.org/favicon.ico';
        var mainIcon = 'https://upload.wikimedia.org/wikipedia/commons/e/ec/External_link_icon.png'; // Main popup trigger icon


         // Define the mapping between Hebrew book names and their English and AlHaTorah equivalents
         var bookNameMapping = {
        const bookNameMapping = {
             'Genesis': 'Bereshit', 'Exodus': 'Shemot', 'Leviticus': 'Vayikra', 'Numbers': 'Bemidbar',
             'בראשית': { english: 'Genesis', alHaTorah: 'Bereshit' },
             'Deuteronomy': 'Devarim', 'Joshua': 'Yehoshua', 'Judges': 'Shofetim', 'Samuel I': 'Shemuel I',
            'שמות': { english: 'Exodus', alHaTorah: 'Shemot' },
             'Samuel II': 'Shemuel II', 'Kings I': 'Melakhim I', 'Kings II': 'Melakhim II', 'Isaiah': 'Yeshayahu',
            'ויקרא': { english: 'Leviticus', alHaTorah: 'Vayikra' },
             'Jeremiah': 'Yirmeyahu', 'Ezekiel': 'Yechezkel', 'Hosea': 'Hoshea', 'Joel': 'Yoel', 'Amos': 'Amos',
            'במדבר': { english: 'Numbers', alHaTorah: 'Bemidbar' },
             'Obadiah': 'Ovadyah', 'Jonah': 'Yonah', 'Micah': 'Mikhah', 'Nahum': 'Nachum', 'Habakkuk': 'Chavakkuk',
             'דברים': { english: 'Deuteronomy', alHaTorah: 'Devarim' },
             'Zephaniah': 'Zephanyah', 'Haggai': 'Chaggai', 'Zechariah': 'Zekharyah', 'Malachi': 'Malakhi',
            'יהושע': { english: 'Joshua', alHaTorah: 'Yehoshua' },
             'Psalms': 'Tehillim', 'Proverbs': 'Mishlei', 'Job': 'Iyyov', 'Song of Songs': 'Shir HaShirim',
            'שופטים': { english: 'Judges', alHaTorah: 'Shofetim' },
             'Ruth': 'Rut', 'Lamentations': 'Eikhah', 'Ecclesiastes': 'Kohelet', 'Esther': 'Esther', 'Daniel': 'Daniel',
            'שמואל א': { english: 'I_Samuel', alHaTorah: 'Shemuel_I' },
             'Ezra': 'Ezra', 'Nehemiah': 'Nechemyah', 'Chronicles I': 'Divrei HaYamim I', 'Chronicles II': 'Divrei HaYamim II'
             'שמואל ב': { english: 'II_Samuel', alHaTorah: 'Shemuel_II' },
            'מלכים א': { english: 'I_Kings', alHaTorah: 'Melakhim_I' },
            'מלכים ב': { english: 'II_Kings', alHaTorah: 'Melakhim_II' },
            'ישעיהו': { english: 'Isaiah', alHaTorah: 'Yeshayahu' },
             'ירמיהו': { english: 'Jeremiah', alHaTorah: 'Yirmeyahu' },
            'יחזקאל': { english: 'Ezekiel', alHaTorah: 'Yechezkel' },
            'הושע': { english: 'Hosea', alHaTorah: 'Hoshea' },
            'יואל': { english: 'Joel', alHaTorah: 'Yoel' },
            'עמוס': { english: 'Amos', alHaTorah: 'Amos' },
             'עובדיה': { english: 'Obadiah', alHaTorah: 'Ovadyah' },
            'יונה': { english: 'Jonah', alHaTorah: 'Yonah' },
            'מיכה': { english: 'Micah', alHaTorah: 'Mikhah' },
            'נחום': { english: 'Nahum', alHaTorah: 'Nachum' },
            'חבקוק': { english: 'Habakkuk', alHaTorah: 'Chavakkuk' },
             'צפניה': { english: 'Zephaniah', alHaTorah: 'Zephanyah' },
            'חגי': { english: 'Haggai', alHaTorah: 'Chaggai' },
            'זכריה': { english: 'Zechariah', alHaTorah: 'Zekharyah' },
            'מלאכי': { english: 'Malachi', alHaTorah: 'Malakhi' },
             'תהילים': { english: 'Psalms', alHaTorah: 'Tehillim' },
            'משלי': { english: 'Proverbs', alHaTorah: 'Mishlei' },
            'איוב': { english: 'Job', alHaTorah: 'Iyyov' },
            'שיר השירים': { english: 'Song_of_Songs', alHaTorah: 'Shir_HaShirim' },
             'רות': { english: 'Ruth', alHaTorah: 'Rut' },
            'איכה': { english: 'Lamentations', alHaTorah: 'Eikhah' },
            'קהלת': { english: 'Ecclesiastes', alHaTorah: 'Kohelet' },
            'אסתר': { english: 'Esther', alHaTorah: 'Esther' },
            'דניאל': { english: 'Daniel', alHaTorah: 'Daniel' },
             'עזרא': { english: 'Ezra', alHaTorah: 'Ezra' },
            'נחמיה': { english: 'Nehemiah', alHaTorah: 'Nechemyah' },
            'דברי הימים א': { english: 'I_Chronicles', alHaTorah: 'Divrei HaYamim_I' },
            'דברי הימים ב': { english: 'II_Chronicles', alHaTorah: 'Divrei HaYamim_II' }
         };
         };


         // Iterate over each Tanakh citation link
         function createPopup(link, sefariaUrl, alHaTorahUrl) {
            var popup = $('<div class="custom-popup">')
                .css({
                    position: 'absolute', background: '#fff', border: '1px solid #ccc',
                    padding: '5px', 'border-radius': '5px', 'box-shadow': '0px 2px 5px rgba(0,0,0,0.2)',
                    display: 'none', 'z-index': 1000
                })
                .append(
                    $('<a>').attr({ href: sefariaUrl, target: '_blank', title: 'עפן אין ספריא' })
                        .html('<img src="' + sefariaFavicon + '" style="width:16px; height:16px; margin:3px;">'),
                    $('<a>').attr({ href: alHaTorahUrl, target: '_blank', title: 'עפן אין על התורה' })
                        .html('<img src="' + alHaTorahFavicon + '" style="width:16px; height:16px; margin:3px;">')
                );
 
            $('body').append(popup);
 
            return popup;
        }
 
         $('.tanach-citation').each(function () {
         $('.tanach-citation').each(function () {
             var $link = $(this);
             var $link = $(this);
שורה 55: שורה 42:
             var pasuk = $link.data('pasuk');
             var pasuk = $link.data('pasuk');


            // Ensure the necessary data exists
             if (!sefer || !perek || !pasuk) return;
             if (!sefer || !perek || !pasuk) return;


            // Construct Sefaria URL
             var sefariaUrl = 'https://www.sefaria.org/' + encodeURIComponent(sefer) + '.' + encodeURIComponent(perek) + '.' + encodeURIComponent(pasuk);
             var sefariaUrl = 'https://www.sefaria.org/' + encodeURIComponent(sefer) + '.' + encodeURIComponent(perek) + '.' + encodeURIComponent(pasuk);
            var alHaTorahSefer = bookNameMapping[sefer] || sefer;
            var alHaTorahUrl = 'https://mg.alhatorah.org/Full/' + encodeURIComponent(alHaTorahSefer) +
                '/' + encodeURIComponent(perek) + '.' + encodeURIComponent(pasuk);
            var popup = createPopup($link, sefariaUrl, alHaTorahUrl);


            // Create and append the Sefaria icon
             var mainIconLink = $('<a>')
             var sefariaIcon = $('<a>')
                 .attr('href', '#')
                 .attr('href', sefariaUrl)
                 .attr('title', 'View Links')
                .attr('target', '_blank')
                 .html('<img src="' + mainIcon + '" style="width:14px; height:14px; margin-left:3px;">')
                 .attr('title', 'עפן אין ספריא')
                .on('click', function (e) {
                 .html('<img src="' + sefariaFavicon + '" alt="Sefaria" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">');
                    e.preventDefault();
            $link.after(sefariaIcon);
                    var offset = $(this).offset();
                    popup.css({ top: offset.top + 20, left: offset.left }).toggle();
                });


             // Map Hebrew book name to AlHaTorah's naming convention
             $link.after(mainIconLink);
            var alHaTorahNames = bookNameMapping[sefer];
            if (alHaTorahNames) {
                // Construct AlHaTorah URL
                var alHaTorahUrl = 'https://mg.alhatorah.org/Full/' + encodeURIComponent(alHaTorahNames.alHaTorah) +
                    '/' + encodeURIComponent(perek) +
                    '.' + encodeURIComponent(pasuk);


                // Create and append the AlHaTorah icon
            $(document).on('click', function (e) {
                var alHaTorahIcon = $('<a>')
                if (!popup.is(e.target) && popup.has(e.target).length === 0 && !mainIconLink.is(e.target)) {
                    .attr('href', alHaTorahUrl)
                    popup.hide();
                    .attr('target', '_blank')
                }
                    .attr('title', 'עפן אין על התורה')
             });
                    .html('<img src="' + alHaTorahFavicon + '" alt="AlHaTorah" style="width:12px; height:12px; vertical-align:middle; margin-left: 3px;">');
                $link.after(alHaTorahIcon);
             }
         });
         });
     });
     });
});
});