Expand all

ve.dm.MWImageModel

Constructor

new ve.dm.MWImageModel(parentDoc, [config]) #

MediaWiki image model.

Parameters:

Name Type Attributes Description
parentDoc ve.dm.Document

Document that contains or will contain the image

config Object optional

Configuration options

Properties:
Name Type Attributes Default Description
resourceName string optional

The resource name of the given media file

currentDimensions Object optional
{}

Current dimensions, width & height

minDimensions Object optional
{}

Minimum dimensions, width & height

isDefaultSize boolean optional
false

Object is using its default size dimensions

Mixes in:
Source:
MediaWiki image model.

Methods

attachScalable(scalable) #

Attach a new scalable object to the model and request the information from the API.

Parameters:

Name Type Description
scalable ve.dm.Scalable
Source:

Attach a new scalable object to the model and request the information from the API.

cacheOriginalImageAttributes(attrs) #

Cache all image attributes

Parameters:

Name Type Description
attrs Object

Image attributes

Source:
Cache all image attributes

changeImageSource(attrs, [APIinfo]) #

Adjust the model parameters based on a new image

Parameters:

Name Type Attributes Description
attrs Object

New image source attributes

APIinfo Object optional

The image's API info

Source:

Throws:

Image has insufficient details to compute the imageModel details.

Type
Error
Adjust the model parameters based on a new image

getAlignment() → {string|null} #

Get image alignment 'left', 'right', 'center', 'none' or 'default'

Source:

Returns:

Image alignment. Inline images have initial alignment value of null.

Type
string | null
Get image alignment 'left', 'right', 'center', 'none' or 'default'

getAltText() → {string} #

Get the image alternate text

Source:

Returns:

Alternate text

Type
string
Get the image alternate text

getBoundingBox() → {Object} #

Get the original bounding box

Source:

Returns:

Bounding box with width and height

Type
Object
Get the original bounding box

getCaptionDocument() → {ve.dm.Document} #

Get image caption document.

Auto-generates a blank document if no document exists.

Source:

Returns:

Caption document

Type
ve.dm.Document
Get image caption document.

getCurrentDimensions() → {ve.ui.DimensionsWidget.Dimensions} #

Get the image current dimensions

Source:

Returns:

Current dimensions width/height

Type
ve.ui.DimensionsWidget.Dimensions
Get the image current dimensions

getData() → {Array} #

Get linear data representation of the image

Source:

Returns:

Linear data

Type
Array
Get linear data representation of the image

getDefaultDimensions() → {Object} #

Retrieve the currently set default dimensions from the scalable object attached to the image.

Source:

Returns:

Image default dimensions

Type
Object

Retrieve the currently set default dimensions from the scalable object attached to the image.

getDefaultDir([imageNodeType]) → {string} #

Get the default alignment according to the document direction

Parameters:

Name Type Attributes Description
imageNodeType string optional

Optional. The image node type that we would like to get the default direction for. Supplying this parameter allows us to check what the default alignment of a specific type of node would be. If the parameter is not supplied, the default alignment will be calculated based on the current node type.

Source:

Returns:

Node alignment based on document direction

Type
string
Get the default alignment according to the document direction

getFilename() → {string} #

Get the filename of the current image

Source:

Returns:

filename Image filename (without namespace)

Type
string
Get the filename of the current image

getHashObject() → {Object} #

Get the hash object of the current image model state.

Source:

Returns:

Type
Object
Get the hash object of the current image model state.

getImageClassAttr() → {string|null} #

Source:

Returns:

Type
string | null

getImageHref() → {string} #

Get the image href value. This is the link that the image leads to. It usually contains the link to the source of the image in commons or locally, but may hold an alternative link if link= is supplied in the wikitext. For example, './File:Foo.jpg' or 'http://www.wikipedia.org'

Source:

Returns:

The destination href of the given media file

Type
string
Get the image href value.

getImageNodeType([imageType], [align]) → {string} #

Get the current image node type according to the attributes. If either of the parameters are given, the node type is tested against them, otherwise, it is tested against the current image parameters.

Parameters:

Name Type Attributes Description
imageType string optional

Optional. Image type.

align string optional

Optional. Image alignment.

Source:

Returns:

Node type 'mwInlineImage' or 'mwBlockImage'

Type
string
Get the current image node type according to the attributes.

getImageResourceName() → {string} #

Get the image file resource name. The resource name represents the filename without the full source url. For example, './File:Foo.jpg'

Source:

Returns:

The resource name of the given media file

Type
string
Get the image file resource name.

getImageSource() → {string} #

Get the image file source The image file source that points to the location of the file on the Web. For instance, '//upload.wikimedia.org/wikipedia/commons/0/0f/Foo.jpg'

Source:

Returns:

The source of the given media file

Type
string

Get the image file source The image file source that points to the location of the file on the Web.

getImgWrapperClassAttr() → {string|null} #

Source:

Returns:

Type
string | null

getMediaTag() → {string} #

Get media tag: img, video or audio

Source:

Returns:

Tag name

Type
string
Get media tag: img, video or audio

getMediaType() → {string|undefined} #

Get symbolic name of media type.

Example values: "BITMAP" for JPEG or PNG images; "DRAWING" for SVG graphics

Source:

Returns:

Symbolic media type name, or undefined if empty

Type
string | undefined
Get symbolic name of media type.

getNormalizedImageSource() → {string} #

Normalize the source url by stripping the protocol off. This is done so when an image is replaced with the same image, the imageModel can recognize that nothing has actually changed.

Example: 'http://upload.wikimedia.org/wikipedia/commons/0/Foo.png' to '//upload.wikimedia.org/wikipedia/commons/0/Foo.png'

Source:

Returns:

Normalized image source

Type
string
Normalize the source url by stripping the protocol off.

getOriginalImageAttributes() → {Object} #

Get the cache of all image attributes

Source:

Returns:

attrs Image attributes

Type
Object
Get the cache of all image attributes

getResourceName() → {string} #

Get the image file resource name

Source:

Returns:

resourceName The resource name of the given media file

Type
string
Get the image file resource name

getScalable() → {ve.dm.Scalable} #

Get the scalable object responsible for size manipulations for the given image

Source:

Returns:

Type
ve.dm.Scalable

Get the scalable object responsible for size manipulations for the given image

getSizeType() → {string} #

Get the image size type of the image

Source:

Returns:

Size type

Type
string
Get the image size type of the image

getType() → {string} #

Get image wikitext type; 'thumb', 'frame', 'frameless' or 'none/inline'

Source:

Returns:

Image type

Type
string
Get image wikitext type; 'thumb', 'frame', 'frameless' or 'none/inline'

getUpdatedAttributes() → {Object} #

Return all updated attributes that belong to the node.

Source:

Returns:

Updated attributes

Type
Object
Return all updated attributes that belong to the node.

getVerticalAlignment() → {string} #

Get image vertical alignment 'middle', 'baseline', 'sub', 'super', 'top', 'text-top', 'bottom', 'text-bottom' or 'default'

Source:

Returns:

Image alignment

Type
string

Get image vertical alignment 'middle', 'baseline', 'sub', 'super', 'top', 'text-top', 'bottom', 'text-bottom' or 'default'

hasBeenModified() → {boolean} #

Check if the model attributes and parameters have been modified by comparing the current hash to the new hash object.

Source:

Returns:

Model has been modified

Type
boolean

Check if the model attributes and parameters have been modified by comparing the current hash to the new hash object.

hasBorder() → {boolean} #

Check whether the image has the border flag set

Source:

Returns:

Border flag on or off

Type
boolean
Check whether the image has the border flag set

insertImageNode(fragment) → {ve.dm.SurfaceFragment} #

Insert image into a surface.

Image is inserted at the current fragment position.

Parameters:

Name Type Description
fragment ve.dm.SurfaceFragment

Fragment covering range to insert at

Source:

Returns:

Fragment covering inserted image

Type
ve.dm.SurfaceFragment

Throws:

Unknown image node type

Type
Error
Insert image into a surface.

isAligned([align]) → {boolean} #

Check whether the image has floating alignment set

Parameters:

Name Type Attributes Description
align string optional

Optional. Alignment value to test against.

Source:

Returns:

hasAlignment flag on or off

Type
boolean
Check whether the image has floating alignment set

isBorderable() → {boolean} #

Check whether the image can have a border set on it

Source:

Returns:

Border possible or not

Type
boolean
Check whether the image can have a border set on it

isChangedImageSource() → {boolean} #

Check whether the image source is changed

Source:

Returns:

changedImageSource flag on or off

Type
boolean
Check whether the image source is changed

isDefaultAligned([imageType], [align]) → {boolean} #

Check whether the image is set to default alignment We explicitly repeat tests so to avoid recursively calling the other methods.

Parameters:

Name Type Attributes Description
imageType string optional

Type of the image.

align string optional

Optional alignment value to test against. Supplying this parameter would test whether this align parameter would mean the image is aligned to its default position.

Source:

Returns:

defaultAlignment flag on or off

Type
boolean

Check whether the image is set to default alignment We explicitly repeat tests so to avoid recursively calling the other methods.

isDefaultSize() → {boolean} #

Check whether the image is set to default size

Source:

Returns:

Default size flag on or off

Type
boolean
Check whether the image is set to default size

onScalableDefaultSizeChange(isDefault) #

Deal with default change on the scalable object

Parameters:

Name Type Description
isDefault boolean
Source:
Deal with default change on the scalable object

resetDefaultDimensions() #

Reset the default dimensions of the image based on its type and on whether we have the originalDimensions object from the API

Source:

Reset the default dimensions of the image based on its type and on whether we have the originalDimensions object from the API

setAlignment(align) #

Set image alignment

Parameters:

Name Type Description
align string

Alignment

Source:
See:

Fires:

Set image alignment

setAltText(text) #

Set alternate text

Parameters:

Name Type Description
text string

Alternate text

Source:
Set alternate text

setBoundingBox(box) #

Set the original bounding box

Parameters:

Name Type Description
box Object

Bounding box with width and height

Source:
Set the original bounding box

setCaptionDocument(doc) #

Set image caption document.

Parameters:

Name Type Description
doc ve.dm.Document

Image caption document

Source:
Set image caption document.

setCurrentDimensions(dimensions) #

Set the current dimensions of the image. Normalize in case only one dimension is available.

Parameters:

Name Type Description
dimensions Object

Dimensions width and height

Properties:
Name Type Description
width number

The width of the image

height number

The height of the image

Source:
Set the current dimensions of the image.

setFilename(filename) #

Set the filename of the current image

Parameters:

Name Type Description
filename string

Image filename (without namespace)

Source:
Set the filename of the current image

setImageClassAttr(classAttr) #

Parameters:

Name Type Description
classAttr string | null
Source:

setImageHref(href) #

Set the image href value

Parameters:

Name Type Description
href string

The destination href of the given media file

Source:
Set the image href value

setImageResourceName(resourceName) #

Set the image file resource name

Parameters:

Name Type Description
resourceName string

The resource name of the given image file

Source:
Set the image file resource name

setImageSource(src) #

Set the image file source

Parameters:

Name Type Description
src string

The source of the given media file

Source:
Set the image file source

setImgWrapperClassAttr(classAttr) #

Parameters:

Name Type Description
classAttr string | null
Source:

setMediaType(type) #

Set symbolic name of media type.

Example values: "BITMAP" for JPEG or PNG images; "DRAWING" for SVG graphics

Parameters:

Name Type Description
type string | undefined

Symbolic media type name, or undefined if empty

Source:
Set symbolic name of media type.

setSizeType(type) #

Change size type of the image

Parameters:

Name Type Description
type string

Size type 'default', 'custom' or 'scale'

Source:
Change size type of the image

setType(type) #

Set image type

Parameters:

Name Type Description
type string

Image type

Source:
See:

Fires:

Set image type

setVerticalAlignment(valign) #

Set image vertical alignment

Parameters:

Name Type Description
valign string

Alignment

Source:
See:

Fires:

Set image vertical alignment

storeInitialHash(hash) #

Set the initial hash object of the image to be compared to when checking if the model is modified.

Parameters:

Name Type Description
hash Object

The initial hash object

Source:

Set the initial hash object of the image to be compared to when checking if the model is modified.

toggleBorder([hasBorder]) #

Toggle the border flag of the image

Parameters:

Name Type Attributes Description
hasBorder boolean optional

Border flag. Omit to toggle current value.

Source:
Toggle the border flag of the image

toggleBorderable([borderable]) #

Toggle the option of whether this image can or cannot have a border set on it.

Parameters:

Name Type Attributes Description
borderable boolean optional

Set or unset borderable. If not specified, the current state is toggled.

Source:

Toggle the option of whether this image can or cannot have a border set on it.

toggleDefaultSize([isDefault]) #

Toggle the default size flag of the image

Parameters:

Name Type Attributes Description
isDefault boolean optional

Default size flag. Omit to toggle current value.

Source:

Fires:

Toggle the default size flag of the image

updateImageNode(node, surfaceModel) #

Update an existing image node by changing its attributes

Parameters:

Name Type Description
node ve.dm.MWImageNode

Image node to update

surfaceModel ve.dm.Surface

Surface model of main document

Source:
Update an existing image node by changing its attributes

updateScalableDetails(originalDimensions) #

If the image changed, update scalable definitions.

Parameters:

Name Type Description
originalDimensions Object

Image original dimensions

Source:
If the image changed, update scalable definitions.

createImageNode(attributes, [imageType]) → {ve.dm.MWImageNode}static #

Create a new image node based on given parameters.

Parameters:

Name Type Attributes Description
attributes Object

Image attributes

imageType string optional

Image node type 'mwInlineImage' or 'mwBlockImage'. Defaults to 'mwBlockImage'

Source:

Returns:

An image node

Type
ve.dm.MWImageNode
Create a new image node based on given parameters.

newFromImageAttributes(attrs, parentDoc) → {ve.dm.MWImageModel}static #

Load from image data with scalable information.

Parameters:

Name Type Description
attrs Object

Image node attributes

parentDoc ve.dm.Document

Document that contains or will contain the image

Source:

Returns:

Image model

Type
ve.dm.MWImageModel
Load from image data with scalable information.

newFromImageNode(node) → {ve.dm.MWImageModel}static #

Load from existing image node.

Parameters:

Name Type Description
node ve.dm.MWImageNode

Image node

Source:

Returns:

Image model

Type
ve.dm.MWImageModel
Load from existing image node.

Events

alignmentChange(Alignment) #

Change of image alignment or of having alignment at all

Parameters:

Name Type Description
Alignment string

'left', 'right', 'center' or 'none'

Source:
Change of image alignment or of having alignment at all

sizeDefaultChange(Image) #

Change in size type between default and custom

Parameters:

Name Type Description
Image boolean

is default size

Source:
Change in size type between default and custom

typeChange(Image) #

Change in the image type

Parameters:

Name Type Description
Image string

type 'thumb', 'frame', 'frameless' or 'none'

Source:
Change in the image type