JQ闭包 / JS插件开发
SUI的JS
(function($){
var WidgetPlugin = function(){
var _self = this;
var ses = {
'show_plug' : '#plugin .modal-body .form-horizontal',
};
/* 渲染配置表单 */
_self.renderPluginConfigForm = function(data){
var index = layer.load(1);
$.post("/admin/plan/com/plugin/view", data,
function(rep){
layer.close(index);
if(rep.code == 200){
$(ses.show_plug).html(rep.data);
}else{
layer.msg("拉取失败,请重试");
}
}, "json");
};
/* 保存插件配置 */
_self.saveWidgetConfig = function(data){
var index = layer.load(1);
$.post("/admin/plan/com/plugin/edit", data,
function(rep){
layer.close(index);
var content= rep.data;
layer.msg(content, {
time: 1000
}, function(){
document.location.reload();
});
}, "json");
};
_self.insertInstance = function(data){
layer.open({
title:'信息',
content: "是否确定启用实例",
btn: ['是', '否'],
yes:function(index){
$.post("/admin/plan/com/plugin/create", data,
function(rep){
if(rep.code == 200){
layer.msg(rep.data, {
time: 1000
}, function(){
document.location.reload();
});
}else{
layer.msg(rep.data);
}
}, "json");
}
});
};
/* 初始化加载layer插件 */
var init = function(){
layui.use(['layer'], function(args){
var layer = layui.layer;
});
};
init();
};
//-- Process event --
var widgetHandler = new WidgetPlugin;
$(".editPlug").on('click', function() {
var id = $(this).attr("instance-id");
var csrfToken = $('meta[name="csrf-token"]').attr("content");
var data = { "id": id,"_csrf":csrfToken };
widgetHandler.renderPluginConfigForm(data);
});
})(Zepto);