MediaWiki:Common.js: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
(function ($) { // Wrap with anonymous function
/**
    var $summaryBox  = $('#wpSummary');
* Adds direction mark tool to VE (for adding RLM)
*/
(function () {
// localization for button name
if(!mw.messages.exists('DirectionTool-toolname')){
mw.messages.set('DirectionTool-toolname', 'תו כיווניות');
}
// localization for rlm template name
if(!mw.config.exists('rlmTemplateName')){
mw.config.set('rlmTemplateName', 'כ');
}
//end of localization


    function editsummAddOptionToDropdown(dropdown, optionText) {
function DirectionTool( toolGroup, config ) {
        var option = document.createElement("option");
OO.ui.Tool.call( this, toolGroup, config );
        var optionTextNode = document.createTextNode(optionText);
}
        option.appendChild(optionTextNode);
OO.inheritClass( DirectionTool, OO.ui.Tool );
        dropdown.appendChild(option);
 
    }
DirectionTool.static.name = 'DirectionTool';
DirectionTool.static.title = mw.msg('DirectionTool-toolname');
    function editsummAddCatToDropdown(dropdown, catText) {
 
        var option = document.createElement("option");
DirectionTool.prototype.onSelect = function () {
        option.disabled = true;
this.toolbar.getSurface().getModel().getFragment().collapseToEnd().insertContent([{
        option.selected = true;
'type': 'mwTransclusionInline',
        var optionTextNode = document.createTextNode(catText);
'attributes': {
        option.appendChild(optionTextNode);
'mw': {
        dropdown.appendChild(option);
parts: [ {
    }
template: {
target: {
    function editsummOnCannedSummarySelected() {
href: wgFormattedNamespaces[10]+ ':'+ mw.config.get('rlmTemplateName'),
        // Save the original value of the edit summary field
wt: mw.config.get('rlmTemplateName')
        var editsummOriginalSummary = $summaryBox.val();
},
params: {}
        var idx = this.selectedIndex;
}
        var canned = this.options[idx].text;
}]
}
        var newSummary = editsummOriginalSummary;
}
}]);
        // Append old edit summary with space, if exists,
};
        // and last character != space
 
        if (newSummary.length !== 0 && newSummary.charAt(newSummary.length - 1) !== " ") {
DirectionTool.prototype.onUpdateState = function () {
            newSummary += " ";
this.setActive( false );
        }
};
        newSummary += canned;
 
        $summaryBox.val( newSummary ).trigger( 'change' );
ve.ui.toolFactory.register( DirectionTool );
    }
 
})();
    function insertSummaryOptions($insertBeforeThis, dropdownWidth) {  
        // For convenience, add a dropdown box with some canned edit
        // summaries to the form.
        var dropdown = document.createElement("select");
        dropdown.style.width = dropdownWidth;
        dropdown.style.margin = "0 4px 0 0";
        dropdown.onchange = editsummOnCannedSummarySelected;
        var minorDropdown = document.createElement("select");
        minorDropdown.style.width = dropdownWidth;
        minorDropdown.onchange = editsummOnCannedSummarySelected;
        editsummAddCatToDropdown(minorDropdown, "Common minor edit summaries – click to use");
        editsummAddCatToDropdown(dropdown, "Common edit summaries – click to use");
        editsummAddOptionToDropdown(minorDropdown, "Spelling/grammar correction");
        editsummAddOptionToDropdown(minorDropdown, "Fixing style/layout errors");
        editsummAddOptionToDropdown(minorDropdown, "[[Help:Reverting|Reverting]] [[Wikipedia:Vandalism|vandalism]] or test edit");
        editsummAddOptionToDropdown(minorDropdown, "[[Help:Reverting|Reverting]] unexplained content removal");
        editsummAddOptionToDropdown(minorDropdown, "Copyedit (minor)");
        if (mw.config.get('wgNamespaceNumber') === 0) {
            editsummAddOptionToDropdown(dropdown, "Expanding article");
            editsummAddOptionToDropdown(dropdown, "Adding/improving reference(s)");
            editsummAddOptionToDropdown(dropdown, "Adding/removing category/ies");
            editsummAddOptionToDropdown(dropdown, "Adding/removing external link(s)");
            editsummAddOptionToDropdown(dropdown, "Adding/removing wikilink(s)");
            editsummAddOptionToDropdown(dropdown, "Removing unsourced content");
            editsummAddOptionToDropdown(dropdown, "Removing [[WP:SPAM|linkspam]] per [[WP:EL]]");
            editsummAddOptionToDropdown(dropdown, "Clean up");
            editsummAddOptionToDropdown(dropdown, "Copyedit (major)");
        } else {
            editsummAddOptionToDropdown(dropdown, "Reply");
            editsummAddOptionToDropdown(dropdown, "Comment");
            editsummAddOptionToDropdown(dropdown, "Suggestion");
            if ((mw.config.get('wgNamespaceNumber') % 2 !== 0) & (mw.config.get('wgNamespaceNumber') !== 3)) {
                editsummAddOptionToDropdown(dropdown, "[[Wikipedia:WikiProject|WikiProject]] tagging");
                editsummAddOptionToDropdown(dropdown, "[[Wikipedia:WikiProject|WikiProject]] assessment");
            }
        }
$insertBeforeThis.before(dropdown);
        $insertBeforeThis.before(minorDropdown);
    }
    mw.hook( 've.saveDialog.stateChanged' ).add(function(){
        //.ve-init-mw-viewPageTarget-saveDialog-checkboxes
        var target = ve.init.target;
        var $insertBeforeThis = target.saveDialog.$body.find('.ve-ui-mwSaveDialog-options');
        $summaryBox = target.saveDialog.$body.find('.ve-ui-mwSaveDialog-summary textarea');
        if (!$insertBeforeThis.length) {
            return;
        }
        insertSummaryOptions($insertBeforeThis, "98%");
    });
    $(function() {
        var $insertBeforeThis = $('.editCheckboxes');
        // If we failed to find the editCheckboxes class
        if (!$insertBeforeThis.length) {
            return;
        }
        insertSummaryOptions($insertBeforeThis, "38%");
    });
}(jQuery)); // End wrap with anonymous function

Version vom 1. Februar 2016, 18:23 Uhr

/**
 * Adds direction mark tool to VE (for adding RLM) 
 */
(function () {
// localization for button name
if(!mw.messages.exists('DirectionTool-toolname')){
	mw.messages.set('DirectionTool-toolname', 'תו כיווניות');
}
// localization for rlm template name
if(!mw.config.exists('rlmTemplateName')){
	mw.config.set('rlmTemplateName', 'כ');
}
//end of localization

function DirectionTool( toolGroup, config ) {
	OO.ui.Tool.call( this, toolGroup, config );
}
OO.inheritClass( DirectionTool, OO.ui.Tool );

DirectionTool.static.name = 'DirectionTool';
DirectionTool.static.title = mw.msg('DirectionTool-toolname');

DirectionTool.prototype.onSelect = function () {
	this.toolbar.getSurface().getModel().getFragment().collapseToEnd().insertContent([{
		'type': 'mwTransclusionInline',
		'attributes': {
			'mw': {
				parts: [ {
					template: {
						target: {
							href: wgFormattedNamespaces[10]+ ':'+ mw.config.get('rlmTemplateName'),
							wt: mw.config.get('rlmTemplateName')
						},
						params: {}
					}
				}]
			}
		}
	}]);
};

DirectionTool.prototype.onUpdateState = function () {
	this.setActive( false );
};

ve.ui.toolFactory.register( DirectionTool );

})();