Index: trunk/phase3/skins/common/history.js |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | window.historyRadios = function( parent ) { |
3 | | - var inputs = parent.getElementsByTagName( 'input' ); |
4 | | - var radios = [], |
| 3 | + var inputs = parent.getElementsByTagName( 'input' ); |
| 4 | + var radios = [], |
5 | 5 | i = 0; |
6 | 6 | for ( i = 0; i < inputs.length; i++ ) { |
7 | 7 | if ( inputs[i].name == 'diff' || inputs[i].name == 'oldid' ) { |
— | — | @@ -76,4 +76,84 @@ |
77 | 77 | } |
78 | 78 | } |
79 | 79 | return true; |
80 | | -}; |
\ No newline at end of file |
| 80 | +}; |
| 81 | + |
| 82 | +//update the compare link as you select radio buttons |
| 83 | +window.updateCompare = function () { |
| 84 | + var hf = compareLink.$form.get(0); |
| 85 | + var oldInd = -1; |
| 86 | + var i = 0; |
| 87 | + while(oldInd == -1 & i<hf.oldid.length) { |
| 88 | + if(hf.oldid[i].checked){ |
| 89 | + oldInd=i; |
| 90 | + } |
| 91 | + i++; |
| 92 | + } |
| 93 | + var diffInd=-1; |
| 94 | + var j=0; |
| 95 | + while(diffInd==-1 & j<hf.diff.length) { |
| 96 | + if(hf.diff[j].checked){ |
| 97 | + diffInd=j; |
| 98 | + } |
| 99 | + j++; |
| 100 | + } |
| 101 | + var wikiLinkURL = wgServer + wgScript + "?title=" + encodeURIComponent(hf.title.value) |
| 102 | + + "&diff=" + hf.diff[diffInd].value + "&oldid=" + hf.oldid[oldInd].value; |
| 103 | + compareLink.wikiTop.attr("href", wikiLinkURL); |
| 104 | + compareLink.wikiEnd.attr("href", wikiLinkURL); |
| 105 | + |
| 106 | + if(compareLink.htmlDiffs) |
| 107 | + { |
| 108 | + var htmlLinkURL = wgServer + wgScript + "?title=" + encodeURIComponent(hf.title.value) |
| 109 | + + "&htmldiff=" + compareLink.htmlDiffButtonTxt |
| 110 | + + "&diff=" + hf.diff[diffInd].value + "&oldid=" + hf.oldid[oldInd].value; |
| 111 | + compareLink.htmlTop.attr("href", htmlLinkURL); |
| 112 | + compareLink.htmlEnd.attr("href", htmlLinkURL); |
| 113 | + } |
| 114 | +}; |
| 115 | + |
| 116 | +//change the button to a link where possible |
| 117 | +window.fixCompare = function () { |
| 118 | + window.compareLink = {}; |
| 119 | + var doneHtml = false; |
| 120 | + var doneWiki = false; |
| 121 | + compareLink.htmlDiffs = false; |
| 122 | + |
| 123 | + compareLink.$form = $("#mw-history-compare"); |
| 124 | + var hf = compareLink.$form.get(0); |
| 125 | + |
| 126 | + var $buttons = $('input.historysubmit'); |
| 127 | + |
| 128 | + if (!compareLink.$form.length || !$buttons.length) return; |
| 129 | + |
| 130 | + $buttons.each(function() { |
| 131 | + if(this.name == "htmldiff") { |
| 132 | + if (doneHtml) return true; |
| 133 | + doneHtml = true; |
| 134 | + var url = wgServer + wgScript + "?title=" + encodeURIComponent(hf.title.value) |
| 135 | + + "&htmldiff=" + this.value + "&diff=" + hf.diff[0].value + "&oldid=" + hf.oldid[1].value; |
| 136 | + compareLink.htmlDiffs = true; |
| 137 | + } else { |
| 138 | + if (doneWiki) return true; |
| 139 | + doneWiki = true; |
| 140 | + var url = wgServer + wgScript + "?title=" + encodeURIComponent(hf.title.value) |
| 141 | + + "&diff=" + hf.diff[0].value + "&oldid=" + hf.oldid[1].value; |
| 142 | + } |
| 143 | + var $linkTop = $("<a href='" + url + "' class='historycomparelink ui-button'>" + this.value + "</a>").button(); |
| 144 | + compareLink.$form.before($linkTop); |
| 145 | + $linkEnd = $linkTop.clone(); |
| 146 | + compareLink.$form.append($linkEnd); |
| 147 | + |
| 148 | + if(this.name == "htmldiff") { |
| 149 | + compareLink.htmlTop = $linkTop; |
| 150 | + compareLink.htmlEnd = $linkEnd; |
| 151 | + } else { |
| 152 | + compareLink.wikiTop = $linkTop; |
| 153 | + compareLink.wikiEnd = $linkEnd; |
| 154 | + } |
| 155 | + }); |
| 156 | + $buttons.hide(); |
| 157 | + |
| 158 | + $("#pagehistory").change(function() {window.updateCompare()}); |
| 159 | +}; |
| 160 | + |
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js |
— | — | @@ -5,4 +5,7 @@ |
6 | 6 | // Replaces histrowinit |
7 | 7 | $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( diffcheck ); |
8 | 8 | diffcheck(); |
| 9 | + mediaWiki.loader.using('jquery.ui.button', function() { |
| 10 | + window.fixCompare(); |
| 11 | + }); |
9 | 12 | }); |
\ No newline at end of file |