UNPKG

vuikit

Version:

A responsive Vue UI library for web site interfaces based on UIkit

112 lines (107 loc) 3.34 kB
/** * Vuikit 0.8.10 * (c) 2018 Miljan Aleksic * @license MIT **/ /* Substantial part of the code is adapted from UIkit, Copyright (c) 2013-2018 YOOtheme GmbH, getuikit.com */ import { apply } from '../util/vue'; import { ready } from '../util/dom'; import { fastdom } from '../util/fastdom'; import { on, createEvent } from '../util/event'; import { includes, assign, isPlainObject } from '../util/lang'; var DATA = '_vk_fastdom_data'; var FRAMES = '_vk_fastdom_frames'; var scroll = 0; var instances = []; if (typeof window !== 'undefined') { on(window, 'load resize', function () { return instances.forEach(function (i) { return i.fastdomUpdate(); }); } ); on(window, 'scroll', function (e) { e.dir = scroll <= window.pageYOffset ? 'down' : 'up'; e.scrollY = scroll = window.pageYOffset; instances.forEach(function (inst) { return inst.fastdomUpdate(e); }); }); } var fastdom$1 = { methods: { fastdomUpdate: function fastdomUpdate (e, parents) { if ( parents === void 0 ) parents = false; e = createEvent(e || 'update'); var instance = this; if (parents) { do { if (instance._fastdom_ready) { instance._fastdomUpdate(e); } instance = instance.$parent(); } while (instance) } else { apply(instance, function (instance) { if (instance._fastdom_ready) { instance._fastdomUpdate(e); } }); } }, _fastdomUpdate: function _fastdomUpdate (e) { var this$1 = this; e = createEvent(e || 'update'); var type = e.type; var updates = this.$options.fastdom; var ref = this[FRAMES]; var reads = ref.reads; var writes = ref.writes; if (!updates) { return } updates.forEach(function (ref, i) { var read = ref.read; var write = ref.write; var events = ref.events; if (type !== 'update' && !includes(events, type)) { return } if (read && !includes(fastdom.reads, reads[i])) { reads[i] = fastdom.read(function () { var result = read.call(this$1, this$1[DATA], e); if (result === false && write) { fastdom.clear(writes[i]); delete writes[i]; } else if (isPlainObject(result)) { assign(this$1[DATA], result); } delete reads[i]; }); } if (write && !includes(fastdom.writes, writes[i])) { writes[i] = fastdom.write(function () { write.call(this$1, this$1[DATA], e); delete writes[i]; }); } }); } }, created: function created () { this[DATA] = {}; this[FRAMES] = { reads: {}, writes: {} }; instances.push(this); }, mounted: function mounted () { var this$1 = this; this._fastdom_ready || ready(function () { var hook = this$1.$options.domReady; hook && hook.call(this$1); this$1._fastdom_ready = true; this$1._fastdomUpdate(); }); this._fastdomUpdate(); }, beforeDestroy: function beforeDestroy () { var this$1 = this; var index = instances.indexOf(instances.filter(function (inst) { return inst === this$1; })[0]); instances.splice(index, 1); } } export default fastdom$1;