MediaWiki:Gadget-MapFrame.js: differenze tra le versioni
Aspetto
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() { |
||
var self = this, |
|||
$self = $(this); |
|||
⚫ | |||
validateMap($self); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
var ifstr = '<iframe src="'+exsrc+'" width="'+ |
var ifstr = '<iframe src="'+exsrc+'" width="'+$self.data("width")+'" height="'+$self.data("height") |
||
+'" style="border:0"></iframe>'; |
+'" style="border:0"></iframe>'; |
||
$self.html(ifstr); |
|||
if ( |
if ( $self.data("layer").indexOf('O') < 0 ) { |
||
$('.vcard a').attr('href', function () { return this.href.replace('layer=O','layer='+ |
$('.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);