Vai al contenuto

MediaWiki:Gadget-MapFrame.js: differenze tra le versioni

Da Wikivoyage.
Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
Nessun oggetto della modifica
Riga 6: Riga 6:
var map = $('div #mapdiv');
var map = $('div #mapdiv');
map.each(function() {
map.each(function() {
validateMap(map);
var self = this,
$self = $(this);
var exsrc = exhtml+'lat='+map.data("lat")+'&lon='+map.data("long")
validateMap($self);
+'&zoom='+map.data("zoom")+'&layer='+map.data("layer")+'&lang='+wgContentLanguage+'&name='+wgPageName;
var exsrc = exhtml+'lat='+$self.data("lat")+'&lon='+$self.data("long")
+'&zoom='+$self.data("zoom")+'&layer='+$self.data("layer")+'&lang='+mw.config.get('wgContentLanguage')+'&name='+mw.config.get('wgPageName');
var ifstr = '<iframe src="'+exsrc+'" width="'+map.data("width")+'" height="'+map.data("height")
var ifstr = '<iframe src="'+exsrc+'" width="'+$self.data("width")+'" height="'+$self.data("height")
+'" style="border:0"></iframe>';
+'" style="border:0"></iframe>';
map.html(ifstr);
$self.html(ifstr);
if ( map.data("layer").indexOf('O') < 0 ) {
if ( $self.data("layer").indexOf('O') < 0 ) {
$('.vcard a').attr('href', function () { return this.href.replace('layer=O','layer='+map.data("layer")[0]) });
$('.vcard a').attr('href', function () { return this.href.replace('layer=O','layer='+$self.data("layer")[0]) });
}
}
});
});

Versione delle 00:51, 7 mar 2014

/* Usage: inserts an iframe into a div with id "mapdiv", in conjunction with Template:MapFrame
          for embeddable dynamic maps. Relies on HTML5 data parameters.  */                    

function insertIFrame() {
    var exhtml = '//tools.wmflabs.org/wikivoyage/w/poimap2.php?';
    var map = $('div #mapdiv');
    map.each(function() {
    	var self = this,
    	$self = $(this);
        validateMap($self);
        var exsrc = exhtml+'lat='+$self.data("lat")+'&lon='+$self.data("long")
            +'&zoom='+$self.data("zoom")+'&layer='+$self.data("layer")+'&lang='+mw.config.get('wgContentLanguage')+'&name='+mw.config.get('wgPageName');
 
        var ifstr = '<iframe src="'+exsrc+'" width="'+$self.data("width")+'" height="'+$self.data("height")
            +'" style="border:0"></iframe>';
        $self.html(ifstr);
        if ( $self.data("layer").indexOf('O') < 0 ) {
            $('.vcard a').attr('href', function () { return this.href.replace('layer=O','layer='+$self.data("layer")[0]) });
        }
    });
}

function validateMap(map) {
    if (!$.isNumeric(map.data("lat"))) map.data("lat", 51.47766);
    if (!$.isNumeric(map.data("long"))) map.data("long", -0.00115);
    if (!$.isNumeric(map.data("zoom")) && map.data("zoom") != 'auto') map.data("zoom", 14);
    if (!$.isNumeric(map.data("height"))) map.data("height", 420);
    if (!$.isNumeric(map.data("width"))) map.data("width", 420);
    if (map.data("layer").length > 8) map.data("layer", 'O');
}

jQuery(document).ready(insertIFrame);