mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
implement
This commit is contained in:
parent
806dc05cd0
commit
37fc8d072e
1 changed files with 41 additions and 0 deletions
41
src/ui/public/Binder.js
Normal file
41
src/ui/public/Binder.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
var $ = require('jquery');
|
||||
var d3 = require('d3');
|
||||
var callEach = require('lodash').callEach;
|
||||
var bindKey = require('lodash').bindKey;
|
||||
var rest = require('lodash').rest;
|
||||
|
||||
function Binder($scope) {
|
||||
this.disposal = [];
|
||||
if ($scope) {
|
||||
$scope.$on('$destroy', bindKey(this, 'destroy'));
|
||||
}
|
||||
}
|
||||
|
||||
Binder.prototype.jqOn = function (el/*, ...args */) {
|
||||
var $el = $(el);
|
||||
var args = rest(arguments);
|
||||
$el.on.apply($el, args);
|
||||
this.disposal.push(function () {
|
||||
$el.off.apply($el, args);
|
||||
$el = null;
|
||||
});
|
||||
};
|
||||
|
||||
Binder.prototype.fakeD3Bind = function (el, event, handler) {
|
||||
this.jqOn(el, event, function (e) {
|
||||
// mimick https://github.com/mbostock/d3/blob/3abb00113662463e5c19eb87cd33f6d0ddc23bc0/src/selection/on.js#L87-L94
|
||||
var o = d3.event; // Events can be reentrant (e.g., focus).
|
||||
d3.event = e;
|
||||
try {
|
||||
handler.apply(this, [this.__data__]);
|
||||
} finally {
|
||||
d3.event = o;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Binder.prototype.destroy = function () {
|
||||
callEach(this.disposal.slice(0));
|
||||
};
|
||||
|
||||
module.exports = Binder;
|
Loading…
Add table
Add a link
Reference in a new issue