User:PerfektesChaos/js/externalLinkProblem/category/d.js

/// User:PerfektesChaos/js/externalLinkProblem/category/d.js /// 2018-08-24 PerfektesChaos@de.wikipedia // Sub-module: Handle category // ResourceLoader: compatible; //                 dependencies: No MW /// Fingerprint: #0#0# /// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA) /// /* global window:false                                                */ /* jshint forin:false, bitwise:true, curly:true, eqeqeq:true, latedef:true, laxbreak:true, nocomma:true, strict:true, undef:true, unused:true          */

( function ( mw, $ ) {  "use strict";   var Version    =  -2.8,       ELP        =  "externalLinkProblem",       Sub        =  "category",       Section    =  "#deadurl_",       SubjectPg  =  "SubjectPg";   if ( typeof mw.libs[ ELP ]  !==  "object"   ||   ! mw.libs[ ELP ] ) {     mw.libs[ ELP ]  =  { };   }   mw.libs[ ELP ].type  =  ELP;   ELP                  =  mw.libs[ ELP ];

/*   * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as   * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. *   * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. *   * You should have received a copy of the GNU General Public License * along with this program; * if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html */

if ( typeof ELP[ Sub ] !==  "object" ) { ELP[ Sub ] =  { }; }  ELP[ Sub ].vsn  =  Version;

function facilitated { // Mark sub-module as ready // Uses: //   >  .signature //   >  Sub //   >  .type //   mw.loader.getState //   mw.loader.state //   mw.hook // 2018-08-24 PerfektesChaos@de.wikipedia var rls, signature, sub; if ( typeof ELP.signature ===  "string" ) { sub       =  "/" + Sub; signature =  ELP.signature + sub; if ( mw.loader.getState( signature ) !==  "ready" ) { rls = { }; rls[ signature ] = "ready"; mw.loader.state( rls ); mw.hook( ELP.type + sub + ".ready" ).fire; }     }   }   // facilitated

function $factory( area, article ) { // Create subject page access // Precondition: //   area     -- namespace number //   article  -- false: initialise,  string: encoded title // Postcondition: //   Returns jQuery element // Uses: //   >  .category.rooms //   >  .config.loose //   >  SubjectPg //   >  .type //   >  Sub //   >< .category.$element // 2016-04-25 PerfektesChaos@de.wikipedia var s, $r; if ( article ) { $r =  ELP[ Sub ].$element.clone; if ( area ) { s =  ELP[ Sub ].rooms[ area ]; if ( s ) { s =  s + ":"; } else { s =  ""; }        } else { s =  ""; }        s  =  "/wiki/" + s + article; $r.attr( "href", s ); } else { if ( ELP.config.loose ) { s =  "_blank"; } else { s =  SubjectPg; }        $r  =  $( "" ); $r.attr( { "class": ELP.type + "-article-view",                    "href":   "#",                    "target": s } ); $r.css( { "background-color": "#F0F0F0",                  "border-color":       "#E0E0E0"                                       + " #E0E0E0"                                       + " #707070"                                       + " #707070",                   "border-style":     "solid",                   "border-width":     "2px",                   "display":          "inline-block",                   "font-size":        "90%",                   "margin-left":      "3em",                   "padding-bottom":   "0",                   "padding-left":     "0.2em",                   "padding-right":    "0.2em",                   "text-decoration":  "none" } ); $r.text( "*" ); ELP[ Sub ].$element =  $r; }     return $r; }  // $factory

function facet( $aim ) { // Equip  with subject page link // Precondition: //   $aim  -- li element // Uses: //   >  Sub //   >  .category.stamp //   >  .category.show //   >  .category.wgNamespaceIds //   mw.util.getUrl //   mw.Title.newFromText // 2015-11-24 PerfektesChaos@de.wikipedia var $a  =  $aim.children( "a" ), s   =  $a.attr( "href" ), got =  /\/wiki\/([^:]+):(.+)$/.exec( s ), ns, space; if ( got ) { if ( ELP[ Sub ].stamp &&  s.indexOf( "#" ) < 0 ) { s =  s + ELP[ Sub ].stamp; $a.attr( "href", s ); }        $a.attr( "target", ELP[ Sub ].show ); space =  got[ 1 ].toLowerCase; s     =  got[ 2 ]; ns    =  ELP[ Sub ].wgNamespaceIds[ space ]; if ( ns ) { ns =  --ns; if ( ns % 2 === 0 ) { $aim.append( $factory( ns, s ) ); }        }      }   }   // facet

function fiat { // Equip talk entry category page // Precondition: //   DOM ready, all resources available // Uses: //   >  Sub //   >  Section //   >  .project.template //   >  .config.loose //    < .category.rooms //    < .category.wgNamespaceIds //    < .category.stamp //    < .category.show //   $factory //   facet // 2015-11-25 PerfektesChaos@de.wikipedia var $pages =  $( "#mw-pages" ), n      =  $pages.length, env, i, j, k, s, $group, $groups, $h3, $list; $( ".cn-fundraiser-banner, #fundraising" ).remove; if ( n ) { $groups =  $pages.find( ".mw-category-group" ); n       =  $groups.length; if ( ! n ) { $groups =  $pages; n       =  1; }     }      if ( n ) { j   =  0; env =  mw.config.get( [ "wgFormattedNamespaces",                                  "wgNamespaceIds" ] ); ELP[ Sub ].rooms =  { }; for ( s in env.wgFormattedNamespaces ) { k =  parseInt( s, 10 ); if ( k > 0  &&   k % 2  ===  0 ) { ELP[ Sub ].rooms[ k ] =  env.wgFormattedNamespaces[ s ] .replace( /\s/, "_" ); }        }   // for s in env.wgFormattedNamespace ELP[ Sub ].wgNamespaceIds =  env.wgNamespaceIds; if ( typeof ELP.project.template ===  "object"              &&     ELP.project.template    &&              typeof ELP.project.template.stamp  ===  "string"              &&     ELP.project.template.stamp ) { ELP[ Sub ].stamp =  Section + ELP.project.template.stamp; } else { ELP[ Sub ].stamp =  false; }        if ( ELP.config.loose ) { ELP[ Sub ].show =  "_blank"; } else { ELP[ Sub ].show =  "talkELdead"; }        $factory; $h3 =  $groups.eq( 0 ).find( "h3" ).eq( 0 ); if ( $h3.length ) { $h3 =  $h3.eq( 0 ); if ( ! $h3.text ) { j =  1; }        }         for ( i = j;  i < $groups.length;  i++ ) { $group =  $groups.eq( i ); $list  =  $group.find( "li" ); for ( k = 0; k < $list.length;  k++ ) { facet( $list.eq( k ) ); }  // for k         }   // for i      } }  // fiat

ELP[ Sub ].fire =  function  { // Start action on category page // Uses: //   >  Sub //   >  .config //   >< .request //   facilitated //   (fiat) // Remark: May be used as event handler -- 'this' is not accessed // 2015-11-23 PerfektesChaos@de.wikipedia facilitated; if ( typeof ELP.request ===  "string"   &&           ELP.request === Sub   &&           typeof ELP.config  ===  "object"           &&     ELP.config ) { ELP.request =  false; $( fiat ); }  };   // .category.fire

function first { // Initialize sub-module // Uses: //   >  Sub //   facilitated //   .featuring //   (.category.fire) // 2015-10-22 PerfektesChaos@de.wikipedia facilitated; if ( typeof ELP.featuring ===  "function" ) { ELP.featuring( ELP[ Sub ].fire ); }  }   // first first;  // autorun }( window.mediaWiki, window.jQuery ) );

// Emacs // Local Variables: // fill-column: 80 // End:

/// EOF  externalLinkProblem/category/d.js