source: Dev/trunk/src/client/dojox/widget/tests/test_PlaceholderMenuItem.html

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 5.4 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2                "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5
6        <title>PlaceholderMenuItem Test</title>
7
8        <style type="text/css">
9                @import "../../../dojo/resources/dojo.css";
10                @import "../../../dijit/tests/css/dijitTests.css";
11        </style>
12
13        <!-- required: a default dijit theme: -->
14        <link id="themeStyles" rel="stylesheet" href="../../../dijit/themes/tundra/tundra.css">
15       
16        <!-- required: dojo.js -->
17        <script type="text/javascript" src="../../../dojo/dojo.js"
18                data-dojo-config="parseOnLoad: true, isDebug: true"></script>
19       
20        <!-- not needed, for testing alternate themes -->
21        <script type="text/javascript" src="../../../dijit/tests/_testCommon.js"></script>
22
23        <script language="JavaScript" type="text/javascript">
24                dojo.require("doh.runner");
25                dojo.require("dojox.widget.PlaceholderMenuItem");
26                dojo.require("dijit.ColorPalette");
27                dojo.require("dijit.Calendar");
28                dojo.require("dojo.parser");    // scan page for widgets and instantiate them
29        </script>
30   
31    <script language="Javascript" type="text/javascript">
32                dojo.addOnLoad(function(){
33                        doh.register("tests",
34                                [
35                                        function test_getPlaceholder(t){
36                                                var m = dijit.byId("submenu1");
37                                                t.is(3, m.getPlaceholders().length);
38                                                t.is(2, m.getPlaceholders("PHCopyPaste").length);
39                                                t.is(1, m.getPlaceholders("PH2").length);
40                                                t.is(0, m.getPlaceholders("None").length);
41                                        },
42                                        function test_replace(t){
43                                                var m = dijit.byId("submenu1"), m3 = dijit.byId("submenu3");
44                                                t.is(6, m.getChildren().length); // Placeholder counts as one
45                                                t.is(1, m3.getChildren().length); // Placeholder counts as one
46                                                dojo.forEach(m.getPlaceholders("PHCopyPaste"), function(ph){
47                                                        ph.replace([
48                                                                new dijit.MenuItem({iconClass: "dijitEditorIcon dijitEditorIconCut",
49                                                                                                        onClick: function(){alert('not actually cutting')},
50                                                                                                        label: "Cut"}),
51                                                                new dijit.MenuItem({iconClass: "dijitEditorIcon dijitEditorIconCopy",
52                                                                                                        onClick: function(){alert('not actually copying')},
53                                                                                                        label: "Copy"}),
54                                                                new dijit.MenuItem({iconClass: "dijitEditorIcon dijitEditorIconPaste",
55                                                                                                        onClick: function(){alert('not actually pasting')},
56                                                                                                        label: "Paste"})
57                                                        ]);
58                                                });
59                                                t.is(9, m.getChildren().length); // Placeholder is still there
60                                                t.is(4, m3.getChildren().length); // Placeholder is still there
61                                        },
62                                        function test_unReplace(t){
63                                                var m = dijit.byId("submenu1"), m2 = dijit.byId("submenu2");
64                                                t.is(3, m2.getChildren().length); // Placeholder counts as one
65                                                var ph = m.getPlaceholders("PH2")[0];
66                                                t.f(ph._replaced);
67                                                ph.replace([
68                                                        new dijit.MenuItem({label: "Added 1"}),
69                                                        new dijit.MenuItem({label: "Added 2"})
70                                                ]);
71                                                t.t(ph._replaced);
72                                                t.is(5, m2.getChildren().length); // Placeholder is still there
73                                                t.is(2, ph.unReplace(true).length);
74                                                t.f(ph._replaced);
75                                                t.is(3, m2.getChildren().length);
76                                                ph = m.getPlaceholders("PH2")[0];
77                                                ph.replace([
78                                                        new dijit.MenuItem({label: "Added Submenu Item"})
79                                                ]);
80                                                t.t(ph._replaced);
81                                                t.is(4, m2.getChildren().length);
82                                        },
83                                        function test_destroyRecursive(t){
84                                                var menu = new dijit.Menu(),
85                                                        ph = new dojox.widget.PlaceholderMenuItem(),
86                                                        subMenu = new dijit.Menu();
87                                                menu.addChild(ph);
88                                                t.f(ph._replaced, "ph._replaced 1");
89                                                ph.replace([
90                                                        new dijit.PopupMenuItem({label: "Popup 1", popup: subMenu})
91                                                ]);
92                                                t.t(ph._replaced, "ph._replaced 2");
93                                                ph.unReplace(true);
94                                                t.f(ph._replaced, "ph._replaced 3");
95                                                // subMenu is destroyed iff the Placeholder called
96                                                // destroyRecursive on the PopupMenuItem instead of just
97                                                // destroy.
98                                                t.t(subMenu._destroyed, "subMenu._destroyed");
99                                        }
100                                ]
101                        );
102                        doh.run();
103                });
104    </script>
105</head>
106<body class="tundra">
107
108        <div dojoType="dijit.Menu" id="submenu1" contextMenuForWindow="true" style="display: none;">
109                <div dojoType="dijit.MenuItem">First Item</div>
110                <div dojoType="dijit.MenuItem" disabled="true">Disabled Item</div>
111                <div dojoType="dijit.MenuSeparator"></div>
112                <div dojoType="dojox.widget.PlaceholderMenuItem">PHCopyPaste</div>
113<!--
114                <div dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCut"
115                        onClick="alert('not actually cutting anything, just a test!')">Cut</div>
116                <div dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconCopy"
117                        onClick="alert('not actually copying anything, just a test!')">Copy</div>
118                <div dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconPaste"
119                        onClick="alert('not actually pasting anything, just a test!')">Paste</div>
120-->
121                <div dojoType="dijit.MenuSeparator"></div>
122                <div dojoType="dijit.PopupMenuItem">
123                        <span>Enabled Submenu</span>
124                        <div dojoType="dijit.Menu" id="submenu2">
125                                <div dojoType="dijit.MenuItem" onClick="alert('Submenu 1!')">Submenu Item One</div>
126                                <div dojoType="dojox.widget.PlaceholderMenuItem">PH2</div>
127<!--
128                                <div dojoType="dijit.MenuItem" onClick="alert('Submenu 2!')">Submenu Item Two</div>
129-->
130                                <div dojoType="dijit.PopupMenuItem">
131                                        <span>Deeper Submenu</span>
132                                        <div dojoType="dijit.Menu" id="submenu3"">
133                                                <div dojoType="dojox.widget.PlaceholderMenuItem">PHCopyPaste</div>
134                                        </div>
135                                </div>
136                        </div>
137                </div>
138        </div>
139
140        <div style="padding: 1em">
141               
142                <h1 class="testTitle">PlaceholderMenuItem Test</h1>
143                left click to open the menu
144               
145        </div>
146</body>
147</html>
Note: See TracBrowser for help on using the repository browser.