Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var pagedir='pages/',
- pages=[<?php
- function scd($dir){
- ///$files=scandir($dir); USE IF DYNAMICLY CREATED PAGE LISTS OR IF YOU HAVE MANY PAGES
- $files = array('forside.php', 'menukort.php', 'catering.php', 'hvem_er_vi.php', 'Kontakt.php'); //USE IF PRE-DEFINED NUMBER OF PAGES
- foreach($files as $key => $val){
- if($val[$key]==='.'||$val[$key]==='..'){unset($files[$key]);}
- }
- ///sort($files); USE WITH THE DYNAMICALLY INCLUDED PAGES
- reset($files);
- return $files;
- }
- $pagedir='pages';
- $str='';
- $arr=scd($pagedir);
- foreach($arr as $val){
- $str.="'".$val."',";
- }
- echo substr($str,0,-1);
- ?>];
- function buildMenu(targetID,arr,contentID){
- /* 'hvem_er_vi' will be replaced with 'hvem er vi'*/
- var str='';
- for(var i=0; i<pages.length;i++){
- str+='<li><a href="'+pages[i]+'">'+(pages[i].substring(0,1).toUpperCase()+pages[i].substring(1,pages[i].length-4)).replace(/_/g,' ')+'</a></li>';
- }
- $('#'+targetID).html('<ul>'+str+'</ul>');
- $('#'+targetID+' a').click(function(e) {
- e.preventDefault();
- $.get(pagedir+$(this).attr('href'),function(data){
- $('#'+contentID).fadeOut('slow',function(){
- $(this).html(data).fadeIn('slow');
- });
- })
- });
- }
- $(document).ready(function(){
- buildMenu('menu',pages,'content');
- });
- document.getElementById("#menu a").className += " active";
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement