Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    2
    Member #
    18918
    Hi everyone,

    I am noob to javascript, really I am still waiting for my visual quickstart guide book.

    my question is this, I am pretty good at xhtml and css as a designer but I am trying to make a website a bit more dynamic. I've found a website which offers free code and though it seems harmless enough while looking at its source it links to hotscripts, when I went to hotscripts there to be a ton of scripts dealing with adult content. That alone raises a bunch of flags; scripts for adult video? scripts to make pop ups unblockable? no thank you!

    nevertheless, the original site http://www.jtricks.com has one particular script which is exactly what I am looking for, but I don't want to paste this code into a site without knowing what it does. I can tell by looking at the code more or less what it is doing but there are a few lines which has me worried...most likely it is a case of ignorance on my part. would one of your resident java script gurus have a look at this to see if it is safe for a cut and past operation? i.e.: make sure it doesn't "reach out" to a remote server to load more code or anything else which may make a website toxic? also if you could, maybe take a look at the original site itself and see if other tools appear to be legit as well. I have pasted the code for a "floating menu" down below.

    I humbly apologize for this, but I as I have previously stated, I am just beginning to take my first steps into javascript and until I know exactly what I am doing, I have to rely on other sources.

    here is the code for the "floating menu" that I am interested in:

    Code:
    <script type="text/javascript"><!--
    /* Script by: www.jtricks.com
     * Version: 20071017
     * Latest version:
     * http://www.jtricks.com/javascript/na.../floating.html
     */
    var floatingMenuId = 'floatdiv';
    var floatingMenu =
    {
        targetX: -250,
        targetY: 10,
    
        hasInner: typeof(window.innerWidth) == 'number',
        hasElement: typeof(document.documentElement) == 'object'
            && typeof(document.documentElement.clientWidth) == 'number',
    
        menu:
            document.getElementById
            ? document.getElementById(floatingMenuId)
            : document.all
              ? document.all[floatingMenuId]
              : document.layers[floatingMenuId]
    };
    
    floatingMenu.move = function ()
    {
        floatingMenu.menu.style.left = floatingMenu.nextX + 'px';
        floatingMenu.menu.style.top = floatingMenu.nextY + 'px';
    }
    
    floatingMenu.computeShifts = function ()
    {
        var de = document.documentElement;
    
        floatingMenu.shiftX =  
            floatingMenu.hasInner  
            ? pageXOffset  
            : floatingMenu.hasElement  
              ? de.scrollLeft  
              : document.body.scrollLeft;  
        if (floatingMenu.targetX < 0)
        {
            floatingMenu.shiftX +=
                floatingMenu.hasElement
                ? de.clientWidth
                : document.body.clientWidth;
        }
    
        floatingMenu.shiftY = 
            floatingMenu.hasInner
            ? pageYOffset
            : floatingMenu.hasElement
              ? de.scrollTop
              : document.body.scrollTop;
        if (floatingMenu.targetY < 0)
        {
            if (floatingMenu.hasElement && floatingMenu.hasInner)
            {
                // Handle Opera 8 problems
                floatingMenu.shiftY +=
                    de.clientHeight > window.innerHeight
                    ? window.innerHeight
                    : de.clientHeight
            }
            else
            {
                floatingMenu.shiftY +=
                    floatingMenu.hasElement
                    ? de.clientHeight
                    : document.body.clientHeight;
            }
        }
    }
    
    floatingMenu.calculateCornerX = function()
    {
        if (floatingMenu.targetX != 'center')
            return floatingMenu.shiftX + floatingMenu.targetX;
    
        var width = parseInt(floatingMenu.menu.offsetWidth);
    
        var cornerX =
            floatingMenu.hasElement
            ? (floatingMenu.hasInner
               ? pageXOffset
               : document.documentElement.scrollLeft) + 
              (document.documentElement.clientWidth - width)/2
            : document.body.scrollLeft + 
              (document.body.clientWidth - width)/2;
        return cornerX;
    };
    
    floatingMenu.calculateCornerY = function()
    {
        if (floatingMenu.targetY != 'center')
            return floatingMenu.shiftY + floatingMenu.targetY;
    
        var height = parseInt(floatingMenu.menu.offsetHeight);
    
        // Handle Opera 8 problems
        var clientHeight = 
            floatingMenu.hasElement && floatingMenu.hasInner
            && document.documentElement.clientHeight 
                > window.innerHeight
            ? window.innerHeight
            : document.documentElement.clientHeight
    
        var cornerY =
            floatingMenu.hasElement
            ? (floatingMenu.hasInner  
               ? pageYOffset
               : document.documentElement.scrollTop) + 
              (clientHeight - height)/2
            : document.body.scrollTop + 
              (document.body.clientHeight - height)/2;
        return cornerY;
    };
    
    floatingMenu.doFloat = function()
    {
        var stepX, stepY;
    
        floatingMenu.computeShifts();
    
        var cornerX = floatingMenu.calculateCornerX();
    
        var stepX = (cornerX - floatingMenu.nextX) * .07;
        if (Math.abs(stepX) < .5)
        {
            stepX = cornerX - floatingMenu.nextX;
        }
    
        var cornerY = floatingMenu.calculateCornerY();
    
        var stepY = (cornerY - floatingMenu.nextY) * .07;
        if (Math.abs(stepY) < .5)
        {
            stepY = cornerY - floatingMenu.nextY;
        }
    
        if (Math.abs(stepX) > 0 ||
            Math.abs(stepY) > 0)
        {
            floatingMenu.nextX += stepX;
            floatingMenu.nextY += stepY;
            floatingMenu.move();
        }
    
        setTimeout('floatingMenu.doFloat()', 20);
    };
    
    // addEvent designed by Aaron Moore
    floatingMenu.addEvent = function(element, listener, handler)
    {
        if(typeof element[listener] != 'function' || 
           typeof element[listener + '_num'] == 'undefined')
        {
            element[listener + '_num'] = 0;
            if (typeof element[listener] == 'function')
            {
                element[listener + 0] = element[listener];
                element[listener + '_num']++;
            }
            element[listener] = function(e)
            {
                var r = true;
                e = (e) ? e : window.event;
                for(var i = element[listener + '_num'] -1; i >= 0; i--)
                {
                    if(element[listener + i](e) == false)
                        r = false;
                }
                return r;
            }
        }
    
        //if handler is not already stored, assign it
        for(var i = 0; i < element[listener + '_num']; i++)
            if(element[listener + i] == handler)
                return;
        element[listener + element[listener + '_num']] = handler;
        element[listener + '_num']++;
    };
    
    floatingMenu.init = function()
    {
        floatingMenu.initSecondary();
        floatingMenu.doFloat();
    };
    
    // Some browsers init scrollbars only after
    // full document load.
    floatingMenu.initSecondary = function()
    {
        floatingMenu.computeShifts();
        floatingMenu.nextX = floatingMenu.calculateCornerX();
        floatingMenu.nextY = floatingMenu.calculateCornerY();
        floatingMenu.move();
    }
    
    if (document.layers)
        floatingMenu.addEvent(window, 'onload', floatingMenu.init);
    else
    {
        floatingMenu.init();
        floatingMenu.addEvent(window, 'onload',
            floatingMenu.initSecondary);
    }
    
    //--></script>

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    Which lines worried you? FYI there's nothing to worry about in that script.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    Junior Member
    Join Date
    May 2009
    Posts
    2
    Member #
    18918
    Thanks WIRED I really appreciate you taking time to review the script. I am just barely learning javascript and though I have read about event listeners in relation to javascript my ignorance of the language makes things difficult for me to understand exactly what I am looking at. Essentially I just wanted to make sure I wasn't going to use anything which did something in the background so to speak. I am pretty much a designer...you get me on maya, photoshop, painter, illustrator, and a good wysiwyg and I am rock and rolling...outside of xhtml and css, once I get into any heavy coding I end up taking a nap after about twenty minutes. I am really more orientated towards doing things visually and am really inspired by those who can write line after line and end up with what they were seeing in their mind's eye. I know posts like these may really make some of you who can create all your code with text editors pull your hair out and I really do want you to know that helping out the clueless ones like me, really helps us on so many levels. again, thank you helping me out on this.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:10 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com