ginebra2/chrome/bedrockchrome/suggests.snippet/suggests.js
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
child 5 0f2326c2a325
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     1 function Suggests()
       
     2 {
       
     3     // attach internal funcs
       
     4     this.write = writeSuggests;
       
     5 
       
     6     // do setup
       
     7     this.write();
       
     8 
       
     9     this.showSuggests = function() {
       
    10         window.chrome.alert("showSuggests");
       
    11         //window.snippets.updateGeometry();
       
    12         window.snippets.SuggestsId.repaint();
       
    13 
       
    14      	var curPos = window.snippets.SuggestsId.getPosition();
       
    15         window.chrome.alert(curPos.x);
       
    16         if (curPos.y == 0)
       
    17             window.snippets.SuggestsId.setPosition(5,68);
       
    18         window.snippets.SuggestsId.show();
       
    19         window.snippets.SuggestsId.zValue = 10;
       
    20     }
       
    21 
       
    22     this.hideSuggests = function() {
       
    23         window.snippets.SuggestsId.hide();
       
    24     }
       
    25 
       
    26     this.setWidth = function(width) {
       
    27         document.getElementById("SuggestsId").style.width = width;
       
    28         //window.chrome.alert("set width:" + document.getElementById("SuggestsId").offsetWidth);
       
    29     }
       
    30 
       
    31     this.setHeight = function(height) {
       
    32         document.getElementById("SuggestsId").style.height = height;
       
    33         //window.chrome.alert("set height:" + document.getElementById("SuggestsId").offsetHeight);
       
    34     }
       
    35 
       
    36     this.removeAllItems = function() {
       
    37         var parentList = document.getElementById("SuggestsUListId");
       
    38         while (parentList.childNodes[0]) {
       
    39             parentList.removeChild(parentList.childNodes[0]);
       
    40         }
       
    41         this.setHeight(0);
       
    42     }
       
    43 
       
    44     this.addItem = function(str) {
       
    45         this.setHeight(document.getElementById("SuggestsId").offsetHeight + 26); // FIXME 26 is the row height
       
    46         var parentList = document.getElementById("SuggestsUListId");
       
    47         var item = document.createElement("li");
       
    48         item.innerHTML = str;
       
    49         item.onclick=function() { window.chrome.alert(item.innerHTML + " is selected."); window.snippets.SuggestsId.hide();}
       
    50         item.onmouseover=function() { item.style.backgroundColor = 'Aquamarine'; }
       
    51         item.onmouseout=function() { item.style.backgroundColor = ''; }
       
    52         parentList.appendChild(item);
       
    53     }
       
    54 }
       
    55 
       
    56 // "Private" methods
       
    57 function writeSuggests() {
       
    58     var html =
       
    59     '<div class="suggestsBox">' +
       
    60         '<div class="suggestBoxBody">' +
       
    61           '<div id="SuggestsListId" class="show">' +
       
    62             '<ul id="SuggestsUListId">' +
       
    63             '</ul>' +
       
    64           '</div>' +
       
    65         '</div>' +
       
    66     '</div>'; 
       
    67   document.write(html);
       
    68 }
       
    69