mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Choice widget annotations: core and display layer implementation
This commit is contained in:
parent
6c263c1994
commit
d5d9f362aa
4 changed files with 140 additions and 14 deletions
|
@ -76,6 +76,8 @@ AnnotationElementFactory.prototype =
|
|||
switch (fieldType) {
|
||||
case 'Tx':
|
||||
return new TextWidgetAnnotationElement(parameters);
|
||||
case 'Ch':
|
||||
return new ChoiceWidgetAnnotationElement(parameters);
|
||||
}
|
||||
return new WidgetAnnotationElement(parameters);
|
||||
|
||||
|
@ -400,9 +402,7 @@ var TextAnnotationElement = (function TextAnnotationElementClosure() {
|
|||
* @alias WidgetAnnotationElement
|
||||
*/
|
||||
var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
|
||||
function WidgetAnnotationElement(parameters) {
|
||||
var isRenderable = parameters.renderInteractiveForms ||
|
||||
(!parameters.data.hasAppearance && !!parameters.data.fieldValue);
|
||||
function WidgetAnnotationElement(parameters, isRenderable) {
|
||||
AnnotationElement.call(this, parameters, isRenderable);
|
||||
}
|
||||
|
||||
|
@ -432,7 +432,9 @@ var TextWidgetAnnotationElement = (
|
|||
var TEXT_ALIGNMENT = ['left', 'center', 'right'];
|
||||
|
||||
function TextWidgetAnnotationElement(parameters) {
|
||||
WidgetAnnotationElement.call(this, parameters);
|
||||
var isRenderable = parameters.renderInteractiveForms ||
|
||||
(!parameters.data.hasAppearance && !!parameters.data.fieldValue);
|
||||
WidgetAnnotationElement.call(this, parameters, isRenderable);
|
||||
}
|
||||
|
||||
Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
|
||||
|
@ -528,6 +530,64 @@ var TextWidgetAnnotationElement = (
|
|||
return TextWidgetAnnotationElement;
|
||||
})();
|
||||
|
||||
/**
|
||||
* @class
|
||||
* @alias ChoiceWidgetAnnotationElement
|
||||
*/
|
||||
var ChoiceWidgetAnnotationElement = (
|
||||
function ChoiceWidgetAnnotationElementClosure() {
|
||||
function ChoiceWidgetAnnotationElement(parameters) {
|
||||
WidgetAnnotationElement.call(this, parameters,
|
||||
parameters.renderInteractiveForms);
|
||||
}
|
||||
|
||||
Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
|
||||
/**
|
||||
* Render the choice widget annotation's HTML element in the empty
|
||||
* container.
|
||||
*
|
||||
* @public
|
||||
* @memberof ChoiceWidgetAnnotationElement
|
||||
* @returns {HTMLSectionElement}
|
||||
*/
|
||||
render: function ChoiceWidgetAnnotationElement_render() {
|
||||
this.container.className = 'choiceWidgetAnnotation';
|
||||
|
||||
var selectElement = document.createElement('select');
|
||||
selectElement.disabled = this.data.readOnly;
|
||||
|
||||
if (!this.data.combo) {
|
||||
// List boxes have a size and (optionally) multiple selection.
|
||||
selectElement.size = this.data.options.length;
|
||||
|
||||
if (this.data.multiSelect) {
|
||||
selectElement.multiple = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the options into the choice field.
|
||||
for (var i = 0, ii = this.data.options.length; i < ii; i++) {
|
||||
var option = this.data.options[i];
|
||||
|
||||
var optionElement = document.createElement('option');
|
||||
optionElement.textContent = option.displayValue;
|
||||
optionElement.value = option.exportValue;
|
||||
|
||||
if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
|
||||
optionElement.setAttribute('selected', true);
|
||||
}
|
||||
|
||||
selectElement.appendChild(optionElement);
|
||||
}
|
||||
|
||||
this.container.appendChild(selectElement);
|
||||
return this.container;
|
||||
}
|
||||
});
|
||||
|
||||
return ChoiceWidgetAnnotationElement;
|
||||
})();
|
||||
|
||||
/**
|
||||
* @class
|
||||
* @alias PopupAnnotationElement
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue