<html>
  <head>
    <script type="text/javascript" src="{{ url_for('static', filename='js/jquery.js') }}" charset="utf-8"></script>

    <style>
      .flash {
          margin-top: 20px;
          padding: 20px;
          background-color: #fff3cd;
          border-color: #ffeeba;
      }
    </style>
  </head>

  <body>

    <div id="flash" class="flash">
      <p>&quot;{{ term_text }}&quot; updated.</p>
    </div>

    <script>
      let reload_updated_text_div = function() {
        const context = window.parent.document;
        const bookid = $('#book_id', context).val();
        const pagenum = $('#page_num', context).val();
        const url = `/read/renderpage/${bookid}/${pagenum}`;
        const repel = $('#thetext', context);
        const marked = $('.kwordmarked', context);
        const marked_id = $(marked[0]).attr('id');

        // Force remove the old popup.
        // ref https://stackoverflow.com/questions/19266886/
        //   tooltip-not-disappearing
        $('div.ui-tooltip', context).remove();

        repel.load(url, function() {
          // console.log(`adding hover class to id ${marked_id}`);
          const re_marked = $(`#${marked_id}`, context);
          re_marked.removeClass('kwordmarked');
          re_marked.addClass('wordhover');
        });
      };

      $(document).ready(function() {
        top.frames.dictframe.location.href = '/read/empty';
        reload_updated_text_div();
        $('#flash').delay(1000).fadeOut();
      });
    </script>

  </body>

</html>
