How to import Clipboard.js library into Google Script application?

Since manipulating the clipboard is prohibited in a Google application, I want to find a workaround using the Clipboard.js library.

My questions:

1. How to import Clipboard.js library into Google Script application?

2. And how to call functions on other pages (for example, try to call the calculateWeight () function from BMI.gs in index.html?

What I tried:

I tried pasting the Clipboard.js source code into the Clipboard.js.html file and putting everything inside the tag.

What I want to achieve:

Copy the text string by pressing the "COPY" button.

β†’ what I want to achieve

I spent several hours searching for solutions, but still can not find the relevant information. Any help would be greatly appreciated. Thank!

+4
1

script html , HTML Services: Best Practices, HTML, CSS ( ) Javascript . index.html HTML- . , :

<!DOCTYPE html>
<html>
  <head>
  <script src="//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.4.0/clipboard.min.js"></script>
    <?!= include('myCSS'); ?>
    <title>Give it a Title</title>
  </head>
  <body>
      ...
      All the Body stuff
      ...
  </body>
    <?!= include('myScript'); ?>
</html>

JS . , - clipboard.js. clipboard.js. :

<?!= include('myCSS'); ?>

( .gs) , HTML , doGet():

function include(filename) {
  return HtmlService.createTemplateFromFile(filename).evaluate()
      .getContent();
}

HTML doGet, , Templated HTML:

function doGet(passed) {

  if(passed.parameter.festival && passed.parameter.year){
    passedParameter = passed.parameter.festival + ' ' + passed.parameter.year;
  }

  var result=HtmlService.createTemplateFromFile('index').evaluate()
        .setTitle('My Title')
        .setWidth(1285)
        .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);

  return result;
}

"" HTML myCSS CSS:

<style>
  h1 {
     color: #0F6B5E;
     font-size: 300%;
     text-align:center;
     vertical-align: middle;
     font-family: 'Raleway', sans-serif;
     font-weight:bold;
     padding-top: 0.5em;
     padding-bottom: 0.5em;
  }
</style>

HTML myScript screipt, HTML . script SErver Side script, script. ( HTML .html , script .gs). calculateWeight() HTML,

<script>
  //Script to load after the page has loaded
  $(function() {
  google.script.run.withSuccessHandler(showMenuYear).withFailureHandler(loadFailed).getDropDownContent();
      });

  calculateWeight() {
    //code goes here
  }

function showMenuYear(menuItems) {
  var list = $('#optionListYear');
  var desiredValue = '<?!= passedParameter ?>';

  list.find('option').remove();  // remove existing contents

  list.append('<option value="-1">Select a Festival and Year</option>');

  for (var i = 0; i < menuItems.length ; i++) {
    list.append('<option value=' + menuItems[i].sheetrow + '>' + menuItems[i].fullFestival + '</option>');
    if (menuItems[i].fullFestival === desiredValue){
      list.val(menuItems[i].sheetrow);
    }
  }

  setFormList();

}
function setFormList() {
//    alert('In setFormList ');
//    alert($('#optionListYear').val());

  var replacement = document.getElementById("OverallGrid");
  replacement.innerHTML = "Retrieving Registrations...";

  if ($('#optionListYear').val() === "-1") {
//    if(passedData.year && passedData.festival){replacement.innerHTML = passedData.festival & " " & passedData.year;};
    replacement.innerHTML = "Select a Festival/Year above.";
    return;
  }
  google.script.run.withSuccessHandler(showRegistrationsTable).withFailureHandler(loadFailed).getValidRegistrations($('#optionListYear').val());
  }

  function loadFailed(error){
    var replacement = document.getElementById("OverallGrid");

    var displayMessage = "Error loading data: " + error.name + ' ' + error.message;

    if (error.message.includes("is missing (perhaps it was deleted?)") ) {
      displayMessage = "You do not have access to these registrations." 
    }

    replacement.innerHTML = displayMessage;

  }
</script>

, google.script.run, Server Side, , . Successful, , withSuccessHandler(successFunction), . , showMenuYear(menuItems) menuItems, getDropDownContent(). , loadFailed(error). :

google.script.run.withSuccessHandler(showMenuYear).withFailureHandler(loadFailed).getDropDownContent();
+3

Source: https://habr.com/ru/post/1683497/


All Articles