Expand all

ve.dm.Scalable

Constructor

new ve.dm.Scalable([config]) #

Scalable object.

Parameters:

Name Type Attributes Description
config Object optional

Configuration options

Properties:
Name Type Attributes Default Description
fixedRatio boolean optional
true

Object has a fixed aspect ratio

currentDimensions Object optional

Current dimensions, width & height

originalDimensions Object optional

Original dimensions, width & height

defaultDimensions Object optional

Default dimensions, width & height

isDefault boolean optional

Object is using its default dimensions

minDimensions Object optional

Minimum dimensions, width & height

maxDimensions Object optional

Maximum dimensions, width & height

enforceMin boolean optional
true

Enforce the minimum dimensions

enforceMax boolean optional
true

Enforce the maximum dimensions

Mixes in:
Source:
Scalable object.

Methods

clearDefaultDimensions() #

Reset and remove the default dimensions

Source:

Fires:

Reset and remove the default dimensions

clearMaxDimensions() #

Clear the maximum dimensions

Source:

Fires:

Clear the maximum dimensions

clearMinDimensions() #

Clear the minimum dimensions

Source:

Fires:

Clear the minimum dimensions

clearOriginalDimensions() #

Reset and remove the default dimensions

Source:

Fires:

Reset and remove the default dimensions

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

Clone the current scalable object

Source:

Returns:

Cloned scalable object

Type
ve.dm.Scalable
Clone the current scalable object

getBoundedDimensions(dimensions, [grid]) → {Object} #

Get a set of dimensions bounded by current restrictions, from specified dimensions

Parameters:

Name Type Attributes Description
dimensions Object

Dimensions object with width & height

grid number optional

Optional grid size to snap to

Source:

Returns:

Dimensions object with width & height

Type
Object
Get a set of dimensions bounded by current restrictions, from specified dimensions

getCurrentDimensions() → {Object} #

Get the original dimensions

Source:

Returns:

Dimensions object with width & height

Type
Object
Get the original dimensions

getCurrentScale() → {number|null} #

Get the current scale of the object

Source:

Returns:

A scale (1=100%), or null if not applicable

Type
number | null
Get the current scale of the object

getDefaultDimensions() → {Object} #

Get the default dimensions

Source:

Returns:

Dimensions object with width & height

Type
Object
Get the default dimensions

getMaxDimensions() → {Object} #

Get the maximum dimensions

Source:

Returns:

Dimensions object with width & height

Type
Object
Get the maximum dimensions

getMinDimensions() → {Object} #

Get the minimum dimensions

Source:

Returns:

Dimensions object with width & height

Type
Object
Get the minimum dimensions

getOriginalDimensions() → {Object} #

Get the original dimensions

Source:

Returns:

Dimensions object with width & height

Type
Object
Get the original dimensions

getRatio() → {number} #

Get the fixed aspect ratio (width/height)

Source:

Returns:

Aspect ratio

Type
number
Get the fixed aspect ratio (width/height)

isCurrentDimensionsValid() → {boolean} #

Checks whether the current dimensions are numeric and within range

Source:

Returns:

Current dimensions are valid

Type
boolean
Checks whether the current dimensions are numeric and within range

isDefault() → {boolean} #

Get the default state of the scalable object

Source:

Returns:

Default size or custom

Type
boolean
Get the default state of the scalable object

isEnforcedMax() → {boolean} #

The object enforces the maximum dimensions when scaling

Source:

Returns:

Enforces the maximum dimensions

Type
boolean
The object enforces the maximum dimensions when scaling

isEnforcedMin() → {boolean} #

The object enforces the minimum dimensions when scaling

Source:

Returns:

Enforces the minimum dimensions

Type
boolean
The object enforces the minimum dimensions when scaling

isFixedRatio() → {boolean} #

Check if the object has a fixed ratio

Source:

Returns:

The object has a fixed ratio

Type
boolean
Check if the object has a fixed ratio

isTooLarge() → {boolean} #

Check if current dimensions are greater than maximum dimensions in either direction

Only possible if enforceMax is false.

Source:

Returns:

Current dimensions are greater than maximum dimensions

Type
boolean

Check if current dimensions are greater than maximum dimensions in either direction

Only possible if enforceMax is false.

isTooSmall() → {boolean} #

Check if current dimensions are smaller than minimum dimensions in either direction

Only possible if enforceMin is false.

Source:

Returns:

Current dimensions are greater than maximum dimensions

Type
boolean

Check if current dimensions are smaller than minimum dimensions in either direction

Only possible if enforceMin is false.

setCurrentDimensions(dimensions) #

Set the current dimensions

Also sets the aspect ratio if not set and in fixed ratio mode.

Parameters:

Name Type Description
dimensions Object

Dimensions object with width & height

Source:

Fires:

Set the current dimensions

Also sets the aspect ratio if not set and in fixed ratio mode.

setDefaultDimensions(dimensions) #

Set the default dimensions

Parameters:

Name Type Description
dimensions Object

Dimensions object with width & height

Source:

Fires:

Set the default dimensions

setEnforcedMax(enforceMax) #

Set enforcement of maximum dimensions

Parameters:

Name Type Description
enforceMax boolean

Enforces the maximum dimensions

Source:
Set enforcement of maximum dimensions

setEnforcedMin(enforceMin) #

Set enforcement of minimum dimensions

Parameters:

Name Type Description
enforceMin boolean

Enforces the minimum dimensions

Source:
Set enforcement of minimum dimensions

setMaxDimensions(dimensions) #

Set the maximum dimensions

Parameters:

Name Type Description
dimensions Object

Dimensions object with width & height

Source:

Fires:

Set the maximum dimensions

setMinDimensions(dimensions) #

Set the minimum dimensions

Parameters:

Name Type Description
dimensions Object

Dimensions object with width & height

Source:

Fires:

Set the minimum dimensions

setOriginalDimensions(dimensions) #

Set the original dimensions

Also resets the aspect ratio if in fixed ratio mode.

Parameters:

Name Type Description
dimensions Object

Dimensions object with width & height

Source:

Fires:

Set the original dimensions

Also resets the aspect ratio if in fixed ratio mode.

setRatioFromDimensions(dimensions) #

Set the fixed aspect ratio from specified dimensions.

Parameters:

Name Type Description
dimensions Object

Dimensions object with width & height

Source:
Set the fixed aspect ratio from specified dimensions.

toggleDefault([isDefault]) #

Toggle the default size setting, or set it to particular value

Parameters:

Name Type Attributes Description
isDefault boolean optional

Default or not, toggles if unset

Source:

Fires:

Toggle the default size setting, or set it to particular value

getDimensionsFromValue(dimensions, [ratio]) → {Object}static #

Calculate the dimensions from a given value of either width or height. This method doesn't take into account any restrictions of minimum or maximum, it simply calculates the new dimensions according to the aspect ratio in case it exists.

If aspect ratio does not exist, or if the original object is empty, or if the original object is fully specified, the object is returned as-is without calculations.

Parameters:

Name Type Attributes Description
dimensions Object

Dimensions object with either width or height if both are given, the object will be returned as-is.

Properties:
Name Type Attributes Description
width number optional

The width of the image

height number optional

The height of the image

ratio number optional

The image width/height ratio, if it exists

Source:

Returns:

Dimensions object with width and height

Type
Object
Calculate the dimensions from a given value of either width or height.

isDimensionsObjectValid(dimensions) → {boolean}static #

Check if an object is a dimensions object. Make sure that if width or height are set, they are not 'undefined'.

Parameters:

Name Type Description
dimensions Object

A dimensions object to test

Source:

Returns:

Valid or invalid dimensions object

Type
boolean
Check if an object is a dimensions object.

Events

currentSizeChange(currentDimensions) #

Current changed

Parameters:

Name Type Description
currentDimensions Object

Current dimensions width and height

Source:
Current changed

defaultSizeChange(isDefault) #

Default size or state changed

Parameters:

Name Type Description
isDefault boolean

The size is default

Source:
Default size or state changed

maxSizeChange(maxDimensions) #

Max size changed

Parameters:

Name Type Description
maxDimensions Object

Max dimensions width and height

Source:
Max size changed

minSizeChange(minDimensions) #

Min size changed

Parameters:

Name Type Description
minDimensions Object

Min dimensions width and height

Source:
Min size changed

originalSizeChange(originalDimensions) #

Original size changed

Parameters:

Name Type Description
originalDimensions Object

Original dimensions width and height

Source:
Original size changed