MediaWiki:Common.js

From MakeICT Wiki
Revision as of 01:38, 21 November 2016 by Dominic Canare (talk | contribs)
Jump to navigationJump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* 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 meetingListBullets = document.getElementById("meeting-list").getElementsByTagName("li");
    
  var processList = function(listIndex){
    if(listIndex >= meetingListBullets.length) return;
      var tmpFrame = document.createElement("iframe");
      tmpFrame.onload = function(){
        processList(listIndex+1);
  
        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 @todo summary :(</div>";
          }
        
          document.body.removeChild(this);
	    }
      };
      tmpFrame.style.display = "none";
      tmpFrame.src = meetingListBullets[listIndex].getElementsByTagName("a")[0].href;
      document.body.appendChild(tmpFrame);
  };
  
  processList(0);
}());