Merge pull request #891 from nasa/fix-clickaway-888
[General] remove dupe, debounce inputs
This commit is contained in:
@@ -268,8 +268,8 @@ define([
|
||||
"key": "ClickAwayController",
|
||||
"implementation": ClickAwayController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$document"
|
||||
"$document",
|
||||
"$timeout"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define,Promise*/
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
@@ -36,20 +36,19 @@ define(
|
||||
* @param $scope the scope in which this controller is active
|
||||
* @param $document the document element, injected by Angular
|
||||
*/
|
||||
function ClickAwayController($scope, $document) {
|
||||
function ClickAwayController($document, $timeout) {
|
||||
var self = this;
|
||||
|
||||
this.state = false;
|
||||
this.$scope = $scope;
|
||||
this.$document = $document;
|
||||
|
||||
// Callback used by the document listener. Deactivates;
|
||||
// note also $scope.$apply is invoked to indicate that
|
||||
// the state of this controller has changed.
|
||||
// Callback used by the document listener. Timeout ensures that
|
||||
// `clickaway` action occurs after `toggle` if `toggle` is
|
||||
// triggered by a click/mouseup.
|
||||
this.clickaway = function () {
|
||||
self.deactivate();
|
||||
$scope.$apply();
|
||||
return false;
|
||||
$timeout(function () {
|
||||
self.deactivate();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
/*global define,describe,it,expect,beforeEach,jasmine*/
|
||||
|
||||
define(
|
||||
["../../src/controllers/ClickAwayController"],
|
||||
@@ -27,20 +27,20 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("The click-away controller", function () {
|
||||
var mockScope,
|
||||
mockDocument,
|
||||
var mockDocument,
|
||||
mockTimeout,
|
||||
controller;
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
[ "$apply" ]
|
||||
);
|
||||
mockDocument = jasmine.createSpyObj(
|
||||
"$document",
|
||||
[ "on", "off" ]
|
||||
);
|
||||
controller = new ClickAwayController(mockScope, mockDocument);
|
||||
mockTimeout = jasmine.createSpy('timeout');
|
||||
controller = new ClickAwayController(
|
||||
mockDocument,
|
||||
mockTimeout
|
||||
);
|
||||
});
|
||||
|
||||
it("is initially inactive", function () {
|
||||
@@ -79,10 +79,12 @@ define(
|
||||
});
|
||||
|
||||
it("deactivates and detaches listener on document click", function () {
|
||||
var callback;
|
||||
var callback, timeout;
|
||||
controller.setState(true);
|
||||
callback = mockDocument.on.mostRecentCall.args[1];
|
||||
callback();
|
||||
timeout = mockTimeout.mostRecentCall.args[0];
|
||||
timeout();
|
||||
expect(controller.isActive()).toEqual(false);
|
||||
expect(mockDocument.off).toHaveBeenCalledWith("mouseup", callback);
|
||||
});
|
||||
@@ -91,4 +93,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user