Javascript-less navigation using anchor tags on long lists
--- a/busui/common.inc.php
+++ b/busui/common.inc.php
@@ -93,6 +93,8 @@
echo '</div>';
}
+$service_periods = Array ('sunday','saturday','weekday');
+
function service_period()
{
switch (date('w')){
@@ -104,6 +106,11 @@
default:
return 'weekday';
}
+}
+
+function remove_spaces($string)
+{
+ return str_replace(' ','',$string);
}
function midnight_seconds()
--- a/busui/index.php
+++ b/busui/index.php
@@ -17,14 +17,37 @@
</ul>
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
<li data-role="list-divider">Timetables - Routes</li>
- <li><a href="routeList.php">All Routes</a></li>
+ <li><a href="routeList.php">Routes By Final Destination</a></li>
+ <li><a href="routeList.php?bynumber=yes">Routes By Number</a></li>
<li><a href="routeList.php?nearbyfavs=yes">Nearby/Favourites Routes</a></li>
</ul>
<div class="ui-body ui-body-c">
- Current Location: <input type="text" id="geolocate" name="geolocate"/> Search? Update to Here?<br>
- Time: <?php echo date("H:m"); ?> <br>
- Service Period: <?php echo ucwords(service_period()); ?><br>
+ <h3>Time/Place Settings</h3>
+ <div data-role="fieldcontain">
+ <label for="geolocate"> Current Location: </label>
+ <input type="text" id="geolocate" name="geolocate"/> <a href="#" style="display:none" name="here" id="here"/>Here?</a>
+ </div>
+ <div data-role="fieldcontain">
+ <label for="time"> Time: </label>
+ <input type="time" value="<?php echo date("H:m"); ?>"/> <a href="#" style="display:none" name="currentTime" id="currentTime"/>Current Time?</a>
+ </div>
+ <div data-role="fieldcontain">
+ <label for="service_period"> Service Period: </label>
+ <select name="service_period">
+ <?php
+ foreach ($service_periods as $service_period) {
+ echo "<option value=\"$service_period\"".(service_period() === $service_period ? "SELECTED" : "").'>'.ucwords($service_period).'</option>';
+ }?>
+ </select>
+ <a href="#" style="display:none" name="currentPeriod" id="currentPeriod"/>Current Period?</a>
+ </div>
+
+ <input type="submit" value="Update"/>
</div>
+ <script>
+$('#here').click(function(event) { $('#geolocate').val(getCookie('geolocate')); return false;});
+$('#here').show();
+ </script>
</div>
</div>
</body>
--- a/busui/routeList.php
+++ b/busui/routeList.php
@@ -4,15 +4,14 @@
echo'
<div data-role="navbar">
<ul>
- <li><a href="routeList.php" class="ui-btn-active">By Final Destination...</a></li>
+ <li><a href="routeList.php">By Final Destination...</a></li>
<li><a href="routeList.php?bynumber=yes">By Number... </a></li>
- <li><a href="routeList.php?bysuburb=yes">By Suburb... </a></li>
+ <!--<li><a href="routeList.php?bysuburb=yes">By Suburb... </a></li>-->
</ul>
</div>
';
echo ' <ul data-role="listview">';
$url = $APIurl."/json/routes";
-
$contents = json_decode(getPage($url));
debug(print_r($contents,true));
@@ -24,19 +23,41 @@
if ($_REQUEST['bynumber']) {
$routeSeries = Array();
+ $seriesRange = Array();
foreach ($contents as $key => $row) {
foreach (explode(" ",$row[1]) as $routeNumber ) {
$seriesNum = substr($routeNumber, 0, -1)."0";
if ($seriesNum == "0") $seriesNum = $routeNumber;
+ $finalDigit = substr($routeNumber, sizeof($routeNumber)-1, 1);
+ if (isset($seriesRange[$seriesNum])) {
+ if ($finalDigit < $seriesRange[$seriesNum]['max'])
+ $seriesRange[$seriesNum]['max'] = $routeNumber;
+ if ($finalDigit > $seriesRange[$seriesNum]['min'])
+ $seriesRange[$seriesNum]['min'] = $routeNumber;
+ } else {
+ $seriesRange[$seriesNum]['max'] = $routeNumber;
+ $seriesRange[$seriesNum]['min'] = $routeNumber;
+ }
$routeSeries[$seriesNum][$seriesNum."-".$row[1]."-".$row[0]] = $row;
-
-
}
}
ksort($routeSeries);
+ ksort($seriesRange);
+ echo '<div class="noscriptnav"> Go to route numbers: ';
+ foreach ($seriesRange as $series => $range)
+ {
+ if ($range['min'] == $range['max']) echo "<a href=\"#$series\">$series</a> ";
+ else echo "<a href=\"#$series\">{$range['min']}-{$range['max']}</a> ";
+ }
+ echo "</div>
+ <script>
+ $('.noscriptnav').hide();
+ </script>";
foreach ($routeSeries as $series => $routes)
{
- echo '<li>'.$series."... <ul>\n";
+ echo '<a name="'.$series.'"></a>';
+ if ($series <= 9) echo '<li>'.$series."<ul>\n";
+ else echo "<li>{$seriesRange[$series]['min']}-{$seriesRange[$series]['max']}<ul>\n";
printRoutes($routes);
echo "</ul></li>\n";
}
@@ -44,8 +65,18 @@
foreach ($contents as $key => $row) {
$routeDestinations[$row[2]][] = $row;
}
+ echo '<div class="noscriptnav"> Go to Destination: ';
+ foreach($routeDestinations as $destination => $routes)
+ {
+ echo "<a href=\"#$destination\">$destination</a> ";
+ }
+ echo "</div>
+ <script>
+ $('.noscriptnav').hide();
+ </script>";
foreach ($routeDestinations as $destination => $routes)
{
+ echo '<a name="'.$destination.'"></a>';
echo '<li>'.$destination."... <ul>\n";
printRoutes($routes);
echo "</ul></li>\n";
@@ -53,6 +84,7 @@
}
echo "</ul>\n";
+
include_footer();
?>
--- a/busui/stopList.php
+++ b/busui/stopList.php
@@ -4,12 +4,22 @@
echo'
<div data-role="navbar">
<ul>
- <li><a href="stopList.php" class="ui-btn-active">Timing Points</a></li>
+ <li><a href="stopList.php">Timing Points</a></li>
<li><a href="stopList.php?allstops=yes">All Stops</a></li>
</ul>
</div>
';
-echo ' <ul data-role="listview" data-filter="true">';
+
+ echo '<div class="noscriptnav"> Go to letter: ';
+foreach(range('A','Z') as $letter)
+{
+ echo "<a href=\"#$letter\">$letter</a> ";
+}
+echo "</div>
+ <script>
+$('.noscriptnav').hide();
+ </script>";
+echo ' <ul data-role="listview" data-filter="true" data-inset="true" >';
$url = $APIurl."/json/timingpoints";
if ($_REQUEST['allstops']) $url = $APIurl."/json/stops";
if ($_REQUEST['lat'] && $_REQUEST['lon']) $url = $APIurl."/json/neareststops?lat={$_REQUEST['lat']}&lon={$_REQUEST['lon']}&limit=15";
@@ -19,13 +29,16 @@
$stopName[$key] = $row[1];
}
-// Sort the data with volume descending, edition ascending
-// Add $data as the last parameter, to sort by the common key
+// Sort the stops by name
array_multisort($stopName, SORT_ASC, $contents);
+$firstletter = "";
foreach ($contents as $row)
{
-
+ if (substr($row[1],0,1) != $firstletter){
+ echo "<a name=$firstletter></a>";
+ $firstletter = substr($row[1],0,1);
+ }
echo '<li><a href="stop.php?stopid='.$row[0].'">'.$row[1].'</a></li>';
}
echo '</ul>';