Difference between revisions of "MediaWiki:Common.js"

From MakeICT Wiki
Jump to navigationJump to search
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
  
 +
 +
/**
 +
* Copy @todos and @decisions into summaries at the bottom of meeting minutes
 +
**/
 
(function () {
 
(function () {
 
   var cloneNodesToList = function(list, nodes) {
 
   var cloneNodesToList = function(list, nodes) {
Line 31: Line 35:
 
   };
 
   };
  
  try{
+
var list = $("#makeict-decision-summary")[0];
    cloneNodesToList($("#makeict-decision-summary")[0], $(".makeict-decision"));
+
if(list){
  }catch(exc){
+
      cloneNodesToList(list, $(".makeict-decision"));
    console.log(exc);
+
}
  }
 
  
  var tasks = $(".makeict-todo");
+
list = $("#makeict-todo-summary")[0];
  try{
+
if(list){
    tasks.sort(taskCompare);
+
      var tasks = $(".makeict-todo");
  }catch(exc){}
+
      try{
 
+
        tasks.sort(taskCompare);
  try{
+
      }catch(exc){}
    cloneNodesToList($("#makeict-todo-summary")[0], tasks);
+
     
  }catch(exc){
+
      cloneNodesToList(list, tasks);
    console.log(exc);
+
}
  }
 
 
}());
 
}());
  
  
  
 +
/**
 +
* Pull @todos and @decisions from all the meeting minutes into aggregate summaries
 +
**/
 
(function () {
 
(function () {
   var outputNode = document.getElementById("makeict-all-todos");
+
   var summaries = {
   if(outputNode){
+
  'todos': {
    var bullets = document.getElementById("meeting-list").getElementsByTagName("li");
+
        'outputNode': document.getElementById('makeict-all-todos'),
 +
        'inputNode': 'makeict-todo-summary',
 +
  },
 +
  'decisions': {
 +
        'outputNode': document.getElementById('makeict-all-decisions'),
 +
'inputNode': 'makeict-decision-summary',
 +
  },
 +
  };
 +
    
 +
  var meetingList = document.getElementById("meeting-list");
 +
  if(!meetingList) return;
 +
 
 +
  var meetingListBullets = meetingList.getElementsByTagName("li");
 
      
 
      
    var processList = function(listIndex){
+
  var processList = function(listIndex){
      if(listIndex >= bullets.length) return;
+
    if(listIndex >= meetingListBullets.length) return;
 
+
       var tmpFrame = document.createElement("iframe");
      processList(listIndex+1);
+
      tmpFrame.onload = function(){
        
+
        processList(listIndex+1); // start processing next one
      try{
+
       
        var tmpFrame = document.createElement("iframe");
+
        // wait for JS on sub pages to run
        tmpFrame.onload = function(){
+
        var processSummaries = function(){
           var summaryNode = this.contentDocument.getElementById("makeict-todo-summary");
+
           for(var key in summaries){
          var heading = document.createElement("h2");
+
            var outputNode = summaries[key].outputNode;
          var link = document.createElement("a");
+
            if(!outputNode) continue;
          link.href = this.src;
+
           
          link.innerHTML = this.contentDocument.getElementsByTagName("h1")[0].innerHTML;
+
      var summaryNode = this.contentDocument.getElementById(summaries[key].inputNode);
          heading.appendChild(link);
+
            var heading = document.createElement("h2");
          outputNode.appendChild(heading);
+
            var link = document.createElement("a");
          if(summaryNode){
+
            link.href = this.src;
            outputNode.appendChild(summaryNode.cloneNode(true));
+
link.innerHTML = this.contentDocument.getElementsByTagName("h1")[0].innerHTML;
          }else{
+
            heading.appendChild(link);
            outputNode.appendChild(document.createTextElement("Could not find @todo summary"));
+
            outputNode.appendChild(heading);
          }
+
            if(summaryNode){
 +
              outputNode.appendChild(summaryNode.cloneNode(true));
 +
            }else{
 +
              outputNode.innerHTML += "<div>Could not find " + key + " summary :(</div>";
 +
            }
 
            
 
            
          document.body.removeChild(this);
+
            document.body.removeChild(this);
         };
+
        }
        tmpFrame.style.display = "none";
+
};
        tmpFrame.src = bullets[listIndex].getElementsByTagName("a")[0].href;
+
         setTimeout(processSummaries.bind(this), 5000);
        document.body.appendChild(tmpFrame);
+
      };
       }catch(exc){
+
      tmpFrame.style.display = "none";
        console.log(exc);
+
      tmpFrame.src = meetingListBullets[listIndex].getElementsByTagName("a")[0].href;
      }
+
      console.log('Processing ' + tmpFrame.src);
    };
+
       document.body.appendChild(tmpFrame);
 
+
  };
    processList(0);
+
 
  }
+
  processList(0);
 
}());
 
}());

Latest revision as of 01:54, 21 November 2016

/* Any JavaScript here will be loaded for all users on every page load. */


/**
 * Copy @todos and @decisions into summaries at the bottom of meeting minutes
 **/
(function () {
  var cloneNodesToList = function(list, nodes) {
    if(nodes.length == 0){
      var listItem = document.createElement("li");
      listItem.innerHTML = "None";
      list.appendChild(listItem);
    }else{
      for(var i=0; i<nodes.length; i++){
        var listItem = document.createElement("li");
        listItem.appendChild(nodes[i].cloneNode(true));
        list.appendChild(listItem);
      }
    }
  };

  var getTaskProperty = function(task, property){
    return $(task).find(".makeict-todo-" + property)[0].innerText.toLowerCase();
  }

  var taskCompare = function(taskA, taskB){
    var props = ["who", "when"];
    for(i in props){
      var a = getTaskProperty(taskA, props[i]);
      var b = getTaskProperty(taskB, props[i]);
      if(a > b) return 1;
      if(b > a) return -1;
    }
    return 0;
  };

	var list = $("#makeict-decision-summary")[0];
	if(list){
      cloneNodesToList(list, $(".makeict-decision"));
	}

	list = $("#makeict-todo-summary")[0];
	if(list){
      var tasks = $(".makeict-todo");
      try{
        tasks.sort(taskCompare);
      }catch(exc){}
      
      cloneNodesToList(list, tasks);
	}
}());



/**
 * Pull @todos and @decisions from all the meeting minutes into aggregate summaries
 **/
(function () {
  var summaries = {
	  'todos': {
        'outputNode': document.getElementById('makeict-all-todos'),
        'inputNode': 'makeict-todo-summary',
	  },
	  'decisions': {
        'outputNode': document.getElementById('makeict-all-decisions'),
		'inputNode': 'makeict-decision-summary',
	  },
  };
  
  var meetingList = document.getElementById("meeting-list");
  if(!meetingList) return;
  
  var meetingListBullets = meetingList.getElementsByTagName("li");
    
  var processList = function(listIndex){
    if(listIndex >= meetingListBullets.length) return;
      var tmpFrame = document.createElement("iframe");
      tmpFrame.onload = function(){
        processList(listIndex+1);	// start processing next one
        
        // wait for JS on sub pages to run
        var processSummaries = function(){
          for(var key in summaries){
            var outputNode = summaries[key].outputNode;
            if(!outputNode) continue;
            
  		    var summaryNode = this.contentDocument.getElementById(summaries[key].inputNode);
            var heading = document.createElement("h2");
            var link = document.createElement("a");
            link.href = this.src;
			link.innerHTML = this.contentDocument.getElementsByTagName("h1")[0].innerHTML;
            heading.appendChild(link);
            outputNode.appendChild(heading);
            if(summaryNode){
              outputNode.appendChild(summaryNode.cloneNode(true));
            }else{
              outputNode.innerHTML += "<div>Could not find " + key + " summary :(</div>";
            }
          
            document.body.removeChild(this);
  	      }
		};
        setTimeout(processSummaries.bind(this), 5000);
      };
      tmpFrame.style.display = "none";
      tmpFrame.src = meetingListBullets[listIndex].getElementsByTagName("a")[0].href;
      console.log('Processing ' + tmpFrame.src);
      document.body.appendChild(tmpFrame);
  };
  
  processList(0);
}());