Chrome Storage API keys getting reset - google-chrome

I am developing my first chrome extension. It highlights the words that are passed to it. I used storage API to save a few objects so when I open the extension again, it will retain what I highlighted. but once in a while, they get reset to the first string value of the object only.
https://www.screencast.com/t/0jF6AtCc
I went through the code for hours but there is nothing that could be doing this. i have tried them reassigning them in multiple places but nothing helped. There are no errors in both consoles.
popup.js
var rstr = [];
var rnum = [];
var rcolor = [];
var rfont = [];
chrome.storage.local.get(['htxt', 'hnum', 'hcolor', 'hfont'], function(result) {
if (result.hnum != null) {
rnum = (result.hnum);
rcolor = (result.hcolor);
rfont = (result.hfont);
rstr = (result.htxt);
}
if (rstr.length > 0) {
document.getElementById('tbl').innerHTML = '<tr><td>Search Key</td><td style="width: 25px;">Score</td><td></td><td></td></tr>';
for (var j = 1; j <= rstr.length; j++) {
document.getElementById('tbl').innerHTML += '<tr><td><input type="text" id="txt' + j + '"></input></td><td><input type="text" id="num' + j + '" style="width: 25px;" value=0></input></td><td><input type="color" id="bg' + j + '" style="width: 15px;"> </td> <td> <input type="color" id="font' + j + '" style="width: 15px;"> </td> </tr> ';
}
for (var j = 1; j <= rstr.length; j++) {
document.getElementById("txt" + j).value = rstr[j - 1];
document.getElementById("num" + j).value = rnum[j - 1];
document.getElementById("bg" + j).value = rcolor[j - 1];
document.getElementById("font" + j).value = rfont[j - 1];
}
}
colorarr = ["#b1c7fd", "#ddfdb1", "#fdb1f3", "#b1fdf0", "#fddab1", "#c4b1fd", "#b4fdb1", "#FFFF00", "#FFA500"];
function getRandomColor() {
return colorarr[Math.floor(Math.random() * 9)];
}
document.getElementById("bg1").value = getRandomColor();
var i = 2;
var txt = [];
var num = [];
var color = [];
var font = [];
document.getElementById('btn').addEventListener('click', function() {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(activeTabs) {
txt = [];
num = [];
color = [];
font = [];
for (var j = 1; j < i; j++) {
if (document.getElementById("txt" + j).value != null) {
txt.push(document.getElementById("txt" + j).value);
num.push(document.getElementById("num" + j).value);
color.push(document.getElementById("bg" + j).value);
font.push(document.getElementById("font" + j).value);
}
}
chrome.storage.local.set({
"htxt": txt
});
chrome.storage.local.set({
"hnum": num
});
chrome.storage.local.set({
"hcolor": color
});
chrome.storage.local.set({
"hfont": font
});
chrome.tabs.executeScript(null, {
code: "var str=" + JSON.stringify(txt) + ";var numjson=" + JSON.stringify(num) + ";var color=" + JSON.stringify(color) + ";var font=" + JSON.stringify(font) + ";"
}, function() {
chrome.tabs.executeScript(null, {
file: 'highlight.js'
}, function(results) {
if (results != null) {
document.getElementById('scorevalue').innerHTML = results[0];
chrome.browserAction.setBadgeText({
text: results[0] ? results[0].toString() : "0"
});
}
});
});
});
});
document.getElementById('add').addEventListener('click', function() {
var tr = document.createElement('tr');
tr.innerHTML = '<td><input type="text" id="txt' + i + '"></input></td><td><input type="text" id="num' + i + '" style="width: 25px;" value=0></input></td><td><input type="color" id="bg' + i + '" style="width: 15px;"> </td> <td> <input type="color" id="font' + i + '" style="width: 15px;"> </td> ';
document.getElementById('tbl').appendChild(tr);
document.getElementById("bg" + i).value = getRandomColor();
i++;
});
document.getElementById('delete').addEventListener('click', function() {
chrome.storage.local.remove(['htxt', 'hnum', 'hcolor', 'hfont'], function() {
var error = chrome.runtime.lastError;
if (error) {
console.error(error);
}
})
document.getElementById('tbl').innerHTML = '<tr><td>Search Key</td><td style="width: 25px;">Score</td><td></td><td></td></tr>';
document.getElementById('tbl').innerHTML += '<tr><td><input type="text" id="txt1"></input></td><td><input type="text" id="num1" style="width: 25px;" value=0></input></td><td><input type="color" id="bg1" style="width: 15px;"> </td> <td> <input type="color" id="font1" style="width: 15px;"> </td> </tr> ';
chrome.tabs.getSelected(null, function(tab) {
var code = 'window.location.reload();';
chrome.tabs.executeScript(tab.id, {
code: code
});
});
});
document.getElementById('bulk').addEventListener('click', function() {
document.getElementById('bulkdiv').innerHTML = "<textarea rows='4' cols='50' id='bulktext'></textarea><input id='bulkbtn' type=button value='Fill Up'>"
document.getElementById('bulkbtn').addEventListener('click', function() {
var res = document.getElementById('bulktext').value.split("\n");
i = res.length + 1;
document.getElementById('tbl').innerHTML = '<tr><td>Search Key</td><td style="width: 25px;">Score</td><td></td><td></td></tr>';
for (var j = 1; j < i; j++) {
document.getElementById('tbl').innerHTML += '<tr><td><input type="text" id="txt' + j + '"></input></td><td><input type="text" id="num' + j + '" style="width: 25px;" value=0></input></td><td><input type="color" id="bg' + j + '" style="width: 15px;"> </td> <td> <input type="color" id="font' + j + '" style="width: 15px;"> </td> </tr> ';
}
for (var j = 1; j < i; j++) {
document.getElementById("txt" + j).value = res[j - 1].trim();
document.getElementById("bg" + j).value = getRandomColor();
}
console.log(res);
});
});
});
Highlight.js
function highlight(container, what, spanClass) {
var content = container.innerHTML,
pattern = new RegExp('(>[^<.]*)(' + what + ')([^<.]*)', 'gi'),
replaceWith = '$1<span ' + (spanClass ? 'style=background:' + spanClass + ';' : '') + '">$2</span>$3',
highlighted = content.replace(pattern, replaceWith);
return (container.innerHTML = highlighted) !== content;
}
function num(container, what) {
if ((container.innerHTML.match(new RegExp('(>[^<.]*)(' + what + ')([^<.]*)', "gi"))) != null) return container.innerHTML.match(new RegExp('(>[^<.]*)(' + what + ')([^<.]*)', "gi")).length;
return 0;
}
chrome.storage.local.remove(['htxt', 'hnum', 'hcolor', 'hfont'], function() {
var error = chrome.runtime.lastError;
if (error) {
console.error(error);
}
var score = 0;
for (var i = 0; i < str.length; i++) {
if (str[i] != '') {
console.log("inside highlight.js");
console.log(str[i]);
highlight(document.getElementsByTagName('body')[0], str[i], color[i]);
score += num(document.getElementsByTagName('body')[0], str[i]) * numjson[i];
}
}
chrome.storage.local.set({
"htxt": str
});
chrome.storage.local.set({
"hnum": numjson
});
chrome.storage.local.set({
"hcolor": color
});
chrome.storage.local.set({
"hfont": font
});
score;
});
There is an inject.js also which run on all pages with similar code to highlight.js. It was made so that pages get highlighted even when someone navigate away or reload the page. It is also accessing the Chrome Storage API.
Only popup.js have code to modify the key pairs in storage API but it still somehow get changed to the first string. Please help.
Here is an unpacked version of it.
https://drive.google.com/file/d/1icG6pa9xTGAJ6DO2Wgwn7LE5yG8CSRzz/

Related

Django CreateView form can't submit

My views:
class AddSuiteView(CreateView):
model = TestSuite
form_class = TestSuiteForm
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
my_TestCase = TestCase.objects.all()
context['my_testcase'] = my_TestCase
return context
def get_success_url(self):
return reverse("integratedTest:testSuite")
My form.py:
class TestSuiteForm(forms.ModelForm):
class Meta:
model = TestSuite
fields = ( 'name', 'test_case_list', 'created_by' )
My model is:
class TestSuite(models.Model):
name = models.CharField(max_length=200)
test_case_list = models.CharField(max_length=200, validators=[validate_comma_separated_integer_list], default = "1")
created_by = models.CharField(max_length=200, default = "anyone")
create_datetime = models.DateTimeField("TestSuite created on", auto_now = True)
class TestCase(models.Model):
name = models.CharField(max_length=200)
.....
My html is a bit complex:
<form method="post">
{% csrf_token %}
<script src="https://code.jquery.com/jquery-3.5.0.min.js"></script>
<h1 class="addsuite">Create Test Suite:</h1>
<p>
<label for="id_name">Name:</label>
<input type="text" id="id_name" name="name" required><br><br>
</p>
<p>
<label for="id_test_case_list_select_l">test_case_list(double click to add):</label><br><br>
<select size=10 name="test_case_list_select_l" id="id_test_case_list_select_l" class="multiselect" multiple="multiple" >
{%for case in my_testcase %}
<option value="{{case.name}}" >{{case.name}}</option>
{%endfor %}
</select>
<br><br>
<label for="id_test_case_list_select_r" >test case selected(double click to remove):</label><br>
<select size=10 name="test_case_list_select_r" id="id_test_case_list_select_r" class="multiselect" multiple="multiple" >
</select>
<input type="hidden" id="id_test_case_list" name="test_case_list" value="">
</p>
<p>⇧
<input type="button" id="addTestcaseByOne" value="++" onclick="addTestcaseByOne">
</p>
<p>⇩
<input type="button" id="decreaseTestcaseByOne" value="--" onclick="decreaseTestcaseByOne">
</p>
<br><br>
<p>
<label for="id_created_by">created_by:</label>
<input type="text" id="id_created_by" name="created_by" "><br><br>
</p>
<input type="submit" value="Save">
</form>
<script>
$(document).ready(function() {
$("#id_test_case_list_select_l").dblclick(function() {
var selectedItem = $('#id_test_case_list_select_l').find(":selected").text()
$('#id_test_case_list_select_r').append
('<option value= ' + selectedItem + '"*1">'+selectedItem+'*1</option>')
var old_val = $('#id_test_case_list').val()
//alert("old_val" + old_val)
var new_val = ""
if (old_val.length == 0){
new_val = selectedItem + "*1"
}
else{
new_val = old_val + "," + selectedItem + "*1"
}
//alert("new_val:" + new_val)
$('#id_test_case_list').val(new_val)
});
});
$(document).ready(function() {
$("#id_test_case_list_select_r").dblclick(function() {
select_str = $('#id_test_case_list_select_r').find(":selected").text()
//alert("select_str:"+select_str)
var textArry = select_str.split("*")
if( textArry.length == 2 ){
var rep = parseInt(textArry[1])
//alert("rep:"+rep)
if( rep==1 ){
var old_val = $('#id_test_case_list').val()
//alert("old_val:" + old_val)
var indexSel = $("#id_test_case_list_select_r").prop('selectedIndex')
//alert("indexSel:"+indexSel)
var textArry_oldlist = old_val.split(",")
var new_val = ""
for( let i = 0; i < textArry_oldlist.length; i++ ){
if(i == indexSel){
continue
}
else{
if (new_val.length == 0){
new_val = textArry_oldlist[i]
}else{
new_val = new_val + "," + textArry_oldlist[i]
}
}
//alert("new_val:" + new_val)
}
//alert("new_val:" + new_val)
$('#id_test_case_list').val(new_val)
$('#id_test_case_list_select_r').find(":selected").remove()
}
}
});
});
$(document).ready(function() {
$("#addTestcaseByOne").click(function() {
var optionLength = $('#id_test_case_list_select_r').find('option').length
if(optionLength>=1){
select_str = $('#id_test_case_list_select_r').find(":selected").text()
var textArry = select_str.split("*")
if( textArry.length == 2 ){
var rep = parseInt(textArry[1]) + 1
var new_text = textArry[0] + "*" + rep
$('#id_test_case_list_select_r').find(":selected").text(new_text)
var new_val = textArry[0] + "*" + rep
$('#id_test_case_list_select_r').find(":selected").val(new_val)
var indexSel = $("#id_test_case_list_select_r").prop('selectedIndex')
//alert("indexSel:"+indexSel)
var old_val = $('#id_test_case_list').val()
//alert("old_val:" + old_val)
var textArry_oldlist = old_val.split(",")
var new_val_list = ""
for( let i = 0; i < textArry_oldlist.length; i++ ){
if(i == indexSel){
if (new_val_list.length == 0){
new_val_list = new_val
}else{
new_val_list = new_val_list + "," + new_val
}
}
else{
if (new_val_list.length == 0){
new_val_list = textArry_oldlist[i]
}else{
new_val_list = new_val_list + "," + textArry_oldlist[i]
}
}
}
//alert("new_val_list:" + new_val_list)
$('#id_test_case_list').val(new_val_list)
}
}
});
});
$(document).ready(function() {
$("#decreaseTestcaseByOne").click(function() {
var optionLength = $('#id_test_case_list_select_r').find('option').length
if(optionLength>=1){
select_str = $('#id_test_case_list_select_r').find(":selected").text()
var selectedTextSpls = select_str.split("*")
if( selectedTextSpls.length == 2 ){
var rep = parseInt(selectedTextSpls[1])
if( rep>1 ){
rep = rep - 1
var new_text = selectedTextSpls[0] + "*" + rep
$('#id_test_case_list_select_r').find(":selected").text(new_text)
var new_val = selectedTextSpls[0] + "*" + rep
$('#id_test_case_list_select_r').find(":selected").val(new_val)
var indexSel = $("#id_test_case_list_select_r").prop('selectedIndex')
//alert("indexSel:"+indexSel)
var old_hidden_val = $('#id_test_case_list').val()
//alert("old_hidden_val:" + old_hidden_val)
var textArry_oldlist = old_hidden_val.split(",")
var new_val_list = ""
for( let i = 0; i < textArry_oldlist.length; i++ ){
if(i == indexSel){
if (new_val_list.length == 0){
new_val_list = new_val
}else{
new_val_list = new_val_list + "," + new_val
}
}
else{
if (new_val_list.length == 0){
new_val_list = textArry_oldlist[i]
}else{
new_val_list = new_val_list + "," + textArry_oldlist[i]
}
}
}
//alert("new_val_list:" + new_val_list)
$('#id_test_case_list').val(new_val_list)
}else if( rep==1 ){
var indexSel = $("#id_test_case_list_select_r").prop('selectedIndex')
//alert("indexSel:"+indexSel)
var old_hidden_val = $('#id_test_case_list').val()
//alert("old_hidden_val:" + old_hidden_val)
var textArry_oldlist = old_hidden_val.split(",")
var new_val_list = ""
for( let i = 0; i < textArry_oldlist.length; i++ ){
if(i == indexSel){
continue
}
else{
if (new_val_list.length == 0){
new_val_list = textArry_oldlist[i]
}else{
new_val_list = new_val_list + "," + textArry_oldlist[i]
}
}
}
//alert("new_val_list:" + new_val_list)
$('#id_test_case_list').val(new_val_list)
$('#id_test_case_list_select_r').find(":selected").remove()
}
}
}
});
});
</script>
Details: Upper list selection(name="test_case_list_select_l") is a full list. Double clicking options in upper list can add a same named one to the lower list(name="test_case_list_select_r") and the hidden input(name="test_case_list") get a new value. Hopefully, the hidden input will update the field test_case_list
The code seems good to me, but unfortunately it can't save. After input everything and click save the button, the page never redirect and model TestSuite have no new record. The selected list becomes empty immediately instead.
P.S. My form.html is coming from the Django tutorial:
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save">
</form>
I add an additional button to test the value to be submitted.
<input type="submit" value="test" onclick="testButton()">
script as:
function testButton(){
valu = $('#id_test_case_list').val()
alert("valu:" + valu)
}
After select some cases, the first click button shows valu is the correct strings as I expected. But the selected list is cleared immediately after the button click. The repeatedly clicking of testButton also displays valu as blank.
I resolved this issue after I modified the model from test_case_list = models.CharField(max_length=200, validators=[validate_comma_separated_integer_list], default = "1")
to
test_case_list = models.CharField(max_length=200, default = "1")
by which I deleted the validators=[validate_comma_separated_integer_list].
I forgot it's not comma_separated_integer_list but comma_separated_string_list, I didn't know if there's any comma_separated_string_list
action="/your-name/" is missing in your form tag.
<form action="/your-route" method="post">
.
.
.
<button type="submit">Submit</button>
</form>

How to get min/max values for two data sets in one canvasJS chart

I have a chart with two data sets and I am trying to get the min/max values for both data sets but for the moment I don't even get for any of the data sets!
With the same principle of code for one data set graph it work perfectly.
See my code for two data set graph:
window.onload = function() {
// first data set for PM2.5
var $dataPointsP2m5 = <?php echo json_encode($dataPoints_p2m5, JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION | JSON_NUMERIC_CHECK); ?>;
// second data set for PM1.0
var $dataPointsP1m0 = <?php echo json_encode($dataPoints_p1m0, JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION | JSON_NUMERIC_CHECK); ?>;
var chartPm = new CanvasJS.Chart("chartContainer_pm", {
zoomEnabled: true,
theme: "light2",
title: {
text: "Air Quality Index PM2.5 & PM1.0"
},
axisX:{
title: "chart updates every " + updateInterval / 1000 + " secs"
},
axisY:{
suffix: " μg/m3"
},
data: [
{
type: "line",
yValueFormatString: "##.##",
xValueFormatString: "hh:mm:ss TT",
showInLegend: true,
legendText: "{name} " + yValueP2m5 + " μg/m3",
toolTipContent: "{y} μg/m3",
dataPoints: $dataPointsP2m5
},
{
type: "line",
yValueFormatString: "##.##",
xValueFormatString: "hh:mm:ss TT",
showInLegend: true,
legendText: "{name} " + yValueP1m0 + " μg/m3",
toolTipContent: "{y} μg/m3",
dataPoints: $dataPointsP1m0
}]
});
chartPm.render();
document.getElementById("getMinMaxdataPoints").addEventListener("click",function(){
var maxYp2m5 = -Infinity;
var minYp2m5 = Infinity;
var viewportMinimum = chartPm.axisX[0].get("viewportMinimum");
var viewportMaximum = chartPm.axisX[0].get("viewportMaximum");
for(var i = 0; i < chartPm.data[0].dataPoints.length; i++){
if(chartPm.data[0].dataPoints[i].x >= viewportMinimum && chartPm.data[0].dataPoints[i].x <= viewportMaximum && chartPm.data[0].dataPoints[i].y > maxYp2m5){
maxYp2m5 = charPm.data[0].dataPoints[i].y;
}
if(chartPm.data[0].dataPoints[i].x >= viewportMinimum && chartPm.data[0].dataPoints[i].x <= viewportMaximum && chartPm.data[0].dataPoints[i].y < minYp2m5){
minYp2m5 = chartPm.data[0].dataPoints[i].y;
}
}
document.getElementById("MinimumP2m5Value").innerHTML = " min. "+ minYp2m5;
document.getElementById("MaximumP2m5Value").innerHTML = " max. "+ maxYp2m5;
});
and my html part is:
<body>
<div class="flex-container">
<div>
<button id="getMinMaxdataPoints">Get min/max.</button><br/>
</div>
<div>
<span>PM2.5 & PM1.0</span><br/>
<span id="MinimumP2m5Value"></span><br/>
<span id="MaximumP2m5Value"></span><br/>
</div>
</div>
</body>
In the above code, you have just looped through the dataPoints of first dataSeries. Whereas, you need to first loop through each dataSeries then through the respective dataPoints.
Here is a JSFiddle example for the same.
document.getElementById("getMinMaxdataPoints").addEventListener("click",function(){
var minContent = "";
var maxContent = "";
var viewportMinimum = chart.axisX[0].get("viewportMinimum");
var viewportMaximum = chart.axisX[0].get("viewportMaximum");
for( i = 0; i < chart.data.length; i++){
var maxYp2m5 = -Infinity;
var minYp2m5 = Infinity;
for(var j = 0; j < chart.data[i].dataPoints.length; j++){
if(chart.data[i].dataPoints[j].x >= viewportMinimum && chart.data[i].dataPoints[j].x <= viewportMaximum && chart.data[i].dataPoints[j].y > maxYp2m5){
maxYp2m5 = chart.data[i].dataPoints[j].y;
}
if(chart.data[i].dataPoints[j].x >= viewportMinimum && chart.data[i].dataPoints[j].x <= viewportMaximum && chart.data[i].dataPoints[j].y < minYp2m5){
minYp2m5 = chart.data[i].dataPoints[j].y;
}
}
minContent += "Series " + (i + 1) + " min. Y value " + minYp2m5 + " | ";
maxContent += "Series " + (i + 1) + " max. Y value " + maxYp2m5 + " | ";
}
document.getElementById("MinimumYValue").innerHTML = minContent;
document.getElementById("MaximumYValue").innerHTML = maxContent;
});

Creating A Worksheet Generator

I hope you are having a great day!
I have an ecommerce website with pdfs and ebooks for sale. We are based on "education" and we have seen a few websites that have worksheet generators. We tried using httrack to see how they made the script but nothing worked. We would love some help in how does it work and are there any tutorials for that type of task. Thanks and have a great day!
Edit: We forgot to say, we want something similar to education.com
I think this code useful for you....
code.
<html>
<head>
<title>Math WorkSheet</title>
<script type="text/javascript">
// For: http://codingforums.com/showthread.php?t=184125
var NProblems = 25;
var xvals = [];
var yvals = [];
for (var i = 0; i < NProblems; i++) {
// xvals.push(i); yvals.push(i+1); // limit to problem values to (0,1) ... 25
xvals.push(i % 10);
yvals.push((i % 10) + 1); // limit to single digit problems
}
function MakeTable(act) {
var tmp = '';
var str = '<table border="1" width="80%"><tr>';
i = 0;
while (i < NProblems) {
x = xvals[i];
y = yvals[i];
str += '<td align="right">' + x;
if (act == 'add') {
str += '<br>+ ' + y;
tmp = x + y;
}
if (act == 'sub') {
str += '<br>- ' + y;
tmp = x - y;
}
if (act == 'mul') {
str += '<br>* ' + y;
tmp = x * y;
}
if (act == 'div') {
str += '<br>/ ' + y;
tmp = (x / y).toFixed(2);
}
str += '<br>_____';
if (document.getElementById('answers').checked) {
str += '<br>' + tmp;
} else {
str += '<br> '
}
str += '<br> </td>';
i++;
if ((i % 5) == 0) {
str += '</tr><tr>';
}
}
str += '</tr></table>';
return str;
}
function GenerateWS() {
var x = 0;
var y = 0;
var str = '';
var str = '';
var sel = document.getElementById('MathAction').value;
switch (sel) {
case 'add':
str += MakeTable(sel);
break;
case 'sub':
str += MakeTable(sel);
break;
case 'mul':
str += MakeTable(sel);
break;
case 'div':
str += MakeTable(sel);
break;
default:
alert('No choice selected');
break;
}
document.getElementById('TBL').innerHTML = str;
}
function randOrd() {
return (Math.round(Math.random()) - 0.5);
}
function NewSet() {
xvals.sort(randOrd);
yvals.sort(randOrd);
}
</script>
</head>
<body>
<select id="MathAction">
<option value="add">Addition</option>
<option value="sub">Subtraction</option>
<option value="mul">Multiplication</option>
<option value="div">Division</option>
</select>
<button onclick="NewSet()">New worksheet</button>
<input type="checkbox" id="answers">Show Answers
<button onclick="GenerateWS()">Generate Worksheet</button>
<div id="TBL"></div>
</body>
</html>

Get total rows filtered by if() statement in google apps scripts

I've got this fn().
Is there any simple way to return the number of filtered rows by this conditional statement in Google app scripts?
function getGlobers(globers, project){
var body = "";
var data = globers.getValues();
for( i = 0; i < data.length; i++ ){
if( data[i][2] == project ){
body += "<tr><td style=" + STYLE.TD + ">" + data[i].join("</td><td style=" + STYLE.TD + ">") + "</td></tr>";
}
}
return body;
}
Thanks.
for example (see comments in code)
function getGlobers(globers, project){
var body = "";
var n = 0; // use a variable to count
var data = globers.getValues();
for( i = 0; i < data.length; i++ ){
if( data[i][2] == project ){
n++;// increment each time condition is true
body += "<tr><td style=" + STYLE.TD + ">" + data[i].join("</td><td style=" + STYLE.TD + ">") + "</td></tr>";
}
}
return [body,n];// return an array of 2 values
}
Usage :
var result = getGlobers(range,project);
Logger.log('array result = '+result);
Logger.log('body (string) = '+result[0]);
Logger.log('length (integer) = '+result[1]);
note : instead of an array you could also return an object with 2 properties... a matter of choice.
EDIT : an example using object properties :
function getGlobers(globers, project){
var body = "";
var n = 0;
var result = {};
var data = globers.getValues();
for( i = 0; i < data.length; i++ ){
if( data[i][2] == project ){
n++;
body += "<tr><td style=" + STYLE.TD + ">" + data[i].join("</td><td style=" + STYLE.TD + ">") + "</td></tr>";
}
}
result['body'] = body;
result['length'] = n;
return result;
}
Usage :
var result = getGlobers(range,project);
Logger.log('body = '+result.body);
Logger.log('length = '+result.length);

Google maps zoom broken

I've created a Google Maps overlay, but for some reason the zoom slider in the top-left of the map has stopped working. Have been trying to pick apart the code to fix it, but can't seem to find what is broken. Can someone have a look to see what I'm missing?
http://www.ucl.ac.uk/study/virtualtours/
My code is here:
<script type="text/javascript">
google.load("maps", "2");
google.load("jquery", "1.4.2");
var map;
var camera;
var side_bar_html = "";
var gmarkers = [];
function TileToQuadKey ( tx, ty, zl){
var quad = "";
for (var i = zl; i > 0; i--) {
var mask = 1 << (i - 1);
var cell = 0;
if ((tx & mask) != 0) cell++;
if ((ty & mask) != 0) cell += 2;
quad += cell;
}
return quad;
}
var uclvtTiles = function (a,b) {
var f = "http://www.ucl.ac.uk/prosp-students/access/virtual-tour/tourlayers/" + TileToQuadKey(a.x,a.y,b) + ".png";
return f;
}
function createUclVTSatMapType() {
var uclvtHybridLayer = new Array();
uclvtHybridLayer[0] = G_NORMAL_MAP.getTileLayers()[0];
uclvtHybridLayer[1] = new GTileLayer(new GCopyrightCollection('') , 17, 17);
uclvtHybridLayer[1].getTileUrl = uclvtTiles;
uclvtHybridLayer[1].getCopyright = function(a,b) {return "University College London, 2010";};
uclvtHybridLayer[1].getOpacity = function () {return 0.97;};//opacity of the non transparent part
if(navigator.userAgent.indexOf("MSIE") == -1) {
uclvtHybridLayer[1].isPng = function() {return true;};
}
var uclvtSatMap = new GMapType(
uclvtHybridLayer,
G_NORMAL_MAP.getProjection(),
'UCL Map',
{errorMessage:"", alt:"Show imagery with UCL Map"});
uclvtSatMap.getTextColor = function() {return "#000000";};
return uclvtSatMap;
}
function myclick(i) {
GEvent.trigger(gmarkers[i], 'click');
}
function addMarker(point, title, video, details) {
var marker = new GMarker(point, {title: title, icon:camera});
GEvent.addListener(marker, "click", function() {
if (details) {
marker.openInfoWindowTabsHtml([new GInfoWindowTab("Video", video),
new GInfoWindowTab("More", details)]);
} else {
marker.openInfoWindowHtml(video);
}
});
var id = gmarkers.length;
gmarkers.push(marker);
map.addOverlay(marker);
return id;
}
function flashMovieHTML(title, file) {
return '<div style="width:335px; height:260px">' +
'<b>' + title + '</b>' +
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="325" height="244" ' +
'id="' + title + '" ' +
'title="' + title + '">' +
'<param name="movie" value="http://www.ucl.ac.uk/prosp-students/access/virtual-tour/' + file + '" />' +
'<param name="quality" value="high" />' +
'<param name="wmode" value="opaque" />' +
'<param name="swfversion" value="8.0.35.0" />' +
'<embed src="http://www.ucl.ac.uk/prosp-students/access/virtual-tour/' + file + '" ' +
'quality="high" ' +
'width="325" ' +
'height="244" ' +
'name="' + title + '" ' +
'type="application/x-shockwave-flash" ' +
'pluginspage="http://www.macromedia.com/go/getflashplayer">' +
'</embed>' +
'</object>' +
'</div>';
}
function addMarkersToMap() {
GDownloadUrl('campus.xml', function(doc) {
var xmlDoc = GXml.parse(doc);
var locations = xmlDoc.documentElement.getElementsByTagName("location");
var currentCategory = "";
for (var i = 0; i < locations.length; i++) {
var lat = parseFloat(locations[i].getAttribute("lat"));
var lng = parseFloat(locations[i].getAttribute("lng"));
var point = new GLatLng(lat,lng);
var title = locations[i].getAttribute("title");
var menu = locations[i].getAttribute("menu");
var video = locations[i].getAttribute("video");
var category = locations[i].getAttribute("category");
var details = locations[i].childNodes.length == 0 ? null :
'<div style="width:335px; height:260px">' +
locations[i].childNodes[0].nodeValue +
'</div>';
var id = addMarker(point, title, flashMovieHTML(title, video), details);
if (category != currentCategory) {
if (id > 0) {
side_bar_html += '</ul></div></div>';
}
side_bar_html += '<div class="collapsable">';
side_bar_html += '<h4 class="toggleCollapsableContent">' + category + '</h4>';
side_bar_html += '<div class="collapsableContent"><ul>';
}
side_bar_html += '<li><a href="javascript:myclick(' + id + ')">' + menu + '<\/a></li>';
currentCategory = category;
}
side_bar_html += '</ul></div></div>';
document.getElementById("right").innerHTML = side_bar_html;
$("h4.toggleCollapsableContent:gt(0)")
.addClass('closed')
.next('.collapsableContent').hide();
$("h4.toggleCollapsableContent").click(function () {
if ($(this).next($(".collapsableContent")).is(":hidden")) {
$(this).next($(".collapsableContent")).slideDown("fast");
$(this).removeClass("closed");
} else {
$(this).next($(".collapsableContent")).slideUp("fast");
$(this).addClass("closed");
}
});
});
}
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("mapDiv"));
map.setCenter(new GLatLng(51.52484592590448, -0.13345599174499512), 17);
map.setUIToDefault();
var uclvtSatMapType = createUclVTSatMapType()
map.addMapType(uclvtSatMapType);
map.setMapType(uclvtSatMapType);
camera = new GIcon(G_DEFAULT_ICON);
camera.image = "ucl-video.png";
camera.iconSize = new GSize(32,37);
camera.iconAnchor = new GPoint(16,35);
camera.infoWindowAnchor = new GPoint(16,2);
addMarkersToMap();
}
}
google.setOnLoadCallback(initialize);
Cheers,
G
The div that holds this image
http://www.ucl.ac.uk/prosp-students/access/virtual-tour/campus-map-key.png
is positioned absolutely above the map and it blocking access to everything underneath it.
This may help you:
#map img{max-width: inherit;}