Annotation of 2002/css-validator/scripts/w3c-validator.js, revision 1.7

1.1       ot          1: var W3C = {
1.5       tgambet     2:        
1.1       ot          3:        start: function(){
1.5       tgambet     4:                
1.1       ot          5:                //select elements
1.5       tgambet     6:                
1.1       ot          7:                W3C.Legends = $$('legend.toggletext');
                      8:                W3C.Options = $$('div.options');
1.5       tgambet     9:                
1.1       ot         10:                W3C.TabSet = $('tabset_tabs');
1.5       tgambet    11:                
1.1       ot         12:                W3C.Tabs = W3C.TabSet.getElements('li');
                     13:                W3C.TabLinks = W3C.TabSet.getElements('a');
1.5       tgambet    14:                
1.1       ot         15:                W3C.Sections = $$('fieldset.tabset_content');
                     16:                W3C.Submits = $$('input[type=submit]');
                     17:                W3C.Forms = $$('form');
1.5       tgambet    18:                
1.1       ot         19:                W3C.Submits.each(function(submit, i){
                     20:                        var value = submit.value;
                     21:                        submit.setStyle('display', 'none');
                     22:                        var link = new Element('a', {'class': 'submit', 'href': '#'});
1.6       tgambet    23:                        var span = new Element('span').set('text', value).inject(link);
1.1       ot         24:                        link.injectAfter(submit).addEvent('click', function(event){
                     25:                                new Event(event).stop();
                     26:                                W3C.Forms[i].submit();
                     27:                        });
                     28:                });
1.5       tgambet    29:                
                     30:                
1.1       ot         31:                //initialize effects arrays
1.5       tgambet    32:                
1.1       ot         33:                W3C.SectionFx = [];
                     34:                W3C.OptionsFx = [];
1.5       tgambet    35:                
1.1       ot         36:                //creating the Effects for the Options
1.5       tgambet    37:                
1.1       ot         38:                W3C.Options.each(function(option, i){
                     39:                        W3C.OptionsFx[i] = new Fx.Slide(option, {'wait': false, 'duration': 180});
                     40:                        W3C.OptionsFx[i].addEvent('onComplete', function(){
                     41:                                if (this.element.getStyle('margin-top').toInt() == 0){
                     42:                                        this.wrapper.setStyle('height', 'auto');
                     43:                                }
                     44:                                else {
                     45:                                  this.element.setStyle('display','none');  // if a slideOut completed, set display:none
                     46:                                }
                     47:                        });
                     48:                });
1.5       tgambet    49:                
1.1       ot         50:                //creating links on legends, with event listeners
1.5       tgambet    51:                
1.1       ot         52:                W3C.Legends.each(function(legend, i){
1.5       tgambet    53:                        var html = legend.innerHTML;
1.1       ot         54:                        var pid = W3C.Sections[i].id.replace(/-/g, '_');
                     55:                        var opt = '+with_options';
1.7     ! tgambet    56:                        legend.set('html', '<a href="#'+ pid + opt + '">' + html + '</a>');
1.1       ot         57:                        var option = W3C.Options[i];
1.4       tgambet    58:                        var link = legend.getFirst();
1.1       ot         59:                        link.addEvent('click', function(event){
                     60:                          option.setStyle('display', 'block'); // before any slide effect, set display:block
                     61:                                var block = (option.getStyle('margin-top').toInt() == 0);
                     62:                                W3C.setHash((block) ? pid : pid + opt);
                     63:                                new Event(event).stop();
                     64:                                W3C.refreshOptionLinks(!block, i);
                     65:                        });
                     66:                });
1.5       tgambet    67:                
1.1       ot         68:                //creating event listeners on tabs
1.5       tgambet    69:                
1.1       ot         70:                W3C.Tabs.each(function(li, i){
                     71:                        var link = li.getFirst();
                     72:                        link.href = link.original = '#' + link.href.split('#')[1].replace(/-/g, '_');
                     73:                        li.addEvent('click', function(){
                     74:                                W3C.updateLocation();
                     75:                                W3C.displaySection(i);
                     76:                        });
                     77:                });
1.5       tgambet    78:                
1.1       ot         79:                //updating the location
1.5       tgambet    80:                
1.1       ot         81:                W3C.updateLocation();
1.5       tgambet    82:                
1.1       ot         83:                //setting the initial display of the options, based on the location
1.5       tgambet    84:                
1.1       ot         85:                W3C.refreshOptionLinks(W3C.WithOptions);
1.5       tgambet    86:                
1.1       ot         87:                //attaching the Sections effects, and display section based on the uri
1.5       tgambet    88:                
1.1       ot         89:                W3C.Sections.each(function(section, i){
                     90:                        var fakeId = section.id.replace(/-/g, '_');
1.6       tgambet    91:                        W3C.SectionFx[i] = new Fx.Tween(section, {property:'opacity', link: 'cancel', duration: 220});
1.1       ot         92:                        section.setStyle('display', 'none');
                     93:                        if (W3C.Location[0] && fakeId.contains(W3C.Location[0].replace(/-/g, '_'))){
                     94:                                W3C.displaySection(i, true);
                     95:                                W3C.Located = true;
                     96:                        }
                     97:                });
1.5       tgambet    98:                
1.1       ot         99:                //displaying the first section if no one is located
1.5       tgambet   100:                
1.1       ot        101:                if (!W3C.Located) W3C.displaySection(0, true);
1.5       tgambet   102:                
1.1       ot        103:                if (window.ie) $$('legend').setStyle('margin-left', '-0.4em');
                    104:        },
1.5       tgambet   105:        
1.1       ot        106:        updateLocation: function(){
                    107:                W3C.Location = window.location.hash.replace('#', '').split('+');
                    108:                W3C.WithOptions = (W3C.Location[1] && W3C.Location[1].contains('with_options'));
                    109:        },
1.5       tgambet   110:        
1.1       ot        111:        refreshOptionLinks: function(options, idx){
1.5       tgambet   112:                
1.1       ot        113:                if (!options){
                    114:                        if ($chk(idx)) W3C.OptionsFx[idx].slideOut();
                    115:                        W3C.Legends.removeClass('toggled');
                    116:                } else {
1.5       tgambet   117:                        if ($chk(idx)) W3C.OptionsFx[idx].slideIn();
                    118:                        W3C.Legends.addClass('toggled');
1.1       ot        119:                }
1.5       tgambet   120:                
1.1       ot        121:                W3C.TabLinks.each(function(link){
                    122:                        link.href = (options) ? link.original + '+with_options' : link.original;
                    123:                });
                    124:        },
1.5       tgambet   125:        
1.1       ot        126:        displaySection: function(i, sudden){
                    127:                W3C.Sections.each(function(section, j){
                    128:                        var block = section.getStyle('display') == 'block';
                    129:                        if (j == i){
                    130:                                if (block) return;
                    131:                                W3C.Sections[j].setStyles({'opacity': sudden ? 1 : 0, 'display': 'block'});
                    132:                                if (!sudden) W3C.SectionFx[j].start(1);
                    133:                                if (W3C.WithOptions) W3C.OptionsFx[j].show().fireEvent('onComplete');
                    134:                                else W3C.OptionsFx[j].hide();
                    135:                        } else {
                    136:                                if (!block) return;
                    137:                                W3C.Sections[j].setStyles({'display': 'none', 'opacity': 0});
                    138:                        }
                    139:                });
1.5       tgambet   140:                
1.1       ot        141:                W3C.Tabs.each(function(link, j){
                    142:                        if (j == i) link.addClass('selected');
                    143:                        else link.removeClass('selected');
                    144:                });
                    145:        },
1.5       tgambet   146:        
1.1       ot        147:        setHash: function(hash){
                    148:                if (window.webkit419){
                    149:                        W3C.FakeForm = W3C.FakeForm || new Element('form', {'method': 'get'}).injectInside(document.body);
                    150:                        W3C.FakeForm.setProperty('action', '#' + hash).submit();
                    151:                } else {
                    152:                        window.location.hash = hash;
                    153:                }
                    154:        }
1.5       tgambet   155:        
1.1       ot        156: };
                    157: 
1.6       tgambet   158: window.addEvent('domready', W3C.start);

Webmaster