This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-schema-form-previewer.js
64 lines (57 loc) · 1.94 KB
/
angular-schema-form-previewer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @see {@link https://github.com/jboavida/asf-previewer}
* @copyright João Pedro Boavida 2017
* @license MIT
*/
'use strict';
angular.module('angularSchemaFormPreviewer', ['schemaForm']).config([
'schemaFormDecoratorsProvider', 'sfBuilderProvider',
function (schemaFormDecoratorsProvider, sfBuilderProvider) {
function previewerBuilder(args) {
if (!args.form.previewer) return;
angular.element(args.fieldFrag.firstChild).append(
'<div asf-previewer class={{::form.previewerHtmlClass}} ' +
'ng-bind-html="preview" ng-hide="preview == undefined" ' +
'sf-field-model></div>'
);
}
var builders = [previewerBuilder].concat(sfBuilderProvider.stdBuilders);
schemaFormDecoratorsProvider.defineAddOn(
'bootstrapDecorator', 'text', 'decorators/bootstrap/default.html',
builders
);
schemaFormDecoratorsProvider.defineAddOn(
'bootstrapDecorator', 'textarea', 'decorators/bootstrap/textarea.html',
builders
);
}
]);
/**
* @see {@link https://github.com/jboavida/asf-previewer}
* @copyright João Pedro Boavida 2017
* @license MIT
*/
'use strict';
angular.module('angularSchemaFormPreviewer').value('asfPreviewer', {});
angular.module('angularSchemaFormPreviewer').directive('asfPreviewer', [
'asfPreviewer', function (previewers) {
return {
scope: true,
link: function (scope, element, attrs) {
var previewer = scope.form.previewer;
if (!angular.isFunction(previewer)) {
previewer = previewers[scope.form.previewer];
}
if (!previewer) return;
var watched = [attrs.ngModel];
if (scope.form.previewerWatch) {
watched = watched.concat(scope.form.previewerWatch);
}
scope.preview = undefined;
scope.$watchGroup(watched, function (newValues, oldValues, scope) {
scope.preview = previewer(newValues, oldValues, scope, watched);
});
}
};
}
]);