mdbootstrap / bootstrap-toggle-buttons

Bootstrap-toggle-buttons has moved to https://github.com/nostalgiaz/bootstrap-switch
https://github.com/nostalgiaz/bootstrap-switch
Apache License 2.0
1.02k stars 92 forks source link

Added programmable state as per issue #21 #25

Closed ryan-endacott closed 11 years ago

ryan-endacott commented 11 years ago

$('#toggle-button').toggleButtons('set', true); // (or set false) will now toggle the button as expected. Feature added as requested in issue #21

Note: This is my first ever pull-request :-D So I'm sorry if I've done something wrong. Let me know how I can do better next time! I'm trying to get involved in open source!

ryan-endacott commented 11 years ago

The 'toggleState' method wasn't working or implemented anywhere that I could see, so I also added that. I once again apologize if I did something wrong.

icholy commented 11 years ago

this PR needs to be cleaned up. The diffs are useless.

volpino commented 11 years ago

The diffs are useless. I dunno why all the files are changed even if they are not.

Besides from that i'm not sure that click() is the best solution.

ryan-endacott commented 11 years ago

I'm sorry. Yeah, I tried to use changeStatus, but I wasn't sure how to access it from outside of that scope.

Also, I'm not sure why the diffs got so messed up. I just changed a couple lines.

ryan-endacott commented 11 years ago

I fixed the diff. I'm not sure what had caused that.

volpino commented 11 years ago

@ryan-endacott my suggestion is to remove changeStatus and change toggleState to be

$(this).siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
icholy commented 11 years ago

@volpino I second that

EDIT:

if (state != $(this).find('input').is(':checked'))
  $(this).siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
ryan-endacott commented 11 years ago

Thanks for being understanding!

I'll implement that new togglestate.

So should the new if statement call toggle state? Or also call the $(this).siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');

volpino commented 11 years ago

As changeStatus is used somewhere else you should write the function toggleState and replace changeStatus with that.

toggleState: function () {
  $(this).siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
}

Then implement the new if statement to use toggleState.

:D

ryan-endacott commented 11 years ago

Alright will do!

So how would I make toggleState callable like a regular function? Or should I just replace all the calls to changeStatus with $(this).toggleButtons('toggleState'); Is there a better way of going about it?

icholy commented 11 years ago

@ryan-endacott lol almost there, now just squash those 2 commits into 1. git rebase -i HEAD~2

ryan-endacott commented 11 years ago

Done! Thanks!

volpino commented 11 years ago

You didn't replace chageStatus, could you please do that?

ryan-endacott commented 11 years ago

Yeah, I had a question about that.

So how would I make toggleState callable like a regular function? Or should I just replace all the calls to changeStatus with $(this).toggleButtons('toggleState'); Is there a better way of going about it?

nostalgiaz commented 11 years ago

$('#toggle-button').toggleButtons('toggleState');