Jump to content

User:Year2000Prob/Wijits.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var Wijits = new Object();
Wijits.Manager = new Object();
if (!Wijits.List) Wijits.List = [];

Wijits.Manager._ImageData = { // silk icons, encoded into base64
  cog: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK" // cog.png
   + "/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGSSURBVCj"
   + "PVVFNSwJhEF78Ad79Cf6PvXQRsotUlzKICosuRYmR2RJR0KE6lBFFZVEbpFBSqKu2rum6"
   + "llFS9HHI4iUhT153n6ZtIWMOM+/MM88z7wwH7s9Ub16SJcnbmrNcxVm2q7Z8/QPvEOtnt"
   + "pj92NkCqITLepEpjix7xQtiLOoQ2b6+E7YAN/5nfOEJ2WbKqOIOJ4bYVMEQx4LfBBQDsv"
   + "FMhUcCVU1/CxVXmDBGA5ZETrhDCQVcYAPbyEJBhvrnBVPiSpNr6cYDNCQwo4zzU/ySckk"
   + "gDYuNuVpI42T9k4gLKGMPs/xPzzovQiY2hQYe0jlJfyNNhTqiWDYBq/wBMcSRpnyPzu1o"
   + "S7WtxjVBSthU1vgVksiQ3Dn6Gp5ah2YOKQo5GiuHPA6xT1EKpxQNCNYejgIR457KKio0S"
   + "56YckjSa9jo//3mrj+BV0QQagqGTOo+Y7gZIf1puP3WHoLhEb2PjTlCTCWGXtbp8DCX3h"
   + "ZuOdaIc9A+aQvWk4ihq95p67a7nP+u+Ws+r0dql9z/zv0NCYhdCPKZ7oYAAAAASUVORK5CYII=",
  cross: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK" // cross.png
   + "/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAIhSURBVDj"
   + "LlZPrThNRFIWJicmJz6BWiYbIkYDEG0JbBiitDQgm0PuFXqSAtKXtpE2hNuoPTXwSnwtE"
   + "xd6w0pl2OtPlrphKLSXhx07OZM769qy19wwAGLhM1ddC184+d18QMzoq3lfsD3LZ7Y3Xb"
   + "E5DL6Atzuyilc5Ciyd7IHVfgNcDYTQ2tvDr5crn6uLSvX+Av2Lk36FFpSVENDe3OxDZu8"
   + "apO5rROJDLo30+Nlvj5RnTlVNAKs1aCVFr7b4BPn6Cls21AWgEQlz2+Dl1h7IdA+i97A/"
   + "geP65WhbmrnZZ0GIJpr6OqZqYAd5/gJpKox4Mg7pD2YoC2b0/54rJQuJZdm6Izcgma4TW"
   + "1WZ0h+y8BfbyJMwBmSxkjw+VObNanp5h/adwGhaTXF4NWbLj9gEONyCmUZmd10pGgf1/v"
   + "wcgOT3tUQE0DdicwIod2EmSbwsKE1P8QoDkcHPJ5YESjgBJkYQpIEZ2KEB51Y6y3ojvY+"
   + "P8XEDN7uKS0w0ltA7QGCWHCxSWWpwyaCeLy0BkA7UXyyg8fIzDoWHeBaDN4tQdSvAVdU1"
   + "Aok+nsNTipIEVnkywo/FHatVkBoIhnFisOBoZxcGtQd4B0GYJNZsDSiAEadUBCkstPtN3"
   + "Avs2Msa+Dt9XfxoFSNYF/Bh9gP0bOqHLAm2WUF1YQskwrVFYPWkf3h1iXwbvqGfFPSGW9"
   + "Eah8HSS9fuZDnS32f71m8KFY7xs/QZyu6TH2+2+FAAAAABJRU5ErkJggg=="
};

Wijits.Manager._show = function() {
  if (navigator.appName.indexOf("Netscape") != -1) {
    try {
      jsMsg('<div id="wijits-manager-close" style="float: right;"><img src="' + Wijits.Manager._ImageData.cross + '" onclick="Wijits.Manager._hide()" alt="Close" /></div><div><b>Wijits Manager (Alpha)</b></div><div id="wijits-manager-panel">The following wijits are available:<br></div>');
      var panel = document.getElementById("wijits-manager-panel");
      for (var i=0; i<Wijits.List.length; i++) {
        var wijit = Wijits.List[i];
        var option = document.createElement("input");
        option.type = "checkbox";
        option.id = "wijits-option-"+i;
        option.name = "wijits-option-"+i;
        var label = document.createElement("label");
        label.setAttribute("for", option.name);
        label.appendChild(document.createTextNode(wijit.name));
        option.onclick = function() {
          Wijits.Cookie.set("wijit"+i+"IsEnabled", option.checked);
          Wijits.Update();
        };
        option.checked = Wijits.Update(i);
        if (i != 0) panel.appendChild(document.createElement("br"));
        panel.appendChild(option);
        panel.appendChild(label);
      };
    } catch(e) {
      if (Y2P.Debug.Enabled) {
        Y2P.Debug.Retry("Wijits Manager\nError: " + e, {
          onAccept: Wijits.Manager._show,
          onDecline: Wijits.Manager._hide
        });
      }
    };
  } else if (Y2P.Debug.Enabled) {
    Y2P.Debug.Error("Browser \""+navigator.appName+"\" is not supported.");
  } else {
    alert("Browser \""+navigator.appName+"\" is not supported.");
  }
};

Wijits.Manager._hide = function() {
  if (document.getElementById("mw-js-message"))
    document.getElementById("mw-js-message").parentNode.removeChild(document.getElementById("mw-js-message"));
};

window.addEventListener("load", function() {
  var li = document.createElement("li");
  var img = document.createElement("img");
  img.src = Wijits.Manager._ImageData.cog;
  img.alt = "Wijits Manager";
  img.onclick = Wijits.Manager._show;
  li.appendChild(img);
  document.getElementById("p-personal").getElementsByTagName("ul")[0].appendChild(li);
}, false);

Wijits.Update = function() {
  var isEnabled = Wijits.Cookie.get("wijit"+i+"IsEnabled");
  for (var i=0; i<Wijits.List.length; i++) {
    var wijit = Wijits.List[i];
    if (wijits && isEnabled == "true") {
      if (typeof wijit.onEnabled == "function") {
        wijit.onEnabled();
      } else {
        var script = document.createElement("script");
        script.src = wijit.onEnabled;
        script.id = "wijits-import-"+i;
        document.getElementsByTagName("head")[0].appendChild(script);
      }
    } else if (wijits) {
      if (typeof wijit.onDisabled == "function") {
        wijit.onDisabled();
      } else {
        var scriptId = "wijits-import-"+i;
        if (document.getElementById(scriptId)) document.getElementById(scriptId).parentNode.removeChild(document.getElementById(scriptId));
      }
    } else {
      setTimeout("Wijits.Update()", 50);
    }
  };
  return isEnabled;
};

Wijits.Cookie = {
  noexpire:(function(){
    var d = new Date();
    d.setTime(d.getTime()+(365*24*60*60*1000));
    return d.toGMTString();
  })(),
 
  expire:(function(){
    var d = new Date();
    d.setTime(d.getTime()-1);
    return d.toGMTString();
  })(),
 
  get:function(name) {
    var cl = document.cookie.split(/;\s*/);
    for (var i=0; i<cl.length; i++) {
      var curc = cl[i].split(/\=/);
      if (curc[0] == name) {
        return(curc[1]);
      }
    }
    return null;
  },
 
  set:function(name, value) {
    document.cookie = name + "=" + escape(value) +
        "; expires=" + Wijits.Cookie.noexpire +
        "; path=/";
  },
 
  del:function(name) {
    document.cookie = name+"=; expires="+Wijits.Cookie.expire+"; path=/";
  }
};

Wijits.Update();