UNPKG

vueisotope

Version:
1 lines 4.19 kB
"use strict";function _toConsumableArray(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e<t.length;e++)i[e]=t[e];return i}return Array.from(t)};!function(){function t(t,e){function i(t,e){if(t.data){var i=t.data.staticClass?t.data.staticClass+" ":"";t.data.staticClass=i+e}}function n(t){return t.__underlying_element}var r={options:{type:Object,"default":{layoutMode:"masonry",masonry:{gutter:10}}},itemSelector:{type:String,"default":"item"},list:{type:Array,required:!0}},o={name:"isotope",props:r,render:function(t){var e=this,n={},r=this.prevChildren=this.children,o=this.$slots["default"]||[],s=this.children=[],l=this.removedIndex=[];o.forEach(function(t){return i(t,e.itemSelector)});for(var a=0;a<o.length;a++){var u=o[a];if(u.tag)if(null!=u.key&&0!==String(u.key).indexOf("__vlist"))s.push(u),n[u.key]=u;else{var f=u.componentOptions,c=f?f.Ctor.options.name||f.tag||"":u.tag;console.log("Warning template error: isotope children must be keyed: <"+c+">")}}var h=this.displayChildren=[].concat(s);if(r)for(var d=0;d<r.length;d++){var p=r[d];n[p.key]||(h.splice(d,0,p),l.push(d))}return t("div",null,h)},mounted:function(){var i=this,r=t.merge({},this.compiledOptions),o=function(e){t.forOwn(e,function(t,r){e[r]=function(e){var r=n(e);return t.call(i,r.vm,r.index)}})};o(r.getSortData),o(r.getFilterData),this._isotopeOptions=r,r.filter&&(r.filter=this.buildFilterFunction(r.filter)),this.$nextTick(function(){i.link(),i.listen();var t=new e(i.$el,r);t._requestUpdate=function(){t._willUpdate||(t._willUpdate=!0,i.$nextTick(function(){t.arrange(),t._willUpdate=!1}))},i.iso=t})},beforeDestroy:function(){t.forEach(this._listeners,function(t){t()}),this._filterlistener&&this._filterlistener(),this.iso=null},beforeUpdate:function(){this._oldChidren=Array.prototype.slice.call(this.$el.children)},updated:function(){var e=this;if(this.iso){var i=[].concat(_toConsumableArray(this.$el.children)),n=t.difference(i,this._oldChidren),r=this.removedIndex.map(function(t){return e.$el.children[t]});this.cleanupNodes(),this.link(),(r.length||n.length)&&(this.listen(),this.iso.remove(r),this.iso.insert(n),this.iso._requestUpdate())}},methods:{cleanupNodes:function(){var t=this;this.removedIndex.reverse(),this.removedIndex.forEach(function(e){return t._vnode.children.splice(e,1)})},link:function(){var t=this,e=this.$slots["default"]||[];e.forEach(function(e,i){var n=e.elm;n&&(n.__underlying_element={vm:t.list[i],index:i})})},listen:function(){var e=this;this._listeners=t(this.compiledOptions.getSortData).map(function(i){return t.map(e.list,function(t,n){return e.$watch(function(){return i(t)},function(){e.iso.updateSortData(),e.iso._requestUpdate()})})}).flatten().value()},sort:function s(e){var s=e;t.isString(e)&&(s={sortBy:e}),this.arrange(s),this.$emit("sort",e)},buildFilterFunction:function(e){var i=this,n=this._isotopeOptions.getFilterData[e];return this._filterlistener=this.$watch(function(){return t.map(i.list,function(t,n){return i.options.getFilterData[e](t,n)})},function(){i.iso._requestUpdate()}),n},filter:function l(t){var l=this.buildFilterFunction(t);this.arrange({filter:l}),this.$emit("filter",t)},unfilter:function(){this.arrange({filter:function(){return!0}}),this.$emit("filter",null)},layout:function a(e){var a=e;t.isString(e)&&(a={layoutMode:e}),this.arrange(a),this.$emit("layout",a)},arrange:function(t){this.iso.arrange(t),this.$emit("arrange",t)},shuffle:function(){this.iso.shuffle(),this.$emit("shuffle"),this.$emit("sort",null)},getFilteredItemElements:function(){return this.iso.getFilteredItemElements()},getElementItems:function(){return this.iso.getElementItems()}},computed:{compiledOptions:function(){var e=t.merge({},this.options,{itemSelector:"."+this.itemSelector,isJQueryFiltering:!1});return t.forOwn(e.getSortData,function(i,n){t.isString(i)&&(e.getSortData[n]=function(t){return t[i]})}),e}}};return o}if(typeof exports=="object"){var e=require("lodash"),i=require("isotope-layout");module.exports=t(e,i)}else if("function"==typeof define&&define.amd)define(["lodash","Isotope"],function(e,i){return t(e,i)});else if(window.Vue&&window._&&window.Isotope){var n=t(window._,window.Isotope);Vue.component("isotope",n)}}();