原本這程式會分別出兩張報表,新的需求是要併成一張,
看到程式的第一個念頭就是「重構」,
請記住!「重構」不是「重寫」,
我們是懷著讓原本程式更容易閱讀的心情再做「重構」的。
影片不是很清楚,程式不是很容易閱讀,純粹紀錄「重構」的感覺,
如果你也進行過「重構」工作,我想你會懂我的。
/*
不曉得有沒有人想過像 Konami 那種,按 "上上下下左右左右BA" 後,
會觸發某些事件的功能,如何撰寫,以下是我的實作,除了特定的 Konami 按鍵外,
也允許自訂自己的按鍵事件序列的測試方法,
整個程式的概念,是註冊 document 的 keyup 事件,並紀錄下最近 10 次的按鍵內容,
並提供一個 RegisterTest 方法,由註冊者自行決定目前按下的按鍵是否符合觸發的條件,
若符合要觸發什麼事件; RegisterTest 會先把這兩個 function 紀錄下來,
等到畫面上的 kepup 事件產生時,逐一呼叫 testFun , testFun 回傳 true ,
就呼叫 triggerFun 執行當初註冊的觸發事件。
這個程式需要 jQuery ,
另外這個陽春的版本不提供組合鍵的處理,當然稍微修改一下也可以支援組合鍵。
*/
var HotKeyControler = {
MAX_QUEUE: 10, /* 保留最後 10 個鍵盤事件 */
testFuns: new Object(),
triggerFuns: new Object(),
KeyQueue: new Array,
Keyup: function(event) {
HotKeyControler.KeyQueue.push(event.keyCode);
if (HotKeyControler.KeyQueue.length > HotKeyControler.MAX_QUEUE) {
HotKeyControler.KeyQueue.shift();
}
for (var key in HotKeyControler.testFuns) {
if (HotKeyControler.testFuns[key](event, HotKeyControler.KeyQueue)) {
HotKeyControler.triggerFuns[key]();
}
}
},
/* 函數名稱:註冊熱鍵
* 參數說明:(唯一鍵值, 測試function, 觸發function)
* 說 明:提供註冊熱鍵的方法,提供目前畫面被按下的按鍵佇列,供AP自行判斷是否觸發執行事件
*/
RegisterTest: function(key, testFun, triggerFun) {
if (typeof(testFun)=='function' && typeof(triggerFun)=='function') {
HotKeyControler.testFuns[key] = testFun;
HotKeyControler.triggerFuns[key] = triggerFun;
}
}
}
$(document).ready(function(){
$(document).unbind("keyup",HotKeyControler.Keyup);
$(document).bind("keyup",HotKeyControler.Keyup);
});
/* DEMO 註冊當按下 Konami(上上下下左右左右BA)時要觸發的事件 */
HotKeyControler.RegisterTest("Konami"
,function(event,code) { /* 上上下下左右左右BA */
if (code.length!=10) return false;
if (code[0]==38 && code[1]==38 && code[2]==40 && code[3]==40 &&
code[4]==37 && code[5]==39 && code[6]==37 && code[7]==39 &&
code[8]==66 && code[9]==65) {
return true;
}
return false;
}
,function() {
alert('上上下下左右左右BA!!!');
}
);
element.style.getAttribute(styleProperty);糟糕的是,其它的 browser 不甩這種寫法,而是要這麼寫
element.style.setAttribute(styleProperty, value);
element.style.getPropertyValue(style-property)更慘的是,新舊參雜的風格時,有大量的程式需要調整、測試,在不動舊程式的情況下,
element.style.setProperty(style-property, value)
if (typeof (CSSStyleDeclaration.prototype.getAttribute) == "undefined") {
CSSStyleDeclaration.prototype.getAttribute = function (propName) {
return this.getPropertyValue(Me._changePropName(propName));
}
}
if (typeof (CSSStyleDeclaration.prototype.setAttribute) == "undefined") {
CSSStyleDeclaration.prototype.setAttribute = function (propName, value) {
this.setProperty(Me._changePropName(propName), value);
}
}
但這卻遇到一個問題,當用 get/set Property 時, propertyName 格式是和 CSS 一樣, function changePropName(propName) {
var pattern = /[A-Z]/;
var c = ("-" + (propName.match(pattern))).toLowerCase();
var s = propName.split(pattern);
var result = s[0];
if (s.length > 1) {
result += c + s[1];
}
return result;
}
function ValidatorOnLoad() {
if (typeof(Page_Validators) == "undefined")
return;
var i, val;
for (i = 0; i < Page_Validators.length; i++) {
val = Page_Validators[i];
if (typeof(val.evaluationfunction) == "string") {
eval("val.evaluationfunction = " + val.evaluationfunction + ";");
} // 略 .....
.Net 1.0 and 2.0 hybrid validator not work終於勉強找到了
Why might ASP.NET be putting JavaScript in HTML Comment blocks, not CDATA?裡面提到了關鍵字 <xhtmlConformance mode="Transitional" />
http://en.wikipedia.org/wiki/Hard_link
http://linux.vbird.org/linux_basic/0230filesystem/0230filesystem.php
http://en.wikipedia.org/wiki/NTFS_symbolic_link
http://webcache.googleusercontent.com/search?q=cache:2FHejrp9CZAJ:blog.miniasp.com/post/2011/09/17/How-to-create-NTFS-Reparse-Points-Symbolic-and-Hard-Links.aspx+&cd=2&hl=zh-TW&ct=clnk&lr=lang_zh-TW
http://jdev.tw/blog/729/vista-soft-and-hard-link
在 finder 下按 Command + k ,然後輸入 smb://yourWinServer/sharedFolderName但如果是在文件中看到的是長這樣的路徑
\\yourWinServer/sharedFolderName那就要很辛苦的把 "\" 換成 "/" 如果很多層的話那心情就會很糟。