Remoto - VFS: fileUploadWidget Class Reference
Remoto - VFS

A file upload field. More...

#include "remoto!stdlib:js/widgets/widgets/fileUploadWidget.js"

Inheritance diagram for fileUploadWidget:
widget

Public Member Functions

 fileUploadWidget (d)
 fileUploadWidget constructor More...
 
 activate ()
 Activate this widget, which will enable clicking and dropping. More...
 
 createWidget ()
 Create only the widget portion of this widget. More...
 
 deactivate ()
 Remove clicking and dropping, and make this widget inert. More...
 
 doFileRemove ()
 Store an empty value in this field, and trigger the correct down-stream things. More...
 
 doFileSelect ()
 Trigger the hidden file upload field to do its thing. More...
 
 fileContentsChanged ()
 Do the encoding work and follow the logic based on mime type. More...
 
- Public Member Functions inherited from widget
 widget (d)
 widget contstructor More...
 
 activate ()
 Activate the widget, which will cause changes to propagate to the form, and therefore the submit() mechanism. More...
 
 applyOptions ()
 Apply option changes to an existing widget, like from a diff. More...
 
 arrowMessage (m)
 Create an arrowMessage and point its arrow at this widget's position on screen. More...
 
 createHTML ()
 Create the HTML representation of this object, including the label and form field. More...
 
 createLabel ()
 Create the label jQuery object. More...
 
 createWidget ()
 Create the widget jQuery object. More...
 
 deactivate ()
 Deactivate the widget, which will unbind input events from their callbacks. More...
 
 destroy ()
 Destroy this widget. More...
 
 disable ()
 Disable this widget. More...
 
 doChange ()
 Collect changes to the value of this widget and call this widget's _change method, if it exists, after a period of the user's uifreqency has expired. More...
 
 enable ()
 Enable this widget. More...
 
 sync ()
 Sync the visible value with the internal value. More...
 
 validate ()
 Validate the value of this widget using the _validator function. More...
 
setter immediateValue
 Set the value of this widget, and trigger the doChange method without waiting. More...
 
getter value
 Return the internal value of this widget, which may not be the same as what is displayed in the interface. More...
 
getter defaultValue
 Return the default value of this widget. More...
 
getter visibleWidget
 Return the visible jQuery object for this widget. More...
 
getter isDefault
 Return whether or not this widget's value is its default value. More...
 
getter nonDefaultValue
 Return the value of this widget, or return undefined if it contains the default value. More...
 
setter validator
 Set this widget's validator function. More...
 
setter error
 Set the error value of this widget. More...
 
setter activeUser
 Set the activeUser of this widget. More...
 
getter enabled
 Return true or false based on _enabled state. More...
 
getter hidden
 The hidden state of this widget. More...
 

Detailed Description

A file upload field.

This field can contain any data, however it is primarily used for images. Data is stored as a data URI string to the widget field.

For images, an invisible canvas is created and the toDataURL method is used:

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

For images, the folowing web formats are supported: ".jpg,.jpeg,.gif,.png,.svg,image/[mime]".

Notice that on a system that can detect a file type without an extension, a mime type starting with "image/" is accepted.

Available options:

  • maxSize - Maximum size of data URI to save. Defaults to ~1MB (1000000 bytes)
  • maxDimension - Maximum length of an image side. Defaults to 1000px. Will maintain aspect ratio and resize an uplaoded image so that the longest side does not exceed this value. This will not scale up an image.
  • allowType - Defaults to "image", which is a grouping of mime types and file extensions. Any other type will probably need testing.
  • imageFormat - Defaults to "image/jpg". Can be any valid web image format. An uploaded png, for example, can be saved as a jpg. If you anticipate an alpha channel, use "image/png".
  • imageQuality - Defaults to 0.9. Can be any value on [0,1]. A 90% quality reduces jpg size significantly while maintaining quality quite well.
  • aspectRatio - if present, will apply a center crop to an incoming image, observing the rules listed above. The aspect ratio should be a decimal value. For instance, a 16:9 aspect should be represented as "16/9=1.778". A square image has an aspect of "1.0".
See also
widget

Constructor & Destructor Documentation

◆ fileUploadWidget()

fileUploadWidget constructor

Parameters
dThe widget definition object

Member Function Documentation

◆ activate()

activate ( )

Activate this widget, which will enable clicking and dropping.

◆ createWidget()

createWidget ( )

Create only the widget portion of this widget.

Returns
A jquery object containing the widget only.

This will create a "remove" and "choose" button, as well as a larger box that is clickable and droppable for new images or files.

See also
widget.createHTML()

◆ deactivate()

deactivate ( )

Remove clicking and dropping, and make this widget inert.

◆ doFileRemove()

doFileRemove ( )

Store an empty value in this field, and trigger the correct down-stream things.

◆ doFileSelect()

doFileSelect ( )

Trigger the hidden file upload field to do its thing.

Effectively we are submitting a form here, but abstracted by layers of VFS interface.

◆ fileContentsChanged()

fileContentsChanged ( )

Do the encoding work and follow the logic based on mime type.

Do the best we can to understand an incoming mime type and process it. Images have the most focus here.

Ultimately the result is a data URI stored to the value() setter.


The documentation for this class was generated from the following file: