layui-js/build/lay/modules/element.js
2016-10-18 08:23:17 +08:00

2 lines
3.2 KiB
JavaScript

/** layui-v1.0.2 经典模块化前端框架 LGPL license By www.layui.com */
;layui.define("jquery",function(i){"use strict";var t=layui.jquery,a=(layui.hint(),layui.device()),e="element",n="layui-this",l="layui-show",o=function(){this.config={}};o.prototype.set=function(i){var a=this;return t.extend(!0,a.config,i),a},o.prototype.on=function(i,t){return layui.onevent(e,i,t)},o.prototype.init=function(i){var o={tabClick:function(i,a){var o=t(this),a=a||o.index(),s=o.parents(".layui-tab"),u=s.find(".layui-tab-content .layui-tab-item"),c=s.attr("lay-filter");o.addClass(n).siblings().removeClass(n),u.eq(a).addClass(l).siblings().removeClass(l),layui.event.call(this,e,"tab("+c+")",{elem:s,index:a})},tabAuto:function(){var i="layui-tab-more",e="layui-tab-bar",l="layui-tab-close",s=this;t(".layui-tab").each(function(){var u=t(this),c=u.find(".layui-tab-title"),r=(u.find(".layui-tab-item"),'lay-stope="tabmore"'),f=t('<span class="layui-unselect layui-tab-bar" '+r+"><i "+r+' class="layui-icon">&#xe61a;</i></span>');if(s===window&&8!=a.ie&&o.hideTabMore(!0),u.attr("lay-allowClose")&&!c.find("li").find("."+l)[0]){var y=t('<i class="layui-icon layui-unselect '+l+'">&#x1006;</i>');y.on("click",function(){var i=t(this).parent(),a=i.index(),e=i.parents(".layui-tab"),l=e.find(".layui-tab-content .layui-tab-item");i.hasClass(n)&&(i.next()[0]?o.tabClick.call(i.next()[0],{},a+1):i.prev()[0]&&o.tabClick.call(i.prev()[0],{},a-1)),i.remove(),l.eq(a).remove()}),c.find("li").append(y)}if(c.prop("scrollWidth")>c.outerWidth()+1){if(c.find("."+e)[0])return;c.append(f),f.on("click",function(t){c[this.title?"removeClass":"addClass"](i),this.title=this.title?"":"收缩"})}else c.find("."+e).remove()})},hideTabMore:function(i){var a=t(".layui-tab-title");i!==!0&&"tabmore"===i.target.getAttribute("lay-stope")||(a.removeClass("layui-tab-more"),a.find(".layui-tab-bar").attr("title",""))}},s={tab:function(){var i=".layui-tab-title li";o.tabAuto.call({}),u.off("click",i,o.tabClick).on("click",i,o.tabClick),t(window).off("resize",o.tabAuto).on("resize",o.tabAuto),t(document).off("click",o.hideTabMore).on("click",o.hideTabMore)},nav:function(){var i,e=".layui-nav",n="layui-nav-item",l="layui-nav-bar",o="layui-nav-tree",s=200,u=function(a,e){var n=t(this);e.hasClass(o)?a.css({top:n.position().top,height:n.height(),opacity:1}):(a.css({left:n.position().left+parseFloat(n.css("marginLeft")),top:n.position().top+n.height()-5}),i=setTimeout(function(){a.css({width:n.width(),opacity:1})},s))};t(e).each(function(){var e=t(this),c=t('<span class="'+l+'"></span>');e.find("."+l)[0]||a.ie&&a.ie<10||(e.append(c),e.find("."+n).on("mouseenter",function(){u.call(this,c,e)}),e.on("mouseleave",function(){clearTimeout(i),setTimeout(function(){e.hasClass(o)?c.css({height:0,top:c.position().top+c.height()/2,opacity:0}):c.css({width:0,left:c.position().left+c.width()/2,opacity:0})},s)}))})},breadcrumb:function(){var i=".layui-breadcrumb";t(i).each(function(){var i=t(this),a=i.attr("lay-separator")||">",e=i.find("a");e.each(function(i){i!==e.length-1&&t(this).append("<span>"+a+"</span>")}),i.css("visibility","visible")})}};return layui.each(s,function(i,t){t()})};var s=new o,u=t("body");s.init(),i(e,function(i){return s.set(i)})});