2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "JSMenuItem.h"
25 #include <NGObjWeb/NGObjWeb.h>
26 #include <NGObjWeb/WEClientCapabilities.h>
29 @implementation JSMenu
31 - (id)initWithName:(NSString *)_name
32 associations:(NSDictionary *)_config
33 template:(WOElement *)_subs
35 if((self = [super initWithName:_name associations:_config template:_subs])) {
36 self->fgColor = OWGetProperty(_config,@"fgColor");
37 self->bgColor = OWGetProperty(_config,@"bgColor");
38 self->fgColorHigh = OWGetProperty(_config,@"fgColorHigh");
39 self->bgColorHigh = OWGetProperty(_config,@"bgColorHigh");
40 self->borderColor = OWGetProperty(_config,@"borderColor");
41 self->borderWidth = OWGetProperty(_config,@"borderWidth");
42 self->fontSize = OWGetProperty(_config,@"fontSize");
43 self->width = OWGetProperty(_config,@"width");
44 self->leftPadding = OWGetProperty(_config,@"leftPadding");
45 self->string = OWGetProperty(_config,@"string");
46 self->bindAtId = OWGetProperty(_config,@"bindAtId");
47 self->align = OWGetProperty(_config,@"align");
48 self->tag = OWGetProperty(_config,@"tag");
50 self->template = [_subs retain];
56 [self->fgColor release];
57 [self->bgColor release];
58 [self->fgColorHigh release];
59 [self->bgColorHigh release];
60 [self->borderWidth release];
61 [self->fontSize release];
62 [self->width release];
63 [self->leftPadding release];
64 [self->string release];
65 [self->bindAtId release];
66 [self->align release];
68 [self->template release];
72 /* handling requests */
74 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
75 return [self->template invokeActionForRequest:_req inContext:_ctx];
78 /* generate response */
80 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
83 NSString *eid; // [_ctx elementID]
84 WEClientCapabilities *ccaps;
87 eid = [[[_ctx elementID] componentsSeparatedByString:@"."]
88 componentsJoinedByString:@"_"];
89 comp = [_ctx component];
90 ccaps = [[_ctx request] clientCapabilities];
91 ie = [ccaps isJavaScriptBrowser] && [ccaps isInternetExplorer];
92 ns = [ccaps isJavaScriptBrowser] && [ccaps isNetscape];
94 [_ctx setObject:eid forKey:@"eid"];
99 [_response appendContentString:@"<font size=\"-1\">["];
100 [self->template appendToResponse:_response inContext:_ctx];
101 [_response appendContentString:@"]</font>"];
106 if ([_ctx objectForKey:@"jsmenu_included"] == nil) {
107 [_ctx setObject:@"done" forKey:@"jsmenu_included"];
108 tmp = [[NSString alloc] initWithFormat:
111 @" font:%@pt sans-serif;\n"
113 @" padding-left:%@;\n"
114 @" background-Color:%@;\n"
118 @".highlightItem {\n"
119 @" font:%@pt sans-serif;\n"
121 @" padding-left:%@;\n"
122 @" background-Color:%@;\n"
127 [self->fontSize stringValueInComponent:comp],
128 [self->width stringValueInComponent:comp],
129 [self->leftPadding stringValueInComponent:comp],
130 [self->bgColor stringValueInComponent:comp],
131 [self->fgColor stringValueInComponent:comp],
132 [self->align stringValueInComponent:comp],
133 [self->fontSize stringValueInComponent:comp],
134 [self->width stringValueInComponent:comp],
135 [self->leftPadding stringValueInComponent:comp],
136 [self->bgColorHigh stringValueInComponent:comp],
137 [self->fgColorHigh stringValueInComponent:comp],
138 [self->align stringValueInComponent:comp]];
139 [_response appendContentString:tmp];
142 tmp = [[NSString alloc] initWithFormat:
143 @"<script language=\"javascript\">\n"
145 @"function displayMenu(m) {\n"
147 @" if(m.parentNode != event.srcElement)\n"
150 @" m.style.posLeft=event.clientX+document.body.scrollLeft;\n"
151 @" m.style.posTop=event.clientY+document.body.scrollTop;\n"
152 @" if(document.body.clientWidth<event.clientX+%@+5)\n"
153 @" m.style.posLeft-=%@;\n"
154 @" m.style.display=\"\";\n"
155 @" m.setCapture();\n"
158 @"function switchMenu() {\n"
159 @" el=event.srcElement;\n"
160 @" if(el.className==\"menuItem\")\n"
161 @" el.className=\"highlightItem\";\n"
162 @" else if(el.className==\"highlightItem\")\n"
163 @" el.className=\"menuItem\";\n"
165 @"function clickMenu(m) {\n"
166 @" m.releaseCapture();\n"
167 @" m.style.display=\"none\";\n"
168 @" el=event.srcElement;\n"
169 @" if(m==el.parentNode)window.location=el.url;\n"
172 @"function closeMenu() {\n"
173 @" if(menuOpened==null)"
175 @" menuOpened.releaseCapture();\n"
176 @" menuOpened.style.display=\"none\";\n"
177 @" menuOpened=null;\n"
180 [self->width stringValueInComponent:comp],
181 [self->width stringValueInComponent:comp]];
182 [_response appendContentString:tmp];
185 tmp = [[NSString alloc] initWithFormat:
186 @"<div id=\"m%@\" onclick=\"return clickMenu(m%@);\" "
187 @"onmouseover=\"switchMenu();\" "
188 @"onmouseout=\"switchMenu();\" "
189 @"style=\"position:absolute;display:none;width:%@;"
190 @"background-Color:%@;border:outset %@px %@;"
191 @"text-decoration:none\">",
193 [self->width stringValueInComponent:comp],
194 [self->bgColor stringValueInComponent:comp],
195 [self->borderWidth stringValueInComponent:comp],
196 [self->borderColor stringValueInComponent:comp]];
197 [_response appendContentString:tmp];
200 [self->template appendToResponse:_response inContext:_ctx];
202 [_response appendContentString:@"</div>"];
204 if ([self->tag stringValueInComponent:comp] != nil)
205 tmp = [[NSString alloc] initWithFormat:
206 @"<script id=\"s%@\" language=\"javascript\">"
207 @"function c%@(){return displayMenu(m%@);}"
208 @"tmp=document.getElementById(\"s%@\");"
210 @"while((tmp.tagName!=\"%@\")&&i--)"
211 @"tmp=tmp.parentNode;"
212 @"tmp.oncontextmenu=c%@;"
215 [self->tag stringValueInComponent:comp], eid];
218 tmp = [[NSString alloc] initWithFormat:
219 @"<script id=\"s%@\" language=\"javascript\">"
220 @"function c%@() { return displayMenu(m%@); }"
221 @"s%@.parentNode.oncontextmenu=c%@;"
223 eid, eid, eid, eid, eid];
224 [_response appendContentString:tmp];
229 if ([_ctx objectForKey:@"jsmenu_included"] == nil) {
230 tmp = [[NSString alloc] initWithFormat:
231 @"<script language=\"javascript1.2\" "
232 @"src=\"http://inster:9000/sascha/menu07.js\">"
234 @"<script language=\"javascript1.2\">"
235 @"function onLoad(){m%@.writeMenus();}</script>\n",
237 [_response appendContentString:tmp];
241 tmp = [[NSString alloc] initWithFormat:
242 @"<script language=\"javascript1.2\">\n"
243 @"m%@=new Menu();",eid];
244 [_response appendContentString:tmp];
247 [self->template appendToResponse:_response inContext:_ctx];
249 tmp = [[NSString alloc] initWithFormat:
251 @"<a href=\"#\" onclick=\"showMenu(m%@);return false;\">"
253 [_response appendContentString:tmp];
256 [_ctx setObject:@"done" forKey:@"jsmenu_included"];