mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
parent
b6a2ec51e5
commit
1924f63207
3 changed files with 58 additions and 30 deletions
|
@ -18,42 +18,15 @@
|
|||
*/
|
||||
|
||||
import { uiModules } from '../modules';
|
||||
|
||||
const attributeName = 'data-render-complete';
|
||||
import { RenderCompleteHelper } from './render_complete_helper';
|
||||
|
||||
uiModules
|
||||
.get('kibana')
|
||||
.directive('renderComplete', () => ({
|
||||
controller($scope, $element) {
|
||||
const el = $element[0];
|
||||
const renderCompleteHelper = new RenderCompleteHelper(el);
|
||||
|
||||
const start = () => {
|
||||
$element.attr(attributeName, false);
|
||||
return true;
|
||||
};
|
||||
|
||||
const complete = () => {
|
||||
$element.attr(attributeName, true);
|
||||
return true;
|
||||
};
|
||||
|
||||
const teardown = () => {
|
||||
el.removeEventListener('renderStart', start);
|
||||
el.removeEventListener('renderComplete', complete);
|
||||
};
|
||||
|
||||
const setup = () => {
|
||||
$element.attr(attributeName, false);
|
||||
el.addEventListener('renderStart', start);
|
||||
el.addEventListener('renderComplete', complete);
|
||||
$scope.$on('$destroy', teardown);
|
||||
};
|
||||
|
||||
this.disable = () => {
|
||||
$element.attr(attributeName, 'disabled');
|
||||
teardown();
|
||||
};
|
||||
|
||||
setup();
|
||||
$scope.$on('$destroy', renderCompleteHelper.destroy);
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -33,3 +33,5 @@ export function dispatchRenderComplete(el) {
|
|||
export function dispatchRenderStart(el) {
|
||||
dispatchCustomEvent(el, 'renderStart');
|
||||
}
|
||||
|
||||
export * from './render_complete_helper';
|
||||
|
|
53
src/ui/public/render_complete/render_complete_helper.js
Normal file
53
src/ui/public/render_complete/render_complete_helper.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
const attributeName = 'data-render-complete';
|
||||
|
||||
export class RenderCompleteHelper {
|
||||
constructor(element) {
|
||||
this._element = element;
|
||||
this.setup();
|
||||
}
|
||||
|
||||
_start = () => {
|
||||
this._element.setAttribute(attributeName, false);
|
||||
return true;
|
||||
};
|
||||
|
||||
_complete = () => {
|
||||
this._element.setAttribute(attributeName, true);
|
||||
return true;
|
||||
};
|
||||
|
||||
destroy = () => {
|
||||
this._element.removeEventListener('renderStart', this._start);
|
||||
this._element.removeEventListener('renderComplete', this._complete);
|
||||
};
|
||||
|
||||
setup = () => {
|
||||
this._element.setAttribute(attributeName, false);
|
||||
this._element.addEventListener('renderStart', this._start);
|
||||
this._element.addEventListener('renderComplete', this._complete);
|
||||
};
|
||||
|
||||
disable = () => {
|
||||
this._element.setAttribute(attributeName, 'disabled');
|
||||
this.destroy();
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue