Skip to content

Instantly share code, notes, and snippets.

View 6174's full-sized avatar

Marc Chen 6174

View GitHub Profile
@6174
6174 / arrayUtil.js
Created August 22, 2013 12:12
array util.js
*
jQuery array utils - 0.1
http://code.google.com/p/jquery-utils/
(c) Maxime Haineault <[email protected]>
http://haineault.com
MIT License (http://www.opensource.org/licenses/mit-license.php
*/
@6174
6174 / throttle1.js
Created August 21, 2013 09:01
throttle 函数啦 *_*
/**
* 版本1
* Throttles a call to a method based on the time between calls.
* @param {Function} fn The function call to throttle.
* @param {Object} [context] context fn to run
* @param {Number} [ms] The number of milliseconds to throttle the method call.
* Passing a -1 will disable the throttle. Defaults to 150.
* @return {Function} Returns a wrapped function that calls fn throttled.
* @member KISSY
*/
@6174
6174 / reRender.js
Last active December 21, 2015 10:19
mobile web 下面强制浏览器重渲染页面。 // 这种问题一般出现在动态生成的html当中, 如果这部分动态生成的一开始就被隐藏, 那么以后出现的时候不会被浏览器渲染。
/**
* web 浏览器有这样的一类问题:
* 当某些内容被隐藏, 过一段时间需要被显示 显示出来, 这个时候可能导致浏览器不会渲染被隐藏
* 的内容, 可以通过旋转屏幕等方式强制浏览器重新渲染页面, 下面是一个比较笨的解决方法。 求更好的解决方法
*/
function reRender(){
document.body.style.display = 'none';
setTimeout(function(){
document.body.style.display = 'block';
}, 0);
@6174
6174 / socket.io.sessionID.js
Created August 17, 2013 03:31
set session id to socket in nodejs
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
@6174
6174 / gruntfile.js
Created August 16, 2013 01:58
a sample grunt file
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
/**
*--livescripts
*/
livescript: {
src: {
@6174
6174 / html-decode.js
Created August 14, 2013 08:42
html decode and encode function
function html_encode(str)
{
var s = "";
if (str.length == 0) return "";
s = str.replace(/&/g, "&gt;");
s = s.replace(/</g, "&lt;");
s = s.replace(/>/g, "&gt;");
s = s.replace(/ /g, "&nbsp;");
s = s.replace(/\'/g, "&#39;");
s = s.replace(/\"/g, "&quot;");
@6174
6174 / execCommand.html
Created August 12, 2013 05:50
execCommand兼容性测试脚本
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script>
window.onload=function (){
function getCommandList(){
return {'2D-Position':true,
'absolutePosition':true,
@6174
6174 / isArrayLike.js
Created August 11, 2013 09:48
isArrayLike
function isArrayLike(obj) {
if (obj && typeof obj === "object") {
var n = obj.length
if (+n === n && !(n % 1) && n >= 0) {//检测length属性是否为非负整数
try {
if ({}.propertyIsEnumerable.call(obj, 'length') === false) {//如果是原生对象
return Array.isArray(obj) || /^\s?function/.test(obj.item || obj.callee)
}
return true;
} catch (e) {//IE的NodeList直接抛错
@6174
6174 / whichTransitionEvent.js
Created August 8, 2013 08:40
transitionEnd s事件兼容
function whichTransitionEvent(){
var t;
var el = document.createElement('fakeelement');
var transitions = {
'transition':'transitionend',
'OTransition':'oTransitionEnd',
'MozTransition':'transitionend',
'WebkitTransition':'webkitTransitionEnd'
}
@6174
6174 / isElInDom.js
Created August 7, 2013 08:03
判断元素节点是否还在dom中
//from api
document.contains(someReferenceToADomElement);
//from job
var elementInDocument = function(element) {
while (element = element.parentNode) {
if (element == document) {
return true;
}
}