Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.js |
— | — | @@ -1,120 +0,0 @@ |
2 | | -/** |
3 | | - * Animate watch/unwatch links to use asynchronous API requests to |
4 | | - * watch pages, rather than clicking on links. Requires jQuery. |
5 | | - * Uses jsMsg() from wikibits.js. |
6 | | - */ |
7 | | - |
8 | | -if ( typeof wgAjaxWatch === 'undefined' || !wgAjaxWatch ) { |
9 | | - window.wgAjaxWatch = { }; |
10 | | -} |
11 | | - |
12 | | -wgAjaxWatch.setLinkText = function( $link, action ) { |
13 | | - if ( action == 'watch' || action == 'unwatch' ) { |
14 | | - // save the accesskey from the title |
15 | | - var keyCommand = $link.attr( 'title' ).match( /\[.*?\]$/ ) ? $link.attr( 'title' ).match( /\[.*?\]$/ )[0] : ''; |
16 | | - $link.attr( 'title', mediaWiki.msg( 'tooltip-ca-' + action ) + ' ' + keyCommand ); |
17 | | - } |
18 | | - if ( $link.data( 'icon' ) ) { |
19 | | - $link.attr( 'alt', mediaWiki.msg( action ) ); |
20 | | - if ( action == 'watching' || action == 'unwatching' ) { |
21 | | - $link.addClass( 'loading' ); |
22 | | - } else { |
23 | | - $link.removeClass( 'loading' ); |
24 | | - } |
25 | | - } else { |
26 | | - $link.html( mediaWiki.msg( action ) ); |
27 | | - } |
28 | | -}; |
29 | | - |
30 | | -wgAjaxWatch.processResult = function( response ) { |
31 | | - response = response.watch; |
32 | | - var $link = $( this ); |
33 | | - // To ensure we set the same status for all watch links with the |
34 | | - // same target we trigger a custom event on *all* watch links. |
35 | | - if( response.watched !== undefined ) { |
36 | | - wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'watch'] ); |
37 | | - } else if ( response.unwatched !== undefined ) { |
38 | | - wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'unwatch'] ); |
39 | | - } else { |
40 | | - // Either we got an error code or it just plain broke. |
41 | | - window.location.href = $link.attr( 'href' ); |
42 | | - return; |
43 | | - } |
44 | | - |
45 | | - jsMsg( response.message, 'watch' ); |
46 | | - |
47 | | - // Bug 12395 - update the watch checkbox on edit pages when the |
48 | | - // page is watched or unwatched via the tab. |
49 | | - if( response.watched !== undefined ) { |
50 | | - $( '#wpWatchthis' ).attr( 'checked', '1' ); |
51 | | - } else { |
52 | | - $( '#wpWatchthis' ).removeAttr( 'checked' ); |
53 | | - } |
54 | | -}; |
55 | | - |
56 | | -$( document ).ready( function() { |
57 | | - var $links = $( '.mw-watchlink a, a.mw-watchlink' ); |
58 | | - // BC with older skins |
59 | | - $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' ) ); |
62 | | - // allowing people to add inline animated links is a little scary |
63 | | - $links = $links.filter( ':not( #bodyContent *, #content * )' ); |
64 | | - |
65 | | - $links.each( function() { |
66 | | - var $link = $( this ); |
67 | | - $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, ' ' ) ); |
72 | | - }); |
73 | | - |
74 | | - $links.click( function( event ) { |
75 | | - var $link = $( this ); |
76 | | - |
77 | | - if( wgAjaxWatch.supported === false || !wgEnableWriteAPI || !wfSupportsAjax() ) { |
78 | | - // Lazy initialization so we don't toss up |
79 | | - // ActiveX warnings on initial page load |
80 | | - // for IE 6 users with security settings. |
81 | | - wgAjaxWatch.$links.unbind( 'click' ); |
82 | | - return true; |
83 | | - } |
84 | | - |
85 | | - wgAjaxWatch.setLinkText( $link, $link.data( 'action' ) + 'ing' ); |
86 | | - $.get( wgScriptPath |
87 | | - + '/api' + wgScriptExtension + '?action=watch&format=json&title=' |
88 | | - + encodeURIComponent( $link.data( 'target' ) ) |
89 | | - + ( $link.data( 'action' ) == 'unwatch' ? '&unwatch' : '' ), |
90 | | - {}, |
91 | | - wgAjaxWatch.processResult, |
92 | | - 'json' |
93 | | - ); |
94 | | - |
95 | | - return false; |
96 | | - }); |
97 | | - |
98 | | - // When a request returns, a custom event 'mw-ajaxwatch' is triggered |
99 | | - // 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 | | - var foo = $link.data( 'target' ); |
103 | | - if( $link.data( 'target' ) == target ) { |
104 | | - var otheraction = action == 'watch' |
105 | | - ? 'unwatch' |
106 | | - : 'watch'; |
107 | | - |
108 | | - $link.data( 'action', otheraction ); |
109 | | - wgAjaxWatch.setLinkText( $link, otheraction ); |
110 | | - $link.attr( 'href', $link.attr( 'href' ).replace( '/&action=' + action + '/', '&action=' + otheraction ) ); |
111 | | - if( $link.parents( 'li' ).attr( 'id' ) == 'ca-' + action ) { |
112 | | - $link.parents( 'li' ).attr( 'id', 'ca-' + otheraction ); |
113 | | - // update the link text with the new message |
114 | | - $link.text( mediaWiki.msg( otheraction ) ); |
115 | | - } |
116 | | - } |
117 | | - return false; |
118 | | - }); |
119 | | - |
120 | | - wgAjaxWatch.$links = $links; |
121 | | -}); |
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js |
— | — | @@ -0,0 +1,120 @@ |
| 2 | +/** |
| 3 | + * Animate watch/unwatch links to use asynchronous API requests to |
| 4 | + * watch pages, rather than clicking on links. Requires jQuery. |
| 5 | + * Uses jsMsg() from wikibits.js. |
| 6 | + */ |
| 7 | + |
| 8 | +if ( typeof wgAjaxWatch === 'undefined' || !wgAjaxWatch ) { |
| 9 | + window.wgAjaxWatch = { }; |
| 10 | +} |
| 11 | + |
| 12 | +wgAjaxWatch.setLinkText = function( $link, action ) { |
| 13 | + if ( action == 'watch' || action == 'unwatch' ) { |
| 14 | + // save the accesskey from the title |
| 15 | + var keyCommand = $link.attr( 'title' ).match( /\[.*?\]$/ ) ? $link.attr( 'title' ).match( /\[.*?\]$/ )[0] : ''; |
| 16 | + $link.attr( 'title', mediaWiki.msg( 'tooltip-ca-' + action ) + ' ' + keyCommand ); |
| 17 | + } |
| 18 | + if ( $link.data( 'icon' ) ) { |
| 19 | + $link.attr( 'alt', mediaWiki.msg( action ) ); |
| 20 | + if ( action == 'watching' || action == 'unwatching' ) { |
| 21 | + $link.addClass( 'loading' ); |
| 22 | + } else { |
| 23 | + $link.removeClass( 'loading' ); |
| 24 | + } |
| 25 | + } else { |
| 26 | + $link.html( mediaWiki.msg( action ) ); |
| 27 | + } |
| 28 | +}; |
| 29 | + |
| 30 | +wgAjaxWatch.processResult = function( response ) { |
| 31 | + response = response.watch; |
| 32 | + var $link = $( this ); |
| 33 | + // To ensure we set the same status for all watch links with the |
| 34 | + // same target we trigger a custom event on *all* watch links. |
| 35 | + if( response.watched !== undefined ) { |
| 36 | + wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'watch'] ); |
| 37 | + } else if ( response.unwatched !== undefined ) { |
| 38 | + wgAjaxWatch.$links.trigger( 'mw-ajaxwatch', [response.title, 'unwatch'] ); |
| 39 | + } else { |
| 40 | + // Either we got an error code or it just plain broke. |
| 41 | + window.location.href = $link.attr( 'href' ); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + jsMsg( response.message, 'watch' ); |
| 46 | + |
| 47 | + // Bug 12395 - update the watch checkbox on edit pages when the |
| 48 | + // page is watched or unwatched via the tab. |
| 49 | + if( response.watched !== undefined ) { |
| 50 | + $( '#wpWatchthis' ).attr( 'checked', '1' ); |
| 51 | + } else { |
| 52 | + $( '#wpWatchthis' ).removeAttr( 'checked' ); |
| 53 | + } |
| 54 | +}; |
| 55 | + |
| 56 | +$( document ).ready( function() { |
| 57 | + var $links = $( '.mw-watchlink a, a.mw-watchlink' ); |
| 58 | + // BC with older skins |
| 59 | + $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' ) ); |
| 62 | + // allowing people to add inline animated links is a little scary |
| 63 | + $links = $links.filter( ':not( #bodyContent *, #content * )' ); |
| 64 | + |
| 65 | + $links.each( function() { |
| 66 | + var $link = $( this ); |
| 67 | + $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, ' ' ) ); |
| 72 | + }); |
| 73 | + |
| 74 | + $links.click( function( event ) { |
| 75 | + var $link = $( this ); |
| 76 | + |
| 77 | + if( wgAjaxWatch.supported === false || !wgEnableWriteAPI || !wfSupportsAjax() ) { |
| 78 | + // Lazy initialization so we don't toss up |
| 79 | + // ActiveX warnings on initial page load |
| 80 | + // for IE 6 users with security settings. |
| 81 | + wgAjaxWatch.$links.unbind( 'click' ); |
| 82 | + return true; |
| 83 | + } |
| 84 | + |
| 85 | + wgAjaxWatch.setLinkText( $link, $link.data( 'action' ) + 'ing' ); |
| 86 | + $.get( wgScriptPath |
| 87 | + + '/api' + wgScriptExtension + '?action=watch&format=json&title=' |
| 88 | + + encodeURIComponent( $link.data( 'target' ) ) |
| 89 | + + ( $link.data( 'action' ) == 'unwatch' ? '&unwatch' : '' ), |
| 90 | + {}, |
| 91 | + wgAjaxWatch.processResult, |
| 92 | + 'json' |
| 93 | + ); |
| 94 | + |
| 95 | + return false; |
| 96 | + }); |
| 97 | + |
| 98 | + // When a request returns, a custom event 'mw-ajaxwatch' is triggered |
| 99 | + // 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 | + var foo = $link.data( 'target' ); |
| 103 | + if( $link.data( 'target' ) == target ) { |
| 104 | + var otheraction = action == 'watch' |
| 105 | + ? 'unwatch' |
| 106 | + : 'watch'; |
| 107 | + |
| 108 | + $link.data( 'action', otheraction ); |
| 109 | + wgAjaxWatch.setLinkText( $link, otheraction ); |
| 110 | + $link.attr( 'href', $link.attr( 'href' ).replace( '/&action=' + action + '/', '&action=' + otheraction ) ); |
| 111 | + if( $link.parents( 'li' ).attr( 'id' ) == 'ca-' + action ) { |
| 112 | + $link.parents( 'li' ).attr( 'id', 'ca-' + otheraction ); |
| 113 | + // update the link text with the new message |
| 114 | + $link.text( mediaWiki.msg( otheraction ) ); |
| 115 | + } |
| 116 | + } |
| 117 | + return false; |
| 118 | + }); |
| 119 | + |
| 120 | + wgAjaxWatch.$links = $links; |
| 121 | +}); |
Property changes on: trunk/phase3/resources/mediawiki.action/mediawiki.action.watch.ajax.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 122 | + native |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -341,8 +341,8 @@ |
342 | 342 | 'mediawiki.action.view.rightClickEdit' => array( |
343 | 343 | 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js', |
344 | 344 | ), |
345 | | - 'mediawiki.action.watch' => array( |
346 | | - 'scripts' => 'resources/mediawiki.action/mediawiki.action.watch.js', |
| 345 | + 'mediawiki.action.watch.ajax' => array( |
| 346 | + 'scripts' => 'resources/mediawiki.action/mediawiki.action.watch.ajax.js', |
347 | 347 | 'dependencies' => 'mediawiki.legacy.wikibits', |
348 | 348 | ), |
349 | 349 | 'mediawiki.special.preferences' => array( |