Skip to content

Commit 494db89

Browse files
committed
ui-scroll-grid refactoring and build fix
1 parent a52a0c6 commit 494db89

File tree

4 files changed

+102
-96
lines changed

4 files changed

+102
-96
lines changed

Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ module.exports = function (grunt) {
6868
]
6969
},
7070
files: {
71+
"./temp/ui-scroll-jqlite.js": ["./src/ui-scroll-jqlite.js"],
7172
"./temp/ui-scroll.js": ["./src/ui-scroll.js"],
72-
"./temp/ui-scroll-jqlite.js": ["./src/ui-scroll-jqlite.js"]
73+
"./temp/ui-scroll-grid.js": ["./src/ui-scroll-grid.js"]
7374
}
7475
}
7576
},

dist/ui-scroll-grid.js

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*!
22
* angular-ui-scroll
33
* https://github.com/angular-ui/ui-scroll.git
4-
* Version: 1.5.2 -- 2017-01-13T00:53:53.341Z
4+
* Version: 1.5.2 -- 2017-01-13T01:48:13.045Z
55
* License: MIT
66
*/
77

88

99
(function () {
10+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=='function'&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error('Cannot find module \''+o+'\'');throw f.code='MODULE_NOT_FOUND',f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=='function'&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
1011
'use strict';
1112

1213
angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout', function (console, $timeout) {
@@ -48,11 +49,11 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
4849
};
4950

5051
this.moveBefore = function (index) {
51-
controller.moveBefore(column, index);
52+
return controller.moveBefore(column, index);
5253
};
5354

5455
this.exchangeWith = function (index) {
55-
controller.exchangeWith(column, index);
56+
return controller.exchangeWith(column, index);
5657
};
5758

5859
Object.defineProperty(this, 'columnId', { get: function get() {
@@ -63,7 +64,6 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
6364
function ColumnController(controller, columns, header) {
6465

6566
this.header = header;
66-
this.cells = [];
6767
this.css = {};
6868
this.mapTo = columns.length;
6969
this.id = columns.length;
@@ -95,10 +95,12 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
9595
this.columnFromPoint = function (x, y) {
9696
var _this2 = this;
9797

98-
if (insidePoint(header, x, y)) return this;
99-
var result = undefined;
98+
if (insidePoint(header, x, y)) {
99+
return this;
100+
}
101+
var result = null;
100102
controller.forEachRow(function (row) {
101-
if (insidePoint(row[_this2.id], x, y)) result = _this2;
103+
return result = insidePoint(row[_this2.id], x, y) ? _this2 : result;
102104
});
103105
return result;
104106
};
@@ -121,7 +123,7 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
121123
target.before(element);
122124
}
123125

124-
function moveLast(element, target) {
126+
function moveLast(element) {
125127
var parent = element.parent();
126128
element.detach();
127129
parent.append(element);
@@ -130,12 +132,14 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
130132
function applyCss(target, css) {
131133
target.removeAttr('style');
132134
for (var attr in css) {
133-
if (css.hasOwnProperty(attr)) target.css(attr, css[attr]);
135+
if (css.hasOwnProperty(attr)) {
136+
target.css(attr, css[attr]);
137+
}
134138
}
135-
};
139+
}
136140
}
137141

138-
function GridController(scope, scrollViewport) {
142+
function GridController(scrollViewport) {
139143
var _this3 = this;
140144

141145
var columns = [];
@@ -154,13 +158,13 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
154158

155159
this.registerCell = function (scope, cell) {
156160
var row = rowMap.get(scope);
157-
158161
if (!row) {
159162
row = [];
160163
rowMap.set(scope, row);
161164
}
162-
163-
if (row.length >= columns.length) return false;
165+
if (row.length >= columns.length) {
166+
return false;
167+
}
164168
row.push(cell);
165169
return true;
166170
};
@@ -169,7 +173,9 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
169173
var row = rowMap.get(scope);
170174
var i = row.indexOf(cell);
171175
row.splice(i, 1);
172-
if (!row.length) rowMap.delete(scope);
176+
if (!row.length) {
177+
rowMap['delete'](scope);
178+
}
173179
};
174180

175181
this.forEachRow = function (callback) {
@@ -205,25 +211,28 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
205211
throw new Error('Failed to apply layout - number of layouts should match number of columns');
206212
}
207213
layouts.forEach(function (layout, index) {
208-
columns[index].applyLayout(layout);
214+
return columns[index].applyLayout(layout);
209215
});
210216
transform(columns.map(function (column) {
211217
return column.header;
212218
}));
213219
rowMap.forEach(function (row) {
214-
transform(row);
220+
return transform(row);
215221
});
216222
};
217223

218224
this.moveBefore = function (selected, target) {
219225
var index = target;
220226

221-
if (target % 1 !== 0) index = target ? columns[target.columnId].mapTo : columns.length;
222-
223-
if (index < 0 || index > columns.length) return; // throw an error?
227+
if (target % 1 !== 0) {
228+
index = target ? columns[target.columnId].mapTo : columns.length;
229+
}
230+
if (index < 0 || index > columns.length) {
231+
return; // throw an error?
232+
}
224233

225234
var mapTo = selected.mapTo,
226-
next = undefined;
235+
next = null;
227236
index -= mapTo < index ? 1 : 0;
228237

229238
columns.forEach(function (c) {
@@ -237,20 +246,20 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
237246
};
238247

239248
this.exchangeWith = function (selected, index) {
240-
if (index < 0 || index >= columns.length) return;
249+
if (index < 0 || index >= columns.length) {
250+
return;
251+
}
241252
columns.find(function (c) {
242253
return c.mapTo === index;
243254
}).mapTo = selected.mapTo;
244255
selected.mapTo = index;
245256
};
246257

247258
this.columnFromPoint = function (x, y) {
248-
for (var i = 0; i < columns.length; i++) {
249-
var column = columns[i].columnFromPoint(x, y);
250-
if (column) break;
251-
}
252-
if (column) return new ColumnAdapter(this, column);
253-
return undefined;
259+
var column = columns.find(function (col) {
260+
return col.columnFromPoint(x, y);
261+
});
262+
return column ? new ColumnAdapter(this, column) : undefined;
254263
};
255264

256265
// function definitions
@@ -274,16 +283,16 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
274283
return {
275284
require: ['^^uiScrollViewport'],
276285
restrict: 'A',
277-
link: function link($scope, element, $attr, controllers, linker) {
278-
controllers[0].gridController = controllers[0].gridController || new GridController($scope, controllers[0]);
286+
link: function link($scope, element, $attr, controllers) {
287+
controllers[0].gridController = controllers[0].gridController || new GridController(controllers[0]);
279288
controllers[0].gridController.registerColumn(element);
280289
}
281290
};
282-
}]).directive('uiScrollTd', ['$log', function (console) {
291+
}]).directive('uiScrollTd', ['$log', function () {
283292
return {
284293
require: ['?^^uiScrollViewport'],
285294
restrict: 'A',
286-
link: function link($scope, element, $attr, controllers, linker) {
295+
link: function link($scope, element, $attr, controllers) {
287296
if (controllers[0]) {
288297
(function () {
289298
var gridController = controllers[0].gridController;
@@ -297,4 +306,6 @@ angular.module('ui.scroll.grid', []).directive('uiScrollTh', ['$log', '$timeout'
297306
}
298307
};
299308
}]);
309+
310+
},{}]},{},[1]);
300311
}());

dist/ui-scroll-grid.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)