Skip to content

Commit

Permalink
plugin system updates
Browse files Browse the repository at this point in the history
updating to closer match spec in issue Knockout-Contrib#79
  • Loading branch information
orneryd committed Nov 6, 2012
1 parent 3ca0479 commit 27028c8
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 44 deletions.
33 changes: 19 additions & 14 deletions KoGrid-1.2.4.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* koGrid JavaScript Library
* Authors: https://github.com/ericmbarnard/KoGrid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 11/05/2012 19:40:39
* Compiled At: 11/05/2012 21:34:40
***********************************************/


Expand Down Expand Up @@ -667,7 +667,7 @@ kg.Row = function (entity, config, selectionManager) {
var element = event.target;

//check and make sure its not the bubbling up of our checked 'click' event
if (element.type == "checkbox" && element.parentElement.className.indexOf("kgSelectionCell" !== -1)) {
if (element.type == "checkbox" && $(element).parent().attr('class').indexOf("kgSelectionCell" !== -1)) {
return true;
}
if (config.selectWithCheckboxOnly && element.type != "checkbox"){
Expand Down Expand Up @@ -827,7 +827,8 @@ kg.HeaderCell = function (col, rightHeaderGroup, grid) {
}, DELAY);
} else {
clearTimeout(timer); //prevent single-click action
grid.resizeOnDataCallback(self.column); //perform double-click action
grid.resizeOnData(self.column); //perform double-click action
kg.cssBuilder.buildStyles(grid);
clicks = 0; //after action performed, reset counter
}
};
Expand Down Expand Up @@ -976,7 +977,9 @@ kg.RowManager = function (grid) {
//null the row pointer for next iteration
row = null;
});

kg.utils.forEach(grid.config.plugins, function (p) {
p.onRowsChanged(grid, rowArr);
});
self.rows(rowArr);
});

Expand Down Expand Up @@ -2406,14 +2409,14 @@ kg.KoGrid = function (options, gridWidth) {
columnDefs.splice(targetCol, 0, { field: '__kg_selected__', width: self.elementDims.rowSelectedCellW });
}
}
var createColumnSortClosure = function (col) {
return function (dir) {

var createColumnSortClosure = function(col) {
return function(dir) {
if (dir) {
self.sortData(col, dir);
}
}
}
};
};

if (columnDefs.length > 0) {

Expand Down Expand Up @@ -2467,7 +2470,9 @@ kg.KoGrid = function (options, gridWidth) {
self.rows = self.rowManager.rows; // dependent observable

kg.cssBuilder.buildStyles(self);

kg.utils.forEach(self.config.plugins, function (p) {
p.onGridInit(self);
});
self.initPhase = 1;
};

Expand All @@ -2490,6 +2495,9 @@ kg.KoGrid = function (options, gridWidth) {
} else {
h_updateTimeout = setTimeout(updater, 0);
}
kg.utils.forEach(self.config.plugins, function(p) {
p.onGridUpdate(self);
});
};

this.showFilter_Click = function () {
Expand Down Expand Up @@ -2868,7 +2876,7 @@ ko.bindingHandlers['koGrid'] = (function () {
$element.addClass("kgGrid")
.addClass("ui-widget")
.addClass(grid.gridId.toString());

//make sure the templates are generated for the Grid
return ko.bindingHandlers['template'].init(element, makeNewValueAccessor(grid), allBindingsAccessor, grid, bindingContext);

Expand All @@ -2892,9 +2900,6 @@ ko.bindingHandlers['koGrid'] = (function () {
//now use the manager to assign the event handlers
kg.gridManager.assignGridEventHandlers(grid);

kg.utils.forEach(grid.config.plugins, function(p) {
p.init(grid);
});
//call update on the grid, which will refresh the dome measurements asynchronously
grid.update();

Expand Down
33 changes: 19 additions & 14 deletions build/KoGrid.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* koGrid JavaScript Library
* Authors: https://github.com/ericmbarnard/KoGrid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 11/05/2012 19:40:39
* Compiled At: 11/05/2012 21:34:40
***********************************************/


Expand Down Expand Up @@ -667,7 +667,7 @@ kg.Row = function (entity, config, selectionManager) {
var element = event.target;

//check and make sure its not the bubbling up of our checked 'click' event
if (element.type == "checkbox" && element.parentElement.className.indexOf("kgSelectionCell" !== -1)) {
if (element.type == "checkbox" && $(element).parent().attr('class').indexOf("kgSelectionCell" !== -1)) {
return true;
}
if (config.selectWithCheckboxOnly && element.type != "checkbox"){
Expand Down Expand Up @@ -827,7 +827,8 @@ kg.HeaderCell = function (col, rightHeaderGroup, grid) {
}, DELAY);
} else {
clearTimeout(timer); //prevent single-click action
grid.resizeOnDataCallback(self.column); //perform double-click action
grid.resizeOnData(self.column); //perform double-click action
kg.cssBuilder.buildStyles(grid);
clicks = 0; //after action performed, reset counter
}
};
Expand Down Expand Up @@ -976,7 +977,9 @@ kg.RowManager = function (grid) {
//null the row pointer for next iteration
row = null;
});

kg.utils.forEach(grid.config.plugins, function (p) {
p.onRowsChanged(grid, rowArr);
});
self.rows(rowArr);
});

Expand Down Expand Up @@ -2406,14 +2409,14 @@ kg.KoGrid = function (options, gridWidth) {
columnDefs.splice(targetCol, 0, { field: '__kg_selected__', width: self.elementDims.rowSelectedCellW });
}
}
var createColumnSortClosure = function (col) {
return function (dir) {

var createColumnSortClosure = function(col) {
return function(dir) {
if (dir) {
self.sortData(col, dir);
}
}
}
};
};

if (columnDefs.length > 0) {

Expand Down Expand Up @@ -2467,7 +2470,9 @@ kg.KoGrid = function (options, gridWidth) {
self.rows = self.rowManager.rows; // dependent observable

kg.cssBuilder.buildStyles(self);

kg.utils.forEach(self.config.plugins, function (p) {
p.onGridInit(self);
});
self.initPhase = 1;
};

Expand All @@ -2490,6 +2495,9 @@ kg.KoGrid = function (options, gridWidth) {
} else {
h_updateTimeout = setTimeout(updater, 0);
}
kg.utils.forEach(self.config.plugins, function(p) {
p.onGridUpdate(self);
});
};

this.showFilter_Click = function () {
Expand Down Expand Up @@ -2868,7 +2876,7 @@ ko.bindingHandlers['koGrid'] = (function () {
$element.addClass("kgGrid")
.addClass("ui-widget")
.addClass(grid.gridId.toString());

//make sure the templates are generated for the Grid
return ko.bindingHandlers['template'].init(element, makeNewValueAccessor(grid), allBindingsAccessor, grid, bindingContext);

Expand All @@ -2892,9 +2900,6 @@ ko.bindingHandlers['koGrid'] = (function () {
//now use the manager to assign the event handlers
kg.gridManager.assignGridEventHandlers(grid);

kg.utils.forEach(grid.config.plugins, function(p) {
p.init(grid);
});
//call update on the grid, which will refresh the dome measurements asynchronously
grid.update();

Expand Down
14 changes: 12 additions & 2 deletions plugins/koGrid-reorderable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@
self.config = $.extend(defaults, options);
self.myGrid = null;

// The init method gets called during the ng-grid directive execution.
self.init = function (grid) {
// The init method gets called during the koGrid binding handler execution.
self.onGridInit = function (grid) {
/* logic */

};
self.onGridUpdate = function (grid) {
/* logic */
// The directive passes in the grid scope and the grid object which we will want to save for manipulation later.
self.myGrid = grid;
// In this example we want to assign grid events.
self.assignEvents();
};
self.onRowsChanged = function (grid, rowCollection) {
/* logic */
};

//internal funcs
self.colToMove = undefined;
self.rowToMove = undefined;
self.assignEvents = function () {
Expand Down
5 changes: 1 addition & 4 deletions src/BindingHandlers/koGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ko.bindingHandlers['koGrid'] = (function () {
$element.addClass("kgGrid")
.addClass("ui-widget")
.addClass(grid.gridId.toString());

//make sure the templates are generated for the Grid
return ko.bindingHandlers['template'].init(element, makeNewValueAccessor(grid), allBindingsAccessor, grid, bindingContext);

Expand All @@ -88,9 +88,6 @@ ko.bindingHandlers['koGrid'] = (function () {
//now use the manager to assign the event handlers
kg.gridManager.assignGridEventHandlers(grid);

kg.utils.forEach(grid.config.plugins, function(p) {
p.init(grid);
});
//call update on the grid, which will refresh the dome measurements asynchronously
grid.update();

Expand Down
17 changes: 11 additions & 6 deletions src/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,14 @@ kg.KoGrid = function (options, gridWidth) {
columnDefs.splice(targetCol, 0, { field: '__kg_selected__', width: self.elementDims.rowSelectedCellW });
}
}
var createColumnSortClosure = function (col) {
return function (dir) {

var createColumnSortClosure = function(col) {
return function(dir) {
if (dir) {
self.sortData(col, dir);
}
}
}
};
};

if (columnDefs.length > 0) {

Expand Down Expand Up @@ -544,7 +544,9 @@ kg.KoGrid = function (options, gridWidth) {
self.rows = self.rowManager.rows; // dependent observable

kg.cssBuilder.buildStyles(self);

kg.utils.forEach(self.config.plugins, function (p) {
p.onGridInit(self);
});
self.initPhase = 1;
};

Expand All @@ -567,6 +569,9 @@ kg.KoGrid = function (options, gridWidth) {
} else {
h_updateTimeout = setTimeout(updater, 0);
}
kg.utils.forEach(self.config.plugins, function(p) {
p.onGridUpdate(self);
});
};

this.showFilter_Click = function () {
Expand Down
3 changes: 2 additions & 1 deletion src/GridClasses/HeaderCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
}, DELAY);
} else {
clearTimeout(timer); //prevent single-click action
grid.resizeOnDataCallback(self.column); //perform double-click action
grid.resizeOnData(self.column); //perform double-click action
kg.cssBuilder.buildStyles(grid);
clicks = 0; //after action performed, reset counter
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/GridClasses/Row.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ kg.Row = function (entity, config, selectionManager) {
var element = event.target;

//check and make sure its not the bubbling up of our checked 'click' event
if (element.type == "checkbox" && element.parentElement.className.indexOf("kgSelectionCell" !== -1)) {
if (element.type == "checkbox" && $(element).parent().attr('class').indexOf("kgSelectionCell" !== -1)) {
return true;
}
if (config.selectWithCheckboxOnly && element.type != "checkbox"){
Expand Down
4 changes: 3 additions & 1 deletion src/GridClasses/RowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@
//null the row pointer for next iteration
row = null;
});

kg.utils.forEach(grid.config.plugins, function (p) {
p.onRowsChanged(grid, rowArr);
});
self.rows(rowArr);
});

Expand Down
3 changes: 2 additions & 1 deletion tests/RowManager_Tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ kg.getTestGrid = function () {
config: {
rowHeight: 30,
currentPage: ko.observable(1),
pageSize: ko.observable(100)
pageSize: ko.observable(100),
plugins: []
},
changeSelectedItem: function (handler) {

Expand Down

0 comments on commit 27028c8

Please sign in to comment.