]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/toggle_fails_on_Safari.mdwn
Joey's right, that's good enough.
[ikiwiki.git] / doc / bugs / toggle_fails_on_Safari.mdwn
1 The [[plugins/toggle]] plugin has no effect when viewed on the Safari web browser.
2
3 All toggles appear open all the time.
4
5 I don't know if this is true for other webkit browsers (the new Konqueror, the iPhone, etc).
6 I'm currently testing in the Safari nightly builds, but I've seen the bug in the current release
7 of Safari too.
8
9 Looking at the Safari Web Inspector, it believes there is a parse error on line 47 of the
10 [[news]] page.  This is the definition of the getElementsByClass(class) function.
11
12     45 }
13     46
14     47 function getElementsByClass(class) {
15        SyntaxError: Parse error
16     48  var ret = new Array();
17
18 > Reproduced in epiphany-webkit on debian.
19
20 > Also noticed something interesting when I opened the page in vim. It
21 > highlighted the "class" like a type definition, not a variable. Sure
22 > enough, replacing with "c" fixed it.
23
24 > I wonder if webkit is actually in the right here, and using a reseved
25 > word like, presumably, "class" as a variable name is not legal. As I try
26 > to ignore javascript as much as possible, I can't say. [[done]] --[[Joey]]
27
28 >> I also started having a look at this.  I found the same issue with the
29 >> the variable 'class'.  I'm not a javascript guru so I looked on the web
30 >> at other implementations of getElementsByClass() and noticed some
31 >> things that we might use.  I took a bunch of different ideas and came
32 >> up with this:
33
34     function getElementsByClass(cls, node, tag) {
35         if (document.getElementsByClass)
36                 return document.getElementsByClass(cls, node, tag);
37         if (! node) node = document;
38         if (! tag) tag = '*';
39         var ret = new Array();
40         var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)");
41         var els = node.getElementsByTagName(tag);
42         for (i = 0; i < els.length; i++) {
43                 if ( pattern.test(els[i].className) ) {
44                         ret.push(els[i]);
45                 }
46         }
47         return ret;
48     }
49
50 >> Most of the changes are minor, except that this one will use the
51 >> built in function if it is available.  That is likely to be significantly
52 >> faster.  Adding the extra parameters doesn't cause a problem --
53 >> they're filled in with useful defaults.
54
55 >> I don't know if it is worth making this change, but it is there if you want it.
56
57 >>> Well, it seems to work. Although god only knows about IE. Suppose I
58 >>> might as well.. --[[Joey]]