開始接觸menu控件
感覺怎麼這麼別扭啊
首先說數據訪問部分
為了所謂的provider pattern
一層一層的包裝
而且都是些黑盒子
雖然概念是挺先進
結構好象也很清楚
但還是讓我覺的迷迷糊糊
至於嘛
只是想做幾個數據驅動的menu而已
還有那個前台的menu類
那麼多的Properties
尤其想到menu類也是個黑盒子
一點都不知道
它生成的xhtml會是什麼樣的
而我只有一點點css知識而已
想到這裡連嘗試的欲望都沒了
還不如自己動手親自寫一個menu呢
網上好象有好多現成的javascript類
比如這個
Div_css 結構的
雖然沒有 控件那麼漂亮
可也很是實用
至少都是透明的
不過後台有點麻煩
當時的想法是
設計一個類sitemap
從數據庫裡讀導航信息
然後存到一個dataset中
在application_start 事件處理函數中 實例化一個sitemap 和一個sqlCachedependency
插入到cache中
一個dependency的回調函數
以更新cache中的數據
從cache中提取數據生成menu
這樣一來可以想象default
master的代碼的代碼會亂七八糟
非但不太容易寫
寫好的代碼也不太容易復用
而且還有關於cache的很多問題
肯定有其他辦法
好多東西我都沒有接觸過
不過現在想想 provider pattern還是不錯
一層api連接表示層
一層api連接數據訪問層
被迫學習menu類
希望它不要太讓人意外
終於明白為什麼開源讓那麼多人激動
開放透明啊!
/**//*****************************************************
* ypSlideOutMenu
*
/
/
*
* a nice little script to create exclusive
slide
out
* menus for ns
ns
mozilla
opera
ie
ie
on
* mac and win
I
ve got no linux or unix to test on but
* it should(?) work
*
* Revised:
*
/
/
: added
hideAll()
*
/
/
: added
writeCSS() to support more
*
than
menus
*
*
youngpup
*****************************************************/
ypSlideOutMenu
Registry = []
ypSlideOutMenu
aniLen =
ypSlideOutMenu
hideDelay =
ypSlideOutMenu
minCPUResolution =
// constructor
function ypSlideOutMenu(id
dir
left
top
width
height)
{
this
ie = document
all ?
:
this
ns
= document
layers ?
:
this
dom = document
getElementById ?
:
if (this
ie || this
ns
|| this
dom)
{
this
id = id
this
dir = dir
this
orientation = dir ==
left
|| dir ==
right
?
h
:
v
this
dirType = dir ==
right
|| dir ==
down
?
:
+
this
dim = this
orientation ==
h
? width : height
this
hideTimer = false
this
aniTimer = false
this
open = false
this
over = false
this
startTime =
this
gRef =
ypSlideOutMenu_
+id
eval(this
gRef+
=this
)
ypSlideOutMenu
Registry[id] = this
var d = document
var strCSS =
;
strCSS +=
#
+ this
id +
Container { visibility:hidden;
strCSS +=
left:
+ left +
px;
strCSS +=
top:
+ top +
px;
strCSS +=
overflow:hidden; z
index:
; }
strCSS +=
#
+ this
id +
Container
#
+ this
id +
Content { position:absolute;
strCSS +=
width:
+ width +
px;
strCSS +=
height:
+ height +
px;
strCSS +=
clip:rect(
+ width +
+ height +
);
strCSS +=
}
this
css = strCSS;
this
load()
}
}
ypSlideOutMenu
writeCSS = function()
{
document
writeln(
<style type=
text/css
>
);
for (var id in ypSlideOutMenu
Registry)
{
document
writeln(ypSlideOutMenu
Registry[id]
css);
}
document
writeln(
</style>
);
}
ypSlideOutMenu
prototype
load = function()
{
var d = document
var lyrId
= this
id +
Container
var lyrId
= this
id +
Content
var obj
= this
dom ? d
getElementById(lyrId
) : this
ie ? d
all[lyrId
] : d
layers[lyrId
]
if (obj
) var obj
= this
ns
? obj
layers[lyrId
] : this
ie ? d
all[lyrId
] : d
getElementById(lyrId
)
var temp
if (!obj
|| !obj
) window
setTimeout(this
gRef +
load()
)
else
{
ntainer = obj
nu = obj
this
style = this
ns
? nu : nu
style
this
homePos = eval(
+ this
dirType + this
dim)
this
outPos =
this
accelConst = (this
outPos
this
homePos) / ypSlideOutMenu
aniLen / ypSlideOutMenu
aniLen
// set event handlers
if (this
ns
) nu
captureEvents(Event
MOUSEOVER | Event
MOUSEOUT);
nu
onmouseover = new Function(
ypSlideOutMenu
showMenu(
+ this
id +
)
)
nu
onmouseout = new Function(
ypSlideOutMenu
hideMenu(
+ this
id +
)
)
//set initial state
this
endSlide()
}
}
ypSlideOutMenu
showMenu = function(id)
{
var reg = ypSlideOutMenu
Registry
var obj = ypSlideOutMenu
Registry[id]
if (ntainer)
{
obj
over = true
for (menu in reg) if (id != menu) ypSlideOutMenu
hide(menu)
if (obj
hideTimer)
{ reg[id]
hideTimer = window
clearTimeout(reg[id]
hideTimer) }
if (!obj
open && !obj
aniTimer) reg[id]
startSlide(true)
}
}
ypSlideOutMenu
hideMenu = function(id)
{
var obj = ypSlideOutMenu
Registry[id]
if (ntainer)
{
if (obj
hideTimer) window
clearTimeout(obj
hideTimer)
obj
hideTimer = window
setTimeout(
ypSlideOutMenu
hide(
+ id +
)
ypSlideOutMenu
hideDelay);
}
}
ypSlideOutMenu
hideAll = function()
{
var reg = ypSlideOutMenu
Registry
for (menu in reg)
{
ypSlideOutMenu
hide(menu);
if (menu
hideTimer) window
clearTimeout(menu
hideTimer);
}
}
ypSlideOutMenu
hide = function(id)
{
var obj = ypSlideOutMenu
Registry[id]
obj
over = false
if (obj
hideTimer) window
clearTimeout(obj
hideTimer)
obj
hideTimer =
if (obj
open && !obj
aniTimer) obj
startSlide(false)
}
ypSlideOutMenu
prototype
startSlide = function(open)
{
this[open ?
onactivate
:
ondeactivate
]()
this
open = open
if (open) this
setVisibility(true)
this
startTime = (new Date())
getTime()
this
aniTimer = window
setInterval(this
gRef +
slide()
ypSlideOutMenu
minCPUResolution)
}
ypSlideOutMenu
prototype
slide = function()
{
var elapsed = (new Date())
getTime()
this
startTime
if (elapsed > ypSlideOutMenu
aniLen) this
endSlide()
else
{
var d = Math
round(Math
pow(ypSlideOutMenu
aniLen
elapsed
) * this
accelConst)
if (this
open && this
dirType ==
) d =
d
else if (this
open && this
dirType ==
+
) d =
d
else if (!this
open && this
dirType ==
) d =
this
dim + d
else d = this
dim + d
this
moveTo(d)
}
}
ypSlideOutMenu
prototype
endSlide = function()
{
this
aniTimer = window
clearTimeout(this
aniTimer)
this
moveTo(this
open ? this
outPos : this
homePos)
if (!this
open) this
setVisibility(false)
if ((this
open && !this
over) || (!this
open && this
over))
{
this
startSlide(this
over)
}
}
ypSlideOutMenu
prototype
setVisibility = function(bShow)
{
var s = this
ns
? ntainer : ntainer
style
s
visibility = bShow ?
visible
:
hidden
}
ypSlideOutMenu
prototype
moveTo = function(p)
{
this
style[this
orientation ==
h
?
left
:
top
] = this
ns
? p : p +
px
}
ypSlideOutMenu
prototype
getPos = function(c)
{
return parseInt(this
style[c])
}
ypSlideOutMenu
prototype
onactivate = function()
{ }
ypSlideOutMenu
prototype
ondeactivate = function()
{ }
From:http://tw.wingwit.com/Article/program/net/201311/12693.html