Difference between revisions of "MediaWiki:Common.js"

From JaWiki (Jabber/XMPP wiki)
Jump to: navigation, search
m (debuggin')
Line 27: Line 27:
 
             var realTitle = document.getElementById("RealTitle");
 
             var realTitle = document.getElementById("RealTitle");
 
             if (realTitle) {
 
             if (realTitle) {
/*DEBUG*/document.write('/1/');
 
 
                 var realTitleHTML = realTitle.innerHTML;
 
                 var realTitleHTML = realTitle.innerHTML;
/*DEBUG*/document.write('/2/');
 
 
                 realTitleText = pickUpText(realTitle);
 
                 realTitleText = pickUpText(realTitle);
/*DEBUG*/document.write('/3/');
 
 
                  
 
                  
 
                 var isPasteable = 0;
 
                 var isPasteable = 0;
/*DEBUG*/document.write('/4/');
 
 
                 //var containsHTML = /</.test(realTitleHTML);    // contains ANY HTML
 
                 //var containsHTML = /</.test(realTitleHTML);    // contains ANY HTML
 
                 var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
 
                 var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
/*DEBUG*/document.write('/5/');
+
/*DEBUG*/document.write('/5:', containsTooMuchHTML);
 
                 // calculate whether the title is pasteable
 
                 // calculate whether the title is pasteable
 
                 var verifyTitle = realTitleText.replace(/^ +/, "");      // trim left spaces
 
                 var verifyTitle = realTitleText.replace(/^ +/, "");      // trim left spaces
/*DEBUG*/document.write('/6/');
+
/*DEBUG*/document.write('/6:', verifyTitle);
 
                 verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);    // uppercase first character
 
                 verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);    // uppercase first character
/*DEBUG*/document.write('/7/');
+
/*DEBUG*/document.write('/7:', verifyTitle);
 
   
 
   
 
                 // if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
 
                 // if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
 
                 if (wgNamespaceNumber != 0) {
 
                 if (wgNamespaceNumber != 0) {
/*DEBUG*/document.write('/8/');
 
 
                     if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
 
                     if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
/*DEBUG*/document.write('/9/');
 
 
                         verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
 
                         verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
/*DEBUG*/document.write('/10/');
 
 
                     } else {
 
                     } else {
/*DEBUG*/document.write('/11/');
 
 
                         realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
 
                         realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
 
                         realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
 
                         realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
/*DEBUG*/document.write('/12/');
 
 
                     }
 
                     }
/*DEBUG*/document.write('/13/');
 
 
                 }
 
                 }
/*DEBUG*/document.write('/14/');
 
 
   
 
   
 
                 // verify whether wgTitle matches
 
                 // verify whether wgTitle matches
 
                 verifyTitle = verifyTitle.replace(/[\s_]+/g, " ");      // underscores and multiple spaces to single spaces
 
                 verifyTitle = verifyTitle.replace(/[\s_]+/g, " ");      // underscores and multiple spaces to single spaces
/*DEBUG*/document.write('/15/');
+
/*DEBUG*/document.write('/15:', verifyTitle);
 
                 verifyTitle = verifyTitle.replace(/^\s+/, "").replace(/\s+$/, "");        // trim left and right spaces
 
                 verifyTitle = verifyTitle.replace(/^\s+/, "").replace(/\s+$/, "");        // trim left and right spaces
/*DEBUG*/document.write('/16/');
+
/*DEBUG*/document.write('/16:', verifyTitle);
 
                 verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);    // uppercase first character
 
                 verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);    // uppercase first character
/*DEBUG*/document.write('/17/');
+
/*DEBUG*/document.write('/17:', verifyTitle);
 
                 if ( (verifyTitle == wgTitle) || (verifyTitle == wgTitle.replace(/^(.+)?(January|February|March|April|May|June|July|August|September|October|November|December)\s+([12]?[0-9]|3[0123])([^\d].*)?$/g, "$1$3 $2$4") )) isPasteable = 1;
 
                 if ( (verifyTitle == wgTitle) || (verifyTitle == wgTitle.replace(/^(.+)?(January|February|March|April|May|June|July|August|September|October|November|December)\s+([12]?[0-9]|3[0123])([^\d].*)?$/g, "$1$3 $2$4") )) isPasteable = 1;
/*DEBUG*/document.write('/18/');
+
/*DEBUG*/document.write('/7:', isPasteable);
 
                 var h1 = document.getElementsByTagName("h1")[0];
 
                 var h1 = document.getElementsByTagName("h1")[0];
/*DEBUG*/document.write('/19/');
 
 
                 if (h1 && isPasteable) {
 
                 if (h1 && isPasteable) {
/*DEBUG*/document.write('/20/');
 
 
                     h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
 
                     h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
 
                     if (!containsTooMuchHTML)
 
                     if (!containsTooMuchHTML)
 
                         realTitleBanner.style.display = "none";
 
                         realTitleBanner.style.display = "none";
 
                 }
 
                 }
/*DEBUG*/document.write('/21/');
 
 
                 document.title = realTitleText + " — Jabber Wiki";
 
                 document.title = realTitleText + " — Jabber Wiki";
 
             }
 
             }

Revision as of 18:28, 11 December 2007

/* Any JavaScript here will be loaded for all users on every page load. */

 /** "Technical restrictions" title fix *****************************************
 *
 * Description:
 * Maintainers: [[w:en:User:Interiot|Interiot]], [[w:en:User:Mets501|Mets501]], [[w:en:User:Freakofnurture|Freakofnurture]]
 * Спёрто в [[w:en:MediaWiki:Common.js|Википедии]]
 */
 //
 // For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink.
 // (for instance iPod's title is updated. But [[w:en:C#|C#]] is not an equivalent
 // wikilink, so [[w:en:C Sharp|C Sharp]] doesn't have its main title changed)
 // Likewise for users who have selected the U.K. date format ("1 March") the  
 // titles of day-of-the-year articles will appear in that style. Users with any
 // other date setting are not affected.
 //
 // The function looks for a banner like this: 
 // &lt;div id="RealTitleBanner"&gt;  ... &lt;span id="RealTitle"&gt;title&lt;/span&gt; ... &lt;/div&gt;
 // An element with id=DisableRealTitle disables the function.
 //
 var disableRealTitle = 0; // users can set disableRealTitle = 1 locally to disable.
 if (wgIsArticle) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
  addOnloadHook(function() {
    try {
        var realTitleBanner = document.getElementById("RealTitleBanner");
        if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle ) {
            var realTitle = document.getElementById("RealTitle");
            if (realTitle) {
                var realTitleHTML = realTitle.innerHTML;
                realTitleText = pickUpText(realTitle);
                
                var isPasteable = 0;
                //var containsHTML = /</.test(realTitleHTML);    // contains ANY HTML
                var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
/*DEBUG*/document.write('/5:', containsTooMuchHTML);
                // calculate whether the title is pasteable
                var verifyTitle = realTitleText.replace(/^ +/, "");       // trim left spaces
/*DEBUG*/document.write('/6:', verifyTitle);
                verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);    // uppercase first character
/*DEBUG*/document.write('/7:', verifyTitle);
 
                // if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
                if (wgNamespaceNumber != 0) {
                    if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
                        verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
                    } else {
                        realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
                        realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
                    }
                }
 
                // verify whether wgTitle matches
                verifyTitle = verifyTitle.replace(/[\s_]+/g, " ");      // underscores and multiple spaces to single spaces
/*DEBUG*/document.write('/15:', verifyTitle);
                verifyTitle = verifyTitle.replace(/^\s+/, "").replace(/\s+$/, "");        // trim left and right spaces
/*DEBUG*/document.write('/16:', verifyTitle);
                verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length);    // uppercase first character
/*DEBUG*/document.write('/17:', verifyTitle);
                if ( (verifyTitle == wgTitle) || (verifyTitle == wgTitle.replace(/^(.+)?(January|February|March|April|May|June|July|August|September|October|November|December)\s+([12]?[0-9]|3[0123])([^\d].*)?$/g, "$1$3 $2$4") )) isPasteable = 1;
/*DEBUG*/document.write('/7:', isPasteable);
                var h1 = document.getElementsByTagName("h1")[0];
                if (h1 && isPasteable) {
                    h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
                    if (!containsTooMuchHTML)
                        realTitleBanner.style.display = "none";
                }
                document.title = realTitleText + " — Jabber Wiki";
            }
        }
    } catch (e) {
        /* Something went wrong. */
    }
  });
 }
 
 // similar to innerHTML, but only returns the text portions of the insides, excludes HTML
 function pickUpText(aParentElement) {
 var str = "";
 
 function pickUpTextInternal(aElement) {
  var child = aElement.firstChild;
  while (child) {
   if (child.nodeType == 1)     // ELEMENT_NODE 
    pickUpTextInternal(child);
   else if (child.nodeType == 3)   // TEXT_NODE
    str += child.nodeValue;
 
   child = child.nextSibling;
  }
 }
 
  pickUpTextInternal(aParentElement);
  return str;
 }
 
 //fix edit summary prompt for undo
 //this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the
 //edit summary unchanged
 //this was added by [[w:en:User:Deskana|Deskana]], code by [[w:en:User:Tra|Tra]]
 addOnloadHook(function () {
   if (document.location.search.indexOf("undo=") != -1
   && document.getElementsByName('wpAutoSummary')[0]) {
     document.getElementsByName('wpAutoSummary')[0].value='1';
   }
 })