2009年7月23日 星期四

Pack your source codes by git archive (使用 git archive 打包程式碼)

程式碼若有使用 git 管理,要打包散佈出去的使用,可以使用 archive 來做。

[查出要打包的 tree-ish]
> git reflog
af8283a... HEAD@{0}: commit: First release!
61e0cf6... HEAD@{1}: pull : Fast forward
d5e17c4... HEAD@{2}: commit: Modify files ...
f20638e... HEAD@{3}: pull : Fast forward

[執行 git archive 指令]
> git archive --prefix myCode/ af8283a | gzip > myCode.tar.gz

[注意 umask 的問題]
umask 會影響打包的程式碼解開後的檔案或目錄權限問題。可調整 git config 中的 tar.umask 設定

2009年7月9日 星期四

Check/uncheck multiple checkboxs by javascript (使用 javascript 一次選取/取消選取多個 checkboxs)

如何使用 javascript 一次選取/取消選取多個 checkboxs?
[HTML]
假設有一段 input type 為 checkbox 的 html
...
<input name="checkRow" type="checkbox"> Row 1
<input name="checkRow" type="checkbox"> Row 2
<input name="checkRow" type="checkbox"> Row 3
<input name="checkRow" type="checkbox"> Row 4
<input name="checkRow" type="checkbox"> Row 5
<input id="selectButton" value="SELECT ALL" type="button" onclick="selectAll();">
...

[JavaScript function]
再 HTML 中加入一個 javascript function
<script type="text/javascript">
function selectAll() {
var checks = document.getElementsByName('checkRow');
var len = checks.length;
var buttonText = document.getElementById('selectButton').value;
if (buttonText == 'SELECT ALL') {
for (i=0;i<len;i++) {
checks[i].checked=true;
}
document.getElementById('selectButton').value='UN-SELECT ALL';
} else {
for (i=0;i<len;i++) {
checks[i].checked=false;
}
document.getElementById('selectButton').value='SELECT ALL';
}
}
</script>