Benutzer:PerfektesChaos/js/editMenusPREGO/d.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/// PerfektesChaos/js/editMenusPREGO/d.js
/// 2018-12-01 PerfektesChaos@de.wikipedia
/// Fingerprint: #0#0#
/// <nowiki>
/* 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 = -1.4,
       Sign    = "editMenus",
       Sub     = "Prego",
       Support = "Wikipedia:Technik/Skin/Gadgets/" + Sign,
       EDIT    = { learnt:   false,
                   lower:    false,
                   mini:     1,
                   singles:  "",
                   standard: "Standard" },
       PREGO   = { app:        false,
                   live:       false,
                   maxage:     604815,
                   order:      { selector: Sign + "-order",
                                 style:    "font-size:85%;" +
                                           "font-style:italic;",
                                 suggest:  "",
                                 $suggest: false },
                   pars:       [ [ "learnt",  "boolean" ],
                                 [ "mini",    "number" ],
                                 [ "singles", "string" ] ],
                   signature:  "preferencesGadgetOptions",
                   site:       "w:en",
                   store:      "User:PerfektesChaos/js/",
                   sub:        "/r.js" },
       REPOS   = { };



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



   PREGO.texts = {
         // 2018-11-14 PerfektesChaos@de.wikipedia
         "^show":     {"de": Sign},
         "^suffix":   {"de": "&#8211; Sonderzeichenleiste usw."},
         "^^learnt":  {"de": "Direktverlinkung mit der Projektseite"
                             + " nicht mehr anzeigen"},
         "^^mini":    {"de": "Minimieren für die jeweilige Seite"},
         "^^lower":   {"de": "HTML-Generation unterdrücken"
                             + " (vor allem"
                             + " für nicht angemeldete Benutzer)"},
         "^^mini0":   {"de": "Nicht anbieten"},
         "^^mini1":   {"de": "Eingeblendet beginnen"},
         "^^mini2":   {"de": "Ausgeblendet beginnen"},
         "^^singles": {"de": "Bevorzugte Sprachen,"
                             + " durch Leerzeichen getrennt"
                             + " (wichtigste zuerst)"}
   };   // PREGO.texts




   EDIT.fire = function ( app ) {
      // PREGO has been installed in edit mode
      // Precondition:
      //    app  -- menuSwitcher object
      // Uses:
      //    >  EDIT.learnt
      //    >  EDIT.lower
      //    >  EDIT.mini
      //    >  EDIT.singles
      //    >  EDIT.standard
      // 2018-11-30 PerfektesChaos@de.wikipedia
      var i, got, hide, options, s, top;
      if ( typeof app  ===  "object"
           &&     app    &&
           typeof app.fire  ===  "function" ) {
         if ( EDIT.lower ) {
            options = false;
         } else {
            if ( EDIT.singles ) {
               got = EDIT.singles.split( " " );
               if ( got.length ) {
                  top = [ EDIT.standard ];
                  for ( i = 0;  i < got.length;  i++ ) {
                     s = got[ i ];
                     if ( s ) {
                        top.unshift( s );
                     }
                  }   // for i
               }
            }
            if ( EDIT.mini ) {
               hide = { less:  ( EDIT.mini > 1 ) };
            } else {
               hide = false;
            }
            options = { hide: hide,
                        top:  top };
            if ( EDIT.learnt ) {
               options.help = false;
            }
         }
         app.fire( options );
      }
   };   // EDIT.fire()




   EDIT.fired = function ( access ) {
      // PREGO has been installed in edit mode
      // Precondition:
      //    access  -- menuSwitcher function
      // Uses:
      //    >  EDIT.learnt
      //    >  EDIT.lower
      //    >  EDIT.mini
      //    >  EDIT.singles
      //    >  EDIT.standard
      // 2018-12-01 PerfektesChaos@de.wikipedia
      var i, got, hide, options, s, top;
      if ( typeof access  ===  "function" ) {
         if ( EDIT.lower ) {
            options = false;
         } else {
            if ( EDIT.singles ) {
               got = EDIT.singles.split( " " );
               if ( got.length ) {
                  top = [ EDIT.standard ];
                  for ( i = 0;  i < got.length;  i++ ) {
                     s = got[ i ];
                     if ( s ) {
                        top.unshift( s );
                     }
                  }   // for i
               }
            }
            if ( EDIT.mini ) {
               hide = { less:  ( EDIT.mini > 1 ) };
            } else {
               hide = false;
            }
            options = { hide: hide,
                        top:  top };
            if ( EDIT.learnt ) {
               options.help = false;
            }
         }
         access( options );
      }
   };   // EDIT.fire()



   PREGO.features = function ( applied ) {
      // User options available
      // Precondition:
      //    applied  -- object, may be null, with values
      // Uses:
      //    >  PREGO.pars
      //    >  PREGO.live
      //    PREGO.form()
      //    (EDIT.fire)
      //    (EDIT.fired)
      // 2018-12-01 PerfektesChaos@de.wikipedia
      var i, n, s, v;
      if ( typeof applied  ===  "object"
           &&     applied ) {
         n = PREGO.pars.length;
         for ( i = 0;  i < n;  i++ ) {
            v = PREGO.pars[ i ];
            s = v[ 0 ];
            if ( typeof applied[ s ]  ===  v[ 1 ] ) {
               EDIT[ s ]  =  applied[ s ];
            }
         }   // for i
      }
      if ( PREGO.live ) {
         PREGO.form( EDIT );
      } else {
         mw.hook( "editMenus.completed" ).add( EDIT.fire );
         mw.hook( "editMenusPrego.options" ).add( EDIT.fired );
      }
   };   // PREGO.features()



   PREGO.feed = function () {
      // Provide PREGO
      // Uses:
      //    >  PREGO.signature
      //    >  PREGO.site
      //    >  PREGO.store
      //    >  PREGO.sub
      //    >  PREGO.maxage
      //    mw.loader.getState()
      //    mw.loader.state()
      //    REPOS.fire()
      // 2018-09-03 PerfektesChaos@de.wikipedia
      var sign = "ext.gadget." + PREGO.signature,
          rls;
      if ( ! mw.loader.getState( sign ) ) {
         rls = { };
         rls[ sign ] = "loading";
         mw.loader.state( rls );
         REPOS.fire( PREGO.site,
                     PREGO.store + PREGO.signature + PREGO.sub,
                     false,
                     { action: "raw",
                       ctype:  "text/javascript",
                       bcache: 1,
                       maxage: PREGO.maxage } );
      }
   };   // PREGO.feed()



   PREGO.first = function ( application ) {
      // PREGO has been installed
      // Precondition:
      //    application  -- PREGO object
      // Uses:
      //    >  PREGO.signature
      //    >  Sign
      //    >  PREGO.live
      //     < PREGO.app
      //    (PREGO.features)
      //    (PREGO.order.fed)
      // 2018-11-14 PerfektesChaos@de.wikipedia
      PREGO.app = application;
      mw.hook( PREGO.signature + ".fetch" ).fire( Sign,
                                                  PREGO.features );
      if ( PREGO.live ) {
         mw.hook( "editMenusDef.sprachen" ).add( PREGO.order.fed );
      }
   };   // PREGO.first()



   PREGO.form = function ( apply ) {
      // Equip Special:Blankpage page with entry and form
      // Precondition:
      //    apply  -- preferences
      //              >  .learnt
      //              >  .mini
      //              >  .singles
      // Uses:
      //    >  PREGO.order
      //    >  PREGO.texts
      //    >  PREGO.app
      //    >  Sign
      //    >  Support
      //    PREGO.order.fiat()
      //    (PREGO.order.field)
      //    (PREGO.order.form)
      //    mw.libs.preferencesGadgetOptions.form()
      // 2018-11-30 PerfektesChaos@de.wikipedia
      var opts    = [ ],
          dialog;
      opts.push( { signature: "singles",
                   type:      "text",
                   show:      PREGO.texts[ "^^singles" ],
                   minimum:   100,
                   val:       PREGO.order.fiat( apply.singles ),
                   field:     PREGO.order.field },
                 { signature: "sprachen",
                   type:      "html",
                   source:    "<div id='" + PREGO.order.selector + "'" +
                               " style='" + PREGO.order.style + "'>"
                                                            + "</div>" },
                 { signature: "mini",
                   type:      "radio",
                   show:      PREGO.texts[ "^^mini" ],
                   val:       ( apply.mini ? apply.mini
                                           : 0 ),
                   poly:      [ { val:  0,
                                  show: PREGO.texts[ "^^mini0" ] },
                                { val:  1,
                                  show: PREGO.texts[ "^^mini1" ] },
                                { val:  2,
                                  show: PREGO.texts[ "^^mini2" ] }
                              ] },
                 { signature: "learnt",
                   type:      "checkbox",
                   show:      PREGO.texts[ "^^learnt" ],
                   val:       apply.learnt },
                 { signature: "lower",
                   type:      "checkbox",
                   show:      PREGO.texts[ "^^lower" ],
                   val:       apply.lower }
               );
      dialog = { script:  Sign,
                 show:    PREGO.texts[ "^show" ],
                 support: "//de.wikipedia.org/wiki/" + Support,
                 suffix:  PREGO.texts[ "^suffix" ],
                 opts:    opts,
                 fiat:    PREGO.order.form };
      if ( typeof PREGO.app.form  ===  "function" ) {
         PREGO.app.form( dialog );
      }
   };   // PREGO.form()



   PREGO.order.fed = function ( aliens ) {
      // Arrival of singles selection Array
      // Precondition:
      //    aliens --  string with initialization, or not
      // Uses:
      //    >  PREGO.order.$suggest
      //     < PREGO.order.suggest
      // 2018-11-14 PerfektesChaos@de.wikipedia
      var e, i;
      if ( typeof aliens  ===  "object"
           &&     aliens    &&
           typeof aliens.length  ===  "number"
           &&     aliens.length ) {
         PREGO.order.suggest = "";
         for ( i = 0;  i < aliens.length;  i++ ) {
            e = aliens[ i ];
            if ( typeof e  ===  "object"
                 &&     e    &&
                 typeof e.length  ===  "number"
                 &&     e.length > 1 ) {
               e = e[ 0 ];
               if ( typeof e  ===  "string"
                    &&     e ) {
                  if ( PREGO.order.suggest ) {
                     PREGO.order.suggest = PREGO.order.suggest + " ";
                  }
                  PREGO.order.suggest = PREGO.order.suggest + e;
               }
            }
         }   // for i
         if ( PREGO.order.$suggest && PREGO.order.suggest ) {
            PREGO.order.$suggest.text( PREGO.order.suggest );
         }
      }
   };   // PREGO.order.fed()



   PREGO.order.fiat = function ( apply ) {
      // Format singles text input field
      // Precondition:
      //    apply --  string with initialization, or not
      // Postcondition:
      //    Returns string with input formatting
      // Uses:
      //    >  PREGO.order.$input
      //    >< PREGO.reWScollapse
      // 2018-11-14 PerfektesChaos@de.wikipedia
      var got, r;
      if ( PREGO.order.$input ) {
         r = PREGO.order.$input.val();
      } else {
         r = apply;
      }
      if ( typeof PREGO.reWScollapse  !==  "object" ) {
         PREGO.reWScollapse = new RegExp( "\\s+", "g" );
      }
      r   = r.replace( PREGO.reWScollapse, " " );
      got = r.split( " " );
      if ( got.length ) {
         r = got.join( "  " ) + " ";
      } else {
         r = "";
      }
      if ( PREGO.order.$input ) {
         PREGO.order.$input.val( r );
      }
      return r;
   };   // PREGO.order.fiat()



   PREGO.order.field = function ( $applying ) {
      // Generation of singles text input field completed
      // Precondition:
      //    $applying  --  jQuery object of text input field
      // Uses:
      //     < PREGO.order.$input
      //    (PREGO.order.fiat)
      // 2018-11-14 PerfektesChaos@de.wikipedia
      PREGO.order.$input = $applying;
      PREGO.order.$input.change( PREGO.order.fiat );
   };   // PREGO.order.field()



   PREGO.order.form = function () {
      // Special:Blankpage page form entry has been created
      // Uses:
      //    >  PREGO.order.selector
      //     < PREGO.order.$suggest
      // 2018-11-14 PerfektesChaos@de.wikipedia
      PREGO.order.$suggest = this.$pop.find( "#"
                                             + PREGO.order.selector );
      if ( PREGO.order.suggest ) {
         PREGO.order.$suggest.text( PREGO.order.suggest );
      }
   };   // PREGO.order.form()



   REPOS.fire = function ( at, access, append, alter ) {
      // Load from external URL
      // Precondition:
      //    at      -- Wikimedia Foundation site code, or not
      //    access  -- string with basic page name
      //    append  -- string with subpage, or not
      //    alter   -- parameter object, or MIME string, or not
      // Uses:
      //    >< REPOS.requests
      //    REPOS.foundation()
      //    mw.loader.load()
      // 2018-03-21 PerfektesChaos@de.wikipedia
      var source, syntax;
      if ( typeof REPOS.requests  !==  "object" ) {
         REPOS.requests = { };
      }
      if ( typeof REPOS.requests[ access ]  !==  "boolean" ) {
         REPOS.requests[ access ] = true;
         if ( append ) {
            source = access + append;
         } else {
            source = access;
         }
         if ( at ) {
            source = REPOS.foundation( at, source, alter );
            if ( typeof alter  ===  "object"
                 &&     alter   &&
                 typeof alter.ctype  ===  "string" ) {
               syntax = alter.ctype;
            }
         } else {
            syntax = alter;
         }
         mw.loader.load( source, syntax );
      }
   };   // REPOS.fire()



   REPOS.foundation = function ( at, access, alter ) {
      // Create URL within Wikimedia Foundation
      // Precondition:
      //    at      -- site code, or not
      //    access  -- string with page name
      //    alter   -- parameter object, or not
      // Postcondition:
      //    Returns full URL
      // 2018-03-21 PerfektesChaos@de.wikipedia
      var s = access,
          r = encodeURI( s );
      if ( typeof alter  ===  "object"
           &&     alter ) {
         r = "/w/index.php?title=" + r;
         if ( access.substr( -3 ) === ".js" ) {
            alter.ctype = "text/javascript";
         } else if ( access.substr( -4 ) === ".css" ) {
            alter.ctype = "text/css";
         }
         alter.action = "raw";
         for ( s in alter ) {
            r = r + "&" + s + "=" + encodeURI( alter[ s ] );
         }   // for s in alter
      } else {
         r = "/wiki/" + r;
      }
      if ( typeof at  ===  "string"
           &&     at ) {
         switch ( at ) {
            case "meta":
               r = "meta.wikimedia.org" + r;
               break;
            case "mw":
               r = "www.mediawiki.org" + r;
               break;
            case "w:en":
               r = "en.wikipedia.org" + r;
               break;
            default:
               r = window.location.host + r;
         }   // switch at
         r = "https://" + r;
      }
      return r;
   };   // REPOS.foundation()



   function fire() {
      // Initialize sub-module
      // Uses:
      //    >  Sign
      //    >  Sub
      //    >  PREGO.signature
      //     < PREGO.live
      //    PREGO.feed()
      //    (PREGO.features)
      // 2018-11-14 PerfektesChaos@de.wikipedia
      var signature = "ext.gadget." + Sign + "." + Sub,
          rls, special;
      if ( mw.loader.getState( signature )  !==  "ready" ) {
         rls = { };
         rls[ signature ] = "ready";
         mw.loader.state( rls );
         special = mw.config.get( "wgCanonicalSpecialPageName" );
         if ( special === "Blankpage" ) {
            special    = mw.config.get( "wgTitle" );
            signature  = "/" + PREGO.signature;
            PREGO.live = ( special.indexOf( signature ) > 1 );
         }
         PREGO.feed();
         mw.hook( PREGO.signature + ".ready" ).add( PREGO.first );
      }
   }   // fire()



   fire();   // autorun
}( window.mediaWiki, window.jQuery ) );



/// EOF </nowiki>   editMenusPREGO/d.js