Skip to content

Instantly share code, notes, and snippets.

View radist2s's full-sized avatar

Alex Batalov radist2s

  • Georgia, Tbilisi
View GitHub Profile
@radist2s
radist2s / resolved.js
Last active August 29, 2015 13:56
Return only resolved $.Deferred objects.
$.resolved = function () {
var defers = arguments,
defersResolvedData = [],
alwaysCount = 0
var resolvedDeferWrapper = $.Deferred()
var always = function checkQueue() {
if (++alwaysCount === defers.length) {
resolvedDeferWrapper.resolveWith($, defersResolvedData)
@radist2s
radist2s / gulp-less-sourcemap-config.js
Created May 7, 2014 19:19
Gulpfile for LESS compilation with external sourcemap file support
var gulp = require('gulp');
var less = require('gulp-less');
var path = require('path');//
var fs = require('fs');
var ensureDirectory = function (filepath) {
var dir = path.dirname(filepath),
cmd,
existsSync = fs.existsSync || path.existsSync;
if (!existsSync(dir)) {
@radist2s
radist2s / ready-checker.js
Created May 20, 2014 17:30
Simple ready checker (simple deferred) + Dom ready Checker
var ReadyChecker = (function () {
/**
* Simple Deferred
* @param {Function} readyCheckerResolver
* @param {Function} [callback]
* @constructor
*/
function ReadyChecker (readyCheckerResolver, callback) {
this.onReady(callback)
@radist2s
radist2s / require-js-build.js
Created June 9, 2014 10:36
NodeJS build RequireJS app
var requirejs = require('requirejs');
// Build config file. See example in https://github.com/jrburke/r.js/blob/master/build/example.build.js
var jsBuildFile = '../../static/js/app/build.js'
try {
var buildConfig = eval(
String(fs.readFileSync(jsBuildFile))
)
}
@radist2s
radist2s / affix-it.js
Last active August 29, 2015 14:03
Affixed header
/* jQuery throttle https://github.com/cowboy/jquery-throttle-debounce */
(function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this);
;
(function ($) {
var $window
$(function () {
$window = window.$window || $(window)
})
@radist2s
radist2s / transform-property-name.js
Last active August 29, 2015 14:05
Get style transform property name
var transformStylePropertyName
window.getTransformStyleProperty = function getTransformStyleProperty() {
if (transformStylePropertyName !== undefined) {
return transformStylePropertyName
}
var detectedTransform,
el = document.createElement('transformdetector'),
transforms = [
@radist2s
radist2s / model-extend.js
Created October 9, 2014 14:12
Backbone Model previousAttributes() delta
Backbone.Model.prototype.set = function(key, val, options) {
var attr, attrs, unset, changes, silent, changing, prev, current;
if (key == null) return this;
// Handle both `"key", value` and `{key: value}` -style arguments.
if (typeof key === 'object') {
attrs = key;
options = val;
} else {
(attrs = {})[key] = val;
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@radist2s
radist2s / bind.js
Created April 5, 2015 21:01
Function.prototype.bind polyfill with underscore _.bind
if (!Function.prototype.bind) {
Function.prototype.bind = function () {
return _.bind.apply(_, [this].concat(_.toArray(arguments)))
}
}
@radist2s
radist2s / better-afterlag.js
Created April 11, 2015 08:36
Better Afterlag. Little fork of https://github.com/iserdmi/afterlag-js . Written by using requestAnimationFrame instead setInterval for better results.
/**
* BetterAfterlag 1.0.0 — Plugin for tracking page load lags.
* Author: Alex Batalov
* Based on Afterlag Plugin (https://github.com/iserdmi/afterlag-js) of Sergey Dmitriev (serdmi.com). Licensed MIT.
**/
;(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], function () {
return (root.Afterlag = factory());
});