Amire80 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/213998
Change subject: Cleanup ext.cx.publish.js
......................................................................
Cleanup ext.cx.publish.js
* Simplified jQuery selector for removing elements
* Comments and whitespace
Change-Id: Id7945105fc9907fa1fd2c8fb92d4f8c7f5a0cdab
---
M modules/publish/ext.cx.publish.js
1 file changed, 27 insertions(+), 15 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/98/213998/1
diff --git a/modules/publish/ext.cx.publish.js
b/modules/publish/ext.cx.publish.js
index 0991f9a..9faf2ae 100644
--- a/modules/publish/ext.cx.publish.js
+++ b/modules/publish/ext.cx.publish.js
@@ -27,7 +27,9 @@
var apiParams,
self = this;
- this.targetTitle = ( params && params.title ) || $(
'.cx-column--translation > h2' ).text();
+ this.targetTitle = ( params && params.title ) ||
+ $( '.cx-column--translation > h2' ).text();
+
apiParams = $.extend( {}, params, {
action: 'cxpublish',
from: mw.cx.sourceLanguage,
@@ -127,7 +129,7 @@
};
/**
- * Checks to see if there is already a published article with the title
+ * Checks to see if there is already a published article with the title.
* @param {string} title The title to check
* @return {jQuery.promise}
*/
@@ -153,7 +155,7 @@
};
/**
- * Generate an alternate title in case of title collision
+ * Generate an alternate title in case of title collision.
* @param {string} title The title
* @return {string}
*/
@@ -185,6 +187,7 @@
if ( !titleExists ) {
return title;
}
+
// Show a dialog to decide what to do now
self.$trigger.cxPublishingDialog();
$dialog = self.$trigger.data( 'cxPublishingDialog' );
@@ -216,26 +219,28 @@
}
/**
- * Get categories for the current translation pair
+ * Get categories for the current translation pair.
* @return {string[]} Category titles
*/
CXPublish.prototype.getCategories = function () {
- var i, sortedKeys, categoryTitles, targetCategories;
+ var targetCategories, sortedKeys, categoryTitles, i;
targetCategories = mw.cx.categoryTool.categories.target;
if ( !targetCategories ) {
return [];
}
+
sortedKeys = Object.keys( targetCategories ).sort();
categoryTitles = [];
for ( i = 0; i < sortedKeys.length; i++ ) {
categoryTitles.push( targetCategories[ sortedKeys[ i ]
] );
}
+
return categoryTitles;
};
/**
- * Get the current translation content
+ * Get the current translation content.
* @return {string}
*/
CXPublish.prototype.getContent = function () {
@@ -245,12 +250,13 @@
};
/**
- * Success handler for publishing
+ * Success handler for publishing.
*/
CXPublish.prototype.onSuccess = function () {
$( '.cx-column--translation > h2' )
.text( this.targetTitle )
.keepAlignment();
+
mw.hook( 'mw.cx.success' )
.fire( mw.message( 'cx-publish-page-success',
$( '<a>' ).attr( {
@@ -258,17 +264,19 @@
target: '_blank'
} ).text( this.targetTitle )[ 0 ].outerHTML
) );
+
mw.hook( 'mw.cx.translation.published' ).fire(
mw.cx.sourceLanguage,
mw.cx.targetLanguage,
mw.cx.sourceTitle,
this.targetTitle
);
+
mw.cx.dirty = false;
};
/**
- * Failure handler for publishing
+ * Failure handler for publishing.
* @param {string} code
* @param {object} details
*/
@@ -281,6 +289,7 @@
targetTitle: this.targetTitle,
error: details
};
+
mw.hook( 'mw.cx.translation.publish.error' ).fire(
mw.cx.sourceLanguage,
mw.cx.targetLanguage,
@@ -288,27 +297,28 @@
this.targetTitle,
JSON.stringify( details )
);
+
mw.hook( 'mw.cx.error' ).fire( mw.msg( 'cx-publish-page-error'
) );
mw.log( '[CX] Error while publishing:', code, trace );
};
/**
- * Prepare the translated content for publishing by removing
- * unwanted parts.
+ * Prepare the translated content for publishing by removing unwanted
parts.
* @return {string} processed html
*/
CXPublish.prototype.prepareTranslationForPublish = function ( $content
) {
+ // Remove the wrapper tags that are added for highlighting
segments
$content.find( '.cx-segment' ).replaceWith( function () {
return $( this ).html();
} );
- $content.find( 'link, title' ).remove();
- // Remove placeholder sections
- $content.find( '.placeholder' ).remove();
- // Remove empty sections.
+ // Remove unnecessary elements
+ $content.find( 'link, title, .placeholder' ).remove();
+
$content.find( mw.cx.getSectionSelector() ).each( function () {
var $section = $( this );
- // Firefox inserts <br type="_moz"> in Content ediables
while clearing the content
+
+ // Firefox inserts <br type="_moz"> in contenteditables
while clearing the content
// to keep the height and caret.
https://bugzilla.mozilla.org/show_bug.cgi?id=414223
// It is not guaranted that the type attribute will be
present.
// Remove them. But do not remove breaks from
paragraphs. They can be intentional
@@ -316,6 +326,8 @@
if ( $section.is( 'h1, h2, h3, h4, h5, h6' ) ) {
$section.find( 'br' ).remove();
}
+
+ // Remove empty sections
if ( !$.trim( $section.text() ) ) {
$section.remove();
}
--
To view, visit https://gerrit.wikimedia.org/r/213998
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id7945105fc9907fa1fd2c8fb92d4f8c7f5a0cdab
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits