MediaWiki:Gadget-artTab.js: Difference between revisions
Jump to navigation
Jump to search
m Forgot basepath |
Added live2d check |
||
Line 14: | Line 14: | ||
// Set "active" at the end | // Set "active" at the end | ||
currentElement.addClass('active'); | currentElement.addClass('active'); | ||
} | |||
function doesLive2dAnimationExist(artTabDiv, costume) { | |||
var costumeId = costume; | |||
if (costumeId[0] === '_') { | |||
costumeId = costumeId.substr(1); | |||
} | |||
if (costume == "") { | |||
costumeId = "costume0"; | |||
} | |||
return $(artTabDiv).attr("data-live2d-exist-" + costumeId) == "true"; | |||
} | } | ||
Line 38: | Line 50: | ||
damagedArt.find('img').attr("srcset", fullartDamagedPath ); | damagedArt.find('img').attr("srcset", fullartDamagedPath ); | ||
damagedArt.find('img').attr("alt", fullartDamagedPath ); | damagedArt.find('img').attr("alt", fullartDamagedPath ); | ||
var isLive2dPossible = doesLive2dAnimationExist(artTabDiv, costumeSuffix); | |||
console.log("Live2D check", isLive2dPossible); | |||
}; | }; | ||
Revision as of 16: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 doesLive2dAnimationExist(artTabDiv, costume) {
var costumeId = costume;
if (costumeId[0] === '_') {
costumeId = costumeId.substr(1);
}
if (costume == "") {
costumeId = "costume0";
}
return $(artTabDiv).attr("data-live2d-exist-" + costumeId) == "true";
}
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 );
var isLive2dPossible = doesLive2dAnimationExist(artTabDiv, costumeSuffix);
console.log("Live2D check", isLive2dPossible);
};
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();
});
});