Advertisement
Guest User

Untitled

a guest
Jan 26th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. var pagedir='pages/',
  3.     pages=[<?php
  4. function scd($dir){
  5. ///$files=scandir($dir); USE IF DYNAMICLY CREATED PAGE LISTS OR IF YOU HAVE MANY PAGES
  6. $files = array('forside.php', 'menukort.php', 'catering.php', 'hvem_er_vi.php', 'Kontakt.php');  //USE IF PRE-DEFINED NUMBER OF PAGES
  7. foreach($files as $key => $val){
  8. if($val[$key]==='.'||$val[$key]==='..'){unset($files[$key]);}
  9. }
  10. ///sort($files); USE WITH THE DYNAMICALLY INCLUDED PAGES
  11. reset($files);
  12. return $files;
  13. }
  14.  
  15. $pagedir='pages';
  16. $str='';
  17. $arr=scd($pagedir);
  18. foreach($arr as $val){
  19. $str.="'".$val."',";
  20. }
  21. echo substr($str,0,-1);
  22. ?>];
  23.  
  24. function buildMenu(targetID,arr,contentID){
  25. /* 'hvem_er_vi' will be replaced with 'hvem er vi'*/
  26. var str='';
  27. for(var i=0; i<pages.length;i++){
  28. str+='<li><a href="'+pages[i]+'">'+(pages[i].substring(0,1).toUpperCase()+pages[i].substring(1,pages[i].length-4)).replace(/_/g,' ')+'</a></li>';
  29. }
  30. $('#'+targetID).html('<ul>'+str+'</ul>');
  31. $('#'+targetID+' a').click(function(e) {
  32. e.preventDefault();
  33. $.get(pagedir+$(this).attr('href'),function(data){
  34. $('#'+contentID).fadeOut('slow',function(){
  35. $(this).html(data).fadeIn('slow');
  36. });
  37. })
  38. });
  39. }
  40.  
  41.  
  42.  
  43. $(document).ready(function(){
  44. buildMenu('menu',pages,'content');
  45. });
  46.  
  47. document.getElementById("#menu a").className += " active";
  48. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement