includes/clientside/static/grippy.js
changeset 1 fe660c52c48f
child 1227 bdac73ed481e
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 // Resizable textareas (fun!)
       
     2 
       
     3 function taStartDrag()
       
     4 {
       
     5   obj = this;
       
     6   current_ta = obj.previousSibling;
       
     7   startmouseX = mouseX;
       
     8   startmouseY = mouseY;
       
     9   startScroll = getScrollOffset();
       
    10   is_dragging = true;
       
    11   startwidth  = getElementWidth(current_ta.id);
       
    12   startheight = getElementHeight(current_ta.id);
       
    13   var body = document.getElementsByTagName('body');
       
    14   body = body[0];
       
    15   body.style.cursor = 's-resize';
       
    16 }
       
    17 function taInDrag()
       
    18 {
       
    19   if(!is_dragging) return;
       
    20   cw = startwidth;
       
    21   ch = startheight;
       
    22   mx = mouseX;
       
    23   my = mouseY + getScrollOffset() - startScroll;
       
    24   ch = -6 + ch + ( my - startmouseY );
       
    25   current_ta.style.height = ch+'px';
       
    26   if(do_width)
       
    27   {
       
    28     current_ta.style.width  = mx+'px';
       
    29     current_ta.nextSibling.style.width  = mx+'px';
       
    30   }
       
    31 }
       
    32 function taCloseDrag()
       
    33 {
       
    34   is_dragging = false;
       
    35   current_ta = false;
       
    36   body = document.getElementsByTagName('body');
       
    37   body = body[0];
       
    38   body.style.cursor = 'default';
       
    39 }
       
    40 
       
    41 var grippied_textareas = new Array();
       
    42 
       
    43 function initTextareas()
       
    44 {
       
    45   var textareas = document.getElementsByTagName('textarea');
       
    46   for (i = 0;i < textareas.length;i++)
       
    47   {
       
    48     if(!textareas[i].id)
       
    49       textareas[i].id = 'autoTextArea_'+Math.floor(Math.random()*100000);
       
    50     cta = textareas[i];
       
    51     var divchk = ( in_array(cta.id, grippied_textareas) ) ? false : true;
       
    52     if(divchk)
       
    53     {
       
    54       grippied_textareas.push(cta.id);
       
    55       makeGrippy(cta);
       
    56     }
       
    57   }
       
    58 }
       
    59 
       
    60 function makeGrippy(cta)
       
    61 {
       
    62   var thediv = document.createElement('div');
       
    63   thediv.style.backgroundColor = '#ceceed';
       
    64   thediv.style.backgroundImage = 'url('+scriptPath+'/images/grippy.gif)';
       
    65   thediv.style.backgroundPosition = 'bottom right';
       
    66   thediv.style.backgroundRepeat = 'no-repeat';
       
    67   thediv.style.width = getElementWidth(cta.id)+'px';
       
    68   thediv.style.cursor = 's-resize';
       
    69   thediv.style.className = 'ThisIsATextareaGrippy';
       
    70   thediv.id = 'autoGrippy_'+Math.floor(Math.random()*100000);
       
    71   thediv.style.height = '12px';
       
    72   thediv.onmousedown = taStartDrag;
       
    73   thediv.style.border = '1px solid #0000A0';
       
    74   if(cta.style.marginBottom)
       
    75   {
       
    76     thediv.style.marginBottom = cta.style.marginBottom;
       
    77     cta.style.marginBottom = '0';
       
    78   }
       
    79   if(cta.style.marginLeft)
       
    80   {
       
    81     thediv.style.marginLeft = cta.style.marginLeft;
       
    82   }
       
    83   if(cta.style.marginRight)
       
    84   {
       
    85     thediv.style.marginRight = cta.style.marginRight;
       
    86   }
       
    87   document.onmouseup = taCloseDrag;
       
    88   if(cta.nextSibling) cta.parentNode.insertBefore(thediv, cta.nextSibling);
       
    89   else cta.parentNode.appendChild(thediv);
       
    90 }
       
    91