Advertisement
mihir_amreli

AutoComplete Textbox

Mar 22nd, 2011
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.   Parameters Description :-
  4.  
  5.   obj            :- On which Object The Box is Setup
  6.   ca             :- Array of Words
  7.   isMultiple     :- Array is Miltiple
  8.   forwardPage    :- indicates Page URL to forward in case of Master Entry
  9.   divID          :- The id Of div Tag for Displaying Messages
  10.   isForwardAllow :- Forwarding is Allow or Not
  11.   isRequired     :- Must Be Filled or Not  
  12.   maxLimit       :- Display the content at a time
  13.   gridFunction   :  Any Grid Function, if this component is attaching with grid
  14.  *                 to call.
  15.   isEventAllow   :- If occuring event is allowed to propogate to its parent component,in case
  16.  *                 while we using this componet in the grid.
  17.   subGridDef     :- Direct SubgridDef to populate child that exist from the
  18.  *                 same text object on which this autoComplete is populated.
  19.  *
  20.   customEventsFunctions :- this is an object defining custom events for this component.for example
  21.  *                        
  22.  *                        'beforeTableCreation' : we can call or does any procedure before table is creating for first time.,
  23.  *                        'beforeTableRecreaion',
  24.  *                        'onInit',
  25.  *                        'onTableInit',
  26.  *                        'onLoad',
  27.  *                        'onUnload',
  28.  *
  29.  * we can hook extrenal functions or even  other components to act on behalf of this
  30.  * custom event.right now we programme for 'beforeTableCreation' custom event, passing an extrenal
  31.  * function that must be called before actual list is populated to display in to table. (as on Date :- 04-12-2010).
  32.  *                        
  33.                        
  34.  */
  35.  
  36. /*
  37.         @include:-
  38.        
  39.         1 :- EventUtil.js
  40.  
  41.  */
  42.  
  43. function autoCompleteMixed(obj, ca, isMultiple, forwardPage, divID,
  44.         isForwardAllow, isRequired, maxLimit, gridFunction, isEventAllow,
  45.         subGridDef, customEventsFunctions) {
  46.  
  47.     /* Global variable which is pointing to itself , means it holds the reference of
  48.        whole the components including properties,events,methods of this component. */
  49.  
  50.     var atm = this;
  51.  
  52.     /*
  53.  
  54.      this all variables are respoinsible for look & feel
  55.      of autocomplete text box
  56.      
  57.      */
  58.  
  59.     if (typeof (maxLimit) == "undefined" || maxLimit == undefined) {
  60.         maxLimit = 10;
  61.     }
  62.  
  63.     if (typeof (maxLimit) == "string") {
  64.         maxLimit = parseInt(maxLimit, 10);
  65.     }
  66.  
  67.     this.tblNormalClassName = '';
  68.     var trNormalClassName = 'quickhelp';
  69.     var trSelectedClassName = 'auto_right';
  70.     this.tdNormalClassName = '';
  71.     this.tdSelectdClassName = '';
  72.     var trOnMouseOverClassName = 'right';
  73.     var trOnMouseOutClassName = 'quickhelp';
  74.  
  75.     /////////////////////////////////////
  76.  
  77.     this.txtFontSize = '';
  78.     this.txtFontFamily = '';
  79.     this.txtStyleNormal = '';
  80.     this.txtStyleSelected = '';
  81.  
  82.     /*
  83.         variables for storing Array
  84.      */
  85.  
  86.     var act_keywords = ca;
  87.     var act_multiple = null;
  88.  
  89.     this.curObject = obj;
  90.     this.forwardPage = forwardPage;
  91.  
  92.     /*
  93.    
  94.              Key bord related Variables
  95.      */
  96.  
  97.     var blockKeyCode = false;
  98.  
  99.     /*
  100.          General variable  
  101.          
  102.    
  103.      */
  104.  
  105.     var pos = (-1);
  106.     var counter = (-1);
  107.     var actStart = 0;
  108.     var actEnd = 0;
  109.     var selectedidx = 0;
  110.     var isFound = false;
  111.     var isZeroLength = true;
  112.     var isNormalKey = false;
  113.     var t;
  114.     var foundPosition = -1;
  115.  
  116.     /*
  117.          Variable for calculating upper & lower limit
  118.      */
  119.  
  120.     var uLimit = 0;
  121.     var dLimit = 0;
  122.     var uDifference = 0;
  123.     var dDifference = 0;
  124.  
  125.     /*
  126.      this is the Core function which initialized all the things
  127.      */
  128.  
  129.     /* First Remove Previous Event Handler if Exist */
  130.     /* Date MOdified :- 11-09-09  */
  131.  
  132.     this.customEventsFunctions = customEventsFunctions;
  133.  
  134.     if (this.customEventsFunctions != undefined) {
  135.  
  136.         if (typeof (this.customEventsFunctions) == "string") {
  137.  
  138.             this.customEventsFunctions = eval(this.customEventsFunctions);
  139.  
  140.         }
  141.     }
  142.  
  143.     EventUtil.addEventHandler(obj, "focus", setup);
  144.     EventUtil.addEventHandler(obj, "focus", createTable);
  145.  
  146.     function setup() {
  147.         // Text Box Events
  148.         // showMessage(divID,"Setup");
  149.  
  150.         EventUtil.addEventHandler(obj, "blur", clearEvent);
  151.  
  152.         //if(Def(gridFunction))
  153.         // EventUtil.addEventHandler(obj,"blur",eval(gridFunction));
  154.  
  155.         // Keyboard Events
  156.  
  157.         EventUtil.addEventHandler(obj, "keypress", obj_KeyPressed);
  158.         EventUtil.addEventHandler(obj, "keydown", obj_KeyDown);
  159.     }
  160.  
  161.     /*
  162.         this is the  function which removes  all the events
  163.    
  164.      */
  165.  
  166.     function clearEvent() {
  167.         var oEvent = EventUtil.getEvent();
  168.         EventUtil.removeEventHandler(obj, "keydown", obj_KeyDown);
  169.         EventUtil.removeEventHandler(obj, "keypress", obj_KeyPressed);
  170.         EventUtil.removeEventHandler(obj, "blur", clearEvent);
  171.         showMessage(divID, "");
  172.         removeDisplay();
  173.         if (!isFound)
  174.             obj.value = "";
  175.     }
  176.  
  177.     /* this function is responsible
  178.        for reseting all gloabl variables for this function
  179.    
  180.      */
  181.  
  182.     this.resetGV = function() {
  183.         blockKeyCode = false;
  184.  
  185.         /*
  186.              General variable  
  187.          */
  188.  
  189.         counter = (-1);
  190.         actStart = 0;
  191.         actEnd = 0;
  192.         selectedidx = 0;
  193.         pos = (-1);
  194.         isFound = false;
  195.         isZeroLength = true;
  196.         isNormalKey = false;
  197.         t = null;
  198.         foundPosition = -1;
  199.  
  200.         /*
  201.              Variable for calculating upper & lower limit
  202.          */
  203.  
  204.         uLimit = 0;
  205.         dLimit = 0;
  206.         uDifference = 0;
  207.         dDifference = 0;
  208.  
  209.     };
  210.  
  211.     //alert(typeof(this));
  212.     /*
  213.         this function is responsible for creating table dynamically
  214.      */
  215.  
  216.     /* Date Created  :- 27-09-08 */
  217.     /* Function is Responsible for setting Global Array */
  218.  
  219.     this.resetDataStructure = function(srcDS) {
  220.         if (srcDS.constructor == String) {
  221.             act_keywords[act_keywords.length] = srcDS;
  222.             act_keywords.sort();
  223.         } else {
  224.             act_keywords = srcDS;
  225.         }
  226.     };
  227.  
  228.     this.setForwardPage = function(fp) {
  229.         forwardPage = fp;
  230.     };
  231.  
  232.     this.setRequired = function(ir) {
  233.         isRequired = ir; /* either true or false */
  234.     }
  235.  
  236.     this.beforeTableCreation = function(cef) {
  237.  
  238.         /*
  239.               cef stands for custom events functions
  240.          */
  241.  
  242.         if (cef != undefined) {
  243.             alert(atm.customEventsFunctions.beforeTableCreation);
  244.             with (cef) {
  245.  
  246.                 if (beforeTableCreation != undefined) {
  247.                     /* We are Passing here in the external functional */
  248.                     /* the Object on which this autoComplete is Populating and */
  249.                     /* the array that we want to display on it .*/
  250.                     /* if the data is passed in the array and if modified from */
  251.                     /* the external functions we have to call here resetDataStructure function which
  252.                     we are getting from outside. */
  253.  
  254.                     var srcData = window[beforeTableCreation].call(this, obj,
  255.                             oEvent);
  256.  
  257.                     this.resetDataStructure(srcData);
  258.  
  259.                 }
  260.  
  261.             }
  262.  
  263.         }
  264.     }
  265.  
  266.     function createTable() {
  267.  
  268.         if (document.getElementById('tt_table')) {
  269.             document.body.removeChild(document.getElementById('tt_table'));
  270.         }
  271.  
  272.         /* Hook here before Table creation custom events */
  273.         /* if there is an external function call it here before */
  274.         /* creation of a table. */
  275.  
  276.         atm.beforeTableCreation(atm.customEventsFunctions);
  277.  
  278.         //  showMessage(divID,"From Table");
  279.  
  280.         t = document.createElement('table');
  281.         t.id = "tt_table";
  282.  
  283.         /*
  284.                 Here Is Code For Table Class
  285.                 t.tblNormalClassName='';
  286.          */
  287.  
  288.         t.cellPadding = '1px';
  289.         t.cellSpacing = '0px';
  290.         t.style.border = "1px solid";
  291.         t.style.width = obj.offsetWidth;
  292.         t.style.position = 'absolute';
  293.         t.style.zIndex = '99999';
  294.         // This Two Lines are Very Important
  295.         // Setting Top ,Left  Of created Table
  296.  
  297.         var oFFset = objLeftTop(obj);
  298.  
  299.         //document.getElementById("divDisplayMessage").innerHTML=oFFset;
  300.         /* Date Modified On 17-04-09 */
  301.         if (oFFset == undefined || oFFset == null) {
  302.             //t.style.top= eval(obj.offsetHeight)+'px';
  303.             //t.style.left= obj.offsetLeft;
  304.             removeDisplay();
  305.         } else {
  306.             t.style.top = eval(obj.offsetHeight + oFFset[0]) + 'px';
  307.             t.style.left = oFFset[1] + 'px';
  308.             adjustWindowAuto(obj);
  309.         }
  310.  
  311.         /////////////////////////////////////
  312.         document.body.appendChild(t);
  313.  
  314.         for (i = 0; i < act_keywords.length; i++) {
  315.             var r = t.insertRow(-1);
  316.             r.id = 'tblRow' + i;
  317.             r.setAttribute('pos', i);
  318.             r.className = trNormalClassName;
  319.             addMouseEvent(r);
  320.  
  321.             /*
  322.                   Here we put condition
  323.                   if i > maxLimit then we stop here &
  324.                   put marker here
  325.              */
  326.  
  327.             if (i == maxLimit && act_keywords.length > maxLimit) {
  328.                 leftEntry = act_keywords.length - maxLimit;
  329.                 createMarkerCell(r, leftEntry + " more... ");
  330.                 break;
  331.             }
  332.             if (isMultiple) {
  333.                 createMultiColumnTable(r, act_keywords[i], i);
  334.             } //ends If
  335.             else {
  336.                 createSingleColumnTable(r, act_keywords[i], i);
  337.             } //ends Else
  338.         }//ends For
  339.  
  340.         uLimit = 0;
  341.         dLimit = i - 1;
  342.  
  343.         if (obj.value.length > 0 && isMultiple)
  344.             showkeywordsmultiple(obj);
  345.         else if (obj.value.length > 0 && !isMultiple)
  346.             showkeywords(obj);
  347.         else {
  348.         }
  349.         //   goDown();
  350.  
  351.     }
  352.  
  353.     function remake() {
  354.  
  355.         if (document.getElementById('tt_table')) {
  356.             document.body.removeChild(document.getElementById('tt_table'));
  357.         }
  358.  
  359.         t = document.createElement('table');
  360.         /*
  361.                Here is Code For Table Class Name
  362.                t.className='';
  363.          */
  364.  
  365.         t.id = "tt_table";
  366.         t.cellPadding = '1px';
  367.         t.cellSpacing = '0px';
  368.         t.style.border = "1px solid";
  369.         t.style.width = obj.offsetWidth;
  370.         t.style.position = 'absolute';
  371.         t.style.zIndex = '99999';
  372.         var oFFset = objLeftTop(obj);
  373.  
  374.         /* Date Modified On 19-04-09 */
  375.         if (oFFset == undefined || oFFset == null) {
  376.             //t.style.top= eval(obj.offsetHeight)+'px';
  377.             //t.style.left= obj.offsetLeft;
  378.             removeDisplay();
  379.         } else {
  380.             t.style.top = eval(obj.offsetHeight + oFFset[0]) + 'px';
  381.             t.style.left = oFFset[1] + 'px';
  382.         }
  383.  
  384.         /////////////////////////////////////
  385.  
  386.         document.body.appendChild(t);
  387.  
  388.         if (uLimit > 0) {// && act_keywords.length>maxLimit){
  389.             var r = t.insertRow(-1);
  390.             r.id = 'tblRow' + i;
  391.             r.setAttribute('pos', i);
  392.             r.className = trNormalClassName;
  393.             addMouseEvent(r);
  394.             createMarkerCell(r, uLimit + " more... ");
  395.  
  396.         }
  397.         var j = 0;
  398.         for (i = 0; i < act_keywords.length; i++) {
  399.             if (i >= uLimit && i <= dLimit) {
  400.                 var r = t.insertRow(-1);
  401.                 r.id = 'tblRow' + i;
  402.                 r.setAttribute('pos', i);
  403.                 r.className = trNormalClassName;
  404.                 addMouseEvent(r);
  405.                 j++;
  406.                 if (pos > -1 && pos == i) {
  407.                     counter = pos;
  408.                     selectedidx = true;
  409.                 } //ends IF
  410.                 if (isMultiple) {
  411.                     createMultiColumnTableRemake(r, act_keywords[i], i, pos);
  412.                 } else {
  413.                     createSingleColumnTableRemake(r, act_keywords[i], i, pos);
  414.                 }//ends Else
  415.             }
  416.  
  417.             if (j == maxLimit && (act_keywords.length - (dLimit + 1) > 0)) {
  418.                 var r = t.insertRow(-1);
  419.                 r.id = 'tblRow' + i;
  420.                 r.setAttribute('pos', i);
  421.                 r.className = trNormalClassName;
  422.                 addMouseEvent(r);
  423.                 leftEntry = act_keywords.length - (dLimit + 1);
  424.                 createMarkerCell(r, leftEntry + " more... ");
  425.                 break;
  426.             }
  427.  
  428.         } //ends For
  429.     }
  430.  
  431.     /*
  432.              Date Created:- 27-08-08      
  433.      */
  434.  
  435.     function createMarkerCell(tObj, textHTML) {
  436.         var c = tObj.insertCell(-1);
  437.         c.align = "left";
  438.         c.className = "Header_left";
  439.  
  440.         var txt = document.createTextNode(textHTML);
  441.         c.appendChild(txt);
  442.  
  443.     }
  444.  
  445.     function createMultiColumnTable(tObj, mArray, idx) {
  446.         for (j = 0; j < mArray.length; j++) {
  447.             var c = tObj.insertCell(-1);
  448.             c.id = "tblCol" + idx + j;
  449.             var txt = document.createTextNode(mArray[j]);
  450.             c.appendChild(txt);
  451.         }
  452.  
  453.     }
  454.  
  455.     function createSingleColumnTable(tObj, sArray, idx) {
  456.         var c = tObj.insertCell(-1);
  457.         var txt = document.createTextNode(sArray);
  458.         c.appendChild(txt);
  459.         c.id = "tblCol" + idx;
  460.     }
  461.  
  462.     function createMultiColumnTableRemake(tObj, mArray, idx) {
  463.  
  464.         for (j = 0; j < mArray.length; j++) {
  465.             var c = tObj.insertCell(-1);
  466.             c.id = "tblCol" + idx + j;
  467.             var txt = document.createTextNode(mArray[j]);
  468.             c.appendChild(txt);
  469.             if (selectedidx)
  470.                 c.parentNode.className = trSelectedClassName;
  471.             selectedidx = false;
  472.         } //ends if
  473.  
  474.     }
  475.  
  476.     function createSingleColumnTableRemake(tObj, sArray, idx) {
  477.         var c = tObj.insertCell(-1);
  478.         var txt = document.createTextNode(sArray);
  479.         c.appendChild(txt);
  480.         c.id = "tblCol" + idx;
  481.         if (selectedidx) {
  482.             c.parentNode.className = trSelectedClassName;
  483.             selectedidx = false;
  484.         }
  485.     }
  486.  
  487.     function removeDisplay() {
  488.         if (document.getElementById('tt_table')) {
  489.             document.body.removeChild(document.getElementById('tt_table'));
  490.         }
  491.         if (document.getElementById('pMessage')) {
  492.             document.body.removeChild(document.getElementById('pMessage'));
  493.         }
  494.     }
  495.     /*------------------------------End Table Functions-----------------------------*/
  496.     /********************************************************************************/
  497.  
  498.     /*
  499.                  
  500.                  Functions For Mouse Event Processing
  501.                  Date Created:-  21-12-07
  502.                  Date Modified:- 24-01-08
  503.      */
  504.  
  505.     function addMouseEvent(robj) {
  506.  
  507.         //oTarget,sEventType,fnHandler
  508.  
  509.         robj.onmouseover = function() {
  510.             robj.className = trOnMouseOverClassName;
  511.             // showMessage(divID,' Mouse Over :- Element Name :- '+ this.id +" Pos: "+pos+" Row Pos: "+this.getAttribute('pos'));
  512.         };
  513.  
  514.         robj.onmouseout = function() {
  515.             if (parseInt(this.getAttribute('pos')) != pos) {
  516.                 //   showMessage(divID," Mouse Out :- Element Name :- "+ this.id +" Pos: "+pos+" Row Pos: "+this.getAttribute('pos'));
  517.                 robj.className = trOnMouseOutClassName;
  518.             } else {
  519.                 robj.className = trOnMouseOverClassName;
  520.             }
  521.         };
  522.  
  523.         robj.onmousedown = function() {
  524.             //showMessage(divID,'Event Type:- Element Name :- '+ this.id +" Pos: "+pos+" Row Pos: "+this.getAttribute('pos'));
  525.             counter = robj.getAttribute('pos');
  526.             // showMessage(divID,'counter:- '+ counter +" word is "+ act_keywords[counter]+ " Row Pos: "+this.getAttribute('pos'));
  527.             isFound = true;
  528.             isZeroLength = false;
  529.             getSelected(obj);
  530.         };
  531.  
  532.     }
  533.  
  534.     /*                    
  535.        function rowMouseOver(){
  536.             var oEvent=EventUtil.getEvent();
  537.             var el=oEvent.target;
  538.              showMessage(divID,'Event Type:- '+oEvent.type+' Element Name :- '+ rowMouseOver.caller +" Pos: "+pos+" Row Pos: "+el.getAttribute('pos'));
  539.            
  540.        }
  541.        
  542.        function rowMouseOut(){
  543.            var oEvent=EventUtil.getEvent();
  544.            var el=oEvent.target;
  545.            
  546.        }
  547.        
  548.        function rowMouseDown(){
  549.            var oEvent=EventUtil.getEvent();
  550.            var el=oEvent.target;
  551.            
  552.        }
  553.        
  554.      */
  555.  
  556.     /*-------------------------End Mouse Function----------------------------*/
  557.     /*************************************************************************/
  558.  
  559.     /*
  560.          Functions For Key board Events Processing
  561.          Date Created :- 20-12-07
  562.          Date Modified:- 24-01-08
  563.          
  564.      */
  565.  
  566.     function obj_KeyPressed() {
  567.         oEvent = EventUtil.getEvent();
  568.  
  569.         //showMessage(divID,'blockKeyCode:- '+blockKeyCode+' isFOund :- '+ isFound+ ' isZeroLength:- '+ isZeroLength+ ' isNormalKey:- '+ isNormalKey);              
  570.  
  571.         if (Def(isEventAllow) && !isEventAllow && isRequired) {
  572.             //alert("Event is Stopped");
  573.             oEvent.stopPropagation();
  574.             oEvent.preventDefault();
  575.             return false;
  576.         }
  577.  
  578.         isZeroLength = !(obj.value.length > 0)
  579.  
  580.         if ((blockKeyCode && isZeroLength && isRequired)) {
  581.             //  showMessage(divID,"Event Type:- "+oEvent.type);
  582.             oEvent.stopPropagation();
  583.             oEvent.preventDefault();
  584.             //  showMessage(divID,"Event Type:- "+oEvent.type);
  585.             return false;
  586.         } else if ((!isFound && isZeroLength && !isNormalKey) && isRequired) {
  587.             oEvent.stopPropagation();
  588.             oEvent.preventDefault();
  589.             //   showMessage(divID,"Event Type:- "+oEvent.type);
  590.             return false;
  591.         } else if (!isFound && blockKeyCode && !isZeroLength) {
  592.             oEvent.stopPropagation();
  593.             oEvent.preventDefault();
  594.             //     showMessage(divID,"Event Type:- "+oEvent.type);
  595.             return false;
  596.         }
  597.  
  598.         return (!blockKeyCode);
  599.     }
  600.  
  601.     function getFormFields() {
  602.  
  603.         var oForm = obj.form;
  604.         var oName, oValue = '', tmpString = '';
  605.         for ( var i = 0; i < oForm.length - 1; i++) {
  606.             if (oForm.elements[i].type.toUpperCase() == "TEXT") {
  607.                 if (oForm.elements[i].value.trim().length != '') {
  608.                     oName = oForm.elements[i].name;
  609.                     oValue = encode(oForm.elements[i].value, 'ascii');
  610.                     tmpString += '&' + oName + '=' + oValue;
  611.                 }
  612.             }
  613.             if (oForm.elements[i].type.toUpperCase() == "RADIO") {
  614.                 if (oForm.elements[i].checked) {
  615.                     oName = oForm.elements[i].name;
  616.                     oValue = oForm.elements[i].value;
  617.                     tmpString += '&' + oName + '=' + oValue;
  618.                 }
  619.             }
  620.             if ((oForm.elements[i].type.toUpperCase() == "CHECK" || oForm.elements[i].type
  621.                     .toUpperCase() == "CHECKBOX")
  622.                     && oForm.elements[i].checked == true) {
  623.                 oName = oForm.elements[i].name;
  624.                 oValue = oForm.elements[i].value;
  625.                 tmpString += '&' + oName + '=' + oValue;
  626.             }
  627.         }
  628.         // alert(tmpString);
  629.         return tmpString;
  630.     }
  631.  
  632.     function obj_KeyDown() {
  633.  
  634.         var oEvent = EventUtil.getEvent();
  635.         var k = oEvent.keyCode;
  636.         blockKeyCode = 0;
  637.         if (oEvent.altKey && (k == 67)) {
  638.             if (isForwardAllow)
  639.                 if (forwardPage != 'undefined') {
  640.                     //var qString=getFormFields();
  641.                     //setTimeout(function(){document.location.href=forwardPage+qString;},50);  
  642.                     createPopupAsType(obj, forwardPage);
  643.                 }
  644.  
  645.         } else if (oEvent.shiftKey && (k == 9)) {
  646.             blockKeyCode = true;
  647.             isNormalKey = false;
  648.             // alert("Shift");
  649.             return false;
  650.         } else {
  651.             switch (k) {
  652.             case 38:
  653.                 goUp();
  654.                 blockKeyCode = true;
  655.                 isNormalKey = false;
  656.                 oEvent.stopPropagation();
  657.                 oEvent.preventDefault();
  658.                 return false;
  659.                 break;
  660.             // For UP ARROW KEY
  661.             case 40:
  662.                 goDown();
  663.                 blockKeyCode = true;
  664.                 isNormalKey = false;
  665.                 oEvent.stopPropagation();
  666.                 oEvent.preventDefault();
  667.                 return false;
  668.                 break;
  669.             // For Down Arrow KEY
  670.             case 13:
  671.                 getSelected(obj);
  672.  
  673.                 if (Def(gridFunction) && (isRequired == true)) {
  674.                     //gridFunction=gridFunction+"("+obj+")";
  675.                     //logMsg(gridFunction);
  676.                     if (gridFunction != undefined) {// && typeof(gridFunction)==""){
  677.                         if (Def(subGridDef)) {
  678.                             window[gridFunction].call(this, obj, oEvent,
  679.                                     undefined, subGridDef);
  680.                         } else {
  681.                             window[gridFunction].call(this, obj, oEvent);
  682.                         }
  683.                     }
  684.                 } else if (!isRequired) {
  685.                     if (Def(gridFunction) && typeof (gridFunction) == "string") {
  686.                         if (obj.value.trim().length > 0) {
  687.                             window[gridFunction].call(this, obj, oEvent);
  688.                         }
  689.                         if (Def(isEventAllow) && !isEventAllow) {
  690.                             window[gridFunction].call(this, obj, oEvent);
  691.                         }
  692.                     }
  693.                 } else {
  694.                     /* For Future Use */
  695.                 }
  696.                 if (Def(isEventAllow) && !isEventAllow) {
  697.                     oEvent.stopPropagation();
  698.                     oEvent.preventDefault();
  699.                     blockKeyCode = true;
  700.                     isNormalKey = false;
  701.                     return false;
  702.                     break;
  703.                 }
  704.                 blockKeyCode = true;
  705.                 isNormalKey = false;
  706.                 //showMessage(divID,"isNormalKey : "+isNormalKey+ " isFound : "+ isFound + " blockKeyCode : "+blockKeyCode);
  707.                 // alert("isNormalKey : "+isNormalKey+ " isFound : "+ isFound + " blockKeyCode : "+blockKeyCode);
  708.                 return false;
  709.                 break;
  710.             case 9:
  711.                 getSelected(obj);
  712.                 blockKeyCode = true;
  713.                 isNormalKey = false;
  714.                 return false;
  715.                 break;
  716.             case 27:
  717.                 /* Date Modified On 19-04-09 */
  718.                 removeDisplay();
  719.                 blockKeyCode = true;
  720.                 isNormalKey = false;
  721.  
  722.                 return false;
  723.                 break;
  724.  
  725.             /*
  726.             case 116:
  727.             blockKeyCode=true;
  728.             break;
  729.             // F5
  730.            
  731.             case 46:
  732.             blockKeyCode=true;
  733.             break;
  734.             // Delete
  735.              */
  736.             default:
  737.                 isNormalKey = true;
  738.                 blockKeyCode = false;
  739.  
  740.                 /* Here Should Be function for Handling */
  741.                 /* Back & Left Arrow Key */
  742.                 /* What if Required is Remaining */
  743.  
  744.                 if (k == 8 || k == 37) {
  745.                     if (obj.value.length == 0) {
  746.                         removeDisplay();
  747.                         break;
  748.                     } else {
  749.                         var cPos = getSelectionStart_AUTO(obj);
  750.                         if (cPos == 0) {
  751.                             if (!SerachArray_AUTO()) {
  752.                                 obj.value = "";
  753.                                 removeDisplay();
  754.                                 break;
  755.                             } else {
  756.                                 /* Date Modified On 19-04-09 */
  757.                                 removeDisplay();
  758.                                 break;
  759.                             }
  760.                         }
  761.                     }
  762.                 }
  763.  
  764.                 if (isMultiple) {
  765.                     // setTimeout(function(){actb_tocomplete(a)},50);
  766.                     setTimeout(function() {
  767.                         showkeywordsmultiple(obj)
  768.                     }, 50);
  769.                     break;
  770.                 } else {
  771.                     setTimeout(function() {
  772.                         showkeywords(obj)
  773.                     }, 50);
  774.                     break;
  775.                 }
  776.             } // ends Switch
  777.         }// ends Else
  778.     } //Ends Function
  779.  
  780.     /*----------------------------- Ends Keyboard Functions-------------------------*/
  781.     /********************************************************************************/
  782.  
  783.     /*
  784.                Navigation Functions
  785.                Date Created :- 21-12-07
  786.                Date Modified:- 24-01-07
  787.      */
  788.     function goUp() {
  789.         if (pos <= 0)
  790.             return;
  791.  
  792.         if ((document.getElementById("tblRow" + pos)) != null) {
  793.             document.getElementById("tblRow" + pos).className = trNormalClassName;
  794.  
  795.         }
  796.         pos--;
  797.         if (pos < uLimit) {
  798.             uLimit--;
  799.             dLimit--;
  800.             counter = pos;
  801.             isFound = true;
  802.             remake();
  803.             return;
  804.         }
  805.  
  806.         //   showMessage(divID," Go Up After Pos : "+pos + " Array Elements : "+ act_keywords[pos]  + " length : " + act_keywords.length);
  807.  
  808.         if ((document.getElementById("tblRow" + pos)) != null) {
  809.             document.getElementById("tblRow" + pos).className = trSelectedClassName;
  810.             counter = pos;
  811.             isFound = true;
  812.         }
  813.     }
  814.  
  815.     function goDown() {
  816.  
  817.         // showMessage(divID,"Before Pos : "+pos + " Array Elements : "+ act_keywords[pos]  + " length : " + act_keywords.length);
  818.         if (pos == act_keywords.length - 1) {
  819.             if ((document.getElementById("tblRow" + pos)) != null) {
  820.                 document.getElementById("tblRow" + pos).className = trNormalClassName;
  821.                 return;
  822.             }
  823.         }
  824.  
  825.         // showMessage(divID," "+pos);
  826.  
  827.         if (pos >= 0) {
  828.             if ((document.getElementById("tblRow" + pos)) != null) {
  829.                 document.getElementById("tblRow" + pos).className = trNormalClassName;
  830.             }
  831.         }
  832.  
  833.         pos++;
  834.  
  835.         if (pos == act_keywords.length || act_keywords.length == 1) {
  836.             if ((document.getElementById("tblRow" + pos)) != null) {
  837.                 document.getElementById("tblRow" + pos).className = trSelectedClassName;
  838.                 counter = pos;
  839.                 isFound = true;
  840.             }
  841.             return;
  842.         }
  843.  
  844.         //  showMessage(divID,"After Pos : "+pos + " Array Elements : "+ act_keywords[pos]  + " length : " + act_keywords.length);
  845.  
  846.         if (pos >= dLimit) {
  847.             uLimit++;
  848.             dLimit++;
  849.             counter = pos;
  850.             isFound = true;
  851.             remake();
  852.             return;
  853.         }
  854.  
  855.         if ((document.getElementById("tblRow" + pos)) != null) {
  856.             document.getElementById("tblRow" + pos).className = trSelectedClassName;
  857.             counter = pos;
  858.             isFound = true;
  859.         }
  860.     }
  861.  
  862.     /*-----------------------Ends Navigation Function----------------------------*/
  863.     /*****************************************************************************/
  864.  
  865.     /*
  866.           Functions For Searching Value From Array
  867.           Date Created :-20-12-07
  868.           Date Modified:-24-01-08
  869.           Date Modified:-25-01-08
  870.      */
  871.  
  872.     function showkeywords(obj) {
  873.  
  874.         if (!obj || obj == 'undefined')
  875.             return;
  876.         counter = -1;
  877.         pos = -1;
  878.         isFound = false;
  879.         isZeroLength = false;
  880.         if (obj.value.length == 0) {
  881.             removeDisplay();
  882.             uLimit = 0;
  883.             dLimit = 0;
  884.             createTable();
  885.             showMessage(divID, "");
  886.             isZeroLength = true;
  887.             // blockKeyCode=false;
  888.  
  889.         }
  890.  
  891.         for (i = 0; i < act_keywords.length; i++) {
  892.             var regk = new RegExp(act_keywords[i], "i");
  893.             var lchar = act_keywords[i].substr(0, obj.value.length);
  894.             if ((lchar.toLowerCase().indexOf(obj.value.toLowerCase()) > -1)
  895.                     && (obj.value.length > 0)) {
  896.                 pos = i;
  897.                 /* Modified on 27-08-08 */
  898.                 uLimit = i;
  899.                 dLimit = (parseInt(uLimit, 10) - 1) + maxLimit;
  900.                 /*************************/
  901.                 removeDisplay();
  902.  
  903.                 // alert(uLimit + " " + dLimit + maxLimit + typeof(maxLimit));
  904.  
  905.                 remake();
  906.                 showMessage(divID, "");
  907.                 // showMessage(divID," uLimit : " +uLimit + " dLimit : " + dLimit);
  908.                 isFound = true;
  909.                 // blockKeyCode=false;
  910.                 break;
  911.             }//ends if
  912.  
  913.         } //ends For    
  914.         /*
  915.                Here Code For Displaying Error Message
  916.          */
  917.         if (!isFound && !isZeroLength) {
  918.             showMessage(divID, "Spelling Error");
  919.         }
  920.         counter = pos;
  921.  
  922.     }
  923.  
  924.     function showkeywordsmultiple(obj) {
  925.         counter = -1;
  926.         pos = -1;
  927.         isFound = false;
  928.         isZeroLength = false;
  929.         var str;
  930.         str = "from Multiple";
  931.  
  932.         if (obj.value.length == 0) {
  933.             removeDisplay();
  934.             remake();
  935.             showMessage(divID, "");
  936.             isFound = true;
  937.             isZerroLength = true;
  938.  
  939.         }
  940.  
  941.         for (i = 0; i < act_keywords.length; i++) {
  942.             for (j = 0; j < act_keywords[i].length; j++) {
  943.                 var regk = new RegExp(act_keywords[i][0], "i");
  944.                 str = "Value:- " + obj.value + " Original Array :- "
  945.                         + act_keywords[i][0];
  946.                 var lchar = act_keywords[i][0].substr(0, obj.value.length)
  947.                 str = str + " lchar:-" + lchar;
  948.                 if (lchar.toLowerCase().indexOf(obj.value.toLowerCase()) > -1
  949.                         && obj.value.length > 0) {
  950.                     pos = i;
  951.                     str = str + "found";
  952.                     removeDisplay();
  953.                     remake();
  954.                     isFound = true;
  955.  
  956.                     showMessage(divID, "");
  957.                     break;
  958.                 } //ends IF
  959.  
  960.             } //ends Innner For
  961.         } // ends Outer For
  962.         /*
  963.             Here Code For Displaying Error Message
  964.          */
  965.         if (!isFound && !isZeroLength) {
  966.             showMessage(divID, "Spelling Error");
  967.         }
  968.         counter = pos;
  969.     } //ends Function
  970.  
  971.     /*-----------------------Ends Searching Function----------------------------------*/
  972.     /***********************************************************************************/
  973.  
  974.     function adjustWindowAuto(obj) {
  975.  
  976.         var lf, tp;
  977.         var tmplt = objLeftTop(obj);
  978.  
  979.         lf = tmplt[1]; /* left according to relative element */
  980.         tp = tmplt[0]; /* top  according to relative element */
  981.  
  982.         var wcw, wch;
  983.         var tmpwh;
  984.  
  985.         tmpwh = getViewPort();
  986.  
  987.         wcw = tmpwh[0]; /* which is client widht  of the window */
  988.         wch = tmpwh[1]; /* which is client height of the window */
  989.  
  990.         /* Now get the auto box height */
  991.  
  992.         var offset = 20; /* to make view more clearer */
  993.  
  994.         var t = document.getElementById("tt_table");
  995.         var tw, th;
  996.  
  997.         if (!t) {
  998.             tw = obj.offsetWidth;
  999.             th = 120;
  1000.         } else {
  1001.             tw = t.offsetWidth;
  1002.             th = t.offsetHeight;
  1003.         }
  1004.  
  1005.         var oh = obj.offsetHeight; /* always consider it */
  1006.  
  1007.         /* Now,convert all to Number */
  1008.  
  1009.         lf = parseInt(lf, 10);
  1010.         tp = parseInt(tp, 10);
  1011.  
  1012.         wcw = parseInt(wcw, 10);
  1013.         wch = parseInt(wch, 10);
  1014.  
  1015.         tw = parseInt(tw, 10);
  1016.         th = parseInt(th, 10);
  1017.  
  1018.         oh = parseInt(oh, 10);
  1019.  
  1020.         offset = parseInt(offset, 10);
  1021.  
  1022.         var tow;
  1023.         var toh;
  1024.  
  1025.         tow = lf + tw;
  1026.         toh = tp + th;
  1027.  
  1028.         tow = parseInt(tow, 10);
  1029.         toh = parseInt(toh, 10);
  1030.  
  1031.         var yDiff = 0;
  1032.         var xDiff = 0;
  1033.  
  1034.         var sTop = getWindowScrollTop();
  1035.         var sLeft = getWindowScrollLeft();
  1036.  
  1037.         if (sTop > 0) {
  1038.             wch += sTop;
  1039.         }
  1040.  
  1041.         if (sLeft > 0) {
  1042.             wcw += sLeft;
  1043.         }
  1044.  
  1045.         if (toh >= wch) {
  1046.             yDiff = Math.abs(toh - wch);
  1047.         }
  1048.  
  1049.         if (tow >= wcw) {
  1050.             xDiff = Math.abs(tow - wcw);
  1051.             if (sLeft > 0) {
  1052.                 xDiff = xDiff + sLeft;
  1053.             }
  1054.         }
  1055.  
  1056.         if (xDiff > 0 || yDiff > 0) {
  1057.             window.scrollBy(xDiff, yDiff);
  1058.         }
  1059.     }
  1060.  
  1061.     function getViewPort() {
  1062.  
  1063.         var viewportwidth;
  1064.         var viewportheight;
  1065.  
  1066.         // http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
  1067.  
  1068.         // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  1069.  
  1070.         if (typeof window.innerWidth != 'undefined') {
  1071.             viewportwidth = window.innerWidth,
  1072.                     viewportheight = window.innerHeight
  1073.         }
  1074.  
  1075.         // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  1076.  
  1077.         else if (typeof document.documentElement != 'undefined'
  1078.                 && typeof document.documentElement.clientWidth != 'undefined'
  1079.                 && document.documentElement.clientWidth != 0) {
  1080.             viewportwidth = document.documentElement.clientWidth,
  1081.                     viewportheight = document.documentElement.clientHeight
  1082.         }
  1083.  
  1084.         // older versions of IE
  1085.  
  1086.         else {
  1087.                     viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
  1088.                     viewportheight = document.getElementsByTagName('body')[0].clientHeight
  1089.         }
  1090.         //document.write('<p>Your viewport width is '+viewportwidth+'x'+viewportheight+'</p>');
  1091.  
  1092.         return [ viewportwidth, viewportheight ];
  1093.  
  1094.     }
  1095.  
  1096.     function getWindowScrollTop() {
  1097.  
  1098.         var stp = document.body.scrollTop;
  1099.  
  1100.         if (stp == 0) {
  1101.  
  1102.             if (window.pageYOffset)
  1103.                 stp = window.pageYOffset;
  1104.             else
  1105.                 stp = (document.body.parentElement) ? document.body.parentElement.scrollTop
  1106.                         : 0;
  1107.  
  1108.         }
  1109.  
  1110.         return stp;
  1111.     }
  1112.  
  1113.     function getWindowScrollLeft() {
  1114.  
  1115.         var slf = document.body.scrollLeft;
  1116.  
  1117.         if (slf == 0) {
  1118.  
  1119.             if (window.pageXOffset)
  1120.                 slf = window.pageXOffset;
  1121.             else
  1122.                 slf = (document.body.parentElement) ? document.body.parentElement.scrollLeft
  1123.                         : 0;
  1124.  
  1125.         }
  1126.  
  1127.         return slf;
  1128.     }
  1129.  
  1130.     function objLeftTop(obj) {
  1131.         var cleft = ctop = 0;
  1132.         //  JS_LOG(obj);
  1133.  
  1134.         //document.getElementById("divDisplayMessage").innerHTML=obj.offsetParent;
  1135.  
  1136.         if (obj.offsetParent) {
  1137.             ctop = obj.offsetTop;
  1138.             cleft = obj.offsetLeft;
  1139.             while (obj = obj.offsetParent) {
  1140.                 ctop += obj.offsetTop;
  1141.                 cleft += obj.offsetLeft;
  1142.             }
  1143.  
  1144.             return [ ctop, cleft ];
  1145.         }
  1146.  
  1147.         //return [ctop,cleft];
  1148.     }
  1149.  
  1150.     function getSelected(obj) {
  1151.         if (counter >= 0) {
  1152.             if (isMultiple)
  1153.                 obj.value = act_keywords[counter][0];
  1154.             else
  1155.                 //showMessage(divID,"Counter:="+counter );
  1156.                 obj.value = act_keywords[counter];
  1157.             isZeroLength = false;
  1158.             removeDisplay();
  1159.         }
  1160.     }
  1161.     ;
  1162.  
  1163.     /*
  1164.                This Function Is For Displaying Message
  1165.                Date Created:- 24-01-08
  1166.    
  1167.      */
  1168.  
  1169.     function showMessage(objDiv, sMessage) {
  1170.  
  1171.         if (!objDiv)
  1172.             return;
  1173.  
  1174.         if (document.getElementById('pMessage')) {
  1175.             document.body.divID
  1176.                     .removeChild(document.getElementById('pMessage'));
  1177.         }
  1178.         /*
  1179.          var pMessage=document.createElement('DIV');
  1180.              pMessage.className='error';
  1181.              pMessage.appendChild(document.createTextNode(sMessage));
  1182.              document.body.appendChild(pMessage);
  1183.          */
  1184.         if (!objDiv) {
  1185.             return;
  1186.         }
  1187.         if (sMessage == "")
  1188.             objDiv.innerHTML = "";
  1189.         else
  1190.             objDiv.innerHTML = "<p class='error'>" + sMessage + "</p>";
  1191.  
  1192.         var oFFset = objLeftTop(obj);
  1193.  
  1194.         /* Date Modified On 17-04-09 */
  1195.         if (oFFset == undefined || oFFset == null) {
  1196.             //t.style.top= eval(obj.offsetHeight)+'px';
  1197.             //t.style.left= obj.offsetLeft;
  1198.             removeDisplay();
  1199.         } else {
  1200.             if (t) {
  1201.                 t.style.top = eval(obj.offsetHeight + oFFset[0]) + 'px';
  1202.                 t.style.left = oFFset[1] + 'px';
  1203.             }
  1204.         }
  1205.     }
  1206.  
  1207.     /* Date Created :- 29-03-09 */
  1208.     /* Copied Here On 11-04-09 */
  1209.  
  1210.     function SerachArray_AUTO(refText) {
  1211.         for (i = 0; i < act_keywords.length; i++) {
  1212.             var regk = new RegExp(act_keywords[i], "i");
  1213.  
  1214.             if (act_keywords[i].toLowerCase() == obj.value.toLowerCase()) {
  1215.                 return true;
  1216.                 break;
  1217.             }
  1218.         }
  1219.  
  1220.         return false;
  1221.     }
  1222.  
  1223.     function getSelectionStart_AUTO(oTextbox) {
  1224.         if (oTextbox.createTextRange) {
  1225.             var r = document.selection.createRange().duplicate();
  1226.             r.moveEnd('character', oTextbox.value.length);
  1227.             if (r.text == '')
  1228.                 return oTextbox.value.length;
  1229.             return oTextbox.value.lastIndexOf(r.text);
  1230.         } else {
  1231.             return oTextbox.selectionStart;
  1232.         }
  1233.  
  1234.     }
  1235.  
  1236.     return this;
  1237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement