includes/clientside/static/misc.js
changeset 520 4c16e87cfeae
parent 513 c15fbf197a54
child 537 547b7ba6d535
equal deleted inserted replaced
517:c6118b9e13bd 520:4c16e87cfeae
   210     document.getElementById('ajaxloadicon').src=scriptPath + '/images/spacer.gif';
   210     document.getElementById('ajaxloadicon').src=scriptPath + '/images/spacer.gif';
   211   }
   211   }
   212 }
   212 }
   213 
   213 
   214 /*
   214 /*
   215  * Search boxes
       
   216  */
       
   217  
       
   218 function buildSearchBoxes()
       
   219 {
       
   220   var divs = document.getElementsByTagName('*');
       
   221   var boxes = new Array();
       
   222   for ( var i = 0; i < divs.length; i++ )
       
   223   {
       
   224     if ( divs[i].className)
       
   225     {
       
   226       if ( divs[i].className.substr(0, 9) == 'searchbox' )
       
   227       {
       
   228         boxes.push(divs[i]);
       
   229       }
       
   230     }
       
   231   }
       
   232   for ( var i = 0; i < boxes.length; i++ )
       
   233   {
       
   234     if ( boxes[i].className.match(/^searchbox\[([0-9]+)px\]$/) )
       
   235     {
       
   236       var width = boxes[i].className.match(/^searchbox\[([0-9]+)px\]$/);
       
   237       width = parseInt(width[1]);
       
   238     }
       
   239     else
       
   240     {
       
   241       var width = 120;
       
   242     }
       
   243     createSearchBox(boxes[i], width);
       
   244   }
       
   245 }
       
   246 
       
   247 function createSearchBox(parent, width)
       
   248 {
       
   249   if ( typeof(parent) != 'object')
       
   250   {
       
   251     alert('BUG: createSearchBox(): parent is not an object');
       
   252     return false;
       
   253   }
       
   254   //parent.style.padding = '0px';
       
   255   //parent.style.textAlign = 'center';
       
   256   parent.style.width = width + 'px';
       
   257   var submit = document.createElement('div');
       
   258   submit.onclick = function() { searchFormSubmit(this); };
       
   259   submit.className = 'js-search-submit';
       
   260   var input = document.createElement('input');
       
   261   input.className = 'js-search-box';
       
   262   input.value = 'Search';
       
   263   input.name = 'q';
       
   264   input.style.width = ( width - 28 ) + 'px';
       
   265   input.onfocus = function() { if ( this.value == 'Search' ) this.value = ''; };
       
   266   input.onblur  = function() { if ( this.value == '' ) this.value = 'Search'; };
       
   267   parent.appendChild(input);
       
   268   var off = fetch_offset(input);
       
   269   var top = off['top'] + 'px';
       
   270   var left = ( parseInt(off['left']) + ( width - 24 ) ) + 'px';
       
   271   submit.style.top = top;
       
   272   submit.style.left = left;
       
   273   parent.appendChild(submit);
       
   274 }
       
   275 
       
   276 function searchFormSubmit(obj)
       
   277 {
       
   278   var input = obj.previousSibling;
       
   279   if ( input.value == 'Search' || input.value == '' )
       
   280     return false;
       
   281   var p = obj;
       
   282   while(true)
       
   283   {
       
   284     p = p.parentNode;
       
   285     if ( !p )
       
   286       break;
       
   287     if ( typeof(p.tagName) != 'string' )
       
   288       break;
       
   289     else if ( p.tagName.toLowerCase() == 'form' )
       
   290     {
       
   291       p.submit();
       
   292     }
       
   293     else if ( p.tagName.toLowerCase() == 'body' )
       
   294     {
       
   295       break;
       
   296     }
       
   297   }
       
   298 }
       
   299 
       
   300 /*
       
   301  * AJAX login box (experimental)
   215  * AJAX login box (experimental)
   302  * Moved / rewritten in login.js
   216  * Moved / rewritten in login.js
   303  */
   217  */
   304 
   218 
   305 // Included only for API-compatibility
   219 // Included only for API-compatibility