UNPKG

uikit

Version:

UIkit is a lightweight and modular front-end framework for developing fast and powerful web interfaces.

3 lines (2 loc) 5.19 kB
/*! UIkit 3.2.1 | http://www.getuikit.com | (c) 2014 - 2019 YOOtheme | MIT License */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("uikit-util")):"function"==typeof define&&define.amd?define("uikitfilter",["uikit-util"],e):(t=t||self).UIkitFilter=e(t.UIkit.util)}(this,function(h){"use strict";var c,u="uk-animation-target";function f(t,e){var i=h.css(t,"zIndex");return!!h.isVisible(t)&&h.assign({display:"",opacity:e?h.css(t,"opacity"):"0",pointerEvents:"none",position:"absolute",zIndex:"auto"===i?h.index(t):i},d(t))}function l(t){h.css(t.children,{height:"",left:"",opacity:"",pointerEvents:"",position:"",top:"",width:""}),h.removeClass(t,u),h.css(t,"height","")}function d(t){var e=t.getBoundingClientRect(),i=e.height,n=e.width,r=h.position(t),a=r.top,o=r.left;return{top:a+=h.toFloat(h.css(t,"marginTop")),left:o,height:i,width:n}}var t={mixins:[{props:{animation:Number},data:{animation:150},computed:{target:function(){return this.$el}},methods:{animate:function(t){var n=this;!function(){if(c)return;(c=h.append(document.head,"<style>").sheet).insertRule("."+u+" > * {\n margin-top: 0 !important;\n transform: none !important;\n }",0)}();var r=h.toNodes(this.target.children),a=r.map(function(t){return f(t,!0)}),e=h.height(this.target),i=window.pageYOffset;t(),h.Transition.cancel(this.target),r.forEach(h.Transition.cancel),l(this.target),this.$update(this.target),h.fastdom.flush();var o=h.height(this.target),s=(r=r.concat(h.toNodes(this.target.children).filter(function(t){return!h.includes(r,t)}))).map(function(t,e){return!!(t.parentNode&&e in a)&&(a[e]?h.isVisible(t)?d(t):{opacity:0}:{opacity:h.isVisible(t)?1:0})});return a=s.map(function(t,e){var i=r[e].parentNode===n.target&&(a[e]||f(r[e]));if(i)if(t){if(!("opacity"in t)){i.opacity%1?t.opacity=1:delete i.opacity}}else delete i.opacity;return i}),h.addClass(this.target,u),r.forEach(function(t,e){return a[e]&&h.css(t,a[e])}),h.css(this.target,"height",e),h.scrollTop(window,i),h.Promise.all(r.map(function(t,e){return a[e]&&s[e]?h.Transition.start(t,s[e],n.animation,"ease"):h.Promise.resolve()}).concat(h.Transition.start(this.target,{height:o},this.animation,"ease"))).then(function(){r.forEach(function(t,e){return h.css(t,{display:0===s[e].opacity?"none":"",zIndex:""})}),l(n.target),n.$update(n.target),h.fastdom.flush()},h.noop)}}}],args:"target",props:{target:Boolean,selActive:Boolean},data:{target:null,selActive:!1,attrItem:"uk-filter-control",cls:"uk-active",animation:250},computed:{toggles:{get:function(t,e){t.attrItem;return h.$$("["+this.attrItem+"],[data-"+this.attrItem+"]",e)},watch:function(){this.updateState()}},target:function(t,e){var i=t.target;return h.$(i,e)},children:{get:function(){return h.toNodes(this.target&&this.target.children)},watch:function(t,e){!function(t,e){return t.length===e.length&&t.every(function(t){return~e.indexOf(t)})}(t,e)&&this.updateState()}}},events:[{name:"click",delegate:function(){return"["+this.attrItem+"],[data-"+this.attrItem+"]"},handler:function(t){t.preventDefault(),this.apply(t.current)}}],connected:function(){var e=this;if(this.updateState(),!1!==this.selActive){var i=h.$$(this.selActive,this.$el);this.toggles.forEach(function(t){return h.toggleClass(t,e.cls,h.includes(i,t))})}},methods:{apply:function(t){this.setState(n(t,this.attrItem,this.getState()))},getState:function(){var i=this;return this.toggles.filter(function(t){return h.hasClass(t,i.cls)}).reduce(function(t,e){return n(e,i.attrItem,t)},{filter:{"":""},sort:[]})},setState:function(a,t){var o=this;void 0===t&&(t=!0),a=h.assign({filter:{"":""},sort:[]},a),h.trigger(this.$el,"beforeFilter",[this,a]);var s=this.children;this.toggles.forEach(function(t){return h.toggleClass(t,o.cls,!!function(t,e,i){var n=i.filter;void 0===n&&(n={"":""});var r=i.sort,a=r[0],o=r[1],s=p(t,e),c=s.filter;void 0===c&&(c="");var u=s.group;void 0===u&&(u="");var f=s.sort,l=s.order;void 0===l&&(l="asc");return h.isUndefined(f)?u in n&&c===n[u]||!c&&u&&!(u in n)&&!n[""]:a===f&&o===l}(t,o.attrItem,a))});function e(){var e=function(t){var e=t.filter,i="";return h.each(e,function(t){return i+=t||""}),i}(a);s.forEach(function(t){return h.css(t,"display",e&&!h.matches(t,e)?"none":"")});var t=a.sort,i=t[0],n=t[1];if(i){var r=function(t,i,n){return h.assign([],t).sort(function(t,e){return h.data(t,i).localeCompare(h.data(e,i),void 0,{numeric:!0})*("asc"===n||-1)})}(s,i,n);h.isEqual(r,s)||r.forEach(function(t){return h.append(o.target,t)})}}t?this.animate(e).then(function(){return h.trigger(o.$el,"afterFilter",[o])}):(e(),h.trigger(this.$el,"afterFilter",[this]))},updateState:function(){var t=this;h.fastdom.write(function(){return t.setState(t.getState(),!1)})}}};function p(t,e){return h.parseOptions(h.data(t,e),["filter"])}function n(t,e,i){var n=p(t,e),r=n.filter,a=n.group,o=n.sort,s=n.order;return void 0===s&&(s="asc"),(r||h.isUndefined(o))&&(a?r?(delete i.filter[""],i.filter[a]=r):(delete i.filter[a],(h.isEmpty(i.filter)||""in i.filter)&&(i.filter={"":r||""})):i.filter={"":r||""}),h.isUndefined(o)||(i.sort=[o,s]),i}return"undefined"!=typeof window&&window.UIkit&&window.UIkit.component("filter",t),t});