ginebra/chrome/bedrockchrome/suggests.snippet/suggests.js
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 2 bf4420e9fa4d
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     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         window.snippets.SuggestsId.setPosition(5,68);
       
    15         window.snippets.SuggestsId.show();
       
    16         window.snippets.SuggestsId.zValue = 10;
       
    17     }
       
    18 
       
    19     this.hideSuggests = function() {
       
    20        // window.snippets.ContextMenuBgId.hide();
       
    21         window.snippets.SuggestsId.hide();
       
    22     }
       
    23 
       
    24     this.setWidth = function(width) {
       
    25         document.getElementById("SuggestsId").style.width = width;
       
    26         //window.chrome.alert("set width:" + document.getElementById("SuggestsId").offsetWidth);
       
    27     }
       
    28 
       
    29     this.setHeight = function(height) {
       
    30         document.getElementById("SuggestsId").style.height = height;
       
    31         //window.chrome.alert("set height:" + document.getElementById("SuggestsId").offsetHeight);
       
    32     }
       
    33 
       
    34     this.removeAllItems = function() {
       
    35         var parentList = document.getElementById("SuggestsUListId");
       
    36         while (parentList.childNodes[0]) {
       
    37             parentList.removeChild(parentList.childNodes[0]);
       
    38         }
       
    39         this.setHeight(0);
       
    40     }
       
    41 
       
    42     this.addItem = function(str) {
       
    43         this.setHeight(document.getElementById("SuggestsId").offsetHeight + 26); // FIXME 26 is the row height
       
    44         var parentList = document.getElementById("SuggestsUListId");
       
    45         var item = document.createElement("li");
       
    46         var searchTag = "<span id='sTag' class='searchTag'>S: <span/>";
       
    47         var historyTag = "<span id='hTag' class='searchTag'>H: <span/>";
       
    48         var bookmarkTag = "<span id='bTag' class='searchTag'>B: <span/>";
       
    49         item.innerHTML = searchTag + "<span class='listTag'>" + str + "<span/>";
       
    50         item.onmousedown=function() {
       
    51             document.getElementById("urlBox").value = str;
       
    52             var searchStr = window.chrome.searchUrl(str);
       
    53             window.snippets.SuggestsId.hide();
       
    54             window.pageController.currentLoad(searchStr);
       
    55         }
       
    56         item.onmouseover=function() { item.style.backgroundColor = 'Aquamarine';}
       
    57         item.onmouseout=function() { item.style.backgroundColor = ''; }
       
    58         parentList.appendChild(item);
       
    59     }
       
    60 }
       
    61 
       
    62 // "Private" methods
       
    63 function writeSuggests() {
       
    64     var html =
       
    65     '<div class="suggestsBox">' +
       
    66         '<div class="suggestBoxBody">' +
       
    67           '<div id="SuggestsListId" class="show">' +
       
    68             '<ul id="SuggestsUListId">' +
       
    69             '</ul>' +
       
    70           '</div>' +
       
    71         '</div>' +
       
    72     '</div>'; 
       
    73   document.write(html);
       
    74 }
       
    75