Skip to content

Instantly share code, notes, and snippets.

View liximomo's full-sized avatar
👻
Hi, there.

X.L liximomo

👻
Hi, there.
View GitHub Profile
function observeStore(store, select, onChange) {
let currentState;
function handleChange() {
let nextState = select(store.getState());
if (nextState !== currentState) {
currentState = nextState;
onChange(currentState);
}
}
<html>
<body>
<div id="rte" contenteditable="true" style="height: 100%; width: 100%; outline: 0; overflow: auto"></div>
<script type="text/javascript">
document.getElementById("rte").focus();
document.body.addEventListener("paste", function(e) {
for (var i = 0; i < e.clipboardData.items.length; i++) {
if (e.clipboardData.items[i].kind == "file" && e.clipboardData.items[i].type == "image/png") {
// get the blob
var imageFile = e.clipboardData.items[i].getAsFile();
var img=new Image();
img.src="mm.jpg";
img.onload=function(){
var image = document.createElement('img');
image.src = img;
document.body.appendChild(image);
};
function uploadAudio(mp3Data){
var reader = new FileReader();
reader.onload = function(event){
var fd = new FormData();
var mp3Name = encodeURIComponent('audio_recording_' + new Date().getTime() + '.mp3');
console.log("mp3name = " + mp3Name);
fd.append('fname', mp3Name);
fd.append('data', event.target.result);
$.ajax({
type: 'POST',
@liximomo
liximomo / event-delegate.js
Last active December 17, 2016 09:33
event delegate without javascript library ie9+
function on(elSelector, eventName, selector, handler, useCapture) {
const _useCapture = useCapture === undefined ? false : useCapture;
const elements = document.querySelectorAll(elSelector);
const addEventListener = function(element) {
element.addEventListener(eventName, function(e) {
for (let target = e.target; target && target != this; target = target.parentNode) {
// loop parent nodes from the target to the delegation node
let match = false;
if (target.matches) {
match = target.matches(selector);
@liximomo
liximomo / isDescendant.js
Created September 12, 2016 04:33
check if an element is a descendant of another
var nodeContainsWorksWithTextNodes = false;
try {
var testParent = document.createElement('div'),
testText = document.createTextNode(' ');
testParent.appendChild(testText);
nodeContainsWorksWithTextNodes = testParent.contains(testText);
} catch (exc) {}
function isDescendant(parent, child, checkEquality) {
if (!parent || !child) {
git gc --prune=now
git remote prune origin
@liximomo
liximomo / gist:280829fd8836d4b855795f7d21df5103
Created September 30, 2016 02:50 — forked from toddmotto/gist:6596373
Disable Web Security in Chrome Canary to make cross-domain XHR requests (local servers obvs).
open -a Google\ Chrome\ Canary --args --disable-web-security
@liximomo
liximomo / accessible.css
Created October 15, 2016 00:48
accessible css utlis
.visually-hidden {
clip: rect(1px, 1px, 1px, 1px);
position: absolute !important;
overflow: hidden;
height: 1px;
width: 1px;
}
@liximomo
liximomo / you.md
Created November 5, 2016 11:47
文字

鱼的记忆只有七秒,(七秒),关于你的记忆只有雨中的九秒,被淋湿,视线模糊了,是雨水