Content deleted Content added
fix responseWikiText capitalization, do not preview when no response template is chosen |
es6-polyfills removed |
||
(10 intermediate revisions by the same user not shown) | |||
Line 15:
EFFPRH.init = function () {
mw.loader.using(
[ 'vue', '
EFFPRH.run
);
Line 53:
border: 1px solid black;
margin: 10px 0 10px 0;
}▼
}
/* Override normal rules for indenting lists */
.
margin-left: 0px;
}
/* Separate the dropdown and input */
.
margin-bottom: 10px;
}
/* Reduce vertical space in the dropdown options */
.
line-height: 1em;
}▼
}
/* Center form elements and labels */
.script-EFFPRH-handler td {
vertical-align: middle;
▲ }
/* Don't use the grey background in the preview */
.script-EFFPRH-preview {
background-color: white;
}
`);
Line 124 ⟶ 119:
// Handler options, see {{EFFP}}
EFFPRH.responseOptions = [
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{
{ value: 'pin', label: 'Pin' },
{ value: 'moot', label: 'Moot (filter working properly)' },
{ value: 'mootefm', label: 'Moot (may need a change to filter)' }
];
Line 150 ⟶ 148:
// We shouldn't use the mw.loader access directly, but I'm not
// pasing around the `require` function everywhere
const
// Extra component to render wikitext preview
const previewRenderer = EFFPRH.getPreviewComponent();
const handlerApp = {
components: {
CdxSelect: cdx.CdxSelect,
CdxTextInput: cdx.CdxTextInput,
CdxToggleButton: cdx.CdxToggleButton,
previewRenderer: previewRenderer
},
Line 200 ⟶ 198:
},
methods: {
onCommentChange: function ( newComment ) {▼
},▼
},▼
reloadPage: function () {
// Needs to be a function instead of using href so that we
Line 246 ⟶ 238:
<tr>
<td><span>Action:</span></td>
<td><
</tr>
<tr>
<td><span>Comment:</span></td>
<td><
</tr>
</tbody></table>
Line 259 ⟶ 251:
<li v-show="editError">Uh-oh, something went wrong. Please check the console for details.</li>
</ul>
<
<
<
<!-- v-if so that we don't call the api to parse and render a preview when its not needed, do not render with no response template chosen -->
<preview-renderer v-if="showPreview && canSubmit" :wikitext="responseWikiText"></preview-renderer>
Line 277 ⟶ 269:
props: {
wikitext: { type: String, default: '' }
▲ },
data: function () {
return {
previewHtml: '',
haveHtml: false
methods: {
// Separate from the watcher so that can be called on mounted too
loadPreview: function ( wikitextToPreview ) {
new mw.Api().get( {
action: 'parse',
formatversion: 2,
title: mw.config.get( 'wgPageName' ),
text: wikitextToPreview,
prop: 'text|wikitext',
pst: true,
disablelimitreport: true,
disableeditsection: true,
sectionpreview: true
} ).then(
( res ) => {
console.log( res );
if ( res
&& res.parse
&& res.parse.wikitext === this.wikitext
&& res.parse.text
) {
this.previewHtml = res.parse.text;
this.haveHtml = true;
}
}
);
}
},
watch: {
// Reset when the wikitext to preview changes
this.previewHtml = '';
this.haveHtml = false;
this.loadPreview( newValue );
}
},
mounted: function () {
// Preview starting wikitext
this.loadPreview( this.wikitext );
},
template: `
<div class="script-EFFPRH-preview">
<hr>
Loading preview of {{ wikitext }}▼
<div v-if="haveHtml" v-html="previewHtml"></div>
▲<div v-else>Loading preview of {{ wikitext }}</div>
</div>`
};
|