Jack Phoenix has uploaded a new change for review. https://gerrit.wikimedia.org/r/106240
Change subject: Fix the JS so that it actually works. ...................................................................... Fix the JS so that it actually works. Kudos to http://en.uncyclopedia.co/wiki/User:Bizzeebeever for suggesting this approach, which, no doubt, is far saner than my initial attempt at fixing this. So why was this broken in the first place? I have no idea to be honest. It used to work at some point, I'm sure of that. What's a part of the problem is that there are many components, lots of similar IDs and DOM structures and many different pieces using similar concepts. Change-Id: Ieeb1218bd6d28f7973f2a87ed0f64e99c4553254 --- M FanBoxes.js 1 file changed, 28 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FanBoxes refs/changes/40/106240/1 diff --git a/FanBoxes.js b/FanBoxes.js index bc9124e..b09e1ac 100644 --- a/FanBoxes.js +++ b/FanBoxes.js @@ -378,34 +378,35 @@ // Special:TopUserBoxes, Special:ViewUserBoxes, <userboxes /> parser hook, // and /extensions/SocialProfile/UserProfile/UserProfilePage.php jQuery( 'body' ).on( 'click', 'input.fanbox-cancel-button', function() { - var $fantagId = jQuery( 'div[id^="fanboxPopUpBox"]' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); + var $fantagId = jQuery( this ).parents( 'div:eq(0)' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); FanBoxes.closeFanboxAdd( 'fanboxPopUpBox' + $fantagId, 'individualFanbox' + $fantagId ); } ); - // FanBoxClass.php - jQuery( 'div.individual-fanbox table.fanBoxTable' ).on( 'click', function() { - var $fantagId = jQuery( 'div[id^="individualFanbox"]' ).attr( 'id' ).replace( /individualFanbox/, '' ); - FanBoxes.openFanBoxPopup( - 'fanboxPopUpBox' + $fantagId, - 'individualFanbox' + $fantagId - ); - } ); + // FanBoxClass.php (UserBox: pages), Special:TopUserBoxes, Special:ViewUserBoxes + if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'UserBoxes' ) { + jQuery( 'body' ).on( 'click', 'table.fanBoxTable', function() { + var $element; + if ( jQuery( this ).parent().attr( 'id' ) ) { + // FanBoxClass.php case + $element = jQuery( this ).parent(); + } else { + // Special:TopUserBoxes, Special:ViewUserBoxes + $element = jQuery( this ).parent().parent().parent(); + } - // Special:TopUserBoxes, Special:ViewUserBoxes - jQuery( 'body' ).on( 'click', 'div.show-message-container table.fanBoxTable', function() { - var $element = jQuery( 'div[id^="individualFanbox"]' ); - var $fantagId = $element.attr( 'id' ).replace( /individualFanbox/, '' ); - FanBoxes.openFanBoxPopup( - 'fanboxPopUpBox' + $fantagId, - 'individualFanbox' + $fantagId - ); - } ); + var $fantagId = $element.attr( 'id' ).replace( /individualFanbox/, '' ); + FanBoxes.openFanBoxPopup( + 'fanboxPopUpBox' + $fantagId, + 'individualFanbox' + $fantagId + ); + } ); + } // UserBoxesHook.php (<userboxes /> parser hook) & /extensions/SocialProfile/UserProfile/UserProfilePage.php - jQuery( 'table.fanBoxTableProfile' ).on( 'click', function() { + jQuery( 'body' ).on( 'click', 'table.fanBoxTableProfile', function() { var $fantagId, $element; // UserBoxesHook.php @@ -424,7 +425,7 @@ } ); jQuery( 'input.fanbox-add-button-half' ).on( 'click', function() { - var $fantagId = jQuery( 'div[id^="fanboxPopUpBox"]' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); + var $fantagId = jQuery( this ).parents( 'div:eq(0)' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); FanBoxes.closeFanboxAdd( 'fanboxPopUpBox' + $fantagId, 'individualFanbox' + $fantagId @@ -433,7 +434,7 @@ } ); jQuery( 'input.fanbox-remove-button-half' ).on( 'click', function() { - var $fantagId = jQuery( 'div[id^="fanboxPopUpBox"]' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); + var $fantagId = jQuery( this ).parents( 'div:eq(0)' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); FanBoxes.closeFanboxAdd( 'fanboxPopUpBox' + $fantagId, 'individualFanbox' + $fantagId @@ -441,9 +442,10 @@ FanBoxes.showAddRemoveMessageUserPage( 2, $fantagId, 'show-addremove-message-half' ); } ); - // Special:TopUserBoxes & Special:ViewUserBoxes + // "Add this box to your user page?"/"Remove this box from your user page?" + // (the add/remove buttons) on Special:TopUserBoxes & Special:ViewUserBoxes jQuery( 'input.fanbox-add-button' ).on( 'click', function() { - var $fantagId = jQuery( 'div[id^="fanboxPopUpBox"]' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); + var $fantagId = jQuery( this ).parents( 'div:eq(0)' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); FanBoxes.closeFanboxAdd( 'fanboxPopUpBox' + $fantagId, 'individualFanbox' + $fantagId @@ -452,7 +454,7 @@ } ); jQuery( 'input.fanbox-remove-button' ).on( 'click', function() { - var $fantagId = jQuery( 'div[id^="fanboxPopUpBox"]' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); + var $fantagId = jQuery( this ).parents( 'div:eq(0)' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); FanBoxes.closeFanboxAdd( 'fanboxPopUpBox' + $fantagId, 'individualFanbox' + $fantagId @@ -462,7 +464,7 @@ // FanBoxClass.php jQuery( 'input.fanbox-remove-has-button' ).on( 'click', function() { - var $fantagId = jQuery( 'div[id^="fanboxPopUpBox"]' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); + var $fantagId = jQuery( this ).parents( 'div:eq(0)' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); FanBoxes.closeFanboxAdd( 'fanboxPopUpBox' + $fantagId, 'individualFanbox' + $fantagId @@ -471,7 +473,7 @@ } ); jQuery( 'input.fanbox-add-doesnt-have-button' ).on( 'click', function() { - var $fantagId = jQuery( 'div[id^="fanboxPopUpBox"]' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); + var $fantagId = jQuery( this ).parents( 'div:eq(0)' ).attr( 'id' ).replace( /fanboxPopUpBox/, '' ); FanBoxes.closeFanboxAdd( 'fanboxPopUpBox' + $fantagId, 'individualFanbox' + $fantagId -- To view, visit https://gerrit.wikimedia.org/r/106240 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ieeb1218bd6d28f7973f2a87ed0f64e99c4553254 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/FanBoxes Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <j...@countervandalism.net> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits