2018-11-05 05:06:39 -05: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 05:02:56 -04:00
|
|
|
import App from '../base'
|
2023-10-13 05:13:49 -04:00
|
|
|
App.directive('focusWhen', [
|
|
|
|
'$timeout',
|
2023-10-17 04:36:46 -04:00
|
|
|
function ($timeout) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attr) {
|
|
|
|
return scope.$watch(attr.focusWhen, function (value) {
|
|
|
|
if (value) {
|
|
|
|
return $timeout(() => element.focus())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2023-10-13 05:13:49 -04:00
|
|
|
])
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2023-10-17 04:36:46 -04:00
|
|
|
App.directive('focusOn', function () {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
return scope.$on(attrs.focusOn, () => element.focus())
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2023-10-13 05:13:49 -04:00
|
|
|
App.directive('selectWhen', [
|
|
|
|
'$timeout',
|
2023-10-17 04:36:46 -04:00
|
|
|
function ($timeout) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attr) {
|
|
|
|
return scope.$watch(attr.selectWhen, function (value) {
|
|
|
|
if (value) {
|
|
|
|
return $timeout(() => element.select())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2023-10-13 05:13:49 -04:00
|
|
|
])
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2023-10-17 04:36:46 -04:00
|
|
|
App.directive('selectOn', function () {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
return scope.$on(attrs.selectOn, () => element.select())
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2023-10-13 05:13:49 -04:00
|
|
|
App.directive('selectNameWhen', [
|
|
|
|
'$timeout',
|
2023-10-17 04:36:46 -04:00
|
|
|
function ($timeout) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
return scope.$watch(attrs.selectNameWhen, function (value) {
|
|
|
|
if (value) {
|
|
|
|
return $timeout(() => selectName(element))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
])
|
|
|
|
|
|
|
|
App.directive('selectNameOn', function () {
|
|
|
|
return {
|
2023-10-13 05:13:49 -04:00
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
2023-10-17 04:36:46 -04:00
|
|
|
return scope.$on(attrs.selectNameOn, () => selectName(element))
|
2023-10-13 05:13:49 -04:00
|
|
|
},
|
2023-10-17 04:36:46 -04:00
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2023-10-13 05:13:49 -04:00
|
|
|
App.directive('focus', [
|
|
|
|
'$timeout',
|
2023-10-17 04:36:46 -04:00
|
|
|
function ($timeout) {
|
|
|
|
return {
|
|
|
|
scope: {
|
|
|
|
trigger: '@focus',
|
|
|
|
},
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2023-10-17 04:36:46 -04:00
|
|
|
link(scope, element) {
|
|
|
|
return scope.$watch('trigger', function (value) {
|
|
|
|
if (value === 'true') {
|
|
|
|
return $timeout(() => element[0].focus())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2023-10-13 05:13:49 -04:00
|
|
|
])
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-05-05 09:05:04 -04:00
|
|
|
function selectName(element) {
|
2020-05-19 05:02:56 -04: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 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return element[0].setSelectionRange(0, selectionEnd)
|
2019-01-24 06:49:42 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|