Widget:Character-Banner: Difference between revisions

From Elwiki
No edit summary
(Replaced content with "<includeonly> <script type="application/javascript"> console.log(1); </script> </includeonly>")
Tag: Replaced
Line 1: Line 1:
<includeonly>
<includeonly>
     <script type="application/javascript">
     <script type="application/javascript">
RLQ.push(function () {
console.log(1);
var classes = [];
var maps = {};
jQuery('#p-Characters-label + .mw-portlet-body #nav > ul > li > a').each(function(){
    classes.push(jQuery(this).attr('title').replace('/', ''))
});
 
var api = new mw.Api();
for (let classx of classes) {
    var apix = api.parse(
    '[[File: Face - '+classx+'.png]]', {contentmodel: 'wikitext', wrapoutputclass: '', disablelimitreport: true});
    apix.then(function(text) {
        maps[classx] = text.match(/\/wiki(.*?)\.png/g)[0];
    });
}
 
var face_coords = function(path_no, job_no) {
    var coords = [1, 1];
if (job_no !== undefined && path_no !== undefined) {
    if (job_no == 1) {
        if (path_no == 4) coords = [2, 4]
        else coords=[1+path_no, 1]
    } else if (job_no == 2) {
        if (path_no == 4) coords = [3, 4]
        else coords = [path_no, 2]
    } else {
        if (path_no == 1) coords = [3, 3]
        else if (path_no == 2) coords = [4, 3]
        else if (path_no == 3) coords = [1, 4]
        else coords = [1, 5]
    }
}
    return coords;
}
 
var face = function(base_char, path_no, job_no) {
    var coords = face_coords(path_no, job_no);
    var offset_left = Math.abs(((coords[0]-1)*118)+1) * -1;
    var offset_top = Math.abs(((coords[1]-1)*62)+1) * -1;
    return '<div class="image-cropped"><div class="image-wrap" style="top: '+offset_top+'px; left: '+offset_left+'px;"><img src="'+maps[base_char]+'"/></div>';
}
 
    jQuery('.char-banner-tree-image').mouseenter(function(e) {
        var base_name = jQuery(this).parent().attr('data-base');
        var class_name = jQuery(this).attr('data-class-name');
        var index = jQuery(this).index()+1;
        var coords = [1, 1];
       
        if (index >= 1 && index <= 4) coords = [index, 1];
        else if (index >= 5 && index <= 8) coords = [index-4, 1];
        else coords = [index-8, 3];
 
        jQuery('.char-banner-title').text(class_name);
        jQuery('.char-banner-image').html(face('Aisha', coords[0], coords[1]));
    });
 
    jQuery('.char-banner-tree').mouseleave(function(e) {
        var base_name = jQuery(this).attr('data-base');
        if (base_name == 'LuCiel') base_name = 'Lu/Ciel';
        jQuery('.char-banner-title').text(base_name);
        jQuery('.char-banner-image').html(face('Aisha'));
        jQuery('.char-banner-image').click(function(){
            window.location.href = '/w/' + base_name;
        });
    });
});
     </script>
     </script>
</includeonly>
</includeonly>

Revision as of 21:42, 11 May 2022