|
From: Steve W. <sw...@pa...> - 2001-07-12 17:23:06
|
Here's a sample of an edit macro button. Ugly but functional. When I was
at the NYT on the Web, I was given the task of evaluating Javascript and
making recommendations for coding practices in JS on the content
management system we were building for the editors; I found JS has far
more capability than most people use, and it's also a really cool language
despite being trapped in a couple of really crappy browsers.
diff -r1.19 editpage.html
15c15
< <form class="wikiaction" method="POST" action="###BROWSE_PAGE###">
---
> <form name="editbox" class="wikiaction" method="POST"
action="###BROWSE_PAGE###">
30a31
> <input type="button" name="timestamper" value="Add timestamp"><br>
58a60,65
>
> <script language="Javascript">
> document.editbox.timestamper.onclick = function () {
> document.editbox.content.value += Date();
> }
> </script>
In short,
1) I named the form "editbox", probably a poor name though... the textarea
is called "content" for reasons internal to PhpWiki, but here it all looks
confusing. Forms and their elements should always have names, since
all Javascript objects are really hashes and you can access things
by name instead of number. Anyway:
2) I added a button input called "timestamper"
3) At the end of the file, I put JS code in <script> tags where it is
separated out from the HTML. This makes the code much easier to maintain
in most cases. Most developers jam all the JS inside the HTML which is a
huge unreadable mess.
~swain
---
http://www.panix.com/~swain/
"Without music to decorate it, time is just a bunch of boring
production deadlines or dates by which bills must be paid."
-- Frank Zappa
|