Add iD editor

iD sources live in vendor/assets/iD, and are managed with
vendorer, using the "rewrite" functionality to replace relative
paths in the CSS with <%= asset_path(…) %> directives.

To avoid needing to namespace all of its CSS classes, iD
is embedded via an iframe.

To setup, edit application.yml to include an `id_key` key.
(It can use the same consumer key as P2 if you like.)
This commit is contained in:
Tom MacWright 2013-04-01 17:19:15 -04:00 committed by John Firebaugh
parent 2c8ed19553
commit 7a98913d0c
59 changed files with 77628 additions and 2 deletions

View file

@ -37,4 +37,14 @@ folder 'vendor/assets' do
file 'ohauth.js'
end
end
folder 'iD' do
from 'git://github.com/systemed/iD', :branch => 'embed' do
folder 'iD/img', 'dist/img'
file 'iD.css.erb', 'dist/iD.css' do |path|
rewrite(path) { |content| content.gsub(/url\('?(img\/[^')]+)'?\)/, 'url(<%= asset_path("iD/\1") %>)') }
end
file 'iD.js', 'dist/iD.js'
end
end
end

View file

@ -1784,3 +1784,11 @@ a.button.submit {
text-align: right;
}
}
/*
* Rules for the iD editor
*/
.id-embed {
width: 100%;
height: 100%;
}

View file

@ -65,4 +65,8 @@ class SiteController < ApplicationController
def preview
render :text => RichText.new(params[:format], params[:text]).to_html
end
def id_iframe
render "id_iframe", :layout => false
end
end

View file

@ -0,0 +1,34 @@
<% if defined? ID_KEY %>
<iframe frameBorder="0" id="id-embed" class="id-embed"></iframe>
<% token = @user.access_token(ID_KEY) %>
<script>
var keys = {
'<%= request.protocol + request.host_with_port %>': {
oauth_consumer_key: "<%= token.client_application.key %>",
oauth_secret: "<%= token.client_application.secret %>",
oauth_token: "<%= token.token %>",
oauth_token_secret: "<%= token.secret %>"
}
};
var coord = {};
<% if @lat && @lon && @zoom -%>
coord.lat = <%= @lat %>;
coord.lon = <%= @lon %>;
coord.zoom = <%= @zoom %>;
<% else -%>
var params = OSM.mapParams();
coord.lat = params.lat;
coord.lon = params.lon;
coord.zoom = params.zoom;
<% end -%>
var url = 'id_iframe#map=' + coord.zoom + '/' + coord.lon + '/' + coord.lat +
'&preauth=' + JSON.stringify(keys);
$('#id-embed').attr('src', url);
</script>
<% else%>
<script type="text/javascript">alert("<%= t 'site.edit.id_not_configured' %>")</script>
<% end %>
<script type="text/javascript">
</script>

View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<%= stylesheet_link_tag 'iD' %>
<!--[if !IE || gte IE 9]><!-->
<%= javascript_include_tag 'iD' %>
<!-- <![endif]-->
</head>
<body>
<div id='id-container'></div>
<script>
if (typeof iD == 'undefined') {
document.getElementById('id-container').innerHTML = 'This editor is supported ' +
'in Firefox, Chrome, Safari, Opera, and Internet Explorer 9 and above. ' +
'Please upgrade your browser or use Potlatch 2 to edit the map.';
document.getElementById('id-container').className = 'unsupported';
} else {
var qs = iD.util.stringQs(location.hash);
if (qs.preauth) {
var preauth = JSON.parse(qs.preauth);
var id = iD()
.embed(true)
.imagePath("/assets/iD/img/"); <%# Can't use asset_path('id/img/') in production. %>
id.connection()
.url(Object.keys(preauth)[0])
.keys(preauth);
d3.select('#id-container')
.call(id.ui());
}
}
</script>
</body>
</html>

View file

@ -62,6 +62,7 @@ OpenStreetMap::Application.configure do
config.assets.precompile += %w( large-rtl.css small-rtl.css print-rtl.css )
config.assets.precompile += %w( browse.css leaflet-all.css leaflet.ie.css )
config.assets.precompile += %w( embed.js embed.css )
config.assets.precompile += %w( iD.js iD.css )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false

View file

@ -78,6 +78,8 @@ defaults: &defaults
#potlatch2_key: ""
# OAuth consumer key for the web site
#oauth_key: ""
# OAuth consumer key for iD
#id_key: ""
# Whether to require users to view the CTs before continuing to edit...
require_terms_seen: false
# Whether to require users to agree to the CTs before editing

View file

@ -85,6 +85,9 @@ en:
potlatch:
name: "Potlatch 1"
description: "Potlatch 1 (in-browser editor)"
id:
name: "iD"
description: "iD (in-browser editor)"
potlatch2:
name: "Potlatch 2"
description: "Potlatch 2 (in-browser editor)"
@ -1312,6 +1315,7 @@ en:
potlatch_unsaved_changes: "You have unsaved changes. (To save in Potlatch, you should deselect the current way or point, if editing in live mode, or click save if you have a save button.)"
potlatch2_not_configured: "Potlatch 2 has not been configured - please see http://wiki.openstreetmap.org/wiki/The_Rails_Port#Potlatch_2 for more information"
potlatch2_unsaved_changes: "You have unsaved changes. (To save in Potlatch 2, you should click save.)"
id_not_configured: "iD has not been configured"
no_iframe_support: "Your browser doesn't support HTML iframes, which are necessary for this feature."
sidebar:
search_results: Search Results

View file

@ -131,6 +131,7 @@ OpenStreetMap::Application.routes.draw do
match '/logout' => 'user#logout', :via => [:get, :post]
match '/offline' => 'site#offline', :via => :get
match '/key' => 'site#key', :via => :get
match '/id_iframe' => 'site#id_iframe', :via => :get
match '/user/new' => 'user#new', :via => :get
match '/user/terms' => 'user#terms', :via => [:get, :post]
match '/user/save' => 'user#save', :via => :post

View file

@ -1,4 +1,4 @@
module Editors
ALL_EDITORS = [ "potlatch", "potlatch2", "remote" ]
RECOMMENDED_EDITORS = [ "potlatch2", "remote" ]
ALL_EDITORS = [ "potlatch", "potlatch2", "id", "remote" ]
RECOMMENDED_EDITORS = [ "id", "potlatch2", "remote" ]
end

4320
vendor/assets/iD/iD.css.erb vendored Normal file

File diff suppressed because it is too large Load diff

70963
vendor/assets/iD/iD.js vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

BIN
vendor/assets/iD/iD/img/bing_maps.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 832 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

BIN
vendor/assets/iD/iD/img/cursor-draw.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

BIN
vendor/assets/iD/iD/img/cursor-grab.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 851 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 603 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

BIN
vendor/assets/iD/iD/img/loader-black.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
vendor/assets/iD/iD/img/loader-white.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
vendor/assets/iD/iD/img/loader_bg.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

BIN
vendor/assets/iD/iD/img/logo.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
vendor/assets/iD/iD/img/mini-loader.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

BIN
vendor/assets/iD/iD/img/pattern/dots.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

2242
vendor/assets/iD/iD/img/sprite.svg vendored Normal file

File diff suppressed because it is too large Load diff

After

Width:  |  Height:  |  Size: 160 KiB