Bsitu has uploaded a new change for review.
https://gerrit.wikimedia.org/r/95754
Change subject: Add preview function
......................................................................
Add preview function
Maryana said no-js support is of low priority, that will be implemented
in another patch later
Change-Id: Ia98006ba7c8d961d78e89de45d93a72513b21970
---
M Flow.i18n.php
M Resources.php
A modules/base/styles/preview.less
M modules/base/ui-functions.js
M modules/discussion/forms.js
M modules/discussion/ui.js
A modules/preview/preview.js
A modules/preview/styles/preview.less
8 files changed, 91 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/54/95754/1
diff --git a/Flow.i18n.php b/Flow.i18n.php
index aaf800e..d05019a 100644
--- a/Flow.i18n.php
+++ b/Flow.i18n.php
@@ -33,6 +33,7 @@
'flow-post-actions' => 'Actions',
'flow-topic-actions' => 'Actions',
'flow-cancel' => 'Cancel',
+ 'flow-preview' => 'Preview',
'flow-newtopic-title-placeholder' => 'New topic',
'flow-newtopic-content-placeholder' => "Add some details if you'd like",
@@ -285,6 +286,8 @@
{{Identical|Action}}',
'flow-cancel' => 'Used as action link text.
{{Identical|Cancel}}',
+ 'flow-preview' => 'Used as action link text.
+{{Identical|Preview}}',
'flow-newtopic-title-placeholder' => 'Used as placeholder for the
"Subject/Title for topic" textarea.
{{Identical|New topic}}',
'flow-newtopic-content-placeholder' => 'Used as placeholder for the
"Content" textarea.',
diff --git a/Resources.php b/Resources.php
index cf2a657..004bfe8 100644
--- a/Resources.php
+++ b/Resources.php
@@ -14,6 +14,7 @@
'base/styles/form.less',
'base/styles/actionbox.less',
'base/styles/various.less',
+ 'base/styles/preview.less',
/*
* This is CSS that adds to/overrides Agora styles,
meant to be
* moved to mediawiki.ui at a later point
@@ -32,6 +33,7 @@
'jquery.json',
),
'messages' => array(
+ 'flow-preview',
),
),
'ext.flow.header' => $flowResourceTemplate + array(
@@ -42,6 +44,7 @@
),
'dependencies' => array(
'ext.flow.editor',
+ 'ext.flow.preview',
),
),
'ext.flow.discussion' => $flowResourceTemplate + array(
@@ -61,6 +64,7 @@
'jquery.spinner',
'mediawiki.Title',
'mediawiki.util',
+ 'ext.flow.preview'
),
'messages' => array(
'flow-newtopic-start-placeholder',
@@ -130,6 +134,13 @@
'jquery.spinner',
),
),
+ 'ext.flow.preview' => $flowResourceTemplate + array(
+ 'scripts' => 'preview/preview.js',
+ 'styles' => 'preview/styles/preview.less',
+ 'dependencies' => array(
+ 'ext.flow.base',
+ ),
+ ),
'ext.flow.editor' => $flowResourceTemplate + array(
'scripts' => 'editor/ext.flow.editor.js',
'dependencies' => array(
diff --git a/modules/base/styles/preview.less b/modules/base/styles/preview.less
new file mode 100644
index 0000000..08cb398
--- /dev/null
+++ b/modules/base/styles/preview.less
@@ -0,0 +1,8 @@
+.flow-content-preview {
+ background-color: #FDFFE7;
+ border: 1px solid #FCEB92;
+ padding: 5px;
+ display: none;
+ margin-top: 5px;
+ margin-bottom: 5px;
+}
diff --git a/modules/base/ui-functions.js b/modules/base/ui-functions.js
index f467b79..39d7d3f 100644
--- a/modules/base/ui-functions.js
+++ b/modules/base/ui-functions.js
@@ -124,9 +124,10 @@
$postForm.remove();
}
);
+
mw.flow.preview.hide( $postForm );
} )
)
- .append( ' ' )
+ .append( ' ' )
.append(
$(
'<input />' )
.attr( 'type', 'submit' )
@@ -138,6 +139,8 @@
)
.insertAfter( $contentContainer
);
+ mw.flow.preview.attachPreview(
$postForm );
+
if ( typeof initialContent != 'object'
) {
initialContent = {
'content' :
initialContent,
diff --git a/modules/discussion/forms.js b/modules/discussion/forms.js
index e4f7927..4784f02 100644
--- a/modules/discussion/forms.js
+++ b/modules/discussion/forms.js
@@ -239,6 +239,7 @@
$realTitle
.show();
$titleEditForm.remove();
+
mw.flow.preview.hide( $titleEditForm );
} )
)
.append( ' ' )
@@ -255,6 +256,7 @@
.find( '.flow-edit-title-textbox' )
.focus()
.select();
+ mw.flow.preview.attachPreview( $titleEditForm,
{ '.flow-edit-title-textbox': 'plain' } );
$titleEditForm.flow( 'setupFormHandler',
'.flow-edit-title-submit',
diff --git a/modules/discussion/ui.js b/modules/discussion/ui.js
index 8d8205e..51af6c3 100644
--- a/modules/discussion/ui.js
+++ b/modules/discussion/ui.js
@@ -117,9 +117,13 @@
.find( '.flow-error' )
.remove();
} );
+ mw.flow.preview.hide( $( this ).closest(
'.flow-reply-form' ) );
} )
.after( ' ' )
.insertBefore( $container.find( '.flow-reply-form
input[type=submit]' ) );
+ $container.find( 'form.flow-reply-form' ).each( function() {
+ mw.flow.preview.attachPreview( $( this ) );
+ } );
// Set up new topic form
$container.find( '.flow-newtopic-step2' ).hide();
@@ -171,10 +175,15 @@
.remove();
} );
$container.find( '.flow-new-topic-link'
).show();
+ mw.flow.preview.hide( $form );
} )
.after( ' ' )
.insertBefore( $container.find( '.flow-newtopic-form
input[type=submit]' ) );
+ mw.flow.preview.attachPreview(
+ $container.find( 'form.flow-newtopic-form' ),
+ { '.flow-newtopic-title': 'plain', 'textarea': 'parse' }
+ );
// Hide reply button until user initiates reply (hidden in JS
because it needs to be there for non-JS users)
$container.find( '.flow-topic-reply-form
.flow-post-form-controls' ).hide();
$container.find( '.flow-topic-reply-form textarea' )
@@ -208,9 +217,14 @@
.hide();
mw.flow.editor.destroy( $form.find( 'textarea'
) );
+ mw.flow.preview.hide( $form );
} )
.prependTo( $container.find( '.flow-topic-reply-form
.flow-post-form-controls') );
+ $container.find( 'form.flow-topic-reply-form' ).each(
function() {
+ mw.flow.preview.attachPreview( $( this ) );
+ } );
+
// Set up the scroll to new topic reply form
$container.find( '.flow-topic-comments .flow-reply-link'
).click(
function( e ) {
diff --git a/modules/preview/preview.js b/modules/preview/preview.js
new file mode 100644
index 0000000..f47a6b5
--- /dev/null
+++ b/modules/preview/preview.js
@@ -0,0 +1,41 @@
+( function ( $, mw ) {
+ 'use strict';
+
+ mw.flow.preview = {
+ 'show': function( $container, contents, $form ) {
+ var content = '';
+ for ( var identifier in contents ) {
+ if ( content ) {
+ content += '<br />';
+ }
+ if ( contents[identifier] === 'parse' ) {
+ content += mw.flow.parsoid.convert(
mw.flow.editor.getFormat(), 'html', $form.find( identifier ).val() );
+ } else {
+ content += mw.html.escape( $form.find(
identifier ).val() );
+ }
+ }
+ $container.html( content ).show();
+ },
+
+ 'hide': function( $form ) {
+ $form.find( '.flow-content-preview' ).empty().hide();
+ },
+
+ 'attachPreview': function( $form, contents ) {
+ if ( !contents ) {
+ contents = { 'textarea': 'parse' };
+ }
+ $( '<input />' )
+ .attr( 'type', 'submit' )
+ .val( mw.msg( 'flow-preview' ) )
+ .addClass( 'mw-ui-button' )
+ .addClass( 'flow-preview-submit' )
+ .click( function ( e ) {
+ e.preventDefault();
+ mw.flow.preview.show( $form.find(
'.flow-content-preview' ), contents, $form );
+ } ).insertAfter( $form.find(
'.flow-cancel-link' ) );
+
+ $form.prepend( $( '<div>' ).addClass(
'flow-content-preview' ) );
+ },
+ };
+} ) ( jQuery, mediaWiki );
diff --git a/modules/preview/styles/preview.less
b/modules/preview/styles/preview.less
new file mode 100644
index 0000000..08cb398
--- /dev/null
+++ b/modules/preview/styles/preview.less
@@ -0,0 +1,8 @@
+.flow-content-preview {
+ background-color: #FDFFE7;
+ border: 1px solid #FCEB92;
+ padding: 5px;
+ display: none;
+ margin-top: 5px;
+ margin-bottom: 5px;
+}
--
To view, visit https://gerrit.wikimedia.org/r/95754
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia98006ba7c8d961d78e89de45d93a72513b21970
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits