home *** CD-ROM | disk | FTP | other *** search
/ csi.uticak12.org / csi.uticak12.org.tar / csi.uticak12.org / js / utils.hint.js < prev    next >
Text File  |  2011-10-20  |  2KB  |  59 lines

  1. Utils.Hint = function() {
  2.   return {
  3.     CreateHintWindow: function() {
  4.         var hintWindow = document.createElement('DIV');
  5.         
  6.         if (!Utils.Navigator.IE()) {
  7.             hintWindow.setAttribute('style', 'position: absolute; background: #FEFEFE; padding: 1px; display: none');
  8.             hintWindow.setAttribute('id', 'hintWindow');
  9.         }
  10.         else {
  11.             hintWindow.style.position = 'absolute';
  12.             hintWindow.style.background = '#FEFEFE';
  13.             hintWindow.style.padding = '1px';
  14.             hintWindow.style.display = 'none';
  15.             hintWindow.id = 'hintWindow';
  16.         }
  17.         
  18.         hintWindow.innerHTML = '<div id="hintText" style="background: #FEFEFE; padding: 5px;' 
  19.             + 'border: 1px solid #CCCCCC; font: 12px Arial; text-align: justify"></div>';
  20.         document.body.appendChild(hintWindow);
  21.     },
  22.     
  23.     ShowHint: function(elem) {
  24.         if (typeof elem == 'string') elem = $(elem);
  25.         if (!elem) return;
  26.         
  27.         var hint_text = elem.getAttribute('hint');
  28.         if (!hint_text) return;
  29.         
  30.         if (!$('hintWindow')) Utils.Hint.CreateHintWindow();
  31.         
  32.         var pos = Utils.Common.absolute_position(elem);
  33.         var maxLeft = Utils.Measure.windowWidth() - 255;
  34.         if (pos.left > maxLeft) pos.left = pos.left - 250;
  35.         
  36.         $('hintWindow').style.left = pos.left + 'px';
  37.         $('hintWindow').style.top = pos.top + elem.offsetHeight + 'px';
  38.         $('hintWindow').style.width = '250px';
  39.         
  40.         $('hintText').innerHTML = hint_text;
  41.         $('hintWindow').style.display = 'block';
  42.     },
  43.     
  44.     HideHint: function() {
  45.         if (!$('hintWindow')) return;
  46.         $('hintWindow').style.display = 'none';
  47.     },
  48.     
  49.     add_listeners: function() {
  50.         var list = document.getElementsByTagName('hint');
  51.         for (var i=0; i<list.length; i++) {
  52.             Utils.Event.add(list[i].getAttribute('element'), "mouseover", Utils.Hint.ShowHint.bind(this, list[i].getAttribute('element')), false);
  53.         }
  54.     }
  55.     
  56.   }
  57. }();
  58.  
  59. Utils.Init.observe(Utils.Hint.add_listeners);