Skip to content

Instantly share code, notes, and snippets.

View crossai-2033's full-sized avatar
😇
I may be slow to respond.

LC crossai-2033

😇
I may be slow to respond.
View GitHub Profile
<script>
/*利且window.name来做缓存库,缓存天气及新闻 最终存成的window.name格式为 key1@=val1@@127545353@;key2@=val2@@127889999@;*/
var Cache = (function() {
var cache = {
$: function(x) { return new RegExp('\\b' + x + '@=(.*?)(?=$|@;)') },
get: function(x) { this.$(x).test(window.name); return (RegExp.$1 && RegExp.$1.split('@@')[0]) || null },
set: function(x, val) {
var $ = window, __ = this.$(x), value= x + '@=' + val + '@@' + (+ new Date());
__.test($.name) ? ($.name = $.name.replace(__, value), 1) : ($.name += value + '@;')
},
/*
sessvars ver 1.01
- JavaScript based session object
copyright 2008 Thomas Frank
This EULA grants you the following rights:
Installation and Use. You may install and use an unlimited number of copies of the SOFTWARE PRODUCT.
Reproduction and Distribution. You may reproduce and distribute an unlimited number of copies of the SOFTWARE PRODUCT either in whole or in part; each copy should include all copyright and trademark notices, and shall be accompanied by a copy of this EULA. Copies of the SOFTWARE PRODUCT may be distributed as a standalone product or included with your own product.
/*!
* JavaScript preload() function
* Preload images, CSS and JavaScript files without executing them
* Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/
* Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/
* Demo: http://mathiasbynens.be/demo/javascript-preload
*/
function preload(arr) {
var i = arr.length,
@crossai-2033
crossai-2033 / gist:1133358
Created August 9, 2011 03:39
Incorrect ES5 fallbacks

Incorrect ES5 fallbacks

Over the weekend I implemented a few Array methods in plain JavaScript to avoid recently patched Rhino bugs. That got my thinking about ES5 fallback implementations in various JavaScript libs/frameworks/transpilers. I decided to compile a not-so-complete list of ES5 related discrepancies found in many of them. Differences in native vs. fallback implementations create cross-browser inconsistencies and increase the chance of usage errors. I hope this post will raise awareness of just how hard it is to follow spec (during my research I found a couple of issues in my own projects too). All library developers should to take a closer look at their code and make the small changes needed to follow the specification (especially if your code forks for native methods).

Common Issues

Most implementations suffer from the foll

@crossai-2033
crossai-2033 / js2image
Created June 24, 2013 09:55
将文本编码到图片中
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<textarea name="base64" id="base64" cols="30" rows="10"></textarea>
<script>
function encodeUTF8(str) {
@crossai-2033
crossai-2033 / Notification
Created June 27, 2013 07:51
Notification本地通知类
// Notification类
(function () {
var Notification = window.Notification,
webkitNotify = window.webkitNotifications;
function DesktopNotify(title, options) {
this._title = title;
this._options = options;
this._instance = null;
this._events = {
@crossai-2033
crossai-2033 / adapter&plugin designpattern
Last active December 19, 2015 17:48
适配器和插件架构的设计模式
var Lawnchair = function(options, callback) {
// 确保Lawnchair被作为contructor调用
if (!(this instanceof Lawnchair)) return new Lawnchair(options, callback);
// lawnchair依赖JSON
if (!JSON) throw 'JSON unavailable! Include http://www.json.org/json2.js to fix.';
// options是可选的,但callback是必须的
if (arguments.length <= 2 && arguments.length > 0) {
callback = (typeof arguments[0] === 'function') ? arguments[0] : arguments[1];
@crossai-2033
crossai-2033 / noscript
Created August 6, 2013 11:24
noscript adapter
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>NoScript</title>
</head>
<body>
<script>
document.write("<\!--");
</script>
@crossai-2033
crossai-2033 / parallax
Created August 13, 2013 03:44
Parallax Scrolling Demo
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Parallax</title>
<style>
/**
* HTML5 ✰ Boilerplate
*
* style.css contains a reset, font normalization and some base styles.
@crossai-2033
crossai-2033 / aop.js
Created August 17, 2013 05:04
simple aop..
// AOP简易模型
function Ting() {}
Thing.prototype.doSomething = function(x, y) {
var result;
return result;
};
var thing = new Thing;