ff-streaming-platform

git clone git://archive.git.mtrnord.blog/MTRNord/ff-streaming-platform.git
Log | Files | Refs | README | LICENSE

script.js (3845B)


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