forked from aknuds1/knockout-isotope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo2.html
89 lines (74 loc) · 3.04 KB
/
demo2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<html>
<head>
<title>Knockout-Isotope Demo</title>
<link rel="stylesheet" type="text/css" href="lib/style2.css">
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.js"></script>
<script type="text/javascript" src="spec/lib/knockout-2.2.0.debug.js"></script>
<script type="text/javascript" src="spec/lib/jquery.isotope.js"></script>
<script type="text/javascript" src="spec/lib/JSLog.js"></script>
<script type="text/javascript" src="lib/knockout-isotope.js"></script>
<script type="text/javascript">
$(document).ready(function () {
JSLog.SetLevel(4);
logger = JSLog.Register('Application');
var ViewModel = function () {
var self = this;
this.filterValue = ko.observable();
this.things = ko.observableArray([{type: 'type1', stuff: 'Thing1'},
{type: 'type1', stuff: 'Thing2'},
{type: 'type2', stuff: 'Thing3'},
{type: 'type2', stuff: 'Thing4'},
{type: 'type2', stuff: 'Thing5'},
{type: 'type2', stuff: 'Thing6'}
]);
this.filters = ko.observableArray(['none', 'type1', 'type2']);
this.isoFilter = ko.observable(false);
function itemFilter(value) {
if (value != 'none') {
return ko.utils.arrayFilter(self.things(), function(thing) {
return thing.type === value;
});
} else {
return self.things();
}
}
this.isotopefilteredThings = ko.computed(function () {
var filter = self.isoFilter();
if (filter !== 'none') {
return ko.utils.arrayFilter(self.things(), function (thing) {
return thing.type === filter;
});
}
return self.things();
});
this.isotopeOptions = function () {
return {layoutMode: 'fitRows'};
};
this.foreachFilter = ko.observable(false);
this.filteredThings = ko.computed(function () {
var filter = self.foreachFilter(), result;
logger.debug('Foreach filter: ' + filter);
if (filter !== 'none') {
result = ko.utils.arrayFilter(self.things(), function (thing) {
return thing.type === filter;
});
}
else
result = self.things();
logger.debug('Filtered things: ' + result);
return result;
});
};
ko.applyBindings(new ViewModel());
});
</script>
</head>
<body>
<h1>Knockout Isotope Binding Demo 2</h1>
<select data-bind="options: filters, value: isoFilter"></select>
<div id="myContainer" data-bind="isotope: { data: isotopefilteredThings, isotopeOptions: isotopeOptions }">
<div class="thing" data-bind="text: stuff, css: type"></div>
</div>
</body>
</html>
<!-- vim: set sts=2 sw=2 et: -->