473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

zichun's autocomplete question

6
dear fellow members,

This is my first post in this forum, I hope for your guidances.

I recently uses autocomplete control from Zichun, a powerful autocomplete control used by youtube as well.

the autocomplete consist of two files:

actb.js
Expand|Select|Wrap|Line Numbers
  1. //////actb.js
  2. function actbpro(obj, ca, hid, ids) {
  3.       /* ---- Public Variables ---- */
  4.       this.actb_timeOut = -1;
  5.       // Autocomplete Timeout in ms (-1: autocomplete never time out)
  6.       this.actb_lim =10;
  7.       // Number of elements autocomplete can show (-1: no limit)
  8.       this.actb_firstText = true;
  9.       // should the auto complete be limited to the beginning of keyword?
  10.       this.actb_mouse = true;
  11.       // Enable Mouse Support
  12.       this.actb_delimiter = new Array(';', ',');
  13.       // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
  14.       this.actb_startcheck =0;
  15.       // Show widget only after this number of characters is typed in.
  16.       /* ---- Public Variables ---- */
  17.  
  18.       /* --- Styles --- */
  19.       this.actb_bgColor = '#6699CC';
  20.       this.actb_textColor = '#000';
  21.       this.actb_hColor = '#ffffdb';
  22.       this.actb_fFamily = 'Verdana, Geneva, Arial, Helvetica, sans-serif';
  23.       this.actb_fSize = '11px';
  24.       this.actb_hStyle = 'text-decoration:underline;font-weight="bold"';
  25.       /* --- Styles --- */
  26.  
  27.       /* ---- Private Variables ---- */
  28.       var actb_delimwords = new Array();
  29.       var actb_cdelimword = 0;
  30.       var actb_delimchar = new Array();
  31.       var actb_display = false;
  32.       var actb_pos = 0;
  33.       var actb_total = 0;
  34.       var actb_curr = null;
  35.       var actb_hidd = null;
  36.       var actb_rangeu = 0;
  37.       var actb_ranged = 0;
  38.       var actb_bool = new Array();
  39.       var actb_pre = 0;
  40.       var actb_toid;
  41.       var actb_tomake = false;
  42.       var actb_getpre = "";
  43.       var actb_mouse_on_list = 1;
  44.       var actb_kwcount = 0;
  45.       var actb_caretmove = false;
  46.       this.actb_keywords = new Array();
  47.       this.actb_ids = new Array();
  48.       /* ---- Private Variables---- */
  49.  
  50.       this.actb_keywords = ca;
  51.       this.actb_ids = ids;
  52.       var actb_self = this;
  53.  
  54.       actb_curr = obj;
  55.       actb_hidd = hid;
  56.  
  57.       addEvent(actb_curr, "focus", actb_setup);
  58.       function actb_setup() {
  59.             addEvent(document, "keydown", actb_checkkey);
  60.             addEvent(actb_curr, "blur", actb_clear);
  61.             addEvent(document, "keypress", actb_keypress);
  62.       }
  63.  
  64.       function actb_clear(evt) {
  65.             if (!evt) evt = event;
  66.             removeEvent(document, "keydown", actb_checkkey);
  67.             removeEvent(actb_curr, "blur", actb_clear);
  68.             removeEvent(document, "keypress", actb_keypress);
  69.             actb_removedisp();
  70.       }
  71.       function actb_parse(n) {
  72.             if (actb_self.actb_delimiter.length > 0) {
  73.                   var t = actb_delimwords[actb_cdelimword].trim().addslashes();
  74.                   var plen = actb_delimwords[actb_cdelimword].trim().length;
  75.             } else {
  76.                   var t = actb_curr.value.addslashes();
  77.                   var plen = actb_curr.value.length;
  78.             }
  79.             var tobuild = '';
  80.             var i;
  81.  
  82.             if (actb_self.actb_firstText) {
  83.                   var re = new RegExp("^" + t, "i");
  84.             } else {
  85.                   var re = new RegExp(t, "i");
  86.             }
  87.             var p = n.search(re);
  88.  
  89.             for (i = 0; i < p; i++) {
  90.                   tobuild += n.substr(i, 1);
  91.             }
  92.             tobuild += "<font style='" + (actb_self.actb_hStyle) + "'>"
  93.             for (i = p; i < plen + p; i++) {
  94.                   tobuild += n.substr(i, 1);
  95.             }
  96.             tobuild += "</font>";
  97.             for (i = plen + p; i < n.length; i++) {
  98.                   tobuild += n.substr(i, 1);
  99.             }
  100.             return tobuild;
  101.       }
  102.       function actb_generate() {
  103.             if (document.getElementById('tat_table')) {
  104.                   actb_display = false;
  105.                   document.body.removeChild(document.getElementById('tat_table'));
  106.             }
  107.             if (actb_kwcount == 0) {
  108.                   actb_display = false;
  109.                   return;
  110.             }
  111.             a = document.createElement('table');
  112.             a.cellSpacing = '1px';
  113.             a.cellPadding = '2px';
  114.             a.style.position = 'absolute';
  115.             a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
  116.             a.style.left = curLeft(actb_curr) + "px";
  117.             a.style.backgroundColor = actb_self.actb_bgColor;
  118.             a.id = 'tat_table';
  119.             document.body.appendChild(a);
  120.             var i;
  121.             var first = true;
  122.             var j = 1;
  123.             if (actb_self.actb_mouse) {
  124.                   a.onmouseout = actb_table_unfocus;
  125.                   a.onmouseover = actb_table_focus;
  126.             }
  127.             var counter = 0;
  128.  
  129.             for (i = 0; i < actb_self.actb_keywords.length; i++) {
  130.                   if (actb_bool[i]) {
  131.                         counter++;
  132.                         r = a.insertRow(-1);
  133.                         if (first && !actb_tomake) {
  134.                               r.style.backgroundColor = actb_self.actb_hColor;
  135.                               first = false;
  136.                               actb_pos = counter;
  137.                         } else if (actb_pre == i) {
  138.                               r.style.backgroundColor = actb_self.actb_hColor;
  139.                               first = false;
  140.                               actb_pos = counter;
  141.                         } else {
  142.                               r.style.backgroundColor = actb_self.actb_bgColor;
  143.                         }
  144.                         r.id = 'tat_tr' + (j);
  145.                         c = r.insertCell(-1);
  146.                         c.style.color = actb_self.actb_textColor;
  147.                         c.style.fontFamily = actb_self.actb_fFamily;
  148.                         c.style.fontSize = actb_self.actb_fSize;
  149.                         c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
  150.                         c.id = 'tat_td' + (j);
  151.                         c.setAttribute('pos', j);
  152.                         if (actb_self.actb_mouse) {
  153.                               c.style.cursor = 'pointer';
  154.                               c.onclick = actb_mouseclick;
  155.                               c.onmouseover = actb_table_highlight;
  156.                         }
  157.                         j++;
  158.                   }
  159.                   if (j - 1 == actb_self.actb_lim && j < actb_total) {
  160.                         r = a.insertRow(-1);
  161.                         r.style.backgroundColor = actb_self.actb_bgColor;
  162.                         c = r.insertCell(-1);
  163.                         c.style.color = actb_self.actb_textColor;
  164.                         c.style.fontFamily = 'arial narrow';
  165.                         c.style.fontSize = actb_self.actb_fSize;
  166.                         c.align = 'center';
  167.                         replaceHTML(c, '\\/');
  168.                         if (actb_self.actb_mouse) {
  169.                               c.style.cursor = 'pointer';
  170.                               c.onclick = actb_mouse_down;
  171.                         }
  172.                         break;
  173.                   }
  174.             }
  175.             actb_rangeu = 1;
  176.             actb_ranged = j - 1;
  177.             actb_display = true;
  178.             if (actb_pos <= 0) actb_pos = 1;
  179.       }
  180.       function actb_remake() {
  181.             document.body.removeChild(document.getElementById('tat_table'));
  182.             a = document.createElement('table');
  183.             a.cellSpacing = '1px';
  184.             a.cellPadding = '2px';
  185.             a.style.position = 'absolute';
  186.             a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight) + "px";
  187.             a.style.left = curLeft(actb_curr) + "px";
  188.             a.style.backgroundColor = actb_self.actb_bgColor;
  189.             a.id = 'tat_table';
  190.             if (actb_self.actb_mouse) {
  191.                   a.onmouseout = actb_table_unfocus;
  192.                   a.onmouseover = actb_table_focus;
  193.             }
  194.             document.body.appendChild(a);
  195.             var i;
  196.             var first = true;
  197.             var j = 1;
  198.             if (actb_rangeu > 1) {
  199.                   r = a.insertRow(-1);
  200.                   r.style.backgroundColor = actb_self.actb_bgColor;
  201.                   c = r.insertCell(-1);
  202.                   c.style.color = actb_self.actb_textColor;
  203.                   c.style.fontFamily = 'arial narrow';
  204.                   c.style.fontSize = actb_self.actb_fSize;
  205.                   c.align = 'center';
  206.                   replaceHTML(c, '/\\');
  207.                   if (actb_self.actb_mouse) {
  208.                         c.style.cursor = 'pointer';
  209.                         c.onclick = actb_mouse_up;
  210.                   }
  211.             }
  212.             for (i = 0; i < actb_self.actb_keywords.length; i++) {
  213.                   if (actb_bool[i]) {
  214.                         if (j >= actb_rangeu && j <= actb_ranged) {
  215.                               r = a.insertRow(-1);
  216.                               r.style.backgroundColor = actb_self.actb_bgColor;
  217.                               r.id = 'tat_tr' + (j);
  218.                               c = r.insertCell(-1);
  219.                               c.style.color = actb_self.actb_textColor;
  220.                               c.style.fontFamily = actb_self.actb_fFamily;
  221.                               c.style.fontSize = actb_self.actb_fSize;
  222.                               c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
  223.                               c.id = 'tat_td' + (j);
  224.                               c.setAttribute('pos', j);
  225.                               if (actb_self.actb_mouse) {
  226.                                     c.style.cursor = 'pointer';
  227.                                     c.onclick = actb_mouseclick;
  228.                                     c.onmouseover = actb_table_highlight;
  229.                               }
  230.                               j++;
  231.                         } else {
  232.                               j++;
  233.                         }
  234.                   }
  235.                   if (j > actb_ranged) break;
  236.             }
  237.             if (j - 1 < actb_total) {
  238.                   r = a.insertRow(-1);
  239.                   r.style.backgroundColor = actb_self.actb_bgColor;
  240.                   c = r.insertCell(-1);
  241.                   c.style.color = actb_self.actb_textColor;
  242.                   c.style.fontFamily = 'arial narrow';
  243.                   c.style.fontSize = actb_self.actb_fSize;
  244.                   c.align = 'center';
  245.                   replaceHTML(c, '\\/');
  246.                   if (actb_self.actb_mouse) {
  247.                         c.style.cursor = 'pointer';
  248.                         c.onclick = actb_mouse_down;
  249.                   }
  250.             }
  251.       }
  252.       function actb_goup() {
  253.             if (!actb_display) return;
  254.             if (actb_pos == 1) return;
  255.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
  256.             actb_pos--;
  257.             if (actb_pos < actb_rangeu) actb_moveup();
  258.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
  259.             if (actb_toid) clearTimeout(actb_toid);
  260.             if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() {
  261.                   actb_mouse_on_list = 0;
  262.                   actb_removedisp();
  263.             }, actb_self.actb_timeOut);
  264.       }
  265.       function actb_godown() {
  266.             if (!actb_display) return;
  267.             if (actb_pos == actb_total) return;
  268.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
  269.             actb_pos++;
  270.             if (actb_pos > actb_ranged) actb_movedown();
  271.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
  272.             if (actb_toid) clearTimeout(actb_toid);
  273.             if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() {
  274.                   actb_mouse_on_list = 0;
  275.                   actb_removedisp();
  276.             }, actb_self.actb_timeOut);
  277.       }
  278.       function actb_movedown() {
  279.             actb_rangeu++;
  280.             actb_ranged++;
  281.             actb_remake();
  282.       }
  283.       function actb_moveup() {
  284.             actb_rangeu--;
  285.             actb_ranged--;
  286.             actb_remake();
  287.       }
  288.  
  289.       /* Mouse */
  290.       function actb_mouse_down() {
  291.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
  292.             actb_pos++;
  293.             actb_movedown();
  294.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
  295.             actb_curr.focus();
  296.             actb_mouse_on_list = 0;
  297.             if (actb_toid) clearTimeout(actb_toid);
  298.             if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() {
  299.                   actb_mouse_on_list = 0;
  300.                   actb_removedisp();
  301.             }, actb_self.actb_timeOut);
  302.       }
  303.       function actb_mouse_up(evt) {
  304.             if (!evt) evt = event;
  305.             if (evt.stopPropagation) {
  306.                   evt.stopPropagation();
  307.             } else {
  308.                   evt.cancelBubble = true;
  309.             }
  310.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
  311.             actb_pos--;
  312.             actb_moveup();
  313.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
  314.             actb_curr.focus();
  315.             actb_mouse_on_list = 0;
  316.             if (actb_toid) clearTimeout(actb_toid);
  317.             if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() {
  318.                   actb_mouse_on_list = 0;
  319.                   actb_removedisp();
  320.             }, actb_self.actb_timeOut);
  321.       }
  322.       function actb_mouseclick(evt) {
  323.             if (!evt) evt = event;
  324.             if (!actb_display) return;
  325.             actb_mouse_on_list = 0;
  326.             actb_pos = this.getAttribute('pos');
  327.             actb_penter();
  328.       }
  329.       function actb_table_focus() {
  330.             actb_mouse_on_list = 1;
  331.       }
  332.       function actb_table_unfocus() {
  333.             actb_mouse_on_list = 0;
  334.             if (actb_toid) clearTimeout(actb_toid);
  335.             if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() {
  336.                   actb_mouse_on_list = 0;
  337.                   actb_removedisp();
  338.             }, actb_self.actb_timeOut);
  339.       }
  340.       function actb_table_highlight() {
  341.             actb_mouse_on_list = 1;
  342.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
  343.             actb_pos = this.getAttribute('pos');
  344.             while (actb_pos < actb_rangeu) actb_moveup();
  345.             while (actb_pos > actb_ranged) actb_movedown();
  346.             document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
  347.             if (actb_toid) clearTimeout(actb_toid);
  348.             if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() {
  349.                   actb_mouse_on_list = 0;
  350.                   actb_removedisp();
  351.             }, actb_self.actb_timeOut);
  352.       }
  353.       /* ---- */
  354.  
  355.       function actb_insertword(a) {
  356.             if (actb_self.actb_delimiter.length > 0) {
  357.                   str = '';
  358.                   l = 0;
  359.                   for (i = 0; i < actb_delimwords.length; i++) {
  360.                         if (actb_cdelimword == i) {
  361.                               prespace = postspace = '';
  362.                               gotbreak = false;
  363.                               for (j = 0; j < actb_delimwords[i].length; ++j) {
  364.                                     if (actb_delimwords[i].charAt(j) != ' ') {
  365.                                           gotbreak = true;
  366.                                           break;
  367.                                     }
  368.                                     prespace += ' ';
  369.                               }
  370.                               for (j = actb_delimwords[i].length - 1; j >= 0; --j) {
  371.                                     if (actb_delimwords[i].charAt(j) != ' ') break;
  372.                                     postspace += ' ';
  373.                               }
  374.                               str += prespace;
  375.                               str += a;
  376.                               l = str.length;
  377.                               if (gotbreak) str += postspace;
  378.                         } else {
  379.                               str += actb_delimwords[i];
  380.                         }
  381.                         if (i != actb_delimwords.length - 1) {
  382.                               str += actb_delimchar[i];
  383.                         }
  384.                   }
  385.                   actb_curr.value = str;
  386.                   setCaret(actb_curr, l);
  387.             } else {
  388.                   actb_curr.value = a;
  389.             }
  390.             actb_mouse_on_list = 0;
  391.             actb_removedisp();
  392.       }
  393.       function actb_inserthidden(index) {
  394.             if (actb_hidd)
  395.                   actb_hidd.value = ids[index];
  396.       }
  397.       /*
  398.             Function executed when an option is selected
  399.       */
  400.       function actb_penter() {
  401.             if (!actb_display) return;
  402.             actb_display = false;
  403.             var word = '';
  404.             var word_index = 0;
  405.             var c = 0;
  406.             for (var i = 0; i <= actb_self.actb_keywords.length; i++) {
  407.                   if (actb_bool[i]) c++;
  408.                   if (c == actb_pos) {
  409.                         word = actb_self.actb_keywords[i];
  410.                         word_index = i
  411.                         break;
  412.                   }
  413.             }
  414.             //alert('here we can handle an hidden with some database id values');
  415.             actb_insertword(word);
  416.             actb_inserthidden(word_index);
  417.             l = getCaretStart(actb_curr);
  418.       }
  419.       function actb_removedisp() {
  420.             if (actb_mouse_on_list == 0) {
  421.                   actb_display = 0;
  422.                   if (document.getElementById('tat_table')) {
  423.                         document.body.removeChild(document.getElementById('tat_table'));
  424.                   }
  425.                   if (actb_toid) clearTimeout(actb_toid);
  426.             }
  427.       }
  428.       function actb_keypress(e) {
  429.             if (actb_caretmove) stopEvent(e);
  430.             return !actb_caretmove;
  431.       }
  432.       function actb_checkkey(evt) {
  433.             if (!evt) evt = event;
  434.             a = evt.keyCode;
  435.             caret_pos_start = getCaretStart(actb_curr);
  436.             actb_caretmove = 0;
  437.             switch (a) {
  438.                   case 38:
  439.                         actb_goup();
  440.                         actb_caretmove = 1;
  441.                         return false;
  442.                         break;
  443.                   case 13: case 9:
  444.                   if (actb_display) {
  445.                         actb_caretmove = 1;
  446.                         actb_penter();
  447.                         return false;
  448.                   } else {
  449.                         return true;
  450.                   }
  451.                   break;
  452.                   case 40:
  453.                         if (actb_curr.value != '') {
  454.                               actb_godown();
  455.                               actb_caretmove = 1;
  456.                               return false;
  457.                               break;
  458.                         }
  459.                   default:
  460.                         setTimeout(function() {
  461.                               actb_tocomplete(a)
  462.                         }, 50);
  463.                         break;
  464.             }
  465.       }
  466.  
  467.       function actb_tocomplete(kc) {
  468.             if (kc == 38 || (kc == 40 && actb_curr.value != '') || kc == 13) return;
  469.             var i;
  470.             if (actb_display) {
  471.                   var word = 0;
  472.                   var c = 0;
  473.                   for (var i = 0; i <= actb_self.actb_keywords.length; i++) {
  474.                         if (actb_bool[i]) c++;
  475.                         if (c == actb_pos) {
  476.                               word = i;
  477.                               break;
  478.                         }
  479.                   }
  480.                   actb_pre = word;
  481.             } else {
  482.                   actb_pre = -1;
  483.             }
  484.  
  485.             if (actb_curr.value == '' && kc != 40) {
  486.                   actb_mouse_on_list = 0;
  487.                   actb_removedisp();
  488.                   return;
  489.             }
  490.             if (actb_self.actb_delimiter.length > 0) {
  491.                   caret_pos_start = getCaretStart(actb_curr);
  492.                   caret_pos_end = getCaretEnd(actb_curr);
  493.  
  494.                   delim_split = '';
  495.                   for (i = 0; i < actb_self.actb_delimiter.length; i++) {
  496.                         delim_split += actb_self.actb_delimiter[i];
  497.                   }
  498.  
  499.                   delim_split = delim_split.addslashes();
  500.                   delim_split_rx = new RegExp("([" + delim_split + "])");
  501.                   c = 0;
  502.                   actb_delimwords = new Array();
  503.                   actb_delimwords[0] = '';
  504.                   for (i = 0,j = actb_curr.value.length; i < actb_curr.value.length; i++,j--) {
  505.                         if (actb_curr.value.substr(i, j).search(delim_split_rx) == 0) {
  506.                               ma = actb_curr.value.substr(i, j).match(delim_split_rx);
  507.                               actb_delimchar[c] = ma[1];
  508.                               c++;
  509.                               actb_delimwords[c] = '';
  510.                         } else {
  511.                               actb_delimwords[c] += actb_curr.value.charAt(i);
  512.                         }
  513.                   }
  514.  
  515.                   var l = 0;
  516.                   actb_cdelimword = -1;
  517.                   for (i = 0; i < actb_delimwords.length; i++) {
  518.                         if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length) {
  519.                               actb_cdelimword = i;
  520.                         }
  521.                         l += actb_delimwords[i].length + 1;
  522.                   }
  523.                   var ot = actb_delimwords[actb_cdelimword].trim();
  524.                   var t = actb_delimwords[actb_cdelimword].addslashes().trim();
  525.             } else {
  526.                   var ot = actb_curr.value;
  527.                   var t = actb_curr.value.addslashes();
  528.             }
  529.             //patch to permit swohing the entire list
  530.             if (kc == 40 && actb_curr.value == '') {
  531.                   actb_total = 0;
  532.                   actb_tomake = false;
  533.                   actb_kwcount = 0;
  534.                   for (i = 0; i < actb_self.actb_keywords.length; i++) {
  535.                         actb_bool[i] = false;
  536.                         if (actb_self.actb_keywords[i] != '' && actb_self.actb_keywords[i]) {
  537.                               if (actb_curr.value == '') {
  538.                                     actb_curr.value = actb_self.actb_keywords[i];
  539.                               }
  540.                               actb_total++;
  541.                               actb_bool[i] = true;
  542.                               actb_kwcount++;
  543.                               if (actb_pre == i) actb_tomake = true;
  544.                         }
  545.                   }
  546.                   if (actb_toid) clearTimeout(actb_toid);
  547.                   if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() {
  548.                         actb_mouse_on_list = 0;
  549.                         actb_removedisp();
  550.                   }, actb_self.actb_timeOut);
  551.                   return actb_generate();
  552.             }
  553.  
  554.             if (ot.length == 0) {
  555.                   actb_mouse_on_list = 0;
  556.                   actb_removedisp();
  557.             }
  558.             if (ot.length < actb_self.actb_startcheck) return this;
  559.             if (actb_self.actb_firstText) {
  560.                   var re = new RegExp("^" + t, "i");
  561.             } else {
  562.                   var re = new RegExp(t, "i");
  563.             }
  564.  
  565.  
  566.             actb_total = 0;
  567.             actb_tomake = false;
  568.             actb_kwcount = 0;
  569.             for (i = 0; i < actb_self.actb_keywords.length; i++) {
  570.                   actb_bool[i] = false;
  571.                   if (re.test(actb_self.actb_keywords[i])) {
  572.                         actb_total++;
  573.                         actb_bool[i] = true;
  574.                         actb_kwcount++;
  575.                         if (actb_pre == i) actb_tomake = true;
  576.                   }
  577.             }
  578.  
  579.             if (actb_toid) clearTimeout(actb_toid);
  580.             if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() {
  581.                   actb_mouse_on_list = 0;
  582.                   actb_removedisp();
  583.             }, actb_self.actb_timeOut);
  584. //            alert(actb_kwcount)
  585.             actb_generate();
  586.       }
  587.       return this;
  588.  
common.js
Expand|Select|Wrap|Line Numbers
  1. /* Event Functions */
  2.  
  3. // Add an event to the obj given
  4. // event_name refers to the event trigger, without the "on", like click or mouseover
  5. // func_name refers to the function callback when event is triggered
  6. function addEvent(obj,event_name,func_name){
  7.     if (obj.attachEvent){
  8.         obj.attachEvent("on"+event_name, func_name);
  9.     }else if(obj.addEventListener){
  10.         obj.addEventListener(event_name,func_name,true);
  11.     }else{
  12.         obj["on"+event_name] = func_name;
  13.     }
  14. }
  15.  
  16. // Removes an event from the object
  17. function removeEvent(obj,event_name,func_name){
  18.     if (obj.detachEvent){
  19.         obj.detachEvent("on"+event_name,func_name);
  20.     }else if(obj.removeEventListener){
  21.         obj.removeEventListener(event_name,func_name,true);
  22.     }else{
  23.         obj["on"+event_name] = null;
  24.     }
  25. }
  26.  
  27. // Stop an event from bubbling up the event DOM
  28. function stopEvent(evt){
  29.     evt || window.event;
  30.     if (evt.stopPropagation){
  31.         evt.stopPropagation();
  32.         evt.preventDefault();
  33.     }else if(typeof evt.cancelBubble != "undefined"){
  34.         evt.cancelBubble = true;
  35.         evt.returnValue = false;
  36.     }
  37.     return false;
  38. }
  39.  
  40. // Get the obj that starts the event
  41. function getElement(evt){
  42.     if (window.event){
  43.         return window.event.srcElement;
  44.     }else{
  45.         return evt.currentTarget;
  46.     }
  47. }
  48. // Get the obj that triggers off the event
  49. function getTargetElement(evt){
  50.     if (window.event){
  51.         return window.event.srcElement;
  52.     }else{
  53.         return evt.target;
  54.     }
  55. }
  56. // For IE only, stops the obj from being selected
  57. function stopSelect(obj){
  58.     if (typeof obj.onselectstart != 'undefined'){
  59.         addEvent(obj,"selectstart",function(){ return false;});
  60.     }
  61. }
  62.  
  63. /*    Caret Functions     */
  64.  
  65. // Get the end position of the caret in the object. Note that the obj needs to be in focus first
  66. function getCaretEnd(obj){
  67.     if(typeof obj.selectionEnd != "undefined"){
  68.         return obj.selectionEnd;
  69.     }else if(document.selection&&document.selection.createRange){
  70.         var M=document.selection.createRange();
  71.         try{
  72.             var Lp = M.duplicate();
  73.             Lp.moveToElementText(obj);
  74.         }catch(e){
  75.             var Lp=obj.createTextRange();
  76.         }
  77.         Lp.setEndPoint("EndToEnd",M);
  78.         var rb=Lp.text.length;
  79.         if(rb>obj.value.length){
  80.             return -1;
  81.         }
  82.         return rb;
  83.     }
  84. }
  85. // Get the start position of the caret in the object
  86. function getCaretStart(obj){
  87.     if(typeof obj.selectionStart != "undefined"){
  88.         return obj.selectionStart;
  89.     }else if(document.selection&&document.selection.createRange){
  90.         var M=document.selection.createRange();
  91.         try{
  92.             var Lp = M.duplicate();
  93.             Lp.moveToElementText(obj);
  94.         }catch(e){
  95.             var Lp=obj.createTextRange();
  96.         }
  97.         Lp.setEndPoint("EndToStart",M);
  98.         var rb=Lp.text.length;
  99.         if(rb>obj.value.length){
  100.             return -1;
  101.         }
  102.         return rb;
  103.     }
  104. }
  105. // sets the caret position to l in the object
  106. function setCaret(obj,l){
  107.     obj.focus();
  108.     if (obj.setSelectionRange){
  109.         obj.setSelectionRange(l,l);
  110.     }else if(obj.createTextRange){
  111.         m = obj.createTextRange();        
  112.         m.moveStart('character',l);
  113.         m.collapse();
  114.         m.select();
  115.     }
  116. }
  117. // sets the caret selection from s to e in the object
  118. function setSelection(obj,s,e){
  119.     obj.focus();
  120.     if (obj.setSelectionRange){
  121.         obj.setSelectionRange(s,e);
  122.     }else if(obj.createTextRange){
  123.         m = obj.createTextRange();        
  124.         m.moveStart('character',s);
  125.         m.moveEnd('character',e);
  126.         m.select();
  127.     }
  128. }
  129.  
  130. /*    Escape function   */
  131. String.prototype.addslashes = function(){
  132.     return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
  133. }
  134. String.prototype.trim = function () {
  135.     return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
  136. };
  137. /* --- Escape --- */
  138.  
  139. /* Offset position from top of the screen */
  140. function curTop(obj){
  141.     toreturn = 0;
  142.     while(obj){
  143.         toreturn += obj.offsetTop;
  144.         obj = obj.offsetParent;
  145.     }
  146.     return toreturn;
  147. }
  148. function curLeft(obj){
  149.     toreturn = 0;
  150.     while(obj){
  151.         toreturn += obj.offsetLeft;
  152.         obj = obj.offsetParent;
  153.     }
  154.     return toreturn;
  155. }
  156. /* ------ End of Offset function ------- */
  157.  
  158. /* Types Function */
  159.  
  160. // is a given input a number?
  161. function isNumber(a) {
  162.     return typeof a == 'number' && isFinite(a);
  163. }
  164.  
  165. /* Object Functions */
  166.  
  167. function replaceHTML(obj,text){
  168.     while(el = obj.childNodes[0]){
  169.         obj.removeChild(el);
  170.     };
  171.     obj.appendChild(document.createTextNode(text));
  172. }
  173.  
my problem: atm the autocomplete can only recognise more than one words when they are arranged consecutively in the result, example: when user input "apple bee" it only show result of "apple bee cat", "apple bee dog", "apple bee orange" and so on, but NOT "apple orange bee", "bee apple orage", etc

is there any solution for this?

any help will greatly appreciated.
Jul 21 '10 #1
6 1927
gits
5,390 Expert Mod 4TB
it's probably the actb_tocomplete() method that needs adaption - but hopefully you don't just want us to write the change for you? what have you tried so far?

regards
Jul 21 '10 #2
eyik
6
to be honest, I am also unsure what to look at.
I'm actually suspecting some modification at actb_parse because actb_tocomplete is more like button handler.

If anyone can give me hint so I know where to begin, it is a great first step.

meanwhile I will keep looking for clue myself
Jul 22 '10 #3
Ok, i need some help to. I use this drop down script, but i need to add width for drop down rows. How can i do that? I dont know much about .js, in css its simply, but not here... help!
Jul 23 '10 #4
eyik
6
Ok,seems that I found a dead end. Even worse, I'm not sure which function doing what.

could anyone can help me doing dissection on the code (as in understanding each function role)
Jul 23 '10 #5
Ok, i get answer.. if someone need to get drop down list width, than simply add

a.style.width='150px'; after " function actb_generate() " function :)
Jul 23 '10 #6
eyik maybe you can find answer here - http://www.codeproject.com/KB/scripting/jsactb.aspx there is some Q/A
Jul 23 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

40
by: Alex | last post by:
Hello, does anybody know how to turn off the autocomplete feature for a certain text field? I am aware of the "autocomplete" attribute, but I have seen other implementions achieving it...
0
by: Scott | last post by:
I have a webform that I would like to use the autocomplete feature for all my textboxes. My textboxes are the <ASP:Textbox /> control. The only way I seem to be able to get autocomplete to work...
8
by: moondaddy | last post by:
I have a form for entering a user's address and all fields have a required validating control associated with them and the error msg for each field displays right next to it. The normal behavior...
0
by: Rich | last post by:
Hello, I found this code on google for autocompleting text from a combobox. The works fine. It was the shortest sample of the samples I found. I added a few extra keys to ignore on keyup like...
1
by: rbg.net | last post by:
I know that there is a autocomplete property for the HTML "INPUT type=text" control which if set to OFF, disables autocomplete of the input textbox (doesn't remember previously entered values) ...
1
by: wkerplunk | last post by:
Below is what I have build with several different languages. It works great but I need help, I am stuck. When you click on an item in the dropdown autocomplete div it does a mousedown function...
5
by: Doug | last post by:
Hi I have a simple form, just with one combo box and an OK button - and i have tried to use the autocomplete routine and I have enabled autocomplete in the combo box properties. ...
1
by: shapper | last post by:
Hello, I am creating a custom web control which uses AutoComplete associated to a TextBox. In this project I also have the necessary .asmx file. The project is compiled to a .dll library. ...
0
by: BaseballGraphs | last post by:
Hello, I am trying to format the output of my data with the autocomplete function from jQuery. So far, I've been able to build the entire process, however, I want to limit the information I show...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.