JSFiddle - React, Tailwind, and code Playground
by aknuds1
HTML
<script src="http://isotope.metafizzy.co/jquery.isotope.min.js"></script>
<script src="https://github.com/downloads/SteveSanderson/knockout/knockout-2.2.0.debug.js"></script>
<div id="container" data-bind="template: {foreach: items, afterAdd: afterAdd, beforeRemove: beforeRemove}, click: addItem">
<div class="item show" data-bind="text: text, click: $parent.removeItem"></div>
</div>
CSS
.item {
background-color: blue;
border: none;
width: 200px;
height: 150px;
text-align: center;
line-height: 150px;
margin-bottom: 10px;
}
/**** Isotope Filtering ****/
.isotope-item {
z-index: 2;
}
.isotope-hidden.isotope-item {
pointer-events: none;
z-index: 1;
}
/**** Isotope CSS3 transitions ****/
.isotope, .isotope .isotope-item {
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
-ms-transition-duration: 0.8s;
-o-transition-duration: 0.8s;
transition-duration: 0.8s;
}
.isotope {
-webkit-transition-property: height, width;
-moz-transition-property: height, width;
-ms-transition-property: height, width;
-o-transition-property: height, width;
transition-property: height, width;
}
.isotope .isotope-item {
-webkit-transition-property: -webkit-transform, opacity;
-moz-transition-property: -moz-transform, opacity;
-ms-transition-property: -ms-transform, opacity;
-o-transition-property: -o-transform, opacity;
transition-property: transform, opacity;
}
/**** disabling Isotope CSS3 transitions ****/
.isotope.no-transition, .isotope.no-transition .isotope-item, .isotope .isotope-item.no-transition {
-webkit-transition-duration: 0s;
-moz-transition-duration: 0s;
-ms-transition-duration: 0s;
-o-transition-duration: 0s;
transition-duration: 0s;
}
JavaScript
var itemValues = [];
function ItemModel() {
var value;
var self = this;
for (value = 0; value < itemValues.length; ++value) {
if (itemValues.indexOf(value) == -1) {
break;
}
}
this.value = ko.observable(value);
itemValues.push(value);
this.text = ko.computed(function () {
return "Item " + self.value();
});
}
var ViewModel = function () {
var self = this;
this.items = ko.observableArray([
new ItemModel(),
new ItemModel()
]);
this.afterAdd = function (elem) {
// Node type 1 means the element node itself, we may get notifications for sub-nodes,
// e.g. text
if (elem.nodeType != 1) {
return;
}
$('#container').isotope('appended', $(elem));
console.log("After add");
console.log(elem);
};
this.beforeRemove = function (elem, event) {
// Node type 1 means the element node itself, we may get notifications for sub-nodes,
// e.g. text
if (elem.nodeType != 1) {
return;
}
$(elem).removeClass('show');
};
this.removeItem = function (item) {
console.log("About to remove element " + item.value());
self.items.remove(item);
return false;
};
this.addItem = function () {
console.log('Add item');
self.items.push(new ItemModel());
};
};
ko.applyBindings(new ViewModel("Test"));
$('#container').isotope({
itemSelector: '.item',
masonry: {
columnWidth: 210,
rowHeight: 160
},
filter: '.show'
});