Apps Script公式リファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2019年12月8日日曜日

テキストエリアに入力して練習するアプリ


デモ





コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>
  <head>
    <style>
      textarea {
        width: 20vw;
        height: 1em;
        font-size: 15px;
      }
    </style>
  </head>
  <body>
    <div id="mainDiv" class="table vertical_top">
      <textarea id="ta0">Outlet malls seem to offer great deals, and the merchandise is so cheap, up to 65 percent off normal retail prices.</textarea>
    </div>
    <script>
      taAutoHeight(elem('ta0'));
      createTa();
      
      function elem(id) {
        return document.getElementById(id);
      }
      
      function createTa() {
        var ta = document.createElement('textarea');
        var parent = elem('mainDiv');
        
        ta.style.height = elem('ta0').style.height;
        
        ta.onkeyup = function(e) { 
          var keycode = e.keyCode;
          var value = this.value;
          var valueSplit = value.split("\n");
          taAutoHeight(this);
          elem('ta0').style.height = this.style.height;
          if (keycode == 13) { //returnキーなら
            if (valueSplit[valueSplit.length - 2] == "") { //改行2つなら
              createTa();
            }
          }
        }

        parent.appendChild(ta);
        ta.focus();
      }
      
      function taAutoHeight(ta){
        if(ta.scrollHeight > ta.offsetHeight){   
          ta.style.height = ta.scrollHeight + "px";
        }
      }      
    </script>
  </body>
</html>





Latest post

Google Apps Scriptの障害時はIssueTrackerを見てみる - Incidents for Apps Script are reported on Issue Tracker

IssueTracker > Apps Script issues https://issuetracker.google.com/savedsearches/566234 Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...