Update Mapstraction to properly scrape data from notice-list pages

Refactored the JavaScript for Mapstraction use so it scrapes data from
the HTML of the page it's on, if possible, and otherwise generates a
JSON array.
This commit is contained in:
Evan Prodromou
2009-12-04 14:31:19 -05:00
parent 2c07d4a530
commit a92228c713
3 changed files with 65 additions and 49 deletions

View File

@@ -112,6 +112,11 @@ class MapstractionPlugin extends Plugin
{
$actionName = $action->trimmed('action');
if (!in_array($actionName,
array('showstream', 'all', 'usermap', 'allmap'))) {
return true;
}
switch ($this->provider)
{
case 'cloudmade':
@@ -143,9 +148,20 @@ class MapstractionPlugin extends Plugin
$action->script(common_path('plugins/Mapstraction/usermap.js'));
$action->elementStart('script', array('type' => 'text/javascript'));
$action->raw(sprintf('var _provider = "%s";', $this->provider));
$action->elementEnd('script');
$action->inlineScript(sprintf('var _provider = "%s";', $this->provider));
// usermap and allmap handle this themselves
if (in_array($actionName,
array('showstream', 'all'))) {
$action->inlineScript('$(document).ready(function() { '.
' var user = null; '.
(($actionName == 'showstream') ? ' user = scrapeUser(); ' : '') .
' var notices = scrapeNotices(user); ' .
' console.log(notices); ' .
' showMapstraction($("#map_canvas"), notices); '.
'});');
}
return true;
}