Skip to content

Instantly share code, notes, and snippets.

@AimWhy
AimWhy / outerClick.js
Last active September 26, 2017 11:21
outside click outerclick outclick
(function (ELEMENT) {
ELEMENT.matches = ELEMENT.matches || ELEMENT.mozMatchesSelector || ELEMENT.msMatchesSelector || ELEMENT.oMatchesSelector || ELEMENT.webkitMatchesSelector
ELEMENT.closest = ELEMENT.closest || function closest (selector) {
if (!this) return null
if (this.matches(selector)) return this
return !this.parentElement ? null : this.parentElement.closest(selector)
}
ELEMENT.contains = ELEMENT.contains || function contains (elem) {
var comparison = this.compareDocumentPosition(elem)
return comparison === 0 || comparison & 16
@AimWhy
AimWhy / skeleton.html
Last active November 19, 2017 12:15
骨架屏幕,placeholder
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Skeleton Screen</title>
<style>
:root {
--card-padding: 1rem;
--card-width: 80rem;
@AimWhy
AimWhy / clock.js
Created October 16, 2018 12:18
尽量准确的时钟
function createWorker (fun) {
var blob = new Blob(['(' + fun.toString() + ')()'])
var url = window.URL.createObjectURL(blob)
return new Worker(url)
}
var clockWorker = createWorker(function () {
var adjustTimer = 1000 - Date.now() % 1000
setTimeout(function () {
self.postMessage(Date.now())
@AimWhy
AimWhy / vmMap.js
Last active September 16, 2019 10:18
线上vue组件查找snippets
function vmMapToDom(vm) {
if(vm.$el.setAttribute) {
var name = '$' + (vm.$options.name + vm._uid + '').replace(/-/g, '_');
vm.$el.setAttribute('vm' + vm._uid, name)
window[name] = vm
}
var l = vm.$children.length;
var i = 0;
while (i < l) {
vmMapToDom(vm.$children[i]);
@AimWhy
AimWhy / syncQuery_mixin.js
Last active December 17, 2018 11:31
同步query与data
function getTrue () { return true }
function getSelf (item) { return item }
export default {
data () {
return {
queryCount: 0,
queryLinq: {}
}
},
@AimWhy
AimWhy / wait_plugin.js
Created November 8, 2018 05:03
loading & progress
class VueWait {
constructor (Vue) {
this.initialized = false
this.init(Vue)
}
init (Vue) {
if (!this.initialized) {
this.stateHandler = new Vue({
data () {
@AimWhy
AimWhy / dispatch.js
Created November 8, 2018 05:14
dispatch & broadcast
function broadcast(componentName, eventName, params) {
this.$children.forEach(child => {
var name = child.$options.componentName;
if (name === componentName) {
child.$emit.apply(child, [eventName].concat(params));
} else {
broadcast.apply(child, [componentName, eventName].concat([params]));
}
});
@AimWhy
AimWhy / router.js
Created November 8, 2018 08:24
vue router middleware
import RoutesConfigArr from './routes'
import commonRoutesArr from './common'
import { recordChannel } from './hooks'
function nextFactory (context, middlewareArr, index) {
const subsequentMiddleware = middlewareArr[index]
if (!subsequentMiddleware) {
return context.next
@AimWhy
AimWhy / Vue_set2_get2.js
Created November 8, 2018 09:54
set2 get2 Vue
Vue.prototype.$get2 = function (obj, key, def, sp = '.') {
var p = 0
var keys = (typeof key === 'string') ? key.split(sp) : key
var len = keys.length
while (obj && p < len) {
obj = obj[keys[p++]]
}
return (obj === undefined || p < len) ? def : obj
}
@AimWhy
AimWhy / demo.vue
Last active November 8, 2018 10:21
layout vue
``` App.vue
<template>
<component :is="layout" :layout.sync="layout">
<router-view />
</component>
</template>
<script>
export default {
name: `App`,