From 57d543107b2b44715cd0bc6312e1da2b0327bb6b Mon Sep 17 00:00:00 2001 From: Tim Jones Date: Mon, 19 Jan 2015 22:51:53 -0600 Subject: [PATCH] =?UTF-8?q?I=20=E2=99=A5=20Lo-Dash,=20but=20for=20now,=20l?= =?UTF-8?q?ess=20dependencies=20seems=20better=20than=20more?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/tcGridDirective.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/js/tcGridDirective.js b/src/js/tcGridDirective.js index ecaaefc..f8cea68 100644 --- a/src/js/tcGridDirective.js +++ b/src/js/tcGridDirective.js @@ -1,8 +1,8 @@ (function () { 'use strict'; - angular.module('tc-grid', []); - angular.module('tc-grid').directive('tcGrid', tcGrid); - angular.module('tc-grid').directive('tcGridColumn', tcGridColumn); + angular.module('tc-grid', []) + .directive('tcGrid', tcGrid) + .directive('tcGridColumn', tcGridColumn); function tcGrid($parse, $templateCache) { return { @@ -11,7 +11,7 @@ var children = element.children(); var headerHtml = ""; - _.each(children, function (child) { + angular.forEach(children, function (child) { var el = angular.element(child); var colField = el.attr('tc-col-field'); @@ -29,13 +29,12 @@ if (ignoreClick) el.attr('ng-click', '$event.stopPropagation();'); - if (el.html() === '' && colField) el.html('{{row.' + colField + '}}'); headerHtml += '
' + colName + '
'; }); - + var templateHtml = $templateCache.get('tcGrid.html'); templateHtml = templateHtml.replace(/%OPTIONS%/g, attrs.tcGridOptions); @@ -62,13 +61,15 @@ // TODO: This could probably just be removed and replaced with code in the compile which already traverses the children elements this.addColumn = function (col) { - if (options && _.indexOf(options.internal.columns, col) == -1) { + if (options && options.internal.columns.indexOf(col) == -1) { options.internal.columns.push(col); } }; var options = $parse($attrs.tcGridOptions)($scope); + var watchInitialized = false; + return init(); function init() { @@ -105,9 +106,14 @@ } function initWatch() { - $scope.$watch($attrs.tcGridOptions, _.after(2, pageCountWatcher), true); + $scope.$watch($attrs.tcGridOptions, pageCountWatcher, true); function pageCountWatcher() { + if(!watchInitialized) { + watchInitialized = true; + return; + } + options = $parse($attrs.tcGridOptions)($scope); if (options && options.paging) @@ -133,7 +139,7 @@ function initSort() { if(!options.sorting.sort) return; - _.each(options.sorting.sort, function (sortItem) { + angular.forEach(options.sorting.sort, function (sortItem) { var col = sortItem.split(' ')[0]; var dir = sortItem.split(' ')[1] || 'asc'; @@ -216,7 +222,7 @@ } function cleanSortClasses() { - _.each(options.internal.columns, function (col) { + angular.forEach(options.internal.columns, function (col) { var colElement = fetchColumn(col); colElement.removeClass('desc'); colElement.removeClass('asc');