diff --git a/build/KoGrid.debug.js b/build/KoGrid.debug.js
index 2c62756b..bc392d50 100644
--- a/build/KoGrid.debug.js
+++ b/build/KoGrid.debug.js
@@ -2,10 +2,11 @@
* 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: 12/18/2012 12:55:08
+* Compiled At: 12/18/2012 15:27:17
***********************************************/
-(function(window, undefined){
+(function (window) {
+'use strict';
/***********************************************
* FILE: ..\src\namespace.js
@@ -13,41 +14,46 @@
if (!window.kg) {
window.kg = {};
}
-kg.numberOfGrids = 0;
-kg.eventStorage = {};
+window.kg.numberOfGrids = 0;
+window.kg.eventStorage = {};
/***********************************************
* FILE: ..\src\constants.js
***********************************************/
-var SELECTED_PROP = '__kg_selected__';
-var GRID_KEY = '__koGrid__';
-// the # of rows we want to add to the top and bottom of the rendered grid rows
-var EXCESS_ROWS = 8;
-var SCROLL_THRESHOLD = 6;
-var ASC = "asc"; // constant for sorting direction
-var DESC = "desc"; // constant for sorting direction
-var KG_FIELD = '_kg_field_';
-var KG_DEPTH = '_kg_depth_';
-var KG_HIDDEN = '_kg_hidden_';
-var KG_COLUMN = '_kg_column_';
-var TEMPLATE_REGEXP = /<.+>/;
+var SELECTED_PROP = '__kg_selected__',
+ GRID_KEY = '__koGrid__',
+ // the # of rows we want to add to the top and bottom of the rendered grid rows
+ EXCESS_ROWS = 8,
+ SCROLL_THRESHOLD = 6,
+ ASC = "asc", // constant for sorting direction
+ DESC = "desc", // constant for sorting direction
+ KG_FIELD = '_kg_field_',
+ KG_DEPTH = '_kg_depth_',
+ KG_HIDDEN = '_kg_hidden_',
+ KG_COLUMN = '_kg_column_',
+ TEMPLATE_REGEXP = /<.+>/;
/***********************************************
* FILE: ..\src\navigation.js
***********************************************/
//set event binding on the grid so we can select using the up/down keys
-kg.moveSelectionHandler = function (grid, evt) {
+window.kg.moveSelectionHandler = function(grid, evt) {
// null checks
- if (grid === null || grid === undefined) return true;
- if (grid.config.selectedItems === undefined) return true;
+ if (window.kg.utils.isNullOrUndefined(grid) || window.kg.utils.isNullOrUndefined(grid.config.selectedItems)) {
+ return true;
+ }
var charCode = (evt.which) ? evt.which : event.keyCode;
// detect which direction for arrow keys to navigate the grid
var offset = (charCode == 38 ? -1 : (charCode == 40 ? 1 : null));
- if (!offset) return true;
+ if (!offset) {
+ return true;
+ }
var items = grid.renderedRows();
var index = items.indexOf(grid.selectionService.lastClickedRow) + offset;
- if (index < 0 || index >= items.length) return true;
- grid.selectionService.ChangeSelection(items[index], evt);
+ if (index < 0 || index >= items.length) {
+ return true;
+ }
+grid.selectionService.ChangeSelection(items[index], evt);
if (index > items.length - EXCESS_ROWS) {
grid.$viewport.scrollTop(grid.$viewport.scrollTop() + (grid.config.rowHeight * EXCESS_ROWS));
} else if (index < EXCESS_ROWS) {
@@ -64,43 +70,45 @@ if (!String.prototype.trim) {
return this.replace(/^\s+|\s+$/g, '');
};
}
-if (!Array.prototype.indexOf)
-{
- Array.prototype.indexOf = function(elt /*, from*/){
- var len = this.length >>> 0;
- var from = Number(arguments[1]) || 0;
- from = (from < 0) ? Math.ceil(from) : Math.floor(from);
- if (from < 0) from += len;
- for (; from < len; from++){
- if (from in this && this[from] === elt) return from;
- }
- return -1;
- };
+if (!Array.prototype.indexOf) {
+ Array.prototype.indexOf = function(elt /*, from*/) {
+ var len = this.length >>> 0;
+ var from = Number(arguments[1]) || 0;
+ from = (from < 0) ? Math.ceil(from) : Math.floor(from);
+ if (from < 0) {
+ from += len;
+ }
+ for (; from < len; from++) {
+ if (from in this && this[from] === elt) {
+ return from;
+ }
+ }
+ return -1;
+ };
}
-if (!Array.prototype.filter)
-{
- Array.prototype.filter = function(fun /*, thisp */)
- {
- "use strict";
- var t = Object(this);
- var len = t.length >>> 0;
- if (typeof fun !== "function")throw new TypeError();
- var res = [];
- var thisp = arguments[1];
- for (var i = 0; i < len; i++)
- {
- if (i in t)
- {
- var val = t[i]; // in case fun mutates this
- if (fun.call(thisp, val, i, t))
- res.push(val);
- }
- }
- return res;
- };
+if (!Array.prototype.filter) {
+ Array.prototype.filter = function(fun /*, thisp */) {
+ "use strict";
+ var t = Object(this);
+ var len = t.length >>> 0;
+ if (typeof fun !== "function") {
+ throw new TypeError();
+ }
+ var res = [];
+ var thisp = arguments[1];
+ for (var i = 0; i < len; i++) {
+ if (i in t) {
+ var val = t[i]; // in case fun mutates this
+ if (fun.call(thisp, val, i, t)) {
+ res.push(val);
+ }
+ }
+ }
+ return res;
+ };
}
-kg.utils = {
- visualLength: function (node) {
+window.kg.utils = {
+ visualLength: function(node) {
var elem = document.getElementById('testDataLength');
if (!elem) {
elem = document.createElement('SPAN');
@@ -112,104 +120,110 @@ kg.utils = {
elem.innerHTML = $(node).text();
return elem.offsetWidth;
},
- forIn: function (obj, action) {
- for (var prop in obj) {
- if(obj.hasOwnProperty(prop)){
+ forIn: function(obj, action) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) {
action(obj[prop], prop);
}
}
},
- evalProperty: function (entity, path) {
+ evalProperty: function(entity, path) {
var e = ko.utils.unwrapObservable(entity);
var propPath = path.split('.'), i = 0;
- var tempProp = ko.utils.unwrapObservable(e[propPath[i++]]), links = propPath.length;
+ var tempProp = ko.utils.unwrapObservable(e[propPath[i]]), links = propPath.length;
+ i++;
while (tempProp && i < links) {
- tempProp = ko.utils.unwrapObservable(tempProp[propPath[i++]]);
+ tempProp = ko.utils.unwrapObservable(tempProp[propPath[i]]);
+ i++;
}
return tempProp;
},
- endsWith: function (str, suffix) {
- if (!str || !suffix || typeof str != "string") return false;
+ endsWith: function(str, suffix) {
+ if (!str || !suffix || typeof str != "string") {
+ return false;
+ }
return str.indexOf(suffix, str.length - suffix.length) !== -1;
},
- isNullOrUndefined: function (obj) {
- if (obj === undefined || obj === null) return true;
+ isNullOrUndefined: function(obj) {
+ if (obj === undefined || obj === null) {
+ return true;
+ }
return false;
},
getElementsByClassName: function(cl) {
var retnode = [];
- var myclass = new RegExp('\\b'+cl+'\\b');
+ var myclass = new RegExp('\\b' + cl + '\\b');
var elem = document.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
- if (myclass.test(classes)) retnode.push(elem[i]);
+ if (myclass.test(classes)) {
+ retnode.push(elem[i]);
+ }
}
return retnode;
},
getTemplatePromise: function(path) {
return $.ajax(path);
},
- newId: (function () {
+ newId: (function() {
var seedId = new Date().getTime();
- return function () {
+ return function() {
return seedId += 1;
};
})(),
// we copy KO's ie detection here bc it isn't exported in the min versions of KO
// Detect IE versions for workarounds (uses IE conditionals, not UA string, for robustness)
- ieVersion: (function () {
+ ieVersion: (function() {
var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');
// Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
- while (
- div.innerHTML = '',
- iElems[0]
- );
+ while (div.innerHTML = '',
+ iElems[0]) ;
return version > 4 ? version : undefined;
})()
};
-$.extend(kg.utils, {
- isIe6: (function(){
- return kg.utils.ieVersion === 6;
+$.extend(window.kg.utils, {
+ isIe6: (function() {
+ return window.kg.utils.ieVersion === 6;
+ })(),
+ isIe7: (function() {
+ return window.kg.utils.ieVersion === 7;
})(),
- isIe7: (function(){
- return kg.utils.ieVersion === 7;
- } )(),
- isIe: (function () {
- return kg.utils.ieVersion !== undefined;
+ isIe: (function() {
+ return window.kg.utils.ieVersion !== undefined;
})()
-});
+});
/***********************************************
* FILE: ..\src\templates\gridTemplate.html
***********************************************/
-kg.defaultGridTemplate = function(){ return '
Drag a column header here and drop it to group by that column
';};
+window.kg.defaultGridTemplate = function(){ return 'Drag a column header here and drop it to group by that column
';};
/***********************************************
* FILE: ..\src\templates\rowTemplate.html
***********************************************/
-kg.defaultRowTemplate = function(){ return '';};
+window.kg.defaultRowTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\templates\cellTemplate.html
***********************************************/
-kg.defaultCellTemplate = function(){ return '';};
+window.kg.defaultCellTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\templates\aggregateTemplate.html
***********************************************/
-kg.aggregateTemplate = function(){ return '';};
+window.kg.aggregateTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\templates\headerRowTemplate.html
***********************************************/
-kg.defaultHeaderRowTemplate = function(){ return '';};
+window.kg.defaultHeaderRowTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\templates\headerCellTemplate.html
***********************************************/
-kg.defaultHeaderCellTemplate = function(){ return '';};
+window.kg.defaultHeaderCellTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\bindingHandlers\ko-grid.js
@@ -219,12 +233,14 @@ ko.bindingHandlers['koGrid'] = (function () {
'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();
});
@@ -243,17 +259,18 @@ ko.bindingHandlers['koGrid'] = (function () {
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 };
}
};
@@ -269,16 +286,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);
@@ -373,14 +390,14 @@ ko.bindingHandlers['mouseEvents'] = (function () {
if (eFuncs.mouseDown) {
$(element).mousedown(eFuncs.mouseDown);
}
- },
+ }
};
}());
/***********************************************
* FILE: ..\src\classes\aggregate.js
***********************************************/
-kg.Aggregate = function (aggEntity, rowFactory) {
+window.kg.Aggregate = function (aggEntity, rowFactory) {
var self = this;
self.index = 0;
self.offsetTop = ko.observable(0);
@@ -461,16 +478,17 @@ kg.Aggregate = function (aggEntity, rowFactory) {
/***********************************************
* FILE: ..\src\classes\column.js
***********************************************/
-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;
@@ -483,7 +501,7 @@ kg.Column = function (config, grid) {
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();
@@ -493,21 +511,21 @@ kg.Column = function (config, grid) {
}
});
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;
@@ -520,13 +538,13 @@ kg.Column = function (config, grid) {
};
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 () {
@@ -565,11 +583,12 @@ kg.Column = function (config, grid) {
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);
@@ -581,14 +600,15 @@ kg.Column = function (config, grid) {
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;
};
@@ -597,7 +617,7 @@ kg.Column = function (config, grid) {
/***********************************************
* FILE: ..\src\classes\dimension.js
***********************************************/
-kg.Dimension = function (options) {
+window.kg.Dimension = function (options) {
this.outerHeight = null;
this.outerWidth = null;
$.extend(this, options);
@@ -606,7 +626,7 @@ kg.Dimension = function (options) {
/***********************************************
* FILE: ..\src\classes\eventProvider.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;
@@ -718,7 +738,9 @@ 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]);
@@ -726,42 +748,53 @@ kg.EventProvider = function (grid) {
// 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 };
}
};
@@ -772,8 +805,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);
@@ -782,7 +817,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
}
};
@@ -795,7 +830,7 @@ 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
@@ -803,12 +838,13 @@ kg.EventProvider = function (grid) {
//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();
}
@@ -822,7 +858,7 @@ kg.EventProvider = function (grid) {
/***********************************************
* FILE: ..\src\classes\rowFactory.js
***********************************************/
-kg.RowFactory = function(grid) {
+window.kg.RowFactory = function (grid) {
var self = this;
// we cache rows when they are built, and then blow the cache away when sorting
self.rowCache = [];
@@ -845,7 +881,7 @@ kg.RowFactory = function(grid) {
afterSelectionChangeCallback: grid.config.afterSelectionChange
};
- self.renderedRange = new kg.Range(0, grid.minRowsToRender() + EXCESS_ROWS);
+ self.renderedRange = new window.kg.Range(0, grid.minRowsToRender() + EXCESS_ROWS);
// Builds rows for each data item in the 'filteredData'
// @entity - the data item
// @rowIndex - the index of the row
@@ -853,7 +889,7 @@ kg.RowFactory = function(grid) {
var row = self.rowCache[rowIndex]; // first check to see if we've already built it
if (!row) {
// build the row
- row = new kg.Row(entity, self.rowConfig, self.selectionService);
+ row = new window.kg.Row(entity, self.rowConfig, self.selectionService);
row.rowIndex(rowIndex + 1); //not a zero-based rowIndex
row.offsetTop((self.rowHeight * rowIndex).toString() + 'px');
row.selected(entity[SELECTED_PROP]);
@@ -867,7 +903,7 @@ kg.RowFactory = function(grid) {
var agg = self.aggCache[aggEntity.aggIndex]; // first check to see if we've already built it
if (!agg) {
// build the row
- agg = new kg.Aggregate(aggEntity, self);
+ agg = new window.kg.Aggregate(aggEntity, self);
self.aggCache[aggEntity.aggIndex] = agg;
}
agg.index = rowIndex + 1; //not a zero-based rowIndex
@@ -953,9 +989,10 @@ kg.RowFactory = function(grid) {
'_kg_hidden_': false,
children: [],
aggChildren: [],
- aggIndex: self.numberOfAggregates++,
+ aggIndex: self.numberOfAggregates,
aggLabelFilter: g[KG_COLUMN].aggLabelFilter
}, 0);
+ self.numberOfAggregates++;
//set the aggregate parent to the parent in the array that is one less deep.
agg.parent = self.parentCache[agg.depth - 1];
// if we have a parent, set the parent to not be collapsed and append the current agg to its children
@@ -989,31 +1026,43 @@ kg.RowFactory = function(grid) {
var ptr = self.groupedData;
$.each(groups, function(depth, group) {
if (!cols[depth].isAggCol && depth <= maxDepth) {
- grid.columns.splice(item.gDepth, 0, new kg.Column({
+ grid.columns.splice(item.gDepth, 0, new window.kg.Column({
colDef: {
field: '',
width: 25,
sortable: false,
resizable: false,
- headerCellTemplate: '',
+ headerCellTemplate: ''
},
isAggCol: true,
index: item.gDepth,
headerRowHeight: grid.config.headerRowHeight
}));
- kg.domUtilityService.BuildStyles(grid);
+ window.kg.domUtilityService.BuildStyles(grid);
}
var col = cols.filter(function (c) { return c.field == group; })[0];
- var val = kg.utils.evalProperty(item, group);
- if (col.cellFilter) val = col.cellFilter(val);
+ var val = window.kg.utils.evalProperty(item, group);
+ if (col.cellFilter) {
+ val = col.cellFilter(val);
+ }
val = val ? val.toString() : 'null';
- if (!ptr[val]) ptr[val] = {};
- if (!ptr[KG_FIELD]) ptr[KG_FIELD] = group;
- if (!ptr[KG_DEPTH]) ptr[KG_DEPTH] = depth;
- if (!ptr[KG_COLUMN]) ptr[KG_COLUMN] = col;
+ if (!ptr[val]) {
+ ptr[val] = {};
+ }
+ if (!ptr[KG_FIELD]) {
+ ptr[KG_FIELD] = group;
+ }
+ if (!ptr[KG_DEPTH]) {
+ ptr[KG_DEPTH] = depth;
+ }
+ if (!ptr[KG_COLUMN]) {
+ ptr[KG_COLUMN] = col;
+ }
ptr = ptr[val];
});
- if (!ptr.values) ptr.values = [];
+ if (!ptr.values) {
+ ptr.values = [];
+ }
ptr.values.push(item);
});
grid.fixColumnIndexes();
@@ -1029,7 +1078,7 @@ kg.RowFactory = function(grid) {
/***********************************************
* FILE: ..\src\classes\grid.js
***********************************************/
-kg.Grid = function (options) {
+window.kg.Grid = function (options) {
var defaults = {
rowHeight: 30,
columnWidth: 100,
@@ -1068,7 +1117,7 @@ kg.Grid = function (options) {
disableTextSelection: true,
filterOptions: {
filterText: ko.observable(""),
- useExternalFilter: false,
+ useExternalFilter: false
},
//Paging
enablePaging: false,
@@ -1076,8 +1125,8 @@ kg.Grid = function (options) {
pageSizes: ko.observableArray([250, 500, 1000]), //page Sizes
pageSize: ko.observable(250), //Size of Paging data
totalServerItems: ko.observable(0), //how many items are on the server (for paging)
- currentPage: ko.observable(1), //what page they are currently on
- },
+ currentPage: ko.observable(1) //what page they are currently on
+ }
},
self = this;
@@ -1085,7 +1134,7 @@ kg.Grid = function (options) {
//self vars
self.config = $.extend(defaults, options);
self.config.columnDefs = ko.utils.unwrapObservable(options.columnDefs);
- self.gridId = "ng" + kg.utils.newId();
+ self.gridId = "ng" + window.kg.utils.newId();
self.$root = null; //this is the root element that is passed in with the binding handler
self.$groupPanel = null;
self.$topPanel = null;
@@ -1114,7 +1163,7 @@ kg.Grid = function (options) {
rowIndexCellW: 25,
rowSelectedCellW: 25,
rootMaxW: 0,
- rootMaxH: 0,
+ rootMaxH: 0
};
//self funcs
self.setRenderedRows = function (newRows) {
@@ -1142,7 +1191,7 @@ kg.Grid = function (options) {
var item;
item = sd[0];
- kg.utils.forIn(item, function (prop, propName) {
+ window.kg.utils.forIn(item, function (prop, propName) {
if (propName != SELECTED_PROP) {
self.config.columnDefs.push({
field: propName
@@ -1170,7 +1219,7 @@ kg.Grid = function (options) {
}
if (columnDefs.length > 0) {
$.each(columnDefs, function (i, colDef) {
- var column = new kg.Column({
+ var column = new window.kg.Column({
colDef: colDef,
index: i,
headerRowHeight: self.config.headerRowHeight,
@@ -1199,11 +1248,11 @@ kg.Grid = function (options) {
$.each(cols, function (i, col) {
var isPercent = false, t = undefined;
//if width is not defined, set it to a single star
- if (kg.utils.isNullOrUndefined(col.width)) {
+ if (window.kg.utils.isNullOrUndefined(col.width)) {
col.width = "*";
} else { // get column width
- isPercent = isNaN(col.width) ? kg.utils.endsWith(col.width, "%") : false;
- t = isPercent ? col.width : parseInt(col.width);
+ isPercent = isNaN(col.width) ? window.kg.utils.endsWith(col.width, "%") : false;
+ t = isPercent ? col.width : parseInt(col.width, 10);
}
// check if it is a number
if (isNaN(t)) {
@@ -1227,7 +1276,7 @@ kg.Grid = function (options) {
throw "unable to parse column width, use percentage (\"10%\",\"20%\", etc...) or \"*\" to use remaining width of grid";
}
} else {
- totalWidth += columns[i].width = parseInt(col.width);
+ totalWidth += columns[i].width = parseInt(col.width, 10);
}
});
// check if we saved any asterisk columns for calculating later
@@ -1247,7 +1296,7 @@ kg.Grid = function (options) {
// are we overflowing?
if (self.maxCanvasHt() > self.viewportDimHeight()) {
//compensate for scrollbar
- offset += kg.domUtilityService.ScrollW;
+ offset += window.kg.domUtilityService.ScrollW;
}
columns[col.index].width -= offset;
}
@@ -1259,23 +1308,25 @@ kg.Grid = function (options) {
// do the math
$.each(percentArray, function (i, col) {
var t = col.width;
- columns[col.index].width = Math.floor(self.rootDim.outerWidth() * (parseInt(t.slice(0, -1)) / 100));
+ columns[col.index].width = Math.floor(self.rootDim.outerWidth() * (parseInt(t.slice(0, -1), 10) / 100));
});
}
self.columns(columns);
- kg.domUtilityService.BuildStyles(self);
+ window.kg.domUtilityService.BuildStyles(self);
};
self.init = function () {
//factories and services
- self.selectionService = new kg.SelectionService(self);
- self.rowFactory = new kg.RowFactory(self);
+ self.selectionService = new window.kg.SelectionService(self);
+ self.rowFactory = new window.kg.RowFactory(self);
self.selectionService.Initialize(self.rowFactory);
- self.searchProvider = new kg.SearchProvider(self);
- self.styleProvider = new kg.StyleProvider(self);
+ self.searchProvider = new window.kg.SearchProvider(self);
+ self.styleProvider = new window.kg.StyleProvider(self);
self.buildColumns();
- kg.sortService.columns = self.columns,
+ window.kg.sortService.columns = self.columns;
self.configGroups.subscribe(function (a) {
- if (!a) return;
+ if (!a) {
+ return;
+ }
var tempArr = [];
$.each(a, function (i, item) {
if(item){
@@ -1285,15 +1336,14 @@ kg.Grid = function (options) {
self.config.groups = tempArr;
self.rowFactory.filteredDataChanged();
});
- self.columns.subscribe(function () {
- if (self.$$indexPhase) return;
- self.fixColumnIndexes();
- kg.domUtilityService.BuildStyles(self);
- });
self.filteredData.subscribe(function () {
- if (self.$$selectionPhase) return;
+ if (self.$$selectionPhase) {
+ return;
+ }
self.maxCanvasHt(self.calcMaxCanvasHeight());
- if (!self.isSorting) self.configureColumnWidths();
+ if (!self.isSorting) {
+ self.configureColumnWidths();
+ }
});
self.maxCanvasHt(self.calcMaxCanvasHeight());
self.searchProvider.evalFilter();
@@ -1305,11 +1355,15 @@ kg.Grid = function (options) {
if (self.prevScrollTop === scrollTop && !force) { return; }
var rowIndex = Math.floor(scrollTop / self.config.rowHeight);
// Have we hit the threshold going down?
- if (self.prevScrollTop < scrollTop && rowIndex < self.prevScrollIndex + SCROLL_THRESHOLD) return;
+ if (self.prevScrollTop < scrollTop && rowIndex < self.prevScrollIndex + SCROLL_THRESHOLD) {
+ return;
+ }
//Have we hit the threshold going up?
- if (self.prevScrollTop > scrollTop && rowIndex > self.prevScrollIndex - SCROLL_THRESHOLD) return;
+ if (self.prevScrollTop > scrollTop && rowIndex > self.prevScrollIndex - SCROLL_THRESHOLD) {
+ return;
+ }
self.prevScrollTop = scrollTop;
- self.rowFactory.UpdateViewableRange(new kg.Range(Math.max(0, rowIndex - EXCESS_ROWS), rowIndex + self.minRowsToRender() + EXCESS_ROWS));
+ self.rowFactory.UpdateViewableRange(new window.kg.Range(Math.max(0, rowIndex - EXCESS_ROWS), rowIndex + self.minRowsToRender() + EXCESS_ROWS));
self.prevScrollIndex = rowIndex;
};
self.adjustScrollLeft = function (scrollLeft) {
@@ -1320,33 +1374,33 @@ kg.Grid = function (options) {
self.resizeOnData = function (col) {
// we calculate the longest data.
var longest = col.minWidth;
- var arr = kg.utils.getElementsByClassName('col' + col.index);
+ var arr = window.kg.utils.getElementsByClassName('col' + col.index);
$.each(arr, function (index, elem) {
var i;
- if (index == 0) {
+ if (index === 0) {
var kgHeaderText = $(elem).find('.kgHeaderText');
- i = kg.utils.visualLength(kgHeaderText) + 10;// +10 some margin
+ i = window.kg.utils.visualLength(kgHeaderText) + 10;// +10 some margin
} else {
var ngCellText = $(elem).find('.kgCellText');
- i = kg.utils.visualLength(ngCellText) + 10; // +10 some margin
+ i = window.kg.utils.visualLength(ngCellText) + 10; // +10 some margin
}
if (i > longest) {
longest = i;
}
});
col.width = longest = Math.min(col.maxWidth, longest + 7); // + 7 px to make it look decent.
- kg.domUtilityService.BuildStyles(self);
+ window.kg.domUtilityService.BuildStyles(self);
};
self.sortData = function (col, direction) {
// if external sorting is being used, do nothing.
self.isSorting = true;
- sortInfo = {
+ self.sortInfo({
column: col,
direction: direction
- };
+ });
self.clearSortingData(col);
if(!self.config.useExternalSorting){
- kg.sortService.Sort(sortInfo, self.sortedData);
+ window.kg.sortService.Sort(sortInfo, self.sortedData);
} else {
self.config.sortInfo(sortInfo);
}
@@ -1365,11 +1419,10 @@ kg.Grid = function (options) {
self.fixColumnIndexes = function () {
self.$$indexPhase = true;
//fix column indexes
- var cols = self.columns();
+ var cols = self.columns.peek();
$.each(cols, function (i, col) {
col.index = i;
});
- self.columns(cols);
self.$$indexPhase = false;
};
//self vars
@@ -1385,7 +1438,7 @@ kg.Grid = function (options) {
self.footer = null;
self.selectedItems = self.config.selectedItems;
self.multiSelect = self.config.multiSelect;
- self.footerVisible = kg.utils.isNullOrUndefined(self.config.displayFooter) ? self.config.footerVisible : self.config.displayFooter;
+ self.footerVisible = window.kg.utils.isNullOrUndefined(self.config.displayFooter) ? self.config.footerVisible : self.config.displayFooter;
self.config.footerRowHeight = self.footerVisible ? self.config.footerRowHeight : 0;
self.showColumnMenu = self.config.showColumnMenu;
self.showMenu = ko.observable(false);
@@ -1395,13 +1448,13 @@ kg.Grid = function (options) {
self.enablePaging = self.config.enablePaging;
self.pagingOptions = self.config.pagingOptions;
//Templates
- self.rowTemplate = self.config.rowTemplate || kg.defaultRowTemplate();
- self.headerRowTemplate = self.config.headerRowTemplate || kg.defaultHeaderRowTemplate();
+ self.rowTemplate = self.config.rowTemplate || window.kg.defaultRowTemplate();
+ self.headerRowTemplate = self.config.headerRowTemplate || window.kg.defaultHeaderRowTemplate();
if (self.config.rowTemplate && !TEMPLATE_REGEXP.test(self.config.rowTemplate)) {
- self.rowTemplate = kg.utils.getTemplatePromise(self.config.rowTemplate);
+ self.rowTemplate = window.kg.utils.getTemplatePromise(self.config.rowTemplate);
}
if (self.config.headerRowTemplate && !TEMPLATE_REGEXP.test(self.config.headerRowTemplate)) {
- self.headerRowTemplate = kg.utils.getTemplatePromise(self.config.headerRowTemplate);
+ self.headerRowTemplate = window.kg.utils.getTemplatePromise(self.config.headerRowTemplate);
}
//scope funcs
self.visibleColumns = ko.computed(function () {
@@ -1432,12 +1485,14 @@ kg.Grid = function (options) {
self.showGroupPanel = ko.computed(function(){
return self.config.showGroupPanel;
});
- self.topPanelHeight = ko.observable(self.config.showGroupPanel == true ? (self.config.headerRowHeight * 2) : self.config.headerRowHeight);
+ self.topPanelHeight = ko.observable(self.config.showGroupPanel === true ? (self.config.headerRowHeight * 2) : self.config.headerRowHeight);
self.viewportDimHeight = ko.computed(function () {
return Math.max(0, self.rootDim.outerHeight() - self.topPanelHeight() - self.config.footerRowHeight - 2);
});
self.groupBy = function (col) {
- if (self.sortedData().length < 1) return;
+ if (self.sortedData().length < 1) {
+ return;
+ }
var indx = self.configGroups().indexOf(col);
if (indx == -1) {
col.isGroupedBy(true);
@@ -1446,6 +1501,7 @@ kg.Grid = function (options) {
} else {
self.removeGroup(indx);
}
+ window.kg.domUtilityService.BuildStyles(self);
};
self.removeGroup = function(index) {
var col = self.columns().filter(function(item){
@@ -1456,9 +1512,10 @@ kg.Grid = function (options) {
self.columns.splice(index, 1);
self.configGroups.splice(index, 1);
self.fixGroupIndexes();
- if (self.configGroups().length == 0) {
+ if (self.configGroups().length === 0) {
self.fixColumnIndexes();
}
+ window.kg.domUtilityService.BuildStyles(self);
};
self.fixGroupIndexes = function(){
$.each(self.configGroups(), function(i,item){
@@ -1477,7 +1534,7 @@ kg.Grid = function (options) {
var viewportH = self.viewportDimHeight(),
maxHeight = self.maxCanvasHt(),
vScrollBarIsOpen = (maxHeight > viewportH),
- newDim = new kg.Dimension();
+ newDim = new window.kg.Dimension();
newDim.autoFitHeight = true;
newDim.outerWidth = self.totalRowWidth();
@@ -1540,7 +1597,7 @@ kg.Range = function (top, bottom) {
/***********************************************
* FILE: ..\src\classes\row.js
***********************************************/
-kg.Row = function (entity, config, selectionService) {
+window.kg.Row = function (entity, config, selectionService) {
var self = this; // constant for the selection property that we add to each data item
self.canSelectRows = config.canSelectRows;
@@ -1584,25 +1641,29 @@ kg.Row = function (entity, config, selectionService) {
self.offsetTop = ko.observable("0px");
self.rowDisplayIndex = 0;
self.isEven = ko.computed(function () {
- if (self.rowIndex() % 2 == 0) return true;
+ if (self.rowIndex() % 2 === 0) {
+ return true;
+ }
return false;
});
self.isOdd = ko.computed(function () {
- if (self.rowIndex() % 2 != 0) return true;
+ if (self.rowIndex() % 2 !== 0) {
+ return true;
+ }
return false;
});
self.beforeSelectionChange = config.beforeSelectionChangeCallback;
self.afterSelectionChange = config.afterSelectionChangeCallback;
self.propertyCache = {};
self.getProperty = function (path) {
- return self.propertyCache[path] || (self.propertyCache[path] = kg.utils.evalProperty(self.entity, path));
+ return self.propertyCache[path] || (self.propertyCache[path] = window.kg.utils.evalProperty(self.entity, path));
};
};
/***********************************************
* FILE: ..\src\classes\searchProvider.js
***********************************************/
-kg.SearchProvider = function (grid) {
+window.kg.SearchProvider = function (grid) {
var self = this,
searchConditions = [],
lastSearchStr;
@@ -1612,12 +1673,12 @@ kg.SearchProvider = function (grid) {
self.throttle = grid.config.filterOptions.filterThrottle;
self.fieldMap = {};
self.evalFilter = function () {
- if (searchConditions.length === 0)
+ if (searchConditions.length === 0) {
grid.filteredData(grid.sortedData.peek().filter(function(item) {
return !item._destroy;
}));
- else {
- grid.filteredData(grid.sortedData.peek().filter(function (item) {
+ } else {
+ grid.filteredData(grid.sortedData.peek().filter(function(item) {
if (item._destroy) {
return false;
}
@@ -1629,35 +1690,36 @@ kg.SearchProvider = function (grid) {
for (var prop in item) {
if (item.hasOwnProperty(prop)) {
var pVal = ko.utils.unwrapObservable(item[prop]);
- if (pVal && condition.regex.test(pVal.toString()))
+ if (pVal && condition.regex.test(pVal.toString())) {
return true;
+ }
}
}
return false;
}
//Search by column.
var field = ko.utils.unwrapObservable(item[condition.column]) || ko.utils.unwrapObservable(item[self.fieldMap[condition.columnDisplay]]);
- if (!field || !condition.regex.test(field.toString()))
+ if (!field || !condition.regex.test(field.toString())) {
return false;
+ }
}
return true;
}));
}
grid.rowFactory.filteredDataChanged();
};
- var getRegExp = function (str, modifiers) {
+ var getRegExp = function(str, modifiers) {
try {
return new RegExp(str, modifiers);
- }
- catch (err) {
+ } catch(err) {
//Escape all RegExp metacharacters.
return new RegExp(str.replace(/(\^|\$|\(|\)|\<|\>|\[|\]|\{|\}|\\|\||\.|\*|\+|\?)/g, '\\$1'));
}
- }
+ };
var buildSearchConditions = function (a) {
//reset.
searchConditions = [];
- var qStr = '';
+ var qStr;
if (!(qStr = $.trim(a))) {
return;
}
@@ -1710,7 +1772,7 @@ kg.SearchProvider = function (grid) {
/***********************************************
* FILE: ..\src\classes\selectionService.js
***********************************************/
-kg.SelectionService = function (grid) {
+window.kg.SelectionService = function (grid) {
var self = this;
self.multi = grid.config.multiSelect;
self.selectedItems = grid.config.selectedItems;
@@ -1730,7 +1792,9 @@ kg.SelectionService = function (grid) {
if (self.lastClickedRow) {
var thisIndx = grid.filteredData.indexOf(rowItem.entity);
var prevIndx = grid.filteredData.indexOf(self.lastClickedRow.entity);
- if (thisIndx == prevIndx) return false;
+ if (thisIndx == prevIndx) {
+ return false;
+ }
prevIndx++;
if (thisIndx < prevIndx) {
thisIndx = thisIndx ^ prevIndx;
@@ -1805,7 +1869,7 @@ kg.SelectionService = function (grid) {
/***********************************************
* FILE: ..\src\classes\styleProvider.js
***********************************************/
-kg.StyleProvider = function(grid) {
+window.kg.StyleProvider = function (grid) {
grid.canvasStyle = ko.computed(function() {
return { "height": grid.maxCanvasHt().toString() + "px" };
});
@@ -1816,7 +1880,7 @@ kg.StyleProvider = function(grid) {
return { "width": grid.rootDim.outerWidth() + "px", "height": grid.topPanelHeight() + "px" };
});
grid.headerStyle = ko.computed(function() {
- return { "width": Math.max(0, grid.rootDim.outerWidth() - kg.domUtilityService.ScrollW) + "px", "height": grid.config.headerRowHeight + "px" };
+ return { "width": Math.max(0, grid.rootDim.outerWidth() - window.kg.domUtilityService.ScrollW) + "px", "height": grid.config.headerRowHeight + "px" };
});
grid.viewportStyle = ko.computed(function() {
return { "width": grid.rootDim.outerWidth() + "px", "height": grid.viewportDimHeight() + "px" };
@@ -1829,7 +1893,7 @@ kg.StyleProvider = function(grid) {
/***********************************************
* FILE: ..\src\classes\SortService.js
***********************************************/
-kg.sortService = {
+window.kg.sortService = {
colSortFnCache: {}, // cache of sorting functions. Once we create them, we don't want to keep re-doing it
dateRE: /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/, // nasty regex for date parsing
guessSortFn: function(item) {
@@ -1839,65 +1903,95 @@ kg.sortService = {
month, // for date parsing
day; // for date parsing
- if (item === undefined || item === null || item === '') return null;
+ if (item === undefined || item === null || item === '') {
+ return null;
+ }
itemType = typeof(item);
//check for numbers and booleans
switch (itemType) {
case "number":
- sortFn = kg.sortService.sortNumber;
+ sortFn = window.kg.sortService.sortNumber;
break;
case "boolean":
- sortFn = kg.sortService.sortBool;
+ sortFn = window.kg.sortService.sortBool;
+ break;
+ default:
+ sortFn = undefined;
break;
}
//if we found one, return it
- if (sortFn) return sortFn;
+ if (sortFn) {
+ return sortFn;
+ }
//check if the item is a valid Date
- if (Object.prototype.toString.call(item) === '[object Date]') return kg.sortService.sortDate;
+ if (Object.prototype.toString.call(item) === '[object Date]') {
+ return window.kg.sortService.sortDate;
+ }
// if we aren't left with a string, return a basic sorting function...
- if (itemType !== "string") return kg.sortService.basicSort;
+ if (itemType !== "string") {
+ return window.kg.sortService.basicSort;
+ }
// now lets string check..
//check if the item data is a valid number
- if (item.match(/^-?[£$¤]?[\d,.]+%?$/)) return kg.sortService.sortNumberStr;
+ if (item.match(/^-?[£$¤]?[\d,.]+%?$/)) {
+ return window.kg.sortService.sortNumberStr;
+ }
// check for a date: dd/mm/yyyy or dd/mm/yy
// can have / or . or - as separator
// can be mm/dd as well
- dateParts = item.match(kg.sortService.dateRE);
+ dateParts = item.match(window.kg.sortService.dateRE);
if (dateParts) {
// looks like a date
- month = parseInt(dateParts[1]);
- day = parseInt(dateParts[2]);
+ month = parseInt(dateParts[1], 10);
+ day = parseInt(dateParts[2], 10);
if (month > 12) {
// definitely dd/mm
- return kg.sortService.sortDDMMStr;
+ return window.kg.sortService.sortDDMMStr;
} else if (day > 12) {
- return kg.sortService.sortMMDDStr;
+ return window.kg.sortService.sortMMDDStr;
} else {
// looks like a date, but we can't tell which, so assume that it's MM/DD
- return kg.sortService.sortMMDDStr;
+ return window.kg.sortService.sortMMDDStr;
}
}
//finally just sort the normal string...
- return kg.sortService.sortAlpha;
+ return window.kg.sortService.sortAlpha;
},
basicSort: function(a, b) {
- if (a == b) return 0;
- if (a < b) return -1;
+ if (a == b) {
+ return 0;
+ }
+ if (a < b) {
+ return -1;
+ }
return 1;
},
sortNumber: function(a, b) {
return a - b;
},
sortNumberStr: function(a, b) {
- var numA, numB, badA = false, badB = false;
+ var numA,
+ numB,
+ badA = false,
+ badB = false;
numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
- if (isNaN(numA)) badA = true;
+ if (isNaN(numA)) {
+ badA = true;
+ }
numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
- if (isNaN(numB)) badB = true;
+ if (isNaN(numB)) {
+ badB = true;
+ }
// we want bad ones to get pushed to the bottom... which effectively is "greater than"
- if (badA && badB) return 0;
- if (badA) return 1;
- if (badB) return -1;
+ if (badA && badB) {
+ return 0;
+ }
+ if (badA) {
+ return 1;
+ }
+ if (badB) {
+ return -1;
+ }
return numA - numB;
},
sortAlpha: function(a, b) {
@@ -1906,7 +2000,9 @@ kg.sortService = {
return strA == strB ? 0 : (strA < strB ? -1 : 1);
},
sortBool: function(a, b) {
- if (a && b) return 0;
+ if (a && b) {
+ return 0;
+ }
if (!a && !b) {
return 0;
} else {
@@ -1920,42 +2016,66 @@ kg.sortService = {
},
sortDDMMStr: function(a, b) {
var dateA, dateB, mtch, m, d, y;
- mtch = a.match(kg.sortService.dateRE);
+ mtch = a.match(window.kg.sortService.dateRE);
y = mtch[3];
m = mtch[2];
d = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateA = y + m + d;
- mtch = b.match(kg.sortService.dateRE);
+ mtch = b.match(window.kg.sortService.dateRE);
y = mtch[3];
m = mtch[2];
d = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateB = y + m + d;
- if (dateA == dateB) return 0;
- if (dateA < dateB) return -1;
+ if (dateA == dateB) {
+ return 0;
+ }
+ if (dateA < dateB) {
+ return -1;
+ }
return 1;
},
sortMMDDStr: function(a, b) {
var dateA, dateB, mtch, m, d, y;
- mtch = a.match(kg.sortService.dateRE);
+ mtch = a.match(window.kg.sortService.dateRE);
y = mtch[3];
d = mtch[2];
m = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateA = y + m + d;
mtch = b.match(dateRE);
y = mtch[3];
d = mtch[2];
m = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateB = y + m + d;
- if (dateA == dateB) return 0;
- if (dateA < dateB) return -1;
+ if (dateA == dateB) {
+ return 0;
+ }
+ if (dateA < dateB) {
+ return -1;
+ }
return 1;
},
sortData: function (data /*datasource*/, sortInfo) {
@@ -1970,29 +2090,31 @@ kg.sortService = {
sortFn,
item;
//see if we already figured out what to use to sort the column
- if (kg.sortService.colSortFnCache[col.field]) {
- sortFn = kg.sortService.colSortFnCache[col.field];
+ if (window.kg.sortService.colSortFnCache[col.field]) {
+ sortFn = window.kg.sortService.colSortFnCache[col.field];
} else if (col.sortingAlgorithm != undefined) {
sortFn = col.sortingAlgorithm;
- kg.sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
+ window.kg.sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
} else { // try and guess what sort function to use
item = unwrappedData[0];
- if (!item) return;
+ if (!item) {
+ return;
+ }
sortFn = kg.sortService.guessSortFn(item[col.field]);
//cache it
if (sortFn) {
- kg.sortService.colSortFnCache[col.field] = sortFn;
+ window.kg.sortService.colSortFnCache[col.field] = sortFn;
} else {
// we assign the alpha sort because anything that is null/undefined will never get passed to
// the actual sorting function. It will get caught in our null check and returned to be sorted
// down to the bottom
- sortFn = kg.sortService.sortAlpha;
+ sortFn = window.kg.sortService.sortAlpha;
}
}
//now actually sort the data
unwrappedData.sort(function (itemA, itemB) {
- var propA = kg.utils.evalProperty(itemA, col.field);
- var propB = kg.utils.evalProperty(itemB, col.field);
+ var propA = window.kg.utils.evalProperty(itemA, col.field);
+ var propB = window.kg.utils.evalProperty(itemB, col.field);
// we want to force nulls and such to the bottom when we sort... which effectively is "greater than"
if (!propB && !propA) {
return 0;
@@ -2012,11 +2134,13 @@ kg.sortService = {
return;
},
Sort: function (sortInfo, data) {
- if (kg.sortService.isSorting) return;
- kg.sortService.isSorting = true;
- kg.sortService.sortData(data, sortInfo);
- kg.sortService.isSorting = false;
- },
+ if (window.kg.sortService.isSorting) {
+ return;
+ }
+ window.kg.sortService.isSorting = true;
+ window.kg.sortService.sortData(data, sortInfo);
+ window.kg.sortService.isSorting = false;
+ }
};
/***********************************************
@@ -2029,17 +2153,17 @@ var getWidths = function () {
//measure Scroll Bars
$testContainer.height(100).width(100).css("position", "absolute").css("overflow", "scroll");
$testContainer.append('');
- 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('M');
- 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
@@ -2054,7 +2178,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!
@@ -2087,13 +2211,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));
diff --git a/build/build.ps1 b/build/build.ps1
index 796d9c37..3b05d060 100644
--- a/build/build.ps1
+++ b/build/build.ps1
@@ -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";
diff --git a/koGrid-2.1.1.debug.js b/koGrid-2.1.1.debug.js
index 2c62756b..bc392d50 100644
--- a/koGrid-2.1.1.debug.js
+++ b/koGrid-2.1.1.debug.js
@@ -2,10 +2,11 @@
* 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: 12/18/2012 12:55:08
+* Compiled At: 12/18/2012 15:27:17
***********************************************/
-(function(window, undefined){
+(function (window) {
+'use strict';
/***********************************************
* FILE: ..\src\namespace.js
@@ -13,41 +14,46 @@
if (!window.kg) {
window.kg = {};
}
-kg.numberOfGrids = 0;
-kg.eventStorage = {};
+window.kg.numberOfGrids = 0;
+window.kg.eventStorage = {};
/***********************************************
* FILE: ..\src\constants.js
***********************************************/
-var SELECTED_PROP = '__kg_selected__';
-var GRID_KEY = '__koGrid__';
-// the # of rows we want to add to the top and bottom of the rendered grid rows
-var EXCESS_ROWS = 8;
-var SCROLL_THRESHOLD = 6;
-var ASC = "asc"; // constant for sorting direction
-var DESC = "desc"; // constant for sorting direction
-var KG_FIELD = '_kg_field_';
-var KG_DEPTH = '_kg_depth_';
-var KG_HIDDEN = '_kg_hidden_';
-var KG_COLUMN = '_kg_column_';
-var TEMPLATE_REGEXP = /<.+>/;
+var SELECTED_PROP = '__kg_selected__',
+ GRID_KEY = '__koGrid__',
+ // the # of rows we want to add to the top and bottom of the rendered grid rows
+ EXCESS_ROWS = 8,
+ SCROLL_THRESHOLD = 6,
+ ASC = "asc", // constant for sorting direction
+ DESC = "desc", // constant for sorting direction
+ KG_FIELD = '_kg_field_',
+ KG_DEPTH = '_kg_depth_',
+ KG_HIDDEN = '_kg_hidden_',
+ KG_COLUMN = '_kg_column_',
+ TEMPLATE_REGEXP = /<.+>/;
/***********************************************
* FILE: ..\src\navigation.js
***********************************************/
//set event binding on the grid so we can select using the up/down keys
-kg.moveSelectionHandler = function (grid, evt) {
+window.kg.moveSelectionHandler = function(grid, evt) {
// null checks
- if (grid === null || grid === undefined) return true;
- if (grid.config.selectedItems === undefined) return true;
+ if (window.kg.utils.isNullOrUndefined(grid) || window.kg.utils.isNullOrUndefined(grid.config.selectedItems)) {
+ return true;
+ }
var charCode = (evt.which) ? evt.which : event.keyCode;
// detect which direction for arrow keys to navigate the grid
var offset = (charCode == 38 ? -1 : (charCode == 40 ? 1 : null));
- if (!offset) return true;
+ if (!offset) {
+ return true;
+ }
var items = grid.renderedRows();
var index = items.indexOf(grid.selectionService.lastClickedRow) + offset;
- if (index < 0 || index >= items.length) return true;
- grid.selectionService.ChangeSelection(items[index], evt);
+ if (index < 0 || index >= items.length) {
+ return true;
+ }
+grid.selectionService.ChangeSelection(items[index], evt);
if (index > items.length - EXCESS_ROWS) {
grid.$viewport.scrollTop(grid.$viewport.scrollTop() + (grid.config.rowHeight * EXCESS_ROWS));
} else if (index < EXCESS_ROWS) {
@@ -64,43 +70,45 @@ if (!String.prototype.trim) {
return this.replace(/^\s+|\s+$/g, '');
};
}
-if (!Array.prototype.indexOf)
-{
- Array.prototype.indexOf = function(elt /*, from*/){
- var len = this.length >>> 0;
- var from = Number(arguments[1]) || 0;
- from = (from < 0) ? Math.ceil(from) : Math.floor(from);
- if (from < 0) from += len;
- for (; from < len; from++){
- if (from in this && this[from] === elt) return from;
- }
- return -1;
- };
+if (!Array.prototype.indexOf) {
+ Array.prototype.indexOf = function(elt /*, from*/) {
+ var len = this.length >>> 0;
+ var from = Number(arguments[1]) || 0;
+ from = (from < 0) ? Math.ceil(from) : Math.floor(from);
+ if (from < 0) {
+ from += len;
+ }
+ for (; from < len; from++) {
+ if (from in this && this[from] === elt) {
+ return from;
+ }
+ }
+ return -1;
+ };
}
-if (!Array.prototype.filter)
-{
- Array.prototype.filter = function(fun /*, thisp */)
- {
- "use strict";
- var t = Object(this);
- var len = t.length >>> 0;
- if (typeof fun !== "function")throw new TypeError();
- var res = [];
- var thisp = arguments[1];
- for (var i = 0; i < len; i++)
- {
- if (i in t)
- {
- var val = t[i]; // in case fun mutates this
- if (fun.call(thisp, val, i, t))
- res.push(val);
- }
- }
- return res;
- };
+if (!Array.prototype.filter) {
+ Array.prototype.filter = function(fun /*, thisp */) {
+ "use strict";
+ var t = Object(this);
+ var len = t.length >>> 0;
+ if (typeof fun !== "function") {
+ throw new TypeError();
+ }
+ var res = [];
+ var thisp = arguments[1];
+ for (var i = 0; i < len; i++) {
+ if (i in t) {
+ var val = t[i]; // in case fun mutates this
+ if (fun.call(thisp, val, i, t)) {
+ res.push(val);
+ }
+ }
+ }
+ return res;
+ };
}
-kg.utils = {
- visualLength: function (node) {
+window.kg.utils = {
+ visualLength: function(node) {
var elem = document.getElementById('testDataLength');
if (!elem) {
elem = document.createElement('SPAN');
@@ -112,104 +120,110 @@ kg.utils = {
elem.innerHTML = $(node).text();
return elem.offsetWidth;
},
- forIn: function (obj, action) {
- for (var prop in obj) {
- if(obj.hasOwnProperty(prop)){
+ forIn: function(obj, action) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) {
action(obj[prop], prop);
}
}
},
- evalProperty: function (entity, path) {
+ evalProperty: function(entity, path) {
var e = ko.utils.unwrapObservable(entity);
var propPath = path.split('.'), i = 0;
- var tempProp = ko.utils.unwrapObservable(e[propPath[i++]]), links = propPath.length;
+ var tempProp = ko.utils.unwrapObservable(e[propPath[i]]), links = propPath.length;
+ i++;
while (tempProp && i < links) {
- tempProp = ko.utils.unwrapObservable(tempProp[propPath[i++]]);
+ tempProp = ko.utils.unwrapObservable(tempProp[propPath[i]]);
+ i++;
}
return tempProp;
},
- endsWith: function (str, suffix) {
- if (!str || !suffix || typeof str != "string") return false;
+ endsWith: function(str, suffix) {
+ if (!str || !suffix || typeof str != "string") {
+ return false;
+ }
return str.indexOf(suffix, str.length - suffix.length) !== -1;
},
- isNullOrUndefined: function (obj) {
- if (obj === undefined || obj === null) return true;
+ isNullOrUndefined: function(obj) {
+ if (obj === undefined || obj === null) {
+ return true;
+ }
return false;
},
getElementsByClassName: function(cl) {
var retnode = [];
- var myclass = new RegExp('\\b'+cl+'\\b');
+ var myclass = new RegExp('\\b' + cl + '\\b');
var elem = document.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
- if (myclass.test(classes)) retnode.push(elem[i]);
+ if (myclass.test(classes)) {
+ retnode.push(elem[i]);
+ }
}
return retnode;
},
getTemplatePromise: function(path) {
return $.ajax(path);
},
- newId: (function () {
+ newId: (function() {
var seedId = new Date().getTime();
- return function () {
+ return function() {
return seedId += 1;
};
})(),
// we copy KO's ie detection here bc it isn't exported in the min versions of KO
// Detect IE versions for workarounds (uses IE conditionals, not UA string, for robustness)
- ieVersion: (function () {
+ ieVersion: (function() {
var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');
// Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
- while (
- div.innerHTML = '',
- iElems[0]
- );
+ while (div.innerHTML = '',
+ iElems[0]) ;
return version > 4 ? version : undefined;
})()
};
-$.extend(kg.utils, {
- isIe6: (function(){
- return kg.utils.ieVersion === 6;
+$.extend(window.kg.utils, {
+ isIe6: (function() {
+ return window.kg.utils.ieVersion === 6;
+ })(),
+ isIe7: (function() {
+ return window.kg.utils.ieVersion === 7;
})(),
- isIe7: (function(){
- return kg.utils.ieVersion === 7;
- } )(),
- isIe: (function () {
- return kg.utils.ieVersion !== undefined;
+ isIe: (function() {
+ return window.kg.utils.ieVersion !== undefined;
})()
-});
+});
/***********************************************
* FILE: ..\src\templates\gridTemplate.html
***********************************************/
-kg.defaultGridTemplate = function(){ return 'Drag a column header here and drop it to group by that column
';};
+window.kg.defaultGridTemplate = function(){ return 'Drag a column header here and drop it to group by that column
';};
/***********************************************
* FILE: ..\src\templates\rowTemplate.html
***********************************************/
-kg.defaultRowTemplate = function(){ return '';};
+window.kg.defaultRowTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\templates\cellTemplate.html
***********************************************/
-kg.defaultCellTemplate = function(){ return '';};
+window.kg.defaultCellTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\templates\aggregateTemplate.html
***********************************************/
-kg.aggregateTemplate = function(){ return '';};
+window.kg.aggregateTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\templates\headerRowTemplate.html
***********************************************/
-kg.defaultHeaderRowTemplate = function(){ return '';};
+window.kg.defaultHeaderRowTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\templates\headerCellTemplate.html
***********************************************/
-kg.defaultHeaderCellTemplate = function(){ return '';};
+window.kg.defaultHeaderCellTemplate = function(){ return '';};
/***********************************************
* FILE: ..\src\bindingHandlers\ko-grid.js
@@ -219,12 +233,14 @@ ko.bindingHandlers['koGrid'] = (function () {
'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();
});
@@ -243,17 +259,18 @@ ko.bindingHandlers['koGrid'] = (function () {
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 };
}
};
@@ -269,16 +286,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);
@@ -373,14 +390,14 @@ ko.bindingHandlers['mouseEvents'] = (function () {
if (eFuncs.mouseDown) {
$(element).mousedown(eFuncs.mouseDown);
}
- },
+ }
};
}());
/***********************************************
* FILE: ..\src\classes\aggregate.js
***********************************************/
-kg.Aggregate = function (aggEntity, rowFactory) {
+window.kg.Aggregate = function (aggEntity, rowFactory) {
var self = this;
self.index = 0;
self.offsetTop = ko.observable(0);
@@ -461,16 +478,17 @@ kg.Aggregate = function (aggEntity, rowFactory) {
/***********************************************
* FILE: ..\src\classes\column.js
***********************************************/
-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;
@@ -483,7 +501,7 @@ kg.Column = function (config, grid) {
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();
@@ -493,21 +511,21 @@ kg.Column = function (config, grid) {
}
});
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;
@@ -520,13 +538,13 @@ kg.Column = function (config, grid) {
};
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 () {
@@ -565,11 +583,12 @@ kg.Column = function (config, grid) {
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);
@@ -581,14 +600,15 @@ kg.Column = function (config, grid) {
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;
};
@@ -597,7 +617,7 @@ kg.Column = function (config, grid) {
/***********************************************
* FILE: ..\src\classes\dimension.js
***********************************************/
-kg.Dimension = function (options) {
+window.kg.Dimension = function (options) {
this.outerHeight = null;
this.outerWidth = null;
$.extend(this, options);
@@ -606,7 +626,7 @@ kg.Dimension = function (options) {
/***********************************************
* FILE: ..\src\classes\eventProvider.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;
@@ -718,7 +738,9 @@ 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]);
@@ -726,42 +748,53 @@ kg.EventProvider = function (grid) {
// 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 };
}
};
@@ -772,8 +805,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);
@@ -782,7 +817,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
}
};
@@ -795,7 +830,7 @@ 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
@@ -803,12 +838,13 @@ kg.EventProvider = function (grid) {
//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();
}
@@ -822,7 +858,7 @@ kg.EventProvider = function (grid) {
/***********************************************
* FILE: ..\src\classes\rowFactory.js
***********************************************/
-kg.RowFactory = function(grid) {
+window.kg.RowFactory = function (grid) {
var self = this;
// we cache rows when they are built, and then blow the cache away when sorting
self.rowCache = [];
@@ -845,7 +881,7 @@ kg.RowFactory = function(grid) {
afterSelectionChangeCallback: grid.config.afterSelectionChange
};
- self.renderedRange = new kg.Range(0, grid.minRowsToRender() + EXCESS_ROWS);
+ self.renderedRange = new window.kg.Range(0, grid.minRowsToRender() + EXCESS_ROWS);
// Builds rows for each data item in the 'filteredData'
// @entity - the data item
// @rowIndex - the index of the row
@@ -853,7 +889,7 @@ kg.RowFactory = function(grid) {
var row = self.rowCache[rowIndex]; // first check to see if we've already built it
if (!row) {
// build the row
- row = new kg.Row(entity, self.rowConfig, self.selectionService);
+ row = new window.kg.Row(entity, self.rowConfig, self.selectionService);
row.rowIndex(rowIndex + 1); //not a zero-based rowIndex
row.offsetTop((self.rowHeight * rowIndex).toString() + 'px');
row.selected(entity[SELECTED_PROP]);
@@ -867,7 +903,7 @@ kg.RowFactory = function(grid) {
var agg = self.aggCache[aggEntity.aggIndex]; // first check to see if we've already built it
if (!agg) {
// build the row
- agg = new kg.Aggregate(aggEntity, self);
+ agg = new window.kg.Aggregate(aggEntity, self);
self.aggCache[aggEntity.aggIndex] = agg;
}
agg.index = rowIndex + 1; //not a zero-based rowIndex
@@ -953,9 +989,10 @@ kg.RowFactory = function(grid) {
'_kg_hidden_': false,
children: [],
aggChildren: [],
- aggIndex: self.numberOfAggregates++,
+ aggIndex: self.numberOfAggregates,
aggLabelFilter: g[KG_COLUMN].aggLabelFilter
}, 0);
+ self.numberOfAggregates++;
//set the aggregate parent to the parent in the array that is one less deep.
agg.parent = self.parentCache[agg.depth - 1];
// if we have a parent, set the parent to not be collapsed and append the current agg to its children
@@ -989,31 +1026,43 @@ kg.RowFactory = function(grid) {
var ptr = self.groupedData;
$.each(groups, function(depth, group) {
if (!cols[depth].isAggCol && depth <= maxDepth) {
- grid.columns.splice(item.gDepth, 0, new kg.Column({
+ grid.columns.splice(item.gDepth, 0, new window.kg.Column({
colDef: {
field: '',
width: 25,
sortable: false,
resizable: false,
- headerCellTemplate: '',
+ headerCellTemplate: ''
},
isAggCol: true,
index: item.gDepth,
headerRowHeight: grid.config.headerRowHeight
}));
- kg.domUtilityService.BuildStyles(grid);
+ window.kg.domUtilityService.BuildStyles(grid);
}
var col = cols.filter(function (c) { return c.field == group; })[0];
- var val = kg.utils.evalProperty(item, group);
- if (col.cellFilter) val = col.cellFilter(val);
+ var val = window.kg.utils.evalProperty(item, group);
+ if (col.cellFilter) {
+ val = col.cellFilter(val);
+ }
val = val ? val.toString() : 'null';
- if (!ptr[val]) ptr[val] = {};
- if (!ptr[KG_FIELD]) ptr[KG_FIELD] = group;
- if (!ptr[KG_DEPTH]) ptr[KG_DEPTH] = depth;
- if (!ptr[KG_COLUMN]) ptr[KG_COLUMN] = col;
+ if (!ptr[val]) {
+ ptr[val] = {};
+ }
+ if (!ptr[KG_FIELD]) {
+ ptr[KG_FIELD] = group;
+ }
+ if (!ptr[KG_DEPTH]) {
+ ptr[KG_DEPTH] = depth;
+ }
+ if (!ptr[KG_COLUMN]) {
+ ptr[KG_COLUMN] = col;
+ }
ptr = ptr[val];
});
- if (!ptr.values) ptr.values = [];
+ if (!ptr.values) {
+ ptr.values = [];
+ }
ptr.values.push(item);
});
grid.fixColumnIndexes();
@@ -1029,7 +1078,7 @@ kg.RowFactory = function(grid) {
/***********************************************
* FILE: ..\src\classes\grid.js
***********************************************/
-kg.Grid = function (options) {
+window.kg.Grid = function (options) {
var defaults = {
rowHeight: 30,
columnWidth: 100,
@@ -1068,7 +1117,7 @@ kg.Grid = function (options) {
disableTextSelection: true,
filterOptions: {
filterText: ko.observable(""),
- useExternalFilter: false,
+ useExternalFilter: false
},
//Paging
enablePaging: false,
@@ -1076,8 +1125,8 @@ kg.Grid = function (options) {
pageSizes: ko.observableArray([250, 500, 1000]), //page Sizes
pageSize: ko.observable(250), //Size of Paging data
totalServerItems: ko.observable(0), //how many items are on the server (for paging)
- currentPage: ko.observable(1), //what page they are currently on
- },
+ currentPage: ko.observable(1) //what page they are currently on
+ }
},
self = this;
@@ -1085,7 +1134,7 @@ kg.Grid = function (options) {
//self vars
self.config = $.extend(defaults, options);
self.config.columnDefs = ko.utils.unwrapObservable(options.columnDefs);
- self.gridId = "ng" + kg.utils.newId();
+ self.gridId = "ng" + window.kg.utils.newId();
self.$root = null; //this is the root element that is passed in with the binding handler
self.$groupPanel = null;
self.$topPanel = null;
@@ -1114,7 +1163,7 @@ kg.Grid = function (options) {
rowIndexCellW: 25,
rowSelectedCellW: 25,
rootMaxW: 0,
- rootMaxH: 0,
+ rootMaxH: 0
};
//self funcs
self.setRenderedRows = function (newRows) {
@@ -1142,7 +1191,7 @@ kg.Grid = function (options) {
var item;
item = sd[0];
- kg.utils.forIn(item, function (prop, propName) {
+ window.kg.utils.forIn(item, function (prop, propName) {
if (propName != SELECTED_PROP) {
self.config.columnDefs.push({
field: propName
@@ -1170,7 +1219,7 @@ kg.Grid = function (options) {
}
if (columnDefs.length > 0) {
$.each(columnDefs, function (i, colDef) {
- var column = new kg.Column({
+ var column = new window.kg.Column({
colDef: colDef,
index: i,
headerRowHeight: self.config.headerRowHeight,
@@ -1199,11 +1248,11 @@ kg.Grid = function (options) {
$.each(cols, function (i, col) {
var isPercent = false, t = undefined;
//if width is not defined, set it to a single star
- if (kg.utils.isNullOrUndefined(col.width)) {
+ if (window.kg.utils.isNullOrUndefined(col.width)) {
col.width = "*";
} else { // get column width
- isPercent = isNaN(col.width) ? kg.utils.endsWith(col.width, "%") : false;
- t = isPercent ? col.width : parseInt(col.width);
+ isPercent = isNaN(col.width) ? window.kg.utils.endsWith(col.width, "%") : false;
+ t = isPercent ? col.width : parseInt(col.width, 10);
}
// check if it is a number
if (isNaN(t)) {
@@ -1227,7 +1276,7 @@ kg.Grid = function (options) {
throw "unable to parse column width, use percentage (\"10%\",\"20%\", etc...) or \"*\" to use remaining width of grid";
}
} else {
- totalWidth += columns[i].width = parseInt(col.width);
+ totalWidth += columns[i].width = parseInt(col.width, 10);
}
});
// check if we saved any asterisk columns for calculating later
@@ -1247,7 +1296,7 @@ kg.Grid = function (options) {
// are we overflowing?
if (self.maxCanvasHt() > self.viewportDimHeight()) {
//compensate for scrollbar
- offset += kg.domUtilityService.ScrollW;
+ offset += window.kg.domUtilityService.ScrollW;
}
columns[col.index].width -= offset;
}
@@ -1259,23 +1308,25 @@ kg.Grid = function (options) {
// do the math
$.each(percentArray, function (i, col) {
var t = col.width;
- columns[col.index].width = Math.floor(self.rootDim.outerWidth() * (parseInt(t.slice(0, -1)) / 100));
+ columns[col.index].width = Math.floor(self.rootDim.outerWidth() * (parseInt(t.slice(0, -1), 10) / 100));
});
}
self.columns(columns);
- kg.domUtilityService.BuildStyles(self);
+ window.kg.domUtilityService.BuildStyles(self);
};
self.init = function () {
//factories and services
- self.selectionService = new kg.SelectionService(self);
- self.rowFactory = new kg.RowFactory(self);
+ self.selectionService = new window.kg.SelectionService(self);
+ self.rowFactory = new window.kg.RowFactory(self);
self.selectionService.Initialize(self.rowFactory);
- self.searchProvider = new kg.SearchProvider(self);
- self.styleProvider = new kg.StyleProvider(self);
+ self.searchProvider = new window.kg.SearchProvider(self);
+ self.styleProvider = new window.kg.StyleProvider(self);
self.buildColumns();
- kg.sortService.columns = self.columns,
+ window.kg.sortService.columns = self.columns;
self.configGroups.subscribe(function (a) {
- if (!a) return;
+ if (!a) {
+ return;
+ }
var tempArr = [];
$.each(a, function (i, item) {
if(item){
@@ -1285,15 +1336,14 @@ kg.Grid = function (options) {
self.config.groups = tempArr;
self.rowFactory.filteredDataChanged();
});
- self.columns.subscribe(function () {
- if (self.$$indexPhase) return;
- self.fixColumnIndexes();
- kg.domUtilityService.BuildStyles(self);
- });
self.filteredData.subscribe(function () {
- if (self.$$selectionPhase) return;
+ if (self.$$selectionPhase) {
+ return;
+ }
self.maxCanvasHt(self.calcMaxCanvasHeight());
- if (!self.isSorting) self.configureColumnWidths();
+ if (!self.isSorting) {
+ self.configureColumnWidths();
+ }
});
self.maxCanvasHt(self.calcMaxCanvasHeight());
self.searchProvider.evalFilter();
@@ -1305,11 +1355,15 @@ kg.Grid = function (options) {
if (self.prevScrollTop === scrollTop && !force) { return; }
var rowIndex = Math.floor(scrollTop / self.config.rowHeight);
// Have we hit the threshold going down?
- if (self.prevScrollTop < scrollTop && rowIndex < self.prevScrollIndex + SCROLL_THRESHOLD) return;
+ if (self.prevScrollTop < scrollTop && rowIndex < self.prevScrollIndex + SCROLL_THRESHOLD) {
+ return;
+ }
//Have we hit the threshold going up?
- if (self.prevScrollTop > scrollTop && rowIndex > self.prevScrollIndex - SCROLL_THRESHOLD) return;
+ if (self.prevScrollTop > scrollTop && rowIndex > self.prevScrollIndex - SCROLL_THRESHOLD) {
+ return;
+ }
self.prevScrollTop = scrollTop;
- self.rowFactory.UpdateViewableRange(new kg.Range(Math.max(0, rowIndex - EXCESS_ROWS), rowIndex + self.minRowsToRender() + EXCESS_ROWS));
+ self.rowFactory.UpdateViewableRange(new window.kg.Range(Math.max(0, rowIndex - EXCESS_ROWS), rowIndex + self.minRowsToRender() + EXCESS_ROWS));
self.prevScrollIndex = rowIndex;
};
self.adjustScrollLeft = function (scrollLeft) {
@@ -1320,33 +1374,33 @@ kg.Grid = function (options) {
self.resizeOnData = function (col) {
// we calculate the longest data.
var longest = col.minWidth;
- var arr = kg.utils.getElementsByClassName('col' + col.index);
+ var arr = window.kg.utils.getElementsByClassName('col' + col.index);
$.each(arr, function (index, elem) {
var i;
- if (index == 0) {
+ if (index === 0) {
var kgHeaderText = $(elem).find('.kgHeaderText');
- i = kg.utils.visualLength(kgHeaderText) + 10;// +10 some margin
+ i = window.kg.utils.visualLength(kgHeaderText) + 10;// +10 some margin
} else {
var ngCellText = $(elem).find('.kgCellText');
- i = kg.utils.visualLength(ngCellText) + 10; // +10 some margin
+ i = window.kg.utils.visualLength(ngCellText) + 10; // +10 some margin
}
if (i > longest) {
longest = i;
}
});
col.width = longest = Math.min(col.maxWidth, longest + 7); // + 7 px to make it look decent.
- kg.domUtilityService.BuildStyles(self);
+ window.kg.domUtilityService.BuildStyles(self);
};
self.sortData = function (col, direction) {
// if external sorting is being used, do nothing.
self.isSorting = true;
- sortInfo = {
+ self.sortInfo({
column: col,
direction: direction
- };
+ });
self.clearSortingData(col);
if(!self.config.useExternalSorting){
- kg.sortService.Sort(sortInfo, self.sortedData);
+ window.kg.sortService.Sort(sortInfo, self.sortedData);
} else {
self.config.sortInfo(sortInfo);
}
@@ -1365,11 +1419,10 @@ kg.Grid = function (options) {
self.fixColumnIndexes = function () {
self.$$indexPhase = true;
//fix column indexes
- var cols = self.columns();
+ var cols = self.columns.peek();
$.each(cols, function (i, col) {
col.index = i;
});
- self.columns(cols);
self.$$indexPhase = false;
};
//self vars
@@ -1385,7 +1438,7 @@ kg.Grid = function (options) {
self.footer = null;
self.selectedItems = self.config.selectedItems;
self.multiSelect = self.config.multiSelect;
- self.footerVisible = kg.utils.isNullOrUndefined(self.config.displayFooter) ? self.config.footerVisible : self.config.displayFooter;
+ self.footerVisible = window.kg.utils.isNullOrUndefined(self.config.displayFooter) ? self.config.footerVisible : self.config.displayFooter;
self.config.footerRowHeight = self.footerVisible ? self.config.footerRowHeight : 0;
self.showColumnMenu = self.config.showColumnMenu;
self.showMenu = ko.observable(false);
@@ -1395,13 +1448,13 @@ kg.Grid = function (options) {
self.enablePaging = self.config.enablePaging;
self.pagingOptions = self.config.pagingOptions;
//Templates
- self.rowTemplate = self.config.rowTemplate || kg.defaultRowTemplate();
- self.headerRowTemplate = self.config.headerRowTemplate || kg.defaultHeaderRowTemplate();
+ self.rowTemplate = self.config.rowTemplate || window.kg.defaultRowTemplate();
+ self.headerRowTemplate = self.config.headerRowTemplate || window.kg.defaultHeaderRowTemplate();
if (self.config.rowTemplate && !TEMPLATE_REGEXP.test(self.config.rowTemplate)) {
- self.rowTemplate = kg.utils.getTemplatePromise(self.config.rowTemplate);
+ self.rowTemplate = window.kg.utils.getTemplatePromise(self.config.rowTemplate);
}
if (self.config.headerRowTemplate && !TEMPLATE_REGEXP.test(self.config.headerRowTemplate)) {
- self.headerRowTemplate = kg.utils.getTemplatePromise(self.config.headerRowTemplate);
+ self.headerRowTemplate = window.kg.utils.getTemplatePromise(self.config.headerRowTemplate);
}
//scope funcs
self.visibleColumns = ko.computed(function () {
@@ -1432,12 +1485,14 @@ kg.Grid = function (options) {
self.showGroupPanel = ko.computed(function(){
return self.config.showGroupPanel;
});
- self.topPanelHeight = ko.observable(self.config.showGroupPanel == true ? (self.config.headerRowHeight * 2) : self.config.headerRowHeight);
+ self.topPanelHeight = ko.observable(self.config.showGroupPanel === true ? (self.config.headerRowHeight * 2) : self.config.headerRowHeight);
self.viewportDimHeight = ko.computed(function () {
return Math.max(0, self.rootDim.outerHeight() - self.topPanelHeight() - self.config.footerRowHeight - 2);
});
self.groupBy = function (col) {
- if (self.sortedData().length < 1) return;
+ if (self.sortedData().length < 1) {
+ return;
+ }
var indx = self.configGroups().indexOf(col);
if (indx == -1) {
col.isGroupedBy(true);
@@ -1446,6 +1501,7 @@ kg.Grid = function (options) {
} else {
self.removeGroup(indx);
}
+ window.kg.domUtilityService.BuildStyles(self);
};
self.removeGroup = function(index) {
var col = self.columns().filter(function(item){
@@ -1456,9 +1512,10 @@ kg.Grid = function (options) {
self.columns.splice(index, 1);
self.configGroups.splice(index, 1);
self.fixGroupIndexes();
- if (self.configGroups().length == 0) {
+ if (self.configGroups().length === 0) {
self.fixColumnIndexes();
}
+ window.kg.domUtilityService.BuildStyles(self);
};
self.fixGroupIndexes = function(){
$.each(self.configGroups(), function(i,item){
@@ -1477,7 +1534,7 @@ kg.Grid = function (options) {
var viewportH = self.viewportDimHeight(),
maxHeight = self.maxCanvasHt(),
vScrollBarIsOpen = (maxHeight > viewportH),
- newDim = new kg.Dimension();
+ newDim = new window.kg.Dimension();
newDim.autoFitHeight = true;
newDim.outerWidth = self.totalRowWidth();
@@ -1540,7 +1597,7 @@ kg.Range = function (top, bottom) {
/***********************************************
* FILE: ..\src\classes\row.js
***********************************************/
-kg.Row = function (entity, config, selectionService) {
+window.kg.Row = function (entity, config, selectionService) {
var self = this; // constant for the selection property that we add to each data item
self.canSelectRows = config.canSelectRows;
@@ -1584,25 +1641,29 @@ kg.Row = function (entity, config, selectionService) {
self.offsetTop = ko.observable("0px");
self.rowDisplayIndex = 0;
self.isEven = ko.computed(function () {
- if (self.rowIndex() % 2 == 0) return true;
+ if (self.rowIndex() % 2 === 0) {
+ return true;
+ }
return false;
});
self.isOdd = ko.computed(function () {
- if (self.rowIndex() % 2 != 0) return true;
+ if (self.rowIndex() % 2 !== 0) {
+ return true;
+ }
return false;
});
self.beforeSelectionChange = config.beforeSelectionChangeCallback;
self.afterSelectionChange = config.afterSelectionChangeCallback;
self.propertyCache = {};
self.getProperty = function (path) {
- return self.propertyCache[path] || (self.propertyCache[path] = kg.utils.evalProperty(self.entity, path));
+ return self.propertyCache[path] || (self.propertyCache[path] = window.kg.utils.evalProperty(self.entity, path));
};
};
/***********************************************
* FILE: ..\src\classes\searchProvider.js
***********************************************/
-kg.SearchProvider = function (grid) {
+window.kg.SearchProvider = function (grid) {
var self = this,
searchConditions = [],
lastSearchStr;
@@ -1612,12 +1673,12 @@ kg.SearchProvider = function (grid) {
self.throttle = grid.config.filterOptions.filterThrottle;
self.fieldMap = {};
self.evalFilter = function () {
- if (searchConditions.length === 0)
+ if (searchConditions.length === 0) {
grid.filteredData(grid.sortedData.peek().filter(function(item) {
return !item._destroy;
}));
- else {
- grid.filteredData(grid.sortedData.peek().filter(function (item) {
+ } else {
+ grid.filteredData(grid.sortedData.peek().filter(function(item) {
if (item._destroy) {
return false;
}
@@ -1629,35 +1690,36 @@ kg.SearchProvider = function (grid) {
for (var prop in item) {
if (item.hasOwnProperty(prop)) {
var pVal = ko.utils.unwrapObservable(item[prop]);
- if (pVal && condition.regex.test(pVal.toString()))
+ if (pVal && condition.regex.test(pVal.toString())) {
return true;
+ }
}
}
return false;
}
//Search by column.
var field = ko.utils.unwrapObservable(item[condition.column]) || ko.utils.unwrapObservable(item[self.fieldMap[condition.columnDisplay]]);
- if (!field || !condition.regex.test(field.toString()))
+ if (!field || !condition.regex.test(field.toString())) {
return false;
+ }
}
return true;
}));
}
grid.rowFactory.filteredDataChanged();
};
- var getRegExp = function (str, modifiers) {
+ var getRegExp = function(str, modifiers) {
try {
return new RegExp(str, modifiers);
- }
- catch (err) {
+ } catch(err) {
//Escape all RegExp metacharacters.
return new RegExp(str.replace(/(\^|\$|\(|\)|\<|\>|\[|\]|\{|\}|\\|\||\.|\*|\+|\?)/g, '\\$1'));
}
- }
+ };
var buildSearchConditions = function (a) {
//reset.
searchConditions = [];
- var qStr = '';
+ var qStr;
if (!(qStr = $.trim(a))) {
return;
}
@@ -1710,7 +1772,7 @@ kg.SearchProvider = function (grid) {
/***********************************************
* FILE: ..\src\classes\selectionService.js
***********************************************/
-kg.SelectionService = function (grid) {
+window.kg.SelectionService = function (grid) {
var self = this;
self.multi = grid.config.multiSelect;
self.selectedItems = grid.config.selectedItems;
@@ -1730,7 +1792,9 @@ kg.SelectionService = function (grid) {
if (self.lastClickedRow) {
var thisIndx = grid.filteredData.indexOf(rowItem.entity);
var prevIndx = grid.filteredData.indexOf(self.lastClickedRow.entity);
- if (thisIndx == prevIndx) return false;
+ if (thisIndx == prevIndx) {
+ return false;
+ }
prevIndx++;
if (thisIndx < prevIndx) {
thisIndx = thisIndx ^ prevIndx;
@@ -1805,7 +1869,7 @@ kg.SelectionService = function (grid) {
/***********************************************
* FILE: ..\src\classes\styleProvider.js
***********************************************/
-kg.StyleProvider = function(grid) {
+window.kg.StyleProvider = function (grid) {
grid.canvasStyle = ko.computed(function() {
return { "height": grid.maxCanvasHt().toString() + "px" };
});
@@ -1816,7 +1880,7 @@ kg.StyleProvider = function(grid) {
return { "width": grid.rootDim.outerWidth() + "px", "height": grid.topPanelHeight() + "px" };
});
grid.headerStyle = ko.computed(function() {
- return { "width": Math.max(0, grid.rootDim.outerWidth() - kg.domUtilityService.ScrollW) + "px", "height": grid.config.headerRowHeight + "px" };
+ return { "width": Math.max(0, grid.rootDim.outerWidth() - window.kg.domUtilityService.ScrollW) + "px", "height": grid.config.headerRowHeight + "px" };
});
grid.viewportStyle = ko.computed(function() {
return { "width": grid.rootDim.outerWidth() + "px", "height": grid.viewportDimHeight() + "px" };
@@ -1829,7 +1893,7 @@ kg.StyleProvider = function(grid) {
/***********************************************
* FILE: ..\src\classes\SortService.js
***********************************************/
-kg.sortService = {
+window.kg.sortService = {
colSortFnCache: {}, // cache of sorting functions. Once we create them, we don't want to keep re-doing it
dateRE: /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/, // nasty regex for date parsing
guessSortFn: function(item) {
@@ -1839,65 +1903,95 @@ kg.sortService = {
month, // for date parsing
day; // for date parsing
- if (item === undefined || item === null || item === '') return null;
+ if (item === undefined || item === null || item === '') {
+ return null;
+ }
itemType = typeof(item);
//check for numbers and booleans
switch (itemType) {
case "number":
- sortFn = kg.sortService.sortNumber;
+ sortFn = window.kg.sortService.sortNumber;
break;
case "boolean":
- sortFn = kg.sortService.sortBool;
+ sortFn = window.kg.sortService.sortBool;
+ break;
+ default:
+ sortFn = undefined;
break;
}
//if we found one, return it
- if (sortFn) return sortFn;
+ if (sortFn) {
+ return sortFn;
+ }
//check if the item is a valid Date
- if (Object.prototype.toString.call(item) === '[object Date]') return kg.sortService.sortDate;
+ if (Object.prototype.toString.call(item) === '[object Date]') {
+ return window.kg.sortService.sortDate;
+ }
// if we aren't left with a string, return a basic sorting function...
- if (itemType !== "string") return kg.sortService.basicSort;
+ if (itemType !== "string") {
+ return window.kg.sortService.basicSort;
+ }
// now lets string check..
//check if the item data is a valid number
- if (item.match(/^-?[£$¤]?[\d,.]+%?$/)) return kg.sortService.sortNumberStr;
+ if (item.match(/^-?[£$¤]?[\d,.]+%?$/)) {
+ return window.kg.sortService.sortNumberStr;
+ }
// check for a date: dd/mm/yyyy or dd/mm/yy
// can have / or . or - as separator
// can be mm/dd as well
- dateParts = item.match(kg.sortService.dateRE);
+ dateParts = item.match(window.kg.sortService.dateRE);
if (dateParts) {
// looks like a date
- month = parseInt(dateParts[1]);
- day = parseInt(dateParts[2]);
+ month = parseInt(dateParts[1], 10);
+ day = parseInt(dateParts[2], 10);
if (month > 12) {
// definitely dd/mm
- return kg.sortService.sortDDMMStr;
+ return window.kg.sortService.sortDDMMStr;
} else if (day > 12) {
- return kg.sortService.sortMMDDStr;
+ return window.kg.sortService.sortMMDDStr;
} else {
// looks like a date, but we can't tell which, so assume that it's MM/DD
- return kg.sortService.sortMMDDStr;
+ return window.kg.sortService.sortMMDDStr;
}
}
//finally just sort the normal string...
- return kg.sortService.sortAlpha;
+ return window.kg.sortService.sortAlpha;
},
basicSort: function(a, b) {
- if (a == b) return 0;
- if (a < b) return -1;
+ if (a == b) {
+ return 0;
+ }
+ if (a < b) {
+ return -1;
+ }
return 1;
},
sortNumber: function(a, b) {
return a - b;
},
sortNumberStr: function(a, b) {
- var numA, numB, badA = false, badB = false;
+ var numA,
+ numB,
+ badA = false,
+ badB = false;
numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
- if (isNaN(numA)) badA = true;
+ if (isNaN(numA)) {
+ badA = true;
+ }
numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
- if (isNaN(numB)) badB = true;
+ if (isNaN(numB)) {
+ badB = true;
+ }
// we want bad ones to get pushed to the bottom... which effectively is "greater than"
- if (badA && badB) return 0;
- if (badA) return 1;
- if (badB) return -1;
+ if (badA && badB) {
+ return 0;
+ }
+ if (badA) {
+ return 1;
+ }
+ if (badB) {
+ return -1;
+ }
return numA - numB;
},
sortAlpha: function(a, b) {
@@ -1906,7 +2000,9 @@ kg.sortService = {
return strA == strB ? 0 : (strA < strB ? -1 : 1);
},
sortBool: function(a, b) {
- if (a && b) return 0;
+ if (a && b) {
+ return 0;
+ }
if (!a && !b) {
return 0;
} else {
@@ -1920,42 +2016,66 @@ kg.sortService = {
},
sortDDMMStr: function(a, b) {
var dateA, dateB, mtch, m, d, y;
- mtch = a.match(kg.sortService.dateRE);
+ mtch = a.match(window.kg.sortService.dateRE);
y = mtch[3];
m = mtch[2];
d = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateA = y + m + d;
- mtch = b.match(kg.sortService.dateRE);
+ mtch = b.match(window.kg.sortService.dateRE);
y = mtch[3];
m = mtch[2];
d = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateB = y + m + d;
- if (dateA == dateB) return 0;
- if (dateA < dateB) return -1;
+ if (dateA == dateB) {
+ return 0;
+ }
+ if (dateA < dateB) {
+ return -1;
+ }
return 1;
},
sortMMDDStr: function(a, b) {
var dateA, dateB, mtch, m, d, y;
- mtch = a.match(kg.sortService.dateRE);
+ mtch = a.match(window.kg.sortService.dateRE);
y = mtch[3];
d = mtch[2];
m = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateA = y + m + d;
mtch = b.match(dateRE);
y = mtch[3];
d = mtch[2];
m = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateB = y + m + d;
- if (dateA == dateB) return 0;
- if (dateA < dateB) return -1;
+ if (dateA == dateB) {
+ return 0;
+ }
+ if (dateA < dateB) {
+ return -1;
+ }
return 1;
},
sortData: function (data /*datasource*/, sortInfo) {
@@ -1970,29 +2090,31 @@ kg.sortService = {
sortFn,
item;
//see if we already figured out what to use to sort the column
- if (kg.sortService.colSortFnCache[col.field]) {
- sortFn = kg.sortService.colSortFnCache[col.field];
+ if (window.kg.sortService.colSortFnCache[col.field]) {
+ sortFn = window.kg.sortService.colSortFnCache[col.field];
} else if (col.sortingAlgorithm != undefined) {
sortFn = col.sortingAlgorithm;
- kg.sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
+ window.kg.sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
} else { // try and guess what sort function to use
item = unwrappedData[0];
- if (!item) return;
+ if (!item) {
+ return;
+ }
sortFn = kg.sortService.guessSortFn(item[col.field]);
//cache it
if (sortFn) {
- kg.sortService.colSortFnCache[col.field] = sortFn;
+ window.kg.sortService.colSortFnCache[col.field] = sortFn;
} else {
// we assign the alpha sort because anything that is null/undefined will never get passed to
// the actual sorting function. It will get caught in our null check and returned to be sorted
// down to the bottom
- sortFn = kg.sortService.sortAlpha;
+ sortFn = window.kg.sortService.sortAlpha;
}
}
//now actually sort the data
unwrappedData.sort(function (itemA, itemB) {
- var propA = kg.utils.evalProperty(itemA, col.field);
- var propB = kg.utils.evalProperty(itemB, col.field);
+ var propA = window.kg.utils.evalProperty(itemA, col.field);
+ var propB = window.kg.utils.evalProperty(itemB, col.field);
// we want to force nulls and such to the bottom when we sort... which effectively is "greater than"
if (!propB && !propA) {
return 0;
@@ -2012,11 +2134,13 @@ kg.sortService = {
return;
},
Sort: function (sortInfo, data) {
- if (kg.sortService.isSorting) return;
- kg.sortService.isSorting = true;
- kg.sortService.sortData(data, sortInfo);
- kg.sortService.isSorting = false;
- },
+ if (window.kg.sortService.isSorting) {
+ return;
+ }
+ window.kg.sortService.isSorting = true;
+ window.kg.sortService.sortData(data, sortInfo);
+ window.kg.sortService.isSorting = false;
+ }
};
/***********************************************
@@ -2029,17 +2153,17 @@ var getWidths = function () {
//measure Scroll Bars
$testContainer.height(100).width(100).css("position", "absolute").css("overflow", "scroll");
$testContainer.append('');
- 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('M');
- 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
@@ -2054,7 +2178,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!
@@ -2087,13 +2211,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));
diff --git a/plugins/koGrid-reorderable.js b/plugins/koGrid-reorderable.js
index dae3929e..4aeddf90 100644
--- a/plugins/koGrid-reorderable.js
+++ b/plugins/koGrid-reorderable.js
@@ -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);
diff --git a/plugins/koGridLayoutPlugin.js b/plugins/koGridLayoutPlugin.js
index d5347f1b..cad1562f 100644
--- a/plugins/koGridLayoutPlugin.js
+++ b/plugins/koGridLayoutPlugin.js
@@ -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);
};
}
diff --git a/src/bindingHandlers/kg-mouse-events.js b/src/bindingHandlers/kg-mouse-events.js
index 21853a74..ac982d58 100644
--- a/src/bindingHandlers/kg-mouse-events.js
+++ b/src/bindingHandlers/kg-mouse-events.js
@@ -5,6 +5,6 @@ ko.bindingHandlers['mouseEvents'] = (function () {
if (eFuncs.mouseDown) {
$(element).mousedown(eFuncs.mouseDown);
}
- },
+ }
};
}());
\ No newline at end of file
diff --git a/src/bindingHandlers/kg-row.js b/src/bindingHandlers/kg-row.js
index 9fe52fdc..0a371757 100644
--- a/src/bindingHandlers/kg-row.js
+++ b/src/bindingHandlers/kg-row.js
@@ -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);
diff --git a/src/bindingHandlers/ko-grid.js b/src/bindingHandlers/ko-grid.js
index 97def1ab..a7c4790e 100644
--- a/src/bindingHandlers/ko-grid.js
+++ b/src/bindingHandlers/ko-grid.js
@@ -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();
});
@@ -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 };
}
};
diff --git a/src/classes/aggregate.js b/src/classes/aggregate.js
index 2c8a0ac8..713eecb5 100644
--- a/src/classes/aggregate.js
+++ b/src/classes/aggregate.js
@@ -5,7 +5,7 @@
///
///
///
-kg.Aggregate = function (aggEntity, rowFactory) {
+window.kg.Aggregate = function (aggEntity, rowFactory) {
var self = this;
self.index = 0;
self.offsetTop = ko.observable(0);
diff --git a/src/classes/column.js b/src/classes/column.js
index 09bb2c54..9d3e1dd9 100644
--- a/src/classes/column.js
+++ b/src/classes/column.js
@@ -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;
@@ -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();
@@ -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;
@@ -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 () {
@@ -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);
@@ -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;
};
diff --git a/src/classes/dimension.js b/src/classes/dimension.js
index 05a9c3ca..f6242cd0 100644
--- a/src/classes/dimension.js
+++ b/src/classes/dimension.js
@@ -1,4 +1,4 @@
-kg.Dimension = function (options) {
+window.kg.Dimension = function (options) {
this.outerHeight = null;
this.outerWidth = null;
$.extend(this, options);
diff --git a/src/classes/domUtilityService.js b/src/classes/domUtilityService.js
index 5342344c..54d350aa 100644
--- a/src/classes/domUtilityService.js
+++ b/src/classes/domUtilityService.js
@@ -12,17 +12,17 @@ var getWidths = function () {
//measure Scroll Bars
$testContainer.height(100).width(100).css("position", "absolute").css("overflow", "scroll");
$testContainer.append('');
- 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('M');
- 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
@@ -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!
@@ -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));
diff --git a/src/classes/eventProvider.js b/src/classes/eventProvider.js
index d9e59c9d..d770f0b6 100644
--- a/src/classes/eventProvider.js
+++ b/src/classes/eventProvider.js
@@ -1,6 +1,6 @@
///
///
-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;
@@ -112,7 +112,9 @@ 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]);
@@ -120,42 +122,53 @@ kg.EventProvider = function (grid) {
// 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 };
}
};
@@ -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);
@@ -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
}
};
@@ -189,7 +204,7 @@ 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
@@ -197,12 +212,13 @@ kg.EventProvider = function (grid) {
//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();
}
diff --git a/src/classes/grid.js b/src/classes/grid.js
index b5a354f4..15ec1887 100644
--- a/src/classes/grid.js
+++ b/src/classes/grid.js
@@ -7,7 +7,7 @@
///
///
///
-kg.Grid = function (options) {
+window.kg.Grid = function (options) {
var defaults = {
rowHeight: 30,
columnWidth: 100,
@@ -46,7 +46,7 @@ kg.Grid = function (options) {
disableTextSelection: true,
filterOptions: {
filterText: ko.observable(""),
- useExternalFilter: false,
+ useExternalFilter: false
},
//Paging
enablePaging: false,
@@ -54,8 +54,8 @@ kg.Grid = function (options) {
pageSizes: ko.observableArray([250, 500, 1000]), //page Sizes
pageSize: ko.observable(250), //Size of Paging data
totalServerItems: ko.observable(0), //how many items are on the server (for paging)
- currentPage: ko.observable(1), //what page they are currently on
- },
+ currentPage: ko.observable(1) //what page they are currently on
+ }
},
self = this;
@@ -63,7 +63,7 @@ kg.Grid = function (options) {
//self vars
self.config = $.extend(defaults, options);
self.config.columnDefs = ko.utils.unwrapObservable(options.columnDefs);
- self.gridId = "ng" + kg.utils.newId();
+ self.gridId = "ng" + window.kg.utils.newId();
self.$root = null; //this is the root element that is passed in with the binding handler
self.$groupPanel = null;
self.$topPanel = null;
@@ -92,7 +92,7 @@ kg.Grid = function (options) {
rowIndexCellW: 25,
rowSelectedCellW: 25,
rootMaxW: 0,
- rootMaxH: 0,
+ rootMaxH: 0
};
//self funcs
self.setRenderedRows = function (newRows) {
@@ -120,7 +120,7 @@ kg.Grid = function (options) {
var item;
item = sd[0];
- kg.utils.forIn(item, function (prop, propName) {
+ window.kg.utils.forIn(item, function (prop, propName) {
if (propName != SELECTED_PROP) {
self.config.columnDefs.push({
field: propName
@@ -148,7 +148,7 @@ kg.Grid = function (options) {
}
if (columnDefs.length > 0) {
$.each(columnDefs, function (i, colDef) {
- var column = new kg.Column({
+ var column = new window.kg.Column({
colDef: colDef,
index: i,
headerRowHeight: self.config.headerRowHeight,
@@ -177,11 +177,11 @@ kg.Grid = function (options) {
$.each(cols, function (i, col) {
var isPercent = false, t = undefined;
//if width is not defined, set it to a single star
- if (kg.utils.isNullOrUndefined(col.width)) {
+ if (window.kg.utils.isNullOrUndefined(col.width)) {
col.width = "*";
} else { // get column width
- isPercent = isNaN(col.width) ? kg.utils.endsWith(col.width, "%") : false;
- t = isPercent ? col.width : parseInt(col.width);
+ isPercent = isNaN(col.width) ? window.kg.utils.endsWith(col.width, "%") : false;
+ t = isPercent ? col.width : parseInt(col.width, 10);
}
// check if it is a number
if (isNaN(t)) {
@@ -205,7 +205,7 @@ kg.Grid = function (options) {
throw "unable to parse column width, use percentage (\"10%\",\"20%\", etc...) or \"*\" to use remaining width of grid";
}
} else {
- totalWidth += columns[i].width = parseInt(col.width);
+ totalWidth += columns[i].width = parseInt(col.width, 10);
}
});
// check if we saved any asterisk columns for calculating later
@@ -225,7 +225,7 @@ kg.Grid = function (options) {
// are we overflowing?
if (self.maxCanvasHt() > self.viewportDimHeight()) {
//compensate for scrollbar
- offset += kg.domUtilityService.ScrollW;
+ offset += window.kg.domUtilityService.ScrollW;
}
columns[col.index].width -= offset;
}
@@ -237,23 +237,25 @@ kg.Grid = function (options) {
// do the math
$.each(percentArray, function (i, col) {
var t = col.width;
- columns[col.index].width = Math.floor(self.rootDim.outerWidth() * (parseInt(t.slice(0, -1)) / 100));
+ columns[col.index].width = Math.floor(self.rootDim.outerWidth() * (parseInt(t.slice(0, -1), 10) / 100));
});
}
self.columns(columns);
- kg.domUtilityService.BuildStyles(self);
+ window.kg.domUtilityService.BuildStyles(self);
};
self.init = function () {
//factories and services
- self.selectionService = new kg.SelectionService(self);
- self.rowFactory = new kg.RowFactory(self);
+ self.selectionService = new window.kg.SelectionService(self);
+ self.rowFactory = new window.kg.RowFactory(self);
self.selectionService.Initialize(self.rowFactory);
- self.searchProvider = new kg.SearchProvider(self);
- self.styleProvider = new kg.StyleProvider(self);
+ self.searchProvider = new window.kg.SearchProvider(self);
+ self.styleProvider = new window.kg.StyleProvider(self);
self.buildColumns();
- kg.sortService.columns = self.columns,
+ window.kg.sortService.columns = self.columns;
self.configGroups.subscribe(function (a) {
- if (!a) return;
+ if (!a) {
+ return;
+ }
var tempArr = [];
$.each(a, function (i, item) {
if(item){
@@ -263,15 +265,14 @@ kg.Grid = function (options) {
self.config.groups = tempArr;
self.rowFactory.filteredDataChanged();
});
- self.columns.subscribe(function () {
- if (self.$$indexPhase) return;
- self.fixColumnIndexes();
- kg.domUtilityService.BuildStyles(self);
- });
self.filteredData.subscribe(function () {
- if (self.$$selectionPhase) return;
+ if (self.$$selectionPhase) {
+ return;
+ }
self.maxCanvasHt(self.calcMaxCanvasHeight());
- if (!self.isSorting) self.configureColumnWidths();
+ if (!self.isSorting) {
+ self.configureColumnWidths();
+ }
});
self.maxCanvasHt(self.calcMaxCanvasHeight());
self.searchProvider.evalFilter();
@@ -283,11 +284,15 @@ kg.Grid = function (options) {
if (self.prevScrollTop === scrollTop && !force) { return; }
var rowIndex = Math.floor(scrollTop / self.config.rowHeight);
// Have we hit the threshold going down?
- if (self.prevScrollTop < scrollTop && rowIndex < self.prevScrollIndex + SCROLL_THRESHOLD) return;
+ if (self.prevScrollTop < scrollTop && rowIndex < self.prevScrollIndex + SCROLL_THRESHOLD) {
+ return;
+ }
//Have we hit the threshold going up?
- if (self.prevScrollTop > scrollTop && rowIndex > self.prevScrollIndex - SCROLL_THRESHOLD) return;
+ if (self.prevScrollTop > scrollTop && rowIndex > self.prevScrollIndex - SCROLL_THRESHOLD) {
+ return;
+ }
self.prevScrollTop = scrollTop;
- self.rowFactory.UpdateViewableRange(new kg.Range(Math.max(0, rowIndex - EXCESS_ROWS), rowIndex + self.minRowsToRender() + EXCESS_ROWS));
+ self.rowFactory.UpdateViewableRange(new window.kg.Range(Math.max(0, rowIndex - EXCESS_ROWS), rowIndex + self.minRowsToRender() + EXCESS_ROWS));
self.prevScrollIndex = rowIndex;
};
self.adjustScrollLeft = function (scrollLeft) {
@@ -298,33 +303,33 @@ kg.Grid = function (options) {
self.resizeOnData = function (col) {
// we calculate the longest data.
var longest = col.minWidth;
- var arr = kg.utils.getElementsByClassName('col' + col.index);
+ var arr = window.kg.utils.getElementsByClassName('col' + col.index);
$.each(arr, function (index, elem) {
var i;
- if (index == 0) {
+ if (index === 0) {
var kgHeaderText = $(elem).find('.kgHeaderText');
- i = kg.utils.visualLength(kgHeaderText) + 10;// +10 some margin
+ i = window.kg.utils.visualLength(kgHeaderText) + 10;// +10 some margin
} else {
var ngCellText = $(elem).find('.kgCellText');
- i = kg.utils.visualLength(ngCellText) + 10; // +10 some margin
+ i = window.kg.utils.visualLength(ngCellText) + 10; // +10 some margin
}
if (i > longest) {
longest = i;
}
});
col.width = longest = Math.min(col.maxWidth, longest + 7); // + 7 px to make it look decent.
- kg.domUtilityService.BuildStyles(self);
+ window.kg.domUtilityService.BuildStyles(self);
};
self.sortData = function (col, direction) {
// if external sorting is being used, do nothing.
self.isSorting = true;
- sortInfo = {
+ self.sortInfo({
column: col,
direction: direction
- };
+ });
self.clearSortingData(col);
if(!self.config.useExternalSorting){
- kg.sortService.Sort(sortInfo, self.sortedData);
+ window.kg.sortService.Sort(sortInfo, self.sortedData);
} else {
self.config.sortInfo(sortInfo);
}
@@ -343,11 +348,10 @@ kg.Grid = function (options) {
self.fixColumnIndexes = function () {
self.$$indexPhase = true;
//fix column indexes
- var cols = self.columns();
+ var cols = self.columns.peek();
$.each(cols, function (i, col) {
col.index = i;
});
- self.columns(cols);
self.$$indexPhase = false;
};
//self vars
@@ -363,7 +367,7 @@ kg.Grid = function (options) {
self.footer = null;
self.selectedItems = self.config.selectedItems;
self.multiSelect = self.config.multiSelect;
- self.footerVisible = kg.utils.isNullOrUndefined(self.config.displayFooter) ? self.config.footerVisible : self.config.displayFooter;
+ self.footerVisible = window.kg.utils.isNullOrUndefined(self.config.displayFooter) ? self.config.footerVisible : self.config.displayFooter;
self.config.footerRowHeight = self.footerVisible ? self.config.footerRowHeight : 0;
self.showColumnMenu = self.config.showColumnMenu;
self.showMenu = ko.observable(false);
@@ -373,13 +377,13 @@ kg.Grid = function (options) {
self.enablePaging = self.config.enablePaging;
self.pagingOptions = self.config.pagingOptions;
//Templates
- self.rowTemplate = self.config.rowTemplate || kg.defaultRowTemplate();
- self.headerRowTemplate = self.config.headerRowTemplate || kg.defaultHeaderRowTemplate();
+ self.rowTemplate = self.config.rowTemplate || window.kg.defaultRowTemplate();
+ self.headerRowTemplate = self.config.headerRowTemplate || window.kg.defaultHeaderRowTemplate();
if (self.config.rowTemplate && !TEMPLATE_REGEXP.test(self.config.rowTemplate)) {
- self.rowTemplate = kg.utils.getTemplatePromise(self.config.rowTemplate);
+ self.rowTemplate = window.kg.utils.getTemplatePromise(self.config.rowTemplate);
}
if (self.config.headerRowTemplate && !TEMPLATE_REGEXP.test(self.config.headerRowTemplate)) {
- self.headerRowTemplate = kg.utils.getTemplatePromise(self.config.headerRowTemplate);
+ self.headerRowTemplate = window.kg.utils.getTemplatePromise(self.config.headerRowTemplate);
}
//scope funcs
self.visibleColumns = ko.computed(function () {
@@ -410,12 +414,14 @@ kg.Grid = function (options) {
self.showGroupPanel = ko.computed(function(){
return self.config.showGroupPanel;
});
- self.topPanelHeight = ko.observable(self.config.showGroupPanel == true ? (self.config.headerRowHeight * 2) : self.config.headerRowHeight);
+ self.topPanelHeight = ko.observable(self.config.showGroupPanel === true ? (self.config.headerRowHeight * 2) : self.config.headerRowHeight);
self.viewportDimHeight = ko.computed(function () {
return Math.max(0, self.rootDim.outerHeight() - self.topPanelHeight() - self.config.footerRowHeight - 2);
});
self.groupBy = function (col) {
- if (self.sortedData().length < 1) return;
+ if (self.sortedData().length < 1) {
+ return;
+ }
var indx = self.configGroups().indexOf(col);
if (indx == -1) {
col.isGroupedBy(true);
@@ -424,6 +430,7 @@ kg.Grid = function (options) {
} else {
self.removeGroup(indx);
}
+ window.kg.domUtilityService.BuildStyles(self);
};
self.removeGroup = function(index) {
var col = self.columns().filter(function(item){
@@ -434,9 +441,10 @@ kg.Grid = function (options) {
self.columns.splice(index, 1);
self.configGroups.splice(index, 1);
self.fixGroupIndexes();
- if (self.configGroups().length == 0) {
+ if (self.configGroups().length === 0) {
self.fixColumnIndexes();
}
+ window.kg.domUtilityService.BuildStyles(self);
};
self.fixGroupIndexes = function(){
$.each(self.configGroups(), function(i,item){
@@ -455,7 +463,7 @@ kg.Grid = function (options) {
var viewportH = self.viewportDimHeight(),
maxHeight = self.maxCanvasHt(),
vScrollBarIsOpen = (maxHeight > viewportH),
- newDim = new kg.Dimension();
+ newDim = new window.kg.Dimension();
newDim.autoFitHeight = true;
newDim.outerWidth = self.totalRowWidth();
diff --git a/src/classes/row.js b/src/classes/row.js
index e7e3ed5c..1a367939 100644
--- a/src/classes/row.js
+++ b/src/classes/row.js
@@ -4,7 +4,7 @@
///
///
///
-kg.Row = function (entity, config, selectionService) {
+window.kg.Row = function (entity, config, selectionService) {
var self = this; // constant for the selection property that we add to each data item
self.canSelectRows = config.canSelectRows;
@@ -48,17 +48,21 @@ kg.Row = function (entity, config, selectionService) {
self.offsetTop = ko.observable("0px");
self.rowDisplayIndex = 0;
self.isEven = ko.computed(function () {
- if (self.rowIndex() % 2 == 0) return true;
+ if (self.rowIndex() % 2 === 0) {
+ return true;
+ }
return false;
});
self.isOdd = ko.computed(function () {
- if (self.rowIndex() % 2 != 0) return true;
+ if (self.rowIndex() % 2 !== 0) {
+ return true;
+ }
return false;
});
self.beforeSelectionChange = config.beforeSelectionChangeCallback;
self.afterSelectionChange = config.afterSelectionChangeCallback;
self.propertyCache = {};
self.getProperty = function (path) {
- return self.propertyCache[path] || (self.propertyCache[path] = kg.utils.evalProperty(self.entity, path));
+ return self.propertyCache[path] || (self.propertyCache[path] = window.kg.utils.evalProperty(self.entity, path));
};
};
\ No newline at end of file
diff --git a/src/classes/rowFactory.js b/src/classes/rowFactory.js
index 188f7118..a69ce3d2 100644
--- a/src/classes/rowFactory.js
+++ b/src/classes/rowFactory.js
@@ -4,7 +4,7 @@
///
///
///
-kg.RowFactory = function(grid) {
+window.kg.RowFactory = function (grid) {
var self = this;
// we cache rows when they are built, and then blow the cache away when sorting
self.rowCache = [];
@@ -27,7 +27,7 @@ kg.RowFactory = function(grid) {
afterSelectionChangeCallback: grid.config.afterSelectionChange
};
- self.renderedRange = new kg.Range(0, grid.minRowsToRender() + EXCESS_ROWS);
+ self.renderedRange = new window.kg.Range(0, grid.minRowsToRender() + EXCESS_ROWS);
// Builds rows for each data item in the 'filteredData'
// @entity - the data item
// @rowIndex - the index of the row
@@ -35,7 +35,7 @@ kg.RowFactory = function(grid) {
var row = self.rowCache[rowIndex]; // first check to see if we've already built it
if (!row) {
// build the row
- row = new kg.Row(entity, self.rowConfig, self.selectionService);
+ row = new window.kg.Row(entity, self.rowConfig, self.selectionService);
row.rowIndex(rowIndex + 1); //not a zero-based rowIndex
row.offsetTop((self.rowHeight * rowIndex).toString() + 'px');
row.selected(entity[SELECTED_PROP]);
@@ -49,7 +49,7 @@ kg.RowFactory = function(grid) {
var agg = self.aggCache[aggEntity.aggIndex]; // first check to see if we've already built it
if (!agg) {
// build the row
- agg = new kg.Aggregate(aggEntity, self);
+ agg = new window.kg.Aggregate(aggEntity, self);
self.aggCache[aggEntity.aggIndex] = agg;
}
agg.index = rowIndex + 1; //not a zero-based rowIndex
@@ -135,9 +135,10 @@ kg.RowFactory = function(grid) {
'_kg_hidden_': false,
children: [],
aggChildren: [],
- aggIndex: self.numberOfAggregates++,
+ aggIndex: self.numberOfAggregates,
aggLabelFilter: g[KG_COLUMN].aggLabelFilter
}, 0);
+ self.numberOfAggregates++;
//set the aggregate parent to the parent in the array that is one less deep.
agg.parent = self.parentCache[agg.depth - 1];
// if we have a parent, set the parent to not be collapsed and append the current agg to its children
@@ -171,31 +172,43 @@ kg.RowFactory = function(grid) {
var ptr = self.groupedData;
$.each(groups, function(depth, group) {
if (!cols[depth].isAggCol && depth <= maxDepth) {
- grid.columns.splice(item.gDepth, 0, new kg.Column({
+ grid.columns.splice(item.gDepth, 0, new window.kg.Column({
colDef: {
field: '',
width: 25,
sortable: false,
resizable: false,
- headerCellTemplate: '',
+ headerCellTemplate: ''
},
isAggCol: true,
index: item.gDepth,
headerRowHeight: grid.config.headerRowHeight
}));
- kg.domUtilityService.BuildStyles(grid);
+ window.kg.domUtilityService.BuildStyles(grid);
}
var col = cols.filter(function (c) { return c.field == group; })[0];
- var val = kg.utils.evalProperty(item, group);
- if (col.cellFilter) val = col.cellFilter(val);
+ var val = window.kg.utils.evalProperty(item, group);
+ if (col.cellFilter) {
+ val = col.cellFilter(val);
+ }
val = val ? val.toString() : 'null';
- if (!ptr[val]) ptr[val] = {};
- if (!ptr[KG_FIELD]) ptr[KG_FIELD] = group;
- if (!ptr[KG_DEPTH]) ptr[KG_DEPTH] = depth;
- if (!ptr[KG_COLUMN]) ptr[KG_COLUMN] = col;
+ if (!ptr[val]) {
+ ptr[val] = {};
+ }
+ if (!ptr[KG_FIELD]) {
+ ptr[KG_FIELD] = group;
+ }
+ if (!ptr[KG_DEPTH]) {
+ ptr[KG_DEPTH] = depth;
+ }
+ if (!ptr[KG_COLUMN]) {
+ ptr[KG_COLUMN] = col;
+ }
ptr = ptr[val];
});
- if (!ptr.values) ptr.values = [];
+ if (!ptr.values) {
+ ptr.values = [];
+ }
ptr.values.push(item);
});
grid.fixColumnIndexes();
diff --git a/src/classes/searchProvider.js b/src/classes/searchProvider.js
index 8658b6f5..2b2c3217 100644
--- a/src/classes/searchProvider.js
+++ b/src/classes/searchProvider.js
@@ -1,4 +1,4 @@
-kg.SearchProvider = function (grid) {
+window.kg.SearchProvider = function (grid) {
var self = this,
searchConditions = [],
lastSearchStr;
@@ -8,12 +8,12 @@
self.throttle = grid.config.filterOptions.filterThrottle;
self.fieldMap = {};
self.evalFilter = function () {
- if (searchConditions.length === 0)
+ if (searchConditions.length === 0) {
grid.filteredData(grid.sortedData.peek().filter(function(item) {
return !item._destroy;
}));
- else {
- grid.filteredData(grid.sortedData.peek().filter(function (item) {
+ } else {
+ grid.filteredData(grid.sortedData.peek().filter(function(item) {
if (item._destroy) {
return false;
}
@@ -25,35 +25,36 @@
for (var prop in item) {
if (item.hasOwnProperty(prop)) {
var pVal = ko.utils.unwrapObservable(item[prop]);
- if (pVal && condition.regex.test(pVal.toString()))
+ if (pVal && condition.regex.test(pVal.toString())) {
return true;
+ }
}
}
return false;
}
//Search by column.
var field = ko.utils.unwrapObservable(item[condition.column]) || ko.utils.unwrapObservable(item[self.fieldMap[condition.columnDisplay]]);
- if (!field || !condition.regex.test(field.toString()))
+ if (!field || !condition.regex.test(field.toString())) {
return false;
+ }
}
return true;
}));
}
grid.rowFactory.filteredDataChanged();
};
- var getRegExp = function (str, modifiers) {
+ var getRegExp = function(str, modifiers) {
try {
return new RegExp(str, modifiers);
- }
- catch (err) {
+ } catch(err) {
//Escape all RegExp metacharacters.
return new RegExp(str.replace(/(\^|\$|\(|\)|\<|\>|\[|\]|\{|\}|\\|\||\.|\*|\+|\?)/g, '\\$1'));
}
- }
+ };
var buildSearchConditions = function (a) {
//reset.
searchConditions = [];
- var qStr = '';
+ var qStr;
if (!(qStr = $.trim(a))) {
return;
}
diff --git a/src/classes/selectionService.js b/src/classes/selectionService.js
index 0d460ff5..287c8bb0 100644
--- a/src/classes/selectionService.js
+++ b/src/classes/selectionService.js
@@ -1,4 +1,4 @@
-kg.SelectionService = function (grid) {
+window.kg.SelectionService = function (grid) {
var self = this;
self.multi = grid.config.multiSelect;
self.selectedItems = grid.config.selectedItems;
@@ -18,7 +18,9 @@ kg.SelectionService = function (grid) {
if (self.lastClickedRow) {
var thisIndx = grid.filteredData.indexOf(rowItem.entity);
var prevIndx = grid.filteredData.indexOf(self.lastClickedRow.entity);
- if (thisIndx == prevIndx) return false;
+ if (thisIndx == prevIndx) {
+ return false;
+ }
prevIndx++;
if (thisIndx < prevIndx) {
thisIndx = thisIndx ^ prevIndx;
diff --git a/src/classes/sortService.js b/src/classes/sortService.js
index 52e9df3f..de8bbe69 100644
--- a/src/classes/sortService.js
+++ b/src/classes/sortService.js
@@ -5,7 +5,7 @@
///
///
///
-kg.sortService = {
+window.kg.sortService = {
colSortFnCache: {}, // cache of sorting functions. Once we create them, we don't want to keep re-doing it
dateRE: /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/, // nasty regex for date parsing
guessSortFn: function(item) {
@@ -15,65 +15,95 @@ kg.sortService = {
month, // for date parsing
day; // for date parsing
- if (item === undefined || item === null || item === '') return null;
+ if (item === undefined || item === null || item === '') {
+ return null;
+ }
itemType = typeof(item);
//check for numbers and booleans
switch (itemType) {
case "number":
- sortFn = kg.sortService.sortNumber;
+ sortFn = window.kg.sortService.sortNumber;
break;
case "boolean":
- sortFn = kg.sortService.sortBool;
+ sortFn = window.kg.sortService.sortBool;
+ break;
+ default:
+ sortFn = undefined;
break;
}
//if we found one, return it
- if (sortFn) return sortFn;
+ if (sortFn) {
+ return sortFn;
+ }
//check if the item is a valid Date
- if (Object.prototype.toString.call(item) === '[object Date]') return kg.sortService.sortDate;
+ if (Object.prototype.toString.call(item) === '[object Date]') {
+ return window.kg.sortService.sortDate;
+ }
// if we aren't left with a string, return a basic sorting function...
- if (itemType !== "string") return kg.sortService.basicSort;
+ if (itemType !== "string") {
+ return window.kg.sortService.basicSort;
+ }
// now lets string check..
//check if the item data is a valid number
- if (item.match(/^-?[£$¤]?[\d,.]+%?$/)) return kg.sortService.sortNumberStr;
+ if (item.match(/^-?[£$¤]?[\d,.]+%?$/)) {
+ return window.kg.sortService.sortNumberStr;
+ }
// check for a date: dd/mm/yyyy or dd/mm/yy
// can have / or . or - as separator
// can be mm/dd as well
- dateParts = item.match(kg.sortService.dateRE);
+ dateParts = item.match(window.kg.sortService.dateRE);
if (dateParts) {
// looks like a date
- month = parseInt(dateParts[1]);
- day = parseInt(dateParts[2]);
+ month = parseInt(dateParts[1], 10);
+ day = parseInt(dateParts[2], 10);
if (month > 12) {
// definitely dd/mm
- return kg.sortService.sortDDMMStr;
+ return window.kg.sortService.sortDDMMStr;
} else if (day > 12) {
- return kg.sortService.sortMMDDStr;
+ return window.kg.sortService.sortMMDDStr;
} else {
// looks like a date, but we can't tell which, so assume that it's MM/DD
- return kg.sortService.sortMMDDStr;
+ return window.kg.sortService.sortMMDDStr;
}
}
//finally just sort the normal string...
- return kg.sortService.sortAlpha;
+ return window.kg.sortService.sortAlpha;
},
basicSort: function(a, b) {
- if (a == b) return 0;
- if (a < b) return -1;
+ if (a == b) {
+ return 0;
+ }
+ if (a < b) {
+ return -1;
+ }
return 1;
},
sortNumber: function(a, b) {
return a - b;
},
sortNumberStr: function(a, b) {
- var numA, numB, badA = false, badB = false;
+ var numA,
+ numB,
+ badA = false,
+ badB = false;
numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
- if (isNaN(numA)) badA = true;
+ if (isNaN(numA)) {
+ badA = true;
+ }
numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
- if (isNaN(numB)) badB = true;
+ if (isNaN(numB)) {
+ badB = true;
+ }
// we want bad ones to get pushed to the bottom... which effectively is "greater than"
- if (badA && badB) return 0;
- if (badA) return 1;
- if (badB) return -1;
+ if (badA && badB) {
+ return 0;
+ }
+ if (badA) {
+ return 1;
+ }
+ if (badB) {
+ return -1;
+ }
return numA - numB;
},
sortAlpha: function(a, b) {
@@ -82,7 +112,9 @@ kg.sortService = {
return strA == strB ? 0 : (strA < strB ? -1 : 1);
},
sortBool: function(a, b) {
- if (a && b) return 0;
+ if (a && b) {
+ return 0;
+ }
if (!a && !b) {
return 0;
} else {
@@ -96,42 +128,66 @@ kg.sortService = {
},
sortDDMMStr: function(a, b) {
var dateA, dateB, mtch, m, d, y;
- mtch = a.match(kg.sortService.dateRE);
+ mtch = a.match(window.kg.sortService.dateRE);
y = mtch[3];
m = mtch[2];
d = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateA = y + m + d;
- mtch = b.match(kg.sortService.dateRE);
+ mtch = b.match(window.kg.sortService.dateRE);
y = mtch[3];
m = mtch[2];
d = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateB = y + m + d;
- if (dateA == dateB) return 0;
- if (dateA < dateB) return -1;
+ if (dateA == dateB) {
+ return 0;
+ }
+ if (dateA < dateB) {
+ return -1;
+ }
return 1;
},
sortMMDDStr: function(a, b) {
var dateA, dateB, mtch, m, d, y;
- mtch = a.match(kg.sortService.dateRE);
+ mtch = a.match(window.kg.sortService.dateRE);
y = mtch[3];
d = mtch[2];
m = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateA = y + m + d;
mtch = b.match(dateRE);
y = mtch[3];
d = mtch[2];
m = mtch[1];
- if (m.length == 1) m = '0' + m;
- if (d.length == 1) d = '0' + d;
+ if (m.length == 1) {
+ m = '0' + m;
+ }
+ if (d.length == 1) {
+ d = '0' + d;
+ }
dateB = y + m + d;
- if (dateA == dateB) return 0;
- if (dateA < dateB) return -1;
+ if (dateA == dateB) {
+ return 0;
+ }
+ if (dateA < dateB) {
+ return -1;
+ }
return 1;
},
sortData: function (data /*datasource*/, sortInfo) {
@@ -146,29 +202,31 @@ kg.sortService = {
sortFn,
item;
//see if we already figured out what to use to sort the column
- if (kg.sortService.colSortFnCache[col.field]) {
- sortFn = kg.sortService.colSortFnCache[col.field];
+ if (window.kg.sortService.colSortFnCache[col.field]) {
+ sortFn = window.kg.sortService.colSortFnCache[col.field];
} else if (col.sortingAlgorithm != undefined) {
sortFn = col.sortingAlgorithm;
- kg.sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
+ window.kg.sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
} else { // try and guess what sort function to use
item = unwrappedData[0];
- if (!item) return;
+ if (!item) {
+ return;
+ }
sortFn = kg.sortService.guessSortFn(item[col.field]);
//cache it
if (sortFn) {
- kg.sortService.colSortFnCache[col.field] = sortFn;
+ window.kg.sortService.colSortFnCache[col.field] = sortFn;
} else {
// we assign the alpha sort because anything that is null/undefined will never get passed to
// the actual sorting function. It will get caught in our null check and returned to be sorted
// down to the bottom
- sortFn = kg.sortService.sortAlpha;
+ sortFn = window.kg.sortService.sortAlpha;
}
}
//now actually sort the data
unwrappedData.sort(function (itemA, itemB) {
- var propA = kg.utils.evalProperty(itemA, col.field);
- var propB = kg.utils.evalProperty(itemB, col.field);
+ var propA = window.kg.utils.evalProperty(itemA, col.field);
+ var propB = window.kg.utils.evalProperty(itemB, col.field);
// we want to force nulls and such to the bottom when we sort... which effectively is "greater than"
if (!propB && !propA) {
return 0;
@@ -188,9 +246,11 @@ kg.sortService = {
return;
},
Sort: function (sortInfo, data) {
- if (kg.sortService.isSorting) return;
- kg.sortService.isSorting = true;
- kg.sortService.sortData(data, sortInfo);
- kg.sortService.isSorting = false;
- },
+ if (window.kg.sortService.isSorting) {
+ return;
+ }
+ window.kg.sortService.isSorting = true;
+ window.kg.sortService.sortData(data, sortInfo);
+ window.kg.sortService.isSorting = false;
+ }
};
\ No newline at end of file
diff --git a/src/classes/styleProvider.js b/src/classes/styleProvider.js
index a9b6b8f3..870654a8 100644
--- a/src/classes/styleProvider.js
+++ b/src/classes/styleProvider.js
@@ -1,4 +1,4 @@
-kg.StyleProvider = function(grid) {
+window.kg.StyleProvider = function (grid) {
grid.canvasStyle = ko.computed(function() {
return { "height": grid.maxCanvasHt().toString() + "px" };
});
@@ -9,7 +9,7 @@
return { "width": grid.rootDim.outerWidth() + "px", "height": grid.topPanelHeight() + "px" };
});
grid.headerStyle = ko.computed(function() {
- return { "width": Math.max(0, grid.rootDim.outerWidth() - kg.domUtilityService.ScrollW) + "px", "height": grid.config.headerRowHeight + "px" };
+ return { "width": Math.max(0, grid.rootDim.outerWidth() - window.kg.domUtilityService.ScrollW) + "px", "height": grid.config.headerRowHeight + "px" };
});
grid.viewportStyle = ko.computed(function() {
return { "width": grid.rootDim.outerWidth() + "px", "height": grid.viewportDimHeight() + "px" };
diff --git a/src/constants.js b/src/constants.js
index 2a93a1d5..e07e4602 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -1,12 +1,12 @@
-var SELECTED_PROP = '__kg_selected__';
-var GRID_KEY = '__koGrid__';
-// the # of rows we want to add to the top and bottom of the rendered grid rows
-var EXCESS_ROWS = 8;
-var SCROLL_THRESHOLD = 6;
-var ASC = "asc"; // constant for sorting direction
-var DESC = "desc"; // constant for sorting direction
-var KG_FIELD = '_kg_field_';
-var KG_DEPTH = '_kg_depth_';
-var KG_HIDDEN = '_kg_hidden_';
-var KG_COLUMN = '_kg_column_';
-var TEMPLATE_REGEXP = /<.+>/;
\ No newline at end of file
+var SELECTED_PROP = '__kg_selected__',
+ GRID_KEY = '__koGrid__',
+ // the # of rows we want to add to the top and bottom of the rendered grid rows
+ EXCESS_ROWS = 8,
+ SCROLL_THRESHOLD = 6,
+ ASC = "asc", // constant for sorting direction
+ DESC = "desc", // constant for sorting direction
+ KG_FIELD = '_kg_field_',
+ KG_DEPTH = '_kg_depth_',
+ KG_HIDDEN = '_kg_hidden_',
+ KG_COLUMN = '_kg_column_',
+ TEMPLATE_REGEXP = /<.+>/;
\ No newline at end of file
diff --git a/src/namespace.js b/src/namespace.js
index f828f08f..0863234a 100644
--- a/src/namespace.js
+++ b/src/namespace.js
@@ -2,5 +2,5 @@
if (!window.kg) {
window.kg = {};
}
-kg.numberOfGrids = 0;
-kg.eventStorage = {};
+window.kg.numberOfGrids = 0;
+window.kg.eventStorage = {};
diff --git a/src/navigation.js b/src/navigation.js
index d7913f3b..0f9c61ad 100644
--- a/src/navigation.js
+++ b/src/navigation.js
@@ -5,18 +5,23 @@
///
///
//set event binding on the grid so we can select using the up/down keys
-kg.moveSelectionHandler = function (grid, evt) {
+window.kg.moveSelectionHandler = function(grid, evt) {
// null checks
- if (grid === null || grid === undefined) return true;
- if (grid.config.selectedItems === undefined) return true;
+ if (window.kg.utils.isNullOrUndefined(grid) || window.kg.utils.isNullOrUndefined(grid.config.selectedItems)) {
+ return true;
+ }
var charCode = (evt.which) ? evt.which : event.keyCode;
// detect which direction for arrow keys to navigate the grid
var offset = (charCode == 38 ? -1 : (charCode == 40 ? 1 : null));
- if (!offset) return true;
+ if (!offset) {
+ return true;
+ }
var items = grid.renderedRows();
var index = items.indexOf(grid.selectionService.lastClickedRow) + offset;
- if (index < 0 || index >= items.length) return true;
- grid.selectionService.ChangeSelection(items[index], evt);
+ if (index < 0 || index >= items.length) {
+ return true;
+ }
+grid.selectionService.ChangeSelection(items[index], evt);
if (index > items.length - EXCESS_ROWS) {
grid.$viewport.scrollTop(grid.$viewport.scrollTop() + (grid.config.rowHeight * EXCESS_ROWS));
} else if (index < EXCESS_ROWS) {
diff --git a/src/templates/aggregateTemplate.html b/src/templates/aggregateTemplate.html
index 73ca979b..5ebfac6f 100644
--- a/src/templates/aggregateTemplate.html
+++ b/src/templates/aggregateTemplate.html
@@ -1,4 +1,4 @@
-
+
( Items)
diff --git a/src/templates/cellTemplate.html b/src/templates/cellTemplate.html
index 9fff343f..ca6eec87 100644
--- a/src/templates/cellTemplate.html
+++ b/src/templates/cellTemplate.html
@@ -1,2 +1,2 @@
-
+
diff --git a/src/templates/gridTemplate.html b/src/templates/gridTemplate.html
index 74a3225c..14b0267c 100644
--- a/src/templates/gridTemplate.html
+++ b/src/templates/gridTemplate.html
@@ -1,4 +1,4 @@
-
+
diff --git a/src/templates/headerCellTemplate.html b/src/templates/headerCellTemplate.html
index 19943697..932190c7 100644
--- a/src/templates/headerCellTemplate.html
+++ b/src/templates/headerCellTemplate.html
@@ -1,4 +1,4 @@
-
+
diff --git a/src/templates/headerRowTemplate.html b/src/templates/headerRowTemplate.html
index f9e87a2f..4229aae7 100644
--- a/src/templates/headerRowTemplate.html
+++ b/src/templates/headerRowTemplate.html
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/src/templates/rowTemplate.html b/src/templates/rowTemplate.html
index def83d84..33e74352 100644
--- a/src/templates/rowTemplate.html
+++ b/src/templates/rowTemplate.html
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/src/utils.js b/src/utils.js
index c95eaec4..5ef219d5 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -6,43 +6,45 @@ if (!String.prototype.trim) {
return this.replace(/^\s+|\s+$/g, '');
};
}
-if (!Array.prototype.indexOf)
-{
- Array.prototype.indexOf = function(elt /*, from*/){
- var len = this.length >>> 0;
- var from = Number(arguments[1]) || 0;
- from = (from < 0) ? Math.ceil(from) : Math.floor(from);
- if (from < 0) from += len;
- for (; from < len; from++){
- if (from in this && this[from] === elt) return from;
- }
- return -1;
- };
+if (!Array.prototype.indexOf) {
+ Array.prototype.indexOf = function(elt /*, from*/) {
+ var len = this.length >>> 0;
+ var from = Number(arguments[1]) || 0;
+ from = (from < 0) ? Math.ceil(from) : Math.floor(from);
+ if (from < 0) {
+ from += len;
+ }
+ for (; from < len; from++) {
+ if (from in this && this[from] === elt) {
+ return from;
+ }
+ }
+ return -1;
+ };
}
-if (!Array.prototype.filter)
-{
- Array.prototype.filter = function(fun /*, thisp */)
- {
- "use strict";
- var t = Object(this);
- var len = t.length >>> 0;
- if (typeof fun !== "function")throw new TypeError();
- var res = [];
- var thisp = arguments[1];
- for (var i = 0; i < len; i++)
- {
- if (i in t)
- {
- var val = t[i]; // in case fun mutates this
- if (fun.call(thisp, val, i, t))
- res.push(val);
- }
- }
- return res;
- };
+if (!Array.prototype.filter) {
+ Array.prototype.filter = function(fun /*, thisp */) {
+ "use strict";
+ var t = Object(this);
+ var len = t.length >>> 0;
+ if (typeof fun !== "function") {
+ throw new TypeError();
+ }
+ var res = [];
+ var thisp = arguments[1];
+ for (var i = 0; i < len; i++) {
+ if (i in t) {
+ var val = t[i]; // in case fun mutates this
+ if (fun.call(thisp, val, i, t)) {
+ res.push(val);
+ }
+ }
+ }
+ return res;
+ };
}
-kg.utils = {
- visualLength: function (node) {
+window.kg.utils = {
+ visualLength: function(node) {
var elem = document.getElementById('testDataLength');
if (!elem) {
elem = document.createElement('SPAN');
@@ -54,71 +56,77 @@ kg.utils = {
elem.innerHTML = $(node).text();
return elem.offsetWidth;
},
- forIn: function (obj, action) {
- for (var prop in obj) {
- if(obj.hasOwnProperty(prop)){
+ forIn: function(obj, action) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) {
action(obj[prop], prop);
}
}
},
- evalProperty: function (entity, path) {
+ evalProperty: function(entity, path) {
var e = ko.utils.unwrapObservable(entity);
var propPath = path.split('.'), i = 0;
- var tempProp = ko.utils.unwrapObservable(e[propPath[i++]]), links = propPath.length;
+ var tempProp = ko.utils.unwrapObservable(e[propPath[i]]), links = propPath.length;
+ i++;
while (tempProp && i < links) {
- tempProp = ko.utils.unwrapObservable(tempProp[propPath[i++]]);
+ tempProp = ko.utils.unwrapObservable(tempProp[propPath[i]]);
+ i++;
}
return tempProp;
},
- endsWith: function (str, suffix) {
- if (!str || !suffix || typeof str != "string") return false;
+ endsWith: function(str, suffix) {
+ if (!str || !suffix || typeof str != "string") {
+ return false;
+ }
return str.indexOf(suffix, str.length - suffix.length) !== -1;
},
- isNullOrUndefined: function (obj) {
- if (obj === undefined || obj === null) return true;
+ isNullOrUndefined: function(obj) {
+ if (obj === undefined || obj === null) {
+ return true;
+ }
return false;
},
getElementsByClassName: function(cl) {
var retnode = [];
- var myclass = new RegExp('\\b'+cl+'\\b');
+ var myclass = new RegExp('\\b' + cl + '\\b');
var elem = document.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
- if (myclass.test(classes)) retnode.push(elem[i]);
+ if (myclass.test(classes)) {
+ retnode.push(elem[i]);
+ }
}
return retnode;
},
getTemplatePromise: function(path) {
return $.ajax(path);
},
- newId: (function () {
+ newId: (function() {
var seedId = new Date().getTime();
- return function () {
+ return function() {
return seedId += 1;
};
})(),
// we copy KO's ie detection here bc it isn't exported in the min versions of KO
// Detect IE versions for workarounds (uses IE conditionals, not UA string, for robustness)
- ieVersion: (function () {
+ ieVersion: (function() {
var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');
// Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
- while (
- div.innerHTML = '',
- iElems[0]
- );
+ while (div.innerHTML = '',
+ iElems[0]) ;
return version > 4 ? version : undefined;
})()
};
-$.extend(kg.utils, {
- isIe6: (function(){
- return kg.utils.ieVersion === 6;
+$.extend(window.kg.utils, {
+ isIe6: (function() {
+ return window.kg.utils.ieVersion === 6;
+ })(),
+ isIe7: (function() {
+ return window.kg.utils.ieVersion === 7;
})(),
- isIe7: (function(){
- return kg.utils.ieVersion === 7;
- } )(),
- isIe: (function () {
- return kg.utils.ieVersion !== undefined;
+ isIe: (function() {
+ return window.kg.utils.ieVersion !== undefined;
})()
-});
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/workbench/main.js b/workbench/main.js
index 1d4301dd..e2d607fc 100644
--- a/workbench/main.js
+++ b/workbench/main.js
@@ -12,7 +12,7 @@ function mainViewModel() {
self.myData = ko.observableArray([]);
self.filterOptions = {
filterText: ko.observable(""),
- useExternalFilter: false,
+ useExternalFilter: false
};
self.pagingOptions = {
pageSizes: ko.observable([250, 500, 1000]), //page Sizes