Difference between revisions of "MediaWiki:Common.js"

From MakeICT Wiki
Jump to navigationJump to search
Line 60: Line 60:
  
 
        
 
        
      try{
+
//      try{
 
         var tmpFrame = document.createElement("iframe");
 
         var tmpFrame = document.createElement("iframe");
 
         tmpFrame.onload = function(){
 
         tmpFrame.onload = function(){
Line 83: Line 83:
 
         tmpFrame.src = bullets[listIndex].getElementsByTagName("a")[0].href;
 
         tmpFrame.src = bullets[listIndex].getElementsByTagName("a")[0].href;
 
         document.body.appendChild(tmpFrame);
 
         document.body.appendChild(tmpFrame);
      }catch(exc){
+
//      }catch(exc){
        console.log(exc);
+
//        console.log(exc);
      }
+
//      }
 
     };
 
     };
  
Line 91: Line 91:
 
   }
 
   }
 
}());
 
}());
 
+
/*
  
 
(function () {
 
(function () {
Line 133: Line 133:
 
   }
 
   }
 
}());
 
}());
 +
*/

Revision as of 00:18, 21 November 2016

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

(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;
  };

  try{
    cloneNodesToList($("#makeict-decision-summary")[0], $(".makeict-decision"));
  }catch(exc){
    console.log(exc);
  }

  var tasks = $(".makeict-todo");
  try{
    tasks.sort(taskCompare);
  }catch(exc){}

  try{
    cloneNodesToList($("#makeict-todo-summary")[0], tasks);
  }catch(exc){
    console.log(exc);
  }
}());



(function () {
  var outputNode = document.getElementById("makeict-all-todos");
  if(outputNode){
    var bullets = document.getElementById("meeting-list").getElementsByTagName("li");
    
    var processList = function(listIndex){
      if(listIndex >= bullets.length) return;

      
//      try{
        var tmpFrame = document.createElement("iframe");
        tmpFrame.onload = function(){
          processList(listIndex+1);

          var summaryNode = this.contentDocument.getElementById("makeict-todo-summary");
          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 = bullets[listIndex].getElementsByTagName("a")[0].href;
        document.body.appendChild(tmpFrame);
//      }catch(exc){
//        console.log(exc);
//      }
    };

    processList(0);
  }
}());
/*

(function () {
  var outputNode = document.getElementById("makeict-all-decisions");
  if(outputNode){
    var bullets = document.getElementById("meeting-list").getElementsByTagName("li");
    
    var processList = function(listIndex){
      if(listIndex >= bullets.length) return;

      
      try{
        var tmpFrame = document.createElement("iframe");
        tmpFrame.onload = function(){
          processList(listIndex+1);

          var summaryNode = this.contentDocument.getElementById("makeict-decision-summary");
          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 @DECISION summary :(</div>";
          }
          
          document.body.removeChild(this);
        };
        tmpFrame.style.display = "none";
        tmpFrame.src = bullets[listIndex].getElementsByTagName("a")[0].href;
        document.body.appendChild(tmpFrame);
      }catch(exc){
        console.log(exc);
      }
    };

    processList(0);
  }
}());
*/