SitePoint Sponsor |
|
User Tag List
Results 1 to 14 of 14
-
Jul 13, 2001, 03:43 #1
Why is DW’s JS code so complicated?
I have used Dreamweaver for some time now and was especially thrilled about all automatic functions that can insert Java Script code (the rollover code for example) on my pages. But when I compared the code that DW inserts with some cut n’ paste Java Script code that can be found on the Internet I noticed a big difference. Why is DW’s Java Script code so complicated?
-
Jul 13, 2001, 05:35 #2
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Encapsulated.
Many JS functions are simply:
function myFunc()
{
window.myform.myelement.value="blah";
}
Whereas a DW function might look like:
function myFunc(loc,message)
{
loc.value=message;
}
And you'd call that with myFunc('window.myform.myelement','howdy partner')
This is encapsulation. You can reuse functions again and again. Granted my example was simple, but that's the gist of it all. Does that answer your question? To really debug a DW JS function you need to take it completely in context.... anyways, I'm babbling.
-
Jul 13, 2001, 08:10 #3
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That's not what she means coco.
Take a look at DW's built in image swap function compared to a "good" swap image. The code for DW's is about 20 lines long while the good one can be as little as 4-5 lines.Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jul 13, 2001, 08:13 #4
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
hmm... ah well, I stand mildly corrected
-
Jul 13, 2001, 08:32 #5
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can we get some example code here?
-
Jul 13, 2001, 09:04 #6
Example: Here is a rollover menu made in Fireworks and imported into Dreamweaver. The code is really bad (and the rollovers don't even work properly...).
-
Jul 13, 2001, 09:12 #7
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
as opposed to THIS nice clean code.
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jul 13, 2001, 09:29 #8
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The rollovers work properly for me, and the code itself looks fine. There are several reasons why the functions are complicated:
- Browser compatibility
- Integration - the functions are set up to work with all other DW functions, which you may or may not use. In complicated scripts this results in simpler data, but in simple scripts some of the data is superfluous
- Multiple actions - many of the DW scripts allow multiple actions in a single functions call, like resetting multiple images in MM_SwapImgRestore and swapping multiple images in MM_swapImage
- Editability - It is difficult to automate scripting because the code has to be modified at several different places, like onLoad for <body>, onmouseover of the link, and name of the image. DW tries to keep as much information as possible in the image object itself, so that it's easier for the program to keep track of dynamic data
- User error - Because it's an HTML file, the javascript and other code can be edited by users, which can create mistakes or incongruities. For example, you might delete an image and link from the HTML file manually, but forget that you're still preloading the image in the <body> onLoad tag.
In conclusion, DW's code is good for the level of automation it gives, in that you don't need to edit any code at all. Because it's forced to cater to all user needs as well as integration with other functions, it's somewhat "bloated", but there is no extra or fluff code.
-
Jul 13, 2001, 09:55 #9
Thanx for explaining Anarchos! I knew that there had to be a reason for that code.
-
Jul 13, 2001, 10:30 #10
- Join Date
- May 2001
- Location
- Lyons, Colorado
- Posts
- 391
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've been wondering this one too, good info. Before Dreamweaver I used much more simple code even on more complex rollovers, but these worked fine as far as cross-browser compatibility was concerned. I'd say Anarchos explained it best, but I really did like the old K.I.S.S. method.
Dreamweaver sure took the fun out of working with JS. I'll use it for that simply because I can't ignore how much time it saves.
Look at this mess!
Code:<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_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_findObj(n, d) { //v4.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); if(!x && document.getElementById) x=document.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script>
Everything has been figured out, except how to live. - Jean-Paul Sartre (1905-1980)
-
Jul 13, 2001, 18:49 #11
- Join Date
- Jul 1999
- Location
- Lancashire, UK
- Posts
- 8,277
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I think Dreamweaver code is simply awful. What I do is I ahve a folder on my machine called LIBRARY and over the years I have collected bits of code and other things which I reuse over and over again. Mostly I save them in text files and just copy and paste when the need arises.
-
Jul 14, 2001, 00:26 #12
Sounds like a very good idea, Nicky. I have all my scripts and tutorials printed out and stored in a folder.
-
Jul 14, 2001, 03:05 #13
-
Jul 14, 2001, 13:14 #14
- Join Date
- Sep 1999
- Location
- Singapore
- Posts
- 854
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You could try looking at the k10k.net Javascript library which they are giving away. Some good stuff in there.
And I'll agree with Anarchos about the Dreamweaver Javascript.
Bookmarks