MediaWiki:Result Code Details.js

From Melissa Data Wiki
Revision as of 21:45, 21 January 2015 by Admin (talk | contribs)
Jump to navigation Jump to search

Note: After publishing, 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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
//Changes the Header to act like a button
$(".TileLayoutHead p").css({"cursor":"pointer"});//Cursor change
$(".TileLayoutHead p").hover(function(){$(this).parent().css({"background-color":"#ffffff"});},function(){$(this).parent().css({"background-color":"#f6f6f6"})});//Hover change
//Fixes Result Code Header padding
$(".ResultTileLayoutHead h3").css({"padding-left":"30px"});

//Slide-out Effect
$(".TileLayoutHead p").click(function(){
  $(this).siblings(".TileLayoutBody").toggle(500, tileResetCheck($(this)));//Category Rollout
  $(this).parent().siblings(".TileLayoutHead").toggle(500);//Other Category Hide
  $(".ResultTileLayoutHead").slideUp(500);//Ensures the Result Code table holder is hidden.
  setTimeout(function(){
    $(".ResultTileLayoutHead").css({"background-color":"#f6f6f6"});//Resets Result Head back color.
    //$(".ResultTileLayoutHeat").children("p").first().text("Result Codes");//Resets Result Head text to default.
    $(".ResultTileLayoutHeat p").first().text("Result Codes");//Resets Result Head text to default.
  }, 500);
  //$(".ResultTileLayoutHead").animate().css({"display":"none","background-color":"#f6f6f6"});//Ensures the Result Code table holder is hidden.
  //$(this).siblings(".TileLayoutBody").children().css({"display":"inline-block"});//Ensure Tiles are reset.
 // tileResetCheck();
});

//Ensure Tiles Are Reset
function tileResetCheck(that){
  if (that.siblings().css("display") === "block"){//Checks state of Category Rollout.
    setTimeout(function(){//Ensures tiles don't appear till after the cateogry hide rollout is done.
      that.siblings(".TileLayoutBody").children().css({"display":"inline-block"});
    }, 500);
  };
}

//Click handler on tiles.
$(".TileLayoutBody a").click(function (){
//Matches the hash with a class to know what to hide. Class is set by the TileLayoutTile template.
  var hashTarget = $(this).attr("href");
  var trimmedHashTarget = hashTarget.slice(hashTarget.indexOf("#") + 1,(hashTarget.length));
  cleanedHashTarget = trimmedHashTarget.replace(/[_:]|\.2B|\.2A/g, ""); //Removes spaces, colons, pluses, and asterisks.
  spacedHashTarget = trimmedHashTarget.replace(/_/g, " ");//Readies the hash to be a header with spaces.
  spacedHashTarget = spacedHashTarget.replace(/.2A/g, "*");//Readies the hash to be a header with asterisks.
  spacedHashTarget = spacedHashTarget.replace(/.2B/g, "+");//Readies the hash to be a header with pluses.
  $(".TLT_" + cleanedHashTarget).siblings().toggle(250);//Hides the other tiles.
  $(".ResultTileLayoutHead").toggle(500);//Shows the Result Code table holder.
  var resultBackColor;
//Sets the color variable for the Result Head according to the product selected.
  switch ($(this).closest(".TileLayoutHead").children("p").first().text()){
    case "APIs": resultBackColor = "#005cbe"; break;
    case "Enterprise Solutions": resultBackColor = "#009245"; break;
    case "Web Services": resultBackColor = "#ff9000"; break;
    case "Legacy Services": resultBackColor = "#a31616"; break;
    case "Software": resultBackColor = "#c02040"; break;
    case "Reference Data": resultBackColor = "#6f1ba5"; break;
    default: resultBackColor = "#f6f6f6";
  }
  $(".ResultTileLayoutHead").css({"background-color":resultBackColor});//Sets the Result Head back color to the product.
  $(".ResultTileLayoutHead").children("p").first().text(spacedHashTarget + " Result Codes");//Sets the Result Head text to the selected tile.
  selectedResultCodeDisplayer($(this), trimmedHashTarget);
});


//Handles the result codes to be displayed, depending on the selected product.
function selectedResultCodeDisplayer(that, trimmedHashTarget) {
  $(".ResultTileLayoutHead").children(".TileLayoutBody").children("h3").children("span").each(function(){
    console.log("Each: " + $(this).text());
    if ($(this).text() !== AS||IS){
      $(this).parent("h3").css({"display":"none"});
	  $(this).next("table").css({"display":"none"});
    }
    $(".ResultTileLayoutHead").children(".TileLayoutBody").children("table").children("tr").children("td").each(function(){
      console.log("Each: " + $(this).text());
    })
  }
}

//Check On Page Load
//$(window).on('hashchange', TileLayoutTileHider);//Check on hashchange


/*
$(window).on('hashchange', TileLayoutTileHider);//Check on hashchange
function TileLayoutTileHider(){
  var pageHash = window.location.hash
  var trimmedHash = pageHash.slice(pageHash.indexOf("#") + 1,(pageHash.length));
  console.log("pageHash: " + pageHash);
  console.log("trimmedHash: " + trimmedHash);
}*/