1.0.7 • Published 11 years ago
slashui-image-cntr v1.0.7
#slashui-image-cntr
The slashui-image-cntr is a Node.js UI Component that centers an image in a container by using
Marko Templates
##How it works
Using slashui-image-cntr in Node.js
- Load module:
npm install slashui-image-cntr --save - Insert the following code in your Marko template.
You would need to provide view model.
<slashui-image-cntr viewModel= $data.imageCntr.viewModel />Sample View Model
var imageCntrViewModel = { imageUrl: 'http://i3.ebayimg.com/images/g/~esAAOSw2XFUahOW/s-w225.webp', // Required link: false, // Optional imageText: 'this is image test', // Optional alias: 'slashui-image-cntr' // Required };
###Parameters
viewModel- this parameter is required and if you fail to provide this paramter you will fail rendering the UI Component.
{
**imageUrl: 'http://i3.ebayimg.com/images/g/~esAAOSw2XFUahOW/s-w225.webp',
**alias: 'slashui-image-cntr' // alias should match the name of the UI Component.
link: false, // if you want your image to become linkable assign a link here.
imageText: 'this is image test', // we will use this text for the alt attribute
}
// ** = Required.configthis parameter is optional if you would like to add some attributes to some of the html tags you can use the config option.
There is also config helper.var config = { attrs:{ imgAttrs:{ id:'img-id' }, figureAttrs:{ id:'figure-id', 'data-test': 'data attribute on figure' } } } //Marko Template <slashui-image-cntr config= $data.config />var config = { imgAttrs:{ id:'img-id' }, figureAttrs:{ id:'figure-id', 'data-test': 'data attribute on figure' } } var viewConfig = require('slashui-image-cntr').buildViewConfig(config); // Marko template <slashui-image-cntr config= $data.viewConfig />
###Client Side Use:
var imageCntr = require(slashui-image-cntr');
var imageCntrViewModel = {
imageUrl: 'http://i3.ebayimg.com/images/g/~esAAOSw2XFUahOW/s-w225.webp',
link: false,
imageText: 'this is image test',
alias: 'slashui-image-cntr'
};
var input = imageCntr.getModel(imageCntrViewModel);
imageCntr.render(input, function(error, result){
console.log(result.html);
});Methods
buildViewConfig: function(viewConfig)- Validates configuration and will return the UI Friendly Config.
getModel: function(viewModel, config)- Will return an Object that has both viewModel and viewConfig and will internally convert config to view config
{ viewModel: //View Model config: //UI Config }
- Will return an Object that has both viewModel and viewConfig and will internally convert config to view config
render: function(data, callback)
- this method is called in the client side to render data. callback function will return the html and error
datais generated fromgetModelmethod.var callback = function(error, result){ console.log(result.html); }
1.0.7
11 years ago