lcplben wrote:
> Problem page: www.sellmycalls.com/option-chain-ex.html
> Problem code: lines 344-389
>
> Each column TH has a minimize icon on the left. It's meant to minimize
> the entire column by shrinking its width to some small number, like
> 10px or .5em.
>
> After I click the icon, however, the column width/offsetWidth/
> clientWidth doesn't change; it remains stuck at 46 on my machine.
I have no inclination to debug your original code (which would involve a
lot more than just the lines you mentioned); create (and, if still
necessary, post) a reduced test case, and clearly state your target runtime
environments.
A few initial observations and suggestions (far from being complete),
though:
- I find your source code hard to read; consider
* using multi-line pre-comments instead of single-line post-comments;
use single-line comments only for deactivating comments, not
documenting ones, to distinguish them;
* aligning braces of /Block/ statements (that helps especially if you
would insist on the comment style);
* making it an exception for a line to exceed 80 characters, including
comments;
* removing spaces after opening and before closing parentheses
* always adding a space after control statements like `if', to
distinguish those statements from method calls;
* declaring variables where you use them first instead.
- Line 344 is (comments removed)
for ( i = 0; i < cols.length; ++i ) {
More efficient would be
for (i = 0, len = cols.length; i < len; ++i) {
(provided `len' was declared and `cols.length' did not change in the
loop). If order would not matter, you should consider a countdown
loop which is often more efficient:
for (i = cols.length; i--

{
This applies to other lines as well. (Whether `++i' is more efficient
than `i++' is questionable; I find the latter easier to read than the
former.)
- The identifier `getElementsByClass' might already be in use; consider
prefixing the identifier or "namespacing" the method.
- The first argument of columnHideShow() is named `theClass' but a
reference to the element having the value of the `class' attribute
is expected instead; consider renaming it.
- Consider placing each assignment it its own line instead, including
variable initializations.
- Repeated `findParentTH(theClass)' calls are inefficient if the value
of `theClass' does not change; consider assigning to `theClass' when
necessary and using the assigned value throughout the method.
- It is unnecessary, and less efficient, to create empty Arrays first
and later overwrite the stored reference, if the return value of the
method that is assigned to the property variable later already returns
a reference to an empty Array if there are no matches. This applies,
for example, to
var cols = [];
// ...
cols = getElementsByClass( th.className, main, '*' );
in lines 290 and 298, respectively. Consider writing either
var cols;
//
cols = getElementsByClass(th.className, main, '*');
or
var cols = getElementsByClass(th.className, main, '*');
instead.
- `main' is assigned the same value on each call of columnHideShow();
consider caching it to avoid calling the method right-hand side.
- The `tagName' property might be easier to recognize than the `nodeName'
property; it is sufficient here, and also slightly more compatible.
- In line 304, there is (comments snipped)
if( typeof hideState == 'undefined' ) {
var hideState = columns[j].hideState + 1;
}
columns[j].hideState = hideState & 1;
in which you augment a host object (referred to by `columns[j]') with
a property and read from it. This is unreliable, do not do it; use
wrapper objects instead, or store the state elsewhere but in a host
object.
All in all, I think a rewrite is in order.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)