Skip to content

Commit

Permalink
Fixes the close() method
Browse files Browse the repository at this point in the history
  • Loading branch information
whazap committed Dec 4, 2015
1 parent 12504ad commit 46c8775
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/share-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class ShareButton extends ShareUtils {
*/
_eventToggle(button, networks) {
if (this._hasClass(networks, 'active'))
this._eventClose(networks);
this._eventClose(button, networks);
else
this._eventOpen(button, networks);
}
Expand Down Expand Up @@ -299,9 +299,10 @@ class ShareButton extends ShareUtils {
* @private
*
* @param {DOMNode} button
* @param {DOMNode} networks
*/
_eventClose(button) {
this._removeClass(button, 'active');
_eventClose(button, networks) {
this._removeClass(networks, 'active');
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/features/basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ Feature: Basic Button
Scenario: All social networks should be displayed
When I click the Share Button
Then I should see all Social Networks

@basic
Scenario: All social networks should be hidden
When I close the Share Button manually by calling the close method
Then I should no longer see any Social Network
12 changes: 12 additions & 0 deletions tests/fixtures/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,32 @@
right: 0;
z-index: 100;
}
#close {
float: right;
border: 2px solid #f00;
padding: 10px;
text-transform: uppercase;
background-color: #fff;
text-align: center;
}
</style>
<meta name='description' content='A simple, light, flexible, and good-looking share button'>
<meta property='og:image' content='http://carrot.is/img/fb-share.jpg'>
</head>

<body>
<share-button></share-button>
<button id="close">close</button>
<script src='../../dist/share-button.min.js'></script>
<script>
var shareButton = new ShareButton({
ui: {
flyout: 'center bottom'
}
});
document.getElementById('close').addEventListener('click', function () {
shareButton.close();
}, false);
</script>
</body>

Expand Down
9 changes: 9 additions & 0 deletions tests/steps/basic.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ module.exports = ->
.each (item, i) ->
unless (item.hasClass('whatsapp').then (tf) -> tf)
item.isVisible().should.eventually.eql(true)

@When /^I close the Share Button manually by calling the close method$/, ->
new @Widgets.Body().triggerCloseButton()

@Then /^I should no longer see any Social Network$/, ->
new @Widgets
.ShareButtonNetworks()
.each (item, i) ->
item.isVisible().should.eventually.eql(false)
6 changes: 6 additions & 0 deletions tests/widgets/shareButton.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ module.exports = ->
@Widgets.ShareButtonNetworks = @Widget.List.extend
root: 'share-button ul'
itemSelector: 'li'

@Widgets.Body = @Widget.extend
root: 'body'

triggerCloseButton: ->
return this.click('#close')

0 comments on commit 46c8775

Please sign in to comment.