Text widget annotations: implement maximum length and text alignment
Moreover, we refactor the code a bit to extract code that is shared between the two branches and we only apply text alignment (and create the array) when it is actually defined, since it's optional and left is already the default.
This commit is contained in:
parent
1fae435e88
commit
be485f59ab
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
|
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
|
||||||
var AnnotationType = sharedUtil.AnnotationType;
|
var AnnotationType = sharedUtil.AnnotationType;
|
||||||
|
var isInt = sharedUtil.isInt;
|
||||||
var Util = sharedUtil.Util;
|
var Util = sharedUtil.Util;
|
||||||
var addLinkAttributes = displayDOMUtils.addLinkAttributes;
|
var addLinkAttributes = displayDOMUtils.addLinkAttributes;
|
||||||
var LinkTarget = displayDOMUtils.LinkTarget;
|
var LinkTarget = displayDOMUtils.LinkTarget;
|
||||||
@ -427,6 +428,8 @@ var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
|
|||||||
*/
|
*/
|
||||||
var TextWidgetAnnotationElement = (
|
var TextWidgetAnnotationElement = (
|
||||||
function TextWidgetAnnotationElementClosure() {
|
function TextWidgetAnnotationElementClosure() {
|
||||||
|
var TEXT_ALIGNMENT = ['left', 'center', 'right'];
|
||||||
|
|
||||||
function TextWidgetAnnotationElement(parameters) {
|
function TextWidgetAnnotationElement(parameters) {
|
||||||
WidgetAnnotationElement.call(this, parameters);
|
WidgetAnnotationElement.call(this, parameters);
|
||||||
}
|
}
|
||||||
@ -442,26 +445,33 @@ var TextWidgetAnnotationElement = (
|
|||||||
render: function TextWidgetAnnotationElement_render() {
|
render: function TextWidgetAnnotationElement_render() {
|
||||||
this.container.className = 'textWidgetAnnotation';
|
this.container.className = 'textWidgetAnnotation';
|
||||||
|
|
||||||
|
var element = null;
|
||||||
if (this.renderInteractiveForms) {
|
if (this.renderInteractiveForms) {
|
||||||
var input = document.createElement('input');
|
element = document.createElement('input');
|
||||||
input.type = 'text';
|
element.type = 'text';
|
||||||
input.value = this.data.fieldValue;
|
element.value = this.data.fieldValue;
|
||||||
|
|
||||||
this.container.appendChild(input);
|
if (isInt(this.data.maxLen)) {
|
||||||
|
element.maxLength = this.data.maxLen;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
var content = document.createElement('div');
|
element = document.createElement('div');
|
||||||
content.textContent = this.data.fieldValue;
|
element.textContent = this.data.fieldValue;
|
||||||
var textAlignment = this.data.textAlignment;
|
element.style.verticalAlign = 'middle';
|
||||||
content.style.textAlign = ['left', 'center', 'right'][textAlignment];
|
element.style.display = 'table-cell';
|
||||||
content.style.verticalAlign = 'middle';
|
|
||||||
content.style.display = 'table-cell';
|
|
||||||
|
|
||||||
var font = (this.data.fontRefName ?
|
var font = null;
|
||||||
this.page.commonObjs.getData(this.data.fontRefName) : null);
|
if (this.data.fontRefName) {
|
||||||
this._setTextStyle(content, font);
|
font = this.page.commonObjs.getData(this.data.fontRefName);
|
||||||
|
}
|
||||||
this.container.appendChild(content);
|
this._setTextStyle(element, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isInt(this.data.textAlignment)) {
|
||||||
|
element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.container.appendChild(element);
|
||||||
return this.container;
|
return this.container;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user