User:PerfektesChaos/js/pageLinkHelper/d.js: Difference between revisions

Content deleted Content added
-1.2
-1.3
Line 1:
/// Gadget-pageLinkHelper.js
// MinorSome minor link helpers
// ResourceLoader: compatible; dependencies: user, mediawiki.util
/// 2014-12-0711 PerfektesChaos@de.wikipedia
/// Fingerprint: #0#0#
/// <nowiki>
/*jshint bitwise:true, curly:true, eqeqeq:true, forinlatedef:falsetrue,
latedeflaxbreak:true, laxbreakstrict:true, stricttrailing:true, trailingundef:true,
undef:true, unused:true, white:false */
/*global window:false */
( function ( mw, $ ) {
"use strict";
var VERSIONVersion = -1.23,
Sign = "pageLinkHelper",
Signature = "ext.gadget." + Sign,
Env, PLH;
 
 
 
function $factory( access ) {
// Create <div> for upper right corner
// Precondition:
// access -- distinguishing selector ID
// Uses:
// > Sign
// 2014-12-11 PerfektesChaos@de.wikipedia
var space = "4px",
style = "#808080 1px solid",
$r = $( "<div>" );
$r.attr( { "class": Sign,
"id": access } );
style = "#808080 1px solid";
$r.css( { "border-bottom": style,
"border-left": style,
"float": "right",
"font-family": "monospace",
"margin-bottom": "1em",
"margin-left": "1em",
"margin-top": space,
"padding-bottom": space,
"padding-left": space } );
return $r;
} // $factory()
 
 
 
function $float( $apply ) {
// Insert upper right corner element
// Precondition:
// $apply -- jQuery element to insert
// false to vheck availability
// Postcondition:
// Returns true, if insertion possible
// Uses:
// > Sign
// >< Env
// 2014-12-11 PerfektesChaos@de.wikipedia
var r, // = undefined
$div;
if ( typeof Env.$anchor === "undefined" ) {
Env.$anchor = $( "#firstHeading" );
}
if ( Env.$anchor.length ) {
r = true;
if ( $apply ) {
$div = $( "." + Sign );
$div.remove();
$div = $( "<div>" );
$div.css( { "clear": "left" } );
Env.$anchor.after( $div );
Env.$anchor.after( $apply );
}
}
return r;
} // $float()
 
 
Line 24 ⟶ 85:
// Returns value, or undefined
// Uses:
// > VERSIONmw.libs
// > Sign
// > Version
// >< PLH
// 2014-12-0711 PerfektesChaos@de.wikipedia
var r; // = undefined
if ( typeof mw.libs.pageLinkHelper[ Sign ] === "object" ) {
PLH = mw.libs.pageLinkHelper[ Sign ];
if ( PLH ) {
PLH.vsn = VERSIONVersion;
if ( typeof PLH[ applied ] !== "undefined" ) {
r = PLH[ applied ];
Line 48 ⟶ 111:
// mediawiki.util loaded
// Uses:
// > Sign
// > Env
// > ___location
// mw.util.getParamValue()
// mw.config.get()
// 2014-12-06 PerfektesChaos@de.wikipedia $float()
var// sign = "pageLinkHelperDifflink", $factory()
// 2014-12-11 PerfektesChaos@de.wikipedia
var sign = Sign + "Difflink",
$div = $( "#" + sign ),
got, i, id1, id2, j, re, show, $container, $span;
if ( ! $div.length && $float() ) {
$containerif = $( "#contentSub"Env.wgCanonicalSpecialPageName ); {
if ( $container.length )// {2014 redirected to &diff=
re = /\/wiki\/[^:]+:[^\/]+\/(\d+)(?:\/(\.+))?$/;
if ( Env.wgCanonicalSpecialPageName ) {
got = re.exec( //window.___location.pathname 2014 redirected to &diff=);
if ( got re) = /\/wiki\/[^:]+:[^\/]+\/(\d+)(?:\/(\.+))?$/;{
gotid1 = re.exec(got[ window.___location.pathname1 )];
ifid2 (= got[ )2 {];
id1 = got[ 1 ];
id2 = got[ 2 ];
}
} else {
id1 = mw.util.getParamValue( "diff" );
id2 = mw.util.getParamValue( "oldid" );
}
} if ( id1 )else {
iid1 = parseInt( id1, 10 )Env.diff;
if ( id2 )= {Env.oldid;
}
if ( isNaN( i )id1 ) {
i = parseInt( id1, 10 i = id1);
if ( id2 ) id1 = id2;{
if ( isNaN( i ) ) id2 = i;{
}i else { = id1;
jid1 = parseInt( id2, 10 );
id2 = if ( ! isNaN( j ) ) {i;
} if ( i > j )else {
j = parseInt( id2, =10 i);
if ( ! isNaN( j ) ) id1 = j;{
if ( i }> j ) {
id2 = i;
id1 = j;
}
}
if ( id2 === "prev" ) {
id2 = false;
}
} else if ( isNaN( i ) ) {
id1 = false;
}
if ( id2 === "prev" ) {
id2 = false;
}
} else if ( isNaN( i ) ) {
id1 = false;
}
}
if ( id1 ) {
show = "[["
+ mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
+ ":Diff/" + id1
+ ( id2 ? "/" + id2 : "" )
+ "]]";
$span = $( "<codespan>" );
$span.text( show );
$div = $factory( sign );
$div.append( $span );
$float( $div );
}
}
} // flip()
 
 
 
function freeze() {
// Equip page with wikilink to perma for c&p
// Precondition:
// DOM.ready
// mediawiki.util loaded
// Uses:
// > Sign
// >< Env
// mw.config.get()
// $float()
// $factory()
// mw.util.wikiUrlencode()
// mw.util.getUrl()
// 2014-12-11 PerfektesChaos@de.wikipedia
var sign = Sign + "Permalink",
$div = $( "#" + sign ),
show, special, swift, $a, $br, $spanBeg, $spanEnd;
if ( ! $div.length && $float() ) {
Env.wgPageName = mw.config.get( "wgPageName" );
if ( Env.curid ) {
Env.curid = parseInt( Env.curid, 10 );
} else {
Env.curid = mw.config.get( "wgArticleId" );
}
if ( Env.oldid ) {
Env.oldid = parseInt( Env.oldid, 10 );
} else {
Env.oldid = mw.config.get( "wgCurRevisionId" );
}
$div = $factory( sign );
special = mw.config.get( "wgFormattedNamespaces" )[ "-1" ]
+ ":Redirect/";
swift = "?title="
+ mw.util.wikiUrlencode( Env.wgPageName );
$spanBeg = $( "<span>" );
$spanBeg.text( "[[" );
$spanEnd = $( "<span>" );
$spanEnd.text( "]]" );
$a = $( "<a>" );
if ( Env.oldid ) {
$div.append( $spanBeg.clone() );
show = special + "revision/" + Env.oldid;
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
$div.append( $a );
$div.append( $spanEnd.clone() );
$br = $( "<br />" );
$div.append( $br );
$a = $( "<a>" );
}
$div.append( $spanBeg );
show = special + "page/" + Env.curid;
$a.attr( { "href": mw.util.getUrl( show ) + swift } );
$a.text( show );
$div.append( $a );
$div.append( $spanEnd );
$float( $div );
freezer( false );
}
} // freeze()
 
 
 
function freezer( assign ) {
// Change portlet for permalink
// Precondition:
// assign -- true if link to be diverted, false to gray out
// DOM.ready
// Uses:
// > Sign
// > Version
// (freeze)
// 2014-12-11 PerfektesChaos@de.wikipedia
var $portlet = $( "#t-permalink" ),
show, support, $a, $span;
if ( $portlet.length ) {
support = Sign + " " + Version;
if ( assign ) {
$a = $( "<a>" );
$a.attr( { "title": support } );
$a.click( freeze );
$a.text( "PermaLink" );
$portlet.empty();
$portlet.append( $a );
} else {
$a = $portlet.find( "a" );
show = $a.text();
if ( show ) {
$span = $( "<span>" );
$span.css( { "color": "#808080" } );
$span.text( show );
$div = $span.attr( { "<div>title": support } );
$divportlet.attrempty( { "id": sign } );
$divportlet.cssappend( {$span "float": "right",);
"margin-top" : "1em" } );
$div.append( $span );
$container.append( $div );
}
}
}
} // flipfreezer()
 
 
Line 206 ⟶ 366:
// > ___location
// > document
// > Sign
// >< Env
// mw.util.getUrl()
Line 228 ⟶ 389:
legacy = opts.legacy;
}
caused = { caused: "pageLinkHelper" };
showed = window.document.title;
caused = { caused: Sign };
if ( legacy ) {
state = mw.util.getUrl( Env.wgRedirectedFrom );
Line 253 ⟶ 414:
// mw.util.getParamValue()
// flip()
// freeze()
// freezer()
// fresh()
// from()
// 2014-12-0511 PerfektesChaos@de.wikipedia
Env = mw.config.get( [ "wgAction",
"wgCanonicalSpecialPageName",
"wgRedirectedFrom" ] );
ifEnv.diff ( = mw.util.getParamValue( "diff" ) ||;
Env.oldid = mw.util.getParamValue( "oldid" );
if ( Env.diff ||
Env.wgCanonicalSpecialPageName === "Diff" ) {
flip();
freezer( true );
} else if ( ! Env.wgCanonicalSpecialPageName
} else {
if && ( Env.wgAction === "view" ) {
fresh Env.curid = mw.util.getParamValue( "curid" );
if ( Env.wgRedirectedFromcurid || Env.oldid ) {
from freeze( true );
} else {
freezer( true );
}
fresh();
if ( Env.wgRedirectedFrom ) {
from();
}
} else {
freezer( true );
}
}
Line 273 ⟶ 448:
 
 
if ( mw.loader.stategetState( "ext.gadget.pageLinkHelper"Signature ) !== "ready" ) {
mw.loader.state( "ext.gadget.pageLinkHelper"Signature, "ready" );
mw.loader.using( [ "mediawiki.util",
"user" ],