mw.ForeignStructuredUpload.BookletLayout: Make licensing links clickable again
authorBartosz Dziewoński <matma.rex@gmail.com>
Mon, 23 May 2016 17:38:17 +0000 (19:38 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 23 May 2016 17:38:17 +0000 (19:38 +0200)
Plus some code duplication cleanup.

Bug: T136008
Change-Id: Ic3fbb4edd5042b81488cb19b149bec0a94948ce5

resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js

index 16fec73..0f61d97 100644 (file)
 
                                                // Update license messages
                                                return msgPromise.then( function () {
-                                                       booklet.$ownWorkMessage
-                                                               .msg( 'upload-form-label-own-work-message-' + msgs )
-                                                               .find( 'a' ).attr( 'target', '_blank' );
-                                                       booklet.$notOwnWorkMessage
-                                                               .msg( 'upload-form-label-not-own-work-message-' + msgs )
-                                                               .find( 'a' ).attr( 'target', '_blank' );
-                                                       booklet.$notOwnWorkLocal
-                                                               .msg( 'upload-form-label-not-own-work-local-' + msgs )
-                                                               .find( 'a' ).attr( 'target', '_blank' );
+                                                       var $labels;
+                                                       booklet.$ownWorkMessage.msg( 'upload-form-label-own-work-message-' + msgs );
+                                                       booklet.$notOwnWorkMessage.msg( 'upload-form-label-not-own-work-message-' + msgs );
+                                                       booklet.$notOwnWorkLocal.msg( 'upload-form-label-not-own-work-local-' + msgs );
+
+                                                       $labels = $( [
+                                                               booklet.$ownWorkMessage[ 0 ],
+                                                               booklet.$notOwnWorkMessage[ 0 ],
+                                                               booklet.$notOwnWorkLocal[ 0 ]
+                                                       ] );
+
+                                                       // Improve the behavior of links inside these labels, which may point to important
+                                                       // things like licensing requirements or terms of use
+                                                       $labels.find( 'a' )
+                                                               .attr( 'target', '_blank' )
+                                                               .on( 'click', function ( e ) {
+                                                                       // OO.ui.FieldLayout#onLabelClick is trying to prevent default on all clicks,
+                                                                       // which causes the links to not be openable. Don't let it do that.
+                                                                       e.stopPropagation();
+                                                               } );
                                                } );
                                        } )
                                );