navigation.js 5.1 KB
Newer Older
1
/*
2 3 4 5
 * Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License, 
 * Version 1.0, and under the Eclipse Public License, Version 1.0 
 * (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
6 7 8 9 10 11 12 13 14 15 16 17 18 19
 */

function loadFrameset() {
    var a = location.search.split('&');
    var page = decodeURIComponent(a[0].substr(1));
    var frame = a[1];
    if(page && frame){
        var s = "top." + frame + ".location.replace('" + page + "')";
        eval(s);
    }
    return;
}

function frameMe(frame) {
20 21 22 23
    if(location.host.indexOf('h2database') < 0) {
        // allow translation
        return;
    }
24 25 26 27 28 29 30 31 32 33 34 35
    var frameset = "frame.html"; // name of the frameset page
    if(frame == null) {
        frame = 'main';
    }
    page = new String(self.document.location);
    var pos = page.lastIndexOf("/") + 1;
    var file = page.substr(pos);
    file = encodeURIComponent(file);
    if(window.name != frame) {
        var s = frameset + "?" + file + "&" + frame;
        top.location.replace(s);
    } else {
36
        highlightFrame();
37 38 39 40 41 42 43 44 45 46 47 48 49 50
    }
    return;
}

function addHighlight(page, word, count) {
    if(count > 0) {
        if(top.main.document.location.href.indexOf(page) > 0 && top.main.document.body && top.main.document.body.innerHTML) {
            highlight();
        } else {
              window.setTimeout('addHighlight("'+page+'","'+word+'",'+(count-1)+')', 10);
        }
    }
}

51
function highlightFrame() {
52 53 54 55 56 57 58 59 60 61 62 63
    var url = new String(top.main.location.href);
    if(url.indexOf('?highlight=') < 0) {
        return;
    } else {
        var page = url.split('?highlight=');
        var word = decodeURIComponent(page[1]);
        top.main.document.body.innerHTML = highlightSearchTerms(top.main.document.body, word);
        top.main.location = '#firstFound';
        // window.setTimeout('goFirstFound()', 1);
    }
}

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
function highlight() {
    var url = new String(document.location.href);
    if(url.indexOf('?highlight=') < 0) {
        return;
    } else {
        var page = url.split('highlight=')[1].split('&')[0];
        var search = decodeURIComponent(url.split('search=')[1].split('#')[0]);
        var word = decodeURIComponent(page);
        document.body.innerHTML = highlightSearchTerms(document.body, word);
        document.location = '#firstFound';
        document.getElementById('search').value = search;
        listWords(search, '');
    }
}

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
function goFirstFound() {
    top.main.location = '#firstFound';
/*
    var page = new String(parent.main.location);
    alert('first: ' + page);
    page = page.split('#')[0];
    paramSplit = page.split('?');
    page = paramSplit[0];
    page += '#firstFound';
    if(paramSplit.length > 0) {
        page += '?' + paramSplit[1];
    }
    top.main.location = page;
*/
}

function highlightSearchTerms(body, searchText) {
    matchColor = "ffff00,00ffff,00ff00,ff8080,ff0080".split(',');
    highlightEndTag = "</span>";
    searchArray = searchText.split(",");
    if (!body || typeof(body.innerHTML) == "undefined") {
        return false;
      }
      var bodyText = body.innerHTML;
      for (var i = 0; i < searchArray.length; i++) {
          var color = matchColor[i % matchColor.length];
        highlightStartTag = "<span ";
        if(i==0) {
            highlightStartTag += "id=firstFound ";
        }
        highlightStartTag += "style='color:#000000; background-color:#"+color+";'>";
        bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
      }
      return bodyText;
}

function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) {
  if(searchTerm == undefined || searchTerm=="") {
    return bodyText;
  }
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  return newText;
}
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

var drag = false;
var dragSize = 0;
var dragStart = 0;
function mouseDown(e) {
    dragStart = e.clientX || e.pageX;
    dragSize = parseInt(document.getElementById('searchMenu').style.width);
    drag = true;
    return false;
}
function mouseUp(e) {
    drag = false;
    return false;
}
function mouseMove(e) {
    if (drag) {
        var e = e || window.event;
        var x = e.clientX || e.pageX;
        dragSize += x - dragStart;
        dragStart = x;
        document.getElementById('searchMenu').style.width=dragSize + 'px';
    }
    return false;
}