2018-10-25 16:51:20 +02:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-undef,
|
|
|
|
no-useless-escape,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2018-10-25 16:50:16 +02:00
|
|
|
/*
|
|
|
|
* 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';
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
Application.Directives.directive('url', [ function () {
|
2018-11-21 11:08:53 +01:00
|
|
|
const URL_REGEXP = /^(https?:\/\/)([\da-z\.-]+)\.([-a-z0-9\.]{2,30})([\/\w \.-]*)*\/?$/;
|
2018-10-25 16:50:16 +02:00
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
2018-10-25 16:51:20 +02:00
|
|
|
link (scope, element, attributes, ctrl) {
|
|
|
|
return ctrl.$validators.url = function (modelValue, viewValue) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if (ctrl.$isEmpty(modelValue)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return true;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
if (URL_REGEXP.test(viewValue)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return true;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
// otherwise, this is invalid
|
2018-11-21 11:08:53 +01:00
|
|
|
return false;
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
]);
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
Application.Directives.directive('endpoint', [ function () {
|
2018-11-21 11:08:53 +01:00
|
|
|
const ENDPOINT_REGEXP = /^\/?([-._~:?#\[\]@!$&'()*+,;=%\w]+\/?)*$/;
|
2018-10-25 16:50:16 +02:00
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
2018-10-25 16:51:20 +02:00
|
|
|
link (scope, element, attributes, ctrl) {
|
|
|
|
return ctrl.$validators.endpoint = function (modelValue, viewValue) {
|
2018-10-25 16:50:16 +02:00
|
|
|
if (ctrl.$isEmpty(modelValue)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return true;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
if (ENDPOINT_REGEXP.test(viewValue)) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return true;
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
// otherwise, this is invalid
|
2018-11-21 11:08:53 +01:00
|
|
|
return false;
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
]);
|