helialprofile.png
Welcome to IOPWiki, Commander.
We are lacking editors focused on Girls' Frontline and Girls' Frontline 2. You can contribute without an account. Learn how to contribute and join our Discord server.

Difference between revisions of "MediaWiki:Gadget-artTab.js"

Welcome to IOP Wiki. This website is maintained by the Girls' Frontline community and is free to edit by anyone.
Jump to navigation Jump to search
(Switch art)
m (Forgot basepath)
Line 22: Line 22:
 
   var artModelId = tdollId + costumeSuffix;
 
   var artModelId = tdollId + costumeSuffix;
 
    
 
    
 +
  var basePath = mw.config.get("wgServer") + "/images/";
 
   var cpp = window.gfUtils.createWikiPathPart;
 
   var cpp = window.gfUtils.createWikiPathPart;
 
   var fullartPath = basePath + "thumb/" + cpp(artModelId +".png") + artModelId +".png/420px-" + artModelId +".png";
 
   var fullartPath = basePath + "thumb/" + cpp(artModelId +".png") + artModelId +".png/420px-" + artModelId +".png";

Revision as of 03:12, 13 January 2018

function switchVariant(event, variant) {
  var currentElement = $(event.target);
  var artTabDiv = currentElement.closest('.artTab');
  artTabDiv.find('.artTabLinks').removeClass('active');
  artTabDiv.find('.artTabContent .fullart').hide();
  
  var live2dActive = false; // ToDo
  if (live2dActive) {
    console.log("?");
  } else {
    artTabDiv.find("[data-variant='" + currentElement.data('variant') +"']").show();
  }

  // Set "active" at the end
  currentElement.addClass('active');
}

function modelChanged(event, costumeSuffix) {
  console.log(event);
  var artTabDiv = $(event.target).closest('.artTab');
  var tdollId = artTabDiv.data('tdollId');
  var artModelId = tdollId + costumeSuffix;
  
  var basePath = mw.config.get("wgServer") + "/images/";
  var cpp = window.gfUtils.createWikiPathPart;
  var fullartPath = basePath + "thumb/" + cpp(artModelId +".png") + artModelId +".png/420px-" + artModelId +".png";
  var fullartDamagedPath = basePath + "thumb/" + cpp(artModelId +"_D.png") + artModelId +"_D.png/420px-" + artModelId +"_D.png";
    
  var normArt = artTabDiv.find(".fullart:not(.damaged) a");
  normArt.attr("href", fullartPath );
  normArt.find('img').attr("src", fullartPath );
  normArt.find('img').attr("srcset", fullartPath );
  normArt.find('img').attr("alt", fullartPath );

  var damagedArt = artTabDiv.find(".fullart.damaged a");
  damagedArt.attr("href", fullartDamagedPath );
  damagedArt.find('img').attr("src", fullartDamagedPath );
  damagedArt.find('img').attr("srcset", fullartDamagedPath );
  damagedArt.find('img').attr("alt", fullartDamagedPath );
};

RLQ.push(function () {
  $(document).ready(function() { 
    var artTabDiv = $('.artTab');
    artTabDiv.on('costume_changed', modelChanged);
  
    var normalButton = $('<button></button>');
    normalButton.addClass('artTabLinks');
    normalButton.click(switchVariant);
    normalButton.data('variant', "");
    normalButton.text("Normal");

    var damagedButton = $('<button></button>');
    damagedButton.addClass('artTabLinks');
    damagedButton.click(switchVariant);
    damagedButton.data('variant', "D");
    damagedButton.text("Damaged");
  
    var variantswitcher = $('<div></div>');
    variantswitcher.addClass('variantswitcher');
    variantswitcher.append(normalButton);
    variantswitcher.append(damagedButton);
    
    artTabDiv.prepend(variantswitcher);

    normalButton.click();
  });
});