"use strict";
(function ($) {
/*tabs*/
$.fn.tabs = function (options) {
return this.each(function () {
var $this = $(this);
var opts = $.extend({}, $.fn.tabs.defaults, options);
var o = $.meta ? $.extend(opts, $this.data()) : opts;
var lis = $this.find(o.tabTag).children(o.tabItemTag);
lis.each(function (i, e) {
var $$this = $(this);
var change = function change(index) {
o.curIndex = index;
lis.removeClass(o.tabCurCss);
$$this.addClass(o.tabCurCss);
$this.find(o.conTag).hide();
$this.find(o.conTag).eq(index).show();
if (o.callback) o.callback(index);
};
if (i == o.curIndex) {
change(i);
}
$(this).off().on(o.events, {
index: i
}, function (event) {
var len = o.disabled.length;
var flag = !!0;
if (len > 0) {
for (var i = 0; i < len; i++) {
if (o.disabled[i] == event.data.index) {
flag = !!1;
break;
}
}
}
if (len == 0 || !flag) {
change(event.data.index);
}
}).hover(function () {
$(this).addClass(o.tabHoverCss);
}, function () {
$(this).removeClass(o.tabHoverCss);
});
});
});
};
$.fn.tabs.defaults = {
tabTag: 'ul.tabs-tag',
tabItemTag: 'li',
curIndex: 0,
conTag: 'div.tabs-con',
events: 'click',
tabCurCss: 'cur',
tabHoverCss: 'hover',
timing: false,
callback: undefined,
disabled: []
}; //select
$.fn.extend({
select: function select(options) {
//默认参数
var defaults = {
class: '',
width: "180px",
//生成的select框宽度
listMaxHeight: "200px",
//生成的下拉列表最大高度
//themeColor: "#00bb9c", //主题颜色
fontColor: "#000",
//字体颜色
fontSize: "15px",
//字体大小
showSearch: false,
//是否启用搜索框
rowColor: "#fff",
//行原本的颜色
rowHoverColor: "#0faf03",
//移动选择时,每一行的hover底色
fontHoverColor: "#fff",
//移动选择时,每一行的字体hover颜色
mainContent: "请选择",
//选择显示框的默认文字
searchContent: "关键词搜索",
//搜索框的默认提示文字
optionData: undefined,
//对象类型
callback: undefined,
curIndex: -1,
initCallback: undefined
}; //将默认的参数对象和传进来的参数对象合并在一起
var opts = $.extend(defaults, options); //重新为原select标签对象命名
var $this = this;
var html = '';
if (opts.optionData && opts.optionData.length > 0) {
for (var i = 0; i < opts.optionData.length; i++) {
//html+=''
html += '';
}
$this.html(html);
}
if (opts.curIndex > -1) {
$this.find('option').eq(opts.curIndex).attr('selected', true);
} //隐藏原select标签,并且在其后添加需要的html元素
$this.hide();
$this.after('\
\
\
' + opts.mainContent + '\
\
\
\
\
'); //拿到新生成的对select替代的div
var $This = $this.next(); //灌入原select的数据
$this.find("option").each(function (index, element) {
var $li = $('' + $(element).text() + '');
if ($(element).prop("selected")) {
$li.addClass("list_current");
$This.find(".select_content").text($(element).text());
}
$This.find(".no_result").before($li);
}); //传进来的参数操作
if (opts.width.trim() != "" && opts.width.trim() != "180px") $This.css("width", opts.width.trim());
if (opts.listMaxHeight.trim() != "" && opts.listMaxHeight.trim() != "200px") $This.find(".select_list_body").css("max-height", opts.listMaxHeight.trim());
if (typeof opts.showSearch == "boolean" && !opts.showSearch) $This.find(".select_list_search").hide();
if (opts.fontColor.trim() != "" && opts.fontColor.trim() != "15px") {
$This.find(".select_content,.select_input,li").css("color", opts.fontColor.trim());
$This.find("li").hover(function () {
$(this).css({
"color": opts.fontHoverColor.trim()
});
}, function () {
$(this).css({
"color": opts.fontColor.trim()
});
});
}
if (opts.rowHoverColor.trim() != "" && opts.rowHoverColor.trim() != "#0faf03") {
$This.find("li").hover(function () {
$(this).css({
"background-color": opts.rowHoverColor.trim()
});
}, function () {
$(this).css({
"background-color": opts.rowColor.trim()
});
});
} //获取此时列表的高度
if ($This.find("li").size() < 3) {
$This.find(".select_list_ul .no_result").show();
} else {
$This.find(".select_list_ul .no_result").hide();
}
var list_height = $This.find(".select_list").height(); //列表过滤函数
function Search(self) {
var isAllHide = true;
$This.find(".select_list_ul li").not(".no_result").each(function (index, element) {
if ($(element).text().indexOf($(self).val()) == -1) $(element).hide();else if ($(element).hasClass("list_current")) $(element).hide();else {
isAllHide = false;
$(element).show();
}
});
if (isAllHide) $This.find(".select_list_ul .no_result").show();else $This.find(".select_list_ul .no_result").hide();
$This.find(".select_list").css("height", "auto");
list_height = $This.find(".select_list").height();
} //动态调整搜索框的宽度
$This.find(".select_input").css({
"width": $This.find(".select_main").width() - 41
}); //为显示框添加点击出现下拉框事件
$This.find(".select_arrow,.select_content,.select_arrow_after").click(function (e) {
$This.find(".select_arrow,.select_arrow_after").toggleClass("cast_rotate");
if ($This.find(".select_arrow_after").hasClass("cast_rotate")) $This.find(".select_arrow_after").css("margin-top", "1px");else $This.find(".select_arrow_after").css("margin-top", "-1px");
if ($This.find(".select_list").hasClass("list_open")) {
$This.find(".select_list").removeClass("list_open").animate({
"height": "0px"
}, 200, function () {
$This.find(".select_list").hide();
});
} else {
$(".list_open").css({
"height": "0px"
}).hide().removeClass("list_open");
$This.find(".select_list").addClass("list_open").css({
"height": "0px"
}).show().animate({
"height": list_height + "px"
}, 200);
}
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
}); //动态调整显示框的宽度
$This.find(".select_content").css({
"width": $This.width() - $This.find(".select_arrow").width() - 40 + "px"
});
if (opts.initCallback && $.type(opts.initCallback) == 'function') {
opts.initCallback.call($this);
}
; //为每一行元素添加点击事件
$This.find(".select_list_body").delegate("li", "click", function (e) {
if ($(this).hasClass("no_result")) return;
$This.find(".select_list_body li").removeClass("list_current").show();
$(this).addClass("list_current").hide();
Search($This.find(".select_input"));
$This.find(".select_content").text($(this).attr('title'));
$This.attr({
"val": $(this).attr("val") == null ? '' : $(this).attr("val"),
"text": $(this).text()
});
$this.val($(this).attr("val") == null ? '' : $(this).attr("val"));
list_height = $This.find(".select_list").height();
$This.find(".select_content").trigger("click");
if (opts.callback && $.type(opts.callback) == 'function') {
opts.callback.call($(this));
}
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
});
$(document).on('click', function () {
if ($This.find(".select_list").hasClass("list_open")) {
$This.find(".select_content").trigger("click");
}
}); //为搜索框添加keyup事件
$This.find(".select_input").on("keyup", function () {
Search(this);
});
return $this;
}
}); //返回顶部
$('.totop').on('click', function () {
$("html,body").animate({
scrollTop: 0
}, 500);
}); // 右侧弹窗
setTimeout(function () {
$('#m-popup').fadeIn('200');
}, 5000);
$('#m-popup .close').click(function () {
$('#m-popup').fadeOut('200');
});
})(jQuery);