Difference between revisions 137327 and 137369 on testwiki

/// mw:User:PerfektesChaos/js/paneMarker/?.js
/// 2012-06-123 [email protected]
/// Fingerprint: #0#0#
/// <nowiki>
// 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.

// Requires: JavaScript 1.3
//           MediaWiki 1.18 (mw.libs, jQuery core)
/// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA)
/*
 * 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
[[File:Apple-touch-icon-red-commons.png]]
[[File:Apple-touch-icon-red-mediawiki.png]]
[[File:Apple-touch-icon-red-wikinews.png]]
[[File:Apple-touch-icon-red-wikipedia.png]]
[[File:Apple-touch-icon-red-wiktionary.png]]
[[File:Apple-touch-icon-red-wmf.png]]
[[File:Favicon-red-commons.png]]
[[File:Favicon-red-mediawiki.png]]
[[File:Favicon-red-meta.png]]
[[File:Favicon-red-testwiki.png]]
[[File:Favicon-red-wikibooks.png]]
[[File:Favicon-red-wikinews.png]]
[[File:Favicon-red-wikipedia.png]]
[[File:Favicon-red-wikiquote.png]]
[[File:Favicon-red-wikisource.png]]
[[File:Favicon-red-wikiversity.png]]
[[File:Favicon-red-wmf.png]]
*/
/// <nowiki>
/* 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  */
// Requires: JavaScript 1.3
//           MediaWiki 1.18 (mw.libs, jQuery core)



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


   mw.libs.paneMarker.favicon  =  function () {
      // Try to exchange wiki-favicon for a red one
      // Precondition:
      //    Page used in vulnerable mode (editing, creation, deletion).
      // Uses:
      //    >  this
      //    >  .config.site
      //    >  .config.appleIcon
      //    >  .config.faviconICO
      //    >  .config.faviconPNG
      //    .file()
      // 2012-06-123 [email protected]
      var $apple,
          $head      =  $( document ).find( "head" ),
          $favicon,
          i,
          n,
          apple      =  false,
          png        =  [ "wmf", "##f7" ],   // a9
          show,
          site       =  this.config.site;
      if ( site === "commonswiki" ) {
         apple  =  [ "commons", "##70" ];   // 70
         png    =  [ "commons", "e7" ];
      } else if ( site === "metawiki" ) {
         png    =  [ "meta", "96" ];
      } else if ( site === "testwiki" ) {
         png    =  [ "testwiki", "b6" ];
      } else if ( site === "mediawikiwiki" ) {
         apple  =  [ "mediawiki", "b6" ];
         png    =  [ "mediawiki", "fa" ];
      } else if ( site.slice( -4 )  ===  "wiki" ) {
         apple  =  [ "wikipedia", "f1" ];
         png    =  [ "wikipedia", "fb" ];
      } else if ( site.slice( -9 )  ===  "wikibooks" ) {
         png    =  [ "wikibooks", "7e" ];
      } else if ( site.slice( -8 )  ===  "wikinews" ) {
         apple  =  [ "wikinews", "a9" ];
         png    =  [ "wikinews", "cc" ];
      } else if ( site.slice( -9 )  ===  "wikiquote" ) {
         png    =  [ "wikiquote", "cb" ];
      } else if ( site.slice( -10 )  ===  "wikisource" ) {
         png    =  [ "wikisource", "f4" ];
      } else if ( site.slice( -11 )  ===  "wikiversity" ) {
         png    =  [ "wikiversity", "95" ];
      } else if ( site.slice( -10 )  ===  "wiktionary" ) {
    //       apple  =  [ "wiktionary", "##" ];   // Perhelion
         png    =  [ "wikipedia", "fb" ];
      } else {
         apple  =  [ "wmf", "##a9" ];   // f7
      }
      // https://secure.wikimedia.org/favicon.ico
      if ( $head.length ) {
         $favicon  =  $head.find( "link" ).filter( function() {
                              return ( this.rel === "shortcut icon" );
                                                           } );
         $apple    =  $head.find( "link" ).filter( function() {
                              return ( this.rel === "apple-touch-icon" );
                                                           } );
         if ( $apple.length === 1 ) {
            show  =  false;
            switch ( typeof this.config.appleIcon ) {
               case "string" :
                  show  =  this.config.appleIcon;
                  break;
               case "boolean" :
                  if ( ! this.config.appleIcon  ) {
                     break;
                  }
                  // fall through
               default:
                  if ( apple ) {
                     show  =  this.file( "Apple-touch-icon-red-",
                                         apple[0],
                                         apple[1] );
                  }
show="//upload.wikimedia.org/wikipedia/commons/f/f1/Apple-touch-icon-red-wikipedia.png";
            }   // switch   typeof .config.appleIcon
            if ( show ) {
               $apple.detach();
               $apple.attr( "href", show );
               $head.append( $apple );
            }
         }
         n  =  $favicon.length;
         if ( n ) {
            show  =  false;
            switch ( typeof this.config.faviconPNG ) {
               case "string" :
                  show  =  this.config.faviconPNG;
                  break;
               case "boolean" :
                  if ( ! this.config.faviconPNG ) {
                     break;
                  }
                  // fall through
               default:
if (png[1]==="##") {
show="//upload.wikimedia.org/wikipedia/commons/f/fb/Favicon-red-wikipedia.png";
} else {
                  show  =  this.file( "Favicon-red-", png[0], png[1] );
}
            }   // switch   typeof .config.faviconPNG
            if ( show || this.config.faviconICO ) {
               for ( i = 0;  i < n;  i++ ) {
                  $favicon.eq( i ).detach();
               }   // for i
               if ( n > 1 ) {
                  $favicon  =  $favicon.eq( 0 );
               }
               if ( typeof this.config.faviconICO === "string" ) {
                  $favicon.attr( "href", this.config.faviconICO );
                  $favicon.attr( "type", null"image/x-icon" );
                  $head.append( $favicon );
                  if ( show ) {
                     $favicon  =  $favicon.clone();
                  }
               }
               if ( show ) {
                  $favicon.attr( "type", "image/png" );
(contracted; show full)      //    >  .config.charDiff
      //    >  .config.charHistory
      //    >  .config.charVitally
      //    >  .config.rightleft
      //    >< document.title
      //    mw.config.get()
      // Requires: JavaScript 1.3   String.fromCharCode()
      // 2012-06-1
03 [email protected]
      var c       =  -1,
          learn   =  true;
      if ( typeof this.config.chars === "boolean" ) {
         c  =  this.config.chars;
      } else if ( this.heads.indexOf( this.config.site )  <  0 ) {
         c      =  this.config[ "char" + action ];
         learn  =  false;
      }
      if ( c ) {
         if ( learn ) {
            c      =  this.config[ "char" + action ];
            learn  =  false;
         }
         if ( learn ) {
            switch ( action ) {
               case "Diff" :
                  c  =  "Δ";916;   // 'Δ'
                  // '±' if not displayed by browser
                  break;
               case "History" :
                  c  =  "↓";8595;   // '↓'
                  break;
               case "Vitally" :
                  if ( c === -1 ) {
                     c  =  false;
                     break;
                  }
                  c  =  "*";
(contracted; show full)      //     < .config.site
      //     < .config.nsN
      //    .flip()
      //    .flag()
      //    .favicon()
      //    mw.config.get()
      //    mw.util.getParamValue()
      // 2012-06-1
02 [email protected]
      if ( typeof this.opt === "object"  &&  this.opt ) {
         this.config  =  this.opt;
      } else {
         this.config  =  { };
      }
      this.config.site  =  mw.config.get( "wgDBname" );
      this.config.nsN   =  mw.config.get( "wgNamespaceNumber" );
      this.flip();
      switch ( mw.config.get( "wgAction" ) ) {
         case "edit" :
         case "submit" :
         case "delete" :
            this.favicon();
            this.flag( "Vitally" );
            break;
         case "history" :
            this.flag( "History" );
            break;
         case "view" :
            if ( mw.util.getParamValue( "diff" )  !==  null ) {
               this.flag( "Diff" );
            } else if ( this.config.nsN === -1 ) {
               if ( mw.config.get( "wgCanonicalSpecialPageName" )
                    === "Upload" ) {
                  this.favicon();
                  this.flag( "Vitally" );
               }
            }
            break;
      }   // switch wgAction
   };   // .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 [email protected]
      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 </nowiki>   paneMarker/?.js