]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseui.js
1 qwebirc
. ui
. WINDOW_STATUS
= 0x01 ;
2 qwebirc
. ui
. WINDOW_QUERY
= 0x02 ;
3 qwebirc
. ui
. WINDOW_CHANNEL
= 0x04 ;
4 qwebirc
. ui
. WINDOW_CUSTOM
= 0x08 ;
5 qwebirc
. ui
. WINDOW_CONNECT
= 0x10 ;
6 qwebirc
. ui
. WINDOW_MESSAGES
= 0x20 ;
8 qwebirc
. ui
. CUSTOM_CLIENT
= "custom" ;
10 qwebirc
. ui
. BaseUI
= new Class ({
12 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
13 this . options
= options
;
15 this . windows
= new QHash ();
16 this . clients
= new QHash ();
17 this . windows
. put ( qwebirc
. ui
. CUSTOM_CLIENT
, new QHash ());
18 this . windowArray
= [];
19 this . windowClass
= windowClass
;
20 this . parentElement
= parentElement
;
21 this . parentElement
. addClass ( "qwebirc" );
22 this . parentElement
. addClass ( "qwebirc-" + uiName
);
23 this . firstClient
= false ;
24 this . commandhistory
= new qwebirc
. irc
. CommandHistory ();
27 this . windowFocused
= true ;
29 if ( Browser
. Engine
. trident
) {
30 var checkFocus = function () {
31 var hasFocus
= document
. hasFocus ();
32 if ( hasFocus
!= this . windowFocused
) {
33 this . windowFocused
= hasFocus
;
34 this . focusChange ( hasFocus
);
38 checkFocus
. periodical ( 100 , this );
40 var blur = function () { if ( this . windowFocused
) { this . windowFocused
= false ; this . focusChange ( false ); } }. bind ( this );
41 var focus = function () { if (! this . windowFocused
) { this . windowFocused
= true ; this . focusChange ( true ); } }. bind ( this );
43 /* firefox requires both */
45 document
. addEvent ( "blur" , blur
);
46 window
. addEvent ( "blur" , blur
);
47 document
. addEvent ( "focus" , focus
);
48 window
. addEvent ( "focus" , focus
);
51 newClient : function ( client
) {
52 client
. id
= String ( this . clientId
++);
53 client
. hilightController
= new qwebirc
. ui
. HilightController ( client
);
54 client
. addEvent ( "signedOn" , function () {
55 this . fireEvent ( "signedOn" , client
);
57 this . windows
. put ( client
. id
, new QHash ());
58 this . clients
. put ( client
. id
, client
);
59 var w
= this . newWindow ( client
, qwebirc
. ui
. WINDOW_STATUS
, "Status" );
61 if (! this . firstClient
) {
62 this . firstClient
= true ;
63 w
. addLine ( "" , "qwebirc v" + qwebirc
. VERSION
);
64 w
. addLine ( "" , "Copyright (C) 2008-2014 Chris Porter and the qwebirc project." );
65 w
. addLine ( "" , "http://www.qwebirc.org" );
66 w
. addLine ( "" , "Licensed under the GNU General Public License, Version 2." );
70 getClientId : function ( client
) {
71 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) {
72 return qwebirc
. ui
. CUSTOM_CLIENT
;
77 getWindowIdentifier : function ( client
, type
, name
) {
78 if ( type
== qwebirc
. ui
. WINDOW_MESSAGES
)
80 if ( type
== qwebirc
. ui
. WINDOW_STATUS
)
83 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) /* HACK */
86 return "_" + client
. toIRCLower ( name
);
88 newWindow : function ( client
, type
, name
) {
89 var w
= this . getWindow ( client
, type
, name
);
93 var wId
= this . getWindowIdentifier ( client
, type
, name
);
94 var w
= new this . windowClass ( this , client
, type
, name
, wId
);
95 this . windows
. get ( this . getClientId ( client
)). put ( wId
, w
);
96 this . windowArray
. push ( w
);
100 getWindow : function ( client
, type
, name
) {
101 var c
= this . windows
. get ( this . getClientId ( client
));
105 return c
. get ( this . getWindowIdentifier ( client
, type
, name
));
107 getActiveWindow : function () {
110 getActiveIRCWindow : function ( client
) {
111 if (! this . active
|| this . active
. type
== qwebirc
. ui
. WINDOW_CUSTOM
) {
112 return this . windows
. get ( this . getClientId ( client
)). get ( this . getWindowIdentifier ( client
, qwebirc
. ui
. WINDOW_STATUS
));
117 __setActiveWindow : function ( window
) {
118 this . active
= window
;
120 renameWindow : function ( window
, name
) {
121 if ( this . getWindow ( window
. client
, window
. type
, name
))
124 var clientId
= this . getClientId ( window
. client
);
125 var index
= this . windowArray
. indexOf ( window
);
129 this . windows
. get ( clientId
). remove ( window
. identifier
);
131 var window
= this . windowArray
[ index
];
133 window
. identifier
= this . getWindowIdentifier ( window
. client
, window
. type
, window
. name
);
135 this . windows
. get ( clientId
). put ( window
. identifier
, this . windowArray
[ index
]);
138 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
140 window
. rename ( window
. name
);
143 selectWindow : function ( window
) {
145 this . active
. deselect ();
146 window
. select (); /* calls setActiveWindow */
147 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
149 updateTitle : function ( text
) {
150 document
. title
= text
;
152 nextWindow : function ( direction
) {
153 if ( this . windowArray
. length
== 0 || ! this . active
)
159 var index
= this . windowArray
. indexOf ( this . active
);
163 index
= index
+ direction
;
165 index
= this . windowArray
. length
- 1 ;
166 } else if ( index
>= this . windowArray
. length
) {
170 this . selectWindow ( this . windowArray
[ index
]);
172 prevWindow : function () {
175 __closed : function ( window
) {
177 this . active
= undefined ;
178 if ( this . windowArray
. length
== 1 ) {
179 this . windowArray
= [];
181 var index
= this . windowArray
. indexOf ( window
);
184 } else if ( index
== 0 ) {
185 this . selectWindow ( this . windowArray
[ 1 ]);
187 this . selectWindow ( this . windowArray
[ index
- 1 ]);
192 this . windowArray
= this . windowArray
. erase ( window
);
193 this . windows
. get ( this . getClientId ( window
. client
)). remove ( window
. identifier
);
196 this shouldn't be called by overriding classes!
197 they should implement their own!
198 some form of user input MUST be received before an
199 IRC connection is made, else users are going to get
200 tricked into getting themselves glined
202 loginBox : function ( callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
203 qwebirc
. ui
. GenericLoginBox ( this . parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this . options
. networkName
);
205 focusChange : function ( newValue
) {
206 var window_
= this . getActiveWindow ();
207 if ($ defined ( window_
))
208 window_
. focusChange ( newValue
);
212 qwebirc
. ui
. StandardUI
= new Class ({
213 Extends : qwebirc
. ui
. BaseUI
,
214 UICommands : qwebirc
. ui
. UI_COMMANDS
,
215 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
216 this . parent ( parentElement
, windowClass
, uiName
, options
);
218 this . tabCompleter
= new qwebirc
. ui
. TabCompleterFactory ( this );
219 this . uiOptions
= new qwebirc
. ui
. DefaultOptionsClass ( this , options
. uiOptionsArg
);
220 this . customWindows
= new QHash ();
222 this . __styleValues
= { hue : this . uiOptions
. STYLE_HUE
, saturation : 0 , lightness : 0 , textHue : this . uiOptions
. STYLE_HUE
, textSaturation : 0 , textLightness : 0 };
223 if ($ defined ( this . options
. hue
)) this . __styleValues
. hue
= this . options
. hue
;
224 if ($ defined ( this . options
. saturation
)) this . __styleValues
. saturation
= this . options
. saturation
;
225 if ($ defined ( this . options
. lightness
)) this . __styleValues
. lightness
= this . options
. lightness
;
226 if ($ defined ( this . options
. thue
)) this . __styleValues
. textHue
= this . options
. thue
;
227 if ($ defined ( this . options
. tsaturation
)) this . __styleValues
. textSaturation
= this . options
. tsaturation
;
228 if ($ defined ( this . options
. tlightness
)) this . __styleValues
. textLightness
= this . options
. tlightness
;
230 document
. addEvent ( "keydown" , this . __handleHotkey
. bind ( this ));
232 __handleHotkey : function ( x
) {
234 if (! x
. alt
|| x
. control
) {
235 if (( x
. key
== "backspace" || x
. key
== "/" ) && ! this . getInputFocused ( x
)) {
238 } else if ( x
. key
== "a" || x
. key
== "A" ) {
240 var highestIndex
= - 1 ;
243 for ( var i
= 0 ; i
< this . windowArray
. length
; i
++) {
244 var h
= this . windowArray
[ i
]. hilighted
;
250 if ( highestIndex
> - 1 )
251 this . selectWindow ( this . windowArray
[ highestIndex
]);
252 } else if ( x
. key
>= '0' && x
. key
<= '9' ) {
255 number
= x
. key
- '0' ;
261 if ( number
>= this . windowArray
. length
)
264 this . selectWindow ( this . windowArray
[ number
]);
265 } else if ( x
. key
== "left" ) {
268 } else if ( x
. key
== "right" ) {
277 getInputFocused : function ( x
) {
278 if ($$( "input" ). indexOf ( x
. target
) == - 1 && $$( "textarea" ). indexOf ( x
. target
) == - 1 )
282 newCustomWindow : function ( name
, select
, type
) {
284 type
= qwebirc
. ui
. WINDOW_CUSTOM
;
286 var w
= this . newWindow ( qwebirc
. ui
. CUSTOM_CLIENT
, type
, name
);
287 w
. addEvent ( "close" , function ( w
) {
288 this . windows
. get ( qwebirc
. ui
. CUSTOM_CLIENT
). remove ( w
. identifier
);
292 this . selectWindow ( w
);
296 addCustomWindow : function ( windowName
, class_
, cssClass
, options
) {
297 if (!$ defined ( options
))
300 if ( this . customWindows
. contains ( windowName
)) {
301 this . selectWindow ( this . customWindows
. get ( windowName
));
305 var d
= this . newCustomWindow ( windowName
, true );
306 this . customWindows
. put ( windowName
, d
);
308 d
. addEvent ( "close" , function () {
309 this . customWindows
. remove ( windowName
);
313 d
. lines
. addClass ( "qwebirc-" + cssClass
);
315 var ew
= new class_ ( d
. lines
, options
);
316 ew
. addEvent ( "close" , function () {
322 embeddedWindow : function () {
323 this . addCustomWindow ( "Add webchat to your site" , qwebirc
. ui
. EmbedWizard
, "embeddedwizard" , { baseURL : this . options
. baseURL
, uiOptions : this . uiOptions
, optionsCallback : function () {
324 this . optionsWindow ();
327 optionsWindow : function () {
328 this . addCustomWindow ( "Options" , qwebirc
. ui
. OptionsPane
, "optionspane" , this . uiOptions
);
330 aboutWindow : function () {
331 this . addCustomWindow ( "About" , qwebirc
. ui
. AboutPane
, "aboutpane" , this . uiOptions
);
333 privacyWindow : function () {
334 this . addCustomWindow ( "Privacy policy" , qwebirc
. ui
. PrivacyPolicyPane
, "privacypolicypane" , this . uiOptions
);
336 feedbackWindow : function () {
337 this . addCustomWindow ( "Feedback" , qwebirc
. ui
. FeedbackPane
, "feedbackpane" , this . uiOptions
);
339 helpWindow : function () {
340 this . addCustomWindow ( "Help!" , qwebirc
. ui
. HelpPane
, "helppane" , this . uiOptions
);
342 urlDispatcher : function ( name
, window
) {
343 if ( name
== "embedded" )
344 return [ "a" , this . embeddedWindow
. bind ( this )];
346 if ( name
== "options" )
347 return [ "a" , this . optionsWindow
. bind ( this )];
349 /* doesn't really belong here */
350 if ( name
== "whois" ) {
351 return [ "span" , function ( nick
) {
352 if ( this . uiOptions
. QUERY_ON_NICK_CLICK
) {
353 window
. client
. exec ( "/QUERY " + nick
);
355 window
. client
. exec ( "/WHOIS " + nick
);
362 tabComplete : function ( element
) {
363 this . tabCompleter
. tabComplete ( element
);
365 resetTabComplete : function () {
366 this . tabCompleter
. reset ();
368 setModifiableStylesheet : function ( name
) {
369 this . __styleSheet
= new qwebirc
. ui
. style
. ModifiableStylesheet ( qwebirc
. global
. staticBaseURL
+ "css/" + name
+ qwebirc
. FILE_SUFFIX
+ ".mcss" );
370 this . setModifiableStylesheetValues ({});
372 setModifiableStylesheetValues : function ( values
) {
374 this . __styleValues
[ k
] = values
[ k
];
376 if (!$ defined ( this . __styleSheet
))
379 var back
= { hue : this . __styleValues
. hue
, lightness : this . __styleValues
. lightness
, saturation : this . __styleValues
. saturation
};
380 var front
= { hue : this . __styleValues
. textHue
, lightness : this . __styleValues
. textLightness
, saturation : this . __styleValues
. textSaturation
};
382 if (! this . __styleValues
. textHue
&& ! this . __styleValues
. textLightness
&& ! this . __styleValues
. textSaturation
)
390 this . __styleSheet
. set ( function () {
391 var mode
= arguments
[ 0 ];
393 var t
= colours
[ arguments
[ 2 ]];
394 var x
= new Color ( arguments
[ 1 ]);
395 var c
= x
. setHue ( t
. hue
). setSaturation ( x
. hsb
[ 1 ] + t
. saturation
). setBrightness ( x
. hsb
[ 2 ] + t
. lightness
);
396 if ( c
== "255,255,255" ) /* IE confuses white with transparent... */
399 return "rgb(" + c
+ ")" ;
400 } else if ( mode
== "o" ) {
401 return this . uiOptions
[ arguments
[ 1 ]] ? arguments
[ 2 ] : arguments
[ 3 ];
407 qwebirc
. ui
. NotificationUI
= new Class ({
408 Extends : qwebirc
. ui
. StandardUI
,
409 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
410 this . parent ( parentElement
, windowClass
, uiName
, options
);
412 this . __beeper
= new qwebirc
. ui
. Beeper ( this . uiOptions
);
413 this . __flasher
= new qwebirc
. ui
. Flasher ( this . uiOptions
);
414 this . __notifier
= new qwebirc
. ui
. Notifier ( this . uiOptions
);
416 this . cancelFlash
= this . __flasher
. cancelFlash
. bind ( this . __flasher
);
419 this . __beeper
. beep ();
421 notify : function ( title
, message
, callback
) {
422 this . __beeper
. beep ();
423 this . __flasher
. flash ();
424 this . __notifier
. notify ( title
, message
, callback
);
426 setBeepOnMention : function ( value
) {
428 this . __beeper
. soundInit ();
430 setNotifications : function ( value
) {
431 this . __notifier
. setEnabled ( value
);
433 updateTitle : function ( text
) {
434 if ( this . __flasher
. updateTitle ( text
))
437 focusChange : function ( value
) {
439 this . __flasher
. focusChange ( value
);
440 this . __notifier
. focusChange ( value
);
444 qwebirc
. ui
. NewLoginUI
= new Class ({
445 Extends : qwebirc
. ui
. NotificationUI
,
446 loginBox : function ( callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
447 this . postInitialize ();
449 /* I'd prefer something shorter and snappier! */
450 var w
= this . newCustomWindow ( "Connect" , true , qwebirc
. ui
. WINDOW_CONNECT
);
451 var callback = function ( args
) {
456 qwebirc
. ui
. GenericLoginBox ( w
. lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this . options
. networkName
);
460 qwebirc
. ui
. QuakeNetUI
= new Class ({
461 Extends : qwebirc
. ui
. NewLoginUI
,
462 urlDispatcher : function ( name
, window
) {
463 if ( name
== "qwhois" ) {
464 return [ "span" , function ( auth
) {
465 this . client
. exec ( "/MSG Q whois #" + auth
);
468 return this . parent ( name
, window
);
471 if (! qwebirc
. auth
. loggedin ())
473 if ( confirm ( "Log out?" )) {
474 this . clients
. each ( function ( k
, v
) {
475 v
. quit ( "Logged out" );
479 var foo = function () { document
. location
= qwebirc
. global
. dynamicBaseURL
+ "auth?logout=1" ; };
485 qwebirc
. ui
. RootUI
= qwebirc
. ui
. QuakeNetUI
;
487 qwebirc
. ui
. RequestTransformHTML = function ( options
) {
488 var HREF_ELEMENTS
= {
492 var update
= options
. update
;
493 var onSuccess
= options
. onSuccess
;
495 var fixUp = function ( node
) {
496 if ( node
. nodeType
!= 1 )
499 var tagName
= node
. nodeName
. toUpperCase ();
500 if ( HREF_ELEMENTS
[ tagName
]) {
501 var attr
= node
. getAttribute ( "transform_attr" );
502 var value
= node
. getAttribute ( "transform_value" );
503 if ($ defined ( attr
) && $ defined ( value
)) {
504 node
. removeAttribute ( "transform_attr" );
505 node
. removeAttribute ( "transform_value" );
506 node
. setAttribute ( attr
, qwebirc
. global
. staticBaseURL
+ value
);
510 for ( var i
= 0 ; i
< node
. childNodes
. length
; i
++)
511 fixUp ( node
. childNodes
[ i
]);
514 delete options
[ "update" ];
515 options
. onSuccess = function ( tree
, elements
, html
, js
) {
516 var container
= new Element ( "div" );
517 container
. set ( "html" , html
);
521 while ( container
. childNodes
. length
> 0 ) {
522 var x
= container
. firstChild
;
523 container
. removeChild ( x
);
524 update
. appendChild ( x
);
529 return new Request
. HTML ( options
);