Skip to content

Commit

Permalink
hotfixes!
Browse files Browse the repository at this point in the history
  • Loading branch information
orneryd committed Dec 18, 2012
1 parent c954924 commit 53df68f
Show file tree
Hide file tree
Showing 31 changed files with 1,209 additions and 837 deletions.
680 changes: 402 additions & 278 deletions build/KoGrid.debug.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Add-Content $TempFile "* Authors: https://github.com/ericmbarnard/koGrid/blob/ma
Add-Content $TempFile "* License: MIT (http://www.opensource.org/licenses/mit-license.php)";
Add-Content $TempFile "* Compiled At: $compileTime";
Add-Content $TempFile "***********************************************/`n"
Add-Content $TempFile "(function(window, undefined){";
Add-Content $TempFile "(function (window) {";
Add-Content $TempFile "'use strict';";
Foreach ($file in $files){
# Wrap each file output in a new line
Write-Host "Building... $file";
Expand Down
680 changes: 402 additions & 278 deletions koGrid-2.1.1.debug.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/koGrid-reorderable.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
// Splice the columns
var cols = self.myGrid.columns();
var coldefs = self.myGrid.config.columnDefs();
kg.utils.forEach(cols, function(col, i) {
window.kg.utils.forEach(cols, function (col, i) {
coldefs[i].width = col.width();
});
coldefs.splice(self.colToMove.column.index, 1);
Expand Down
4 changes: 2 additions & 2 deletions plugins/koGridLayoutPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ koGridLayoutPlugin = function () {
self.grid = grid;
};
this.updateGridLayout = function(){
kg.domUtilityService.UpdateGridLayout(self.grid);
window.kg.domUtilityService.UpdateGridLayout(self.grid);
self.grid.configureColumnWidths();
kg.domUtilityService.BuildStyles(self.grid);
window.kg.domUtilityService.BuildStyles(self.grid);
};
}
2 changes: 1 addition & 1 deletion src/bindingHandlers/kg-mouse-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ ko.bindingHandlers['mouseEvents'] = (function () {
if (eFuncs.mouseDown) {
$(element).mousedown(eFuncs.mouseDown);
}
},
}
};
}());
6 changes: 3 additions & 3 deletions src/bindingHandlers/kg-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ ko.bindingHandlers['kgRow'] = (function () {
var grid = row.$grid = bindingContext.$parent;
var source;
if (row.isAggRow) {
source = kg.aggregateTemplate();
source = window.kg.aggregateTemplate();
} else {
source = grid.rowTemplate;
}
var compile = function (html) {
var compile = function(html) {
var rowElem = $(html);
row.$userViewModel = bindingContext.$parent.$userViewModel;
ko.applyBindings(row, rowElem[0]);
$(element).html(rowElem);
}
};
if (source.then) {
source.then(function (p) {
compile(p);
Expand Down
19 changes: 11 additions & 8 deletions src/bindingHandlers/ko-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
'init': function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var options = valueAccessor();
var elem = $(element);
options.gridDim = new kg.Dimension({ outerHeight: ko.observable(elem.height()), outerWidth: ko.observable(elem.width()) });
var grid = new kg.Grid(options);
var gridElem = $(kg.defaultGridTemplate());
options.gridDim = new window.kg.Dimension({ outerHeight: ko.observable(elem.height()), outerWidth: ko.observable(elem.width()) });
var grid = new window.kg.Grid(options);
var gridElem = $(window.kg.defaultGridTemplate());
// if it is a string we can watch for data changes. otherwise you won't be able to update the grid data
options.data.subscribe(function () {
if (grid.$$selectionPhase) return;
if (grid.$$selectionPhase) {
return;
}
grid.searchProvider.evalFilter();
grid.refreshDomSizes();
});
Expand All @@ -27,17 +29,18 @@
grid.$userViewModel = bindingContext.$data;
ko.applyBindings(grid, gridElem[0]);
//walk the element's graph and the correct properties on the grid
kg.domUtilityService.AssignGridContainers(elem, grid);
window.kg.domUtilityService.AssignGridContainers(elem, grid);
grid.configureColumnWidths();
grid.refreshDomSizes();
//now use the manager to assign the event handlers
grid.eventProvider = new kg.EventProvider(grid);
grid.eventProvider = new window.kg.EventProvider(grid);
//initialize plugins.
$.each(grid.config.plugins, function (i, p) {
if (typeof p.onGridInit === 'function')
if (typeof p.onGridInit === 'function') {
p.onGridInit(grid);
}
});
kg.domUtilityService.BuildStyles(grid);
window.kg.domUtilityService.BuildStyles(grid);
return { controlsDescendantBindings: true };
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/classes/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// <reference path="../namespace.js" />
/// <reference path="../navigation.js"/>
/// <reference path="../utils.js"/>
kg.Aggregate = function (aggEntity, rowFactory) {
window.kg.Aggregate = function (aggEntity, rowFactory) {
var self = this;
self.index = 0;
self.offsetTop = ko.observable(0);
Expand Down
33 changes: 18 additions & 15 deletions src/classes/column.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
kg.Column = function (config, grid) {
window.kg.Column = function (config, grid) {
var self = this,
colDef = config.colDef,
delay = 500,
clicks = 0,
timer = null;
self.eventTaget = undefined;
self.width = colDef.width;
self.groupIndex = ko.observable(0);
self.isGroupedBy = ko.observable(false);
self.groupedByClass = ko.computed(function(){ return self.isGroupedBy() ? "kgGroupedByIcon":"kgGroupIcon";});
self.groupedByClass = ko.computed(function(){ return self.isGroupedBy() ? "kgGroupedByIcon": "kgGroupIcon";});
self.sortable = ko.observable(false);
self.resizable = ko.observable(false);
self.minWidth = !colDef.minWidth ? 50 : colDef.minWidth;
Expand All @@ -20,7 +21,7 @@
self.cellFilter = colDef.cellFilter || colDef.cellFormatter;
self.field = colDef.field;
self.aggLabelFilter = colDef.cellFilter || colDef.cellFormatter || colDef.aggLabelFilter || colDef.aggLabelFormatter;
self._visible = ko.observable(kg.utils.isNullOrUndefined(colDef.visible) || colDef.visible);
self._visible = ko.observable(window.kg.utils.isNullOrUndefined(colDef.visible) || colDef.visible);
self.visible = ko.computed({
read: function() {
return self._visible();
Expand All @@ -30,21 +31,21 @@
}
});
if (config.enableSort) {
self.sortable(kg.utils.isNullOrUndefined(colDef.sortable) || colDef.sortable);
self.sortable(window.kg.utils.isNullOrUndefined(colDef.sortable) || colDef.sortable);
}
if (config.enableResize) {
self.resizable(kg.utils.isNullOrUndefined(colDef.resizable) || colDef.resizable);
self.resizable(window.kg.utils.isNullOrUndefined(colDef.resizable) || colDef.resizable);
}
self.sortDirection = ko.observable(undefined);
self.sortingAlgorithm = colDef.sortFn;
self.headerClass = ko.observable(colDef.headerClass);
self.headerCellTemplate = colDef.headerCellTemplate || kg.defaultHeaderCellTemplate();
self.cellTemplate = colDef.cellTemplate || kg.defaultCellTemplate();
self.headerCellTemplate = colDef.headerCellTemplate || window.kg.defaultHeaderCellTemplate();
self.cellTemplate = colDef.cellTemplate || window.kg.defaultCellTemplate();
if (colDef.cellTemplate && !TEMPLATE_REGEXP.test(colDef.cellTemplate)) {
self.cellTemplate = kg.utils.getTemplatePromise(colDef.cellTemplate);
self.cellTemplate = window.kg.utils.getTemplatePromise(colDef.cellTemplate);
}
if (colDef.headerCellTemplate && !TEMPLATE_REGEXP.test(colDef.headerCellTemplate)) {
self.headerCellTemplate = kg.utils.getTemplatePromise(colDef.headerCellTemplate);
self.headerCellTemplate = window.kg.utils.getTemplatePromise(colDef.headerCellTemplate);
}
self.getProperty = function (row) {
var ret;
Expand All @@ -57,13 +58,13 @@
};
self.toggleVisible = function (val) {
var v;
if (kg.utils.isNullOrUndefined(val) || typeof val == "object") {
if (window.kg.utils.isNullOrUndefined(val) || typeof val == "object") {
v = !self._visible();
} else {
v = val;
}
self._visible(v);
kg.domUtilityService.BuildStyles(grid);
window.kg.domUtilityService.BuildStyles(grid);
};

self.showSortButtonUp = ko.computed(function () {
Expand Down Expand Up @@ -102,11 +103,12 @@
event.stopPropagation();
if (event.ctrlKey) {
self.toggleVisible();
kg.domUtilityService.BuildStyles(grid);
window.kg.domUtilityService.BuildStyles(grid);
grid.config.columnsChanged(grid.columns.peek());
return true;
}
event.target.parentElement.style.cursor = 'col-resize';
self.eventTaget = event.target.parentElement;
self.eventTaget.style.cursor = 'col-resize';
self.startMousePosition = event.clientX;
self.origWidth = self.width;
$(document).mousemove(self.onMouseMove);
Expand All @@ -118,14 +120,15 @@
var diff = event.clientX - self.startMousePosition;
var newWidth = diff + self.origWidth;
self.width = (newWidth < self.minWidth ? self.minWidth : (newWidth > self.maxWidth ? self.maxWidth : newWidth));
kg.domUtilityService.BuildStyles(grid);
window.kg.domUtilityService.BuildStyles(grid);
return false;
};
self.gripOnMouseUp = function (event) {
event.stopPropagation();
$(document).off('mousemove');
$(document).off('mouseup');
event.target.parentElement.style.cursor = 'default';
self.eventTaget.style.cursor = self.sortable() ? 'pointer' : 'default';
self.eventTaget = undefined;
grid.config.columnsChanged(grid.columns.peek());
return false;
};
Expand Down
2 changes: 1 addition & 1 deletion src/classes/dimension.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kg.Dimension = function (options) {
window.kg.Dimension = function (options) {
this.outerHeight = null;
this.outerWidth = null;
$.extend(this, options);
Expand Down
14 changes: 7 additions & 7 deletions src/classes/domUtilityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ var getWidths = function () {
//measure Scroll Bars
$testContainer.height(100).width(100).css("position", "absolute").css("overflow", "scroll");
$testContainer.append('<div style="height: 400px; width: 400px;"></div>');
kg.domUtilityService.ScrollH = ($testContainer.height() - $testContainer[0].clientHeight);
kg.domUtilityService.ScrollW = ($testContainer.width() - $testContainer[0].clientWidth);
window.kg.domUtilityService.ScrollH = ($testContainer.height() - $testContainer[0].clientHeight);
window.kg.domUtilityService.ScrollW = ($testContainer.width() - $testContainer[0].clientWidth);
$testContainer.empty();
//clear styles
$testContainer.attr('style', '');
//measure letter sizes using a pretty typical font size and fat font-family
$testContainer.append('<span style="font-family: Verdana, Helvetica, Sans-Serif; font-size: 14px;"><strong>M</strong></span>');
kg.domUtilityService.LetterW = $testContainer.children().first().width();
window.kg.domUtilityService.LetterW = $testContainer.children().first().width();
$testContainer.remove();
};
kg.domUtilityService = {
window.kg.domUtilityService = {
AssignGridContainers: function (rootEl, grid) {
grid.$root = $(rootEl);
//Headers
Expand All @@ -37,7 +37,7 @@ kg.domUtilityService = {
grid.$canvas = grid.$viewport.find(".kgCanvas");
//Footers
grid.$footerPanel = grid.$root.find(".ngFooterPanel");
kg.domUtilityService.UpdateGridLayout(grid);
window.kg.domUtilityService.UpdateGridLayout(grid);
},
UpdateGridLayout: function(grid) {
//catch this so we can return the viewer to their original scroll after the resize!
Expand Down Expand Up @@ -70,13 +70,13 @@ kg.domUtilityService = {
"." + gridId + " .kgCell { height: " + rowHeight + "px; }"+
"." + gridId + " .kgCanvas { width: " + trw + "px; }" +
"." + gridId + " .kgHeaderCell { top: 0; bottom: 0; }" +
"." + gridId + " .kgHeaderScroller { width: " + (trw + kg.domUtilityService.scrollH + 2) + "px}";
"." + gridId + " .kgHeaderScroller { width: " + (trw + window.kg.domUtilityService.scrollH + 2) + "px}";
$.each(cols, function (i, col) {
css += "." + gridId + " .col" + i + " { width: " + col.width + "px; left: " + sumWidth + "px; right: " + (trw - sumWidth - col.width) + "px; height: " + rowHeight + "px }" +
"." + gridId + " .colt" + i + " { width: " + col.width + "px; }";
sumWidth += col.width;
});
if (kg.utils.isIe) { // IE
if (window.kg.utils.isIe) { // IE
$style[0].styleSheet.cssText = css;
} else {
$style.append(document.createTextNode(css));
Expand Down
46 changes: 31 additions & 15 deletions src/classes/eventProvider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference path="../namespace.js" />
/// <reference path="../../lib/knockout-2.2.0.js" />
kg.EventProvider = function (grid) {
window.kg.EventProvider = function (grid) {
var self = this;
// The init method gets called during the ng-grid directive execution.
self.colToMove = undefined;
Expand Down Expand Up @@ -112,50 +112,63 @@ kg.EventProvider = function (grid) {
self.onHeaderMouseDown = function (event) {
// Get the closest header container from where we clicked.
var headerContainer = $(event.target).closest('.kgHeaderSortColumn');
if (!headerContainer[0]) return true;
if (!headerContainer[0]) {
return true;
}
// Get the scope from the header container

var headerScope = ko.dataFor(headerContainer[0]);
if (headerScope) {
// Save the column for later.
self.colToMove = { header: headerContainer, col: headerScope };
}
return true;
};

self.onHeaderDrop = function (event) {
if (!self.colToMove) return true;
if (!self.colToMove) {
return true;
}
// Get the closest header to where we dropped
var headerContainer = $(event.target).closest('.kgHeaderSortColumn');
if (!headerContainer[0]) return true;
if (!headerContainer[0]) {
return true;
}
// Get the scope from the header.
var headerScope = ko.dataFor(headerContainer[0]);
if (headerScope) {
// If we have the same column, do nothing.
if (self.colToMove.col == headerScope) return true;
if (self.colToMove.col == headerScope) {
return true;
}
// Splice the columns
var cols = grid.columns();
var cols = grid.columns.peek();
cols.splice(self.colToMove.col.index, 1);
cols.splice(headerScope.index, 0, self.colToMove.col);
grid.fixColumnIndexes();
grid.columns(cols);
// Finally, rebuild the CSS styles.
kg.domUtilityService.BuildStyles(grid);
window.kg.domUtilityService.BuildStyles(grid);
// clear out the colToMove object
self.colToMove = undefined;
}
return true;
};

// Row functions
self.onRowMouseDown = function (event) {
// Get the closest row element from where we clicked.
var targetRow = $(event.target).closest('.kgRow');
if (!targetRow[0]) return;
if (!targetRow[0]) {
return;
}
// Get the scope from the row element
var rowScope = ko.dataFor(targetRow[0]);
if (rowScope) {
// set draggable events
targetRow.attr('draggable', 'true');
// Save the row for later.
kg.eventStorage.rowToMove = { targetRow: targetRow, scope: rowScope };
window.kg.eventStorage.rowToMove = { targetRow: targetRow, scope: rowScope };
}
};

Expand All @@ -166,8 +179,10 @@ kg.EventProvider = function (grid) {
var rowScope = ko.dataFor(targetRow[0]);
if (rowScope) {
// If we have the same Row, do nothing.
var prevRow = kg.eventStorage.rowToMove;
if (prevRow.scope == rowScope) return;
var prevRow = window.kg.eventStorage.rowToMove;
if (prevRow.scope == rowScope) {
return;
}
// Splice the Rows via the actual datasource
var sd = grid.sortedData();
var i = sd.indexOf(prevRow.scope.entity);
Expand All @@ -176,7 +191,7 @@ kg.EventProvider = function (grid) {
grid.sortedData.splice(j, 0, prevRow.scope.entity);
grid.searchProvider.evalFilter();
// clear out the rowToMove object
kg.eventStorage.rowToMove = undefined;
window.kg.eventStorage.rowToMove = undefined;
// if there isn't an apply already in progress lets start one
}
};
Expand All @@ -189,20 +204,21 @@ kg.EventProvider = function (grid) {
});
grid.$viewport.off('keydown');
grid.$viewport.on('keydown', function(e) {
return kg.moveSelectionHandler(grid, e);
return window.kg.moveSelectionHandler(grid, e);
});
//Chrome and firefox both need a tab index so the grid can recieve focus.
//need to give the grid a tabindex if it doesn't already have one so
//we'll just give it a tab index of the corresponding gridcache index
//that way we'll get the same result every time it is run.
//configurable within the options.
if (grid.config.tabIndex === -1) {
grid.$viewport.attr('tabIndex', kg.numberOfGrids++);
grid.$viewport.attr('tabIndex', window.kg.numberOfGrids);
window.kg.numberOfGrids++;
} else {
grid.$viewport.attr('tabIndex', grid.config.tabIndex);
}
$(window).resize(function() {
kg.domUtilityService.UpdateGridLayout(grid);
window.kg.domUtilityService.UpdateGridLayout(grid);
if (grid.config.maintainColumnRatios) {
grid.configureColumnWidths();
}
Expand Down
Loading

0 comments on commit 53df68f

Please sign in to comment.