Difference between revisions 137379 and 137390 on testwiki

/// mw:User:PerfektesChaos/js/paneMarker/?.js
/// 2012-06-13 [email protected]
/// Fingerprint: #0#0#
// 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
(contracted; show full)
   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-13 [email protected]
      var $apple,
          $head      =  $( document ).find( "head" ),
          $favicon,
          i,
          n,
          apple      =  false,
          png        =  [ "wmf", "f7" ],
          show,
          site       =  this.config.site;
      if ( site === "commonswiki" ) {
         apple  =  [ "commons", "70" ];
         png    =  [ "commons", "e7" ];
      } else if ( site === "metawiki" ) {
         png    =  [ "meta", "96" ];
      } else if ( site === "testwiki" ) {
         apple  =  [ "wikipedia", "f1" ];
         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" ) {
(contracted; show full)      // Uses:
      //    >  this
      //    >  .config.chars
      //    >  .heads
      //    >  .config.charDiff
      //    >  .config.charHistory
      //    >  .config.charVitally
      //    >  
jQuery.browser.msie.lazy
      //    >  .config.rightleft
      //    >< document.title
      //    mw.config.get()
      // Requires: JavaScript 1.3   String.fromCharCode()
      // 2012-06-13 [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 ) {
                     if ( jQuery.browser ) {
                        if ( ! jQuery.browser.msie! this.lazy ) {
                              c  =  false;
                              break;
                        }
                     }
                  }
                  c  =  "*";
                  break;
               default:
                  c  =  false;
            }   // switch action
         }
         if ( c ) {
            if ( typeof c === "number" ) {
               c  =  String.fromCharCode( c );
            }
            if ( typeof c === "string" ) {
               if ( this.config.rightleft ) {
                 document.title  =  document.title + " " + c;
               } else {
                 document.title  =  c + " " + document.title;
               }
            }
         }
      }
   };   // .flag()



   mw.libs.paneMarker.flip  =  function () {
      // Abbreviate document title by namespace shortcut, if any
      // Uses:
      //    >  this
      //    >  .config.nsN
      //    >< document.title
      //    mw.config.get()
      // 2012-06-113 [email protected]
      var e,
          n  =  this.config.nsNi,
          o,
          s,
          t;
      if ( nthis.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 ] === nthis.nsN ) {
                     o  =  mw.config.get( "wgFormattedNamespaces" );
                     s  =  o[ n ];
                     o  =  mw.config.get( "wgPageName" );
                     o  =  o.replace( /_/ig, " " );
                     if ( ! o.indexOf( s + ":" ) ) {
                        t  =  document.title;
                        ni  =  t.indexOf( o );
                        if ( ni >= 0 ) {
                           document.title  =  ( ni  ?  t.substr( 0, ni )
                                                   :  "" )
                                              + e.toUpperCase()
                                              + t.substr( ni + 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.*
      //    >  .config.least
      //    >< this.*
      //     < .config.*
      //     < .config.site
      //     < .config.nsNnsN
      //     < .lazy
      //    .flip()
      //    .flag()
      //    .favicon()
      //    mw.config.get()
      //    mw.util.getParamValue()
      // 2012-06-123 [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" :
            this.favicon();
if ( jQuery.browser ) {
               if ( jQuery.browser.msie ) {
                  if ( ! jQuery.browser.msie ) {
document.title  =  document.title + " !";
}
}version < 9 ) {
                     this.lazy  =  true;
                  }
               }
            }
            if ( ! this.lazy ) {
               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