Browse Source

第二次配置

pull/231/head
star 7 years ago
parent
commit
db82cc3695
  1. 23
      examples/rate.html
  2. 141
      src/lay/modules/rate.js

23
examples/rate.html

@ -67,6 +67,11 @@ body{padding:20px;}
<li class="layui-inline"><i class="layui-icon layui-icon-rate"></i></li> <li class="layui-inline"><i class="layui-icon layui-icon-rate"></i></li>
</ul> </ul>
</div> </div>
<div id="test1"></div>
<div id="test2"></div>
<div id="test3"></div>
</div> </div>
</div> </div>
@ -76,9 +81,21 @@ body{padding:20px;}
layui.use(['rate'], function(){ layui.use(['rate'], function(){
var rate = layui.rate; var rate = layui.rate;
rate.primary(".layui-rate-primary","li"){
//设置全局
} rate.set({
score: 3.5
});
var ins = rate.render({
elem: '#test1'
})
rate.primary(".layui-rate-primary","li");
rate.half(".layui-rate-half","li");
rate.text(".layui-rate-text","li");
}); });
</script> </script>
</body> </body>

141
src/lay/modules/rate.js

@ -1,21 +1,132 @@
layui.define('jquery',function(){ layui.define('jquery',function(exports){
"use strict"; "use strict";
var $ = layui.jquery; var $ = layui.jquery
var rate={
primary:function(e,x){ //外部接口
$(e x).each(function(index){ ,rate = {
var index=index; config: {}
$(this).mouseover(function(){ ,index: layui.rate ? (layui.rate.index + 10000) : 0
// $(e > x:lt(index+1) i).addClass("layui-icon-rate-solid").removeClass("layui-icon-rate");
console.log(11); //设置全局项
}); ,set: function(options){
$(this).click(index){ var that = this;
that.config = $.extend({}, that.config, options);
} return that;
}) }
};
//事件监听
,on: function(events, callback){
return layui.onevent.call(this, MOD_NAME, events, callback);
}
}
//字符常量
,ICON_RATE = 'layui-icon-rate', ICON_RATA_SOLID = 'layui-icon-rate-solid'
//构造器
,Class = function(options){
var that = this;
that.index = ++rate.index;
that.config = $.extend({}, that.config, rate.config, options);
that.render();
};
//默认配置
Class.prototype.config = {
limit: 10 //每页显示的数量
,loading: true //请求数据时,是否显示loading
,cellMinWidth: 60 //所有单元格默认最小宽度
,text: {
none: '无数据'
}
};
//评分渲染
Class.prototype.render = function(){
var that = this
,options = that.config;
/*
div class="layui-rate layui-col-xm4 layui-col-xm-offset4 ">
<h3>只读</h3>
<hr>
<ul class="layui-rate-read">
<li class="layui-inline"><i class="layui-icon layui-icon-rate-solid"></i></li>
<li class="layui-inline"><i class="layui-icon layui-icon-rate-solid"></i></li>
<li class="layui-inline"><i class="layui-icon layui-icon-rate"></i></li>
<li class="layui-inline"><i class="layui-icon layui-icon-rate"></i></li>
<li class="layui-inline"><i class="layui-icon layui-icon-rate"></i></li>
</ul>
</div>
*/
var obj = {
primary:function(e,x){
$(e+' > '+x).each(function(index){
var ind=index;
$(this).mouseover(function(){
}),
$(this).mouseout(function(){
}),
$(this).click(function(){
$(this).children("i").addClass(ICON_RATA_SOLID).removeClass(ICON_RATE)
$(this).prevAll().each(function(){
$(this).children("i").addClass(ICON_RATA_SOLID).removeClass(ICON_RATE)
})
$(this).nextAll().each(function(){
$(this).children("i").addClass(ICON_RATE).removeClass(ICON_RATA_SOLID)
})
})
})
},
half:function(e,x){
},
text:function(e,x){
$(e+' > '+x).each(function(index){
var ind=index;
$(this).click(function(){
$(this).children("i").addClass(ICON_RATA_SOLID).removeClass(ICON_RATE)
$(this).prevAll().each(function(){
$(this).children("i").addClass(ICON_RATA_SOLID).removeClass(ICON_RATE)
})
$(this).nextAll().each(function(){
$(this).children("i").addClass(ICON_RATE).removeClass(ICON_RATA_SOLID)
})
$(e).next("span").text(ind+1);
})
})
}
};
};
//事件处理
Class.prototype.events = function(){
}
//核心接口
rate.render = function(options){
var inst = new Class(options);
return thisTable.call(inst);
}; };
//核心入口
rate.render = function(options){
var inst = new Class(options);
return thisTable.call(inst);
};
exports('rate', rate); exports('rate', rate);
}) })
Loading…
Cancel
Save