DreamWeaver Tips and tricks!!



  • Did you know that DreamWeaver can help you reduce the amount of code you have to write? With the simple DreamWeaver function:

    <script type="text/JavaScript">
    <!--
    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }
    //-->
    </script>

    You can turn this:

    window.open("MyNewWindow.html","MyNewWindow","width=400,height=300")

    Into this:

    MM_openBrWindow("MyNewWindow.html","MyNewWindow","width=400,height=300")

    Thank you, DreamWeaver! What would I have done without you?!?

    BTW, the real WTF is that this is v2.0 of the script... What on earth could they have changed/improved from v1.0?



  • Cool, so you can save -4 chars. I was definitly waiting for that.



  • The real WTF is that people use Dreamweaver and JavaScript popups.



  • The real WTF is that people still waste their time typing SGML comments at the beginning and end of code inside <script> tags. The reason that practice was started was to hide JS code from ridiculously old browsers (i.e. Netscape 3.0) that don't recognize the <script> tag. Pretty much nobody uses those browsers anymore, and I doubt even 1% of the people that continue the practice bother testing their sites in them.



  • Yeah, it definitely seems stupid. But then again, it is Dreamweaver, so I guess it's expected? :P

    Speaking of Dreamweaver, I used to get heaps of people emailing me asking how to get a hit counter in Dreamweaver 8.0. I had no idea why this was until recently. It turns out that a page on my site (http://www.dansoftaustralia.net/other/history.htm, this is like 2 years old now, I should really update it) is the number one result for the term Dreamweaver 8.0 hit counter in Google. Stupid thing :P

    What on earth could they have changed/improved from v1.0?
    It'd imagine it'd be something like:
    <script type="text/JavaScript">
    <!--
    function MM_openBrWindow(theURL,winName,features) { //v1.0
    	// TODO: Replace with production code.
    	alert('Please open ' + theURL + ' in a new browser window. Features:' + features);
    }
    //-->
    </script>
    
    :D


  • @caffeinatedbacon said:

    What on earth could they have changed/improved from v1.0?

    I have here v1.0 of the script.  This is a DailyWTF exclusive: 

    <script language="javascript">
        <!--
            function MM_openBrWindow(theURL,winName,features) {//v1.0
                x = 0;
                start = 0;
                arr = new Array();
                //alert(features);
                for (i = 0; i < features.length; ++i) {
                    if (features.substr(i,1) == ",") {
                        arr[x] = features.substr(start,i - start);
                        start = i + 1;
                        //alert(arr[x]);
                        x = x + 1;
                    }
                }
                for (i = 0; i < x; ++i) {
                    for (j = i + 1; j < x; ++j) {
                        if(arr[i] > arr[j]) {
                            t = arr[i];
                            arr[i] = arr[j];
                            arr[j] = t;
                        }
                    }
                }
                sorted = "";
                for (i = 0; i < x; ++i) {
                    sorted = sorted + ',' + arr[i];
                }
                //alert(sorted);
                 window.open(theURL,winName,sorted);//features);
            }
        //-->
    </script>

    Can you spot the errors?
     



  • @hallo.amt said:

    Cool, so you can save -4 chars. I was definitly waiting for that.

    That's not counting all of these characters:

     

    <script type="text/JavaScript">
    <!--
    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }
    //-->
    </script>
     



  • How come nobody has mentioned this?

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


     



  • If you think this is bad, then look at the GREAT Dreamweaver JS mouse over script it generates.



    function MM_findObj(n, d) { //v4.01
    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);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_nbGroup(event, grpName) { //v6.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])? args[i+1] : img.MM_up);
    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") {
    nbArr = document[grpName];
    if (nbArr)
    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])? args[i+1] : img.MM_up;
    nbArr[nbArr.length] = img;
    } }
    }

     
    instead of
     
    css:
    #menu ul li:hover {
    	background-image: url('button_hover_url') 

     

    But yes, of course there are situations where CSS just won't work, but i'll be damned if a need more then 5 maybe 7 lines of JS code to do it. 


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.