Widget:Live2DSwitcher: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Added document-ready wait functionality as the MediaWiki does not wait for DOM |
||
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly><div><script> | <includeonly><div><script> | ||
RLQ.push(function () { | RLQ.push(['jquery', function () { | ||
$(document).ready(function() { | $(document).ready(function() { | ||
var containers = $('.dollLive2d'); | var containers = $('.dollLive2d'); | ||
Line 8: | Line 8: | ||
var container = $(val); | var container = $(val); | ||
var doll = container.data('t-doll'); | var doll = container.data('t-doll'); | ||
var | container.on("live2dloaded", function(event) { | ||
var settings = gfUtils.live2dUtils.convertSettingsFromUl( | container.find('.live2dswitcher option').remove(); | ||
var settingsContainer = container.find('.live2dsettings').first(); | |||
var settings = gfUtils.live2dUtils.convertSettingsFromUl(settingsContainer); | |||
for (var idx=0; idx<settings.length; idx++) { | |||
var id = doll + "|" + | var currentSettings = settings[idx]; | ||
var name = variant.name; | for (variant in currentSettings) { | ||
if (variant == "costumeId") { | |||
continue; | |||
} | |||
var id = doll + "|" + currentSettings.costumeId + "|" + variant; | |||
var name = currentSettings[variant].name; | |||
if (!name) { | if (!name) { | ||
name = | name = currentSettings.costumeId + " - " + variant; | ||
} | } | ||
container.find('.live2dswitcher').append($('<option>', { | container.find('.live2dswitcher').append($('<option>', { | ||
Line 25: | Line 31: | ||
} | } | ||
} | } | ||
}); | }); | ||
}); | }); | ||
}); | }); | ||
}); | }]); | ||
function | function swap_model(element) { | ||
var selectBox = $(element); | var selectBox = $(element); | ||
var containerDiv = selectBox. | var containerDiv = selectBox.closest('.dollLive2d'); | ||
var selectedValue = selectBox.val(); | var selectedValue = selectBox.val(); | ||
Line 49: | Line 54: | ||
</script> | </script> | ||
<select class="gf-droplist live2dswitcher" style="flex-grow: 1;" autocomplete="off" onchange="swap_model(this)" > | <label>Costume:</label><select class="gf-droplist live2dswitcher" style="flex-grow: 1;" autocomplete="off" onchange="swap_model(this)" > | ||
<option value="" selected="selected">Loading...</option> | |||
</select></div></includeonly><noinclude> | </select></div></includeonly><noinclude> | ||
<div class="dollLive2d" data-t-doll="Thompson" style="height: 800px; width: 700px;"> | <div class="dollLive2d" data-live2d-needed="true" data-t-doll="Thompson" data-costume="costume1" style="height: 800px; width: 700px;"> | ||
{{#widget:Live2DSwitcher}} | {{#widget:Live2DSwitcher}} | ||
<div class="live2dsettings" style="display:none">{{:Thompson/Live2DSettings}}</div> | <div class="live2dsettings" style="display:none">{{:Thompson/Live2DSettings}}</div> | ||
</div> | </div> | ||
</noinclude> | </noinclude> |