Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js |
— | — | @@ -26,15 +26,16 @@ |
27 | 27 | } |
28 | 28 | }; |
29 | 29 | |
30 | | -wgAjaxWatch.processResult = function( response ) { |
| 30 | +wgAjaxWatch.processResult = function( response, $link ) { |
31 | 31 | response = response.watch; |
32 | | - var $link = $( this ); |
| 32 | + |
| 33 | + console.log( $link.get() ); |
33 | 34 | // To ensure we set the same status for all watch links with the |
34 | 35 | // same target we trigger a custom event on *all* watch links. |
35 | 36 | if( response.watched !== undefined ) { |
36 | | - wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'watch'] ); |
| 37 | + wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'watch', $link] ); |
37 | 38 | } else if ( response.unwatched !== undefined ) { |
38 | | - wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'unwatch'] ); |
| 39 | + wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'unwatch', $link] ); |
39 | 40 | } else { |
40 | 41 | // Either we got an error code or it just plain broke. |
41 | 42 | window.location.href = $link.attr( 'href' ); |
— | — | @@ -56,18 +57,19 @@ |
57 | 58 | var $links = $( '.mw-watchlink a, a.mw-watchlink' ); |
58 | 59 | // BC with older skins |
59 | 60 | $links = $links |
60 | | - .add( $( '#ca-watch a, #ca-unwatch a, a#mw-unwatch-link1' ) ) |
61 | | - .add( $( 'a#mw-unwatch-link2, a#mw-watch-link2, a#mw-watch-link1' ) ); |
| 61 | + .add( '#ca-watch a, #ca-unwatch a, a#mw-unwatch-link1, ' + |
| 62 | + 'a#mw-unwatch-link2, a#mw-watch-link2, a#mw-watch-link1' ); |
62 | 63 | // allowing people to add inline animated links is a little scary |
63 | 64 | $links = $links.filter( ':not( #bodyContent *, #content * )' ); |
64 | 65 | |
65 | 66 | $links.each( function() { |
66 | 67 | var $link = $( this ); |
| 68 | + var link = this; |
67 | 69 | $link |
68 | | - .data( 'icon', $link.parents( 'li' ).hasClass( 'icon' ) ) |
69 | | - .data( 'action', $link.attr( 'href' ).match( /[\?&]action=unwatch/i ) ? 'unwatch' : 'watch' ); |
70 | | - var title = $link.attr( 'href' ).match( /[\?&]title=(.*?)&/i )[1]; |
71 | | - $link.data( 'target', decodeURIComponent( title ).replace( /_/g, ' ' ) ); |
| 70 | + .data( 'icon', $link.closest( 'li' ).hasClass( 'icon' ) ) |
| 71 | + .data( 'action', mw.util.getParamValue( 'action', link.href ) == 'unwatch' ? 'unwatch' : 'watch' ); |
| 72 | + var title = mw.util.getParamValue( 'title', link.href ); |
| 73 | + $link.data( 'target', title.replace( /_/g, ' ' ) ); |
72 | 74 | }); |
73 | 75 | |
74 | 76 | $links.click( function( event ) { |
— | — | @@ -82,13 +84,13 @@ |
83 | 85 | } |
84 | 86 | |
85 | 87 | wgAjaxWatch.setLinkText( $link, $link.data( 'action' ) + 'ing' ); |
86 | | - $.get( wgScriptPath |
| 88 | + $.getJSON( wgScriptPath |
87 | 89 | + '/api' + wgScriptExtension + '?action=watch&format=json&title=' |
88 | 90 | + encodeURIComponent( $link.data( 'target' ) ) |
89 | 91 | + ( $link.data( 'action' ) == 'unwatch' ? '&unwatch' : '' ), |
90 | | - {}, |
91 | | - wgAjaxWatch.processResult, |
92 | | - 'json' |
| 92 | + function( data, textStatus, xhr ) { |
| 93 | + wgAjaxWatch.processResult( data, $link ); |
| 94 | + } |
93 | 95 | ); |
94 | 96 | |
95 | 97 | return false; |
— | — | @@ -96,8 +98,7 @@ |
97 | 99 | |
98 | 100 | // When a request returns, a custom event 'mw-ajaxwatch' is triggered |
99 | 101 | // on *all* watch links, so they can be updated if necessary |
100 | | - $links.bind( 'mw-ajaxwatch', function( event, target, action ) { |
101 | | - var $link = $( this ); |
| 102 | + $links.bind( 'mw-ajaxwatch', function( event, target, action, $link ) { |
102 | 103 | var foo = $link.data( 'target' ); |
103 | 104 | if( $link.data( 'target' ) == target ) { |
104 | 105 | var otheraction = action == 'watch' |
— | — | @@ -106,13 +107,15 @@ |
107 | 108 | |
108 | 109 | $link.data( 'action', otheraction ); |
109 | 110 | wgAjaxWatch.setLinkText( $link, otheraction ); |
110 | | - $link.attr( 'href', $link.attr( 'href' ).replace( '/&action=' + action + '/', '&action=' + otheraction ) ); |
| 111 | + $link.attr( 'href', $link.attr( 'href' ).replace( '&action=' + action , '&action=' + otheraction ) ); |
111 | 112 | if( $link.parents( 'li' ).attr( 'id' ) == 'ca-' + action ) { |
112 | 113 | $link.parents( 'li' ).attr( 'id', 'ca-' + otheraction ); |
113 | 114 | // update the link text with the new message |
114 | 115 | $link.text( mediaWiki.msg( otheraction ) ); |
115 | 116 | } |
116 | 117 | } |
| 118 | + |
| 119 | + console.log( $link.get() ); |
117 | 120 | return false; |
118 | 121 | }); |
119 | 122 | |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -343,7 +343,7 @@ |
344 | 344 | ), |
345 | 345 | 'mediawiki.action.watch.ajax' => array( |
346 | 346 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.watch.ajax.js', |
347 | | - 'dependencies' => 'mediawiki.legacy.wikibits', |
| 347 | + 'dependencies' => 'mediawiki.util', |
348 | 348 | ), |
349 | 349 | 'mediawiki.special.preferences' => array( |
350 | 350 | 'scripts' => 'resources/mediawiki.special/mediawiki.special.preferences.js', |