Skip to content

Instantly share code, notes, and snippets.

View imyelo's full-sized avatar
🥽
Not here

yelo imyelo

🥽
Not here
View GitHub Profile
@imyelo
imyelo / waitLazyload.js
Last active August 29, 2015 13:56
wait lazyload for testing
(function () {
var count = 0;
var $lazy = $('.img-lazy-load');
var every = function () {
return _.every($lazy, function (elem) {
return elem.loaded;
});
};
$lazy.on('load', function () {
if (every()) {
@imyelo
imyelo / String.prototype.format.js
Last active August 29, 2015 13:56
String.prototype.format like python
(function (String) {
String.prototype.format = function (args) {
var copy = this + '';
var i, len;
for (i = 0, len = arguments.length; i < len; i++) {
copy = copy.replace(new RegExp("\\{" + i + "\\}", 'g'), String(arguments[i]));
}
return copy;
};
})(String);
@imyelo
imyelo / overload.js
Last active August 29, 2015 13:56
overload function in javascript
;(function (name, definition) {
// Check define
var hasDefine = typeof define === 'function',
// Check exports
hasExports = typeof module !== 'undefined' && module.exports;
if (hasDefine) {
// AMD Module or CMD Module
define(definition);
} else if (hasExports) {
@imyelo
imyelo / iscroll5-pullable.js
Last active August 29, 2015 13:56
pulldown and pullup for iScroll 5
var createPullabledScroll = function (iScroll, elem, options) {
var scroll, pullDownReady, pullUpReady;
// scope variable
pullDownReady = false;
pullUpReady = false;
// setup the scroll object
options.probeType = options.probeType || 2;
scroll = new iScroll(elem, options);
// pullDown
if (typeof options.pullDownOffset === 'number') {
@imyelo
imyelo / sortByKeyCap.js
Last active August 29, 2015 13:57
sort by key capital
var _ = (function () {
var exports = {};
exports.isArray = function (obj) {
return obj instanceof Array;
};
exports.each = function (list, func) {
var i, len;
if (exports.isArray(list)) {
for (i = 0, len = list.length; i < len; i++) {
func(list[i], i, list);
@imyelo
imyelo / whenWechatReady.js
Created March 24, 2014 09:49
better WeixinJSBridgeReady
window.whenWechatReady = (function () {
var isReady = false;
var tasks = [];
var when = function (callback) {
if (isReady) {
return callback();
}
return tasks.push(callback);
};
document.addEventListener('WeixinJSBridgeReady', function () {
@imyelo
imyelo / wait.js
Last active August 29, 2015 13:58
wait window[obj]
var wait = function (name, context) {
context = context || window;
var isReady = false;
var tasks = [];
var when = function (callback) {
if (isReady) {
return callback();
}
return tasks.push(callback);
};
@imyelo
imyelo / loadScript.js
Last active August 29, 2015 13:58
wrap or leak, sync or async
;(function () {
var loadScript = (function () {
var debug = typeof debug !== 'function' ? function (text) {
console.log(text);
} : debug;
var wrapAsync = function (url, doc, win) {
debug('load script: (safe and async) ' + url);
@imyelo
imyelo / debug.js
Last active August 29, 2015 13:58
debugger for frontend
define(function(require, exports, module) {
// Debug:
// print:
// Debug(name, [withTrace])(obj, [obj, ...])
// enable:
// Debug.enable()
// disable:
// Debug.disable()
// Debug.disable(name, [name, ...])
// only:
@imyelo
imyelo / BackendStore.js
Created May 21, 2014 10:15
BackendStore.js
define(function () {
var exports = {};
var _store = {};
var _isReady = false;
var _callback = [];
var doReady = function () {
var i, len;
if (_isReady) {