Index: trunk/phase3/skins/common/history.js |
— | — | @@ -1,159 +0,0 @@ |
2 | | -window.historyRadios = function( parent ) { |
3 | | - var inputs = parent.getElementsByTagName( 'input' ); |
4 | | - var radios = [], |
5 | | - i = 0; |
6 | | - for ( i = 0; i < inputs.length; i++ ) { |
7 | | - if ( inputs[i].name == 'diff' || inputs[i].name == 'oldid' ) { |
8 | | - radios[radios.length] = inputs[i]; |
9 | | - } |
10 | | - } |
11 | | - return radios; |
12 | | -}; |
13 | | - |
14 | | -// check selection and tweak visibility/class onclick |
15 | | -window.diffcheck = function() { |
16 | | - var dli = false, // the li where the diff radio is checked |
17 | | - oli = false, // the li where the oldid radio is checked |
18 | | - i = 0; |
19 | | - var hf = document.getElementById( 'pagehistory' ); |
20 | | - if ( !hf ) { |
21 | | - return true; |
22 | | - } |
23 | | - var lis = hf.getElementsByTagName( 'li' ); |
24 | | - for ( i = 0; i < lis.length; i++ ) { |
25 | | - var inputs = historyRadios( lis[i] ); |
26 | | - if ( inputs[1] && inputs[0] ) { |
27 | | - if ( inputs[1].checked || inputs[0].checked ) { // this row has a checked radio button |
28 | | - if ( inputs[1].checked && inputs[0].checked && inputs[0].value == inputs[1].value ) { |
29 | | - return false; |
30 | | - } |
31 | | - if ( oli ) { // it's the second checked radio |
32 | | - if ( inputs[1].checked ) { |
33 | | - if ( typeof oli.className != 'undefined' ) { |
34 | | - oli.classNameOriginal = oli.className.replace( 'selected', '' ); |
35 | | - } else { |
36 | | - oli.classNameOriginal = ''; |
37 | | - } |
38 | | - |
39 | | - oli.className = 'selected ' + oli.classNameOriginal; |
40 | | - return false; |
41 | | - } |
42 | | - } else if ( inputs[0].checked ) { |
43 | | - return false; |
44 | | - } |
45 | | - if ( inputs[0].checked ) { |
46 | | - dli = lis[i]; |
47 | | - } |
48 | | - if ( !oli ) { |
49 | | - inputs[0].style.visibility = 'hidden'; |
50 | | - } |
51 | | - if ( dli ) { |
52 | | - inputs[1].style.visibility = 'hidden'; |
53 | | - } |
54 | | - if ( (typeof lis[i].className) != 'undefined') { |
55 | | - lis[i].classNameOriginal = lis[i].className.replace( 'selected', '' ); |
56 | | - } else { |
57 | | - lis[i].classNameOriginal = ''; |
58 | | - } |
59 | | - |
60 | | - lis[i].className = 'selected ' + lis[i].classNameOriginal; |
61 | | - oli = lis[i]; |
62 | | - } else { // no radio is checked in this row |
63 | | - if ( !oli ) { |
64 | | - inputs[0].style.visibility = 'hidden'; |
65 | | - } else { |
66 | | - inputs[0].style.visibility = 'visible'; |
67 | | - } |
68 | | - if ( dli ) { |
69 | | - inputs[1].style.visibility = 'hidden'; |
70 | | - } else { |
71 | | - inputs[1].style.visibility = 'visible'; |
72 | | - } |
73 | | - if ( typeof lis[i].classNameOriginal != 'undefined' ) { |
74 | | - lis[i].className = lis[i].classNameOriginal; |
75 | | - } |
76 | | - } |
77 | | - } |
78 | | - } |
79 | | - return true; |
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 |
— | — | @@ -2,8 +2,78 @@ |
3 | 3 | * JavaScript for History action |
4 | 4 | */ |
5 | 5 | jQuery( function( $ ) { |
6 | | - // Replaces histrowinit |
7 | | - $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( diffcheck ); |
8 | | - diffcheck(); |
9 | | - window.fixCompare(); |
| 6 | + var $lis = $( 'ul#pagehistory li' ); |
| 7 | + var updateDiffRadios = function() { |
| 8 | + var diffLi = false, // the li where the diff radio is checked |
| 9 | + oldLi = false; // the li where the oldid radio is checked |
| 10 | + |
| 11 | + if ( !$lis.length ) { |
| 12 | + return true; |
| 13 | + } |
| 14 | + $lis.removeClass( 'selected' ); |
| 15 | + $lis.each( function() { |
| 16 | + var $this = $(this); |
| 17 | + var $inputs = $this.find( 'input[type=radio]' ); |
| 18 | + if ( $inputs.length !== 2 ) { |
| 19 | + return true; |
| 20 | + } |
| 21 | + |
| 22 | + // this row has a checked radio button |
| 23 | + if ( $inputs.get(0).checked ) { |
| 24 | + oldLi = $this; |
| 25 | + $this.addClass( 'selected' ); |
| 26 | + $inputs.eq(0).css( 'visibility', 'visible' ); |
| 27 | + $inputs.eq(1).css( 'visibility', 'hidden' ); |
| 28 | + } else if ( $inputs.get(1).checked ) { |
| 29 | + diffLi = $this; |
| 30 | + $this.addClass( 'selected' ); |
| 31 | + $inputs.eq(0).css( 'visibility', 'hidden' ); |
| 32 | + $inputs.eq(1).css( 'visibility', 'visible' ); |
| 33 | + } else { |
| 34 | + // no radio is checked in this row |
| 35 | + if ( diffLi && oldLi ) { |
| 36 | + // We're below the selected radios |
| 37 | + $inputs.eq(0).css( 'visibility', 'visible' ); |
| 38 | + $inputs.eq(1).css( 'visibility', 'hidden' ); |
| 39 | + } else if ( diffLi ) { |
| 40 | + // We're between the selected radios |
| 41 | + $inputs.eq(0).css( 'visibility', 'visible' ); |
| 42 | + $inputs.eq(1).css( 'visibility', 'visible' ); |
| 43 | + } else { |
| 44 | + // We're above the selected radios |
| 45 | + $inputs.eq(1).css( 'visibility', 'visible' ); |
| 46 | + $inputs.eq(0).css( 'visibility', 'hidden' ); |
| 47 | + } |
| 48 | + } |
| 49 | + }); |
| 50 | + return true; |
| 51 | + }; |
| 52 | + |
| 53 | + var fixCompare = function () { |
| 54 | + var $histForm = $( '#mw-history-compare' ), |
| 55 | + $diffList = $( '#pagehistory' ), |
| 56 | + buttonText = $histForm.find( 'input.historysubmit' ).remove().first().val(), |
| 57 | + $compareLink = $( '<a></a>', { |
| 58 | + 'class': 'compare-link', |
| 59 | + 'text': buttonText |
| 60 | + }).button(); |
| 61 | + $histForm.prepend( $compareLink ) |
| 62 | + .append( $compareLink.clone() ); |
| 63 | + function updateCompare() { |
| 64 | + var $radio = $histForm.find( 'input[type=radio]:checked' ); |
| 65 | + var genLink = mw.config.get( 'wgScript' ) |
| 66 | + + '?title=' + mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ) |
| 67 | + + '&diff=' + $radio.eq(0).val() |
| 68 | + + '&oldid=' + $radio.eq(1).val(); |
| 69 | + $( '.compare-link' ).each( function() { |
| 70 | + $(this).attr('href', genLink); |
| 71 | + }); |
| 72 | + } |
| 73 | + updateCompare(); |
| 74 | + $diffList.change( updateCompare ); |
| 75 | + }; |
| 76 | + |
| 77 | + $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( function() { updateDiffRadios(); } ); |
| 78 | + fixCompare(); |
| 79 | + updateDiffRadios(); |
10 | 80 | }); |
\ No newline at end of file |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -403,7 +403,7 @@ |
404 | 404 | ), |
405 | 405 | 'mediawiki.action.history' => array( |
406 | 406 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.history.js', |
407 | | - 'dependencies' => 'mediawiki.legacy.history', |
| 407 | + 'dependencies' => 'jquery.ui.button', |
408 | 408 | 'group' => 'mediawiki.action.history', |
409 | 409 | ), |
410 | 410 | 'mediawiki.action.edit' => array( |
— | — | @@ -545,13 +545,6 @@ |
546 | 546 | 'localBasePath' => "{$GLOBALS['IP']}/skins", |
547 | 547 | 'dependencies' => 'mediawiki.legacy.wikibits', |
548 | 548 | ), |
549 | | - 'mediawiki.legacy.history' => array( |
550 | | - 'scripts' => 'common/history.js', |
551 | | - 'group' => 'mediawiki.action.history', |
552 | | - 'remoteBasePath' => $GLOBALS['wgStylePath'], |
553 | | - 'localBasePath' => "{$GLOBALS['IP']}/skins", |
554 | | - 'dependencies' => array( 'mediawiki.legacy.wikibits', 'jquery.ui.button' ), |
555 | | - ), |
556 | 549 | 'mediawiki.legacy.IEFixes' => array( |
557 | 550 | 'scripts' => 'common/IEFixes.js', |
558 | 551 | 'remoteBasePath' => $GLOBALS['wgStylePath'], |