HTML: Wide Javascript code cleaning

list_lib Javascript code cleaning, Now it looks like subsurface code.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Gehad elrobey 2014-06-24 16:01:51 +03:00 committed by Dirk Hohndel
parent 33fa8bdf96
commit 46667b5235

View file

@ -15,7 +15,8 @@ var olditemstoshow; //to reference the indexes to all dives if changed
*View N pages each of sizeofpage size items. *View N pages each of sizeofpage size items.
*starting from zero *starting from zero
*/ */
function showAllDives(){ function showAllDives()
{
for (var i = 0; i < items.length; i++) { for (var i = 0; i < items.length; i++) {
itemsToShow.push(i); itemsToShow.push(i);
} }
@ -29,9 +30,11 @@ function showAllDives(){
*It start from 'start' variable. *It start from 'start' variable.
*It showes N pages each of sizeofpage size. *It showes N pages each of sizeofpage size.
*/ */
function viewInPage(){ function viewInPage()
{
var end = start + sizeofpage - 1; var end = start + sizeofpage - 1;
if(end >= itemsToShow.length ) end = itemsToShow.length-1; if (end >= itemsToShow.length)
end = itemsToShow.length - 1;
updateView(start, end); updateView(start, end);
} }
@ -39,7 +42,8 @@ function viewInPage(){
*addHTML this Method puts the HTML of items of given indexes *addHTML this Method puts the HTML of items of given indexes
*@param {array} indexes array of indexes to put in HTML *@param {array} indexes array of indexes to put in HTML
*/ */
function updateView(start,end){ function updateView(start, end)
{
var divelist = document.getElementById('diveslist'); var divelist = document.getElementById('diveslist');
divelist.innerHTML = ""; divelist.innerHTML = "";
for (var i = start; i <= end; i++) { for (var i = start; i <= end; i++) {
@ -54,7 +58,8 @@ function updateView(start,end){
*addHTML this Method puts the HTML of items of given indexes *addHTML this Method puts the HTML of items of given indexes
*@param {array} indexes array of indexes to put in HTML *@param {array} indexes array of indexes to put in HTML
*/ */
function addHTML(indexes){ function addHTML(indexes)
{
var divelist = document.getElementById('diveslist'); var divelist = document.getElementById('diveslist');
divelist.innerHTML = ""; divelist.innerHTML = "";
for (var i = 0; i < indexes.length; i++) { for (var i = 0; i < indexes.length; i++) {
@ -69,9 +74,11 @@ function addHTML(indexes){
*@param {integer} start start from this index *@param {integer} start start from this index
*@param {integer} finish at this index. *@param {integer} finish at this index.
*/ */
function view_in_range(start,end){ function view_in_range(start, end)
{
var ind = new Array(); var ind = new Array();
if(end>=itemsToShow.length)end=itemsToShow.length-1; if (end >= itemsToShow.length)
end = itemsToShow.length - 1;
for (var i = start; i <= end; i++) { for (var i = start; i <= end; i++) {
ind.push(i); ind.push(i);
} }
@ -80,12 +87,12 @@ function view_in_range(start,end){
} }
function prev_page(){ function prev_page()
{
var end = start + sizeofpage - 1; var end = start + sizeofpage - 1;
if (start - sizeofpage > 0) { if (start - sizeofpage > 0) {
start -= sizeofpage; start -= sizeofpage;
} } else {
else{
start = 0; start = 0;
} }
if (end - sizeofpage > 0) { if (end - sizeofpage > 0) {
@ -97,12 +104,12 @@ function prev_page(){
updateView(start, end) updateView(start, end)
} }
function next_page(){ function next_page()
{
var end = start + sizeofpage - 1; var end = start + sizeofpage - 1;
if (end + sizeofpage < itemsToShow.length) { if (end + sizeofpage < itemsToShow.length) {
end += sizeofpage; end += sizeofpage;
} } else {
else{
end = itemsToShow.length - 1; end = itemsToShow.length - 1;
} }
if (start + sizeofpage < itemsToShow.length) { if (start + sizeofpage < itemsToShow.length) {
@ -113,52 +120,59 @@ function next_page(){
/////////////////////////////////////////////// ///////////////////////////////////////////////
function view_pagging(start,end){ function view_pagging(start, end)
{
var page = document.getElementById("pagging"); var page = document.getElementById("pagging");
page.innerHTML = (start + 1) + ' to ' + (end + 1) + ' of ' + (itemsToShow.length) + ' dives'; page.innerHTML = (start + 1) + ' to ' + (end + 1) + ' of ' + (itemsToShow.length) + ' dives';
} }
function expandAll(){ function expandAll()
{
for (var i = start; i < start + sizeofpage; i++) { for (var i = start; i < start + sizeofpage; i++) {
if(i>=itemsToShow.length) break; if (i >= itemsToShow.length)
break;
unexpand(document.getElementById(itemsToShow[i])); unexpand(document.getElementById(itemsToShow[i]));
items[itemsToShow[i]].expanded = false; items[itemsToShow[i]].expanded = false;
} }
} }
function collapseAll(){ function collapseAll()
{
for (var i = start; i < start + sizeofpage; i++) { for (var i = start; i < start + sizeofpage; i++) {
if(i>=itemsToShow.length) break; if (i >= itemsToShow.length)
break;
expand(document.getElementById(itemsToShow[i])); expand(document.getElementById(itemsToShow[i]));
items[itemsToShow[i]].expanded = true; items[itemsToShow[i]].expanded = true;
} }
} }
function setNumberOfDives(e){ function setNumberOfDives(e)
{
var value = e.options[e.selectedIndex].value; var value = e.options[e.selectedIndex].value;
sizeofpage = parseInt(value, 10); sizeofpage = parseInt(value, 10);
var end = start + sizeofpage - 1; var end = start + sizeofpage - 1;
view_in_range(start, end); view_in_range(start, end);
} }
function toggleExpantion(ul){ function toggleExpantion(ul)
if(!items[ul.id].expanded)
{ {
if (!items[ul.id].expanded) {
expand(ul); expand(ul);
items[ul.id].expanded = true; items[ul.id].expanded = true;
} } else {
else
{
unexpand(ul); unexpand(ul);
items[ul.id].expanded = false; items[ul.id].expanded = false;
} }
} }
function expand(ul){ function expand(ul)
{
ul.innerHTML = getlimited(items[ul.id]); ul.innerHTML = getlimited(items[ul.id]);
ul.style.padding = '2px 10px 2px 10px'; ul.style.padding = '2px 10px 2px 10px';
} }
function unexpand(ul){
function unexpand(ul)
{
ul.innerHTML = getExpanded(items[ul.id]); ul.innerHTML = getExpanded(items[ul.id]);
ul.style.padding = '3px 10px 3px 10px'; ul.style.padding = '3px 10px 3px 10px';
} }
@ -169,7 +183,8 @@ function unexpand(ul){
// //
////////////////////////////////////// //////////////////////////////////////
function getlimited (dive) { function getlimited(dive)
{
return '<div style="height:20px"><div class="item">' + (settings.subsurfaceNumbers === '0' ? dive.number : dive.subsurface_number) + '</div>' + return '<div style="height:20px"><div class="item">' + (settings.subsurfaceNumbers === '0' ? dive.number : dive.subsurface_number) + '</div>' +
'<div class="item">' + dive.date + '</div>' + '<div class="item">' + dive.date + '</div>' +
'<div class="item">' + dive.time + '</div>' + '<div class="item">' + dive.time + '</div>' +
@ -178,7 +193,8 @@ function getlimited (dive) {
'<div class="item">' + dive.temperature.water + '</div></div>'; '<div class="item">' + dive.temperature.water + '</div></div>';
}; };
function getExpanded (dive) { function getExpanded(dive)
{
var res = '<table><tr><td class="words">Date: </td><td>' + dive.date + var res = '<table><tr><td class="words">Date: </td><td>' + dive.date +
'</td><td class="words">&nbsp&nbsp&nbsp&nbsp&nbspTime: </td><td>' + dive.time + '</td><td class="words">&nbsp&nbsp&nbsp&nbsp&nbspTime: </td><td>' + dive.time +
'</td><td class="words">&nbsp&nbsp&nbsp&nbsp&nbspLocation: </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\')\">' + '</td><td class="words">&nbsp&nbsp&nbsp&nbsp&nbspLocation: </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\')\">' +
@ -199,7 +215,8 @@ function getExpanded (dive) {
return res; return res;
}; };
function putTags(tags){ function putTags(tags)
{
var result = ""; var result = "";
for (var i in tags) { for (var i in tags) {
result += '<a onclick=\"Search_list_Modules(\'' + tags[i] + '\')\">' + tags[i] + '</a>'; result += '<a onclick=\"Search_list_Modules(\'' + tags[i] + '\')\">' + tags[i] + '</a>';
@ -209,7 +226,8 @@ function putTags(tags){
return result; return result;
} }
function putRating(rating){ function putRating(rating)
{
var result; var result;
result = '<div>'; result = '<div>';
for (var i = 0; i < rating; i++) for (var i = 0; i < rating; i++)
@ -237,14 +255,14 @@ var air = true;
var water = true; var water = true;
var locat = true; var locat = true;
function list_sort(sortOn){ function list_sort(sortOn)
{
switch (sortOn) { switch (sortOn) {
case '1': //number case '1': //number
if (number) { if (number) {
sort_it(sortOn, cmpNumAsc); sort_it(sortOn, cmpNumAsc);
number = 1 - number; number = 1 - number;
} } else {
else{
sort_it(sortOn, cmpNumDes); sort_it(sortOn, cmpNumDes);
number = 1 - number; number = 1 - number;
} }
@ -253,8 +271,7 @@ function list_sort(sortOn){
if (date) { if (date) {
sort_it(sortOn, cmpDateAsc); sort_it(sortOn, cmpDateAsc);
date = 1 - date; date = 1 - date;
} } else {
else{
sort_it(sortOn, cmpDateDes); sort_it(sortOn, cmpDateDes);
date = 1 - date; date = 1 - date;
} }
@ -263,8 +280,7 @@ function list_sort(sortOn){
if (time) { if (time) {
sort_it(sortOn, cmpTimeDes); sort_it(sortOn, cmpTimeDes);
time = 1 - time; time = 1 - time;
} } else {
else{
sort_it(sortOn, cmpTimeAsc); sort_it(sortOn, cmpTimeAsc);
time = 1 - time; time = 1 - time;
} }
@ -273,8 +289,7 @@ function list_sort(sortOn){
if (air) { if (air) {
sort_it(sortOn, cmpAtempDes); sort_it(sortOn, cmpAtempDes);
air = 1 - air; air = 1 - air;
} } else {
else{
sort_it(sortOn, cmpAtempAsc); sort_it(sortOn, cmpAtempAsc);
air = 1 - air; air = 1 - air;
} }
@ -283,8 +298,7 @@ function list_sort(sortOn){
if (water) { if (water) {
sort_it(sortOn, cmpWtempDes); sort_it(sortOn, cmpWtempDes);
water = 1 - water; water = 1 - water;
} } else {
else{
sort_it(sortOn, cmpWtempAsc); sort_it(sortOn, cmpWtempAsc);
water = 1 - water; water = 1 - water;
} }
@ -293,8 +307,7 @@ function list_sort(sortOn){
if (locat) { if (locat) {
sort_it(sortOn, cmpLocationDes); sort_it(sortOn, cmpLocationDes);
locat = 1 - locat; locat = 1 - locat;
} } else {
else{
sort_it(sortOn, cmpLocationAsc); sort_it(sortOn, cmpLocationAsc);
locat = 1 - locat; locat = 1 - locat;
} }
@ -302,46 +315,68 @@ function list_sort(sortOn){
} }
} }
function cmpLocationAsc(j,iSmaller){ function cmpLocationAsc(j, iSmaller)
{
return items[j].location < items[iSmaller].location; return items[j].location < items[iSmaller].location;
} }
function cmpLocationDes(j,iSmaller){ function cmpLocationDes(j, iSmaller)
{
return items[j].location > items[iSmaller].location; return items[j].location > items[iSmaller].location;
} }
function cmpNumAsc(j,iSmaller){ function cmpNumAsc(j, iSmaller)
{
return items[j].subsurface_number < items[iSmaller].subsurface_number; return items[j].subsurface_number < items[iSmaller].subsurface_number;
} }
function cmpNumDes(j,iSmaller){
function cmpNumDes(j, iSmaller)
{
return items[j].subsurface_number > items[iSmaller].subsurface_number; return items[j].subsurface_number > items[iSmaller].subsurface_number;
} }
function cmpTimeAsc(j,iSmaller){
function cmpTimeAsc(j, iSmaller)
{
return items[j].time < items[iSmaller].time; return items[j].time < items[iSmaller].time;
} }
function cmpTimeDes(j,iSmaller){
function cmpTimeDes(j, iSmaller)
{
return items[j].time > items[iSmaller].time; return items[j].time > items[iSmaller].time;
} }
function cmpDateAsc(j,iSmaller){
function cmpDateAsc(j, iSmaller)
{
return items[j].date < items[iSmaller].date; return items[j].date < items[iSmaller].date;
} }
function cmpDateDes(j,iSmaller){
function cmpDateDes(j, iSmaller)
{
return items[j].date > items[iSmaller].date; return items[j].date > items[iSmaller].date;
} }
function cmpAtempAsc(j,iSmaller){
function cmpAtempAsc(j, iSmaller)
{
return parseInt(items[j].temperature.air, 10) < parseInt(items[iSmaller].temperature.air, 10); return parseInt(items[j].temperature.air, 10) < parseInt(items[iSmaller].temperature.air, 10);
} }
function cmpAtempDes(j,iSmaller){
function cmpAtempDes(j, iSmaller)
{
return parseInt(items[j].temperature.air, 10) > parseInt(items[iSmaller].temperature.air, 10); return parseInt(items[j].temperature.air, 10) > parseInt(items[iSmaller].temperature.air, 10);
} }
function cmpWtempAsc(j,iSmaller){
function cmpWtempAsc(j, iSmaller)
{
return parseInt(items[j].temperature.water, 10) < parseInt(items[iSmaller].temperature.water, 10); return parseInt(items[j].temperature.water, 10) < parseInt(items[iSmaller].temperature.water, 10);
} }
function cmpWtempDes(j,iSmaller){
function cmpWtempDes(j, iSmaller)
{
return parseInt(items[j].temperature.water, 10) > parseInt(items[iSmaller].temperature.water, 10); return parseInt(items[j].temperature.water, 10) > parseInt(items[iSmaller].temperature.water, 10);
} }
function sort_it(sortOn,function_){ function sort_it(sortOn, function_)
{
var res = new Array(); var res = new Array();
var visited = new Array(itemsToShow.length); var visited = new Array(itemsToShow.length);
for (var j = 0; j < itemsToShow.length; j++) { for (var j = 0; j < itemsToShow.length; j++) {
@ -371,21 +406,25 @@ function sort_it(sortOn,function_){
// Searching // Searching
// //
////////////////////////////////////// //////////////////////////////////////
function Set(){ function Set()
{
this.keys = new Array(); this.keys = new Array();
} }
Set.prototype.contains = function(key){ Set.prototype.contains = function(key)
{
return (this.keys.indexOf(key) >= 0) ? true : false; return (this.keys.indexOf(key) >= 0) ? true : false;
} }
Set.prototype.push = function(key) { Set.prototype.push = function(key)
{
if (!this.contains(key)) { if (!this.contains(key)) {
this.keys.push(key); this.keys.push(key);
} }
}; };
Set.prototype.isEmpty = function() { Set.prototype.isEmpty = function()
{
return this.keys.length <= 0 ? true : false; return this.keys.length <= 0 ? true : false;
}; };
@ -393,7 +432,8 @@ Set.prototype.forEach = function(do_){
this.keys.forEach (do_); this.keys.forEach (do_);
}; };
Set.prototype.Union = function(another_set){ Set.prototype.Union = function(another_set)
{
if (another_set === null) { if (another_set === null) {
return; return;
} }
@ -404,18 +444,21 @@ Set.prototype.Union = function(another_set){
//////////////////////////////////////// ////////////////////////////////////////
function Node(value){ function Node(value)
{
this.children = new Array(); this.children = new Array();
this.value = value; this.value = value;
this.key = new Set(); this.key = new Set();
} }
/////////////////////////////////////// ///////////////////////////////////////
function Search_list_Modules(searchfor){ function Search_list_Modules(searchfor)
{
document.getElementById("search_input").value = searchfor; document.getElementById("search_input").value = searchfor;
SearchModules(searchfor); SearchModules(searchfor);
} }
function SearchModules(searchfor){ function SearchModules(searchfor)
{
var resultKeys = new Set(); //set var resultKeys = new Set(); //set
if (searchfor.length <= 0) { if (searchfor.length <= 0) {
@ -461,13 +504,16 @@ function SearchModules(searchfor){
viewInPage(); viewInPage();
} }
/////////////////////////////////////// ///////////////////////////////////////
function SearchModule(enabled){ function SearchModule(enabled)
{
this.head = new Node(); this.head = new Node();
this.enabled = enabled; this.enabled = enabled;
} }
SearchModule.prototype.Enter_search_string = function(str,diveno){ SearchModule.prototype.Enter_search_string = function(str, diveno)
if(str==""||!str) return; {
if (str == "" || !str)
return;
var res = str.toLowerCase().split(" "); var res = str.toLowerCase().split(" ");
for (var i = 0; i < res.length; i++) { for (var i = 0; i < res.length; i++) {
insertIn(res[i], diveno, this.head); insertIn(res[i], diveno, this.head);
@ -475,22 +521,27 @@ SearchModule.prototype.Enter_search_string = function(str,diveno){
} }
} }
SearchModule.prototype.Enter_search_tag = function(tags,diveno){ SearchModule.prototype.Enter_search_tag = function(tags, diveno)
if(!tags) return; {
if (!tags)
return;
for (var i = 0; i < tags.length; i++) { for (var i = 0; i < tags.length; i++) {
insertIn(tags[i], diveno, this.head); insertIn(tags[i], diveno, this.head);
numberofwords++; numberofwords++;
} }
} }
SearchModule.prototype.search = function(x){ SearchModule.prototype.search = function(x)
{
return searchin(x.toLowerCase(), this.head); return searchin(x.toLowerCase(), this.head);
} }
//////////////////////////////////////// ////////////////////////////////////////
function insertIn(value,key,node){ function insertIn(value, key, node)
{
node.key.push(key); node.key.push(key);
if(value.length<=0) return; if (value.length <= 0)
return;
var this_char = value[0]; var this_char = value[0];
value = value.substring(1, value.length); value = value.substring(1, value.length);
@ -505,8 +556,10 @@ function insertIn(value,key,node){
insertIn(value, key, node.children[i]); insertIn(value, key, node.children[i]);
} }
function searchin(value,node){ function searchin(value, node)
if(value.length<=0 || node.children.length <= 0) return node.key; {
if (value.length <= 0 || node.children.length <= 0)
return node.key;
var this_char = value[0]; var this_char = value[0];
value = value.substring(1, value.length); value = value.substring(1, value.length);
@ -523,7 +576,8 @@ function searchin(value,node){
var tripsShown; var tripsShown;
function toggleTrips(){ function toggleTrips()
{
var trip_button = document.getElementById('trip_button'); var trip_button = document.getElementById('trip_button');
if (tripsShown) { if (tripsShown) {
tripsShown = false; tripsShown = false;
@ -536,7 +590,8 @@ function toggleTrips(){
} }
} }
function showtrips(){ function showtrips()
{
var divelist = document.getElementById('diveslist'); var divelist = document.getElementById('diveslist');
divelist.innerHTML = ""; divelist.innerHTML = "";
for (var i = 0; i < trips.length; i++) { for (var i = 0; i < trips.length; i++) {
@ -548,7 +603,8 @@ function showtrips(){
} }
} }
function toggle_trip_expansion(trip){ function toggle_trip_expansion(trip)
{
if (trips[trip].expanded === true) { if (trips[trip].expanded === true) {
unexpand_trip(trip); unexpand_trip(trip);
} else { } else {
@ -556,7 +612,8 @@ function toggle_trip_expansion(trip){
} }
} }
function expand_trip(trip){ function expand_trip(trip)
{
trips[trip].expanded = true; trips[trip].expanded = true;
var d = document.getElementById("trip_dive_list_" + trip); var d = document.getElementById("trip_dive_list_" + trip);
for (var j in trips[trip].dives) { for (var j in trips[trip].dives) {
@ -565,13 +622,15 @@ function expand_trip(trip){
} }
} }
function unexpand_trip(trip){ function unexpand_trip(trip)
{
trips[trip].expanded = false; trips[trip].expanded = false;
var d = document.getElementById("trip_dive_list_" + trip); var d = document.getElementById("trip_dive_list_" + trip);
d.innerHTML =''; d.innerHTML ='';
} }
function getItems(){ function getItems()
{
var count = 0; var count = 0;
for (var i in trips) { for (var i in trips) {
for (var j in trips[i].dives) { for (var j in trips[i].dives) {
@ -602,11 +661,20 @@ var MAX_WIDTH;//dive duration, then its the maximum width for canvas
/** /**
*Return RGB css color string. *Return RGB css color string.
*/ */
function rgb(r, g, b){ function rgb(r, g, b)
{
r = Math.floor(r * 255); r = Math.floor(r * 255);
g = Math.floor(g * 255); g = Math.floor(g * 255);
b = Math.floor(b * 255); b = Math.floor(b * 255);
return ["rgb(",r,",",g,",",b,")"].join(""); return[
"rgb(",
r,
",",
g,
",",
b,
")"
].join("");
} }
/** /**
@ -614,7 +682,8 @@ function rgb(r, g, b){
*new scale = (old scale * height of canvas) / max height in dive *new scale = (old scale * height of canvas) / max height in dive
*to ensure that the dive profile is filling the whole area available *to ensure that the dive profile is filling the whole area available
*/ */
function scaleHeight(vari){ function scaleHeight(vari)
{
var height = document.getElementById("profileCanvas").height; var height = document.getElementById("profileCanvas").height;
max = MAX_HEIGHT; max = MAX_HEIGHT;
return (vari * height) / max; return (vari * height) / max;
@ -625,7 +694,8 @@ function scaleHeight(vari){
*new scale = (old scale * width of canvas) / max width in dive *new scale = (old scale * width of canvas) / max width in dive
*to ensure that the dive profile is filling the whole area available *to ensure that the dive profile is filling the whole area available
*/ */
function scaleWidth(vari){ function scaleWidth(vari)
{
var width = document.getElementById("profileCanvas").width; var width = document.getElementById("profileCanvas").width;
max = MAX_WIDTH; max = MAX_WIDTH;
return (vari * width) / max; return (vari * width) / max;
@ -635,7 +705,8 @@ function scaleWidth(vari){
*Show Axis information(Numbers on scale) *Show Axis information(Numbers on scale)
*put a Number every 300 second scaled to canvas width. *put a Number every 300 second scaled to canvas width.
*/ */
function canvas_showAxisInfo(){ function canvas_showAxisInfo()
{
var c = document.getElementById("profileCanvas"); var c = document.getElementById("profileCanvas");
var ctx = c.getContext("2d"); var ctx = c.getContext("2d");
ctx.font = "27px Georgia"; /*This is better be a variable scale*/ ctx.font = "27px Georgia"; /*This is better be a variable scale*/
@ -648,7 +719,8 @@ function canvas_showAxisInfo(){
*with spacing = 5 * 60 = 300 *with spacing = 5 * 60 = 300
*draw line every 5 minutes *draw line every 5 minutes
*/ */
function canvas_showGrid() { function canvas_showGrid()
{
var cnv = document.getElementById("profileCanvas"); var cnv = document.getElementById("profileCanvas");
var cnvWidth = cnv.width; var cnvWidth = cnv.width;
var cnvHeight = cnv.height; var cnvHeight = cnv.height;
@ -694,7 +766,8 @@ function canvas_showGrid() {
*and choose its color. *and choose its color.
*This is the function that should be used internally. *This is the function that should be used internally.
*/ */
function canvas_drawline(ctx,begin,end){ function canvas_drawline(ctx, begin, end)
{
drawline(ctx, begin, end, getcolor(begin, end)); drawline(ctx, begin, end, getcolor(begin, end));
} }
@ -702,7 +775,8 @@ function canvas_drawline(ctx,begin,end){
*Draw a line in the canvas with the given *Draw a line in the canvas with the given
*starting point, ending point, and color. *starting point, ending point, and color.
*/ */
function drawline(ctx,begin,end,col){ function drawline(ctx, begin, end, col)
{
ctx.strokeStyle = col; ctx.strokeStyle = col;
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(scaleWidth(begin[0]), scaleHeight(begin[1])); ctx.moveTo(scaleWidth(begin[0]), scaleHeight(begin[1]));
@ -714,19 +788,25 @@ function drawline(ctx,begin,end,col){
*Choose Color for different speeds. *Choose Color for different speeds.
*this need to be fixed to go with subsurface conversion. *this need to be fixed to go with subsurface conversion.
*/ */
function getcolor(begin,end){ function getcolor(begin, end)
{
var slope = (end[1] - begin[1]) / (end[0] - begin[0]); var slope = (end[1] - begin[1]) / (end[0] - begin[0]);
if (Math.abs(slope) > 300 ) return RED1; if (Math.abs(slope) > 300)
if (Math.abs(slope) > 180 ) return PIRATEGOLD1; return RED1;
if (Math.abs(slope) > 110 ) return RIOGRANDE1; if (Math.abs(slope) > 180)
if (Math.abs(slope) > 70 ) return LIMENADE1; return PIRATEGOLD1;
if (Math.abs(slope) > 110)
return RIOGRANDE1;
if (Math.abs(slope) > 70)
return LIMENADE1;
return CAMARONE1; return CAMARONE1;
} }
/** /**
*Return the HTML string for a dive cylinder entry in the table. *Return the HTML string for a dive cylinder entry in the table.
*/ */
function get_cylinder_HTML(cylinder){ function get_cylinder_HTML(cylinder)
{
return '<tr><td class="Cyl">' + cylinder.Type + '</td><td class="Cyl">' + cylinder.Size + '</td><td class="Cyl">' + cylinder.WPressure + '</td>' + return '<tr><td class="Cyl">' + cylinder.Type + '</td><td class="Cyl">' + cylinder.Size + '</td><td class="Cyl">' + cylinder.WPressure + '</td>' +
'<td class="Cyl">' + cylinder.SPressure + '</td><td class="Cyl">' + cylinder.EPressure + '</td><td class="Cyl">' + cylinder.O2 + '</td></tr>'; '<td class="Cyl">' + cylinder.SPressure + '</td><td class="Cyl">' + cylinder.EPressure + '</td><td class="Cyl">' + cylinder.O2 + '</td></tr>';
} }
@ -734,7 +814,8 @@ function get_cylinder_HTML(cylinder){
/** /**
*Return HTML table of cylinders of a dive. *Return HTML table of cylinders of a dive.
*/ */
function get_cylinders_HTML(dive){ function get_cylinders_HTML(dive)
{
var result = ""; var result = "";
result += '<h2>Dive equipments</h2><table><tr><td class="Cyl">Type</td><td class="Cyl">Size</td><td class="Cyl">Work Pressure</td><td class="Cyl">Start Pressure</td><td class="Cyl">End Pressure</td><td class="Cyl">O2</td></tr>'; result += '<h2>Dive equipments</h2><table><tr><td class="Cyl">Type</td><td class="Cyl">Size</td><td class="Cyl">Work Pressure</td><td class="Cyl">Start Pressure</td><td class="Cyl">End Pressure</td><td class="Cyl">O2</td></tr>';
for (var i in dive.Cylinders) { for (var i in dive.Cylinders) {
@ -747,7 +828,8 @@ function get_cylinders_HTML(dive){
/** /**
*Return HTML main data of a dive *Return HTML main data of a dive
*/ */
function get_dive_HTML(dive) { function get_dive_HTML(dive)
{
return '<h2>Dive Information</h2><table><tr><td class="words">Date: </td><td>' + dive.date + return '<h2>Dive Information</h2><table><tr><td class="words">Date: </td><td>' + dive.date +
'</td><td class="words">&nbsp&nbsp&nbsp&nbsp&nbspTime: </td><td>' + dive.time + '</td><td class="words">&nbsp&nbsp&nbsp&nbsp&nbspTime: </td><td>' + dive.time +
'</td><td class="words">&nbsp&nbsp&nbsp&nbsp&nbspLocation: </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\')\">' + '</td><td class="words">&nbsp&nbsp&nbsp&nbsp&nbspLocation: </td><td>' + '<a onclick=\"Search_list_Modules(\'' + dive.location + '\')\">' +
@ -768,7 +850,8 @@ function get_dive_HTML(dive) {
*Main canvas draw function *Main canvas draw function
*this calls the axis and grid initialization functions. *this calls the axis and grid initialization functions.
*/ */
function canvas_draw(){ function canvas_draw()
{
var c = document.getElementById("profileCanvas"); var c = document.getElementById("profileCanvas");
c.width = window.innerWidth; c.width = window.innerWidth;
c.height = window.innerHeight; c.height = window.innerHeight;
@ -791,7 +874,8 @@ function canvas_draw(){
*Hide the list and show the canvas view. *Hide the list and show the canvas view.
*this is called to view the dive details. *this is called to view the dive details.
*/ */
function showDiveDetails(dive){ function showDiveDetails(dive)
{
//set global variables //set global variables
dive_id = dive; dive_id = dive;
points = items[dive_id].samples; points = items[dive_id].samples;
@ -812,18 +896,21 @@ function showDiveDetails(dive){
*Show the list view and hide the detailed list view. *Show the list view and hide the detailed list view.
*this function have to clear any data saved by showDiveDetails *this function have to clear any data saved by showDiveDetails
*/ */
function unshowDiveDetails(dive){ function unshowDiveDetails(dive)
{
document.getElementById("diveListPanel").style.display = 'block'; document.getElementById("diveListPanel").style.display = 'block';
document.getElementById("divePanel").style.display = 'none'; document.getElementById("divePanel").style.display = 'none';
} }
function nextDetailedDive(){ function nextDetailedDive()
{
if (dive_id < items.length) { if (dive_id < items.length) {
showDiveDetails(++dive_id); showDiveDetails(++dive_id);
} }
} }
function prevDetailedDive(){ function prevDetailedDive()
{
if (dive_id > 0) { if (dive_id > 0) {
showDiveDetails(--dive_id); showDiveDetails(--dive_id);
} }