Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/151989
Change subject: Hygiene: Move the overlay initialisation code into a separate
file
......................................................................
Hygiene: Move the overlay initialisation code into a separate file
Change-Id: I4dcdf9708b700c57679ff878275c5560a62e3a06
---
M Hooks.php
M Resources.php
A modules/overlay/ext.echo.overlay.init.js
M modules/overlay/ext.echo.overlay.js
4 files changed, 80 insertions(+), 71 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/89/151989/1
diff --git a/Hooks.php b/Hooks.php
index bd54197..3cee000 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -623,7 +623,7 @@
if ( $user->isLoggedIn() && $user->getOption(
'echo-notify-show-link' ) ) {
// Load the module for the Notifications flyout
- $out->addModules( array( 'ext.echo.overlay' ) );
+ $out->addModules( array( 'ext.echo.overlay.init' ) );
// Load the styles for the Notifications badge
$out->addModuleStyles( 'ext.echo.badge' );
}
diff --git a/Resources.php b/Resources.php
index fc814ec..82bcedd 100644
--- a/Resources.php
+++ b/Resources.php
@@ -75,6 +75,14 @@
'echo-feedback',
),
),
+ 'ext.echo.overlay.init' => $echoResourceTemplate + array(
+ 'dependencies' => array(
+ 'ext.echo.overlay',
+ ),
+ 'scripts' => array(
+ 'overlay/ext.echo.overlay.init.js',
+ ),
+ ),
'ext.echo.special' => $echoResourceTemplate + array(
'scripts' => array(
'special/ext.echo.special.js',
diff --git a/modules/overlay/ext.echo.overlay.init.js
b/modules/overlay/ext.echo.overlay.init.js
new file mode 100644
index 0000000..49737c8
--- /dev/null
+++ b/modules/overlay/ext.echo.overlay.init.js
@@ -0,0 +1,71 @@
+( function ( $, mw ) {
+ $( function () {
+ var $link = $( '#pt-notifications a' );
+ if ( ! $link.length ) {
+ return;
+ }
+
+ $link.click( function ( e ) {
+ var $target;
+
+ // log the badge click
+ mw.echo.logInteraction( 'ui-badge-link-click' );
+
+ e.preventDefault();
+
+ $target = $( e.target );
+ // If the user clicked on the overlay or any child,
ignore the click
+ if ( $target.hasClass( 'mw-echo-overlay' ) ||
$target.is( '.mw-echo-overlay *' ) ) {
+ return;
+ }
+
+ if ( $( '.mw-echo-overlay' ).length ) {
+ mw.echo.overlay.removeOverlay();
+ return;
+ }
+
+ mw.echo.overlay.buildOverlay(
+ function ( $overlay ) {
+ $overlay
+ .hide()
+ .appendTo( $(
'#pt-notifications' ) );
+
+ // Create the pokey (aka chevron)
+ $overlay.before( $( '<div>' ).addClass(
'mw-echo-overlay-pokey' ) );
+
+ mw.hook(
'ext.echo.overlay.beforeShowingOverlay' ).fire( $overlay );
+
+ // Show the notifications overlay
+ $overlay.show();
+
+ // Make sure the overlay is visible,
even if the badge is near the edge of browser window.
+ // 10 is an arbitrarily chosen "close
enough" number.
+ // We are careful not to slide out from
below the pokey (which is 21px wide) (200-21/2+1 == 189)
+ var
+ offset = $overlay.offset(),
+ width = $overlay.width(),
+ windowWidth = $( window
).width();
+ if ( offset.left < 10 ) {
+ $overlay.css( 'left', '+=' +
Math.min( 189, 10 - offset.left ) );
+ } else if ( offset.left + width >
windowWidth - 10 ) {
+ $overlay.css( 'left', '-=' +
Math.min( 189, ( offset.left + width ) - ( windowWidth - 10 ) ) );
+ }
+ }
+ );
+ } );
+
+ $( 'body' ).click( function ( e ) {
+ if ( ! $( e.target ).is( '.mw-echo-overlay,
.mw-echo-overlay *, .mw-echo-overlay-pokey, #pt-notifications a' ) ) {
+ mw.echo.overlay.removeOverlay();
+ }
+ } );
+
+ // Closes the notifications overlay when ESC key pressed
+ $( document ).on( 'keydown', function ( e ) {
+ if ( e.which === 27 ) {
+ mw.echo.overlay.removeOverlay();
+ }
+ } );
+
+ } );
+}( jQuery, mediaWiki ));
diff --git a/modules/overlay/ext.echo.overlay.js
b/modules/overlay/ext.echo.overlay.js
index 70b8c8f..4fc7889 100644
--- a/modules/overlay/ext.echo.overlay.js
+++ b/modules/overlay/ext.echo.overlay.js
@@ -312,74 +312,4 @@
}
}
};
-
- $( function () {
- var $link = $( '#pt-notifications a' );
- if ( ! $link.length ) {
- return;
- }
-
- $link.click( function ( e ) {
- var $target;
-
- // log the badge click
- mw.echo.logInteraction( 'ui-badge-link-click' );
-
- e.preventDefault();
-
- $target = $( e.target );
- // If the user clicked on the overlay or any child,
ignore the click
- if ( $target.hasClass( 'mw-echo-overlay' ) ||
$target.is( '.mw-echo-overlay *' ) ) {
- return;
- }
-
- if ( $( '.mw-echo-overlay' ).length ) {
- mw.echo.overlay.removeOverlay();
- return;
- }
-
- mw.echo.overlay.buildOverlay(
- function ( $overlay ) {
- $overlay
- .hide()
- .appendTo( $(
'#pt-notifications' ) );
-
- // Create the pokey (aka chevron)
- $overlay.before( $( '<div>' ).addClass(
'mw-echo-overlay-pokey' ) );
-
- mw.hook(
'ext.echo.overlay.beforeShowingOverlay' ).fire( $overlay );
-
- // Show the notifications overlay
- $overlay.show();
-
- // Make sure the overlay is visible,
even if the badge is near the edge of browser window.
- // 10 is an arbitrarily chosen "close
enough" number.
- // We are careful not to slide out from
below the pokey (which is 21px wide) (200-21/2+1 == 189)
- var
- offset = $overlay.offset(),
- width = $overlay.width(),
- windowWidth = $( window
).width();
- if ( offset.left < 10 ) {
- $overlay.css( 'left', '+=' +
Math.min( 189, 10 - offset.left ) );
- } else if ( offset.left + width >
windowWidth - 10 ) {
- $overlay.css( 'left', '-=' +
Math.min( 189, ( offset.left + width ) - ( windowWidth - 10 ) ) );
- }
- }
- );
- } );
-
- $( 'body' ).click( function ( e ) {
- if ( ! $( e.target ).is( '.mw-echo-overlay,
.mw-echo-overlay *, .mw-echo-overlay-pokey, #pt-notifications a' ) ) {
- mw.echo.overlay.removeOverlay();
- }
- } );
-
- // Closes the notifications overlay when ESC key pressed
- $( document ).on( 'keydown', function ( e ) {
- if ( e.which === 27 ) {
- mw.echo.overlay.removeOverlay();
- }
- } );
-
- } );
} )( jQuery, mediaWiki );
--
To view, visit https://gerrit.wikimedia.org/r/151989
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4dcdf9708b700c57679ff878275c5560a62e3a06
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits