Aller au contenu

MediaWiki:Gadget-PopupTextAlt.js

Èn årtike di Wikisource.

Note : après aveur schapé l’ pådje, vos l’ divoz rafrister, po pleur vey les candjmints dins vosse betchteu waibe.

  • Firefox / Safari : tchôkîz so Shift tot clitchant so Rafrister, ou co fjhoz Ctrl-F5 ou Ctrl-R (⌘-R so on Mac)
  • Google Chrome : tchôkîz so Ctrl-Shift-R (⌘-Shift-R so on Mac)
  • Internet Explorer / Edje : tchôkîz so Ctrl tot clitchant so Rafrister, ou co fjhoz Ctrl-F5
  • Konqueror : clitchîz so Rafrister ou tchôkîz so F5
  • Opera : alez dins Menu → Parametes (Opera → Preferinces so on Mac), pus dins Confidance et såvrité → Vudîz les dnêyes d’ vizitaedje → Imådjes et fitchîs metous el muchete.
PopupTextAlt = {
    ncor : 0,
    nsic : 0,
    
    /* 
     * Mete dins l' tiestire di l' espåce Pådje 
     * si gn a des coridjaedjes et des sic
     */
    prpheaderinfo : function(){
    	var lcor='', lsic = '', plural = '';
    	var prph = $('.prp-page-qualityheader');
    	prph.append(' I gn a ');
		if(PopupTextAlt.ncor) {
    		plural = PopupTextAlt.ncor?'s':'';
    		lcor = $('<a>');
    		lcor.attr('href', '#');
    		lcor.text(PopupTextAlt.ncor+' coridjaedje'+plural);
    		lcor.click(function(){
	        	PopupTextAlt.show(0, '.cor');
	        	return false;
	        });
	        prph.append(lcor);
		}
		if(PopupTextAlt.nsic) {
    		plural = PopupTextAlt.nsic?'s':'';
    		lsic = $('<a>');
    		lsic.attr('href', '#');
    		lsic.html(PopupTextAlt.nsic +' eployaedje'+plural+' di «&nbsp;sic&nbsp;»');
    		lsic.click(function(){
	        	PopupTextAlt.show(0, '.sic');
	        	return false;
	        });
	        if(PopupTextAlt.ncor) {
	        	prph.append(' et ');
	        }
	        prph.append(lsic);
		}
		prph.append(' sol pådje.');
    },
    
    /* 
     * Mete on mnu al copete do mwaisse espåce tchoezi les candjmints 
     */
    menu : function(){
    	var toggleSwitch1 = new OO.ui.ToggleSwitchWidget( { 
			value: PopupTextAlt.ncor, // true if > 0
			disabled: !PopupTextAlt.ncor
		} );
		var toggleSwitch2 = new OO.ui.ToggleSwitchWidget( { 
			value: false,
			disabled: !PopupTextAlt.ncor
		} );
		var toggleSwitch3 = new OO.ui.ToggleSwitchWidget( { 
			value: false,
			disabled: !PopupTextAlt.nsic
		} );
		
		toggleSwitch1.on('change', function(){
			PopupTextAlt.replacecor(toggleSwitch1.getValue());
		} );
		toggleSwitch2.on('change', function(){
			PopupTextAlt.highlight(
				'.cor',
				toggleSwitch2.getValue()
			);
		} );
		toggleSwitch3.on('change', function(){
			PopupTextAlt.highlight(
				'.sic',
				toggleSwitch3.getValue()
			);
		} );
	
	    var pluralcor = PopupTextAlt.ncor?'s':'';
	    var pluralsic = PopupTextAlt.nsic?'s':'';
	    var highlightsamplecor = '<span class="highlightsamplecor">çou</span>';
	    var highlightsamplesic = '<span class="highlightsamplesic">çou</span>';
	    var linktemplatecor = '<a href="/wiki/Modele:cor" target="_blank">cor</a>';
	    var linktemplatesic = '<a href="/wiki/Modele:sic" target="_blank">sic</a>';
	    var option1desc = 'Coridje li tecse d’après l’&nbsp;eployaedje do modele '+linktemplatecor;
	        option1desc += ' (' +PopupTextAlt.ncor+ ' coridjaedje'+pluralcor+').';
	    var option2desc = 'Mostere '+highlightsamplecor+' k’&nbsp;a stî coridjîs.';
	    var option3desc = 'Mostere '+highlightsamplesic+' k’&nbsp;on-z î a metou l’&nbsp;modele '+linktemplatesic;
	        option3desc += ' (' +PopupTextAlt.nsic+ ' eployaedje'+pluralsic+').';
	        
    	var content = $('<div>').addClass('popuptextalt-menu').append(
    		$('<div>').addClass('popuptextalt-label').append('Usteyes di coridjaedje'),
    		$('<div>').addClass('popuptextalt-row').append(
    			$('<div>').addClass('popuptextalt-desc').append(
    				$('<div>').append('Aviker l’&nbsp;coridjaedje'),
    				$('<div>').append(option1desc)
    			),
    			$('<div>').addClass('popuptextalt-btn').append(toggleSwitch1.$element)
    		),
    		$('<div>').addClass('popuptextalt-row').append(
    			$('<div>').addClass('popuptextalt-desc').append(
    				$('<div>').append('Sorlignî les coridjaedjes'),
    				$('<div>').append(option2desc)
    			),
    			$('<div>').addClass('popuptextalt-btn').append(toggleSwitch2.$element)
    		),
    		$('<div>').addClass('popuptextalt-row').append(
    			$('<div>').addClass('popuptextalt-desc').append(
    				$('<div>').append('Sorlignî les sic'),
    				$('<div>').append(option3desc)
    			),
    			$('<div>').addClass('popuptextalt-btn').append(toggleSwitch3.$element)
    		)
    	);
    	var menu = new OO.ui.PopupButtonWidget( {
			icon: 'menu',
			label: 'Tchuzes',
			invisibleLabel: true,
			popup: {
				$content: content,
				padded: true,
				align: 'center',
			}
		} );
		$('.mw-indicators').prepend(menu.$element);
    },
    
	/* 
	 * Håyner l' popup ki l' indek c' est 'i' 
	 * pol classe 'cor' u 'sic'
	 */
    show : function(i, selector){
        var j = i+1;
        PopupTextAlt.popup($(selector).eq(i));
        $("#popuptextalt-"+j).removeClass('oo-ui-element-hidden');
        $('html, body').scrollTop($("#popuptextalt-"+j).offset().top - 300);
    },
    
    replacecor : function(replace){
        var attr = replace?'alt':'txt';
        $('.cor').each(function(){
        	$(this).html(
        		decodeURIComponent($(this).data('popuptextalt-'+attr))
        	);
        });
    },
    
    highlight : function(selector, highlight){
    	if(highlight){
			$(selector).addClass('highlight');
		} else {
			$(selector).removeClass('highlight');
		}
    },
    
    /* 
     * Construre el popup d' on elemint 
     */
    popup : function(elem){
		$('.popuptextalt').remove();
		var selector = '.cor';
		var popuptite = "Coridjaedje";
		var thtxt = "Avant";
		var thalt = "Après";
		var tdsic = '';
		if($(elem).hasClass('sic')){
			selector = '.sic';
			popuptite = 'Sic';
			thtxt = "Sicrît";
			thalt = "Fåt i lére";
			tdsic = '<td>&nbsp;?</td>';
		}
		
		// ni nén eployî decodeURI()
		var tdtxt = decodeURIComponent($(elem).data('popuptextalt-txt'));
    	var tdalt = decodeURIComponent($(elem).data('popuptextalt-alt'));
    	var table = '<table>';
    	    table+= '<tr><th>'+thtxt+'</th><td>'+tdtxt+'</td></tr>';
    	    table+= '<tr><th>'+thalt+'</th><td>'+tdalt+'</td>'+tdsic+'</tr>';
    	    table+= '</table>';
    	var content = $('<div>').html(table);
    	if($(elem).data('popuptextalt-reason')){
    		var reason = $(elem).data('popuptextalt-reason');
    		content.append($('<div>').html('<strong>Råjhon</strong>&nbsp;: '+reason+'.'));
    	}
    	var index = $(selector).index(elem);
    	
    	// prev & next button	
    	var previ = index-1;
    	var nexti = index+1;
    	var prevelem = $(selector).eq(previ);
		var nextelem = $(selector).eq(nexti);
		if((index&&prevelem.length) || nextelem.length){
	    	var prev = new OO.ui.ButtonWidget( {
					framed: false,
					icon: 'previous',
					label: 'Divant',
					invisibleLabel: true,
					title: 'Divant',
					disabled: ((index&&prevelem.length)?false:true)
			} );
			if(!prev.isDisabled()){
				$(prev.$element).click(function(event){
					event.stopPropagation();
					PopupTextAlt.show(previ, selector);
				});
			}
			var next = new OO.ui.ButtonWidget( {
					framed: false,
					icon: 'next',
					label: 'Shuvant',
					invisibleLabel: true,
					title: 'Shuvant',
					disabled: (nextelem.length?false:true)
			} );
			if(!next.isDisabled()){
				$(next.$element).click(function(event){
					event.stopPropagation();
					PopupTextAlt.show(nexti, selector);
				});
			}
			// append nav bar
	    	content.append($('<nav>').append(prev.$element, next.$element));
		}
		
    	popup = new OO.ui.PopupWidget( {
			$content: $( content ),
			$container : $('.mw-parser-output'),
			containerPadding: 10,
			padded: true,
			width: 300,
			head: true,
			label: popuptite+' #'+(index+1),
			classes:  [ 'popuptextalt' ],
			id : "popuptextalt-"+(index+1)
		});
		
		$(elem).append(popup.$element);
		popup.toggle(true);
    },
    
    init : function(){
        PopupTextAlt.ncor = $('.cor').length;
    	PopupTextAlt.nsic = $('.sic').length;
    	
    	if(PopupTextAlt.ncor === 0 && PopupTextAlt.nsic === 0){
    		return false;
    	}
        
        $('.cor, .sic').each(function(){
        	$(this).removeAttr('title');
        });
        $('.cor, .sic').click(function(){
			PopupTextAlt.popup(this);
        });
        if (mw.config.get('wgNamespaceNumber') === 250){
        	PopupTextAlt.prpheaderinfo();
    	}
		PopupTextAlt.menu();
	},
};

$.when( mw.loader.using( [
	'oojs-ui-core',
	'oojs-ui-widgets',
	'oojs-ui.styles.icons-movement',
	'oojs-ui.styles.icons-layout'
] ), $.ready).then( PopupTextAlt.init );