This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+48
View File
@@ -0,0 +1,48 @@
// Directives
import Intersect from '../../directives/intersect'; // Utilities
import { consoleWarn } from '../../util/console'; // Types
import Vue from 'vue';
export default function intersectable(options) {
if (typeof window === 'undefined' || !('IntersectionObserver' in window)) {
// do nothing because intersection observer is not available
return Vue.extend({
name: 'intersectable'
});
}
return Vue.extend({
name: 'intersectable',
mounted() {
Intersect.inserted(this.$el, {
name: 'intersect',
value: this.onObserve
});
},
destroyed() {
Intersect.unbind(this.$el);
},
methods: {
onObserve(entries, observer, isIntersecting) {
if (!isIntersecting) return;
for (let i = 0, length = options.onVisible.length; i < length; i++) {
const callback = this[options.onVisible[i]];
if (typeof callback === 'function') {
callback();
continue;
}
consoleWarn(options.onVisible[i] + ' method is not available on the instance but referenced in intersectable mixin options');
}
}
}
});
}
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/mixins/intersectable/index.ts"],"names":[],"mappings":"AAAA;AACA,OAAO,SAAP,MAAsB,4BAAtB,C,CAEA;;AACA,SAAS,WAAT,QAA4B,oBAA5B,C,CAEA;;AACA,OAAO,GAAP,MAAgB,KAAhB;AAEA,eAAc,SAAU,aAAV,CAAyB,OAAzB,EAAyD;AACrE,MAAI,OAAO,MAAP,KAAkB,WAAlB,IAAiC,EAAE,0BAA0B,MAA5B,CAArC,EAA0E;AACxE;AACA,WAAO,GAAG,CAAC,MAAJ,CAAW;AAAE,MAAA,IAAI,EAAE;AAAR,KAAX,CAAP;AACD;;AAED,SAAO,GAAG,CAAC,MAAJ,CAAW;AAChB,IAAA,IAAI,EAAE,eADU;;AAGhB,IAAA,OAAO,GAAA;AACL,MAAA,SAAS,CAAC,QAAV,CAAmB,KAAK,GAAxB,EAA4C;AAC1C,QAAA,IAAI,EAAE,WADoC;AAE1C,QAAA,KAAK,EAAE,KAAK;AAF8B,OAA5C;AAID,KARe;;AAUhB,IAAA,SAAS,GAAA;AACP,MAAA,SAAS,CAAC,MAAV,CAAiB,KAAK,GAAtB;AACD,KAZe;;AAchB,IAAA,OAAO,EAAE;AACP,MAAA,SAAS,CAAE,OAAF,EAAwC,QAAxC,EAAwE,cAAxE,EAA+F;AACtG,YAAI,CAAC,cAAL,EAAqB;;AAErB,aAAK,IAAI,CAAC,GAAG,CAAR,EAAW,MAAM,GAAG,OAAO,CAAC,SAAR,CAAkB,MAA3C,EAAmD,CAAC,GAAG,MAAvD,EAA+D,CAAC,EAAhE,EAAoE;AAClE,gBAAM,QAAQ,GAAI,KAAa,OAAO,CAAC,SAAR,CAAkB,CAAlB,CAAb,CAAlB;;AAEA,cAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,YAAA,QAAQ;AACR;AACD;;AAED,UAAA,WAAW,CAAC,OAAO,CAAC,SAAR,CAAkB,CAAlB,IAAuB,wFAAxB,CAAX;AACD;AACF;;AAdM;AAdO,GAAX,CAAP;AA+BD","sourcesContent":["// Directives\nimport Intersect from '../../directives/intersect'\n\n// Utilities\nimport { consoleWarn } from '../../util/console'\n\n// Types\nimport Vue from 'vue'\n\nexport default function intersectable (options: { onVisible: string[] }) {\n if (typeof window === 'undefined' || !('IntersectionObserver' in window)) {\n // do nothing because intersection observer is not available\n return Vue.extend({ name: 'intersectable' })\n }\n\n return Vue.extend({\n name: 'intersectable',\n\n mounted () {\n Intersect.inserted(this.$el as HTMLElement, {\n name: 'intersect',\n value: this.onObserve,\n })\n },\n\n destroyed () {\n Intersect.unbind(this.$el as HTMLElement)\n },\n\n methods: {\n onObserve (entries: IntersectionObserverEntry[], observer: IntersectionObserver, isIntersecting: boolean) {\n if (!isIntersecting) return\n\n for (let i = 0, length = options.onVisible.length; i < length; i++) {\n const callback = (this as any)[options.onVisible[i]]\n\n if (typeof callback === 'function') {\n callback()\n continue\n }\n\n consoleWarn(options.onVisible[i] + ' method is not available on the instance but referenced in intersectable mixin options')\n }\n },\n },\n })\n}\n"],"sourceRoot":"","file":"index.js"}