26
ImageModel
Objective
- Model
- ImageModel
An instance of ImageModel is a data model which describes an image with the following property:
image | An object with a property image , an array which contains the data URL of the image - a character string such as data:image/png;base64,...=, the width and the height of the image - 2 positive integers, and a property size , an array of 2 positive integers, the width and the height of the image when displayed. |
---|
- function ImageModel(name = null) {
- Model.call(this, name);
- this._value = {
- image: { image: null, size: [0, 0] }
- };
- }
- ImageModel.prototype = Object.create(Model.prototype);
- Object.defineProperty(ImageModel.prototype, 'constructor', { value: ImageModel, enumerable: false, writable: true });
An instance of ImageModel inherits from the class Model.
- ImageModel.prototype.validateValue = function(prop, val) {
- if (prop == 'image') {
- if (typeof val !== 'object')
- return false;
- const { image, size } = val;
- if (image === null)
- return true;
- if (! (Array.isArray(image) && Validator.validateImageDataURL(image[0]) && Number.isInteger(image[1]) && Number.isInteger(image[2]) && image[1] >= 0 && image[2] >= 0))
- return false;
- if (! (Array.isArray(size) && Number.isInteger(size[0]) && Number.isInteger(size[1]) && size[0] >= 0 && size[1] >= 0))
- return false;
- return true;
- }
- return true;
- };
Comments