SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot Shap's Avatar
    Join Date
    Jan 2002
    Location
    Phoenix
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can someone tell me what this does?

    Hey, I got this script somewhere a while back, and can't remember exactly what it does.. I can partially read java. What more does this do besides, preload all the images?

    -------------------------------------------

    <script language="JavaScript">
    <!--

    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v3.0
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
    }

    function MM_nbGroup(event, grpName) { //v3.0
    var i,img,nbArr,args=MM_nbGroup.arguments;
    if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
    img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
    if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
    nbArr[nbArr.length] = img;
    for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
    if (!img.MM_up) img.MM_up = img.src;
    img.src = img.MM_dn = args[i+1];
    nbArr[nbArr.length] = img;
    } }
    } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
    if (!img.MM_up) img.MM_up = img.src;
    img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
    nbArr[nbArr.length] = img;
    }
    } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
    img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
    } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
    for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
    if (!img.MM_up) img.MM_up = img.src;
    img.src = img.MM_dn = args[i+1];
    nbArr[nbArr.length] = img;
    } }
    }

    function MM_callJS(jsStr) { //v2.0
    return eval(jsStr)
    }

    function MM_validateForm() { //v3.0
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
    if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
    if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
    } else if (test!='R') { num = parseFloat(val);
    if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
    if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
    min=test.substring(8,p); max=test.substring(p+1);
    if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
    }

    function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v3.0
    var newURL='', verStr=navigator.appVersion, app=navigator.appName, version = parseFloat(verStr);
    if (app.indexOf('Netscape') != -1) {
    if (version >= NSvers) {if (NSpass>0) newURL=(NSpass==1)?URL:altURL;}
    else {if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;}
    } else if (app.indexOf('Microsoft') != -1) {
    if (version >= IEvers || verStr.indexOf(IEvers) != -1)
    {if (IEpass>0) newURL=(IEpass==1)?URL:altURL;}
    else {if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;}
    } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
    if (newURL) { window.location=unescape(newURL); document.MM_returnValue=false; }
    }
    //-->
    </script>
    --------------------------------

  2. #2
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like a prewritten script from Macromedia (i.e. Dreamweaver) that preloads images, does rollovers and checks the browser amonst other things.

    I would advise against iusing code that is bloated such as this.

    Glen

  3. #3
    SitePoint Zealot Shap's Avatar
    Join Date
    Jan 2002
    Location
    Phoenix
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bloated, you mean does so many diffent things in one? I remember what it was for now, yeah it was for a some role over nav images. thanks

  4. #4
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, bloated in the fact that it uses far too much code when half as much code will do the same job more efficiently.

    For example a generic rollover and preload script is tiny and easier to read and use compared tot he one used there.

    Glen

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2002
    Posts
    420
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would the script be if Dreamweaver didnt make it?
    Like you say its bloated how would you do it?
    Wavelan

  6. #6
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If all that is for a rollover image. WOW...now I do like macromedia preload (I find it ALWAYS works where the typical one seems to no be 100%) but anyways a rollover script is short for images. Try this tip for a good start.

    http://www.sitepointforums.com/showt...threadid=30006

    That is a total rollover and works well.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  7. #7
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is all code generated by Macromedia DreamWeaver 3.0, and it is not all for a single purpose. This particular block contains code which does the following (in order), all of which is 100% cross-browser compatible (which a lot of code isn't):

    Preload images
    Locate an element by name in the DOM
    Rollover groups of images
    Evaluate a JavaScript statement (from a string)
    Validate the data in a form
    Detect browser type & version

    So, it's not surprising that it's a little longer than a standard rollover!! In fact, the code can't really do a "normal" rollover at all!!!

    I have always been impressed with DW's excellent JS code, as it is 100% guaranteed to work every time. In addition, the code is clean and very well optimised (you couldn't replicate the same functionality and flexibility with any shorter code), so I'm afraid I don't agree with Glen at all!!!


    M@rco


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •