לדלג לתוכן

מדיה ויקי:Gadget-WikidataTab.js: הבדלים בין גרסאות בדף

מתוך צפונות ויקי
מ ←using [[mw:CodeEditor|CodeEditor]]: עיצוב וסדר של קיפודנחש
מ 9 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-WikidataTab.js יובאו
 
(2 גרסאות ביניים של 2 משתמשים אינן מוצגות)
שורה 27: שורה 27:
                 dataType: 'jsonp',
                 dataType: 'jsonp',
                 success: function(data) {
                 success: function(data) {
                         var d = $("<li>");
                         var d = $("<li>")
                        $("#p-views ul").append(d);
                        .addClass("mw-list-item")
                        .appendTo("#p-views ul");
                         if (data.success) {
                         if (data.success) {
                                 var lang = mw.config.get('wgPageContentLanguage'),
                                 var lang = mw.config.get('wgPageContentLanguage'),
שורה 61: שורה 62:
                                                                 $("<a>")
                                                                 $("<a>")
                                                                 .attr("href", "//www.wikidata.org/wiki/" + item.title)
                                                                 .attr("href", "//www.wikidata.org/wiki/" + item.title)
                                                                 .attr("title", (item.labels ? item.labels[lang].value : m.nolabel) + " (" + item.title + "):" + (item.descriptions ? item.descriptions[lang].value : m.nodescription))
                                                                 .attr("title", ((item.labels && item.labels[lang]) ? item.labels[lang].value : m.nolabel) + " (" + item.title + "):" + ((item.descriptions && item.descriptions[lang]) ? item.descriptions[lang].value : m.nodescription))
                                                                 .append(
                                                                 .append(
                                                                         $("<img>")
                                                                         $("<img>")

גרסה אחרונה מ־07:25, 5 בדצמבר 2022

if ($.inArray(mw.config.get('wgNamespaceNumber'), [0, 4, 10, 12, 14, 100]) + 1)
$(function($) {
        var translate = {
                'he': {
                        notfound: "לא נמצאה כותרת ויקינתונים",
                        nolabel: "(אין תווית)",
                        nodescription: "(אין תיאור)"
                },
                'en': {
                        notfound: "Wikidata item not found",
                        nolabel: "(No label)",
                        nodescription: "(no description given)"
                }
        },
        pagename = mw.config.get('wgPageName').replace(/_/g, " ");
 
        $.ajax({
                url: '//www.wikidata.org/w/api.php',
                data: {
                        'format': 'json',
                        'action': 'wbgetentities',
                        'sites': mw.config.get('wgDBname'),
                        'titles': pagename,
                        'props': 'info|labels|descriptions|aliases',
                        'languages': mw.config.get('wgPageContentLanguage')
                },
                dataType: 'jsonp',
                success: function(data) {
                        var d = $("<li>")
                        	.addClass("mw-list-item")
                        	.appendTo("#p-views ul");
                        if (data.success) {
                                var lang = mw.config.get('wgPageContentLanguage'),
                                        m = translate[lang] || translate.he;
                                for (var i in data.entities) {
                                        if (i == -1) {
                                                d.append(
                                                        $("<span>")
                                                        .append(
                                                                $("<a>")
                                                                .attr("href", "//www.wikidata.org/wiki/Special:CreateItem?setlang=he&label=" + pagename + "&site=hewiki&page=" + pagename)
                                                                .attr("title", m.notfound)
                                                                .append(
                                                                        $("<img>")
                                                                        .attr("src", "//upload.wikimedia.org/wikipedia/commons/e/e8/Wikidata-favicon.png")
                                                                        .attr("style", "margin-bottom: 5px; opacity:0.3; filter:alpha(opacity=30);")
                                                                )
                                                        )
                                                );
                                        } else {
                                                var item = data.entities[i],
                                                        i = 0,
                                                        aliases = [];
                                                try {
                                                        for (; i < item.aliases[lang].length; i++) {
                                                                aliases.push(item.aliases[lang][i].value);
                                                        }
                                                } catch (e) { }
                                                d.append(
                                                        $("<span>")
                                                        .append(
                                                                $("<a>")
                                                                .attr("href", "//www.wikidata.org/wiki/" + item.title)
                                                                .attr("title", ((item.labels && item.labels[lang]) ? item.labels[lang].value : m.nolabel) + " (" + item.title + "):" + ((item.descriptions && item.descriptions[lang]) ? item.descriptions[lang].value : m.nodescription))
                                                                .append(
                                                                        $("<img>")
                                                                        .attr("src", "//upload.wikimedia.org/wikipedia/commons/e/e8/Wikidata-favicon.png")
                                                                        .attr("style", "margin-bottom: 5px;")
                                                                )
                                                        )
                                                );
                                        } // else
                                } // for
                        } // if success
                } // succeess function
        }); // ajax
}); // ready