|
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<base target="_top"> |
|
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> |
|
<style> |
|
|
|
.back { |
|
float: left; |
|
} |
|
.forward { |
|
float: right; |
|
} |
|
.iframe-view { |
|
display: none; |
|
} |
|
|
|
</style> |
|
</head> |
|
<body> |
|
|
|
<div class="block" style="text-align:center"> |
|
<button class="back">back</button> |
|
|
|
Select the column with your urls: <select class="url-column"></select> |
|
|
|
<button class="forward">forward</button> |
|
</div> |
|
|
|
<div class="iframe-view"> |
|
<iframe height="450" width="690"></iframe> |
|
</div> |
|
|
|
<div class="error-view"> |
|
<h1>You need to select a column with URLs to Google Documents (Docs, Sheets, Forms)</h1> |
|
</div> |
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script> |
|
<script> |
|
$(document).ready(function() { |
|
var srcCount = 0, |
|
srcArray = []; |
|
|
|
google.script.run |
|
.withSuccessHandler(function(response) { |
|
|
|
response.forEach(function(each, ind) { |
|
|
|
$('.url-column').append('<option value="' + ind + '">' + each + '</option>'); |
|
|
|
}); |
|
}) |
|
.getUrlColumn(); |
|
|
|
//set events |
|
$('.forward').click(goForward); |
|
$('.back').click(goBack); |
|
$('.url-column').change(setUrlColumn); |
|
|
|
//move functions |
|
function goForward() { |
|
|
|
if(srcCount < srcArray.length) { |
|
srcCount++; |
|
$('iframe').attr('src', srcArray[srcCount]); |
|
} |
|
|
|
} |
|
|
|
function goBack() { |
|
|
|
if(srcCount < srcArray.length) { |
|
|
|
srcCount--; |
|
$('iframe').attr('src', srcArray[srcCount]); |
|
|
|
} |
|
|
|
} |
|
|
|
//set the column to pull URLs from |
|
function setUrlColumn() { |
|
|
|
google.script.run |
|
.withSuccessHandler(function(response) { |
|
|
|
srcArray = response; |
|
|
|
//make sure that the column has google docs links in it |
|
if(testGoogleUrl(srcArray[0])) { |
|
|
|
toggleViews(); |
|
$('iframe').attr('src', srcArray[0]); |
|
|
|
} else { |
|
|
|
toggleViews(); |
|
|
|
} |
|
|
|
}) |
|
.getUrls($('.url-column').val()); |
|
} |
|
|
|
function testGoogleUrl(url) { |
|
|
|
return (url.match(/(https:\/\/docs\.google\.com\/)/)) ? true : false; |
|
|
|
} |
|
|
|
function toggleViews() { |
|
$('.error-view').toggle(); |
|
$('.iframe-view').toggle(); |
|
} |
|
|
|
}); |
|
</script> |
|
</body> |
|
</html> |