We packed some frequently used web components into Amaze UI Web Widgets. (Introduction, Developing Web Widgets)。
Amaze UI has over 10 web widgets for mobile website development (View demos in new window).
Using templates(hbs) to seperate the data and HTML is one of the most valuable feature. Users can use web widget in different development environment.
There is a widget.html
file in the development templates. It helps to understand how to use widgets in pure browser environment.
Procedure:
handlebars.min.js
;amui.widget.helper.js
;<script type="text/x-handlebars-template" id="amz-tpl">{{>slider slider}}</script>
;$(function() {
var $tpl = $('#amz-tpl');
var source = $tpl.text();
var template = Handlebars.compile(source);
var data = {};
var html = template(data);
$tpl.before(html);
});
Widget can also work with Express.js and hbs.
You may directly use our node module, Amaze UI Widget hbs helper. Here is an example.
Of course, you may call it in your way.
First, register the web widget template to be partial
.
// ...
var hbs = require('hbs');
app.set('view engine', 'hbs');
hbs.registerPartials(widgetDir + '/slider/src');
Then, Call partial
in the page template, where data
is the data of the widget.
{{>slider data}}
See following links:
Now metter which environment above you are using, the following helpers must be registered. (We have already registered these in amui.widget.helper.js
and Node.js module)
(function(hbs) {
hbs.registerHelper("ifCond", function(v1, operator, v2, options) {
switch (operator) {
case "==":
return (v1 == v2) ? options.fn(this) : options.inverse(this);
case "!=":
return (v1 != v2) ? options.fn(this) : options.inverse(this);
case "===":
return (v1 === v2) ? options.fn(this) : options.inverse(this);
case "!==":
return (v1 !== v2) ? options.fn(this) : options.inverse(this);
case "&&":
return (v1 && v2) ? options.fn(this) : options.inverse(this);
case "||":
return (v1 || v2) ? options.fn(this) : options.inverse(this);
case "<":
return (v1 < v2) ? options.fn(this) : options.inverse(this);
case "<=":
return (v1 <= v2) ? options.fn(this) : options.inverse(this);
case ">":
return (v1 > v2) ? options.fn(this) : options.inverse(this);
case ">=":
return (v1 >= v2) ? options.fn(this) : options.inverse(this);
default:
return eval("" + v1 + operator + v2) ? options.fn(this) : options.inverse(this);
}
})(Handlebars);
There seems to be no reason to use web widget without template, but just in case some developers want to do that, we will come back to the old fashion: