Sebastian Berlin (WMSE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/351610 )
Change subject: Add feedback button
......................................................................
Add feedback button
Added a button in the player that takes the user to a feedback page,
if specified in the config. Refactored and reused logic for the help
button for this.
Bug: T162361
Change-Id: I49cf2498b4b62a46a6760c1cbf88b9a9c62058af
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
5 files changed, 101 insertions(+), 27 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech
refs/changes/10/351610/1
diff --git a/Hooks.php b/Hooks.php
index b5c0038..8b3b93f 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -122,6 +122,9 @@
global $wgWikispeechHelpPage;
$vars['wgWikispeechHelpPage'] =
$wgWikispeechHelpPage;
+ global $wgWikispeechFeedbackPage;
+ $vars['wgWikispeechFeedbackPage'] =
+ $wgWikispeechFeedbackPage;
return true;
}
}
diff --git a/extension.json b/extension.json
index a565827..db9ca0b 100644
--- a/extension.json
+++ b/extension.json
@@ -103,6 +103,7 @@
}
},
"WikispeechSkipBackRewindsThreshold": 3.0,
- "WikispeechHelpPage": "Help:Wikispeech"
+ "WikispeechHelpPage": "Help:Wikispeech",
+ "WikispeechFeedbackPage": "Feedback"
}
}
diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index c9777c0..3c145b3 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -42,6 +42,11 @@
content: '\f128';
}
+.ext-wikispeech-feedback:after {
+ font-family: 'Fontawesome';
+ content: '\f075';
+}
+
.ext-wikispeech-control-panel {
position: fixed;
left: 0;
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index cced6fd..4865d92 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -13,9 +13,7 @@
*/
this.addControlPanel = function () {
- var $controlPanel, helpPage, helpPagePath;
-
- $controlPanel = $( '<div></div>' )
+ $( '<div></div>' )
.attr( 'id', 'ext-wikispeech-control-panel' )
.addClass( 'ext-wikispeech-control-panel' )
.appendTo( '#content' );
@@ -41,22 +39,24 @@
'ext-wikispeech-skip-ahead-sentence',
self.skipAheadUtterance
);
- helpPage = mw.config.get( 'wgWikispeechHelpPage' );
- if ( helpPage ) {
- // Only add button for help page if it is
specified in
- // the config.
+ self.addLinkButton(
+ 'ext-wikispeech-help',
+ 'wgWikispeechHelpPage'
+ );
+ self.addLinkButton(
+ 'ext-wikispeech-feedback',
+ 'wgWikispeechFeedbackPage'
+ );
+ if (
+ $( '.ext-wikispeech-help,
ext-wikispeech-feedback' ).length
+ ) {
+ // Add divider if there are any non-control
buttons.
$( '<span></span>' )
.addClass( 'ext-wikispeech-divider' )
- .appendTo( $controlPanel );
- helpPagePath = mw.config.get( 'wgArticlePath' )
- .replace( '$1', helpPage );
- $( '<a></a>' )
- .attr( 'href', helpPagePath )
- .append(
- $( '<button></button>' )
- .addClass(
'ext-wikispeech-help' )
- )
- .appendTo(
'#ext-wikispeech-control-panel' );
+ .insertBefore(
+ $( '.ext-wikispeech-help,
ext-wikispeech-feedback' )
+ .first()
+ );
}
};
@@ -130,6 +130,36 @@
};
/**
+ * Add a button that takes the user to another page.
+ *
+ * The button gets the link destination from a supplied
+ * config variable. If the variable isn't specified, the button
+ * isn't added.
+ *
+ * @param {string} cssClass The name of the CSS class to add to
+ * the button.
+ * @param {string} configVariable The config variable to get
+ * link destination from.
+ */
+
+ this.addLinkButton = function ( cssClass, configVariable ) {
+ var page, pagePath;
+
+ page = mw.config.get( configVariable );
+ if ( page ) {
+ pagePath = mw.config.get( 'wgArticlePath' )
+ .replace( '$1', page );
+ $( '<a></a>' )
+ .attr( 'href', page )
+ .append(
+ $( '<button></button>' )
+ .addClass( cssClass )
+ )
+ .appendTo(
'#ext-wikispeech-control-panel' );
+ }
+ };
+
+ /**
* Play or stop, depending on whether an utterance is playing.
*/
diff --git a/tests/qunit/ext.wikispeech.test.js
b/tests/qunit/ext.wikispeech.test.js
index 96a446c..288c7ce 100644
--- a/tests/qunit/ext.wikispeech.test.js
+++ b/tests/qunit/ext.wikispeech.test.js
@@ -255,25 +255,27 @@
} );
QUnit.test( 'addControlPanel(): add help button if page is set',
function ( assert ) {
- assert.expect( 1 );
- mw.config.set(
- 'wgWikispeechHelpPage',
- 'Help'
- );
+ assert.expect( 2 );
+ mw.config.set( 'wgArticlePath', '$1' );
+ mw.config.set( 'wgWikispeechHelpPage', 'Help' );
wikispeech.addControlPanel();
assert.strictEqual(
$( '#ext-wikispeech-control-panel .ext-wikispeech-help'
).length,
1
);
+ assert.strictEqual(
+ $( '#ext-wikispeech-control-panel .ext-wikispeech-help'
)
+ .parent()
+ .attr( 'href' ),
+ 'Help'
+ );
} );
QUnit.test( 'addControlPanel(): do not add help button if page is not
set', function ( assert ) {
assert.expect( 1 );
- mw.config.set(
- 'wgWikispeechHelpPage',
- null
- );
+ mw.config.set( 'wgWikispeechHelpPage', null );
+
wikispeech.addControlPanel();
assert.strictEqual(
@@ -282,6 +284,39 @@
);
} );
+ QUnit.test( 'addControlPanel(): add feedback button', function ( assert
) {
+ assert.expect( 2 );
+ mw.config.set( 'wgArticlePath', '$1' );
+ mw.config.set( 'wgWikispeechFeedbackPage', 'Feedback' );
+
+ wikispeech.addControlPanel();
+
+ assert.strictEqual(
+ $( '#ext-wikispeech-control-panel
.ext-wikispeech-feedback' )
+ .length,
+ 1
+ );
+ assert.strictEqual(
+ $( '#ext-wikispeech-control-panel
.ext-wikispeech-feedback' )
+ .parent()
+ .attr( 'href' ),
+ 'Feedback'
+ );
+ } );
+
+ QUnit.test( 'addControlPanel(): do not add feedback button if page is
not set', function ( assert ) {
+ assert.expect( 1 );
+ mw.config.set( 'wgWikispeechFeedbackPage', null );
+
+ wikispeech.addControlPanel();
+
+ assert.strictEqual(
+ $( '#ext-wikispeech-control-panel
#ext-wikispeech-feedback' )
+ .length,
+ 0
+ );
+ } );
+
QUnit.test( 'Clicking play/stop button', function ( assert ) {
testClickButton(
assert,
--
To view, visit https://gerrit.wikimedia.org/r/351610
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I49cf2498b4b62a46a6760c1cbf88b9a9c62058af
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits