github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/tools/cmd/present/static/dir.js (about)

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // copied from $GOROOT/doc/godocs.js
     6  
     7  function bindEvent(el, e, fn) {
     8    if (el.addEventListener){
     9      el.addEventListener(e, fn, false);
    10    } else if (el.attachEvent){
    11      el.attachEvent('on'+e, fn);
    12    }
    13  }
    14  
    15  function godocs_bindSearchEvents() {
    16    var search = document.getElementById('search');
    17    if (!search) {
    18      // no search box (index disabled)
    19      return;
    20    }
    21    function clearInactive() {
    22      if (search.className == "inactive") {
    23        search.value = "";
    24        search.className = "";
    25      }
    26    }
    27    function restoreInactive() {
    28      if (search.value !== "") {
    29        return;
    30      }
    31      if (search.type != "search") {
    32        search.value = search.getAttribute("placeholder");
    33      }
    34      search.className = "inactive";
    35    }
    36    restoreInactive();
    37    bindEvent(search, 'focus', clearInactive);
    38    bindEvent(search, 'blur', restoreInactive);
    39  }
    40  
    41  bindEvent(window, 'load', godocs_bindSearchEvents);