[MediaWiki-commits] [Gerrit] Toggle expanded sections only if they are not already expanded. - change (mediawiki...MobileFrontend)

2014-10-21 Thread Bmansurov (Code Review)
Bmansurov has uploaded a new change for review.

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

Change subject: Toggle expanded sections only if they are not already expanded.
..

Toggle expanded sections only if they are not already expanded.

Bug: 72322
Change-Id: I2413fabeb21e86c05986e71d2baa21c83bac2665
---
M javascripts/modules/toggling/toggle.js
1 file changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/95/167895/1

diff --git a/javascripts/modules/toggling/toggle.js 
b/javascripts/modules/toggling/toggle.js
index a919200..737ca34 100644
--- a/javascripts/modules/toggling/toggle.js
+++ b/javascripts/modules/toggling/toggle.js
@@ -45,12 +45,18 @@
 */
function expandStoredSections() {
var expandedSections = getExpandedSections(),
-   $headlines = $( '.section-heading span' ), $headline;
+   $headlines = $( '.section-heading span' ), $headline,
+   $sectionHeading;
 
$headlines.each( function () {
$headline = $( this );
-   if ( expandedSections[currentPageTitle][$headline.attr( 
'id' )] ) {
-   toggle( $headline.parents( '.section-heading' ) 
);
+   $sectionHeading = $headline.parents( '.section-heading' 
);
+   // toggle only if the section is not already expanded
+   if (
+   
expandedSections[currentPageTitle][$headline.attr( 'id' )] 
+   !$sectionHeading.hasClass( 'open-block' )
+   ) {
+   toggle( $sectionHeading );
}
} );
}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2413fabeb21e86c05986e71d2baa21c83bac2665
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov bmansu...@wikimedia.org

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


[MediaWiki-commits] [Gerrit] Toggle expanded sections only if they are not already expanded. - change (mediawiki...MobileFrontend)

2014-10-21 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Toggle expanded sections only if they are not already expanded.
..


Toggle expanded sections only if they are not already expanded.

Bug: 72322
Change-Id: I2413fabeb21e86c05986e71d2baa21c83bac2665
---
M javascripts/modules/toggling/toggle.js
M tests/qunit/modules/toggling/test_toggle.js
2 files changed, 46 insertions(+), 3 deletions(-)

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



diff --git a/javascripts/modules/toggling/toggle.js 
b/javascripts/modules/toggling/toggle.js
index e944104..6a7b9f9 100644
--- a/javascripts/modules/toggling/toggle.js
+++ b/javascripts/modules/toggling/toggle.js
@@ -45,12 +45,18 @@
 */
function expandStoredSections() {
var expandedSections = getExpandedSections(),
-   $headlines = $( '.section-heading span' ), $headline;
+   $headlines = $( '.section-heading span' ), $headline,
+   $sectionHeading;
 
$headlines.each( function () {
$headline = $( this );
-   if ( expandedSections[currentPageTitle][$headline.attr( 
'id' )] ) {
-   toggle( $headline.parents( '.section-heading' ) 
);
+   $sectionHeading = $headline.parents( '.section-heading' 
);
+   // toggle only if the section is not already expanded
+   if (
+   
expandedSections[currentPageTitle][$headline.attr( 'id' )] 
+   !$sectionHeading.hasClass( 'open-block' )
+   ) {
+   toggle( $sectionHeading );
}
} );
}
diff --git a/tests/qunit/modules/toggling/test_toggle.js 
b/tests/qunit/modules/toggling/test_toggle.js
index 1d9c750..8508877 100644
--- a/tests/qunit/modules/toggling/test_toggle.js
+++ b/tests/qunit/modules/toggling/test_toggle.js
@@ -255,6 +255,43 @@
);
 } );
 
+QUnit.test( 'Expanding already expanded section does not toggle it.', 5, 
function( assert ) {
+   this.expandedSections = toggle._getExpandedSections( this.pageTitle );
+   assert.strictEqual( $.isEmptyObject( 
this.expandedSections[this.pageTitle] ),
+   true,
+   'no expanded sections are stored in localStorage yet'
+   );
+
+   assert.strictEqual(
+   this.$section.hasClass( 'open-block' ),
+   false,
+   'section does not have open-block class'
+   );
+
+   // manually toggle the second section
+   toggle.toggle( this.$section );
+
+   assert.strictEqual(
+   this.$section.hasClass( 'open-block' ),
+   true,
+   'revealed section has open-block class'
+   );
+
+   this.expandedSections = toggle._getExpandedSections( this.pageTitle );
+   assert.strictEqual( typeof 
this.expandedSections[this.pageTitle][this.headline],
+   'number',
+   'manually revealed section state has been correctly saved in 
localStorage'
+   );
+
+   toggle._expandStoredSections();
+
+   assert.strictEqual(
+   this.$section.hasClass( 'open-block' ),
+   true,
+   'already revealed section still has open-block class after 
expanding sections'
+   );
+} );
+
 QUnit.module( 'MobileFrontend toggle.js: restore expanded sections', {
setup: function() {
// can't use makeSections because the resulting html is wrapped 
in a div

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2413fabeb21e86c05986e71d2baa21c83bac2665
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Bmansurov bmansu...@wikimedia.org
Gerrit-Reviewer: Awjrichards aricha...@wikimedia.org
Gerrit-Reviewer: Jdlrobson jrob...@wikimedia.org
Gerrit-Reviewer: jenkins-bot 

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