User:PerfektesChaos/js/paneMarker/d.js

/// mw:User:PerfektesChaos/js/paneMarker/d.js /// 2012-08-20 PerfektesChaos@de.wikipedia // Mark browser panes (tabbed or window) if particular action taken. // Try to exchange wiki-favicon for a red one if editing a wiki page. // Insert indicating character before document title. // User defined changes of page title and favicon. // ResourceLoader: compatible; dependencies: user, mediawiki.util /// Fingerprint: #0#0# /// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA) /// /* jshint curly:true, eqeqeq:true, undef:true, white:false            */ /* global document: true, jQuery: true, mediaWiki: true, window: true */ /*jslint plusplus: true, white: true                                  */ /*globals document: true, jQuery: true, mediaWiki: true, window: true */

( function ( mw, $ ) {  "use strict";   if ( typeof mw.libs.paneMarker !== "object" ) {      mw.libs.paneMarker  =  {  opt:  { }  };   }   mw.libs.paneMarker.vsn    =  -1.5;   mw.libs.paneMarker.heads  =  "|dewiki|";   mw.libs.paneMarker.type   =  "paneMarker";

/*   * 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 */

/*  What links here: Global usage */

mw.libs.paneMarker.facilitate =  function  { // Set document title to relevant page name and site name // Postcondition: //   document.title has been set // Uses: //    < document.title // Remark: wgRelevantPageName available since MW 1.20 // 2012-06-19 PerfektesChaos@de.wikipedia var s =  mw.config.get( "wgRelevantPageName" ); if ( ! s ) { s =  mw.config.get( "wgPageName" ); }     document.title  =  s.replace( /_/g, " " )   + " * " +  mw.config.get( "wgSiteName" ); };  // .facilitate

mw.libs.paneMarker.favicon =  function ( apply ) { // Try to exchange wiki-favicon // Precondition: //   apply  -- true:   red icon (page used in vulnerable mode) //             false:  show user defined default project icon // Uses: //   >  this //   >  .site //   >  .config.favicon //   >  .config.appleIcon //   >  .config.faviconICO //   >  .config.faviconPNG //   .file // 2012-06-21 PerfektesChaos@de.wikipedia var $apple, $head    =  $( document ).find( "head" ), $favicon, apple    =  false, i,         light     =  apply, n        =  0, offer    =  false, png      =  false, s;     // https://secure.wikimedia.org/favicon.ico if ( $head.length ) { if ( apply ) { png =  [ "wmf", "f7" ]; if ( this.site === "commonswiki" ) { apple =  [ "commons", "70" ]; png   =  [ "commons", "e7" ]; } else if ( this.site === "metawiki" ) { png   =  [ "meta", "96" ]; } else if ( this.site === "testwiki" ) { apple =  [ "wikipedia", "f1" ]; png   =  [ "testwiki", "b6" ]; } else if ( this.site === "mediawikiwiki" ) { apple =  [ "mediawiki", "b6" ]; png   =  [ "mediawiki", "fa" ]; } else if ( this.site.slice( -4 ) ===  "wiki" ) { apple =  [ "wikipedia", "f1" ]; png   =  [ "wikipedia", "fb" ]; } else if ( this.site.slice( -9 ) ===  "wikibooks" ) { png   =  [ "wikibooks", "7e" ]; } else if ( this.site.slice( -8 ) ===  "wikinews" ) { apple =  [ "wikinews", "a9" ]; png   =  [ "wikinews", "cc" ]; } else if ( this.site.slice( -9 ) ===  "wikiquote" ) { png   =  [ "wikiquote", "cb" ]; } else if ( this.site.slice( -10 ) ===  "wikisource" ) { png   =  [ "wikisource", "f4" ]; } else if ( this.site.slice( -11 ) ===  "wikiversity" ) { png   =  [ "wikiversity", "95" ]; } else if ( this.site.slice( -10 ) ===  "wiktionary" ) { //            apple  =  [ "wiktionary", "##" ];   // Perhelion png   =  [ "wikipedia", "fb" ]; } else { apple =  [ "wmf", "a9" ]; }        } else { light =  this.config.favicon; }        if ( apply ) { $apple =  $head.find( "link" ).filter( function {                              return ( this.rel === "apple-touch-icon" );                                                               } ); if ( $apple.length === 1 ) { s =  false; switch ( typeof this.config.appleIcon ) { case "string" : s =  this.config.appleIcon; break; case "boolean" : if ( ! this.config.appleIcon ) { break; }                    // fall through default: if ( apple ) { s =  this.file( "Apple-touch-icon-red-",                                         apple[0],                                         apple[1] ); }              }   // switch   typeof .config.appleIcon if ( s ) { $apple.detach; $apple.attr( "href", s ); $head.append( $apple ); }           }         }         if ( light ) { $favicon =  $head.find( "link" ).filter( function {                              return ( this.rel === "shortcut icon" );                                                                 } ); n =  $favicon.length; }        if ( n ) { if ( apply ) { s =  false; switch ( typeof this.config.faviconPNG ) { case "string" : s =  this.config.faviconPNG; break; case "boolean" : if ( ! this.config.faviconPNG ) { break; }                    // fall through default: s =  this.file( "Favicon-red-", png[0], png[1] ); }  // switch   typeof .config.faviconPNG offer =  [  [ s, "image/png" ]  ]; s     =  this.config.faviconICO; if ( s ) { if ( typeof s === "string" ) { offer.push( [ s, "image/x-icon" ] ); }              }            } else { s =  this.config.favicon; if ( s ) { if ( typeof s === "string" ) { offer =  [  [ s, null ]  ]; s =  s.slice( -4 ).toLowerCase; switch ( s ) { case ".ico" : offer[0][1] =  "image/x-icon"; break; case ".gif" : case ".png" : offer[0][1] =  "image/" + s.substr(1); break; }  // switch   s.slice( -4 ).toLowerCase }              }            }            if ( offer ) { for ( i = 0; i < n;  i++ ) { $favicon.eq( i ).detach; }  // for i               if ( n > 1 ) { $favicon =  $favicon.eq( 0 ); }              for ( i = 0;  i < offer.length;  i++ ) { $favicon.attr( "href", offer[i][0] ); $favicon.attr( "type", offer[i][1] ); $head.append( $favicon ); if ( i + 1 <  offer.length ) { $favicon =  $favicon.clone; }              }   // for i            } }  // $favicon.length }  // $head };  // .favicon

mw.libs.paneMarker.file =  function ( album, assign, access ) { // Retrieve PNG file URL at commons // Precondition: //   album   -- apple or favicon prefix //   assign  -- site //   access  -- hashcode octet // Postcondition: //   Returns URL // 2012-06-07 PerfektesChaos@de.wikipedia var r =  "//upload.wikimedia.org/wikipedia/commons/" + access.substr( 0, 1 )  +  "/"  +  access  +  "/" + album  +  assign  +  ".png"; return r;  };   // .file

mw.libs.paneMarker.flag =  function ( action ) { // Put character together with document title // Precondition: //   action  -- "Diff", "History", "Links", "Vitally", "*" // Uses: //   >  this //   >  .config.leave //   >  .site //   >  .heads //   >  .config.charDiff //   >  .config.charHistory //   >  .config.charLinks //   >  .config.charVitally //   >  .config.chars //   >  .config.lowChar //   >  .lazy //   >  .config.rightleft //   >< document.title //    < .leave //   .facilitate // Requires: JavaScript 1.3  String.fromCharCode // 2012-08-20 PerfektesChaos@de.wikipedia var c      =  true, learn  =  true; if ( this.config.leave ) { this.facilitate; } else if ( this.heads.indexOf( this.site ) <  0 ) { c     =  this.config[ "char" + action ]; learn =  false; }     if ( typeof this.config.chars === "boolean" ) { if ( c === true ) { c =  this.config.chars; }     }      if ( c ) { if ( learn ) { c =  this.config[ "char" + action ]; if ( c === undefined ) { c =  true; } else { learn =  false; }        }         if ( learn ) { switch ( action ) { case "Diff" : c =  ( this.config.lowChar ? "±" :  916 );   // 'Δ' break; case "History" : c =  ( this.config.lowChar ? "^" : 8595 );   // '↓' break; case "Links" : c =  ( this.config.lowChar ? ">" : 8594 );   // '→' break; case "Vitally" : if ( c &&  ! this.lazy ) { c =  false; break; }                 c  =  "*"; break; default: c =  false; }  // switch action }        if ( c ) { if ( ! this.config.leave ) { if ( action === "Links" ) { this.facilitate; }           }            if ( typeof c === "number" ) { if ( c > 0 ) { c =  String.fromCharCode( c ); }           }            if ( typeof c === "string" ) { if ( this.config.rightleft ) { document.title =  document.title + " " + c;               } else { c =  c + " "; if ( document.title.indexOf( c ) !==  0 ) { document.title =  c + document.title; }              }            }         }      }   };   // .flag

mw.libs.paneMarker.flip =  function  { // Abbreviate document title by namespace shortcut, if any // Uses: //   >  this //   >  .nsN //   >< document.title //   mw.config.get // 2012-08-20 PerfektesChaos@de.wikipedia var e,         i,          o,          s,          t;      if ( this.nsN > 0 ) { o =  mw.config.get( "wgNamespaceIds" ); for ( e in o ) { if ( o.hasOwnProperty( e ) ) { if ( e.length < 4 ) {  // file help talk user if ( o[ e ] === this.nsN ) { o =  mw.config.get( "wgFormattedNamespaces" ); s =  o[ this.nsN ]; o =  mw.config.get( "wgPageName" ); o =  o.replace( /_/g, " " ); if ( o.indexOf( s + ":" ) ===  0 ) { t =  document.title; i =  t.indexOf( o ); if ( i >= 0 ) { document.title =  ( i  ?  t.substr( 0, i )                                                   :  "" ) + e.toUpperCase + t.substr( i + s.length ); }                    }                     break;   // for e                  }   // first match }           }         }   // for e      } };  // .flip

mw.libs.paneMarker.fresh =  function  { // Run paneMarker in this particular situation // Precondition: //   Page may be under loading, but not necessarily ready. //   .using( [ "user", "mediawiki.util" ] ) // Uses: //   >  .opt.* //   >  .jQuery.browser //   >  .config.favicon //   >< this.* //    < .lazy //    < .config.* //    < .site //    < .nsN //   .flag //   mw.config.get //   mw.util.getParamValue //   .flip //   .favicon // 2012-08-20 PerfektesChaos@de.wikipedia var lenient =  true; this.lazy   =  false; if ( typeof this.opt === "object" &&  this.opt ) { this.config =  this.opt; if ( typeof this.opt.lazy === "boolean" ) { this.lazy =  this.opt.lazy; }     } else { this.config =  { }; }     this.site  =  mw.config.get( "wgDBname" ); this.nsN  =  mw.config.get( "wgNamespaceNumber" ); if ( ! this.lazy ) { if ( jQuery.browser ) { if ( jQuery.browser.msie ) { if ( jQuery.browser.version < 10 ) { this.lazy =  true; }           }         }      }      switch ( mw.config.get( "wgAction" ) ) { case "edit" : case "submit" : if ( ! this.lazy ) { this.favicon( true ); lenient =  false; }           this.flag( "Vitally" ); break; case "history" : this.flag( "History" ); break; case "view" : if ( mw.util.getParamValue( "diff" ) !==  null ) { this.flag( "Diff" ); } else if ( this.nsN === -1 ) { switch ( mw.config.get( "wgCanonicalSpecialPageName" ) ) { case "Upload" : if ( ! this.lazy ) { this.favicon( true ); lenient =  false; }                 this.flag( "Vitally" ); break; case "Whatlinkshere" : this.flag( "Links" ); break; }  // switch wgCanonicalSpecialPageName } else { this.flag( "*" ); }           break; }  // switch wgAction this.flip; if ( lenient ) { if ( typeof this.config.favicon === "string" ) { this.favicon( false ); }     }   };   // .fresh

mw.libs.paneMarker.furnish =  function  { // Launch paneMarker from event queue // Uses: //   .fresh // Remark: May be used as event handler -- 'this' is not accessed // 2012-06-07 PerfektesChaos@de.wikipedia mw.libs.paneMarker.fresh; };  // .furnish

if ( window &&  ! mw.libs.paneMarker.loaded ) { mw.libs.paneMarker.loaded =  true; mw.loader.using( [ "user",                        "mediawiki.util" ],                       mw.libs.paneMarker.furnish ); }  mw.loader.state( "ext.gadget.paneMarker", "ready" ); }( mediaWiki, jQuery ) );

// Emacs // Local Variables: // encoding: utf-8-dos // coding: utf-8-dos // fill-column: 80 // End:

/// EOF  paneMarker/d.js