overleaf/services/web/public/coffee/ide/review-panel/directives/reviewPanelToggle.coffee

32 lines
928 B
CoffeeScript
Raw Normal View History

2016-11-23 09:34:21 -05:00
define [
"base"
], (App) ->
App.directive "reviewPanelToggle", () ->
restrict: "E"
scope:
onToggle: '&'
ngModel: '='
valWhenUndefined: '=?'
disabled: '=?'
2017-07-05 06:08:14 -04:00
onDisabledClick: '&?'
link: (scope) ->
if !scope.disabled?
scope.disabled = false
scope.onChange = (args...) ->
scope.onToggle({ isOn: scope.localModel })
scope.handleClick = () ->
2017-07-05 06:08:14 -04:00
if scope.disabled and scope.onDisabledClick?
scope.onDisabledClick()
scope.localModel = scope.ngModel
scope.$watch "ngModel", (value) ->
if scope.valWhenUndefined? and !value?
value = scope.valWhenUndefined
scope.localModel = value
2016-11-23 09:34:21 -05:00
template: """
<div class="rp-toggle" ng-click="handleClick();">
<input id="rp-toggle-{{$id}}" ng-disabled="disabled" type="checkbox" class="rp-toggle-hidden-input" ng-model="localModel" ng-change="onChange()" />
2016-11-23 09:34:21 -05:00
<label for="rp-toggle-{{$id}}" class="rp-toggle-btn"></label>
</div>
"""