Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / ams / doc / js / script.js
blob1be3342485793a761932bb0772b6bb8b48e4f9e5
1 /*!
2  * Documenter 1.6
3  * http://rxa.li/documenter
4  *
5  * Copyright 2011, Xaver Birsak
6  * http://revaxarts.com
7  *
8  */
9 //if Cufon replace headings
10 if(typeof Cufon == 'function') Cufon.replace('h1, h2, h3, h4, h5, h6');
12 $(document).ready(function() {
13         var timeout,
14                 sections = new Array(),
15                 sectionscount = 0,
16                 win = $(window),
17                 sidebar = $('#documenter_sidebar'),
18                 nav = $('#documenter_nav'),
19                 logo = $('#documenter_logo'),
20                 navanchors = nav.find('a'),
21                 timeoffset = 50,
22                 hash = location.hash || null;
23                 iDeviceNotOS4 = (navigator.userAgent.match(/iphone|ipod|ipad/i) && !navigator.userAgent.match(/OS 5/i)) || false,
24                 badIE = $('html').prop('class').match(/ie(6|7|8)/)|| false;
25                 
26         //handle external links (new window)
27         $('a[href^=http]').bind('click',function(){
28                 window.open($(this).attr('href'));
29                 return false;
30         });
31         
32         //IE 8 and lower doesn't like the smooth pagescroll
33         if(!badIE){
34                 window.scroll(0,0);
35                 
36                 $('a[href^=#]').bind('click touchstart',function(){
37                         hash = $(this).attr('href');
38                         $.scrollTo.window().queue([]).stop();
39                         goTo(hash);
40                         return false;
41                 });
42                 
43                 //if a hash is set => go to it
44                 if(hash){
45                         setTimeout(function(){
46                                 goTo(hash);
47                         },500);
48                 }
49         }
50         
51         
52         //We need the position of each section until the full page with all images is loaded
53         win.bind('load',function(){
54                 
55                 var sectionselector = 'section';
56                 
57                 //Documentation has subcategories               
58                 if(nav.find('ol').length){
59                         sectionselector = 'section, h4';
60                 }
61                 //saving some information
62                 $(sectionselector).each(function(i,e){
63                         var _this = $(this);
64                         var p = {
65                                 id: this.id,
66                                 pos: _this.offset().top
67                         };
68                         sections.push(p);
69                 });
70                 
71                 
72                 //iPhone, iPod and iPad don't trigger the scroll event
73                 if(iDeviceNotOS4){
74                         nav.find('a').bind('click',function(){
75                                 setTimeout(function(){
76                                         win.trigger('scroll');                          
77                                 },duration);
78                                 
79                         });
80                         //scroll to top
81                         window.scroll(0,0);
82                 }
84                 //how many sections
85                 sectionscount = sections.length;
86                 
87                 //bind the handler to the scroll event
88                 win.bind('scroll',function(event){
89                         clearInterval(timeout);
90                         //should occur with a delay
91                         timeout = setTimeout(function(){
92                                 //get the position from the very top in all browsers
93                                 pos = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
94                                 
95                                 //iDeviceNotOS4s don't know the fixed property so we fake it
96                                 if(iDeviceNotOS4){
97                                         sidebar.css({height:document.height});
98                                         logo.css({'margin-top':pos});
99                                 }
100                                 //activate Nav element at the current position
101                                 activateNav(pos);
102                         },timeoffset);
103                 }).trigger('scroll');
105         });
106         
107         //the function is called when the hash changes
108         function hashchange(){
109                 goTo(location.hash, false);
110         }
111         
112         //scroll to a section and set the hash
113         function goTo(hash,changehash){
114                 win.unbind('hashchange', hashchange);
115                 hash = hash.replace(/!\//,'');
116                 win.stop().scrollTo(hash,duration,{
117                         easing:easing,
118                         axis:'y'                        
119                 });
120                 if(changehash !== false){
121                         var l = location;
122                         location.href = (l.protocol+'//'+l.host+l.pathname+'#!/'+hash.substr(1));
123                 }
124                 win.bind('hashchange', hashchange);
125         }
126         
127         
128         //activate current nav element
129         function activateNav(pos){
130                 var offset = 100,
131                 current, next, parent, isSub, hasSub;
132                 win.unbind('hashchange', hashchange);
133                 for(var i=sectionscount;i>0;i--){
134                         if(sections[i-1].pos <= pos+offset){
135                                 navanchors.removeClass('current');
136                                 current = navanchors.eq(i-1);
137                                 current.addClass('current');
138                                 
139                                 parent = current.parent().parent();
140                                 next = current.next();
141                                 
142                                 hasSub = next.is('ol');
143                                 isSub = !parent.is('#documenter_nav');
144                                 
145                                 nav.find('ol:visible').not(parent).slideUp('fast');
146                                 if(isSub){
147                                         parent.prev().addClass('current');
148                                         parent.stop().slideDown('fast');
149                                 }else if(hasSub){
150                                         next.stop().slideDown('fast');
151                                 }
152                                 win.bind('hashchange', hashchange);
153                                 break;
154                         };
155                 }       
156         }
157         
158