Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Speed of link_results_loop question

Quote Reply
Speed of link_results_loop question
Hi All,

I am trying to decide the best way to include javascript in templates via a plugin.

It can be done 1 of 2 ways:

1) Write the javascript inside a link_results_loop, like this (method 1):
Code:
function getMarkers() {
var index = 0;
var bounds = new GLatLngBounds();
var batch = [];

<%loop link_results_loop~%>
var icon = getDefaultIcon(index);
var point = new GLatLng(<%ZCS_Latitude%>, <%ZCS_Longitude%>);
var marker = createMarker(point, html, icon);
batch.push(marker);
bounds.extend(point);
index++;
<%~endloop%>

var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
map.setCenter(new GLatLng(clat,clng));
map.setZoom(map.getBoundsZoomLevel(bounds));
return batch;
}

or, I can create a tag in the plugin code while finding the results, like this (method 2)
Code:
$markers = "new GLatLngBounds();";
$markers .= "var batch = [];";
while (my $row = $sth->fetchrow_hashref)
{
if($link_count >= $offset and ( $link_count < ($offset + $args->{mh})) ) {
my $link = $links_db->select ('*', { ID => $row->{ID} })->fetchrow_hashref;
$link = Links::SiteHTML::tags('link', $link);
push (@link_results_loop, $link);
$markers .= "var icon = getDefaultIcon(link_count);";
$markers .= "var point = new GLatLng(". $link->{ZCS_Latitude} .",". $link->{ZCS_Longitude} .");";
$markers .= "var marker = createMarker(point, html, icon);";
$markers .= "batch.push(marker);";
$markers .= "bounds.extend(point);";
}
$link_count++;
}
$markers .= "var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;";
$markers .= "var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;";
$markers .= "map.setCenter(new GLatLng(clat,clng));";
$markers .= "map.setZoom(map.getBoundsZoomLevel(bounds));";

Then use method 2 in template like this:
function getMarkers() {
<%markers%>
}

The difference is that if I create the javascript in the plugin (method 2), I do not have to
run through the link loop twice (once for js and once for link loop).
Should I be concerned about running thru the link loop twice? ( I don't HAVE to).

The bad thing about writting the javascript in the plugin is that it writes
the javascript in the plugin Crazy, and API changes could break the plugin.
Also, the javascript is not easily editable if in the plugin.

The benefits of writing js in plugin is that users can't break it, and only 1 link loop.

Thanks for any comments.
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Subject Author Views Date
Thread Speed of link_results_loop question rgbworld 4495 Jan 20, 2007, 1:17 PM
Thread Re: [rgbworld] Speed of link_results_loop question
eupos 4414 Jan 20, 2007, 11:55 PM
Post Re: [eupos] Speed of link_results_loop question
rgbworld 4370 Jan 22, 2007, 5:03 AM
Thread Re: [rgbworld] Speed of link_results_loop question
brewt 4379 Jan 22, 2007, 5:28 PM
Thread Re: [brewt] Speed of link_results_loop question
rgbworld 4385 Jan 22, 2007, 6:56 PM
Post Re: [rgbworld] Speed of link_results_loop question
brewt 4361 Jan 22, 2007, 7:33 PM