History: Adding JS that converts buttons to links for better UX. Patch based on...
authorLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 14 Apr 2011 13:18:39 +0000 (13:18 +0000)
committerLeo Koppelkamm <diebuche@users.mediawiki.org>
Thu, 14 Apr 2011 13:18:39 +0000 (13:18 +0000)
resources/mediawiki.action/mediawiki.action.history.js
skins/common/history.js

index 3f96347..fb62d65 100644 (file)
@@ -5,4 +5,7 @@ jQuery( function( $ ) {
        // Replaces histrowinit
        $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( diffcheck );
        diffcheck();
+       mediaWiki.loader.using('jquery.ui.button', function() {
+               window.fixCompare();
+       });
 });
\ No newline at end of file
index ee14ac9..98db46e 100644 (file)
@@ -1,6 +1,6 @@
 window.historyRadios = function( parent ) {
-       var     inputs = parent.getElementsByTagName( 'input' );
-       var     radios = [],
+       var inputs = parent.getElementsByTagName( 'input' );
+       var radios = [],
                i = 0;
        for ( i = 0; i < inputs.length; i++ ) {
                if ( inputs[i].name == 'diff' || inputs[i].name == 'oldid' ) {
@@ -76,4 +76,84 @@ window.diffcheck = function() {
                }
        }
        return true;
-};
\ No newline at end of file
+};
+
+//update the compare link as you select radio buttons
+window.updateCompare = function () {
+       var hf = compareLink.$form.get(0);
+       var oldInd = -1;
+       var i = 0;
+       while(oldInd == -1 & i<hf.oldid.length) {
+               if(hf.oldid[i].checked){
+                       oldInd=i;
+               }
+               i++;
+       }
+       var diffInd=-1;
+       var j=0;
+       while(diffInd==-1 & j<hf.diff.length) {
+               if(hf.diff[j].checked){
+                       diffInd=j;
+               }
+               j++;
+       }
+       var wikiLinkURL = wgServer + wgScript + "?title=" + encodeURIComponent(hf.title.value)
+               + "&diff=" + hf.diff[diffInd].value + "&oldid=" + hf.oldid[oldInd].value;
+       compareLink.wikiTop.attr("href", wikiLinkURL);
+       compareLink.wikiEnd.attr("href", wikiLinkURL);
+
+       if(compareLink.htmlDiffs)
+       {
+               var htmlLinkURL = wgServer + wgScript + "?title=" + encodeURIComponent(hf.title.value)
+                       + "&htmldiff=" + compareLink.htmlDiffButtonTxt
+                       + "&diff=" + hf.diff[diffInd].value + "&oldid=" + hf.oldid[oldInd].value;
+               compareLink.htmlTop.attr("href", htmlLinkURL);
+               compareLink.htmlEnd.attr("href", htmlLinkURL);
+       }
+};
+
+//change the button to a link where possible
+window.fixCompare = function () {
+       window.compareLink = {};
+       var doneHtml = false;
+       var doneWiki = false;
+       compareLink.htmlDiffs = false;
+       
+       compareLink.$form = $("#mw-history-compare");
+       var hf = compareLink.$form.get(0);
+       
+       var $buttons = $('input.historysubmit');
+       
+       if (!compareLink.$form.length || !$buttons.length) return;
+
+       $buttons.each(function() {
+               if(this.name == "htmldiff") {
+                       if (doneHtml) return true;
+                       doneHtml = true;
+                       var url = wgServer + wgScript + "?title=" + encodeURIComponent(hf.title.value)
+                               + "&htmldiff=" + this.value + "&diff=" + hf.diff[0].value + "&oldid=" + hf.oldid[1].value;
+                       compareLink.htmlDiffs = true;
+               } else {
+                       if (doneWiki) return true;
+                       doneWiki = true;
+                       var url = wgServer + wgScript + "?title=" + encodeURIComponent(hf.title.value)
+                               + "&diff=" + hf.diff[0].value + "&oldid=" + hf.oldid[1].value;
+               }
+               var $linkTop = $("<a href='" + url + "' class='historycomparelink ui-button'>" + this.value + "</a>").button();
+               compareLink.$form.before($linkTop);
+               $linkEnd = $linkTop.clone();
+               compareLink.$form.append($linkEnd);
+               
+               if(this.name == "htmldiff") {
+                       compareLink.htmlTop = $linkTop;
+                       compareLink.htmlEnd = $linkEnd;
+               } else {
+                       compareLink.wikiTop = $linkTop;
+                       compareLink.wikiEnd = $linkEnd;
+               }
+       });
+       $buttons.hide();
+
+       $("#pagehistory").change(function() {window.updateCompare()});
+};
+