28

ImageModel

Objective
  • Model
    • ImageModel

An instance of ImageModel is a data model which describes an image with the following property:

imageAn 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.
  1. function ImageModel(name = null) {
  2.     Model.call(this, name);
  3.  
  4.     this._value = {
  5.         image:  { image: null, size: [0, 0] }
  6.     };
  7. }
  8.  
  9. ImageModel.prototype = Object.create(Model.prototype);
  10.  
  11. Object.defineProperty(ImageModel.prototype, 'constructor', { value: ImageModel, enumerable: false, writable: true });

An instance of ImageModel inherits from the class Model.

  1. ImageModel.prototype.validateValue = function(prop, val) {
  2.     if (prop == 'image') {
  3.         if (typeof val !== 'object')
  4.             return false;
  5.  
  6.         const { image, size } = val;
  7.  
  8.         if (image === null)
  9.             return true;
  10.  
  11.         if (! (Array.isArray(image) && Validator.validateImageDataURL(image[0]) && Number.isInteger(image[1]) && Number.isInteger(image[2]) && image[1] >= 0 && image[2] >= 0))
  12.             return false;
  13.  
  14.         if (! (Array.isArray(size) && Number.isInteger(size[0]) && Number.isInteger(size[1]) && size[0] >= 0 && size[1] >= 0))
  15.             return false;
  16.  
  17.         return true;
  18.     }
  19.  
  20.     return true;
  21. };
SEE ALSO

Model, VideoModel

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].