Class Block
Define a block to be displayed into a JBlocks.
- Defined in: jblocks.block.js
Constructor Attributes | Constructor Name and Description |
---|---|
Block()
A Block represents a rectangular area inside a JBlocks viewport. |
Method Summary
Class Detail
Block()
A Block represents a rectangular area inside a JBlocks viewport. The exact position of the Block depends on the result of the layout calculation performed by the library based on the created Block objects inside the JBlocks.
The constructor should not be invoked directly but JBlocks#newBlock or JBlocks#addNewBlock should be used instead.
Field Detail
className
The name of the class for this block object.
jBlocks
The JBlocks object managing the block.
Method Detail
-
addTag(tag)Add tag to the block. Tags are used to find blocks more easily. A block can have several tags.
- Parameters:
- {String} tag
- the tag to add to the block.
-
{Boolean} canFullScreen()Check fullscreen availability.
- Returns:
- Whether the browser supports fullscreen
-
canGrow()Returns whether the block uses a set of layouts from options.layouts and can step up to a bigger size.
- Returns:
- whether calling the Block#grow method will have an effect on the block size.
-
canShrink()Returns whether the block uses a set of layouts from options.layouts and can step down to a smaller size.
- Returns:
- whether calling the Block#shrink method will have an effect on the block size.
-
display(geometry)Called to display the block. The method is invoked by the jBlocks core and must never be called directly.
- Parameters:
- {Object} geometry
- the block content geometry.
- {Number} geometry.width
- the width of the block content in pixels
- {Number} geometry.height
- the height of the block content in pixels
-
focus()Ensure the specified Block object will be visible after the next layout.
- See:
- JBlocks#focusBlockId
-
fullscreen(widget, function(entering))Make fullscreen the block content or part of it.
- Parameters:
- {jQuerySet} widget Optional
- the element to make fullscreen. If omitted, this.content is used.
- {Function} function(entering)
- to be called when fullscreen is entered or exited.
-
grow()Step up to the higher layout size if a set of layouts from options.layouts has been defined.
- See:
- Block#canGrow
-
init(layout, options)Initializes a block. The method is invoked by the jBlocks core and must never be called directly.
- Parameters:
- {Object} layout Optional
- Object defining the layout preferences for the Block.
- {Number} layout.priority Optional, Default: 0
- When performing a layout, the actual Block objects positions are calculated starting with highest priority.
- {Number} layout.importance Optional, Default: 0
- If the JBlocks has option fixed set to both and there is no space enough to display all the Blocks, the importance parameter is used to determine which blocks will be hidden.
- {Integer} layout.w Optional, Default: 1
- the minimum virtual width required for this block.
- {Integer} layout.h Optional, Default: 1
- the minimum virtual height required for this block.
- {String} layout.pref Optional, Default: "default"
- the preference for positioning the block:
- default: if JBlocks fixed option is set to height, the pref field behaves as if it was "left top" otherwise as "top left".
- top left: displays the block as top as possible then as left as possible.
- left top: displays the block as left as possible then as top as possible.
- top right: displays the block as top as possible then as right as possible in the viewable viewport area.
- right top: displays the block as right as possible in the viewable area then as top as possible.
- bottom left: displays the block as bottom as possible in the viewable area then as left as possible.
- left bottom: displays the block as left as possible then as bottom as possible in the viewable area.
- bottom right: displays the block as bottom as possible then as right as possible, in the viewable viewport area.
- right bottom: displays the block as right as possible then as bottom as possible, in the viewable area.
- {Boolean} layout.visible Optional, Default: true
- should this block be visible.
- {Number} layout.expandWidth Optional, Default: 1
- if set to 0, the block will never expand and will keep the width given by the w parameter. Otherwise, if JBlock option fillHoles is set to true, the layout algorithm tries to expand the neighbor blocks to fill the holes. Blocks with highest expandWidth are expanded in priority.
- {Number} layout.expandHeight Optional, Default: 1
- if set to 0, the block will never expand and will keep the height given by the h parameter. Otherwise, if JBlock option fillHoles is set to true, the layout algorithm tries to expand the neighbor blocks to fill the holes. Blocks with highest expandHeight are expanded in priority.
- {Object} options Optional
- Object defining the options for the Block.
- {String} options.id Optional
- a string to be used as block id. Only letters, digits and dash characters are to be used. If not set, a safe value is automatically used.
- {String} options.blockClass Optional, Default: null
- an additional class to be added to the block. For instance, the block may define a border.
- {String} options.blockContentClass Optional, Default: null
- an additional class to be added to the block content area. For instance, the block may define a background-color.
- {NumberArray} options.margin Optional
- the margins [top,right,bottom,left] expressed relatively to the block size. If not set, the containing JBlocks margin applies.
- {NumberArray} options.padding Optional
- the paddings [top,right,bottom,left] expressed relatively to the block size. If not set, the containing JBlocks margin applies.
- {Number} options.borderRadius Optional, Default: 0.1
- the block border radius expressed relatively to the block size.
- {Number} options.contentBorderRadius Optional, Default: 0.1
- the block content border radius expressed relatively to the block content size.
- {Boolean} options.requireAuth Optional, Default: false
- if set to true, the becomes visible only when the user is logged in.
- {Boolean} options.requireAnon Optional, Default: false
- if set to true, the becomes visible only when the user is logged out.
- {Function} options.onCreate Optional
- function called when the block is created.
- {Function} options.onRemove Optional
- function called when the block is removed.
- {Function} options.onResize Optional
- function(geometry) called when the block has resized.
- {Function} options.onStartResize Optional
- function(geometry) called when the block starts resizing. Parameter geometry represents the final size.
- {Function} options.w Optional
- function(viewport) called before a relayout so the block can returns its virtual width overloading the provided layout.w.
- {Function} options.h Optional
- function(viewport) called before a relayout so the block can returns its virtual height overloading the provided layout.h.
- {Array} options.layouts Optional
- an array containing the various layouts a block can have. The Block API provides methods to navigate amongst the
defined layouts, allowing blocks to grow or shrink.
Each layout entry contains:
- w: an integer or a function(viewport) returning the block width.
- h: an integer or a function(viewport) returning the block height.
- {Integer} options.layoutIndex Optional
- the initial index within the layouts array.
- {String} options.tooltip Optional
- if set, the given string appears as a tooltip when the mouse is over the block.
- {Boolean} options.earlyLayout Optional, Default: true
- during a single layout process, a block may be asked to resize several times. If resizing is expensive, the earlyLayout option can be set to false so the block is resized only once at the end of the layout operation.
- {Float} options.shadow Optional
- defines a shadow for the block (i.e. 0.15). If unset, the JBlocks blockShadow option applies.
-
log()Log data.
- Parameters:
- {Stringifiable object|String} ...
- See:
- JBlocks.log
-
maximize()Maximizes the block in the JBlocks viewport.
- Parameters:
- {Boolean} options.back Optional, Default: true
- when set to true a Back block button is created and displayed in order to leave the maximized mode.
-
onCreate()Called to build the block content. This function is only called once per block. The method is invoked by the jBlocks core and must never be called directly.
-
onLoggedIn(user)Called when the user logs in. The method is invoked by the jBlocks core and must never be called directly.
- Parameters:
- {Object} user
- the user description.
- {String} user.id
- the user ID.
- {String} user.name
- the user name.
- {String} user.picture
- the URL to the user avatar.
- {String} user.mail
- the user email address.
- {String} user.country
- the user country.
- See:
- Block#onLoggedOut
-
onLoggedOut()Called when the user logs out. The method is invoked by the jBlocks core and must never be called directly.
- See:
- Block#onLoggedIn
-
onRemove()Called when the block is about to be removed.
-
onResize(geometry)Called just after the block has been resized. The method is invoked by the jBlocks core and must never be called directly.
- Parameters:
- {Object} geometry
- the new block content geometry.
- {Number} geometry.width
- the width of the block content in pixels
- {Number} geometry.height
- the height of the block content in pixels
-
onStartResize(geometry)Called just before the block is about to be resized. The method is invoked by the jBlocks core and must never be called directly.
- Parameters:
- {Object} geometry
- the new block content geometry.
- {Number} geometry.width
- the width of the block content in pixels
- {Number} geometry.height
- the height of the block content in pixels
-
remove()Remove the block from its JBlocks context.
-
shrink()Step down to the smaller layout size if a set of layouts from options.layouts has been defined.
- See:
- Block#canShrink
-
t(tag, placeHolders)Generates a translated string based on the given string tag and optional placeholders.
- Parameters:
- {String} tag
- the string tag identifying the text to be be returned.
- {Object} placeHolders Optional
- an object containing the placeholders and corresponding values to be replaced in the returned text.
- Returns:
- the full text to be used in the interface or the string tag itself if no translation has been found for this tag.
- See:
- JBlocks.addTranslation
-
unMaximize()Unmaximizes the block in the JBlocks viewport.