diff options
Diffstat (limited to 'plugins/CoreHome/vue/src/FocusIf/FocusIf.adapter.ts')
-rw-r--r-- | plugins/CoreHome/vue/src/FocusIf/FocusIf.adapter.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/plugins/CoreHome/vue/src/FocusIf/FocusIf.adapter.ts b/plugins/CoreHome/vue/src/FocusIf/FocusIf.adapter.ts new file mode 100644 index 0000000000..a2226866ad --- /dev/null +++ b/plugins/CoreHome/vue/src/FocusIf/FocusIf.adapter.ts @@ -0,0 +1,39 @@ +/*! + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +import { IDirective } from 'angular'; +import FocusIf from './FocusIf'; + +/** + * If the given expression evaluates to true the element will be focused + * + * Example: + * <input type="text" piwik-focus-if="view.editName"> + */ +function piwikFocusIf(): IDirective { + return { + restrict: 'A', + link: function focusIfLink(scope, element, attrs) { + scope.$watch(attrs.piwikFocusIf, (newValue) => { + const binding = { + instance: null, + value: { + focusIf: !!newValue, + afterFocus: () => scope.$apply(), + }, + oldValue: null, + modifiers: {}, + dir: {}, + }; + + FocusIf.updated(element[0], binding); + }); + }, + }; +} + +angular.module('piwikApp.directive').directive('piwikFocusIf', piwikFocusIf); |