mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-15 02:02:56 +00:00
@@ -883,8 +883,16 @@ div.typeahead a:first-child {
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.modal-section:last-child { border-bottom: 0;}
|
||||
|
||||
.modal-section img.wiki-image {
|
||||
max-width: 400px;
|
||||
max-height: 300px;
|
||||
padding: 10px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.changeset-list li {
|
||||
border-top:1px solid #ccc;
|
||||
padding:5px 10px;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<script src='js/lib/d3.typeahead.js'></script>
|
||||
<script src='js/lib/d3.geo.tile.js'></script>
|
||||
<script src='js/lib/d3.size.js'></script>
|
||||
<script src='js/lib/d3.jsonp.js'></script>
|
||||
<script src='js/lib/d3.trigger.js'></script>
|
||||
<script src='js/lib/d3.keybinding.js'></script>
|
||||
<script src='js/lib/d3-compat.js'></script>
|
||||
@@ -30,6 +31,7 @@
|
||||
<script src='js/id/util.js'></script>
|
||||
<script src='js/id/oauth.js'></script>
|
||||
<script src='js/id/services/taginfo.js'></script>
|
||||
<script src='js/id/services/wiki.js'></script>
|
||||
<script src='js/id/renderer/style.js'></script>
|
||||
<script src='js/id/renderer/background.js'></script>
|
||||
<script src='js/id/renderer/background_source.js'></script>
|
||||
@@ -48,6 +50,7 @@
|
||||
<script src='js/id/ui/geocoder.js'></script>
|
||||
<script src='js/id/ui/geolocate.js'></script>
|
||||
<script src='js/id/ui/notice.js'></script>
|
||||
<script src='js/id/ui/flash.js'></script>
|
||||
<script src='js/id/ui/tag_reference.js'></script>
|
||||
|
||||
<script src='js/id/actions.js'></script>
|
||||
|
||||
32
js/id/services/wiki.js
Normal file
32
js/id/services/wiki.js
Normal file
@@ -0,0 +1,32 @@
|
||||
iD.wiki = function() {
|
||||
var wiki = {},
|
||||
endpoint = 'http://wiki.openstreetmap.org/w/api.php';
|
||||
// ?action=query&prop=imageinfo&titles=Image:Residential.jpg&iiprop=url%7Ccontent&format=json&callback=foo',
|
||||
|
||||
wiki.image = function(img, callback) {
|
||||
d3.jsonp(endpoint + '?' +
|
||||
iD.util.qsString({
|
||||
action: 'query',
|
||||
prop: 'imageinfo',
|
||||
titles: img,
|
||||
iiprop: 'url',
|
||||
format: 'json',
|
||||
callback: '{callback}'
|
||||
}), function(d) {
|
||||
try {
|
||||
callback(null,
|
||||
d.query.pages[Object.keys(d.query.pages)[0]].imageinfo[0].url);
|
||||
} catch(e) {
|
||||
callback(new Error('Image not found'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
wiki.endpoint = function(_) {
|
||||
if (!arguments.length) return endpoint;
|
||||
endpoint = _;
|
||||
return wiki;
|
||||
};
|
||||
|
||||
return wiki;
|
||||
};
|
||||
@@ -151,10 +151,14 @@ iD.Inspector = function() {
|
||||
if (en.on_node) types.push('point');
|
||||
if (en.on_way) types.push('line');
|
||||
en.types = types;
|
||||
var mod = iD.modal();
|
||||
mod.select('.content')
|
||||
iD.modal()
|
||||
.select('.content')
|
||||
.datum(en)
|
||||
.call(iD.tagReference);
|
||||
} else {
|
||||
iD.flash()
|
||||
.select('.content')
|
||||
.text('This is no documentation available for this tag combination');
|
||||
}
|
||||
});
|
||||
d3.event.preventDefault();
|
||||
|
||||
@@ -21,9 +21,22 @@ iD.tagReference = function(selection) {
|
||||
|
||||
referenceBody = selection.append('div')
|
||||
.attr('class','modal-section');
|
||||
|
||||
referenceBody
|
||||
.append('h5')
|
||||
.text('Description');
|
||||
|
||||
if (selection.datum().image) {
|
||||
iD.wiki().image(selection.datum().image, function(err, src) {
|
||||
if (!err) {
|
||||
referenceBody
|
||||
.append('img')
|
||||
.attr('class', 'wiki-image')
|
||||
.attr('src', src);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
referenceBody
|
||||
.append('p')
|
||||
.text(g('description'));
|
||||
|
||||
27
js/lib/d3.jsonp.js
Normal file
27
js/lib/d3.jsonp.js
Normal file
@@ -0,0 +1,27 @@
|
||||
d3.jsonp = function (url, callback) {
|
||||
|
||||
function rand() {
|
||||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
||||
c = '', i = -1;
|
||||
while (++i < 15) c += chars.charAt(Math.floor(Math.random() * 52));
|
||||
return c;
|
||||
}
|
||||
|
||||
function create(url) {
|
||||
var e = url.match(/callback=d3.jsonp.(\w+)/),
|
||||
c = e ? e[1] : rand();
|
||||
d3.jsonp[c] = function(data) {
|
||||
callback(data);
|
||||
delete d3.jsonp[c];
|
||||
script.remove();
|
||||
};
|
||||
return 'd3.jsonp.' + c;
|
||||
}
|
||||
|
||||
var cb = create(url),
|
||||
script = d3.select('head')
|
||||
.append('script')
|
||||
.attr('type', 'text/javascript')
|
||||
.attr('src', url.replace(/({|%7B)callback({|%7D)/, cb));
|
||||
|
||||
};
|
||||
1
test/data/foo.jsonp
Normal file
1
test/data/foo.jsonp
Normal file
@@ -0,0 +1 @@
|
||||
d3.jsonp.foo('foo');
|
||||
@@ -24,6 +24,7 @@
|
||||
<script src='../js/lib/d3.size.js'></script>
|
||||
<script src='../js/lib/d3.trigger.js'></script>
|
||||
<script src='../js/lib/d3.typeahead.js'></script>
|
||||
<script src='../js/lib/d3.jsonp.js'></script>
|
||||
<script src='../js/lib/d3.one.js'></script>
|
||||
<script src='../js/lib/ohauth.js'></script>
|
||||
<script src='../js/lib/jxon.js'></script>
|
||||
@@ -32,6 +33,7 @@
|
||||
<script src='../js/id/util.js'></script>
|
||||
<script src='../js/id/oauth.js'></script>
|
||||
<script src='../js/id/services/taginfo.js'></script>
|
||||
<script src='../js/id/services/wiki.js'></script>
|
||||
<script src='../js/id/renderer/style.js'></script>
|
||||
|
||||
<script src='../js/id/renderer/background.js'></script>
|
||||
@@ -133,6 +135,8 @@
|
||||
<script src="spec/renderer/map.js"></script>
|
||||
<script src="spec/renderer/style.js"></script>
|
||||
|
||||
<script src="spec/lib/jsonp.js"></script>
|
||||
|
||||
<script src="spec/ui/inspector.js"></script>
|
||||
<script src="spec/ui/geocoder.js"></script>
|
||||
<script src="spec/connection.js"></script>
|
||||
|
||||
7
test/spec/lib/jsonp.js
Normal file
7
test/spec/lib/jsonp.js
Normal file
@@ -0,0 +1,7 @@
|
||||
describe('JSONP', function() {
|
||||
it('can request data', function() {
|
||||
d3.jsonp('data/foo.jsonp?callback=d3.jsonp.foo', function(d) {
|
||||
expect(d).to.eql('foo');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user