How Can I Integrate these Two Scripts?

Discussion in 'JavaScript' started by Masterful, May 15, 2009.

  1. #1
    I have a script on my site which expands and collapses div elements. This first part goes in the head:

             function ToggleVis(elem, tohide) {
                 if (typeof(elem) != "object") {
                     elem = document.getElementById(elem);
                 }
                 if (typeof(tohide) != "object") {
                       tohide = document.getElementById(tohide);
                 }
                 if (tohide == null || tohide.style == null) {
                  return false;
                 }
                 if (tohide.style.display != 'none') {
                  tohide.style.display = 'none';
                  elem.innerHTML = 'Show store info +';
                  elem.value = 'Show store info +';
                 }
                 else {
                  tohide.style.display = '';
                  //(elem.innerHTML != null) ? elem.innerHTML = 'Hide store info -' : elem.value = 'Hide store info -';
                  elem.innerHTML = 'Hide store info -';
                  elem.value = 'Hide store info -';
                 }
             }
    Code (markup):
    And this other part goes in the body:

    <a  href="#" onclick="ToggleVis(this, 'div_id'); return false;">Show store info +</a>
    
    
    <div id="div_id" style="display: none">Content to be expanded and collapsed.</div>
    Code (markup):
    When the anchor is clicked, the content in the div is expanded/collapsed.

    I also have another script in my site's body element which copies text to clipboard:

             <script type="text/JavaScript">
                var clip = new ZeroClipboard.Client();
                clip.setText('CODE1');
                clip.glue('button');         
                clip.addEventListener('mouseOver', function(client) {
                document.getElementById("hoverpopup").style.visibility = "visible";
                } );
                clip.addEventListener( 'mouseOut', function(client) {
                document.getElementById("hoverpopup").style.visibility = "hidden";
                } );
                clip.addEventListener( 'complete', function(client, text) {
                document.getElementById("hoverpopup").style.visibility = "hidden";
                window.open('http://www..com','','width=400,height=200');
                } );
                window.onresize = resize;
                function resize() {
                 clip.reposition();
                 }
             </script>
    Code (markup):
    Is there a way of making the resize() function of the second script fire whenever a div is expanded or collapsed with the first script?
     
    Masterful, May 15, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Just add:
    resize();

    at the very end of the first script, before the last }
     
    camjohnson95, May 15, 2009 IP
  3. MrMalik

    MrMalik Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah Johnson is quite right. You must call resize(); just before the last } of first script.
     
    MrMalik, May 15, 2009 IP