menu.js 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409
  1. // <script>
  2. _menusZIndex=2000
  3. _menusItems=new Array
  4. _globMenuCaptured=null
  5. _isColor=0
  6. _isLastUsedColor=1
  7. _isNotColor=2
  8. _currentFocus=null
  9. _mitemH=22
  10. // ================================================================================
  11. // ================================================================================
  12. //
  13. // OBJECT newMenuWidget (Constructor)
  14. //
  15. // creates a simple menu widget
  16. // This widget does not have the standard behaviour. Using
  17. // init() and getHTML() and write() is not allowed
  18. //
  19. // ================================================================================
  20. // ================================================================================
  21. function newMenuWidget(id,hideCB,beforeShowCB)
  22. // id [String] the menu id for DHTML processing
  23. // hideCB [Function - Optional] callback called when the menu is closed
  24. // beforeShowCB [Function - Optional] callback called before menu is shown
  25. // Returns [MenuWidget] the new instance
  26. {
  27. var o=newWidget(id)
  28. // Private Fields
  29. o.items=new Array
  30. o.par=null
  31. o.container=null
  32. o.currentSub=-1
  33. o.nextSub=-1
  34. o.zIndex=_menusZIndex
  35. o.hideCB=hideCB
  36. o.beforeShowCB=beforeShowCB
  37. // Public Methods
  38. o.init=MenuWidget_init
  39. o.justInTimeInit=MenuWidget_justInTimeInit
  40. o.getHTML=MenuWidget_getHTML
  41. //o.getShadowHTML=MenuWidget_getShadowHTML
  42. o.show=MenuWidget_show
  43. o.internalAdd=o.add=MenuWidget_add
  44. o.addCheck=MenuWidget_addCheck
  45. o.addSeparator=MenuWidget_addSeparator
  46. o.insert=MenuWidget_insert
  47. o.insertCheck=MenuWidget_insertCheck
  48. o.insertSeparator=MenuWidget_insertSeparator
  49. o.getItem=MenuWidget_getItem
  50. o.getItemByID=MenuWidget_getItemByID
  51. o.isShown=MenuWidget_isShown
  52. o.remove=MenuWidget_remove
  53. o.removeByID=MenuWidget_removeByID
  54. // Private Methods
  55. o.showSub=MenuWidget_showSub
  56. o.captureClicks=MenuWidget_captureClicks
  57. o.releaseClicks=MenuWidget_releaseClicks
  58. o.focus=MenuWidget_focus
  59. o.restoreFocus=MenuWidget_restoreFocus
  60. o.hasVisibleItem=MenuWidget_hasVisibleItem
  61. o.updateIndex=MenuWidget_updateIndex
  62. // Click capture
  63. o.clickCB=new Array
  64. o.clickCBDocs=new Array
  65. // Disable direct write
  66. o.write=MenuWidget_write
  67. o.alignLeft=false
  68. o.sepCount=0
  69. return o
  70. }
  71. // ================================================================================
  72. function MenuWidget_captureClicks(w)
  73. // capture click in current frame and sub-frame, so when the users clicks outside
  74. // the menu, the menu is closed. Eventual click handlers are stored.
  75. // Use releaseClicks() to restore previous click handlers
  76. // Returns [void]
  77. {
  78. var o=this
  79. if (o.par==null)
  80. {
  81. if (w==null)
  82. {
  83. _globMenuCaptured=o
  84. o.clickCB.length=0
  85. o.clickCBDocs.length=0
  86. w=_curWin
  87. }
  88. //_excludeFromFrameScan variable is set by a frame that does not want to
  89. // be scaned, when the frame is used to download document for instance.
  90. if (canScanFrames(w))
  91. {
  92. if (_moz)
  93. {
  94. _oldErrHandler=window.onerror
  95. window.onerror=localErrHandler
  96. }
  97. try
  98. {
  99. d=w.document
  100. o.clickCB[o.clickCB.length]=d.onmousedown
  101. o.clickCBDocs[o.clickCBDocs.length]=d
  102. d.onmousedown=MenuWidget_globalClick
  103. var fr=w.frames,len=fr.length
  104. for (var i=0;i<len;i++)
  105. o.captureClicks(fr[i])
  106. }
  107. catch(expt)
  108. {
  109. }
  110. if (_moz)
  111. window.onerror=_oldErrHandler
  112. }
  113. }
  114. }
  115. // ================================================================================
  116. function MenuWidget_releaseClicks()
  117. // Restore click handlers overrided by captureClicks()
  118. // Returns [void]
  119. {
  120. var o=this
  121. if (o.par==null)
  122. {
  123. var len=o.clickCB.length
  124. for (var i=0;i<len;i++)
  125. {
  126. try
  127. {
  128. o.clickCBDocs[i].onmousedown=o.clickCB[i]
  129. }
  130. catch(expt)
  131. {
  132. }
  133. o.clickCB[i]=null
  134. o.clickCBDocs[i]=null
  135. }
  136. o.clickCB.length=0
  137. o.clickCBDocs.length=0
  138. }
  139. }
  140. // ================================================================================
  141. _menuItem=null;
  142. function MenuWidget_focus()
  143. //give focus to the first visible menuItem
  144. {
  145. var o=this, items=o.items, len=items.length
  146. for(var i=0; i<len;i++)
  147. {
  148. if(items[i].isShown && !items[i].isSeparator)
  149. {
  150. _menuItem=items[i];
  151. setTimeout("_menuItem.focus()",1);
  152. if(o.endLink) o.endLink.show(true)
  153. if(o.startLink) o.startLink.show(true)
  154. break;
  155. }
  156. }
  157. }
  158. // ================================================================================
  159. function MenuWidget_keepFocus(id)
  160. {
  161. var o=getWidget(getLayer(id))
  162. if (o) o.focus();
  163. }
  164. // ================================================================================
  165. function MenuWidget_restoreFocus()
  166. {
  167. var o=this
  168. if(o.endLink) o.endLink.show(false)
  169. if(o.startLink) o.startLink.show(false)
  170. if(o.parIcon) o.parIcon.focus()
  171. else
  172. if (o.par) o.par.focus()
  173. else if(o.parCalendar) o.parCalendar.focus()
  174. }
  175. // ================================================================================
  176. function MenuWidget_keyDown(id,e)
  177. {
  178. var o=getWidget(getLayer(id))
  179. var key=eventGetKey(e)
  180. if(key==27 && o)//escape
  181. {
  182. o.restoreFocus()
  183. o.show(false)
  184. if (o.par && o.par.par)//case submenu
  185. {
  186. o.par.par.currentSub=-1
  187. }
  188. o.currentSub=-1
  189. eventCancelBubble(e);//be careful ! usefull for dialog box close by Escape keypressed
  190. }
  191. else if(o && (key==109 || key==37))//collapse (- ou <-)
  192. {
  193. if (o.par && o.par.par) //only for submenu
  194. {
  195. o.restoreFocus()
  196. o.show(false)
  197. o.par.par.currentSub=-1
  198. o.currentSub=-1
  199. }
  200. }
  201. else if(key==13)//enter
  202. {
  203. eventCancelBubble(e);//be careful ! usefull for dialog box close by Enter keypressed
  204. }
  205. }
  206. // ================================================================================
  207. function MenuWidget_globalClick()
  208. // PRIVATE
  209. // Click handler that close the menu if the user clicks outside the menu
  210. // Also call releaseClicks() to restore previous click handlers
  211. {
  212. var o=_globMenuCaptured
  213. if (o!=null)
  214. {
  215. _globMenuCaptured=null
  216. o.releaseClicks()
  217. o.show(false)
  218. }
  219. }
  220. // ================================================================================
  221. function MenuWidget_add(id,text,cb,icon,dx,dy,disabled,disDx,disDy,alt)
  222. // id [String] the item id
  223. // text [String] the item text
  224. // icon [String - optional] the item icon url (16x16 pixels)
  225. // dx [int - optional] the item icon horizontal offset
  226. // dy [int - optional] the item icon vertical offset
  227. // disabled [boolean - optional] initial disabled state (default is not disabled)
  228. // disDx [int - optional] the item icon horizontal offset for disabled
  229. // disDy [int - optional] the item icon vertical offset for disabled
  230. // Return [MenuItem] the new item
  231. {
  232. var o=this,i=o.items.length
  233. var ret=o.items[i]=newMenuItem(o,id,text,cb,icon,dx,dy,disabled,disDx,disDy,false,alt)
  234. ret.menuIndex=i
  235. ret.dynHTML()
  236. return ret
  237. }
  238. // ================================================================================
  239. function MenuWidget_addCheck(id,text,cb,icon,dx,dy,disabled,disDx,disDy,alt)
  240. // id [String] the item id
  241. // text [String] the item text
  242. // icon [String - optional] the item icon url (16x16 pixels)
  243. // dx [int - optional] the item icon horizontal offset
  244. // dy [int - optional] the item icon vertical offset
  245. // disabled [boolean - optional] initial disabled state (default is not disabled)
  246. // disDx [int - optional] the item icon horizontal offset for disabled
  247. // disDy [int - optional] the item icon vertical offset for disabled
  248. // Return [MenuItem] the new menu item
  249. {
  250. var o=this,i=o.items.length
  251. var ret=o.items[i]=newMenuItem(o,id,text,cb,icon,dx,dy,disabled,disDx,disDy,true,alt)
  252. ret.menuIndex=i
  253. ret.dynHTML()
  254. return ret
  255. }
  256. // ================================================================================
  257. function MenuWidget_addSeparator()
  258. // Return [MenuItem] the new separator
  259. {
  260. var s=this.internalAdd("_menusep_"+(this.sepCount++))
  261. s.isSeparator=true
  262. return s
  263. }
  264. // ================================================================================
  265. function MenuWidget_insert(index,id,text,cb,icon,dx,dy,disabled,disDx,disDy,alt)
  266. // Return [MenuItem] the new separator
  267. {
  268. var o=this, item = newMenuItem(o,id,text,cb,icon,dx,dy,disabled,disDx,disDy,false,alt);
  269. arrayAdd(o,'items',item,index);
  270. o.updateIndex();
  271. item.dynHTML()
  272. return item
  273. }
  274. // ================================================================================
  275. function MenuWidget_insertCheck(index,id,text,cb,icon,dx,dy,disabled,disDx,disDy,alt)
  276. // Return [MenuItem] the new separator
  277. {
  278. var o=this, item = newMenuItem(o,id,text,cb,icon,dx,dy,disabled,disDx,disDy,true,alt);
  279. arrayAdd(o,'items',item,index);
  280. o.updateIndex();
  281. item.dynHTML()
  282. return item
  283. }
  284. // ================================================================================
  285. function MenuWidget_insertSeparator(index)
  286. // index [int] the item index
  287. // Return [MenuItem] the new separator
  288. {
  289. var item = newMenuItem(this,"_menusep_"+(this.sepCount++));
  290. item.isSeparator=true;
  291. arrayAdd(this,'items',item,index);
  292. this.updateIndex();
  293. item.dynHTML()
  294. return item
  295. }
  296. // ================================================================================
  297. function MenuWidget_init()
  298. // Redefined for disable the default widget init function
  299. // Return [void]
  300. {
  301. }
  302. // ================================================================================
  303. function MenuWidget_getItem(index)
  304. // Get an item in the menu
  305. // index [int] the item index
  306. // Return [MenuItem] the item (null if invalid index)
  307. {
  308. var o=this,items=o.items
  309. if ((index>=0)&&(index<items.length))
  310. return items[index]
  311. return null
  312. }
  313. // ================================================================================
  314. function MenuWidget_getItemByID(id)
  315. // Get an item in the menu
  316. // index [int] the item index
  317. // Return [MenuItem] the item (null if invalid index)
  318. {
  319. var o=this,items=o.items
  320. for(var i in items)
  321. {
  322. if(items[i].id == id)
  323. return items[i];
  324. }
  325. return null
  326. }
  327. // ================================================================================
  328. function MenuWidget_removeByID(id)
  329. {
  330. var o=this;
  331. var item = o.getItemByID(id);
  332. if(item)
  333. {
  334. //remove in items
  335. arrayRemove(o,'items',item.menuIndex);
  336. o.updateIndex();
  337. //remove in html
  338. if (o.layer==null)
  339. return
  340. var tbody=o.layer.childNodes[0];
  341. tbody.deleteRow(item.menuIndex);
  342. }
  343. }
  344. // ================================================================================
  345. function MenuWidget_remove(index)
  346. {
  347. var o=this;
  348. if(index != null)
  349. {
  350. arrayRemove(o,'items',index);
  351. o.updateIndex();
  352. }
  353. else //null = remove all
  354. {
  355. o.items.length = 0;
  356. }
  357. //remove in html
  358. if (o.layer==null)
  359. return
  360. if (index != null) {
  361. var tbody=o.layer.childNodes[0];
  362. tbody.deleteRow(index);
  363. }
  364. }
  365. // ================================================================================
  366. function MenuWidget_updateIndex()
  367. {
  368. var items = this.items,len = items.length
  369. for(var i=0; i<len;i++)
  370. {
  371. items[i].menuIndex=i;
  372. }
  373. }
  374. // ================================================================================
  375. function MenuWidget_showSub()
  376. // PRIVATE show the sub menu - for internal purpose
  377. // Return [void]
  378. {
  379. var o=this
  380. if (o.nextSub!=-1)
  381. {
  382. if (o.nextSub!=o.currentSub)
  383. {
  384. // hide current sub-menu
  385. var currentItem=o.items[o.currentSub]
  386. if (currentItem&&currentItem.sub)
  387. {
  388. currentItem.sub.show(false)
  389. o.currentSub=-1
  390. }
  391. // show sub-menu
  392. var nextItem=o.items[o.nextSub]
  393. if (nextItem&&nextItem.sub)
  394. {
  395. var lyr=nextItem.layer
  396. var x=parseInt(o.css.left)
  397. var y=parseInt(o.css.top)
  398. for (var i=0;i<o.nextSub;i++)
  399. {
  400. var item=o.items[i]
  401. if (item.isShown)
  402. {
  403. if ((item.icon!=null)||(item.text!=null))
  404. y+=_mitemH
  405. else
  406. y+=3
  407. }
  408. }
  409. var w=o.getWidth()
  410. x=x+w-4
  411. nextItem.attachSubMenu(nextItem.sub)
  412. nextItem.sub.show(true,x,y,false,w)
  413. o.currentSub=o.nextSub
  414. }
  415. }
  416. }
  417. else if (o.currentSub!=-1)
  418. {
  419. // hide current sub-menu
  420. var currentItem=o.items[o.currentSub]
  421. if (currentItem&&currentItem.sub)
  422. {
  423. currentItem.sub.show(false)
  424. o.currentSub=-1
  425. }
  426. }
  427. }
  428. // ================================================================================
  429. function MenuWidget_write()
  430. // Cancels default widget behaviour
  431. // Return [void]
  432. {
  433. }
  434. // ================================================================================
  435. function MenuWidget_justInTimeInit()
  436. // Initialization called just before showing menu for the first time
  437. // Return [void]
  438. {
  439. var o=this
  440. o.layer=getLayer(o.id)
  441. if (o.layer==null)
  442. {
  443. targetApp(o.getHTML())
  444. o.layer=getLayer(o.id)
  445. }
  446. o.layer._widget=o.widx
  447. o.css=o.layer.style
  448. o.endLink=newWidget("endLink_"+o.id)
  449. o.endLink.init()
  450. o.startLink=newWidget("startLink_"+o.id)
  451. o.startLink.init()
  452. var items=o.items
  453. for (var i in items)
  454. items[i].init()
  455. }
  456. // ================================================================================
  457. function MenuWidget_getHTML()
  458. // PRIVATE get the HTML
  459. // Return [String]
  460. {
  461. var o=this,items=o.items
  462. var keysCbs=' onkeydown="'+_codeWinName+'.MenuWidget_keyDown(\''+o.id+'\',event);return true" '
  463. // we'll add the iframe with the show function
  464. var s='<a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="startLink_'+o.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.MenuWidget_keepFocus(\''+o.id+'\');return false;" ></a><table style="display:none;" class="menuFrame" id="'+o.id+'" cellspacing="0" cellpadding="0" border="0" '+keysCbs+' dir="ltr"><tbody>'
  465. for (var i in items)
  466. s+=items[i].getHTML()
  467. s+='</tbody></table><a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="endLink_'+o.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.MenuWidget_keepFocus(\''+o.id+'\');return false;" ></a>'
  468. return s
  469. }
  470. // ================================================================================
  471. function MenuWidget_show(show,x,y,parentPropagate,parentMenuW,buttonFrom)
  472. // show [boolean] if true shows the menu, otherwise hide it
  473. // x [int] menu abscissa (may be changed if the menu is outside the window)
  474. // y [int] menu ordinate (may be changed if the menu is outside the window)
  475. // parentPropagate [boolean - optional] only active if show=false. Close also all parent menus
  476. // parentMenuW [int - optional] only used internally
  477. // Return [void]
  478. {
  479. var o=this
  480. if (o.layer==null)
  481. o.justInTimeInit()
  482. var css=o.css
  483. if (show)
  484. {
  485. o.iframeLyr=getDynamicBGIFrameLayer()
  486. o.iframeCss=o.iframeLyr.style
  487. if (o.beforeShowCB)
  488. o.beforeShowCB()
  489. //User Rights: don't show menu if it contains no visible menu
  490. if(!o.hasVisibleItem()) return;
  491. o.captureClicks()
  492. // Show and place menu
  493. css.display='block'
  494. css.zIndex=(o.zIndex+1)
  495. css.visibility="hidden"
  496. css.left="-1000px"
  497. css.top="-1000px"
  498. var w=o.getWidth()
  499. var h=o.getHeight()
  500. if (o.alignLeft)
  501. x-=w
  502. // buttonFrom means that we a are in a menu triggered by a button
  503. // (example : IconMenuWidget
  504. if (buttonFrom)
  505. {
  506. var buttonW=buttonFrom.getWidth()
  507. // Align the menu at the button right
  508. // if the button is larger than the menu
  509. if (buttonW>w)
  510. x=x+buttonW-w
  511. }
  512. // Change coordinates if the menu is out of the window
  513. var x2=x+w+4,y2=y+h+4
  514. if (x2-getScrollX()>winWidth())
  515. {
  516. if (buttonFrom)
  517. {
  518. // If the menu go out of the container windows
  519. // align to the the right of the window
  520. x=Math.max(0,winWidth()-w)
  521. }
  522. else
  523. x=Math.max(0,x-4-(w+((parentMenuW!=null)?parentMenuW-12:0)))
  524. }
  525. if (y2-getScrollY()>winHeight())
  526. y=Math.max(0,y-4-h+(parentMenuW!=null?30:0))
  527. css.left=""+x+"px"
  528. css.top=""+y+"px"
  529. css.visibility="visible"
  530. // Show and place menu shadow
  531. iCss=o.iframeCss
  532. iCss.left=""+x+"px"
  533. iCss.top=""+y+"px"
  534. iCss.width=""+w+"px"
  535. iCss.height=""+h+"px"
  536. iCss.zIndex=o.zIndex-1
  537. iCss.display='block'
  538. if (_ie)
  539. {
  540. y-=2
  541. x-=2
  542. }
  543. o.nextSub=-1
  544. o.showSub()
  545. o.focus()
  546. }
  547. else
  548. {
  549. if (parentPropagate && o.par && o.par.par)
  550. {
  551. o.par.par.show(show,x,y,parentPropagate)
  552. }
  553. if (o.iframeLyr) {
  554. releaseBGIFrame(o.iframeLyr.id)
  555. }
  556. css.display='none'
  557. if (o.iframeCss) {
  558. o.iframeCss.display='none'
  559. }
  560. o.nextSub=-1
  561. o.showSub()
  562. if (o.hideCB)
  563. o.hideCB()
  564. o.releaseClicks()
  565. }
  566. }
  567. // ================================================================================
  568. function MenuWidget_isShown()
  569. // Test if the menu is shown
  570. // Returns [boolean]
  571. {
  572. var o=this
  573. if (o.layer==null)
  574. return false
  575. else
  576. return (o.css.display=='block')
  577. }
  578. // ================================================================================
  579. function MenuWidget_hasVisibleItem()
  580. // Test if the menu contains shown items
  581. // Returns [boolean]
  582. {
  583. var o=this
  584. if(o.isMenuColor || o.isCalendar) return true;
  585. var items=o.items
  586. for (var i in items)
  587. {
  588. var item=items[i]
  589. if (item && !(item.isSeparator==true) && item.isShown)
  590. return true;
  591. }
  592. return false
  593. }
  594. // ================================================================================
  595. // ================================================================================
  596. //
  597. // OBJECT newMenuWidgetItem (Constructor)
  598. //
  599. // creates a menu widget item - do not use this constructor directly. use instead
  600. // MenuWidget::add
  601. //
  602. // ================================================================================
  603. // ================================================================================
  604. function newMenuItem(par,id,text,cb,icon,dx,dy,disabled,disDx,disDy,isCheck,alt)
  605. // par [MenuWidget] the parent menu
  606. // id [String] the item id
  607. // text [String] the item text
  608. // icon [String - optional] the item icon url (16x16 pixels)
  609. // dx [int - optional] the item icon horizontal offset
  610. // dy [int - optional] the item icon vertical offset
  611. // disabled [boolean - optional] initial disabled state (default is not disabled)
  612. // disDx [int - optional] the item icon horizontal offset for disabled
  613. // disDy [int - optional] the item icon vertical offset for disabled
  614. // isCheck [boolean - optional] default is false - specified if the item is a check box
  615. // Returns [MenuItem] the new instance
  616. {
  617. // No parent class
  618. var o=new Object
  619. // Private fields
  620. o.par=par
  621. o.id=id
  622. o.text=text
  623. o.cb=cb
  624. o.icon=icon
  625. o.dx=(dx==null)?0:dx
  626. o.dy=(dy==null)?0:dy
  627. o.disDx=(disDx==null)?o.dx:disDx
  628. o.disDy=(disDy==null)?o.dy:disDy
  629. o.sub=null
  630. o.layer=null
  631. o.iconTDLayer=null
  632. o.iconLayer=null
  633. o.textLayer=null
  634. o.textOnlyLayer=null
  635. o.accel=null
  636. o.accelLayer=null
  637. o.hasNoLayer=false
  638. o.isSeparator=false
  639. o.disabled=(disabled!=null)?disabled:false
  640. o.isShown=true
  641. o.alt=alt //icon alt att
  642. o.index=_menusItems.length
  643. _menusItems[o.index]=o
  644. o.menuIndex=-1
  645. o.isCheck=isCheck
  646. o.checked=false
  647. o.menuItemType=_isNotColor
  648. o.init=MenuItem_init
  649. o.leftZoneClass="menuLeftPart"
  650. o.leftZoneSelClass="menuLeftPartSel"
  651. // Public methods
  652. o.attachSubMenu=MenuItem_attachSubMenu
  653. o.getHTML=MenuItem_getHTML
  654. o.getHTMLPart=MenuItem_getHTMLPart
  655. o.dynHTML=MenuItem_dynHTML
  656. o.setDisabled=MenuItem_setDisabled
  657. o.check=MenuItem_check
  658. o.isChecked=MenuItem_isChecked
  659. o.show=MenuItem_show
  660. o.setText=MenuItem_setText
  661. o.setIcon=MenuItem_setIcon
  662. o.setAccelerator=MenuItem_setAccelerator
  663. o.focus=MenuItem_focus
  664. return o
  665. }
  666. // ================================================================================
  667. function MenuItem_init()
  668. // Init widget layers
  669. // Return [void]
  670. {
  671. if (!this.hasNoLayer)
  672. {
  673. var o=this,id=o.par.id
  674. o.layer=getLayer(id+'_item_'+o.id)
  675. o.layer._boIndex=o.index
  676. if (!o.isSeparator)
  677. {
  678. if ((o.icon!=null)||(o.isCheck))
  679. {
  680. o.iconLayer=getLayer(id+'_item_icon_'+o.id)
  681. o.iconTDLayer=getLayer(id+'_item_td_'+o.id)
  682. }
  683. o.textLayer=getLayer(id+'_text_'+o.id)
  684. o.textOnlyLayer=getLayer(id+'_span_text_'+o.id)
  685. o.accelLayer=getLayer(id+'_accel_'+o.id)
  686. if(o.textOnlyLayer) //508
  687. {
  688. o.textOnlyLayer.title=o.checked?o.textOnlyLayer.innerText+" "+_menuCheckLab:""
  689. if (o.disabled) o.textOnlyLayer.title +=" "+_menuDisableLab
  690. }
  691. }
  692. if (o.isCheck)
  693. {
  694. o.check(o.checked,true)
  695. }
  696. }
  697. }
  698. // ================================================================================
  699. function MenuItem_attachSubMenu(menu)
  700. // menu [MenuWidget] the menu to be attached
  701. // return [MenuWidget] the menu to be attached
  702. {
  703. var o=this
  704. o.sub=menu
  705. menu.par=o
  706. menu.zIndex=o.par.zIndex+2
  707. if (o.layer)
  708. {
  709. if (o.arrowLayer==null)
  710. o.arrowLayer=getLayer(o.par.id+'_item_arrow_'+o.id)
  711. var dis=o.disabled
  712. changeSimpleOffset(o.arrowLayer,dis?7:0,dis?81:64)
  713. }
  714. return menu
  715. }
  716. // ================================================================================
  717. function MenuItem_check(check,force)
  718. // check/unchecks an item - only for items that a declared as check boxes
  719. // check [boolean] if true checks the item
  720. // Return [void]
  721. {
  722. var o=this
  723. if ((o.checked!=check)||force)
  724. {
  725. o.checked=check
  726. if (o.par.layer)
  727. {
  728. // Dynamic check
  729. var lyr=o.layer
  730. if (lyr)
  731. {
  732. if (o.icon==null)
  733. changeSimpleOffset(o.iconLayer,0,(o.checked?48:0),null,(o.checked?_menuCheckLab:""))
  734. changeOffset(o.iconTDLayer,0,(o.checked?96:0))
  735. if (o.checkFrame==null)
  736. o.checkFrame=getLayer(o.par.id+'_item_check_'+o.id)
  737. o.checkFrame.className='menuIcon'+(o.checked?"Check":"")
  738. if(o.textOnlyLayer) //508
  739. o.textOnlyLayer.title=o.checked?o.textOnlyLayer.innerText+" "+_menuCheckLab:""
  740. }
  741. }
  742. }
  743. }
  744. // ================================================================================
  745. function MenuItem_setDisabled(dis)
  746. // disables a menu item
  747. // dis [boolean] if true disables the item
  748. // Return [void]
  749. {
  750. var o=this
  751. if (o.disabled!=dis)
  752. {
  753. o.disabled=dis
  754. if (o.par.layer)
  755. {
  756. // Dynamic set disabled
  757. var lyr=o.layer
  758. if (lyr)
  759. {
  760. lyr.style.cursor=dis?'default':_hand
  761. if (o.icon)
  762. changeSimpleOffset(o.iconLayer,dis?o.disDx:o.dx,dis?o.disDy:o.dy)
  763. var cn='menuTextPart'+(o.disabled?'Disabled':'')
  764. if (cn!=o.textLayer.className)
  765. o.textLayer.className=cn
  766. if (o.accel && (cn!=o.accelLayer.className))
  767. o.accelLayer.className=cn
  768. if (o.sub)
  769. {
  770. if (o.arrowLayer==null)
  771. o.arrowLayer=getLayer(o.par.id+'_item_arrow_'+o.id)
  772. changeSimpleOffset(o.arrowLayer,dis?7:0,dis?81:64)
  773. }
  774. if(o.textOnlyLayer) //508
  775. o.textOnlyLayer.title=o.disabled?o.textOnlyLayer.innerText+" "+_menuDisableLab:""
  776. }
  777. }
  778. }
  779. }
  780. // ================================================================================
  781. function _mii(lyr,inv)
  782. // PRIVATE invert a menu item
  783. // lyr [dom element] the <TR> element to invert
  784. // inv [1 or 0] if 1 the menu must have a selected look
  785. // Return [void]
  786. {
  787. var c=lyr.childNodes,y=0,len=c.length,idx=lyr._boIndex
  788. var o=_menusItems[idx]
  789. if (o.disabled)
  790. inv=0
  791. else
  792. {
  793. if (inv)
  794. {
  795. o.par.nextSub=o.menuIndex
  796. MenuItem_callShowSub(idx,true)
  797. if (o.par.par)
  798. {
  799. if (o.par.par.par)
  800. {
  801. o.par.par.par.nextSub=o.par.par.menuIndex
  802. }
  803. }
  804. }
  805. }
  806. var realPart=0
  807. for (var i=0;i<len;i++)
  808. {
  809. var ce=c[i]
  810. if (ce.tagName!=null)
  811. {
  812. if (realPart==0)
  813. ce.className=inv?o.leftZoneSelClass:o.leftZoneClass
  814. else if (realPart==1)
  815. ce.className="menuTextPart"+(inv?"Sel":"")+(o.disabled?"Disabled":"")
  816. else if (o.accel && (realPart==2))
  817. {
  818. ce.className="menuTextPart"+(inv?"Sel":"")+(o.disabled?"Disabled":"")
  819. break
  820. }
  821. else
  822. ce.className="menuRightPart"+(inv?"Sel":"")
  823. realPart++
  824. }
  825. }
  826. }
  827. // ================================================================================
  828. function MenuItem_getHTMLPart(part)
  829. {
  830. var o=this
  831. switch(part)
  832. {
  833. case 0: // the icon on the left
  834. var im=null,className=' class="menuIcon' + (o.checked?"Check":"")+'"'
  835. if (o.isCheck&&(o.icon==null))
  836. im=simpleImgOffset(_skin+"menus.gif",16,16,0,o.checked?48:0,(o.par.id+'_item_icon_'+o.id),null,(o.checked?_menuCheckLab:""))
  837. else
  838. im=o.icon?simpleImgOffset(o.icon,16,16,o.disabled?o.disDx:o.dx,o.disabled?o.disDy:o.dy,(o.par.id+'_item_icon_'+o.id),null,o.alt?o.alt:''):(getSpace(16,16))
  839. if (o.isCheck)
  840. {
  841. var size=_ie?18:16
  842. im='<div id="'+o.par.id+'_item_check_'+o.id+'" class="menuIcon'+(o.checked?"Check":"")+'" style="width:'+size+'px;height:'+size+'px;padding:1px">'+im+'</div>'
  843. }
  844. return im
  845. case 1: // the text
  846. var div1=_saf?'<div style="height:19px;padding-top:5px">':'',div2=_saf?'</div>':''
  847. return div1+'<span id="'+(o.par.id+'_span_text_'+o.id)+'" tabIndex="0">'+convStr(o.text)+'</span>'+div2
  848. case 2:
  849. return simpleImgOffset(_skin+"menus.gif",16,16,o.sub?(o.disabled?7:0):0,o.sub?(o.disabled?81:64):0,o.par.id+'_item_arrow_'+o.id, null, null, null,"right")
  850. case 3:
  851. return '<table width="100%" height="3" cellpadding="0" cellspacing="0" border="0" style="'+backImgOffset(_skin+"menus.gif",0,80)+';"><tbody><tr><td></td></tr></tbody></table>'
  852. case 4: // the accelerator
  853. return convStr(o.accel)
  854. }
  855. }
  856. // ================================================================================
  857. function MenuItem_getHTML()
  858. // Return [String] the HTML
  859. {
  860. var o=this
  861. if ((o.icon!=null)||(o.text!=null))
  862. {
  863. var invertCbs=' onclick="'+_codeWinName+'._micl(this,event);return true" oncontextmenu="'+_codeWinName+'._micl(this,event);return false" onmouseover="'+_codeWinName+'._mii(this,1)" onmouseout="'+_codeWinName+'._mii(this,0);" '
  864. var keysCbs=' onkeydown="'+_codeWinName+'._mikd(this,event);return true" '
  865. var ar=new Array(), i=0
  866. ar[i++] = '<tr onmousedown="'+_codeWinName+'._minb(event)" onmouseup="'+_codeWinName+'._minb(event)" id="'+(o.par.id+'_item_'+o.id)+'" style="'+(!o.isShown?'display:none;':'')+'height:'+_mitemH+'px;width:24px;cursor:'+(o.disabled?'default':_hand)+'" '+invertCbs+keysCbs+' valign="middle">'
  867. ar[i++] = '<td id="'+(o.par.id+'_item_td_'+o.id)+'" style="width:23px;height:'+_mitemH+'px;" align="center" class="'+o.leftZoneClass+'">'
  868. ar[i++] = o.getHTMLPart(0)
  869. ar[i++] = '</td>'
  870. ar[i++] = '<td ' +(o.centered?' align="center" ':'')+' style="height:'+_mitemH+'px" id="'+(o.par.id+'_text_'+o.id)+'" class="menuTextPart'+(o.disabled?'Disabled':'')+'">'
  871. ar[i++] = o.getHTMLPart(1)
  872. ar[i++] = '</td>'
  873. if (o.accel!=null)
  874. {
  875. ar[i++] = '<td class="menuTextPart'+(o.disabled?'Disabled':'') + '" id="'+(o.par.id+'_accel_'+o.id)+'" align="right"' +' style="height:'+_mitemH+'px" tabIndex="-1">'
  876. ar[i++] = o.getHTMLPart(4)
  877. ar[i++] = '</td>'
  878. } else {
  879. ar[i++] = '<td class="menuRightPart" align="right" style="width:40px;height:'+_mitemH+'px;" >'
  880. ar[i++] = o.getHTMLPart(2)
  881. ar[i++] = '</td>'
  882. }
  883. ar[i++] = '</tr>'
  884. return ar.join('')
  885. }
  886. else
  887. {
  888. return '<tr onmousedown="'+_codeWinName+'._minb(event)" onclick="'+_codeWinName+'._minb(event)" id="'+(o.par.id+'_item_'+o.id)+'" onmouseup="'+_codeWinName+'._minb(event)" style="height:3px">'+
  889. '<td class="'+o.leftZoneClass+'" style="width:24px;height:3px;border:0px"></td>'+
  890. '<td colspan="2" style="padding-left:5px;padding-right:5px;border:0px">'+
  891. o.getHTMLPart(3)+
  892. '</td></tr>'
  893. }
  894. }
  895. // ================================================================================
  896. function MenuItem_dynHTML()
  897. {
  898. var o=this
  899. if (o.par.layer==null)
  900. return
  901. var tbody=o.par.layer.childNodes[0],tr=tbody.insertRow(o.menuIndex),st=tr.style
  902. tr.onmousedown=_minb
  903. tr.onmouseup=_minb
  904. tr.id=(o.par.id+'_item_'+o.id)
  905. if ((o.icon!=null)||(o.text!=null))
  906. {
  907. var td1=tr.insertCell(0),td2=tr.insertCell(1),td3=tr.insertCell(2),st1=td1.style,st2=td2.style,st3=td3.style
  908. tr.onclick=MenuItem_clickCallTrue
  909. tr.oncontextmenu=MenuItem_clickCallFalse
  910. tr.onmouseover=MenuItem_invertCall1
  911. tr.onmouseout=MenuItem_invertCall0
  912. st.height=""+_mitemH+"px"
  913. st.width="24px"
  914. st.cursor=(o.disabled?'default':_hand)
  915. td1.id=(o.par.id+'_item_td_'+o.id)
  916. st1.width="23px"
  917. st1.height=""+_mitemH+"px"
  918. td1.innerHTML=o.getHTMLPart(0)
  919. td1.align="center"
  920. td1.className=o.leftZoneClass
  921. if (o.centered)
  922. td2.align="center"
  923. st2.height=""+_mitemH+"px"
  924. td2.id=(o.par.id+'_text_'+o.id)
  925. td2.className="menuTextPart"+(o.disabled?'Disabled':'')
  926. td2.innerHTML=o.getHTMLPart(1)
  927. if (o.accel)
  928. {
  929. td3.className="menuTextPart"+(o.disabled?'Disabled':'')
  930. td3.align="right"
  931. //st3.width="24px"
  932. st3.height=""+_mitemH+"px"
  933. //st3.paddingLeft="4px"
  934. //st3.paddingRight="4px"
  935. td3.innerHTML=o.getHTMLPart(4)
  936. } else {
  937. td3.className="menuRightPart"
  938. td3.align="right"
  939. st3.width="40px"
  940. st3.height=""+_mitemH+"px"
  941. changeOffset(td3,0,0,_skin+"menus.gif")
  942. td3.innerHTML=o.getHTMLPart(2)
  943. }
  944. o.init()
  945. }
  946. else
  947. {
  948. tr.onclick=_minb
  949. tr.style.height="3px"
  950. var td1=tr.insertCell(0),td2=tr.insertCell(1),st1=td1.style,st2=td2.style
  951. td1.className=o.leftZoneClass
  952. st1.width="24px"
  953. st1.height="3px"
  954. st1.border="0px"
  955. td2.colSpan="2"
  956. st2.paddingLeft="5px"
  957. st2.paddingRight="5px"
  958. td2.innerHTML=o.getHTMLPart(3)
  959. }
  960. }
  961. // ================================================================================
  962. function MenuItem_isChecked()
  963. // test if a check box item is checked
  964. // Return [boolean]
  965. {
  966. return this.checked
  967. }
  968. // ================================================================================
  969. function MenuItem_setText(s)
  970. //change text of menu item
  971. {
  972. var o=this,id=o.par.id
  973. o.text=s
  974. if (o.textLayer)
  975. {
  976. o.textLayer.innerHTML=o.getHTMLPart(1)
  977. o.textOnlyLayer=getLayer(id+'_span_text_'+o.id)
  978. }
  979. }
  980. // ================================================================================
  981. function MenuItem_setAccelerator(keystroke, modifier)
  982. // keystroke char corresponding to a keyboard key
  983. // modifier int _ctrl=0,_shift=1,_alt=2
  984. //add an accelerator(key combination) to the text of menu item
  985. {
  986. var o=this,id=o.par.id
  987. o.accel= ((modifier != null)?_modifiers[modifier]:"") + keystroke
  988. if (o.accelLayer)
  989. {
  990. o.accelLayer.innerHTML=o.getHTMLPart(4)
  991. }
  992. }
  993. // ================================================================================
  994. function MenuItem_setIcon(dx,dy,disDx,disDy,url)
  995. // Change icon
  996. {
  997. var o=this
  998. o.url = url ? url : o.url
  999. o.dx = (dx != null) ? dx : o.dx
  1000. o.dy = (dy != null) ? dy : o.dy
  1001. o.disDx = (disDx != null) ? disDx : o.disDx
  1002. o.disDy = (disDy != null) ? disDy : o.disDy
  1003. if (o.icon && o.iconLayer)
  1004. changeSimpleOffset(o.iconLayer,o.disabled?o.disDx:o.dx, o.disabled?o.disDy:o.dy,o.url)
  1005. }
  1006. // ================================================================================
  1007. function MenuItem_show(sh)
  1008. // show/hide a menu item
  1009. // sh [boolean] if true shows the item
  1010. // Return [void]
  1011. {
  1012. var o=this
  1013. o.isShown=sh
  1014. if (o.layer!=null)
  1015. o.layer.style.display=sh?'':'none'
  1016. }
  1017. // ================================================================================
  1018. function _micl(lyr,e)
  1019. // PRIVATE - DHTML Callback
  1020. // lyr [dom element] the <TR> element to invert
  1021. // e [event pointer] the event
  1022. // Return [void]
  1023. {
  1024. eventCancelBubble(e)
  1025. var idx=lyr._boIndex,o=_menusItems[idx]
  1026. o.layer=lyr
  1027. if (!o.disabled)
  1028. {
  1029. if (o.sub)
  1030. {
  1031. o.par.nextSub=o.menuIndex
  1032. MenuItem_callShowSub(idx)
  1033. }
  1034. else
  1035. {
  1036. o.par.show(false,0,0,true)
  1037. if (o.isCheck)
  1038. {
  1039. if (o.par.uncheckAll)
  1040. o.par.uncheckAll()
  1041. o.check(!o.checked)
  1042. }
  1043. if (o.par.container && o.par.container.updateButton)
  1044. o.par.container.updateButton(idx)
  1045. _mii(lyr,0,idx)
  1046. o.par.nextSub=-1
  1047. if (o.cb)
  1048. setTimeout("MenuItem_delayedClick("+idx+")",1)
  1049. }
  1050. }
  1051. }
  1052. // ================================================================================
  1053. function _mikd(lyr,e)
  1054. {
  1055. var idx=lyr._boIndex,o=_menusItems[idx]
  1056. o.layer=lyr
  1057. var k=eventGetKey(e)
  1058. switch(k)
  1059. {
  1060. case 13://enter
  1061. _micl(lyr,e)
  1062. break;
  1063. case 107://expanded (+ ou ->)
  1064. case 39:
  1065. if (!o.disabled && o.sub )
  1066. {
  1067. _micl(lyr,e)
  1068. }
  1069. break;
  1070. case 109://collapse (- ou <-)
  1071. case 37:
  1072. //let menu does action
  1073. break;
  1074. case 40://next
  1075. var items=o.par.items, len = items.length
  1076. for(var i=o.menuIndex+1;i<len;i++)
  1077. {
  1078. if(items[i].isShown && !items[i].isSeparator)
  1079. {
  1080. items[i].focus()
  1081. break;
  1082. }
  1083. }
  1084. break;
  1085. case 38://previous
  1086. var items=o.par.items, len = items.length
  1087. for(var i=o.menuIndex-1;i>=0;i--)
  1088. {
  1089. if(items[i].isShown && !items[i].isSeparator)
  1090. {
  1091. items[i].focus()
  1092. break;
  1093. }
  1094. }
  1095. break;
  1096. }
  1097. }
  1098. // ================================================================================
  1099. function MenuItem_callShowSub(idx,delayed)
  1100. // PRIVATE - DHTML Callback, show a sub menu
  1101. // idx [int] the menu item indes in the _menusItems array
  1102. // delayed [boolean - optional] if true show the menu with a delay (used for rollovers)
  1103. // Return [void]
  1104. {
  1105. var o=_menusItems[idx]
  1106. if (delayed)
  1107. setTimeout('MenuItem_delayedShowSub('+idx+')',500)
  1108. else
  1109. MenuItem_delayedShowSub(idx)
  1110. }
  1111. // ================================================================================
  1112. function MenuItem_delayedShowSub(idx)
  1113. // PRIVATE - DHTML Callback, show a sub menu
  1114. // idx [int] the menu item indes in the _menusItems array
  1115. // Return [void]
  1116. {
  1117. var o=_menusItems[idx]
  1118. o.par.showSub()
  1119. }
  1120. // ================================================================================
  1121. function _minb(e)
  1122. // PRIVATE Cancel event bubble
  1123. // Return [void]
  1124. {
  1125. eventCancelBubble(e)
  1126. }
  1127. // ================================================================================
  1128. function MenuItem_delayedClick(idx)
  1129. // idx [int] the menu item index in the _menusItems array
  1130. // Return [void]
  1131. {
  1132. var item=_menusItems[idx]
  1133. if (item.cb)
  1134. item.cb()
  1135. }
  1136. // ================================================================================
  1137. function MenuItem_clickCallTrue(event)
  1138. // PRIVATE
  1139. {
  1140. _micl(this,event)
  1141. return true
  1142. }
  1143. // ================================================================================
  1144. function MenuItem_clickCallFalse(event)
  1145. // PRIVATE
  1146. {
  1147. _micl(this,event)
  1148. return false
  1149. }
  1150. // ================================================================================
  1151. function MenuItem_invertCall0(event)
  1152. // PRIVATE
  1153. {
  1154. _mii(this,0)
  1155. }
  1156. // ================================================================================
  1157. function MenuItem_invertCall1(event)
  1158. // PRIVATE
  1159. {
  1160. _mii(this,1)
  1161. }
  1162. // ================================================================================
  1163. function MenuItem_focus()
  1164. //give focus to menu item
  1165. {
  1166. var o=this
  1167. if(isLayerDisplayed(o.layer) && o.textOnlyLayer && o.textOnlyLayer.focus)
  1168. {
  1169. o.textOnlyLayer.focus();
  1170. }
  1171. }
  1172. // ================================================================================
  1173. // ================================================================================
  1174. //
  1175. // OBJECT newMenuColorWidget (Constructor)
  1176. //
  1177. // creates a color selector menu widget
  1178. //
  1179. // ================================================================================
  1180. // ================================================================================
  1181. function newMenuColorWidget(id,hideCB)
  1182. // id [String] the menu id for DHTML processing
  1183. // hideCB [Function - Optional] callback called when the menu is closed
  1184. // Returns [MenuColorWidget] the new instance
  1185. {
  1186. var o=newMenuWidget(id,hideCB)
  1187. o.addSeparator=null
  1188. o.lastUsedTxt=""
  1189. o.lastUsedColorsAr=null
  1190. o.addColor=MenuColorWidget_addColor
  1191. o.addLastUsed=MenuColorWidget_addLastUsed
  1192. o.getHTML=MenuColorWidget_getHTML
  1193. o.uncheckAll=MenuColorWidget_uncheckAll
  1194. o.isMenuColor=true
  1195. return o
  1196. }
  1197. // ================================================================================
  1198. function MenuColorWidget_addColor(tooltip,color,cb)
  1199. // tooltip [String] the color name
  1200. // color [String] the color code r,g,b ( 0 <= rgb <= 255)
  1201. // cb [Function - Optional] the click Callback
  1202. // Return [MenuItem] the new menu item
  1203. {
  1204. var o=this,i=o.items.length
  1205. var ret=o.items[i]=newColorMenuItem(o,color,tooltip,cb)
  1206. ret.menuIndex=i
  1207. return ret
  1208. }
  1209. // ================================================================================
  1210. function MenuColorWidget_addLastUsed(text,lastUsedColorsAr,cb, beforeShowCB)
  1211. // text [String] the menu label
  1212. // lastUsedColorsAr [Array] a reference to the stack of last used colors
  1213. {
  1214. var o=this
  1215. o.lastUsedTxt = text
  1216. o.lastUsedColorsAr = lastUsedColorsAr
  1217. o.beforeShowCB = MenuColorWidget_beforeShowCB
  1218. colorsMax = 8
  1219. len = o.items.length
  1220. var it = null
  1221. for (var c = 0; c < colorsMax; c++)
  1222. {
  1223. it = newLastUsedColorMenuItem(o,c,lastUsedColorsAr[c],"",cb)
  1224. it.isLast = (c == colorsMax-1) ? true : false // is it the last 'last used' color item in the item list
  1225. o.items[len + c] = it
  1226. }
  1227. }
  1228. // ================================================================================
  1229. function MenuColorWidget_getHTML()
  1230. // PRIVATE get the HTML
  1231. // Return [String]
  1232. {
  1233. var o=this,items=o.items
  1234. var j = 0
  1235. var keysCbs=' onkeydown="'+_codeWinName+'.MenuWidget_keyDown(\''+o.id+'\',event);return true" '
  1236. var s = new Array
  1237. s[j++] = '<a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="startLink_'+o.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.MenuWidget_keepFocus(\''+o.id+'\');return false;" ></a>'
  1238. s[j++] = '<table style="display:none;" class="menuFrame" id="'+o.id+'" cellspacing="0" cellpadding="0" border="0"'+keysCbs+'><tbody>'
  1239. var sep = '<tr style="height:3px"><td colspan="8" style="padding-left:5px;padding-right:5px;"><table width="100%" height="3" cellpadding="0" cellspacing="0" border="0" style="'+backImgOffset(_skin+"menus.gif",0,80)+';"><tbody><tr><td></td></tr></tbody></table></td></tr>'
  1240. var len = items.length
  1241. lastUsedCol=""
  1242. lastUsedColIconsNb = 0
  1243. lastUsedColIconsMaxLine = 3
  1244. for (var i in items)
  1245. {
  1246. var item=items[i]
  1247. switch (item.menuItemType)
  1248. {
  1249. case _isColor:
  1250. s[j++] = item.getHTML()
  1251. break;
  1252. case _isLastUsedColor:
  1253. lastUsedCol += item.getHTML()
  1254. lastUsedCol += (lastUsedColIconsNb++ == lastUsedColIconsMaxLine)? "</tr><tr>":""
  1255. if (item.isLast)
  1256. {
  1257. s[j++] = sep
  1258. s[j++] = '<tr><td colspan="8">'
  1259. s[j++] = '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr>'
  1260. s[j++] = '<td width="50%" class="menuTextPart">' + convStr(o.lastUsedTxt) + '</td>'
  1261. s[j++] = '<td><table border="0" cellspacing="0" cellpadding="0"><tbody><tr>'
  1262. s[j++] = lastUsedCol
  1263. s[j++] = '</tr></tbody></table></td>'
  1264. s[j++] = '</tr></tbody></table>'
  1265. s[j++] = '</td></tr>'
  1266. s[j++] = sep
  1267. }
  1268. break;
  1269. case _isNotColor:
  1270. item.leftZoneClass="menuLeftPartColor"
  1271. item.leftZoneSelClass="menuLeftPartSel"
  1272. item.centered=true
  1273. s[j++] ='<tr><td colspan="8"><table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr>'+item.getHTML()+'</tr></tbody></table></td></tr>'
  1274. s[j++] = (i == 0 )? sep:""
  1275. }
  1276. }
  1277. s[j++] ='</tbody></table><a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="endLink_'+o.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.MenuWidget_keepFocus(\''+o.id+'\');return false;" ></a>'
  1278. return s.join("")
  1279. }
  1280. // ================================================================================
  1281. function MenuColorWidget_beforeShowCB()
  1282. {
  1283. var o=this, j=0
  1284. lenLastUsed = o.lastUsedColorsAr.length
  1285. if ((lenLastUsed == 1) && ((o.lastUsedColorsAr[0].length == 0) || (o.lastUsedColorsAr[0] == "null"))) {
  1286. lenLastUsed = 0
  1287. o.lastUsedColorsAr.length = 0
  1288. }
  1289. for (var i in o.items)
  1290. {
  1291. var item=o.items[i]
  1292. if (item.menuItemType == _isLastUsedColor)
  1293. {
  1294. if (j < lenLastUsed)
  1295. {
  1296. item.init()
  1297. var c = o.lastUsedColorsAr[j++]
  1298. item.color = c
  1299. item.layer.childNodes[0].childNodes[0].style.backgroundColor = 'rgb(' + c + ')'
  1300. var t = _colorsArr[""+c+""]
  1301. item.text = (t)? t:(_RGBTxtBegin + c + _RGBTxtEnd)
  1302. item.layer.childNodes[0].childNodes[0].childNodes[0].title = item.text
  1303. item.show(true)
  1304. } else {
  1305. item.show(false)
  1306. }
  1307. }
  1308. }
  1309. }
  1310. // ================================================================================
  1311. function MenuColor_invert(lyr,inv)
  1312. // PRIVATE - DHTML Callback
  1313. // lyr [DOM Element] the element
  1314. // inv [0..1] 1 to invert
  1315. // Return [void]
  1316. {
  1317. var o=_menusItems[lyr._boIndex]
  1318. if (o && o.checked)
  1319. inv=1
  1320. lyr.childNodes[0].className="menuColor"+(inv?"sel":"")
  1321. }
  1322. // ================================================================================
  1323. function MenuColor_out()
  1324. // PRIVATE
  1325. {
  1326. MenuColor_invert(this,0);
  1327. }
  1328. // ================================================================================
  1329. function _Mcov(l)
  1330. // PRIVATE
  1331. {
  1332. l.onmouseout=MenuColor_out
  1333. MenuColor_invert(l,1);
  1334. }
  1335. // ================================================================================
  1336. function MenuColorWidget_uncheckAll()
  1337. // Uncheck all items
  1338. // Return [void]
  1339. {
  1340. var o=this,items=o.items
  1341. for (var i in items)
  1342. {
  1343. var item=items[i]
  1344. if (item.checked)
  1345. item.check(false)
  1346. }
  1347. }
  1348. // ================================================================================
  1349. function _mcc(lyr,e)
  1350. // PRIVATE - DHTML Callback
  1351. // lyr [DOM Element] the element
  1352. // e [Event] DHTML Event
  1353. // Return [void]
  1354. {
  1355. eventCancelBubble(e)
  1356. var idx=lyr._boIndex,o=_menusItems[idx]
  1357. o.par.uncheckAll()
  1358. MenuColor_invert(lyr,1,idx)
  1359. o.checked=true
  1360. o.par.show(false,0,0,true)
  1361. if (o.cb)
  1362. setTimeout("MenuItem_delayedClick("+idx+")",1)
  1363. }
  1364. // ================================================================================
  1365. // ================================================================================
  1366. //
  1367. // OBJECT newColorMenuItem (Constructor)
  1368. //
  1369. // creates a color widget item - a color square with the color name as tooltip
  1370. //
  1371. // ================================================================================
  1372. // ================================================================================
  1373. function newColorMenuItem(par,color,text,cb)
  1374. // par [MenuWidget] the parent menu
  1375. // color [String] color (r,g,b)
  1376. // text [String] the item text
  1377. // Returns [ColorMenuItem] the new instance
  1378. {
  1379. var o=newMenuItem(par,"color_"+color,text,cb)
  1380. o.color=color
  1381. // Public methods
  1382. o.attachSubMenu=null
  1383. o.getHTML=ColorMenuItem_getHTML
  1384. o.check=ColorMenuItem_check
  1385. o.menuItemType=_isColor
  1386. return o
  1387. }
  1388. // ================================================================================
  1389. function ColorMenuItem_check(check)
  1390. // Check a color menu item
  1391. // check [boolean] checks the item if true
  1392. // Return [void]
  1393. {
  1394. var o=this
  1395. if (o.checked!=check)
  1396. {
  1397. o.checked=check
  1398. if (o.layer)
  1399. MenuColor_invert(o.layer,o.checked?1:0)
  1400. }
  1401. }
  1402. // ================================================================================
  1403. //
  1404. // PUBLIC ColorMenuItem::getHTML
  1405. //
  1406. // Write the color menu widget HTML
  1407. //
  1408. // Returns
  1409. //
  1410. // [String] the HTML
  1411. //
  1412. // ================================================================================
  1413. function ColorMenuItem_getHTML()
  1414. {
  1415. var o=this,s="",d=_moz?10:12,lenTotal=o.par.items.length,index=o.menuIndex - 1;col=index%8
  1416. var len=0
  1417. for (var i = 0; i <lenTotal; i++)
  1418. {
  1419. if (o.par.items[i].menuItemType == _isColor) len++
  1420. }
  1421. var first=(col==0)
  1422. var last=(col==7)
  1423. var firstL=(index<8)
  1424. var lastL=(index>=(Math.floor((len-1)/8)*8))
  1425. var cbs=' onclick="'+_codeWinName+'._mcc(this,event);return true" oncontextmenu="'+_codeWinName+'._mcc(this,event);return false" onmousedown="'+_codeWinName+'._minb(event)" onmouseup="'+_codeWinName+'._minb(event)" onmouseover="'+_codeWinName+'._Mcov(this)" '
  1426. if (first)
  1427. s+='<tr valign="middle" align="center">'
  1428. s+='<td id="'+(o.par.id+'_item_'+o.id)+'" '+cbs+' style="padding-top:'+(firstL?2:0)+'px;padding-bottom:'+(lastL?2:0)+'px;padding-left:'+(first?3:1)+'px;padding-right:'+(last?3:1)+'px"><div class="menuColor'+(o.checked?'Sel':'')+'"><div style="cursor:'+_hand+';border:1px solid #4A657B;width:'+d+'px;height:'+d+'px;background-color:rgb('+o.color+');">'+img(_skin+'../transp.gif',10,10,null,null,o.text)+'</div></div></td>'
  1429. /*if (o.menuIndex==len-1)
  1430. {
  1431. for (var i=col;i<8;i++)
  1432. s+='<td class="menuLeftPart"></td>'
  1433. }*/
  1434. if (last)
  1435. s+='</tr>'
  1436. return s
  1437. }
  1438. // ================================================================================
  1439. // ================================================================================
  1440. //
  1441. // OBJECT newLastUsedColorMenuItem (Constructor)
  1442. //
  1443. // creates a color widget item - a color square with the color name as tooltip
  1444. //
  1445. // ================================================================================
  1446. // ================================================================================
  1447. function newLastUsedColorMenuItem(par,idx,color,text,cb)
  1448. // par [MenuWidget] the parent menu
  1449. // color [String] color (r,g,b)
  1450. // text [String] the item text
  1451. // Returns [ColorMenuItem] the new instance
  1452. {
  1453. var o=newMenuItem(par,"color_"+idx,text,cb)
  1454. o.idx=idx
  1455. o.color=color
  1456. o.menuItemType = _isLastUsedColor
  1457. // Public methods
  1458. o.attachSubMenu=null
  1459. o.check=ColorMenuItem_check
  1460. o.getHTML=LastUsedColorMenuItem_getHTML
  1461. o.init=LastUsedColorMenuItem_init
  1462. return o
  1463. }
  1464. // ================================================================================
  1465. //
  1466. // PUBLIC lastUsedColorMenuItem_getHTML::getHTML
  1467. //
  1468. // Write the color menu widget HTML
  1469. //
  1470. // Returns
  1471. //
  1472. // [String] the HTML
  1473. //
  1474. // ================================================================================
  1475. function LastUsedColorMenuItem_getHTML()
  1476. {
  1477. var o=this,s="",d=_moz?10:12
  1478. var cbs=' onclick="'+_codeWinName+'._mcc(this,event);return true" oncontextmenu="'+_codeWinName+'._mcc(this,event);return false" onmousedown="'+_codeWinName+'._minb(event)" onmouseup="'+_codeWinName+'._minb(event)" onmouseover="'+_codeWinName+'._Mcov(this)" '
  1479. s+='<td id="'+(o.par.id+'_item_'+o.id)+'" width="18" '+cbs+' style="padding-top:0px;padding-bottom:0px;padding-left:1px;padding-right:1px"><div class="menuColor'+(o.checked?'sel':'')+'"><div style="cursor:'+_hand+';border:1px solid #4A657B;width:'+d+'px;height:'+d+'px;background-color:rgb('+o.color+');">'+img(_skin+'../transp.gif',10,10,null,null,o.text)+'</div></div></td>'
  1480. return s
  1481. }
  1482. // Init widget layers
  1483. // Return [void]
  1484. function LastUsedColorMenuItem_init()
  1485. {
  1486. if (!this.hasNoLayer)
  1487. {
  1488. var o=this,id=o.par.id
  1489. o.layer=getLayer(id+'_item_'+o.id)
  1490. o.layer._boIndex=o.index
  1491. if (o.isCheck)
  1492. {
  1493. o.check(o.checked,true)
  1494. }
  1495. }
  1496. }
  1497. // ================================================================================
  1498. // ================================================================================
  1499. //
  1500. // OBJECT newScrollMenuWidget (Constructor)
  1501. //
  1502. //
  1503. // ================================================================================
  1504. // ================================================================================
  1505. function newScrollMenuWidget(id,changeCB,multi,width,lines,tooltip,dblClickCB,keyUpCB,
  1506. showLabel,label,convBlanks,beforeShowCB,menuClickCB)
  1507. // CONSTRUCTOR
  1508. // id [String] the menu id for DHTML processing
  1509. // changeCB [Function] calback when selection is changed by the user
  1510. // multi [boolean] if true, multiselection is enabled
  1511. // lines [int] number of visible lines
  1512. // tooltip [String - optional] tooltip for 508
  1513. // dblClickCB [Function] calback when an item is double-clicked
  1514. // keyUpCB [Function]
  1515. // showLabel [boolean] if true a label is displayed
  1516. // label [boolean - optional]text of the label
  1517. // convBlanks [int - optional]
  1518. // beforeShowCB [Function - Optional] callback called before menu is shown
  1519. {
  1520. var o=newWidget(id)
  1521. // Properties
  1522. o.list=newListWidget("list_"+id,ScrollMenuWidget_changeCB,multi,width,lines,tooltip,ScrollMenuWidget_dblClickCB,ScrollMenuWidget_keyUpCB,ScrollMenuWidget_clickCB)
  1523. o.list.par=o
  1524. o.label=NewLabelWidget("label_"+id,label,convBlanks)
  1525. o.showLabel=showLabel
  1526. o.changeCB=changeCB
  1527. o.menuClickCB=menuClickCB
  1528. o.dblClickCB=dblClickCB
  1529. o.keyUpCB=keyUpCB
  1530. o.beforeShowCB=beforeShowCB
  1531. o.zIndex=_menusZIndex
  1532. // Methods
  1533. o.init=ScrollMenuWidget_init
  1534. o.justInTimeInit=ScrollMenuWidget_justInTimeInit
  1535. o.setDisabled=ScrollMenuWidget_setDisabled
  1536. o.write=ScrollMenuWidget_write
  1537. o.getHTML=ScrollMenuWidget_getHTML
  1538. o.show=ScrollMenuWidget_show
  1539. o.add=ScrollMenuWidget_add
  1540. o.del=ScrollMenuWidget_del
  1541. o.getSelection=ScrollMenuWidget_getSelection
  1542. o.select=ScrollMenuWidget_select
  1543. o.valueSelect=ScrollMenuWidget_valueSelect
  1544. o.getCount=ScrollMenuWidget_getCount
  1545. // Re-use of existing MenuWidget methods
  1546. o.isShown=MenuWidget_isShown
  1547. o.captureClicks=MenuWidget_captureClicks
  1548. o.releaseClicks=MenuWidget_releaseClicks
  1549. // Click capture
  1550. o.clickCB=new Array
  1551. o.clickCBDocs=new Array
  1552. return o
  1553. }
  1554. // ================================================================================
  1555. function ScrollMenuWidget_init()
  1556. // Do nothing : should not be used
  1557. // Return [void]
  1558. {
  1559. }
  1560. // ================================================================================
  1561. function ScrollMenuWidget_justInTimeInit()
  1562. // Initialization called just before showing scrollMenu for the first time
  1563. // Return [void]
  1564. {
  1565. var o=this
  1566. o.layer=getLayer(o.id)
  1567. if (o.layer==null)
  1568. {
  1569. append2(_curDoc.body,o.getHTML());
  1570. o.layer=getLayer(o.id)
  1571. }
  1572. o.layer._widget=o.widx
  1573. o.css=o.layer.style
  1574. o.css.visibility="hidden"
  1575. //o.iframeLyr=getLayer("menuIframe_"+o.id)
  1576. //o.iframeCss=o.iframeLyr.style
  1577. o.list.init()
  1578. o.label.init()
  1579. }
  1580. // ================================================================================
  1581. function ScrollMenuWidget_setDisabled()
  1582. {
  1583. // To be implemented
  1584. }
  1585. // ================================================================================
  1586. function ScrollMenuWidget_write()
  1587. // Do nothing : should not be used
  1588. // Return [void]
  1589. {
  1590. }
  1591. // ================================================================================
  1592. function ScrollMenuWidget_getHTML()
  1593. // Return [string] the HTML sorce of this widget
  1594. {
  1595. var o=this
  1596. var s=''
  1597. //s+=o.getShadowHTML()
  1598. s+='<table dir="ltr" onmousedown="event.cancelBubble=true" id="'+o.id+'" style="display:none;" class="menuFrame" cellspacing="0" cellpadding="0" border="0"><tbody>'
  1599. s+='<tr><td align="center">'+o.list.getHTML()+'</td></tr>'
  1600. s+='<tr><td align="center">'+o.label.getHTML()+'</td></tr>'
  1601. s+='</tbody></table>'
  1602. return s
  1603. }
  1604. // ================================================================================
  1605. function ScrollMenuWidget_show(show,x,y)
  1606. // show [boolean] if true shows the menu, otherwise hide it
  1607. // x [int] menu abscissa (may be changed if the menu is outside the window)
  1608. // y [int] menu ordinate (may be changed if the menu is outside the window)
  1609. // Return [void]
  1610. {
  1611. var o=this
  1612. if (o.layer==null)
  1613. o.justInTimeInit()
  1614. var css=o.css
  1615. if (show)
  1616. {
  1617. if (o.beforeShowCB)
  1618. o.beforeShowCB()
  1619. o.captureClicks()
  1620. // Show and place menu
  1621. css.display='block'
  1622. css.zIndex=(o.zIndex+1)
  1623. css.visibility="hidden"
  1624. css.left="-1000px"
  1625. css.top="-1000px"
  1626. var w=o.getWidth()
  1627. var h=o.getHeight()
  1628. if (o.alignLeft)
  1629. x-=w
  1630. // Change coordinates if the menu is out of the window
  1631. var x2=x+w+4,y2=y+h+4
  1632. if (x2>winWidth())
  1633. x=Math.max(0,x-4-w)
  1634. if (y2>winHeight())
  1635. y=Math.max(0,y-4-h)
  1636. css.left=""+x+"px"
  1637. css.top=""+y+"px"
  1638. //hideAllInputs(x,y,w+4,h+4)
  1639. css.visibility="visible"
  1640. // Show and place menu shadow
  1641. o.iframeLyr=getDynamicBGIFrameLayer()
  1642. o.iframeCss=o.iframeLyr.style
  1643. iCss=o.iframeCss
  1644. iCss.left=""+x+"px"
  1645. iCss.top=""+y+"px"
  1646. iCss.width=""+w+"px"
  1647. iCss.height=""+h+"px"
  1648. iCss.zIndex=o.zIndex-1
  1649. iCss.display='block'
  1650. if (_ie)
  1651. {
  1652. y-=2
  1653. x-=2
  1654. }
  1655. }
  1656. else
  1657. {
  1658. releaseBGIFrame(o.iframeLyr.id)
  1659. css.display='none'
  1660. iCss.display='none'
  1661. o.releaseClicks()
  1662. }
  1663. }
  1664. // ================================================================================
  1665. function ScrollMenuWidget_add(s,val,sel,id)
  1666. // Add an item to the menu
  1667. // s [string] text displayed
  1668. // val [string] value associated with the text
  1669. // sel [boolean] if true, the <s> is selected
  1670. // id [int]
  1671. // Return [void]
  1672. {
  1673. var o=this
  1674. if (o.layer==null)
  1675. o.justInTimeInit()
  1676. o.list.add(s,val,sel,id)
  1677. }
  1678. // ================================================================================
  1679. function ScrollMenuWidget_del(i)
  1680. // Delete an item from the menu
  1681. // i [int] item index
  1682. // Return [void]
  1683. {
  1684. var o=this
  1685. if (o.layer==null)
  1686. o.justInTimeInit()
  1687. o.list.del(i)
  1688. }
  1689. // ================================================================================
  1690. function ScrollMenuWidget_getSelection()
  1691. // Return [structure] the item selected (index, value, text)
  1692. {
  1693. var o=this
  1694. if (o.layer==null)
  1695. o.justInTimeInit()
  1696. return o.list.getSelection()
  1697. }
  1698. // ================================================================================
  1699. function ScrollMenuWidget_select(i)
  1700. // Select the specified item from its index
  1701. // i [int] item index
  1702. // Return [void]
  1703. {
  1704. var o=this
  1705. if (o.layer==null)
  1706. o.justInTimeInit()
  1707. o.list.select(i)
  1708. }
  1709. // ================================================================================
  1710. function ScrollMenuWidget_valueSelect(v)
  1711. // Select the specified item form its value
  1712. // i [int] item index
  1713. // Return [void]
  1714. {
  1715. var o=this
  1716. if (o.layer==null)
  1717. o.justInTimeInit()
  1718. o.list.valueSelect(v)
  1719. }
  1720. // ================================================================================
  1721. function ScrollMenuWidget_getCount()
  1722. // Return [int] the number of item in the menu
  1723. {
  1724. var o=this
  1725. if (o.layer==null)
  1726. o.justInTimeInit()
  1727. return o.list.getCount()
  1728. }
  1729. // ================================================================================
  1730. function ScrollMenuWidget_changeCB()
  1731. // Callback called when an item is selected in the menu
  1732. // Return [void]
  1733. {
  1734. var o=this
  1735. // Don't hide the menu whenever a different item is selected in the list.
  1736. // We want to keep the menu list visible. We'll hide it only when there's a mouse click or Enter key.
  1737. //o.par.show(false)
  1738. if (o.par.changeCB)
  1739. o.par.changeCB()
  1740. }
  1741. // ================================================================================
  1742. function ScrollMenuWidget_clickCB()
  1743. // Callback called when an item is clicked in the menu
  1744. // Return [void]
  1745. {
  1746. var o=this
  1747. o.par.show(false)
  1748. if (o.par.menuClickCB)
  1749. o.par.menuClickCB()
  1750. }
  1751. // ================================================================================
  1752. function ScrollMenuWidget_dblClickCB()
  1753. // Callback called when an item is double-clicked in the menu
  1754. // Return [void]
  1755. {
  1756. var o=this
  1757. o.par.show(false)
  1758. if (o.par.dblClickCB)
  1759. o.par.dblClickCB()
  1760. }
  1761. // ================================================================================
  1762. function ScrollMenuWidget_keyUpCB(e)
  1763. // Callback called when an keyup event occurs in the menu
  1764. // Return [void]
  1765. {
  1766. var ENTER=13, ESCAPE=27
  1767. var o=this
  1768. var k=eventGetKey(e)
  1769. if (k==ENTER || k==ESCAPE)
  1770. o.par.show(false)
  1771. if (o.par.keyUpCB)
  1772. o.par.keyUpCB()
  1773. }
  1774. // ================================================================================
  1775. // ================================================================================
  1776. //
  1777. // OBJECT newButtonScrollMenuWidget (Constructor)
  1778. //
  1779. //
  1780. // ================================================================================
  1781. // ================================================================================
  1782. function newButtonScrollMenuWidget(id,label,buttonWidth,buttonTooltip,tabIndex,
  1783. changeCB,multi,menuWidth,lines,menuTooltip,dblClickCB,keyUpCB,showMenuLabel,menuLabel,convBlanks,beforeShowCB)
  1784. {
  1785. var o=newButtonWidget(id,label,ButtonScrollMenuWidget_clickCB,buttonWidth,null,buttonTooltip,tabIndex,0,_skin+"menus.gif",7,16,0,81,true,0,97)
  1786. o.menu=newScrollMenuWidget("scrollMenu_menu_"+id,changeCB,multi,menuWidth,lines,menuTooltip,dblClickCB,keyUpCB,showMenuLabel,menuLabel,convBlanks,beforeShowCB)
  1787. o.getMenu=IconMenuWidget_getMenu
  1788. o.add = ButtonScrollMenuWidget_add
  1789. return o;
  1790. }
  1791. // ================================================================================
  1792. function ButtonScrollMenuWidget_clickCB()
  1793. // PRIVATE
  1794. {
  1795. var o=this,l=o.layer;
  1796. o.menu.show(!o.menu.isShown(),getPosScrolled(l).x,getPosScrolled(l).y+o.getHeight(),null,null,o)
  1797. }
  1798. // ================================================================================
  1799. function ButtonScrollMenuWidget_add(s,val,sel,id)
  1800. {
  1801. this.menu.add(s,val,sel,id)
  1802. }
  1803. // ================================================================================
  1804. // ================================================================================
  1805. //
  1806. // OBJECT newBorderMenuItem (Constructor)
  1807. //
  1808. // creates a border widget item
  1809. //
  1810. // ================================================================================
  1811. // ================================================================================
  1812. function newBorderMenuItem(par,idx,cb,isLabel,label)
  1813. // par [MenuWidget] the parent menu
  1814. // Returns [BorderMenuItem] the new instance
  1815. {
  1816. var o=newMenuItem(par,"border_"+idx,null,cb)
  1817. o.idx=idx
  1818. o.isLabel=isLabel?isLabel:false
  1819. o.label=label?label:null
  1820. // Public methods
  1821. o.attachSubMenu=null
  1822. o.getHTML=BorderMenuItem_getHTML
  1823. o.check=BorderMenuItem_check
  1824. o.menuItemType=_isNotColor
  1825. return o
  1826. }
  1827. // ================================================================================
  1828. function BorderMenuItem_check(check)
  1829. // Check a color menu item
  1830. // check [boolean] checks the item if true
  1831. // Return [void]
  1832. {
  1833. var o=this
  1834. if (o.checked!=check)
  1835. {
  1836. o.checked=check
  1837. if (o.layer)
  1838. BorderMenuItem_invert(o.layer,o.checked?1:0)
  1839. }
  1840. }
  1841. // ================================================================================
  1842. function BorderMenuItem_getHTML()
  1843. {
  1844. var o=this,s="",d=_moz?10:12,lenTotal=o.par.items.length,index=o.menuIndex - 1;col=index%8
  1845. var cbs=' onclick="'+_codeWinName+'.MenuBordersWidget_onclickCB(this,event);return true" oncontextmenu="'+_codeWinName+'.MenuBordersWidget_onclickCB(this,event);return false" onmousedown="'+_codeWinName+'._minb(event)" onmouseup="'+_codeWinName+'._minb(event)" onmouseover="'+_codeWinName+'.MenuBordersWidget_onmouseOverCB(this)" '
  1846. var cspan=(o.isLabel?' colspan="4"':'')
  1847. var cls="menuiconborders"+(o.checked?"Sel":"")
  1848. s+='<td '+cspan+' id="'+(o.par.id+'_item_'+o.id)+'" '+cbs+' align="center"><div class="'+cls+'">'
  1849. s+=o.isLabel?convStr(o.label):simpleImgOffset(_skin+'../borders.gif',16,16,16*o.idx,0,'IconImg_'+o.id,null,_bordersTooltip[o.idx],'margin:2px;cursor:default')
  1850. s+='</div></td>'
  1851. return s
  1852. }
  1853. // ================================================================================
  1854. function BorderMenuItem_invert(lyr,inv)
  1855. // PRIVATE - DHTML Callback
  1856. // lyr [DOM Element] the element
  1857. // inv [0..1] 1 to invert
  1858. // Return [void]
  1859. {
  1860. var o=_menusItems[lyr._boIndex]
  1861. if (o && o.checked)
  1862. inv=1
  1863. lyr.childNodes[0].className="menuiconborders"+(inv?"Sel":"")
  1864. }
  1865. // ================================================================================
  1866. // ================================================================================
  1867. //
  1868. // OBJECT newMenuBordersWidget (Constructor)
  1869. //
  1870. // creates borders menu widget
  1871. //
  1872. // ================================================================================
  1873. // ================================================================================
  1874. function newMenuBordersWidget(id,hideCB,beforeShowCB,clickCB)
  1875. // id [String] the menu id for DHTML processing
  1876. // hideCB [Function - Optional] callback called when the menu is closed
  1877. // Returns [MenuBordersWidget] the new instance
  1878. {
  1879. var o=newMenuWidget(id,hideCB,beforeShowCB)
  1880. // properties
  1881. o.items=new Array
  1882. for (var i=0; i < 12; i++)
  1883. o.items[i]=newBorderMenuItem(o,i,clickCB)
  1884. var len=o.items.length
  1885. o.items[len]=newBorderMenuItem(o,12,clickCB,true,_bordersMoreColorsLabel)
  1886. o.clickCB=clickCB
  1887. // methods
  1888. o.getHTML=MenuBordersWidget_getHTML
  1889. o.hasVisibleItem=MenuBordersWidget_hasVisibleItem
  1890. o.uncheckAll=MenuBordersWidget_uncheckAll
  1891. return o
  1892. }
  1893. // ================================================================================
  1894. function MenuBordersWidget_getHTML()
  1895. // PRIVATE get the HTML
  1896. // Return [String]
  1897. {
  1898. var o=this,items=o.items
  1899. var keysCbs=' onkeydown="'+_codeWinName+'.MenuWidget_keyDown(\''+o.id+'\',event);return true" '
  1900. // we'll add the iframe with the show function
  1901. var s='<a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="startLink_'+o.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.MenuWidget_keepFocus(\''+o.id+'\');return false;" ></a>'
  1902. s+='<table style="display:none;" class="menuFrame" id="'+o.id+'" cellspacing="0" cellpadding="0" border="0" '+keysCbs+'><tbody>'
  1903. s+='<tr>'
  1904. for (var i=0; i<=3; i++)
  1905. s+=items[i].getHTML()
  1906. s+='</tr>'
  1907. s+='<tr>'
  1908. for (var i=4; i<=7; i++)
  1909. s+=items[i].getHTML()
  1910. s+='</tr>'
  1911. s+='<tr>'
  1912. for (var i=8; i<=11; i++)
  1913. s+=items[i].getHTML()
  1914. s+='</tr>'
  1915. s+='<tr>'+items[12].getHTML()+'</tr>'
  1916. s+='</tbody></table><a style="position:absolute;left:-30px;top:-30px; visibility:hidden" id="endLink_'+o.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.MenuWidget_keepFocus(\''+o.id+'\');return false;" ></a>'
  1917. return s
  1918. }
  1919. // ================================================================================
  1920. function MenuBordersWidget_hasVisibleItem()
  1921. {
  1922. return true
  1923. }
  1924. // ================================================================================
  1925. function MenuBordersWidget_uncheckAll()
  1926. // Uncheck all items
  1927. // Return [void]
  1928. {
  1929. var o=this,items=o.items
  1930. for (var i in items)
  1931. {
  1932. var item=items[i]
  1933. if (item.checked)
  1934. item.check(false)
  1935. }
  1936. }
  1937. // ================================================================================
  1938. function MenuBordersWidget_onclickCB(lyr,e)
  1939. // PRIVATE - DHTML Callback
  1940. // lyr [DOM Element] the element
  1941. // e [Event] DHTML Event
  1942. // Return [void]
  1943. {
  1944. eventCancelBubble(e)
  1945. var idx=lyr._boIndex,o=_menusItems[idx]
  1946. o.par.uncheckAll()
  1947. BorderMenuItem_invert(lyr,1,idx)
  1948. o.checked=true
  1949. o.par.show(false,0,0,true)
  1950. if (o.cb)
  1951. setTimeout("MenuItem_delayedClick("+idx+")",1)
  1952. }
  1953. // ================================================================================
  1954. function MenuBordersWidget_out()
  1955. // PRIVATE
  1956. {
  1957. BorderMenuItem_invert(this,0);
  1958. }
  1959. // ================================================================================
  1960. function MenuBordersWidget_onmouseOverCB(l)
  1961. {
  1962. l.onmouseout=MenuBordersWidget_out
  1963. BorderMenuItem_invert(l,1)
  1964. }