# MediaWiki:Gadget-refStyle.js

From faraghaib
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.

    // gadget to control the display of reference section. rows, scroll, hide, and text-size
    // depends on 3 classes from common.css: ol.refDisplayRows, ol.refDisplayScroll, ol.refDisplayHide.
    // if classes are removed from common.js, need to add them in gadget.
    $(document).ready(function() {mw.loader.using('jquery.ui', function() {
        var current = $.cookie("ref-col-setting") || '',
    		checkboxes = [
    			{className: 'refDisplayRows', label: 'یک ستون', skip: $.client.profile().name === 'msie'},
    			{className: 'refDisplayScroll', label: 'اسکورال‌دار'},
    			{className: 'refDisplayHide', label: 'مخفی'}
    		];

    	function makeCheckbox(ol, className, label) {
    		var already = ol.closest('.' + className).length;
    		var checkBox = $('<input>', {type: 'checkbox'})
    			.prop({'checked': already || (current.indexOf(className) >= 0), disabled: already})
    			.click(function() {
    				ol.toggleClass(className, $(this).prop('checked'));
    				$.cookie("ref-col-setting", ol.attr('class'), {'expires':30,'path':'/'});
    			});
    		return $('<span>')
    			.append('&nbsp;&nbsp;' + label)
    			.append(checkBox);
    	}

    	function makeSlider(ol) {
    		var value = $.cookie("ref-font-size") || 90;
    		ol.css({fontSize: value + '%'});
    		var slider = $('<div>')
    		.css({fontSize: '130%', width: '200px'})
    		.slider({
    			max: 150,
    			min: 50,
    			value: value,
    			stop: function() {
    				var value = parseInt($(this).slider('value'), 10);
    				value = value < 40 ? 40 : (value > 150 ? 150 : value);
    				ol.css({fontSize: value + '%'});
    				$.cookie("ref-font-size", value, {'expires':30,'path':'/'});
    			}
    		});
    		return $('<div>').css({textAlign:'center', float: 'left'}).text('اندازهٔ متن پانویس').append(slider);
    	}

    	function makeCheckBoxes(ol) {
    		var span = $('<span>').css({fontSize: '50%'});
        		for (var i = 0; i < checkboxes.length; i++)
    			if (! checkboxes[i].skip)
    				span.append(makeCheckbox(ol, checkboxes[i].className, checkboxes[i].label));
    		span.append(makeSlider(ol));
    		return span;
    	}

    	$('ol.references').each(function() {
    		var ol = $(this);
    		var h2 = ol.parent().prev('h2').filter(function() {return /پانویس/.test($(this).text());});
    		if (ol.find('li').length < 10 || h2.length == 0)
    			return;
    		h2.append(makeCheckBoxes(ol));
    		ol.addClass(current);
    	});

    });}); //ready..using

Retrieved from "https://en.faraghaib.ir/w/index.php?title=MediaWiki:Gadget-refStyle.js&oldid=358"