Open main menu

Changes

MediaWiki:Gadget-artTab.js

838 bytes removed, 15:07, 14 October 2019
Added document-ready wait functionality as the MediaWiki does not wait for DOM
function refreshView(artTabDiv) {
var tdoll = $(artTabDiv).data('tdollId');
var costume = $(artTabDiv).dataattr('tdollCostumedata-tdoll-costume');
var variant = $(artTabDiv).attr('data-tdoll-variant'); // why not data though?
var live2dActive = $(artTabDiv).find('.live2dstage').is(':visible');
$(artTabDiv).addClass("loading");
if (live2dActive) {
createLive2dView(artTabDiv, function(view) {
var stage = view.data('live2dStage');
stage.removeChildren();
loadLive2dGirl var anythingFailedHandler = function(x,y,z) { view.closest(".artTab").removeClass("loading"); console.log(tdoll"Failed loading Live2D", costumex, varianty, z); }; var loadLive2DgirlSuccessHandler = function(live2dData) { // remove any view.closest(".artTab").removeClass("loading icons here"); stage.addChild(live2dData); };  var loadLive2DsuccessHandler = function() { gfUtils.live2dUtils.loadLive2dGirl($(artTabDiv), tdoll, costume, variant, loadLive2DgirlSuccessHandler, anythingFailedHandler); }; mw.loader.using('ext.gadget.live2dAnimation').then(loadLive2DsuccessHandler, anythingFailedHandler);
});
} else {
console.log("Switching", tdoll, costume, variant, $(artTabDiv), $(artTabDiv).find(".fullart[data-variant='" + variant + "']"));
$(artTabDiv).find(".fullart[data-variant='" + variant + "']").show();
$(artTabDiv).removeClass("loading");
}
}
return l2d_tdoll_sprite;
}
 
function loadLive2dGirl(tdoll, costume, variant, callback) {
var modelId = tdoll;
if (costume.length > 0) {
modelId = modelId + "_" + costume;
}
if (variant && variant.length > 0) {
modelId = modelId + "_" + variant;
}
$.ajax({
dataType: "json",
url: curl(modelId + "_live2d_model.txt"),
// data: null,
success: function (data) {
json = data;
json.model = curl(modelId + "_live2d_model.moc" + ".skel");
if (json.hasOwnProperty('physics')) { json.physics = curl(modelId + "_live2d_physics" + ".txt"); }
if (json.hasOwnProperty('pose')) { json.pose = curl(modelId + "_live2d_pose" + ".txt"); }
for (var idx=0; idx < json.textures.length; idx++) {
json.textures[idx] = curl(modelId + "_live2d_" + json.textures[idx]);
}
for (var idx=0; idx < json.motions.idle.length; idx++) {
json.motions.idle[idx].file = curl(modelId + "_live2d_" + json.motions.idle[idx].file + ".txt");
}
for (var idx=0; idx < json.motions.tap_figure.length; idx++) {
json.motions.tap_figure[idx].file = curl(modelId + "_live2d_" + json.motions.tap_figure[idx].file + ".txt");
}
var l2d_tdoll_sprite = createLive2dSprite(json);
callback(l2d_tdoll_sprite);
}
});
}
hideLive2dView(artTabDiv);
variantswitcherartTabDiv.find('.rightartTabLive2dSwitch').remove();
var basePath = mw.config.get("wgServer") + "/images/";
var cpp = window.gfUtils.createWikiPathPart;
var fullartPath = basePath + "thumb/" + cpp(artModelId +".png") + artModelId +".png/420px600px-" + artModelId +".png"; var fullartDamagedPath = basePath + "thumb/" + cpp(artModelId +"_D.png") + artModelId +"_D.png/420px600px-" + artModelId +"_D.png";
var normArt = artTabDiv.find(".fullart:not(.damaged) a");
normArt.attr("href", fullartPath "/wiki/File:" + artModelId + ".png");
normArt.find('img').attr("src", fullartPath );
normArt.find('img').attr("srcset", fullartPath );
var damagedArt = artTabDiv.find(".fullart.damaged a");
damagedArt.attr("href", fullartDamagedPath "/wiki/File:" + artModelId + "_D.png");
damagedArt.find('img').attr("src", fullartDamagedPath );
damagedArt.find('img').attr("srcset", fullartDamagedPath );
var isLive2dPossible = doesLive2dAnimationExist(artTabDiv, costumeSuffix);
if (isLive2dPossible) {
var live2dButton live2dButtonHandler = $('<button></button>'); live2dButton.addClass('artTabLinks'); live2dButton.addClass('right'); live2dButton.click(function() {
if (live2dButton.is('.enabled')) {
hideLive2dView($(artTabDiv));
live2dButton.removeClass('enabled');
} else {
$(artTabDiv).addClass("loading");
createLive2dView(artTabDiv, function(view) {
view.show();
live2dButton.addClass('enabled');
}
}); var live2dButton= gfUtils.textcreateSliderButton("Live2Dhttp://en.gfwiki.com/images/a/a3/live2d-logo.png", live2dButtonHandler); live2dButton.addClass('artTabLive2dSwitch'); variantswitcherartTabDiv.append(live2dButton);
}
refreshView(artTabDiv);
};
RLQ.push(['jquery', function () { $(document).ready(function() {
var artTabDiv = $('.artTab');
artTabDiv.on('costume_changed', modelChanged);
normalButton.click();
});
}]);