JSFiddle - React, Tailwind, and code Playground
by shub2079
HTML
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<div data-bind="bootstrapShowModal:modal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-bind="click:hideModal" aria-hidden="true">×</button>
<h3>Header goes here</h3>
</div>
<div class="modal-body">
<p>
Bacon ipsum dolor sit amet jowl bresaola pancetta drumstick filet mignon shank pastrami rump frankfurter beef ribs shoulder andouille. Pork loin swine meatball tongue, jerky bacon tenderloin drumstick rump tail tri-tip turkey prosciutto pastrami. Biltong strip steak andouille tri-tip meatball brisket short ribs corned beef pork kielbasa tail. Ribeye ball tip swine leberkas ham hock andouille fatback cow beef pork loin bacon tail. Pork loin ground round rump doner cow leberkas sirloin sausage. Biltong pork belly kielbasa, shank pork tongue bresaola brisket pig turkey meatloaf ball tip tenderloin.
</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-bind="click: hideModal">Close</a>
</div>
</div>
<h1>Modal dialog binding</h1>
<button id="showModal" class="btn btn-primary">Show Modal</button>
JavaScript
// Custom binding for modal dialog
ko.bindingHandlers.bootstrapShowModal = {
init: function (element, valueAccessor) {
},
update: function (element, valueAccessor) {
var value = valueAccessor();
if (ko.utils.unwrapObservable(value)) {
$(element).modal('show');
// this is to focus input field inside dialog
$("input", element).focus();
}
else {
$(element).modal('hide');
}
}
};
var ModalViewModel = function() {
var self = this;
self.modal = ko.observable(false);
self.showModal = function () {
self.modal(true);
};
self.hideModal = function () {
self.modal(false);
}
};
var viewModel = new ModalViewModel();
$(function() {
$("#showModal").click(function() {
viewModel.showModal();
});
ko.applyBindings(viewModel);
});