Changeset 375:4558d9b9b5f5

Show
Ignore:
Timestamp:
09/15/09 11:45:20 (4 years ago)
Author:
tgambet
Branch:
default
convert_revision:
svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@376
Message:

script automatically opens the right section based on hash

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • WebContent/scripts/w3c_unicorn_results.js

    r372 r375  
     1/* $Id: w3c_unicorn_results.js,v 1.7 2009-09-15 11:45:20 tgambet Exp $Id */ 
    12var W3C = { 
    23         
     
    4142                        if (observer.hasClass('valid') && invalidObservers.length > 0)  
    4243                                W3C.close(observer, false); 
     44                        console.log(observer.getElement('a.anchor')); 
    4345                        observer.getElement('a.anchor').addEvent('click', function(event) { 
    44                                 event.preventDefault(); 
     46                                //event.preventDefault(); 
    4547                                W3C.open(observer, true); 
    46                                 scroller.toElement(observer); 
     48                                //scroller.toElement(observer); 
     49                                /*(new Chain()).wait(slideDuration).chain(function() { 
     50                                        W3C.setHash(observer.getProperty('id')); 
     51                                }).callChain();*/ 
    4752                        }); 
    4853                        if (observer.getElement('a.infos')) { 
     
    8085                    wheelStops: true 
    8186                }); 
     87                 
     88                W3C.cleanHash(); 
     89                W3C.parseHash(); 
    8290        }, 
    8391         
     
    139147        }, 
    140148         
     149        parseHash: function(){ 
     150                var hash = window.location.hash; 
     151                if (hash == "") { 
     152                        return; 
     153                } 
     154                var tab = hash.replace('#', '').split('_'); 
     155                var observerId = tab[0]; 
     156                var sectionId = tab[1]; 
     157                var uriId = tab[2]; 
     158                var messageId = tab[3]; 
     159                 
     160                var scroller = new Fx.Scroll(document, {duration: 0}); 
     161                 
     162                var observerIndex = W3C.Observers.getProperty('id').indexOf(observerId); 
     163                if (observerIndex == -1) { 
     164                        W3C.setHash(''); 
     165                        return; 
     166                } 
     167                var observer = W3C.Observers[observerIndex]; 
     168                W3C.closeAllObserversBut(observer, false); 
     169                 
     170                if (!sectionId) { 
     171                        scroller.toElement(observer); 
     172                        return; 
     173                } 
     174                var sectionIndex =  observer.getElements('.section').getProperty('id').indexOf(observerId + '_' + sectionId); 
     175                if (sectionIndex == -1) { 
     176                        W3C.setHash(observerId); 
     177                        return; 
     178                } 
     179                var section = observer.getElements('.section')[sectionIndex]; 
     180                W3C.closeAllSectionsBut(observer, section, false); 
     181                 
     182                 
     183                if (!uriId) { 
     184                        scroller.toElement(observer); 
     185                        return; 
     186                } 
     187                var uriIndex =  section.getElements('td.uri').getProperty('id').indexOf(observerId + '_' + sectionId + '_' + uriId); 
     188                if (uriIndex == -1) { 
     189                        W3C.setHash(observerId + '_' + sectionId); 
     190                        return; 
     191                } 
     192                var uriTd = section.getElements('td.uri')[uriIndex]; 
     193                 
     194                if (!messageId) { 
     195                        scroller.toElement(uriTd); 
     196                        return; 
     197                } 
     198                 
     199                W3C.setHash(hash); 
     200                 
     201        }, 
     202         
     203        updateHash: function(){ 
     204                var tab = W3C.Forms[W3C.SelectedTab].getProperty('id'); 
     205                var task = '+task_' + W3C.TaskOptions[W3C.SelectedTask].getProperty('value'); 
     206                var withOptions = W3C.WithOptions ? '+with_options' : ''; 
     207                                 
     208                W3C.setHash(tab + task + withOptions); 
     209        }, 
     210         
     211        cleanHash: function(){ 
     212                var hash = window.location.hash; 
     213                if (hash.match('^#validate-by')) 
     214                        W3C.setHash(''); 
     215        }, 
     216         
    141217        setHash: function(hash){ 
    142218                if (window.webkit419){