mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-25 20:42:05 +00:00
726719ce3f
autofocus is html5y and worked on chrome but not firefox for me.
78 lines
1.7 KiB
CoffeeScript
78 lines
1.7 KiB
CoffeeScript
define [
|
|
"base"
|
|
], (App) ->
|
|
App.directive "focusWhen", ($timeout) ->
|
|
return {
|
|
restrict: "A"
|
|
link: (scope, element, attr) ->
|
|
scope.$watch attr.focusWhen, (value) ->
|
|
if value
|
|
$timeout ->
|
|
element.focus()
|
|
}
|
|
|
|
App.directive 'focusOn', ($timeout) ->
|
|
return {
|
|
restrict: 'A'
|
|
link: (scope, element, attrs) ->
|
|
scope.$on attrs.focusOn, () ->
|
|
element.focus()
|
|
}
|
|
|
|
App.directive "selectWhen", ($timeout) ->
|
|
return {
|
|
restrict: "A"
|
|
link: (scope, element, attr) ->
|
|
scope.$watch attr.selectWhen, (value) ->
|
|
if value
|
|
$timeout ->
|
|
element.select()
|
|
}
|
|
|
|
App.directive 'selectOn', ($timeout) ->
|
|
return {
|
|
restrict: 'A'
|
|
link: (scope, element, attrs) ->
|
|
scope.$on attrs.selectOn, () ->
|
|
element.select()
|
|
}
|
|
|
|
App.directive "selectNameWhen", ($timeout) ->
|
|
return {
|
|
restrict: 'A'
|
|
link: (scope, element, attrs) ->
|
|
scope.$watch attrs.selectNameWhen, (value) ->
|
|
if value
|
|
$timeout () ->
|
|
selectName(element)
|
|
}
|
|
|
|
App.directive "selectNameOn", () ->
|
|
return {
|
|
restrict: 'A'
|
|
link: (scope, element, attrs) ->
|
|
scope.$on attrs.selectNameOn, () ->
|
|
selectName(element)
|
|
}
|
|
|
|
|
|
App.directive "focus", ($timeout) ->
|
|
scope:
|
|
trigger: "@focus"
|
|
|
|
link: (scope, element) ->
|
|
scope.$watch "trigger", (value) ->
|
|
if value is "true"
|
|
$timeout ->
|
|
element[0].focus()
|
|
|
|
selectName = (element) ->
|
|
# Select up to last '.'. I.e. everything
|
|
# except the file extension
|
|
element.focus()
|
|
name = element.val()
|
|
if element[0].setSelectionRange?
|
|
selectionEnd = name.lastIndexOf(".")
|
|
if selectionEnd == -1
|
|
selectionEnd = name.length
|
|
element[0].setSelectionRange(0, selectionEnd)
|