Skip to content

Commit 2fe9698

Browse files
committed
Merge pull request nasa#891 from nasa/fix-clickaway-888
[General] remove dupe, debounce inputs
2 parents c6d326b + 7fad4e9 commit 2fe9698

File tree

6 files changed

+22
-230
lines changed

6 files changed

+22
-230
lines changed

platform/commonUI/general/bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ define([
268268
"key": "ClickAwayController",
269269
"implementation": ClickAwayController,
270270
"depends": [
271-
"$scope",
272-
"$document"
271+
"$document",
272+
"$timeout"
273273
]
274274
},
275275
{

platform/commonUI/general/src/controllers/ClickAwayController.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* this source code distribution or the Licensing information page available
2020
* at runtime from the About dialog for additional information.
2121
*****************************************************************************/
22-
/*global define,Promise*/
22+
/*global define*/
2323

2424
define(
2525
[],
@@ -36,20 +36,19 @@ define(
3636
* @param $scope the scope in which this controller is active
3737
* @param $document the document element, injected by Angular
3838
*/
39-
function ClickAwayController($scope, $document) {
39+
function ClickAwayController($document, $timeout) {
4040
var self = this;
4141

4242
this.state = false;
43-
this.$scope = $scope;
4443
this.$document = $document;
4544

46-
// Callback used by the document listener. Deactivates;
47-
// note also $scope.$apply is invoked to indicate that
48-
// the state of this controller has changed.
45+
// Callback used by the document listener. Timeout ensures that
46+
// `clickaway` action occurs after `toggle` if `toggle` is
47+
// triggered by a click/mouseup.
4948
this.clickaway = function () {
50-
self.deactivate();
51-
$scope.$apply();
52-
return false;
49+
$timeout(function () {
50+
self.deactivate();
51+
});
5352
};
5453
}
5554

platform/commonUI/general/test/controllers/ClickAwayControllerSpec.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@
1919
* this source code distribution or the Licensing information page available
2020
* at runtime from the About dialog for additional information.
2121
*****************************************************************************/
22-
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
22+
/*global define,describe,it,expect,beforeEach,jasmine*/
2323

2424
define(
2525
["../../src/controllers/ClickAwayController"],
2626
function (ClickAwayController) {
2727
"use strict";
2828

2929
describe("The click-away controller", function () {
30-
var mockScope,
31-
mockDocument,
30+
var mockDocument,
31+
mockTimeout,
3232
controller;
3333

3434
beforeEach(function () {
35-
mockScope = jasmine.createSpyObj(
36-
"$scope",
37-
[ "$apply" ]
38-
);
3935
mockDocument = jasmine.createSpyObj(
4036
"$document",
4137
[ "on", "off" ]
4238
);
43-
controller = new ClickAwayController(mockScope, mockDocument);
39+
mockTimeout = jasmine.createSpy('timeout');
40+
controller = new ClickAwayController(
41+
mockDocument,
42+
mockTimeout
43+
);
4444
});
4545

4646
it("is initially inactive", function () {
@@ -79,10 +79,12 @@ define(
7979
});
8080

8181
it("deactivates and detaches listener on document click", function () {
82-
var callback;
82+
var callback, timeout;
8383
controller.setState(true);
8484
callback = mockDocument.on.mostRecentCall.args[1];
8585
callback();
86+
timeout = mockTimeout.mostRecentCall.args[0];
87+
timeout();
8688
expect(controller.isActive()).toEqual(false);
8789
expect(mockDocument.off).toHaveBeenCalledWith("mouseup", callback);
8890
});
@@ -91,4 +93,4 @@ define(
9193

9294
});
9395
}
94-
);
96+
);

platform/search/bundle.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
define([
2525
"./src/controllers/SearchController",
2626
"./src/controllers/SearchMenuController",
27-
"./src/controllers/ClickAwayController",
2827
"./src/services/GenericSearchProvider",
2928
"./src/services/SearchAggregator",
3029
"text!./res/templates/search-item.html",
@@ -34,7 +33,6 @@ define([
3433
], function (
3534
SearchController,
3635
SearchMenuController,
37-
ClickAwayController,
3836
GenericSearchProvider,
3937
SearchAggregator,
4038
searchItemTemplate,
@@ -73,14 +71,6 @@ define([
7371
"$scope",
7472
"types[]"
7573
]
76-
},
77-
{
78-
"key": "ClickAwayController",
79-
"implementation": ClickAwayController,
80-
"depends": [
81-
"$scope",
82-
"$document"
83-
]
8474
}
8575
],
8676
"representations": [

platform/search/src/controllers/ClickAwayController.js

Lines changed: 0 additions & 105 deletions
This file was deleted.

platform/search/test/controllers/ClickAwayControllerSpec.js

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)