Skip to content

Commit 15ee480

Browse files
committed
fix(gridUtil): rtlScrollType using wrong method
rtlScrollType was not using angular.element().remove() to remove a temporary element from the DOM. This was working in Chrome and perhaps other browsers but failing in IE, and would only show up on RTL grids. Fixes #3637
1 parent 58bd0eb commit 15ee480

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

src/js/core/services/ui-grid-util.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
4646
val = 0;
4747

4848
var sides = ['Top', 'Right', 'Bottom', 'Left'];
49-
49+
5050
for ( ; i < 4; i += 2 ) {
5151
var side = sides[i];
5252
// dump('side', side);
@@ -166,7 +166,7 @@ var uidPrefix = 'uiGrid-';
166166
/**
167167
* @ngdoc service
168168
* @name ui.grid.service:GridUtil
169-
*
169+
*
170170
* @description Grid utility functions
171171
*/
172172
module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateCache', '$timeout', '$interval', '$injector', '$q', '$interpolate', 'uiGridConstants',
@@ -292,7 +292,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
292292
if (angular.isUndefined(excludeProperties)) { excludeProperties = []; }
293293

294294
var item = data[0];
295-
295+
296296
angular.forEach(item,function (prop, propName) {
297297
if ( excludeProperties.indexOf(propName) === -1){
298298
columnDefs.push({
@@ -383,7 +383,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
383383
.then(s.postProcessTemplate);
384384
},
385385

386-
//
386+
//
387387
postProcessTemplate: function (template) {
388388
var startSym = $interpolate.startSymbol(),
389389
endSym = $interpolate.endSymbol();
@@ -440,7 +440,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
440440
* @returns {number} Element width in pixels, accounting for any borders, etc.
441441
*/
442442
elementWidth: function (elem) {
443-
443+
444444
},
445445

446446
/**
@@ -454,7 +454,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
454454
* @returns {number} Element height in pixels, accounting for any borders, etc.
455455
*/
456456
elementHeight: function (elem) {
457-
457+
458458
},
459459

460460
// Thanks to http://stackoverflow.com/a/13382873/888165
@@ -473,7 +473,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
473473
// add innerdiv
474474
var inner = document.createElement("div");
475475
inner.style.width = "100%";
476-
outer.appendChild(inner);
476+
outer.appendChild(inner);
477477

478478
var widthWithScroll = inner.offsetWidth;
479479

@@ -541,7 +541,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
541541
// var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'];
542542
// var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'];
543543
var lowestDelta, lowestDeltaXY;
544-
544+
545545
var orgEvent = event || window.event,
546546
args = [].slice.call(arguments, 1),
547547
delta = 0,
@@ -727,7 +727,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
727727
resetUids: function () {
728728
uid = ['0', '0', '0'];
729729
},
730-
730+
731731
/**
732732
* @ngdoc method
733733
* @methodOf ui.grid.service:GridUtil
@@ -736,7 +736,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
736736
* treatment within ui-grid if we so desired. At present we only log
737737
* error messages if uiGridConstants.LOG_ERROR_MESSAGES is set to true
738738
* @param {string} logMessage message to be logged to the console
739-
*
739+
*
740740
*/
741741
logError: function( logMessage ){
742742
if ( uiGridConstants.LOG_ERROR_MESSAGES ){
@@ -752,7 +752,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
752752
* treatment within ui-grid if we so desired. At present we only log
753753
* warning messages if uiGridConstants.LOG_WARN_MESSAGES is set to true
754754
* @param {string} logMessage message to be logged to the console
755-
*
755+
*
756756
*/
757757
logWarn: function( logMessage ){
758758
if ( uiGridConstants.LOG_WARN_MESSAGES ){
@@ -767,7 +767,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
767767
* @description wraps the $log method, allowing us to choose different
768768
* treatment within ui-grid if we so desired. At present we only log
769769
* debug messages if uiGridConstants.LOG_DEBUG_MESSAGES is set to true
770-
*
770+
*
771771
*/
772772
logDebug: function() {
773773
if ( uiGridConstants.LOG_DEBUG_MESSAGES ){
@@ -903,7 +903,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
903903
}
904904
}
905905

906-
definer.remove();
906+
angular.element(definer).remove();
907907
rtlScrollType.type = type;
908908

909909
return type;
@@ -1080,11 +1080,11 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
10801080
* trailing (bool) - whether to trigger after throttle time ends if called multiple times
10811081
* Updated to use $interval rather than $timeout, as protractor (e2e tests) is able to work with $interval,
10821082
* but not with $timeout
1083-
*
1083+
*
10841084
* Note that when using throttle, you need to use throttle to create a new function upfront, then use the function
10851085
* return from that call each time you need to call throttle. If you call throttle itself repeatedly, the lastCall
10861086
* variable will get overwritten and the throttling won't work
1087-
*
1087+
*
10881088
* @example
10891089
* <pre>
10901090
* var throttledFunc = gridUtil.throttle(function(){console.log('throttled');}, 500, {trailing: true});
@@ -1258,7 +1258,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
12581258
// offsetX = event.clientX - boundingRect.left;
12591259
// offsetY = event.clientY - boundingRect.top;
12601260
// }
1261-
1261+
12621262
// event.deltaX = deltaX;
12631263
// event.deltaY = deltaY;
12641264
// event.deltaFactor = lowestDelta;

test/unit/core/services/ui-grid-util.spec.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('ui.grid.utilService', function() {
105105
translationExpects.forEach( function (set) {
106106
var strIn = set[0];
107107
var strOut = set[1];
108-
108+
109109
expect(gridUtil.readableColumnName(strIn)).toEqual(strOut);
110110
});
111111
});
@@ -139,7 +139,7 @@ describe('ui.grid.utilService', function() {
139139
]);
140140
});
141141
});
142-
142+
143143
describe('getColumnsFromData', function() {
144144
it('should create column defs from a data array omitting $$hashKey', function() {
145145
var data = [
@@ -149,7 +149,7 @@ describe('ui.grid.utilService', function() {
149149
$$hashKey: '00A'
150150
}
151151
];
152-
152+
153153
var excludeProperties = ['$$hashKey'];
154154

155155
var columns = gridUtil.getColumnsFromData(data, excludeProperties);
@@ -368,7 +368,7 @@ describe('ui.grid.utilService', function() {
368368
describe('resetUids()', function () {
369369
it('should reset the UID index back to 000', function () {
370370
gridUtil.resetUids();
371-
371+
372372
for (var i = 0; i < 50; i++) {
373373
gridUtil.nextUid();
374374
}
@@ -513,4 +513,13 @@ describe('ui.grid.utilService', function() {
513513
}));
514514
});
515515
});
516-
});
516+
517+
describe('rtlScrollType', function () {
518+
it('should not throw an exception', function () {
519+
// This was throwing an exception in IE because IE doesn't have a native <element>.remove() method.
520+
expect(function () {
521+
gridUtil.rtlScrollType();
522+
}).not.toThrow();
523+
});
524+
});
525+
});

0 commit comments

Comments
 (0)