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:
|
- Mixes in:
- Source:
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 |
Attach a new scalable object to the model and request the information from the API.
cacheOriginalImageAttributes(attrs)
#
changeImageSource(attrs, [APIinfo])
#
getAlignment() → {string|null
}
#
null
}
#
Get image alignment 'left', 'right', 'center', 'none' or 'default'
Returns:
Image alignment. Inline images have initial alignment value of null.
- Type
-
string
|
null
getAltText() → {string}
#
Get the image alternate text
Returns:
Alternate text
- Type
- string
getBoundingBox() → {Object}
#
getCaptionDocument() → {ve.dm.Document}
#
Get image caption document.
Auto-generates a blank document if no document exists.
Returns:
Caption document
- Type
- ve.dm.Document
getCurrentDimensions() → {ve.ui.DimensionsWidget.Dimensions}
#
Get the image current dimensions
Returns:
Current dimensions width/height
getDefaultDimensions() → {Object}
#
Retrieve the currently set default dimensions from the scalable object attached to the image.
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. |
Returns:
Node alignment based on document direction
- Type
- string
getFilename() → {string}
#
Get the filename of the current image
Returns:
filename Image filename (without namespace)
- Type
- string
getHashObject() → {Object}
#
getImageClassAttr() → {string|null
}
#
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'
Returns:
The destination href of the given media file
- Type
- string
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. |
Returns:
Node type 'mwInlineImage' or 'mwBlockImage'
- Type
- string
getImageResourceName() → {string}
#
Get the image file resource name. The resource name represents the filename without the full source url. For example, './File:Foo.jpg'
Returns:
The resource name of the given media file
- Type
- string
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
'
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
}
#
null
}
#
getMediaTag() → {string}
#
Get media tag: img, video or audio
Returns:
Tag name
- Type
- string
getMediaType() → {string|undefined
}
#
undefined
}
#
Get symbolic name of media type.
Example values: "BITMAP" for JPEG or PNG images; "DRAWING" for SVG graphics
Returns:
Symbolic media type name, or undefined if empty
- Type
-
string
|
undefined
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
'
Returns:
Normalized image source
- Type
- string
getOriginalImageAttributes() → {Object}
#
getResourceName() → {string}
#
Get the image file resource name
Returns:
resourceName The resource name of the given media file
- Type
- string
getScalable() → {ve.dm.Scalable}
#
Get the scalable object responsible for size manipulations for the given image
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
Returns:
Size type
- Type
- string
getType() → {string}
#
Get image wikitext type; 'thumb', 'frame', 'frameless' or 'none/inline'
Returns:
Image type
- Type
- string
getUpdatedAttributes() → {Object}
#
getVerticalAlignment() → {string}
#
Get image vertical alignment 'middle', 'baseline', 'sub', 'super', 'top', 'text-top', 'bottom', 'text-bottom' or 'default'
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.
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
Returns:
Border flag on or off
- Type
- boolean
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 |
Returns:
Fragment covering inserted image
Throws:
-
Unknown image node type
- Type
- Error
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. |
Returns:
hasAlignment flag on or off
- Type
- boolean
isBorderable() → {boolean}
#
Check whether the image can have a border set on it
Returns:
Border possible or not
- Type
- boolean
isChangedImageSource() → {boolean}
#
Check whether the image source is changed
Returns:
changedImageSource flag on or off
- Type
- boolean
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. |
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
Returns:
Default size flag on or off
- Type
- boolean
onScalableDefaultSizeChange(isDefault)
#
Deal with default change on the scalable object
Parameters:
Name | Type | Description |
---|---|---|
isDefault |
boolean |
resetDefaultDimensions()
#
Reset the default dimensions of the image based on its type and on whether we have the originalDimensions object from the API
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:
setAltText(text)
#
Set alternate text
Parameters:
Name | Type | Description |
---|---|---|
text |
string | Alternate text |
setBoundingBox(box)
#
Set the original bounding box
Parameters:
Name | Type | Description |
---|---|---|
box |
Object | Bounding box with width and height |
setCaptionDocument(doc)
#
Set image caption document.
Parameters:
Name | Type | Description |
---|---|---|
doc |
ve.dm.Document | 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:
|
setFilename(filename)
#
Set the filename of the current image
Parameters:
Name | Type | Description |
---|---|---|
filename |
string | Image filename (without namespace) |
setImageClassAttr(classAttr)
#
Parameters:
Name | Type | Description |
---|---|---|
classAttr |
string
|
null
|
setImageHref(href)
#
Set the image href value
Parameters:
Name | Type | Description |
---|---|---|
href |
string | The destination href of the given media file |
setImageResourceName(resourceName)
#
Set the image file resource name
Parameters:
Name | Type | Description |
---|---|---|
resourceName |
string | The resource name of the given image file |
setImageSource(src)
#
Set the image file source
Parameters:
Name | Type | Description |
---|---|---|
src |
string | The source of the given media file |
setImgWrapperClassAttr(classAttr)
#
Parameters:
Name | Type | Description |
---|---|---|
classAttr |
string
|
null
|
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 |
setSizeType(type)
#
Change size type of the image
Parameters:
Name | Type | Description |
---|---|---|
type |
string | Size type 'default', 'custom' or 'scale' |
setType(type)
#
Set image type
Parameters:
Name | Type | Description |
---|---|---|
type |
string | Image type |
- Source:
- See:
Fires:
setVerticalAlignment(valign)
#
Set image vertical alignment
Parameters:
Name | Type | Description |
---|---|---|
valign |
string | Alignment |
Fires:
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 |
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. |
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. |
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. |
Fires:
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 |
updateScalableDetails(originalDimensions)
#
If the image changed, update scalable definitions.
Parameters:
Name | Type | Description |
---|---|---|
originalDimensions |
Object | Image original dimensions |
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' |
Returns:
An image node
- Type
- ve.dm.MWImageNode
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 |
Returns:
Image model
- Type
- ve.dm.MWImageModel
newFromImageNode(node) → {ve.dm.MWImageModel}static
#
Load from existing image node.
Parameters:
Name | Type | Description |
---|---|---|
node |
ve.dm.MWImageNode | Image node |
Returns:
Image model
- Type
- ve.dm.MWImageModel
Events
alignmentChange(Alignment)
#
Change of image alignment or of having alignment at all
Parameters:
Name | Type | Description |
---|---|---|
Alignment |
string | 'left', 'right', 'center' or 'none' |
sizeDefaultChange(Image)
#
Change in size type between default and custom
Parameters:
Name | Type | Description |
---|---|---|
Image |
boolean | is default size |
typeChange(Image)
#
Change in the image type
Parameters:
Name | Type | Description |
---|---|---|
Image |
string | type 'thumb', 'frame', 'frameless' or 'none' |