|
require(["ipuUI", "jquery"], function (ipuUI, $) {
$.fn.enter = function (back) {
$(this).on("keydown", function (e) { // 输入框是否有值
if (e.which == '13') { // 回车事件
back.call(this);
}
});
return this;
};
$.sizeReady(function () {
// 搜索框交互部分
$(".common-search").each(function (i, obj) {
$(".common-search-wrap", this).submit(function () {
return false; //阻止form跳转
});
$(".common-search-input", this).focus(function () { // 输入框激活时
$(obj).addClass("common-search-active");
$("body").addClass("state-search-input");
});
$(".common-search-input", this).blur(function () { // 输入框未激活时
$(obj).removeClass("common-search-active");
});
$(".common-search-input", this).on("keyup input", function (e) { // 输入框是否有值
$(obj).toggleClass("common-search-value", $(this).val() != "").width();
});
$(".common-search-input-clear", this).click(function () { // 清除按钮
$(".common-search-input", obj).val("").focus();
$(obj).removeClass("common-search-value"); //
});
});
// 搜索框回车事件
$(".common-search-input").enter(function () {
myRefresh.endBottomLoading();
listObj.empty();
countNo++;
myRefresh.enableBottom(true);
myRefresh.refresh();
$("body").removeClass("state-search-input");
});
var totalPage = 2; // 总页数
var nowPage = 1; // 当前显示第几页,因为默认有一些数据了,所以为1
var rootEl = $("#refresh-video-list");
var listObj = $("ul", rootEl);
var contentHtml = $("li:lt(10)", listObj).clone(); // 测试用,复制5条数据
// 移除初始的数据,并初始nowPage=0;
listObj.empty();
nowPage = 0;
var countNo = 0; // 重要计数器,以此来判断不需要
// 初始化下拉刷新
var myRefresh = ipuUI.refresh(rootEl, {
bottomLoadFun: function () { // 加载更多
console.log('加载更多'); // 手势上拉,内容下滚动动
addData();
},
initEnableBottom: false //
});
// 查询数据
function addData(refresh) {// 0搜索,1刷新,2加载更多
$('.no-result-msg', rootEl).hide();
nowPage++;
var localCountNo = ++countNo; // 执行查询前,保留当前计数器,当查询返回时进行检查是否最新查询,不是则抛弃查询结果
setTimeout(function () { // 模拟延时加载
if (localCountNo == countNo) { // 检查是否最新查询返回数据,不是则抛弃查询结果
myRefresh.enableBottom(nowPage < totalPage); // enable应该总是先于endBottom/TopLoading方法执行
if (totalPage == 0) {
$('.no-result-msg', rootEl).show();
} else {
contentHtml.clone().appendTo(listObj);
}
myRefresh.endBottomLoading(); //最后调用
}
}, 3000);
}
});
});
|