Debounce a function when you want it to execute only once after a defined interval of time. If the event occurs multiple times within the interval, the interval is reset each time.
Example A user is typing into an input field and you want to execute a function, such as a call to the server, only when the user stops typing for a certain interval, such as 500ms.
alias nginx.start='brew services start nginx-full' | |
alias nginx.stop='brew services stop nginx-full' | |
alias nginx.restart='brew services restart nginx-full' | |
alias php-fpm.start="brew services start php56" | |
alias php-fpm.stop="brew services stop php56" | |
alias php-fpm.restart='brew services restart php56' | |
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating | |
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel | |
// MIT license | |
(function() { | |
var lastTime = 0; | |
var vendors = ['ms', 'moz', 'webkit', 'o']; |
// 99% done by @rauri rochford | |
// http://js1k.com/2012-love/demo/1071 | |
// i just rAF'd it. | |
// demo at http://bl.ocks.org/1823634 | |
e = [];// trails |
/** | |
* Swap the elements in an array at indexes x and y. | |
* | |
* @param (a) The array. | |
* @param (x) The index of the first element to swap. | |
* @param (y) The index of the second element to swap. | |
* @return {Array} A new array with the elements swapped. | |
*/ | |
var swapArrayElements = function (a, x, y) { | |
if (a.length === 1) return a; |
'use strict'; | |
$(function () { | |
$.ajaxSetup({ | |
error: function (jqXHR, exception) { | |
if (jqXHR.status === 0) { | |
window.alert('Not connect.n Verify Network.'); | |
} else if (jqXHR.status === 404) { | |
window.alert('Requested page not found. [404]'); | |
} else if (jqXHR.status === 500) { | |
window.alert('Internal Server Error [500].'); |
У CSS есть несколько базовых проблем, которые позволяют очень быстро отстрелить себе ногу при неправильном использовании:
-
Глобальный неймспейс – в серверном программировании все что написано в файле, в файле и остается. Все же что написано в css и js засирает глобальное пространство имен со всеми вытекающими. В JS эту проблему сейчас побороли всякими модульными системами, а вот с css сложнее. В идеальном мире это должен починить Shadow DOM и настоящие Web Components, но пока их нет единственный способ с этим бороться – следовать какой-то системе именований селекторов, которая по возможности уменьшает и исключает возможные конфликты.
-
Каскадность – если на один элемент может сработать несколько правил, то они все и сработают последовательно. Если есть элемент
h1.title
, на него сработают все правила для теговh1
и все правила для класса.title
. Так как весь html состоит из тегов, то правил которые применяются на теги без классов будут работать на все вообще.
Соответственно наз
/*global Touch: true */ | |
/*global utils: true */ | |
(function (window, utils) { | |
'use strict'; | |
var defaults = { | |
// 'longTap': true, | |
onLongTap: function () {}, | |
onStart: function () {}, |
(function (root, factory) { | |
'use strict'; | |
if (typeof define === 'function' && define.amd) { | |
define(['exports'], factory); | |
} else if (typeof exports !== 'undefined') { | |
factory(exports); | |
} else { | |
factory((root.dragscroll = {})); | |
} | |
}(this, function (exports) { |
// Shim | |
// Get Viewport dimensions in all browsers | |
// ie8+ | |
(function (window, document) { | |
'use strict'; | |
var html = document.getElementsByTagName('html')[0]; | |
var body = document.getElementsByTagName('body')[0]; | |
var objectDefineProperty = Object.defineProperty; |