Community Central
Community Central
m (correction)
Tag: sourceedit
m (finer selector)
Tag: sourceedit
 
(7 intermediate revisions by the same user not shown)
Line 72: Line 72:
 
var doSine = -1 != my.talkNameSpaces.indexOf(parseInt(wgNamespaceNumber));
 
var doSine = -1 != my.talkNameSpaces.indexOf(parseInt(wgNamespaceNumber));
 
 
var placewpMinoredit = $('.checkboxes .wpMinoredit');
+
var placeSine = $('#EditPageRail .wpSummaryFields .checkboxes');
placewpMinoredit.before('<label class="Sine"><input type="checkbox" name="Sine" id="Sine"><span>Sine</span></label>');
+
placeSine.prepend('<label class="Sine"><input type="checkbox" name="Sine" id="Sine"> <span>Sine</span></label>');
//placewpMinoredit.before('<label><input id="Sine" type="checkbox"> Sine</label>');
 
 
var sineCheckbox = $('#Sine');
 
var sineCheckbox = $('#Sine');
 
 
 
sineCheckbox
 
sineCheckbox
 
.attr('checked', doSine)
 
.attr('checked', doSine)
//.parent().css({
 
// position: 'absolute',
 
// right: parseInt(placewpMinoredit.css('right'), 10) + placewpMinoredit.width() + 20 + 'px',
 
// top: '6px'
 
//});
 
 
 
 
var blocks, editor;
 
var blocks, editor;
Line 294: Line 288:
   
 
/* --- START Standard Edit Summary Settings --- */
 
/* --- START Standard Edit Summary Settings --- */
  +
//No longer used; disable settings too
window.dev = window.dev || {};
 
window.dev.editSummaries = {
+
// window.dev = window.dev || {};
  +
// window.dev.editSummaries = {
select: [
+
// select: [
'Standard edit summaries',
+
// 'Standard edit summaries',
'Refactoring━━━━━━━━━━━━━✳️', [
 
  +
// 'Refactoring━━━━━━━━━━━━━', [
'Cleanup',
 
'Corrected spelling/grammar',
+
// 'Cleanup',
'Factual correction',
+
// 'Corrected spelling/grammar',
'Formatting',
+
// 'Factual correction',
'Source tidying',
+
// 'Formatting',
'Wikifying',
+
// 'Source tidying',
'Corrected template usage'
+
// 'Wikifying',
],
+
// 'Corrected template usage'
 
// ],
'Content━━━━━━━━━━━━━━━✏️', [
 
  +
// 'Content━━━━━━━━━━━━━━━', [
'Updated with new information',
 
'Expanded',
+
// 'Updated with new information',
'Revised',
+
// 'Expanded',
'Added sources',
+
// 'Revised',
'Neutral POV',
+
// 'Added sources',
'Replaced duplicate image(s)'
+
// 'Neutral POV',
],
+
// 'Replaced duplicate image(s)'
 
// ],
'Templates━━━━━━━━━━━━━━🚩', [
 
  +
// 'Templates━━━━━━━━━━━━━━', [
'Added template(s)',
 
'Added {{Delete}}',
+
// 'Added template(s)',
'Added {{Stub}}',
+
// 'Added {{Delete}}',
'Added infobox'
+
// 'Added {{Stub}}',
],
+
// 'Added infobox'
  +
// ],
'Categories━━━━━━━━━━━━━━📁', [
 
  +
// 'Categories━━━━━━━━━━━━━━', [
'Added category',
 
'Modified category',
+
// 'Added category',
'Organized categories'
+
// 'Modified category',
],
+
// 'Organized categories'
  +
// ],
'Removal/Reversion━━━━━━━━━━✂️', [
 
  +
// 'Removal/Reversion━━━━━━━━━━', [
'Reverted vandalism',
 
'Reverted test edit',
+
// 'Reverted vandalism',
'Reverted vanity edit',
+
// 'Reverted test edit',
'Removed fanon',
+
// 'Reverted vanity edit',
'Removed libel/slander',
+
// 'Removed fanon',
'Removed © violation'
+
// 'Removed libel/slander',
]
+
// 'Removed © violation'
]
+
// ]
  +
// ]
};
 
  +
// };
 
/* --- END Standard Edit Summary Settings --- */
 
/* --- END Standard Edit Summary Settings --- */
   
Line 349: Line 344:
 
'u:dev:RevealAnonIP/usercode.js', //http://dev.wikia.com/wiki/RevealAnonIP
 
'u:dev:RevealAnonIP/usercode.js', //http://dev.wikia.com/wiki/RevealAnonIP
 
'u:dev:AjaxRC/code.js', //Special:RecentChanges live update
 
'u:dev:AjaxRC/code.js', //Special:RecentChanges live update
'u:dev:SkinSwitchButton/code.js', //adds buttons to change skin
 
 
'u:dev:LastEdited/code.js', //add who last edited to pages
 
'u:dev:LastEdited/code.js', //add who last edited to pages
 
'u:dev:NullEditButton/code.js', //adds a "Null Edit" option to page controls
 
'u:dev:NullEditButton/code.js', //adds a "Null Edit" option to page controls
'u:dev:Standard_Edit_Summary/code.js', //offer edit summaries
+
'u:dev:MediaWiki:AjaxDiff/code.js', //diff without leaving RC
'u:dev:Sine/code.js', //always sign talk page posts
 
 
'u:dev:SignatureCheck/code.js' //check if talk post was signed
 
'u:dev:SignatureCheck/code.js' //check if talk post was signed
 
//'u:dev:SkinSwitchButton/code.js', //adds buttons to change skin
  +
//↳Not used often enogh to justify extra overhead :P
 
//'u:dev:Standard_Edit_Summary/code.js', //offer edit summaries
 
//↳Hasn't been useful to me
  +
//'u:dev:MediaWiki:Rollback/code.js', //always show rollback, even if not a rollbacker
  +
//↳don't like it :P
 
//'u:dev:QuickToolsv2/code.js', //adds quick tools to pages
 
//'u:dev:QuickToolsv2/code.js', //adds quick tools to pages
 
//↳Not used very often; Wikimarks handles a lot of this anyway
 
//↳Not used very often; Wikimarks handles a lot of this anyway
 
//'u:kocka:MediaWiki:Emoticons.js', //adds list of emotes to chat
 
//'u:kocka:MediaWiki:Emoticons.js', //adds list of emotes to chat
//↳meh
+
//↳meh; imported from user's test wiki (too risky IMHO :P)
 
//'u:dev:InactiveUsers/code.js', //show inactive users
 
//'u:dev:InactiveUsers/code.js', //show inactive users
//↳doesn't work? meh anyway :P
 
//'u:dev:MediaWiki:AjaxDiff/code.js', //diff within RC
 
 
//↳doesn't work? meh anyway :P
 
//↳doesn't work? meh anyway :P
 
//'u:dev:HighlightUsers/code.js', //http://dev.wikia.com/wiki/HighlightUsers
 
//'u:dev:HighlightUsers/code.js', //http://dev.wikia.com/wiki/HighlightUsers
Line 367: Line 364:
 
//'u:dev:MarkForDeletion/code.js', //Quickly insert 'delete' template
 
//'u:dev:MarkForDeletion/code.js', //Quickly insert 'delete' template
 
//↳Not used very often
 
//↳Not used very often
  +
//CODE COPIED HERE; DON'T IMPORT ORIGINAL
 
//'u:dev:Sine/code.js', //always sign talk page posts
  +
//↳temporarily disabled while modified code is here (above)
 
//UNECESSARY
 
//UNECESSARY
 
//'u:dev:PortableCSSPad/code.js', //Add CSS injector to toolbar
 
//'u:dev:PortableCSSPad/code.js', //Add CSS injector to toolbar
Line 379: Line 379:
 
//↳can change with WikiMarks
 
//↳can change with WikiMarks
 
//OLD; DON'T USE
 
//OLD; DON'T USE
//'u:wikimarks:Client.js', //Wikimarks menu
+
//'u:wikimarks:Client.js', //Wikimarks menu; moved to u:dev:Wikimarks/code.js
 
//'u:railgunscript:MediaWiki:RailgunClient.min.js', //http://railgunscript.wikia.com/wiki/Railgun_Wiki
 
//'u:railgunscript:MediaWiki:RailgunClient.min.js', //http://railgunscript.wikia.com/wiki/Railgun_Wiki
 
]
 
]
 
});
 
});
 
/* ####################### END of User:Iynque/global.js ##################### */
 
/* ####################### END of User:Iynque/global.js ##################### */
console.info("Loaded User:Iynque/global.js version 44.3");
+
console.info("Loaded User:Iynque/global.js version 46.3");
 
// </syntaxhighlight>
 
// </syntaxhighlight>

Latest revision as of 01:55, 8 May 2016

// __NOWYSIWYG__ <syntaxhighlight lang="javascript">
/*jshint -W065 */
/* ########################################################################## */
/* ###                       User:Iynque/global.js                        ### */
/* ########################################################################## */
/* Any JavaScript here will be loaded for me only on every Wikia wiki page. */
 
 
/* ########################################################################## */
/* Settings */
/* ########################################################################## */

/* --- START UTC Clock Settings --- */
// See http://dev.wikia.com/wiki/DisplayClock for info
// "21 Oct 18:24 UTC"
window.DisplayClockJS = '%d %b %H:%2M UTC';
/* --- END UTC Clock Settings --- */

/* --- START AjaxRC Settings --- */
// See http://dev.wikia.com/wiki/AjaxRC for info
// Apply Ajax refresh to these pages
window.ajaxPages = ["Special:RecentChanges","Special:Log","Special:Contributions"];
//Refresh rate in milliseconds (60000 = 60 seconds); default 60000
window.ajaxRefresh = 15000;
/* --- END AjaxRC Settings --- */

/* --- START LastEdited Settings --- */
// See http://dev.wikia.com/wiki/LastEdited for info
window.lastEdited = {
    avatar: true, //Display editor's user avatar? boolean:<true|false>
    size: false, //Display current page size in bytes? boolean:<true|false>
    diff: true, //Show diff modal? boolean:<true|false>
    comment: true, //Display given edit summary? boolean:<true|false>
    time: 'timeago', //Time format. <timestamp|timeago>
    lang: 'en', //Any valid language code
    namespaces: {
        include: [],//List of namespaces to include
        exclude: []//List of namespace ids to exclude
    },
    pages: []//List of pages to exclude
};
/* --- END LastEdited Settings --- */

/* --- START Sine Settings --- */
Sine = {
    sine: '~~~',
    spacer: ''
};
/* --- END Sine Settings --- */

/* --- START Sine Custom Code --- */
/** 
 * Sine (this version has been modified)
 * documentation at: http://dev.wikia.com/wiki/Sine
 * © Peter Coester, 2012
*/
 
$(function () {
 
    window.Sine = function (my) {
 
        if ('edit' != $.getUrlVar('action')) return {};
 
        if ('undefined' == typeof my.sine)   my.sine   = '~~' + String.fromCharCode(126) + '~';
        if ('undefined' == typeof my.spacer) my.spacer = '--';
        if ('undefined' == typeof my.talkNameSpaces) {
            my.talkNameSpaces = [1,3,5,7,9,11,13,15,110,111,114,116,401,500,501,502,503];
        }
 
        if ('undefined' != typeof my.init) return my;
 
        var doSine = -1 != my.talkNameSpaces.indexOf(parseInt(wgNamespaceNumber));
 
        var placeSine = $('#EditPageRail .wpSummaryFields .checkboxes');
        placeSine.prepend('<label class="Sine"><input type="checkbox" name="Sine" id="Sine"> <span>Sine</span></label>');
        var sineCheckbox = $('#Sine');
 
        sineCheckbox
        .attr('checked', doSine)
 
        var blocks, editor;
 
        my.add = function () {
            if (!sineCheckbox.is(':checked')) return;
            switch (editor.mode) {
                case 'wysiwyg':
                    sineWYSIWYG();
                    break;
                case 'source':
                    sineSource();
                    break;
            }
        };
 
        my.init = function () {
            editor = getEditor();
            if (!editor) {
                window.setTimeout(
                    function () {
                        window.Sine.init();
                    }, 100
                );
                return;
            }
            $('input#wpSave').click(window.Sine.add);
            $('a#publish').click(window.Sine.add);
        };
 
        function getEditor () {
            if ('undefined' != typeof window.editorInstance) {
                return window.editorInstance;
            }
            if ('undefined' != typeof window.WikiaEditor && 'function' == typeof window.WikiaEditor.getInstance) {
                return window.WikiaEditor.getInstance();
            }
            return false;
        }
 
        function sineWYSIWYG () {
            var wysiwyg = editor.getEditbox();
            if (isSined(wysiwyg)) return;
            blocks = wysiwyg.find('> *');
            if (!blocks.length) return;
            var b = blocks.last();
            var inserted = false;
            if (b.is('p,dl')) {
                inserted = insertSine(b);
            }
            if (!inserted) {
                wysiwyg.append(createSine());
            }
        }
 
        function createSine () {
            var s, left, depth, type = getIndentType();
            switch (type) {
                case 'p':
                    left = getIndent('p');
                    s = $('<p>' + basicSine() +  '</p>');
                    if (left) s = s.css({ marginLeft: left });
                break;
                case 'dl':
                    depth = getIndent('dl');
                    s = basicSine();
                    for (var i = 0; i < depth; i++) {
                        s = '<dl><dd>' + s + '</dd></dl>';
                    }
                break;
            }
            return s;
        }
 
        function getIndentType () {
            for (var i = blocks.length - 1; i >= 0 ; i--) {
                var b = $(blocks[i]);
                if (b.is('p'))  return 'p';
                if (b.is('dl')) return 'dl';
            }
            return 'p';
        }
 
        function getIndent (type) {
            var b, left, depth;
            for (var i = blocks.length - 1; i >= 0 ; i--) {
                b = $(blocks[i]);
                if (b.is('p')) {
                    left = b.css('marginLeft');
                    return 'p' == type ? left : parseInt(left) / 20;
                }
                else if (b.is('dl')) {
                    depth = 0;
                    while (b.parents('dl').length) b = b.parents('dl');
                    b.find('dl').each( function(){
                        var d = $(this).parents('dl').length + 1;
                        if (d > depth) depth = d;
                    });
                    return 'dl' == type ? depth : (depth * 20).toString() + 'px';
                }
            }
            return 0;
        }
 
        function basicSine () {
            return my.sine;
        }
 
        function isSined (element) {
            return basicSine() == element.text().trim().substr(-basicSine().length);
        }
 
        function spacedSine () {
            return (my.spacer.length ? ' ' + my.spacer + ' ' : ' ') + basicSine();
        }
 
        function isInline (element) {
            return 'inline' == element.css('display') && !element.is('img[class*="placeholder"]');
        }
 
        function insertSine (block) {
            var b = block;
            if (block.is('dl')) {
                b = block.find('dd:last');
                b = b.parent().children().last();
                if (!b.is('dd,p')) return false;
            }
            var contents = $.makeArray(b.contents());
            if (!contents.length) {
                b.append(basicSine());
                return true;
            }
            var c = $(contents.pop());
            if ('#text' == c[0].nodeName) {
                c.after(spacedSine());
                return true;
            }
            else if (c.is('br')) {
                var s = basicSine();
                if (contents.length) {
                    var prev = $(contents.pop());
                    if ('#text' != prev[0].nodeName && !isInline(prev)) return false;
                    s = spacedSine();
                }
                c.before(s);
                return true;
            }
            else if (isInline(c)) {
                c.after(spacedSine());
                return true;
            }
            return false;
        }
 
        function isList (line) {
            return /^\:*[*#]/.test(line);
        }
 
        function isHeader (line) {
            return /^(={2,6})[^=]+\1$/.test(line);
        }
 
        function isBlock (line) {
            return /(?:----|\}\}|<\/(?:blockquote|div|pre|code|nowiki)>)$/.test(line);
        }
 
        function sineSource () {
            var source = editor.getContent();
            if (!source.trim().length) return;
            var lines = source.split(/\r\n|\r|\n/).reverse();
            var l = lines[0].trim();
            var s = basicSine();
            if (l.length) {
                if (basicSine() == l.substr(-4)) return;
                if (isList(l) || isHeader(l) || isBlock(l)) {
                    s = "\r\n" + emptySine(lines);
                } else {
                    s = spacedSine();
                }
            } else {
                s = emptySine(lines);
                if (!s) return;
            }
            editor.setContent(source + s);
        }
 
        function emptySine (lines) {
           var s = basicSine();
           for (var i = 1; i < Math.min(4, lines.length); i++) {
                var l = lines[i].trim();
                if (!l.length) continue;
                if (basicSine() == l.substr(-4)) return false;
                var m = l.match(/^(\:+)/);
                if (m) s = m[1] + s;
                break;
            }
            return s;
        }
 
        return my;
 
    }('undefined' == typeof window.Sine ? {} : window.Sine);
 
    if ('undefined' != window.Sine && 'function' == typeof window.Sine.init) {
        window.Sine.init();
    }
});
/* --- END Sine Custom Code --- */


/* --- START Standard Edit Summary Settings --- */
//No longer used; disable settings too
// window.dev = window.dev || {};
// window.dev.editSummaries = {
//     select: [
//         'Standard edit summaries',
//         'Refactoring━━━━━━━━━━━━━', [
//             'Cleanup',
//             'Corrected spelling/grammar',
//             'Factual correction',
//             'Formatting',
//             'Source tidying',
//             'Wikifying',
//             'Corrected template usage'
//          ],
//         'Content━━━━━━━━━━━━━━━', [
//             'Updated with new information',
//             'Expanded',
//             'Revised',
//             'Added sources',
//             'Neutral POV',
//             'Replaced duplicate image(s)'
//          ],
//         'Templates━━━━━━━━━━━━━━', [
//             'Added template(s)',
//             'Added {{Delete}}',
//             'Added {{Stub}}',
//             'Added infobox'
//          ],
//         'Categories━━━━━━━━━━━━━━', [
//             'Added category',
//             'Modified category',
//             'Organized categories'
//          ],
//         'Removal/Reversion━━━━━━━━━━', [
//             'Reverted vandalism',
//             'Reverted test edit',
//             'Reverted vanity edit',
//             'Removed fanon',
//             'Removed libel/slander',
//             'Removed © violation'
//          ]
//     ]
// };
/* --- END Standard Edit Summary Settings --- */


/* ########################################################################## */
/* Import Scripts */
/* ########################################################################## */
importArticles({
    type: 'script',
    articles: [
        'u:dev:Wikimarks/code.js', //Wikimarks menu
        'u:dev:DisplayClock/code.js', //Show UTC clock
        'u:dev:RevealAnonIP/usercode.js', //http://dev.wikia.com/wiki/RevealAnonIP
        'u:dev:AjaxRC/code.js', //Special:RecentChanges live update
        'u:dev:LastEdited/code.js', //add who last edited to pages
        'u:dev:NullEditButton/code.js', //adds a "Null Edit" option to page controls
        'u:dev:MediaWiki:AjaxDiff/code.js', //diff without leaving RC
        'u:dev:SignatureCheck/code.js' //check if talk post was signed
        //'u:dev:SkinSwitchButton/code.js', //adds buttons to change skin
            //↳Not used often enogh to justify extra overhead :P
        //'u:dev:Standard_Edit_Summary/code.js', //offer edit summaries
            //↳Hasn't been useful to me
        //'u:dev:MediaWiki:Rollback/code.js', //always show rollback, even if not a rollbacker
            //↳don't like it :P
        //'u:dev:QuickToolsv2/code.js', //adds quick tools to pages
            //↳Not used very often; Wikimarks handles a lot of this anyway
        //'u:kocka:MediaWiki:Emoticons.js', //adds list of emotes to chat
            //↳meh; imported from user's test wiki (too risky IMHO :P)
        //'u:dev:InactiveUsers/code.js', //show inactive users
            //↳doesn't work? meh anyway :P
        //'u:dev:HighlightUsers/code.js', //http://dev.wikia.com/wiki/HighlightUsers
            //↳Wikia is slower when this is used
        //'u:dev:MarkForDeletion/code.js', //Quickly insert 'delete' template
            //↳Not used very often
    //CODE COPIED HERE; DON'T IMPORT ORIGINAL
        //'u:dev:Sine/code.js', //always sign talk page posts
            //↳temporarily disabled while modified code is here (above)
    //UNECESSARY
        //'u:dev:PortableCSSPad/code.js', //Add CSS injector to toolbar
            //↳Not necessary with modern browser debug/developer tools
        //'u:dev:PurgeButton/code.js', //purge button
            //↳Click UTC clock OR use Wikimarks item instead
        //'u:dev:Translator/Translator.js', //Translator button
            //↳doesn't seem to do anything
        //'u:dev:ShowAdsButton/code.js', //Button to toggle ads on and off while logged in
            //↳doesn't seem to do anything
        //'u:dev:SkinSwitchButton/code.js', //Buttons to easily change wiki skin
            //↳can change with WikiMarks
    //OLD; DON'T USE
        //'u:wikimarks:Client.js', //Wikimarks menu; moved to u:dev:Wikimarks/code.js
        //'u:railgunscript:MediaWiki:RailgunClient.min.js', //http://railgunscript.wikia.com/wiki/Railgun_Wiki
    ]
});
/* ####################### END of User:Iynque/global.js ##################### */
console.info("Loaded User:Iynque/global.js version 46.3");
// </syntaxhighlight>