„Benutzer:Wiegels/js/chess.js“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
Inhalt gelöscht Inhalt hinzugefügt
Neu
 
Update: Synchronisation auch mit neuer Notation
Zeile 20: Zeile 20:
var y = $(this).parent().index()-1;
var y = $(this).parent().index()-1;
var x = $(this).index()-1;
var x = $(this).index()-1;
$('#wpTextbox1').val(
$('#wpTextbox1').val($('#wpTextbox1').val().
$('#wpTextbox1').val().replace(RegExp('^((?:[^$]*?\{\{Schachbrett[^$]+?\}\}){'+z+'}[^$]*?'+
replace(RegExp('^((?:[^$]*?\{\{Schachbrett[^$]+?\}\}){'+z+'}[^$]*?'+
'\{\{Schachbrett[^$]+?Brett=\n?(?:\n [1-8][^=]+?=){'+y+'}\n [1-8] (?:...){'+x+'}.)..([^$]+?\}\}'+
'\{\{Schachbrett[^$]+?Brett=\n\n?(?: [1-8] [^=]+? [1-8]_=\n){'+y+'} [1-8] .(?:...){'+x+'})..([^$]+?\}\}'+
'[^$]*)$'.replace(/\\/g, '\\')), '$1'+figure.replace('--', ' ')+'$2'));
'[^$]*)$'.replace(/\\/g, '\\')), '$1'+figure.replace('--', ' ')+'$2'). // alte Notation
replace(RegExp('^((?:[^$]*?\{\{Schachbrett[^$]+?\}\}){'+z+'}[^$]*?'+
'\{\{Schachbrett[^$]*?\n(?:. Z[1-8]=[^\n]{24}\n){'+y+'}. Z[1-8]=(?:...){'+x+'})..(\/[^$]+?\}\}'+
'[^$]*)$'.replace(/\\/g, '\\')), '$1'+figure.replace('--', ' ')+'$2')); // neue Notation
}).attr('title', 'Klicken, um Figur zu setzen');
}).attr('title', 'Klicken, um Figur zu setzen');
}
}

Version vom 9. Juni 2018, 21:11 Uhr

function Chess() {
    var figures = '-prnbqk'.split('');
    var paths = '1e;45,72,70,b1,15,42;1e;c7,ff,ef,98,47,f0'.split(/[,;]/);
    var black = false;
    return function() {
        $('#wikiPreview img[alt="Chess --t45.svg"]').parents('table').addClass('jw-chess');
        $('#wikiPreview table.jw-chess').on('mouseenter mouseleave',  function(event) {
            $(this).css('outline', (event.type=='mouseenter' ? '2px solid orange' : ''));
        });
        $('#wikiPreview table.jw-chess td:has(img)').on('mouseenter mouseleave',  function(event) {
            $(this).css('outline', (event.type=='mouseenter' ? '2px solid '+(this.black ? '#000' : '#fff') : ''));
        }).on('click', function() {
            var index = (figures.indexOf($(this).html().match(/"Chess (.).t45\.svg"/)[1])+1)%7;
            black = black == (index>0);
            var figure = (index>0 ? figures[index]+(black ? 'd' : 'l') : '--');
            $(this).html($(this).html().
                replace(/(Chess[ _])..(t45)/g, '$1'+figure+'$2').
                replace(/(thumb\/)\w\/\w\w/g, '$1'+paths[index+(black ? 7 : 0)].replace(/^((.).)$/, '$2/$1')));
            var z = $(this).parents('table').index('#wikiPreview table.jw-chess');
            var y = $(this).parent().index()-1;
            var x = $(this).index()-1;
            $('#wpTextbox1').val($('#wpTextbox1').val().
                replace(RegExp('^((?:[^$]*?\{\{Schachbrett[^$]+?\}\}){'+z+'}[^$]*?'+
                    '\{\{Schachbrett[^$]+?Brett=\n\n?(?: [1-8] [^=]+? [1-8]_=\n){'+y+'} [1-8] .(?:...){'+x+'})..([^$]+?\}\}'+
                    '[^$]*)$'.replace(/\\/g, '\\')), '$1'+figure.replace('--', '  ')+'$2'). // alte Notation
                replace(RegExp('^((?:[^$]*?\{\{Schachbrett[^$]+?\}\}){'+z+'}[^$]*?'+
                    '\{\{Schachbrett[^$]*?\n(?:. Z[1-8]=[^\n]{24}\n){'+y+'}. Z[1-8]=(?:...){'+x+'})..(\/[^$]+?\}\}'+
                    '[^$]*)$'.replace(/\\/g, '\\')), '$1'+figure.replace('--', '  ')+'$2')); // neue Notation
        }).attr('title', 'Klicken, um Figur zu setzen');
    }
}
Chess()();