User:Zabshk/heading-icons.js: Difference between revisions

From TestWiki
Content added Content deleted
(My js will be here.)
 
m (Zabshk moved page User:Zabshk/vector.js to User:Zabshk/heading-icons.js without leaving a redirect: Move to script page)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
window.headingIconGadget = {
version: 3,
enabled: true,
firstHeading: null,
managedElements: [],
sortWeights: {
editsection: 1,
padlock: 2,
// other = 5
coordinates: 10,
shortcut_upper: 11
}
};
/* Translatable strings */
mw.messages.set( {
'msg-semi-protection': 'Only autoconfirmed users can edit this page (semi protection).',
'msg-full-protection': 'Only administrators users can edit this page (full protection).',
'msg-other-protection': 'This page is protected on non-standard protection level.',
} );
headingIconGadget.append = function( element ) {
if ( !this.firstHeading ) {
return;
}
var sortKey = 5;
if ( this.sortWeights[element.id] ) {
sortKey = this.sortWeights[element.id]
} else if ( this.sortWeights[element.className] ) {
sortKey = this.sortWeights[element.className];
}
this.managedElements.push( {
'element': element,
'sortKey': sortKey
} );
this.firstHeading.insertBefore( element, this.firstHeading.firstChild );
}
headingIconGadget.grab = function() {
var that = this;
jQuery( "span.put-in-header" ).add( "div.put-in-header" ).each( function() {
this.style.cssText = 'position:static; display:inline-block; float:right; padding:3px 5px; font-size:50%;';
that.append( this );
} );
}
// correction in 0-section edit link
headingIconGadget.fix0SectionEdit = function() {
if ( this.managedElements.length == 0 ) {
return;
}
var secEdit = jQuery( 'div.editsection' );
if ( secEdit.length ) {
secEdit[0].style.cssText = 'padding:.7em 0 0 1.0em; float:right; font-size:50%;';
this.append( secEdit[0] );
}
}
/**
* Shows padlock in the right corner
* when page is protected
*/
headingIconGadget.padlockIcon = function() {
// no padlock on main page
if ( mw.config.get( 'wgTitle' ) == mw.config.get( 'wgMainPageTitle' ) ) {
return;
}
// no protection?
var wgRestrictionEdit = mw.config.get( 'wgRestrictionEdit' );
if ( wgRestrictionEdit == null || wgRestrictionEdit.length < 1 || wgRestrictionEdit[0] == "" ) {
return;
}
// print?
if ( mw.util.getParamValue( 'printable' ) == 'yes' ) {
return;
}
var img = document.createElement( 'img' );
if ( wgRestrictionEdit[0] == "autoconfirmed" ) {
img.src = "//upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Padlock-green.svg/22px-Padlock-green.svg.png";
img.title = mw.msg( 'msg-semi-protection' );
} else if ( wgRestrictionEdit[0] == "sysop" ) {
img.src = "//upload.wikimedia.org/wikipedia/commons/thumb/4/48/Padlock-red.svg/22px-Padlock-red.svg.png";
img.title = mw.msg( 'msg-full-protection' );
} else {
img.src = "//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Padlock-gold.svg/22px-Padlock-gold.svg.png";
img.title = mw.msg( 'msg-other-protection' );
}
img.alt = "padlock";
var link = document.createElement( 'a' );
link.id = "padlock";
link.href = mw.util.getUrl( "Wikipedia:Strona zabezpieczona" );
link.style.cssText = 'position:static; display:inline-block; float:right; padding:3px 5px; font-size:50%;';
link.appendChild( img );
this.append( link );
}
headingIconGadget.sortElements = function() {
if ( this.managedElements.length < 2 ) {
return;
}
// sort array
this.managedElements.sort( function( a, b ) {
return a.sortKey - b.sortKey;
} );
// sort elements
for ( var i = this.managedElements.length - 1; i >= 0; i-- ) {
this.firstHeading.insertBefore( this.managedElements[i].element, this.firstHeading.firstChild );
}
}
headingIconGadget.init = function() {
this.firstHeading = document.getElementById( 'firstHeading' );
if ( !this.firstHeading ) {
return;
}
headingIconGadget.grab();
headingIconGadget.padlockIcon();
headingIconGadget.fix0SectionEdit();
headingIconGadget.sortElements();
}

$( window ).on( 'load', function() {
if ( typeof( wikiminiatlas ) == 'object' && typeof( wikiminiatlas.loader ) == 'function' && document.getElementById( 'coordinates' ) && document.getElementById( 'coordinates' ).getElementsByTagName( 'img' ).length < 1 ) {
wikiminiatlas.oldhookUpMapbutton = wikiminiatlas.hookUpMapbutton;
wikiminiatlas.hookUpMapbutton = function( mb ) {
mb.onload = headingIconGadget.init;
wikiminiatlas.oldhookUpMapbutton( mb );
}
} else {
headingIconGadget.init();
}
} );

Latest revision as of 19:57, 7 April 2017

window.headingIconGadget = {
        version: 3,
        enabled: true,
        firstHeading: null,
        managedElements: [],
        sortWeights: {
                editsection: 1,
                padlock: 2,
                // other = 5
                coordinates: 10,
                shortcut_upper: 11
        }
};
 
/* Translatable strings */
mw.messages.set( {
        'msg-semi-protection': 'Only autoconfirmed users can edit this page (semi protection).',
        'msg-full-protection': 'Only administrators users can edit this page (full protection).',
        'msg-other-protection': 'This page is protected on non-standard protection level.',
} );
 
 
headingIconGadget.append = function( element ) {
        if ( !this.firstHeading ) {
                return;
        }
 
        var sortKey = 5;
        if ( this.sortWeights[element.id] ) {
                sortKey = this.sortWeights[element.id]
        } else if ( this.sortWeights[element.className] ) {
                sortKey = this.sortWeights[element.className];
        }
 
        this.managedElements.push( {
                'element': element,
                'sortKey': sortKey
        } );
 
        this.firstHeading.insertBefore( element, this.firstHeading.firstChild );
}
 
headingIconGadget.grab = function() {
        var that = this;
 
        jQuery( "span.put-in-header" ).add( "div.put-in-header" ).each( function() {
                this.style.cssText = 'position:static; display:inline-block; float:right; padding:3px 5px; font-size:50%;';
                that.append( this );
        } );
}
 
// correction in 0-section edit link
headingIconGadget.fix0SectionEdit = function() {
        if ( this.managedElements.length == 0 ) {
                return;
        }
 
        var secEdit = jQuery( 'div.editsection' );
        if ( secEdit.length ) {
                secEdit[0].style.cssText = 'padding:.7em 0 0 1.0em; float:right; font-size:50%;';
                this.append( secEdit[0] );
        }
}
 
/**
 * Shows padlock in the right corner
 * when page is protected
 */
headingIconGadget.padlockIcon = function() {
        // no padlock on main page
        if ( mw.config.get( 'wgTitle' ) == mw.config.get( 'wgMainPageTitle' ) ) {
                return;
        }
 
        // no protection?
        var wgRestrictionEdit = mw.config.get( 'wgRestrictionEdit' );
        if ( wgRestrictionEdit == null || wgRestrictionEdit.length < 1 || wgRestrictionEdit[0] == "" ) {
                return;
        }
 
        // print?
        if ( mw.util.getParamValue( 'printable' ) == 'yes' ) {
                return;
        }
 
        var img = document.createElement( 'img' );
        if ( wgRestrictionEdit[0] == "autoconfirmed" ) {
                img.src = "//upload.wikimedia.org/wikipedia/commons/thumb/8/8a/Padlock-green.svg/22px-Padlock-green.svg.png";
                img.title = mw.msg( 'msg-semi-protection' );
        } else if ( wgRestrictionEdit[0] == "sysop" ) {
                img.src = "//upload.wikimedia.org/wikipedia/commons/thumb/4/48/Padlock-red.svg/22px-Padlock-red.svg.png";
                img.title = mw.msg( 'msg-full-protection' );
        } else  {
        	img.src = "//upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Padlock-gold.svg/22px-Padlock-gold.svg.png";
            img.title = mw.msg( 'msg-other-protection' );
        }
        img.alt = "padlock";
 
        var link = document.createElement( 'a' );
        link.id = "padlock";
        link.href = mw.util.getUrl( "Wikipedia:Strona zabezpieczona" );
        link.style.cssText = 'position:static; display:inline-block; float:right; padding:3px 5px; font-size:50%;';
        link.appendChild( img );
 
        this.append( link );
}
 
headingIconGadget.sortElements = function() {
        if ( this.managedElements.length < 2 ) {
                return;
        }
 
        // sort array
        this.managedElements.sort( function( a, b ) {
                return a.sortKey - b.sortKey;
        } );
 
        // sort elements
        for ( var i = this.managedElements.length - 1; i >= 0; i-- ) {
                this.firstHeading.insertBefore( this.managedElements[i].element, this.firstHeading.firstChild );
        }
}
 
headingIconGadget.init = function() {
        this.firstHeading = document.getElementById( 'firstHeading' );
 
        if ( !this.firstHeading ) {
                return;
        }
 
        headingIconGadget.grab();
        headingIconGadget.padlockIcon();
        headingIconGadget.fix0SectionEdit();
        headingIconGadget.sortElements();
}

$( window ).on( 'load', function() {
        if ( typeof( wikiminiatlas ) == 'object' && typeof( wikiminiatlas.loader ) == 'function' && document.getElementById( 'coordinates' ) && document.getElementById( 'coordinates' ).getElementsByTagName( 'img' ).length < 1 ) {
                wikiminiatlas.oldhookUpMapbutton = wikiminiatlas.hookUpMapbutton;
                wikiminiatlas.hookUpMapbutton = function( mb ) {
                        mb.onload = headingIconGadget.init;
                        wikiminiatlas.oldhookUpMapbutton( mb );
                }
        } else {
                headingIconGadget.init();
        }
} );