close

  
<div><p> var do_trace = false;

var map1;
var map2;
var geocoder;
var counter = 0;

var undo_buffer_limit = 20;
var undo_buffer = [];
var current_task;

var selecting = false;
var closing = false;

$(function() {
  trace("&gt; start");
  
  if (GBrowserIsCompatible()) {
    
    var ask = function() {
      trace("&gt; ask");
      current_task.query = $("#search_input").val();
      geocode(current_task);
      trace(" -1) {
            input.val(selection + current_query.substring(separator,current_query.length));
          } else {
            input.val(selection);
          }
        }
        selecting = false;
      }
    }).bind("dblclick",function() {
      setTimeout(ask,200);
    });
    
    $("#undo").attr("disabled","disabled");
    
    $("#blurb_toggler").text("more info").hide().click(function() {
      var toggler = $(this);
      if (toggler.text() === "less info") {
        $(this).text("more info");
        $("#more_blurb").slideUp(200);
      } else {
        $(this).text("less info");
        $("#more_blurb").slideDown(200);
      }              
    });
    
    $("#loading").hide();
    $("#voting").hide();
    $("#skipping").hide();
    
    $("#sidebar").show();
    
    $(window).bind("load",initialize);
    $(window).bind("resize",resize);
    
  } else {
    alert("sorry, your browser is not supported.");
  }
  
  trace(" init");
  
  map1 = new GMap2(document.getElementById("map1"));
  map1.addControl(new GLargeMapControl());
  map1.addControl(new GMapTypeControl());
  map1.addControl(new GScaleControl());
  map1.addControl(new GOverviewMapControl());
  map1.enableScrollWheelZoom();
  map1.checkResize();
  
  map2 = new GMap2(document.getElementById("map2"));
  map2.checkResize();
  
  geocoder = new GClientGeocoder();   
  
  GEvent.addListener(map1,'click',mapClickHandler(singleClick,doubleClick));
  
  newLocation();
  
  trace(" map single click");
  if (latlong) {
    $("#sidebar").hide();
    $("#voting").show();
    var marker = new GMarker(latlong);
    map1.addOverlay(marker);
    current_task.marker = marker;
    vote(current_task, latlong, false, function() {
      newLocation();
    });
  }
  trace(" map double click");
  map1.zoomIn();
  trace(" skip");
  vote(current_task, null, true, function() {
    newLocation();
  });
  trace(" new location");
  
  $("#sidebar").hide();
  $("#voting").hide();
  $("#skipping").hide();
  
  if (user == null &amp;&amp; (counter % 5 == 0)) {
    $('#anonymous_dialog').modal({
      "onClose" : function() {
        if (!closing) {
          closing = true;
          $.modal.close();
          getNewLocation();
          closing = false;
        }
      }
    });
  } else {
    getNewLocation();
  }
}      

function getNewLocation() {
  $("#loading").show();
  
  $.ajax({
    type: "POST",
    url: "get_locations_without_coords",
    cache: false,
    data: {
      country_id : country_id
    },
    dataType: "json",
    success: function(data) {
      var task = data.result;            
      augmentWithQuery(task);
      geocode(task);
      populatePage(task);  
      resize();
      current_task = task;
      counter++;
      trace(" close dialog");
  $.modal.close();
  trace(" 0) ? task.topic["state:containedby"][0].name + ", " : "";
  task.query = task.topic.name + ", " + state + task.topic.containedby[0].name;
}

function geocode(task) {
  trace("&gt; geocode");
  geocoder.getLatLng(
    task.query,
    function(point) {
      map2.clearOverlays();            
      if (!point) {
        var point = new GLatLng(5, 20);
        map1.setCenter(point, 2);
        map2.setCenter(point, 0);
        alert(task.query + " not found");
      } else {
        task.latlong = point;
        updateMaps(task);
      }
      trace(" update maps");        
  map1.setCenter(task.latlong, 12);
  map2.setCenter(task.latlong, 3);
  map2.addOverlay(new GMarker(task.latlong));
  trace(" populate page");        
  
  $("#search_input").val(task.query);
  
  var name_div = $("#name").empty();
  
  if ("id" in task.topic) {
    name_div.html('<a target="_blank" href="http://www.freebase.com/view'%20+%20task.topic.id%20+%20'">' + task.query + '</a>');
  }
  
  var types_div = $("#types").empty();
  var types_html = "";
  var types = task.topic['ns:type'];
  for (var i = 0; i " + t.name + "";
        }
  }
  types_div.html(types_html);
  
  var blurb_div = $("#blurb").empty();
  var more_blurb_div = $("#more_blurb").empty().hide();
  var blurb_toggler = $("#blurb_toggler").text("more info");
  
  if ("/service/content/article" in task.umqlResult) {
    
    var remaining_counter = 0;
    var blurb = task.umqlResult["/service/content/article"];
    var paragraphs = blurb.split("\n");
    blurb_div.html(augment(paragraphs[0]));
    if (paragraphs.length &gt; 1) {
      for (var i = 1; i " + augment(paragraphs[i]) + "</p>");
      }
      blurb_toggler.show();
    } else {
      blurb_toggler.hide();
    }  
  }
  
  if ("/common/topic/image" in task.umqlResult) {
    var images = task.umqlResult["/common/topic/image"];  
    if (typeof images != "undefined" &amp;&amp; images.length &gt; 0) {
      $("#thumbnail img").attr("src","http://www.freebase.com/api/trans/image_thumb" + images[images.length - 1].id);
      $("#thumbnail").show();
    } else {
      $("#thumbnail").hide();
      $("#thumbnail img").attr("src","");
    }
  }
  
  var list_div = $("#people .list").empty();
  
  if ("people_born_here" in task.topic) {
    var people = task.topic.people_born_here;
    if (people.length &gt; 0) {
      for (var i = 0; i  0) {
          var image_id = person["/common/topic/image"][0].id;
          image = '<img class="icon" src="http://www.freebase.com/api/trans/image_thumb'%20+%20image_id%20+%20'">';
        } else {
          image = '<img class="icon" src="/pixel.gif">';
        }
        var profession = getProfession(person);
        profession = (typeof profession !== 'undefined') ? '<span class="profession">' + profession + '</span>' : "";
        list_div.append('<div class="person">' + image + '<a target="_blank" href="http://www.freebase.com/view'%20+%20person.id%20+%20'">' + person.name + '</a>' + profession + '</div>');
      }
    }
  }
  
  $("#loading").hide();
  $("#skipping").hide();
  $("#help").show();
  $("#sidebar").show();
  
  trace("" + name + "";
}

function augment(text) {
  return text.replace(matcher, replacer);        
}

function getProfession(person) {
  if ("profession" in person &amp;&amp; person.profession.length &gt; 0) {
    return person.profession[0];
  } else if ("type" in person &amp;&amp; person.type.length &gt; 0) {
    var types = person.type;
    for (var i = 0 ; i  vote");        
  $("#sidebar").hide();
  if (skipping) {
    $("#skipping").show();
  } else {
    $("#voting").show();
  }
  undo_buffer.push(task);
  $("#undo").removeAttr("disabled");
  if (undo_buffer.length &gt; undo_buffer_limit) {
    undo_buffer.shift();
  }  
  var vote = (latlong != null) ? latlong.x + "," + latlong.y : "skip";
  $.ajax({
    type: "POST",
    url: "vote",
    cache: false,
    dataType: "json",
    data: {
      "topic" : task.topic.id,
      "vote" : vote,
      "meta" : "{}",
    },
    success: function(data) {
      continuation(data);
      trace(" undo");
  var task = undo_buffer.pop();
  if (undo_buffer.length == 0) {
    $("#undo").attr("disabled","disabled");
  }       
  if (task) {
    map2.clearOverlays();            
    map1.removeOverlay(task.marker);
    populatePage(task);
    updateMaps(task);
    current_task = task;
  }
  trace(" resize");
  var h = $(window).height() - $("#footer").outerHeight();
  var help_h = $("#help").outerHeight();
  $("#map1").height(h - help_h - 15);
  map1.checkResize();
  
  var map2 = $("#map2");
  var title_h = $("#people .title").outerHeight();
  var list_h = h - map2.offset().top - map2.outerHeight() - title_h - 45;
  if (list_h </div>

Comments

Hide