MediaWiki:Common.js: Unterschied zwischen den Versionen

Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
var surfaceModel = ve.init.target.getSurface().getModel();
(function ($) { // Wrap with anonymous function
surfaceModel.getFragment()
    var $summaryBox  = $('#wpSummary');
.adjustLinearSelection( 1 )
 
.collapseToStart()
    function editsummAddOptionToDropdown(dropdown, optionText) {
.insertContent( [
        var option = document.createElement("option");
{ type: 'table' },
        var optionTextNode = document.createTextNode(optionText);
{ type: 'tableCaption' },
        option.appendChild(optionTextNode);
{ type: 'paragraph' }, 'C', 'a', 'p', 't', 'i', 'o', 'n', { type: '/paragraph' },
        dropdown.appendChild(option);
{ type: '/tableCaption' },
    }
{ type: 'tableSection', attributes: { style: 'body' } },
{ type: 'tableRow' },
    function editsummAddCatToDropdown(dropdown, catText) {
{ type: 'tableCell', attributes: { style: 'header' } },
        var option = document.createElement("option");
{ type: 'paragraph' }, 'A', { type: '/paragraph' },
        option.disabled = true;
{ type: '/tableCell' },
        option.selected = true;
{ type: 'tableCell', attributes: { style: 'data' } },
        var optionTextNode = document.createTextNode(catText);
{ type: 'paragraph' }, 'A', '1', { type: '/paragraph' },
        option.appendChild(optionTextNode);
{ type: '/tableCell' },
        dropdown.appendChild(option);
{ type: 'tableCell', attributes: { style: 'data' } },
    }
{ type: 'paragraph' }, 'A', '2', { type: '/paragraph' },
{ type: '/tableCell' },
    function editsummOnCannedSummarySelected() {
{ type: 'tableCell', attributes: { style: 'data' } },
        // Save the original value of the edit summary field
{ type: 'paragraph' }, 'A', '3', { type: '/paragraph' },
        var editsummOriginalSummary = $summaryBox.val();
{ type: '/tableCell' },
{ type: '/tableRow' },
        var idx = this.selectedIndex;
{ type: 'tableRow' },
        var canned = this.options[idx].text;
{ type: 'tableCell', attributes: { style: 'header' } },
{ type: 'paragraph' }, 'B', { type: '/paragraph' },
        var newSummary = editsummOriginalSummary;
{ type: '/tableCell' },
{ type: 'tableCell', attributes: { style: 'data' } },
        // Append old edit summary with space, if exists,
{ type: 'paragraph' }, 'B', '1', { type: '/paragraph' },
        // and last character != space
{ type: '/tableCell' },
        if (newSummary.length !== 0 && newSummary.charAt(newSummary.length - 1) !== " ") {
{ type: 'tableCell', attributes: { style: 'data' } },
            newSummary += " ";
{ type: 'paragraph' }, 'B', '2', { type: '/paragraph' },
        }
{ type: '/tableCell' },
        newSummary += canned;
{ type: 'tableCell', attributes: { style: 'data' } },
        $summaryBox.val( newSummary ).trigger( 'change' );
{ type: 'paragraph' }, 'B', '3', { type: '/paragraph' },
    }
{ type: '/tableCell' },
{ type: '/tableRow' },
    function insertSummaryOptions($insertBeforeThis, dropdownWidth) {  
{ type: '/tableSection' },
        // For convenience, add a dropdown box with some canned edit
{ type: '/table' }
        // 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:21 Uhr

(function ($) { // Wrap with anonymous function
    var $summaryBox  = $('#wpSummary');

    function editsummAddOptionToDropdown(dropdown, optionText) {
        var option = document.createElement("option");
        var optionTextNode = document.createTextNode(optionText);
        option.appendChild(optionTextNode);
        dropdown.appendChild(option);
    }
 
    function editsummAddCatToDropdown(dropdown, catText) {
        var option = document.createElement("option");
        option.disabled = true;
        option.selected = true;
        var optionTextNode = document.createTextNode(catText);
        option.appendChild(optionTextNode);
        dropdown.appendChild(option);
    }
 
    function editsummOnCannedSummarySelected() {
        // Save the original value of the edit summary field
        var editsummOriginalSummary = $summaryBox.val();
 
        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) !== " ") {
            newSummary += " ";
        }
        newSummary += canned;
        $summaryBox.val( newSummary ).trigger( 'change' );
    }
 
    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