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
|
|
|
|
*/
|
|
|
|
'use strict';
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
Application.Directives.directive('url', [ function() {
|
|
|
|
const URL_REGEXP = /^(https?:\/\/)([\da-z\.-]+)\.([-a-z0-9\.]{2,30})([\/\w \.-]*)*\/?$/;
|
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link(scope, element, attributes, ctrl) {
|
|
|
|
return ctrl.$validators.url = function(modelValue, viewValue) {
|
|
|
|
if (ctrl.$isEmpty(modelValue)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (URL_REGEXP.test(viewValue)) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
// otherwise, this is invalid
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]);
|
2016-03-23 18:39:41 +01:00
|
|
|
|
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
Application.Directives.directive('endpoint', [ function() {
|
|
|
|
const ENDPOINT_REGEXP = /^\/?([-._~:?#\[\]@!$&'()*+,;=%\w]+\/?)*$/;
|
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link(scope, element, attributes, ctrl) {
|
|
|
|
return ctrl.$validators.endpoint = function(modelValue, viewValue) {
|
|
|
|
if (ctrl.$isEmpty(modelValue)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (ENDPOINT_REGEXP.test(viewValue)) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2018-10-25 16:50:16 +02:00
|
|
|
// otherwise, this is invalid
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]);
|