addMenu-1.html

<HTML>

<HEAD>

<script>var dFrameFilePath = '../../../'</script>

<script language="Javascript" src="../../../lib/dFrameAPI.js"></script>

<script language="Javascript">

//Global

//var contextMenu1, contextMenu2, currentMenu

//Style

DFrameAPI.include('styles/colors/styleColors.js')

DFrameAPI.onLoad = function(){

//DFrameAPI.checkStyles(true)

dFrame = new DFrame([10, 10, 90, 90], 'addMenu-1.html', dFrameStyle)

var fnt = '<font face=Arial size=2>'

var txt = fnt + '3 Menus starting from the same Menu arrays definitions:'

txt += '<br>' + fnt + '- Tree Menu.'

txt += '<br>' + fnt + '- Pop-up Menu.'

txt += '<br>' + fnt + '- Context Menu (right-click on mouse).'

dFrame.addText([20, 20], txt)

//Define arrays for a sub Menu

subMenuDef = new Array()

subMenuDef[0] = new Array('Button', 'New', 'alert("Click !")')

subMenuDef[1] = new Array('Button', 'Open', 'alert("Click !")')

//Define arrays for the main menu

var menuDef = new Array()

menuDef[0] = new Array('Button', 'Documents', subMenuDef)

menuDef[1] = new Array('Button', 'Exit', 'thisDFrame.closeFrame()')

//Add a tree Menu, on a vertical bar

var bar = dFrame.addBar('', 'LEFT')

bar.setAutoWidth('CONTENT')

var menu = bar.addMenu(menuDef, ['*', '*']);

menu.setIsTree(true)

menu.setBordersWidth([2, 1])

menu.setItemsSpacing([-2, -1])

menu.setBackgroundColor(['#397375', '#18494A'])

//Add a pop-up Menu

var bar = dFrame.addBar('TOP')

var menu = bar.addMenu(menuDef, null, 'File', null);

menu.setIsTree(false)

//Add a context Menu, from the previous Menu array definition

contextMenu1 = dFrame.addContextMenu(menuDef);

contextMenu1.setBordersWidth(1)

contextMenu1.setItemsSpacing(-1)

contextMenu1.setBackgroundColor('#639E63')

//Define arrays for a new context Menu

//Define arrays for a sub Menu

subMenuDef1 = new Array()

subMenuDef1[0] = new Array('Button', 'Sub-item1', 'alert("Click !")')

subMenuDef1[1] = new Array('Button', 'Sub-item2', 'alert("Click !")')

var menuDef1 = new Array()

menuDef1[0] = new Array('Button', 'Item 1', subMenuDef1)

menuDef1[1] = new Array('Button', 'Item 2', 'alert("CLick !")')

//Add a context Menu, from the previous Menu array definition

contextMenu2 = dFrame.addContextMenu(menuDef1);

contextMenu2.setBordersWidth([4, 2])

contextMenu2.setItemsVSpacing([4, 2])

contextMenu2.setBackgroundColor('#9C6563')

button = dFrame.addButton('Use context Menu 2', 'this.flipFlop()')

button.flipFlop = function() {

if (currentMenu == contextMenu1) {

this.setText('Use context Menu 1');

this.setBgSelected('#9C6563')

currentMenu = contextMenu2

} else {

this.setText('Use context Menu 2');

this.setBgSelected('#639E63')

currentMenu = contextMenu1

}

dFrame.useContextMenu(currentMenu)

}

currentMenu = contextMenu1

dFrame.show()

}

</script>

</HEAD>

</HTML>