This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A set function works in development environment. | |
*/ | |
function set(vari, value) { | |
if (ENV === 'dev') { | |
vari = value; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"lint-legacy": "files=$(git diff --cached --name-only | grep -v '.jsx$' | grep '.js$' | tr '\\n' ' '); if [[ -n \"$files\" ]]; then eslint --config ./.eslintrc.legacy.json --quiet $files || (git reset HEAD; exit 1); else exit 0; fi", | |
"lint-base": "files=$(git diff --cached --name-only | grep '.jsx$' | tr '\\n' ' '); if [[ -n \"$files\" ]]; then eslint --config ./.eslintrc.base.json --quiet $files || (git reset HEAD; exit 1); else exit 0; fi", | |
"lint": "npm run lint-legacy && npm run lint-base", | |
"lint-all": "(eslint --config ./.eslintrc.base.json --ext .jsx --quiet ./) && (eslint --config ./.eslintrc.legacy.json --ext .js --quiet ./)", | |
"build": "gulp build" | |
}, | |
"pre-commit": [ | |
"lint" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Stop propagation behavior for scroll of the element but body. | |
* Compatibility: IE9+ | |
* Ref: | |
* - http://stackoverflow.com/questions/5802467/prevent-scrolling-of-parent-element#answer-16324762 | |
* - https://developer.mozilla.org/en-US/docs/Web/Events/wheel | |
*/ | |
;(function ($) { | |
$.fn.scrollable = function () { | |
this.on('wheel', function (event) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env bash | |
# MIT © Sindre Sorhus - sindresorhus.com | |
# git hook to run a command after `git pull` if a specified file was changed | |
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`. | |
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | |
check_run() { | |
echo "$changed_files" | grep --quiet "$1" && eval "$2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* closestDescendant | |
* An jQuery function to get the closest descendant element which matches the specified selector. | |
* The search strategy is breadth-first. | |
*/ | |
;(function () { | |
$.fn.closestDescendant = function (selector) { | |
var $elem = $(); | |
this.each(function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Transfrom the keys of an object by an filter object, then return a new object. | |
* ToDo: support deep transforming. | |
*/ | |
function transKeys(src, filter) { | |
var dest = {}; | |
var keys = Object.keys(filter); | |
for (var p in src) { | |
if (src.hasOwnProperty(p)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add `:tabbable` selector. (From jQuer UI) | |
* focusable: https://gist.github.com/Alex1990/f086a23bca98672486ca | |
*/ | |
$.extend($.expr[':'], { | |
tabbable: function(element) { | |
var tabIndex = $(element).attr('tabindex'); | |
var hasTabIndex = tabIndex != null; | |
return (!hasTabIndex || tabIndex > 0) && $.expr[':'].focusable(element); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add `:focusable` selector. (From jQuery UI) | |
*/ | |
$.extend($.expr[':'], { | |
focusable: function(element) { | |
var hasTabIndex = $.attr(element, 'tabindex') != null; | |
var nodeName = element.nodeName.toLowerCase(); | |
return (/^input|textarea|select|button$/.test(nodeName) | |
? !element.disabled | |
: ('a' === nodeName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the current active element safely. | |
* Ref: https://github.com/jquery/jquery-ui/blob/2b84531ae9331f60e4d739fabca6d78abde89ae1/ui/safe-active-element.js | |
*/ | |
function safeActiveElement(doc) { | |
doc = doc || document; | |
var activeElement; | |
// Support: IE 9 only | |
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the scorllbar's width. | |
* Note: This script only works on the default zoom level. | |
* Ref: https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/js/modal.js#L277-L284 | |
*/ | |
function scrollbarWidth() { | |
var scrollDiv = document.createElement('div'); | |
scrollDiv.style.cssText = 'position:absolute;left:-9999px;width:50px;height:50px;overflow:scroll;'; | |
document.body.appendChild(scrollDiv); | |
var width = scrollDiv.offsetWidth - scrollDiv.clientWidth; |