1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/assets/javascripts/directives/directives.js

116 lines
3.1 KiB
JavaScript
Raw Normal View History

/* eslint-disable
no-return-assign,
no-undef,
*/
// 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
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
2018-11-21 11:08:53 +01:00
'use strict';
Application.Directives.directive('fileread', [ () =>
({
scope: {
fileread: '='
},
link (scope, element, attributes) {
return element.bind('change', changeEvent =>
scope.$apply(() => scope.fileread = changeEvent.target.files[0])
2018-11-21 11:08:53 +01:00
);
}
})
2018-11-21 11:08:53 +01:00
]);
// This `bsHolder` angular directive is a workaround for
// an incompatability between angular and the holder.js
// image placeholder library.
//
// To use, simply define `bs-holder` on any element
Application.Directives.directive('bsHolder', [ () =>
({
link (scope, element, attrs) {
Holder.addTheme('icon', { background: 'white', foreground: '#e9e9e9', size: 80, font: 'FontAwesome' })
.addTheme('icon-xs', { background: 'white', foreground: '#e0e0e0', size: 20, font: 'FontAwesome' })
.addTheme('icon-black-xs', { background: 'black', foreground: 'white', size: 20, font: 'FontAwesome' })
.addTheme('avatar', { background: '#eeeeee', foreground: '#555555', size: 16, font: 'FontAwesome' })
2018-11-21 11:08:53 +01:00
.run(element[0]);
}
})
2018-11-21 11:08:53 +01:00
]);
2015-05-05 03:10:25 +02:00
Application.Directives.directive('match', [ () =>
({
require: 'ngModel',
restrict: 'A',
scope: {
match: '='
},
link (scope, elem, attrs, ctrl) {
return scope.$watch(() => (ctrl.$pristine && angular.isUndefined(ctrl.$modelValue)) || (scope.match === ctrl.$modelValue)
2018-11-21 11:08:53 +01:00
, currentValue => ctrl.$setValidity('match', currentValue));
}
})
2018-11-21 11:08:53 +01:00
]);
Application.Directives.directive('publishProject', [ () =>
({
restrict: 'A',
link (scope, elem, attrs, ctrl) {
return elem.bind('click', function ($event) {
if ($event) {
2018-11-21 11:08:53 +01:00
$event.preventDefault();
$event.stopPropagation();
}
2018-11-21 11:08:53 +01:00
if (elem.attr('disabled')) { return; }
const input = angular.element('<input name="project[state]" type="hidden" value="published">');
const form = angular.element('form');
form.append(input);
form.triggerHandler('submit');
return form[0].submit();
});
}
})
2018-11-21 11:08:53 +01:00
]);
2015-05-05 03:10:25 +02:00
Application.Directives.directive('disableAnimation', ['$animate', ($animate) =>
({
restrict: 'A',
link (scope, elem, attrs) {
2018-11-27 13:57:41 +01:00
return attrs.$observe('disableAnimation', value => $animate.enabled(elem, !value));
}
})
2018-11-21 11:08:53 +01:00
]);
2016-03-23 18:39:41 +01:00
/**
* Isolate a form's scope from its parent : no nested validation
* @see https://stackoverflow.com/a/37481846/1039377
*/
Application.Directives.directive('isolateForm', [ () =>
({
2016-03-23 18:39:41 +01:00
restrict: 'A',
require: '?form',
link (scope, elm, attrs, ctrl) {
2018-11-21 11:08:53 +01:00
if (!ctrl) { return; }
const parentForm = ctrl.$$parentForm; // Note this uses private API
if (!parentForm) {
return;
}
2016-03-23 18:39:41 +01:00
// Remove this form from parent controller
parentForm.$removeControl(ctrl);
}
2016-03-23 18:39:41 +01:00
})
2018-11-21 11:08:53 +01:00
]);