2018-11-05 10:06:39 +00:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 09:02:56 +00:00
|
|
|
import App from '../base'
|
|
|
|
App.directive('focusWhen', $timeout => ({
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attr) {
|
2021-04-14 13:17:21 +00:00
|
|
|
return scope.$watch(attr.focusWhen, function (value) {
|
2020-05-19 09:02:56 +00:00
|
|
|
if (value) {
|
|
|
|
return $timeout(() => element.focus())
|
|
|
|
}
|
|
|
|
})
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
}))
|
2018-11-05 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
App.directive('focusOn', $timeout => ({
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
return scope.$on(attrs.focusOn, () => element.focus())
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
}))
|
2018-11-05 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
App.directive('selectWhen', $timeout => ({
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attr) {
|
2021-04-14 13:17:21 +00:00
|
|
|
return scope.$watch(attr.selectWhen, function (value) {
|
2020-05-19 09:02:56 +00:00
|
|
|
if (value) {
|
|
|
|
return $timeout(() => element.select())
|
|
|
|
}
|
|
|
|
})
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
}))
|
2018-11-05 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
App.directive('selectOn', $timeout => ({
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
return scope.$on(attrs.selectOn, () => element.select())
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
}))
|
2018-11-05 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
App.directive('selectNameWhen', $timeout => ({
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
2021-04-14 13:17:21 +00:00
|
|
|
return scope.$watch(attrs.selectNameWhen, function (value) {
|
2020-05-19 09:02:56 +00:00
|
|
|
if (value) {
|
|
|
|
return $timeout(() => selectName(element))
|
|
|
|
}
|
|
|
|
})
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
}))
|
2018-11-05 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
App.directive('selectNameOn', () => ({
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
return scope.$on(attrs.selectNameOn, () => selectName(element))
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
}))
|
2018-11-05 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
App.directive('focus', $timeout => ({
|
|
|
|
scope: {
|
2021-04-27 07:52:58 +00:00
|
|
|
trigger: '@focus',
|
2020-05-19 09:02:56 +00:00
|
|
|
},
|
2018-11-05 10:06:39 +00:00
|
|
|
|
2020-05-19 09:02:56 +00:00
|
|
|
link(scope, element) {
|
2021-04-14 13:17:21 +00:00
|
|
|
return scope.$watch('trigger', function (value) {
|
2020-05-19 09:02:56 +00:00
|
|
|
if (value === 'true') {
|
|
|
|
return $timeout(() => element[0].focus())
|
2018-11-05 10:06:39 +00:00
|
|
|
}
|
2020-05-19 09:02:56 +00:00
|
|
|
})
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
2020-05-19 09:02:56 +00:00
|
|
|
}))
|
|
|
|
|
2021-05-05 13:05:04 +00:00
|
|
|
function selectName(element) {
|
2020-05-19 09:02:56 +00:00
|
|
|
// Select up to last '.'. I.e. everything except the file extension
|
|
|
|
element.focus()
|
|
|
|
const name = element.val()
|
|
|
|
if (element[0].setSelectionRange != null) {
|
|
|
|
let selectionEnd = name.lastIndexOf('.')
|
|
|
|
if (selectionEnd === -1) {
|
|
|
|
selectionEnd = name.length
|
2018-11-05 10:06:39 +00:00
|
|
|
}
|
2020-05-19 09:02:56 +00:00
|
|
|
return element[0].setSelectionRange(0, selectionEnd)
|
2019-01-24 11:49:42 +00:00
|
|
|
}
|
2020-05-19 09:02:56 +00:00
|
|
|
}
|