Show a popup listing available editors when hovering over the edit tab

This commit is contained in:
Tom Hughes 2010-11-15 00:44:17 +00:00
parent 6c3b5aa9d4
commit 04a6c41be9
8 changed files with 154 additions and 15 deletions

View file

@ -32,7 +32,7 @@ class SiteController < ApplicationController
end end
def edit def edit
editor = @user.preferred_editor || DEFAULT_EDITOR editor = params[:editor] || @user.preferred_editor || DEFAULT_EDITOR
if editor == "josm" if editor == "josm"
render :action => :index render :action => :index

View file

@ -120,7 +120,9 @@ module ApplicationHelper
end end
def preferred_editor def preferred_editor
if @user and @user.preferred_editor if params[:editor]
params[:editor]
elsif @user and @user.preferred_editor
@user.preferred_editor @user.preferred_editor
else else
DEFAULT_EDITOR DEFAULT_EDITOR

View file

@ -5,6 +5,7 @@
<%= javascript_strings %> <%= javascript_strings %>
<%= javascript_include_tag 'prototype' %> <%= javascript_include_tag 'prototype' %>
<%= javascript_include_tag 'site' %> <%= javascript_include_tag 'site' %>
<%= javascript_include_tag 'menu' %>
<!--[if lt IE 7]><%= javascript_include_tag 'pngfix' %><![endif]--> <!-- thanks, microsoft! --> <!--[if lt IE 7]><%= javascript_include_tag 'pngfix' %><![endif]--> <!-- thanks, microsoft! -->
<%= stylesheet_link_tag 'common' %> <%= stylesheet_link_tag 'common' %>
<!--[if IE]><%= stylesheet_link_tag 'large', :media => "screen" %><![endif]--> <!-- IE is totally broken with CSS media queries --> <!--[if IE]><%= stylesheet_link_tag 'large', :media => "screen" %><![endif]--> <!-- IE is totally broken with CSS media queries -->
@ -73,6 +74,18 @@
</ul> </ul>
</div> </div>
<div id="editmenu">
<ul>
<% Editors::ALL_EDITORS.each do |editor| %>
<li><%= link_to t('layouts.edit_with', :editor => t('user.account.editor.' + editor)), {:controller => 'site', :action => 'edit', :editor => editor}, {:id => editor + 'anchor'} %></li>
<% end %>
</ul>
</div>
<script type="text/javascript">
createMenu("editanchor", "editmenu", 1000);
</script>
<div id="left"> <div id="left">
<div id="logo"> <div id="logo">

View file

@ -279,6 +279,8 @@ end
} }
function installEditHandler() { function installEditHandler() {
$("josmanchor").onclick =josmEditHandler;
<% if preferred_editor == "josm" %> <% if preferred_editor == "josm" %>
$("editanchor").onclick =josmEditHandler; $("editanchor").onclick =josmEditHandler;

View file

@ -912,6 +912,7 @@ en:
gps_traces_tooltip: Manage GPS traces gps_traces_tooltip: Manage GPS traces
user_diaries: User Diaries user_diaries: User Diaries
user_diaries_tooltip: View user diaries user_diaries_tooltip: View user diaries
edit_with: Edit with {{editor}}
tag_line: The Free Wiki World Map tag_line: The Free Wiki World Map
intro_1: "OpenStreetMap is a free editable map of the whole world. It is made by people like you." intro_1: "OpenStreetMap is a free editable map of the whole world. It is made by people like you."
intro_2: "OpenStreetMap allows you to view, edit and use geographical data in a collaborative way from anywhere on Earth." intro_2: "OpenStreetMap allows you to view, edit and use geographical data in a collaborative way from anywhere on Earth."

View file

@ -0,0 +1,62 @@
/*
* Open a menu.
*/
function openMenu(anchor, menu) {
menu.style.display = "block";
menu.clonePosition(anchor, {
setLeft: true, setTop: true, setWidth: false, setHeight: false,
offsetLeft: 0, offsetTop: anchor.getHeight()
});
}
/*
* Callback called when the mouse enters a menu anchor.
*/
function enterMenuAnchor(event, anchor, menu, delay) {
clearTimeout(menu.timer);
if (delay > 0) {
menu.timer = setTimeout(function () { openMenu(anchor, menu) }, delay);
} else {
openMenu(event, menu);
}
}
/*
* Callback called when the mouse leaves a menu anchor.
*/
function leaveMenuAnchor(event, anchor, menu) {
var to = event.relatedTarget || event.toElement;
if (to != menu && !to.descendantOf(menu)) {
menu.style.display = "none";
}
clearTimeout(menu.timer);
}
/*
* Callback called when the mouse leaves a menu.
*/
function leaveMenu(event, anchor, menu) {
var to = event.relatedTarget || event.toElement;
if (to != anchor && !to.descendantOf(menu)) {
menu.style.display = "none";
}
clearTimeout(menu.timer);
}
/*
* Setup a menu, triggered by hovering over an anchor for a given time.
*/
function createMenu(anchorid, menuid, delay) {
var anchor = $(anchorid);
var menu = $(menuid);
anchor.onmouseover = function (event) { enterMenuAnchor(anchor, anchor, menu, delay) };
anchor.onmouseout = function (event) { leaveMenuAnchor(event, anchor, menu) };
menu.onmouseout = function (event) { leaveMenu(event, anchor, menu) };
}

View file

@ -1,4 +1,3 @@
/* /*
* Called as the user scrolls/zooms around to aniplate hrefs of the * Called as the user scrolls/zooms around to aniplate hrefs of the
* view tab and various other links * view tab and various other links
@ -69,15 +68,54 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,obj
} }
} }
node = $("potlatchanchor");
if (node) {
var args = new Object();
args.editor = "potlatch";
args.lat = lat;
args.lon = lon;
args.zoom = zoom;
if (objtype && objid) {
args[objtype] = objid;
}
node.href = setArgs("/edit", args);
}
node = $("potlatch2anchor");
if (node) {
var args = new Object();
args.editor = "potlatch2";
args.lat = lat;
args.lon = lon;
args.zoom = zoom;
if (objtype && objid) {
args[objtype] = objid;
}
node.href = setArgs("/edit", args);
}
node = $("josmanchor");
if (node) {
var args = new Object();
args.editor = "josm";
args.lat = lat;
args.lon = lon;
args.zoom = zoom;
if (objtype && objid) {
args[objtype] = objid;
}
node.href = setArgs("/edit", args);
}
node = $("historyanchor"); node = $("historyanchor");
if (node) { if (node) {
if (zoom >= 11) { if (zoom >= 11) {
var args = new Object(); var args = new Object();
//set bbox param from 'extents' object //set bbox param from 'extents' object
if (typeof minlon == "number" && if (typeof minlon == "number" &&
typeof minlat == "number" && typeof minlat == "number" &&
typeof maxlon == "number" && typeof maxlon == "number" &&
typeof maxlat == "number") { typeof maxlat == "number") {
minlon = Math.round(minlon * decimals) / decimals; minlon = Math.round(minlon * decimals) / decimals;
minlat = Math.round(minlat * decimals) / decimals; minlat = Math.round(minlat * decimals) / decimals;
@ -225,24 +263,24 @@ function makeShortCode(lat, lon, zoom) {
// z18 so we don't need to care for now. // z18 so we don't need to care for now.
var c1 = 0, c2 = 0; var c1 = 0, c2 = 0;
for (var i = 31; i > 16; --i) { for (var i = 31; i > 16; --i) {
c1 = (c1 << 1) | ((x >> i) & 1); c1 = (c1 << 1) | ((x >> i) & 1);
c1 = (c1 << 1) | ((y >> i) & 1); c1 = (c1 << 1) | ((y >> i) & 1);
} }
for (var i = 16; i > 1; --i) { for (var i = 16; i > 1; --i) {
c2 = (c2 << 1) | ((x >> i) & 1); c2 = (c2 << 1) | ((x >> i) & 1);
c2 = (c2 << 1) | ((y >> i) & 1); c2 = (c2 << 1) | ((y >> i) & 1);
} }
var str = ""; var str = "";
for (var i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) { for (var i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
digit = (c1 >> (24 - 6 * i)) & 0x3f; digit = (c1 >> (24 - 6 * i)) & 0x3f;
str += char_array.charAt(digit); str += char_array.charAt(digit);
} }
for (var i = 5; i < Math.ceil((zoom + 8) / 3.0); ++i) { for (var i = 5; i < Math.ceil((zoom + 8) / 3.0); ++i) {
digit = (c2 >> (24 - 6 * (i - 5))) & 0x3f; digit = (c2 >> (24 - 6 * (i - 5))) & 0x3f;
str += char_array.charAt(digit); str += char_array.charAt(digit);
} }
for (var i = 0; i < ((zoom + 8) % 3); ++i) { for (var i = 0; i < ((zoom + 8) % 3); ++i) {
str += "-"; str += "-";
} }
return str; return str;
} }

View file

@ -344,6 +344,27 @@ hr {
text-align: right; text-align: right;
} }
/* Rules for edit menu */
#editmenu {
display: none;
z-index: 10000;
position: absolute;
background-color: #ffffff;
border: 1px solid black;
}
#editmenu ul {
margin-top: 10px;
margin-bottom: 10px;
padding-left: 10px;
padding-right: 10px;
}
#editmenu li {
list-style-type: none;
}
/* Rules for attribution text under the main map shown on printouts */ /* Rules for attribution text under the main map shown on printouts */
#attribution { #attribution {