1 //= require jquery.simulate
 
   3 OSM.History = function(map) {
 
   7     .on("click", ".changeset_more a", loadMore)
 
   8     .on("mouseover", "[data-changeset]", function () {
 
   9       highlightChangeset($(this).data("changeset").id);
 
  11     .on("mouseout", "[data-changeset]", function () {
 
  12       unHighlightChangeset($(this).data("changeset").id);
 
  14     .on("mousedown", "[data-changeset]", function () {
 
  16       $(this).one("click", function (e) {
 
  17         if (!moved && !$(e.target).is('a')) {
 
  18           clickChangeset($(this).data("changeset").id, e);
 
  20       }).one("mousemove", function () {
 
  25   var group = L.featureGroup()
 
  26     .on("mouseover", function (e) {
 
  27       highlightChangeset(e.layer.id);
 
  29     .on("mouseout", function (e) {
 
  30       unHighlightChangeset(e.layer.id);
 
  32     .on("click", function (e) {
 
  33       clickChangeset(e.layer.id, e);
 
  36   group.getLayerId = function(layer) {
 
  40   function highlightChangeset(id) {
 
  41     group.getLayer(id).setStyle({fillOpacity: 0.3});
 
  42     $("#changeset_" + id).addClass("selected");
 
  45   function unHighlightChangeset(id) {
 
  46     group.getLayer(id).setStyle({fillOpacity: 0});
 
  47     $("#changeset_" + id).removeClass("selected");
 
  50   function clickChangeset(id, e) {
 
  51     $("#changeset_" + id).find("a.changeset_id").simulate("click", e);
 
  55     var data = {list: '1'};
 
  57     if (window.location.pathname === '/history') {
 
  58       data.bbox = map.getBounds().wrap().toBBoxString();
 
  62       url: window.location.pathname,
 
  65       success: function(html) {
 
  66         $('#sidebar_content .changesets').html(html);
 
  71     var feedLink = $('link[type="application/atom+xml"]'),
 
  72       feedHref = feedLink.attr('href').split('?')[0];
 
  74     feedLink.attr('href', feedHref + '?bbox=' + data.bbox);
 
  77   function loadMore(e) {
 
  81     var div = $(this).parents(".changeset_more");
 
  84     div.find(".loader").show();
 
  86     $.get($(this).attr("href"), function(data) {
 
  87       div.replaceWith(data);
 
  92   function updateMap() {
 
  97     $("[data-changeset]").each(function () {
 
  98       var changeset = $(this).data('changeset');
 
 100         changeset.bounds = L.latLngBounds(
 
 101           [changeset.bbox.minlat, changeset.bbox.minlon],
 
 102           [changeset.bbox.maxlat, changeset.bbox.maxlon]);
 
 103         changesets.push(changeset);
 
 107     changesets.sort(function (a, b) {
 
 108       return b.bounds.getSize() - a.bounds.getSize();
 
 111     for (var i = 0; i < changesets.length; ++i) {
 
 112       var changeset = changesets[i],
 
 113         rect = L.rectangle(changeset.bounds,
 
 114           {weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFBF", fillOpacity: 0});
 
 115       rect.id = changeset.id;
 
 119     if (window.location.pathname !== '/history') {
 
 120       var bounds = group.getBounds();
 
 121       if (bounds.isValid()) map.fitBounds(bounds);
 
 125   page.pushstate = page.popstate = function(path) {
 
 126     $("#history_tab").addClass("current");
 
 127     OSM.loadSidebarContent(path, page.load);
 
 130   page.load = function() {
 
 133     if (window.location.pathname === '/history') {
 
 134       map.on("moveend", update);
 
 140   page.unload = function() {
 
 141     map.removeLayer(group);
 
 142     map.off("moveend", update);
 
 144     $("#history_tab").removeClass("current");