Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function initialise() {
  2.     navMenu(); // Everything related to the navigation menu - navmenu functionallity
  3.    
  4.     window.setInterval(function(){
  5.         breakingNews() //Everything related to the title changing - ticket functionallity
  6.     },3000);
  7.    
  8.     stories(); //Implementation of the "stories" functionallity
  9.     story_lists();
  10. };
  11.  
  12.  
  13. function navMenu() {
  14.    
  15.     /*Hide all the list items because they are initially shown*/
  16.     var navigate = document.getElementsByClassName("menuitemsholder");
  17.     for (var i = 0 ; i < navigate.length; i++){
  18.         navigate[i].style.display = "none" ;
  19.     }
  20.    
  21.     /* Change the mouse into a cursor and display the list items when mouseovered*/
  22.     var navigateTitles = document.getElementsByClassName("menutitle");
  23.     for(var i = 0; i < navigateTitles.length; i++){
  24.        
  25.      
  26.         /*Add the mouseover event*/
  27.         navigateTitles[i].onmouseover = function(){
  28.            
  29.             /*Some styling for the cursor : */
  30.             this.style.cursor="pointer";
  31.             /*Set the list's visivility to block*/
  32.             this.parentNode.childNodes[3].style.display = "block";
  33.         };
  34.        
  35.         /*Add the mouseleave event */
  36.         navigateTitles[i].parentNode.onmouseleave = function(){
  37.             /*Hide the list after the cursor is moved outside the title or the list elements*/
  38.             this.childNodes[3].style.display="none";
  39.         }
  40.        
  41.        
  42.        
  43.     }
  44.    
  45. }; /*end nav menu*/
  46.  
  47.  
  48.  
  49. var i = 1; //My loop helper function
  50.  
  51. function breakingNews(){
  52.    
  53.     //The list of stories that we have to get display in breaking news :
  54.     var contents = document.getElementById("newstories-list");
  55.     //The ul list that in inside the div that we called contentns :
  56.     var list = contents.childNodes[1];
  57.     //The div that contains the breaking new that appears at the moment:
  58.     var toChange = document.getElementById("breaking");
  59.    
  60.     // Prevent i having undesirable values
  61.     if (i%11===0) {
  62.         i++;
  63.         toChange.innerHTML = "<b>Breaking news:</b> " + list.childNodes[i%11].innerHTML; //change the title  
  64.     }
  65.     else{
  66.         toChange.innerHTML = "<b>Breaking news:</b> " + list.childNodes[i%11].innerHTML; //change the title    
  67.     }
  68.     i+=2;
  69.  
  70. }/* end breaking news ticker */
  71.  
  72.  
  73.  
  74.  
  75. function stories(){
  76.    
  77.     /*VARIABLE DECLARATION*/
  78.         /*EVERYTHING RELATED TO THE LIST AT THE LEFT*/
  79.             var storylists = document.getElementById("storylists"); //The entire div that contains topstories , mostread and newstories.
  80.             var topstories = storylists.childNodes[3]; //The div as one object
  81.             var topstoriesList = topstories.childNodes[1]; //The list as one object
  82.             var topstoriesListElements = topstoriesList.getElementsByClassName("fakelink"); //The list that contains the story elements
  83.         /*EVERYTHING RELATED TO THE CENTRE OF THE PAGE*/    
  84.             var header = document.getElementsByClassName("header")[0]; //the header that should change according to the story that we clicked on
  85.             var storypanel = document.getElementById("storypanel"); //The entire storypanel that contains everything at the centre        
  86.             var startingStory = storypanel.childNodes[3];
  87.         /*EVERYTHING RELATED ON GIVING THE CENTRE THE INITIAL LOOK THAT IS DESIRED*/
  88.             var notstartingstories = storypanel.getElementsByClassName("story");
  89.     /*END VARIABLE DECLARATION */
  90.     //alert(storypanel.childNodes[5].innerHTML);
  91.    
  92.     /***************************SET ONLY ONE STORY TO APPEAR ON THE CENTER OF THE WEBPAGE INITIALLY ***************************************/
  93.         header.innerHTML = startingStory.childNodes[1].innerHTML;
  94.         startingStory.childNodes[1].innerHTML = "";
  95.         for(var i = 1 ; i < notstartingstories.length; i++){
  96.             notstartingstories[i].childNodes[1].innerHTML=""; //also delete all the titles from within the stories.
  97.             notstartingstories[i].style.display = "none";
  98.         }
  99.     /************************************************************END************************************************************************/
  100.    
  101.    
  102.     /*All the functionallity below*/
  103.     for (var i=0; i < topstoriesListElements.length; i++) {
  104.        
  105.         topstoriesListElements[i].onclick = function(){
  106.             header.innerHTML = this.innerHTML;
  107.            
  108.             for(var j = 0; i < notstartingstories.length; j++){
  109.                 if (this.id.indexOf(notstartingstories[j].id) > -1) { //Check if the id of the story matches the id that the title has.
  110.                     startingStory.style.display="none";
  111.                     notstartingstories[j].style.display="block";
  112.                 }
  113.                 else{
  114.                     notstartingstories[j].style.display="none";
  115.                
  116.                 }
  117.             }
  118.         };
  119.     }
  120. }
  121.  
  122. function story_lists() {
  123.     /*******************************VARIABLE DECLARATION*********************************/
  124.     var listheaders = document.getElementById("listheaders");
  125.     var listHeadersEventListeners = listheaders.getElementsByTagName("div");
  126.     var storylists = document.getElementsByClassName("storylist");    
  127.    
  128.  
  129.     //alert(storylists[0].id);
  130.     for(var i = 0; i < listHeadersEventListeners.length; i++){
  131.          
  132.         listHeadersEventListeners[i].onclick = function(){
  133.           //alert(this.id);        
  134.             for(var j = 0; j < listHeadersEventListeners.length; j++){
  135.                 listHeadersEventListeners[j].className ="listheader-hidden";
  136.                     if(storylists[j].id.indexOf(this.id) > - 1){
  137.                         storylists[j].style.display = "block";
  138.                     }
  139.                     else{
  140.                         storylists[j].style.display = "none";
  141.                     }
  142.             }
  143.             this.className = "listheader";
  144.            
  145.         };
  146.     }
  147.    
  148.  
  149.    
  150.    
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement