2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "JSMenuItem.h"
24 #include <NGObjWeb/NGObjWeb.h>
25 #include <NGObjWeb/WEClientCapabilities.h>
28 @implementation JSMenu
30 - (id)initWithName:(NSString *)_name
31 associations:(NSDictionary *)_config
32 template:(WOElement *)_subs
34 if((self = [super initWithName:_name associations:_config template:_subs])) {
35 self->fgColor = OWGetProperty(_config,@"fgColor");
36 self->bgColor = OWGetProperty(_config,@"bgColor");
37 self->fgColorHigh = OWGetProperty(_config,@"fgColorHigh");
38 self->bgColorHigh = OWGetProperty(_config,@"bgColorHigh");
39 self->borderColor = OWGetProperty(_config,@"borderColor");
40 self->borderWidth = OWGetProperty(_config,@"borderWidth");
41 self->fontSize = OWGetProperty(_config,@"fontSize");
42 self->width = OWGetProperty(_config,@"width");
43 self->leftPadding = OWGetProperty(_config,@"leftPadding");
44 self->string = OWGetProperty(_config,@"string");
45 self->bindAtId = OWGetProperty(_config,@"bindAtId");
46 self->align = OWGetProperty(_config,@"align");
47 self->tag = OWGetProperty(_config,@"tag");
49 self->template = [_subs retain];
55 [self->fgColor release];
56 [self->bgColor release];
57 [self->fgColorHigh release];
58 [self->bgColorHigh release];
59 [self->borderWidth release];
60 [self->fontSize release];
61 [self->width release];
62 [self->leftPadding release];
63 [self->string release];
64 [self->bindAtId release];
65 [self->align release];
67 [self->template release];
71 /* handling requests */
73 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
74 return [self->template invokeActionForRequest:_req inContext:_ctx];
77 /* generate response */
79 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
82 NSString *eid; // [_ctx elementID]
83 WEClientCapabilities *ccaps;
86 eid = [[[_ctx elementID] componentsSeparatedByString:@"."]
87 componentsJoinedByString:@"_"];
88 comp = [_ctx component];
89 ccaps = [[_ctx request] clientCapabilities];
90 ie = [ccaps isJavaScriptBrowser] && [ccaps isInternetExplorer];
91 ns = [ccaps isJavaScriptBrowser] && [ccaps isNetscape];
93 [_ctx setObject:eid forKey:@"eid"];
98 [_response appendContentString:@"<font size=\"-1\">["];
99 [self->template appendToResponse:_response inContext:_ctx];
100 [_response appendContentString:@"]</font>"];
105 if ([_ctx objectForKey:@"jsmenu_included"] == nil) {
106 [_ctx setObject:@"done" forKey:@"jsmenu_included"];
107 tmp = [[NSString alloc] initWithFormat:
110 @" font:%@pt sans-serif;\n"
112 @" padding-left:%@;\n"
113 @" background-Color:%@;\n"
117 @".highlightItem {\n"
118 @" font:%@pt sans-serif;\n"
120 @" padding-left:%@;\n"
121 @" background-Color:%@;\n"
126 [self->fontSize stringValueInComponent:comp],
127 [self->width stringValueInComponent:comp],
128 [self->leftPadding stringValueInComponent:comp],
129 [self->bgColor stringValueInComponent:comp],
130 [self->fgColor stringValueInComponent:comp],
131 [self->align stringValueInComponent:comp],
132 [self->fontSize stringValueInComponent:comp],
133 [self->width stringValueInComponent:comp],
134 [self->leftPadding stringValueInComponent:comp],
135 [self->bgColorHigh stringValueInComponent:comp],
136 [self->fgColorHigh stringValueInComponent:comp],
137 [self->align stringValueInComponent:comp]];
138 [_response appendContentString:tmp];
141 tmp = [[NSString alloc] initWithFormat:
142 @"<script language=\"javascript\">\n"
144 @"function displayMenu(m) {\n"
146 @" if(m.parentNode != event.srcElement)\n"
149 @" m.style.posLeft=event.clientX+document.body.scrollLeft;\n"
150 @" m.style.posTop=event.clientY+document.body.scrollTop;\n"
151 @" if(document.body.clientWidth<event.clientX+%@+5)\n"
152 @" m.style.posLeft-=%@;\n"
153 @" m.style.display=\"\";\n"
154 @" m.setCapture();\n"
157 @"function switchMenu() {\n"
158 @" el=event.srcElement;\n"
159 @" if(el.className==\"menuItem\")\n"
160 @" el.className=\"highlightItem\";\n"
161 @" else if(el.className==\"highlightItem\")\n"
162 @" el.className=\"menuItem\";\n"
164 @"function clickMenu(m) {\n"
165 @" m.releaseCapture();\n"
166 @" m.style.display=\"none\";\n"
167 @" el=event.srcElement;\n"
168 @" if(m==el.parentNode)window.location=el.url;\n"
171 @"function closeMenu() {\n"
172 @" if(menuOpened==null)"
174 @" menuOpened.releaseCapture();\n"
175 @" menuOpened.style.display=\"none\";\n"
176 @" menuOpened=null;\n"
179 [self->width stringValueInComponent:comp],
180 [self->width stringValueInComponent:comp]];
181 [_response appendContentString:tmp];
184 tmp = [[NSString alloc] initWithFormat:
185 @"<div id=\"m%@\" onclick=\"return clickMenu(m%@);\" "
186 @"onmouseover=\"switchMenu();\" "
187 @"onmouseout=\"switchMenu();\" "
188 @"style=\"position:absolute;display:none;width:%@;"
189 @"background-Color:%@;border:outset %@px %@;"
190 @"text-decoration:none\">",
192 [self->width stringValueInComponent:comp],
193 [self->bgColor stringValueInComponent:comp],
194 [self->borderWidth stringValueInComponent:comp],
195 [self->borderColor stringValueInComponent:comp]];
196 [_response appendContentString:tmp];
199 [self->template appendToResponse:_response inContext:_ctx];
201 [_response appendContentString:@"</div>"];
203 if ([self->tag stringValueInComponent:comp] != nil)
204 tmp = [[NSString alloc] initWithFormat:
205 @"<script id=\"s%@\" language=\"javascript\">"
206 @"function c%@(){return displayMenu(m%@);}"
207 @"tmp=document.getElementById(\"s%@\");"
209 @"while((tmp.tagName!=\"%@\")&&i--)"
210 @"tmp=tmp.parentNode;"
211 @"tmp.oncontextmenu=c%@;"
214 [self->tag stringValueInComponent:comp], eid];
217 tmp = [[NSString alloc] initWithFormat:
218 @"<script id=\"s%@\" language=\"javascript\">"
219 @"function c%@() { return displayMenu(m%@); }"
220 @"s%@.parentNode.oncontextmenu=c%@;"
222 eid, eid, eid, eid, eid];
223 [_response appendContentString:tmp];
228 if ([_ctx objectForKey:@"jsmenu_included"] == nil) {
229 tmp = [[NSString alloc] initWithFormat:
230 @"<script language=\"javascript1.2\" "
231 @"src=\"http://inster:9000/sascha/menu07.js\">"
233 @"<script language=\"javascript1.2\">"
234 @"function onLoad(){m%@.writeMenus();}</script>\n",
236 [_response appendContentString:tmp];
240 tmp = [[NSString alloc] initWithFormat:
241 @"<script language=\"javascript1.2\">\n"
242 @"m%@=new Menu();",eid];
243 [_response appendContentString:tmp];
246 [self->template appendToResponse:_response inContext:_ctx];
248 tmp = [[NSString alloc] initWithFormat:
250 @"<a href=\"#\" onclick=\"showMenu(m%@);return false;\">"
252 [_response appendContentString:tmp];
255 [_ctx setObject:@"done" forKey:@"jsmenu_included"];