This file contains 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
-- Switch to English (Run in CLI) | |
-- defaults write NSGlobalDomain AppleLanguages "(en, ja, \"zh-Hans\", \"zh-Hant\", fr, de, es, it, pt, \"pt-PT\", nl, sv, nb, da, fi, ru, pl, ko, ar, cs, hu, tr, th, ca, hr, el, he, ro, sk, uk)" | |
-- Switch to Japanese (Run in CLI) | |
-- defaults write NSGlobalDomain AppleLanguages "(ja, en, \"zh-Hans\", \"zh-Hant\", fr, de, es, it, pt, \"pt-PT\", nl, sv, nb, da, fi, ru, pl, ko, ar, cs, hu, tr, th, ca, hr, el, he, ro, sk, uk)" |
This file contains 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
<!--[if lte IE 9]> | |
<script src="https://stringencoders.googlecode.com/svn/trunk/javascript/base64.js"></script> | |
<script> | |
if (!window.btoa) window.btoa = base64.encode; | |
if (!window.atob) window.atob = base64.decode; | |
</script> | |
<![endif]--> |
This file contains 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
# StepAction helps to get rid of nesting setTimeout | |
# | |
# Function.prototype.bind feature is used. | |
# Only support IE9+ for now | |
class StepAction | |
constructor: (@steps, @initDelay) -> | |
@_timer = null | |
@_onStep = 0 |
This file contains 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
function clearLocalStorage() { | |
var len = window.localStorage.length; | |
while (len >= 0) { | |
window.localStorage.removeItem(window.localStorage.key(len--)); | |
} | |
} |
This file contains 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
function randomsort(arr) { | |
var i = arr.length, j, tempi, tempj; | |
if ( i == 0 ) return this; | |
while ( --i ) { | |
j = Math.floor( Math.random() * ( i + 1 ) ); | |
tempi = arr[i]; | |
tempj = arr[j]; | |
arr[i] = tempj; | |
arr[j] = tempi; | |
} |
This file contains 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
//Inspired by jQuery, link: http://www.zhangsuoyong.com/?p=111 | |
function checkParent(refNode, otherNode) { | |
var parent = otherNode.parentNode; | |
try { | |
while ( parent && parent !== refNode ) { | |
parent = parent.parentNode; | |
} | |
return (parent !== refNode); | |
} catch(e) {} |
This file contains 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
<!DOCTYPE html> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Prevent additional mouse event</title> | |
</head> | |
<body> | |
<div id="ele" style="width: 300px; height: 300px; background-color: #0FF;"> | |
This is the parent element. | |
<div style="width: 200px; height: 200px; background-color: #FFF;"> |
This file contains 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
//Since in Chrome, document.body.scrollTop reflects the scroll distance, | |
//while in IE9 and Firefox, document.documentElement.scrollTop does. | |
//So this will work in either of the 3 browsers to scroll to the pos you want. | |
function scrollTo(pos) { | |
if(document.body.scrollTop){ | |
document.body.scrollTop = pos; | |
} else if(document.documentElement.scrollTop){ | |
document.documentElement.scrollTop = pos; | |
} else { | |
document.body.scrollTop = document.documentElement.scrollTop = pos; |
This file contains 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
function getElementOffset(element, property) { | |
//Calculate the actual property name | |
property = "offset"+property[0].toUpperCase()+property.slice(1).toLowerCase(); | |
if (property == "offsetLeft" || property == "offsetTop") { | |
var actualOffset = element[property]; | |
var current = element.offsetParent; | |
//Look up the node tree to add up all the offset value | |
while (current != null) { | |
actualOffset += current[property]; |
This file contains 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
//Search str in arr by either exact match or not | |
function searchArray(str, arr, exactMatch) { | |
if (exactMatch) { | |
//Search for the exact same item with str in arr | |
for (var i = 0; i < arr.length; i++) { | |
if (str == arr[i]) { | |
return true; | |
} | |
} | |
} else { |