Skip to content

Commit

Permalink
Merge pull request #1517 from bitovi/sort-plugin-relocation
Browse files Browse the repository at this point in the history
Sort plugin: Fix events; Fix demo; Relocate to can/list/sort
  • Loading branch information
daffl committed Mar 12, 2015
2 parents 1652319 + c150041 commit 58af00f
Show file tree
Hide file tree
Showing 19 changed files with 852 additions and 797 deletions.
2 changes: 1 addition & 1 deletion builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"type": "plugin",
"description": "Define rich attribute behavior"
},
"can/map/sort/sort": {
"can/list/sort/sort": {
"name": "can.List.Sort",
"type": "plugin",
"description": "Sort observable lists"
Expand Down
30 changes: 13 additions & 17 deletions map/sort/sort.html → list/sort/sort.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
cursor: pointer;
}
</style>
<script src="../../lib/steal/steal.js"></script>
<script src="../../node_modules/steal/steal.js"></script>
<script>
steal('can/view/stache', 'can/map/sort', 'can/view/bindings', function(){
steal('can/view/stache', 'can/list/sort', 'can/view/bindings', function(){

var template = can.view.stache(
'<table>' +
'<tr>' +
'{{#each rows.0.cols}}' +
'{{#each rows.0}}' +
'<th>' +
'<button comparator-index="{{@index}}" can-click="changeComparator">' +
'&#9660;' +
Expand All @@ -40,7 +40,7 @@
'</tr>' +
'{{#each rows}}' +
'<tr>' +
'{{#each cols}}' +
'{{#each .}}' +
'<td style="background-color: rgb({{color}}, {{color}}, {{color}});">' +
'{{num}}' +
'</td>' +
Expand All @@ -51,29 +51,26 @@
);

var rows = new can.List();
var rowCount = 50;
var colCount = 50;
var rowCount = 25;
var colCount = 25;
rows.comparator = 'cols.0.num';

for (var i = 0; i < rowCount; i++) {

var col = new can.List();

var row = {
cols: col
};
var row = new can.List();

for (var j = 0; j < colCount; j++) {

var randomNumber = Math.round(Math.random() * 100);

col.attr(j, new can.Map({
var cell = new can.Map({
num: randomNumber,
color: function () {
var percentage = this.attr('num') / 100;
return 256 - Math.round(156 * percentage);
}
}));
});
row.push(cell);
}

// Push into the list after the values are generated, so that the
Expand All @@ -86,7 +83,7 @@
changeComparator: function (map, el) {
var index = el.attr('comparator-index');

rows.comparator = 'cols.' + index + '.num';
rows.comparator = index + '.num';
rows.sort();
can.trigger(rows, 'length', [rows.length]);
}
Expand All @@ -100,8 +97,8 @@

setInterval(function () {
can.batch.start();
data.rows.each(function (row) {
row.attr('cols').each(function (td) {
rows.each(function (row) {
row.each(function (td) {
td.attr('num', td.attr('num')+1);
});
})
Expand All @@ -112,4 +109,3 @@

});
</script>

Loading

0 comments on commit 58af00f

Please sign in to comment.