#Template#_wev8.js
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
define(["Component"], function (Component) {
var comp = function (options) {
/* 调用父类构造函数,固定写法 */
Component.super(this, options);
/**
* 插件基本属性
* @property {string} type - 插件标识
* @property {string} tpl - 插件模板名称,固定写法,插件没有模板时可以不设置该属性
* @property {string} css - 插件样式名称,固定写法,插件没有样式时可以不设置该属性
* @property {object} viewModel - 插件配置项,属性可用于替换html模板,也可用于完成一些功能性的配置。此配置项可被外部调用时替换
*/
this.type = "#{id}#"; // 根据实际情况修改该值,一经导入或新建插件成功后将不可修改,否则将会导致插件运行异常
this.tpl = this.type + "_html";
this.css = this.type + "_css";
this.viewModel = {
content: "一个新的插件:#{text}#",
click: function () {
alert($(this).text());
}
};
/**
* 插件生命周期方法
* @method beforeMount - 在插件渲染之前被调用,此时还没有创建dom到页面上
* @method mounted - 在插件渲染完成后调用,此时可以通过this.$el操作插件dom
*/
this.beforeMount = function () { };
this.mounted = function () {
/**
* @namespace this
* @property {Zepto} $el - 插件dom的zepto对象 - abbr#NMEC_{this.id} 节点
* @property {Zepto} $comp - 插件内容dom的zepto对象 - div.wev-comp-{this.type}节点
* @property {Zepto} $container - 插件所属页面dom的zepto对象 - div.page.in节点
*/
this.$el.on("click", this.viewModel.click);
};
};
/* 调用父类初始化函数,固定写法 */
return Component.init(comp);
});