Permalink
Browse files

add destroy function

  • Loading branch information...
1 parent 5f1d5db commit 113b493954e6af3ad195048154707674c5e79bdb @nostalgiaz committed Nov 7, 2012
Showing with 63 additions and 4 deletions.
  1. +7 −0 README.md
  2. +41 −2 examples/index.html
  3. +14 −1 static/js/jquery.toggle.buttons.js
  4. +1 −1 static/sass/bootstrap-toggle-buttons.scss
View
@@ -111,6 +111,13 @@ JS
$('#my-toggle-button').toggleButtons('toggleState');
```
+Destroy
+-------
+JS
+``` javascript
+$('#my-toggle-button').toggleButtons('destroy');
+```
+
Like this project?
------------------
[![endorse](http://api.coderwall.com/nostalgia/endorsecount.png)](http://coderwall.com/nostalgia)
View
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
- <title>Bootstrap toggle buttons 2.7</title>
+ <title>Bootstrap toggle buttons 2.8</title>
<meta name="author" content="Mattia Larentis">
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css"
@@ -43,7 +43,7 @@
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
- <h1>Bootstrap toggle buttons 2.7
+ <h1>Bootstrap toggle buttons 2.8
<small>- by Mattia Larentis</small>
</h1>
</div>
@@ -543,6 +543,38 @@
</pre>
</div>
</div>
+<div class="row-fluid">
+ <div class="span12">
+ <h3>Destroy</h3>
+ <hr>
+ </div>
+</div>
+<div class="row-fluid">
+
+ <div class="span4">
+ <div id="destroy-toggle-button">
+ <input type="checkbox" checked="checked">
+ </div>
+ <br>
+ <button id="btn-destroy-toggle-button" class="btn btn-danger">
+ Destroy me!
+ </button>
+ </div>
+ <div class="span8">
+
+ <h4>Html:</h4>
+<pre class="prettyprint linenums">
+&lt;div id="destroy-toggle-button">
+ &lt;input type="checkbox" checked="checked">
+&lt;/div></pre>
+ <h4>Js:</h4>
+<pre class="prettyprint linenums">
+$('#destroy-toggle-button').toggleButtons();
+
+$('#destroy-toggle-button').toggleButtons('destroy');
+</pre>
+ </div>
+</div>
<p class="pull-right">
<a href="https://twitter.com/SpiritualGuru">follow me</a> -
@@ -681,6 +713,13 @@
$('#toggle-state-toggle-button-off').on('click', function () {
$('#toggle-state-toggle-button').toggleButtons('setState', false);
});
+
+ $('#destroy-toggle-button').toggleButtons();
+
+ $('#btn-destroy-toggle-button').on('click', function () {
+ $('#destroy-toggle-button').toggleButtons('destroy');
+ $(this).remove();
+ });
</script>
</body>
@@ -1,6 +1,6 @@
!function ($) {
"use strict";
- // version: 2.7
+ // version: 2.8
// by Mattia Larentis - follow me on twitter! @SpiritualGuru
var addToAttribute = function (obj, array, value) {
@@ -231,6 +231,19 @@
},
status: function () {
return $(this).find('input:checkbox').is(':checked');
+ },
+ destroy: function () {
+ var $div = $(this).find('div')
+ , $checkbox;
+
+ $div.find(':not(input:checkbox)').remove();
+
+ $checkbox = $div.children();
+ $checkbox.unwrap().unwrap();
+
+ $checkbox.unbind('change');
+
+ return $checkbox;
}
};
@@ -1,6 +1,6 @@
@import "compass/css3";
-// version: 2.7
+// version: 2.8
// by Mattia Larentis - follow me on twitter! @SpiritualGuru
$border: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);

0 comments on commit 113b493

Please sign in to comment.