[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Use the id of a visible template fragment for alignment and ...

2016-11-28 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Use the id of a visible template fragment for alignment and 
restore
..


Use the id of a visible template fragment for alignment and restore

Change-Id: I9d5dddbc7ee0c0b78e2bd3449473042b250acbfa
---
M modules/tools/ext.cx.tools.template.js
1 file changed, 29 insertions(+), 12 deletions(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/tools/ext.cx.tools.template.js 
b/modules/tools/ext.cx.tools.template.js
index eba5ae4..b72e6f8 100644
--- a/modules/tools/ext.cx.tools.template.js
+++ b/modules/tools/ext.cx.tools.template.js
@@ -252,12 +252,38 @@
};
 
/**
+* Templates will have fragments and sometimes some of them will be
+* invisible elements holding mw-data. We cannot align target sections
+* against these 0-height fragments. Restoring is also problematic.
+* So we find a 0-height fragments to use for alignment and section
+* restore.
+*
+* @return {jQuery}
+*/
+   Template.prototype.getFirstVisibleFragment = function () {
+   var $fragments, $fragment;
+
+   $fragments = this.getFragments();
+   $fragments.each( function ( index, fragment ) {
+   $fragment = $( fragment );
+
+   // Find a fragment with visible height
+   if ( $fragment.height() > 0 ) {
+   // break the loop
+   return false;
+   }
+   } );
+
+   return $fragment;
+   };
+
+   /**
 * Get the container to which the editor to append
 *
 * @return {jQuery}
 */
Template.prototype.getEditorContainer = function () {
-   var $fragments, $container;
+   var $container;
 
$container = this.$template;
 
@@ -266,16 +292,7 @@
this.$template.parents( 
mw.cx.getSectionSelector() );
$container = this.$parentSection;
} else {
-   $fragments = this.getFragments();
-   $fragments.each( function ( index, fragment ) {
-   var $fragment = $( fragment );
-
-   // Find a fragment with visible height
-   if ( $fragment.height() > 0 ) {
-   $container = $fragment;
-   return false;
-   }
-   } );
+   $container = this.getFirstVisibleFragment() || 
this.$template;
}
 
return $container;
@@ -925,7 +942,7 @@
TemplateTool.prototype.replaceTargetTemplate = function ( $newTemplate, 
state ) {
var sourceId, $new;
 
-   sourceId = this.sourceTemplate.$template.prop( 'id' );
+   sourceId = this.sourceTemplate.getFirstVisibleFragment().prop( 
'id' );
$new = $newTemplate
.clone()
.attr( {

-- 
To view, visit https://gerrit.wikimedia.org/r/323136
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9d5dddbc7ee0c0b78e2bd3449473042b250acbfa
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh 
Gerrit-Reviewer: Nikerabbit 
Gerrit-Reviewer: Santhosh 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...ContentTranslation[master]: Use the id of a visible template fragment for alignment and ...

2016-11-23 Thread Santhosh (Code Review)
Santhosh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/323136

Change subject: Use the id of a visible template fragment for alignment and 
restore
..

Use the id of a visible template fragment for alignment and restore

Change-Id: I9d5dddbc7ee0c0b78e2bd3449473042b250acbfa
---
M modules/tools/ext.cx.tools.template.js
1 file changed, 29 insertions(+), 12 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation 
refs/changes/36/323136/1

diff --git a/modules/tools/ext.cx.tools.template.js 
b/modules/tools/ext.cx.tools.template.js
index 8919458..c6f540f 100644
--- a/modules/tools/ext.cx.tools.template.js
+++ b/modules/tools/ext.cx.tools.template.js
@@ -257,12 +257,38 @@
};
 
/**
+* Templates will have fragments and sometimes some of them will be
+* invisible elements holding mw-data. We cannot align target sections
+* against these 0 hight fragement. Restoring is also problematic.
+* So we find a non-zero height fram to use for alignment and section
+* restore.
+*
+* @return {jQuery}
+*/
+   Template.prototype.getFirstVisibleFragment = function () {
+   var $fragments, $fragment;
+
+   $fragments = this.getFragments();
+   $fragments.each( function ( index, fragment ) {
+   $fragment = $( fragment );
+
+   // Find a fragment with visible height
+   if ( $fragment.height() > 0 ) {
+   // break the loop
+   return false;
+   }
+   } );
+
+   return $fragment;
+   };
+
+   /**
 * Get the container to which the editor to append
 *
 * @return {jQuery}
 */
Template.prototype.getEditorContainer = function () {
-   var $fragments, $container;
+   var $container;
 
$container = this.$template;
 
@@ -271,16 +297,7 @@
this.$template.parents( 
mw.cx.getSectionSelector() );
$container = this.$parentSection;
} else {
-   $fragments = this.getFragments();
-   $fragments.each( function ( index, fragment ) {
-   var $fragment = $( fragment );
-
-   // Find a fragment with visible height
-   if ( $fragment.height() > 0 ) {
-   $container = $fragment;
-   return false;
-   }
-   } );
+   $container = this.getFirstVisibleFragment() || 
this.$template;
}
 
return $container;
@@ -955,7 +972,7 @@
TemplateTool.prototype.replaceTargetTemplate = function ( $newTemplate, 
state ) {
var sourceId, $new;
 
-   sourceId = this.sourceTemplate.$template.prop( 'id' );
+   sourceId = this.sourceTemplate.getFirstVisibleFragment().prop( 
'id' );
$new = $newTemplate
.clone()
.attr( {

-- 
To view, visit https://gerrit.wikimedia.org/r/323136
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d5dddbc7ee0c0b78e2bd3449473042b250acbfa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits