Permalink
Browse files

Switch from Prototype to jQuery

  • Loading branch information...
1 parent 4368ba9 commit 13289d404188bd397ee72852f66c415a2bb87066 @tomhughes tomhughes committed Nov 21, 2011
Showing with 1,162 additions and 1,220 deletions.
  1. +2 −2 Gemfile
  2. +4 −3 Gemfile.lock
  3. +20 −19 app/assets/javascripts/menu.js
  4. +29 −33 app/assets/javascripts/site.js
  5. +3 −13 app/controllers/geocoder_controller.rb
  6. +4 −10 app/controllers/message_controller.rb
  7. +1 −3 app/controllers/user_controller.rb
  8. +2 −5 app/helpers/user_helper.rb
  9. +36 −42 app/views/browse/_map.html.erb
  10. 0 app/views/browse/{_start.html.erb → _sidebar.html.erb}
  11. +545 −0 app/views/browse/start.js.erb
  12. +0 −546 app/views/browse/start.rjs
  13. +2 −2 app/views/changeset/_changeset.html.erb
  14. +2 −2 app/views/changeset/_map.html.erb
  15. +4 −4 app/views/diary_entry/edit.html.erb
  16. 0 app/views/export/{_start.html.erb → _sidebar.html.erb}
  17. +347 −0 app/views/export/start.js.erb
  18. +0 −351 app/views/export/start.rjs
  19. +0 −9 app/views/geocoder/_search.html.erb
  20. +1 −1 app/views/geocoder/{_description.html.erb → description.html.erb}
  21. +14 −6 app/views/geocoder/results.html.erb
  22. +9 −0 app/views/geocoder/search.html.erb
  23. +3 −5 app/views/layouts/site.html.erb
  24. +2 −2 app/views/message/_message_summary.html.erb
  25. +3 −0 app/views/message/mark.js.erb
  26. +4 −8 app/views/site/_key.html.erb
  27. +0 −1 app/views/site/_potlatch.html.erb
  28. +3 −2 app/views/site/_potlatch2.html.erb
  29. +13 −13 app/views/site/_resize.html.erb
  30. +30 −58 app/views/site/_search.html.erb
  31. +7 −7 app/views/site/_sidebar.html.erb
  32. +14 −15 app/views/site/edit.html.erb
  33. +22 −18 app/views/site/index.html.erb
  34. +2 −2 app/views/user/confirm.html.erb
  35. +2 −2 app/views/user/confirm_email.html.erb
  36. +17 −16 app/views/user/login.html.erb
  37. +10 −10 app/views/user/new.html.erb
  38. +3 −8 app/views/user/terms.html.erb
  39. +1 −1 test/functional/browse_controller_test.rb
  40. +1 −1 test/functional/export_controller_test.rb
View
@@ -7,8 +7,8 @@ gem 'rails', '3.1.3'
# Require the postgres database driver
gem 'pg'
-# Load prototype support
-gem 'prototype-rails'
+# Load jquery support
+gem 'jquery-rails'
# Load rails plugins
gem 'rails-i18n-updater'
View
@@ -53,6 +53,9 @@ GEM
hike (1.2.1)
httpclient (2.2.3)
i18n (0.6.0)
+ jquery-rails (1.0.18)
+ railties (~> 3.0)
+ thor (~> 0.14)
json (1.6.1)
libv8 (3.3.10.4)
libxml-ruby (2.2.2)
@@ -79,8 +82,6 @@ GEM
rack-openid (~> 1.3)
pg (0.11.0)
polyglot (0.3.3)
- prototype-rails (3.1.0)
- rails (~> 3.1)
rack (1.3.5)
rack-cache (1.1)
rack (>= 0.4)
@@ -153,13 +154,13 @@ DEPENDENCIES
composite_primary_keys (>= 4.1.1)
dynamic_form
httpclient
+ jquery-rails
libxml-ruby (>= 2.0.5)
memcache-client
memcached
oauth-plugin (>= 0.4.0.pre7)
open_id_authentication (>= 1.1.0)
pg
- prototype-rails
rails (= 3.1.3)
rails-i18n-updater
rinku (>= 1.2.2)
@@ -2,35 +2,36 @@
* Open a menu.
*/
function openMenu(anchor, menu, align) {
+ var anchorPosition = anchor.offset();
var offset;
if (align == "left") {
offset = 0;
} else if (align == "right") {
- offset = anchor.getWidth() - menu.getWidth();
+ offset = menu.outerWidth() - anchor.outerWidth();
}
- menu.clonePosition(anchor, {
- setLeft: true, setTop: true, setWidth: false, setHeight: false,
- offsetLeft: offset, offsetTop: anchor.getHeight()
- });
+ menu.show();
- menu.style.display = "block";
+ menu.offset({
+ top: anchorPosition.top + anchor.outerHeight(),
+ left: anchorPosition.left - offset
+ });
}
/*
* Close a menu.
*/
function closeMenu(menu) {
clearTimeout(menu.timer);
- menu.style.display = "none";
+ menu.hide();
}
/*
* Callback called when the mouse enters a menu anchor.
*/
function enterMenuAnchor(event, anchor, menu, delay, align) {
- if (!anchor.hasClassName("disabled")) {
+ if (!anchor.hasClass("disabled")) {
clearTimeout(menu.timer);
if (delay > 0) {
@@ -47,8 +48,8 @@ function enterMenuAnchor(event, anchor, menu, delay, align) {
function leaveMenuAnchor(event, anchor, menu) {
var to = event.relatedTarget;
- if (to != menu && !to.descendantOf(menu)) {
- menu.style.display = "none";
+ if (!menu.is(to) && menu.has(to).length == 0) {
+ menu.hide();
}
clearTimeout(menu.timer);
@@ -60,8 +61,8 @@ function leaveMenuAnchor(event, anchor, menu) {
function leaveMenu(event, anchor, menu) {
var to = event.relatedTarget;
- if (to != anchor && !to.descendantOf(menu)) {
- menu.style.display = "none";
+ if (!anchor.is(to) && menu.has(to).length == 0) {
+ menu.hide();
}
clearTimeout(menu.timer);
@@ -71,12 +72,12 @@ function leaveMenu(event, anchor, menu) {
* Setup a menu, triggered by hovering over an anchor for a given time.
*/
function createMenu(anchorid, menuid, delay, align) {
- var anchor = $(anchorid);
- var menu = $(menuid);
+ var anchor = $("#" + anchorid);
+ var menu = $("#" + menuid);
- anchor.observe("mouseup", function (event) { closeMenu(menu) });
- anchor.observe("mouseover", function (event) { enterMenuAnchor(anchor, anchor, menu, delay, align) });
- anchor.observe("mouseout", function (event) { leaveMenuAnchor(event, anchor, menu) });
- menu.observe("mouseup", function (event) { closeMenu(menu) });
- menu.observe("mouseout", function (event) { leaveMenu(event, anchor, menu) });
+ anchor.mouseup(function (event) { closeMenu(menu) });
+ anchor.mouseover(function (event) { enterMenuAnchor(anchor, anchor, menu, delay, align) });
+ anchor.mouseout(function (event) { leaveMenuAnchor(event, anchor, menu) });
+ menu.mouseup(function (event) { closeMenu(menu) });
+ menu.mouseout(function (event) { leaveMenu(event, anchor, menu) });
}
@@ -1,8 +1,5 @@
-//= require prototype
-//= require prototype_ujs
-//= require effects
-//= require dragdrop
-//= require controls
+//= require jquery
+//= require jquery_ujs
/*
* Called as the user scrolls/zooms around to aniplate hrefs of the
@@ -22,50 +19,49 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,obj
maxlat = Math.round(maxlat * decimals) / decimals;
}
- $$(".geolink").each(function (link) {
+ $(".geolink").each(function (index, link) {
var args = getArgs(link.href);
- if (link.hasClassName("llz")) {
+ if ($(link).hasClass("llz")) {
args.lat = lat;
args.lon = lon;
args.zoom = zoom;
- } else if (minlon && link.hasClassName("bbox")) {
+ } else if (minlon && $(link).hasClass("bbox")) {
args.bbox = minlon + "," + minlat + "," + maxlon + "," + maxlat;
}
- if (layers && link.hasClassName("layers")) {
+ if (layers && $(link).hasClass("layers")) {
args.layers = layers;
}
- if (objtype && link.hasClassName("object")) {
+ if (objtype && $(link).hasClass("object")) {
args[objtype] = objid;
}
- if (link.hasClassName("minzoom[0-9]+")) {
- $w(link.className).each(function (classname) {
- if (match = classname.match(/^minzoom([0-9]+)$/)) {
- var minzoom = match[1];
- var name = link.id.replace(/anchor$/, "");
-
- if (zoom >= minzoom) {
- link.onclick = null;
- link.title = i18n("javascripts.site." + name + "_tooltip");
- link.removeClassName("disabled");
- } else {
- link.onclick = function () { alert(i18n("javascripts.site." + name + "_zoom_alert")); return false; };
- link.title = i18n("javascripts.site." + name + "_disabled_tooltip");
- link.addClassName("disabled");
- }
+ var classes = $(link).attr("class").split(" ");
+
+ $(classes).each(function (index, classname) {
+ if (match = classname.match(/^minzoom([0-9]+)$/)) {
+ var minzoom = match[1];
+ var name = link.id.replace(/anchor$/, "");
+
+ if (zoom >= minzoom) {
+ $(link).off("click");
+ $(link).attr("title", i18n("javascripts.site." + name + "_tooltip"));
+ $(link).removeClass("disabled");
+ } else {
+ $(link).click(function () { alert(i18n("javascripts.site." + name + "_zoom_alert")); return false; });
+ $(link).attr("title", i18n("javascripts.site." + name + "_disabled_tooltip"));
+ $(link).addClass("disabled");
}
- });
- }
+ }
+ });
link.href = setArgs(link.href, args);
});
- node = $("shortlinkanchor");
- if (node) {
- var args = getArgs(node.href);
+ $("#shortlinkanchor").each(function () {
+ var args = getArgs(this.href);
var code = makeShortCode(lat, lon, zoom);
var prefix = shortlinkPrefix();
@@ -87,11 +83,11 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,obj
// which encodes lat/lon/zoom. If new URL parameters are added to
// the main slippy map this needs to be changed.
if (args["layers"] || args[objtype]) {
- node.href = setArgs(prefix + "/go/" + code, args);
+ this.href = setArgs(prefix + "/go/" + code, args);
} else {
- node.href = prefix + "/go/" + code;
+ this.href = prefix + "/go/" + code;
}
- }
+ });
}
/*
@@ -28,11 +28,6 @@ def search
@sources.push "osm_nominatim"
@sources.push "geonames"
end
-
- render :update do |page|
- page.replace_html :sidebar_content, :partial => "search"
- page.call "openSidebar"
- end
end
def search_latlon
@@ -264,9 +259,9 @@ def search_osm_nominatim
end
render :action => "results"
- rescue Exception => ex
- @error = "Error contacting nominatim.openstreetmap.org: #{ex.to_s}"
- render :action => "error"
+# rescue Exception => ex
+# @error = "Error contacting nominatim.openstreetmap.org: #{ex.to_s}"
+# render :action => "error"
end
def search_geonames
@@ -302,11 +297,6 @@ def description
@sources.push({ :name => "osm_nominatim" })
@sources.push({ :name => "geonames" })
-
- render :update do |page|
- page.replace_html :sidebar_content, :partial => "description"
- page.call "openSidebar"
- end
end
def description_osm_namefinder
@@ -103,23 +103,17 @@ def outbox
def mark
if params[:message_id]
id = params[:message_id]
- message = Message.where(:id => id).where("to_user_id = ? OR from_user_id = ?", @user.id, @user.id).first
+ @message = Message.where(:id => id).where("to_user_id = ? OR from_user_id = ?", @user.id, @user.id).first
if params[:mark] == 'unread'
message_read = false
notice = t 'message.mark.as_unread'
else
message_read = true
notice = t 'message.mark.as_read'
end
- message.message_read = message_read
- if message.save
- if request.xhr?
- render :update do |page|
- page.replace "inboxanchor", :partial => "layouts/inbox"
- page.replace "inbox-count", :partial => "message_count"
- page.replace "inbox-#{message.id}", :partial => "message_summary", :object => message
- end
- else
+ @message.message_read = message_read
+ if @message.save
+ if not request.xhr?
flash[:notice] = notice
redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
end
@@ -23,9 +23,7 @@ def terms
@text = OSM.legal_text_for_country(@legale)
if request.xhr?
- render :update do |page|
- page.replace_html "contributorTerms", :partial => "terms"
- end
+ render :partial => "terms"
elsif using_open_id?
# The redirect from the OpenID provider reenters here
# again and we need to pass the parameters through to
@@ -6,11 +6,8 @@ def openid_logo
def openid_button(name, url)
link_to_function(
image_tag("#{name}.png", :alt => t("user.login.openid_providers.#{name}.alt")),
- nil,
+ "submitOpenidUrl('#{url}')",
:title => t("user.login.openid_providers.#{name}.title")
- ) do |page|
- page[:login_form][:openid_url][:value] = url
- page[:login_form].submit()
- end
+ )
end
end
Oops, something went wrong.

0 comments on commit 13289d4

Please sign in to comment.