انتقل إلى المحتوى

ميدياويكي:OpenStreetMap.js

من ويكيبيديا، الموسوعة الحرة

ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.

function openStreetMapInit() {
    var c = document.getElementById('osm-coordinates');
    if (!c) return;

    var a = c.getElementsByTagName('a');
    var geohack = false;
    for (var i = 0; i < a.length; i++) {
        var h = a[i].href;
        if (!h.match(/geohack/)) continue;
        if (h.match(/_globe:/)) continue; // no OSM for moon, mars, etc
        geohack = true;
        break;
    }
    if (!geohack) return;

    var na = document.createElement('a');
    na.href = '#';
    na.onclick = openStreetMapToggle;
    na.appendChild(document.createTextNode('خارطة'));
    c.appendChild(document.createTextNode(' ('));
    c.appendChild(na);
    c.appendChild(document.createTextNode(')     '));
}

function openStreetMapToggle() {
    var c = document.getElementById('osm-coordinates');
    if (!c) return;
    var cs = document.getElementById('contentSub');
    var osm = document.getElementById('openstreetmap');

    if (cs && osm) {
        if (osm.style.display == 'none') {
            osm.style.display = 'block';
        } else {
            osm.style.display = 'none';
        }
        return false;
    }

    var found_link = false;
    var a = c.getElementsByTagName('a');
    var h;
    for (var i = 0; i < a.length; i++) {
        h = a[i].href;
        if (!h.match(/geohack/)) continue;
        found_link = true;
        break;
    }
    if (!found_link) return; // No geohack link found

    h = h.split('params=')[1];

    var i = document.createElement('iframe');
    var url = '//tools.wmflabs.org/wiwosm/osm-on-ol/kml-on-ol.php?lang=ar&uselang=' + mw.config.get('wgUserLanguage') + '&params=' + h;

    i.id = 'openstreetmap';
    i.style.width = '99.5%';
    i.style.height = '350px';
    i.style.clear = 'both';
    i.src = url;
    cs.appendChild(i);
    return false;
}
jQuery(document).ready(openStreetMapInit);