]>
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 qwebirc
. util
. __log = function ( x
) {
53 if ( typeof console
!= "undefined" )
55 this . getActiveWindow (). addLine ( null , x
);
59 newClient : function ( client
) {
60 client
. id
= String ( this . clientId
++);
61 client
. hilightController
= new qwebirc
. ui
. HilightController ( client
);
62 client
. addEvent ( "signedOn" , function () {
63 this . fireEvent ( "signedOn" , client
);
65 this . windows
. put ( client
. id
, new QHash ());
66 this . clients
. put ( client
. id
, client
);
67 var w
= this . newWindow ( client
, qwebirc
. ui
. WINDOW_STATUS
, "Status" );
69 if (! this . firstClient
) {
70 this . firstClient
= true ;
71 w
. addLine ( "" , "qwebirc v" + qwebirc
. VERSION
);
72 w
. addLine ( "" , "Copyright (C) 2008-2014 Chris Porter and the qwebirc project." );
73 w
. addLine ( "" , "http://www.qwebirc.org" );
74 w
. addLine ( "" , "Licensed under the GNU General Public License, Version 2." );
78 getClientId : function ( client
) {
79 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) {
80 return qwebirc
. ui
. CUSTOM_CLIENT
;
85 getWindowIdentifier : function ( client
, type
, name
) {
86 if ( type
== qwebirc
. ui
. WINDOW_MESSAGES
)
88 if ( type
== qwebirc
. ui
. WINDOW_STATUS
)
91 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) /* HACK */
94 return "_" + client
. toIRCLower ( name
);
96 newWindow : function ( client
, type
, name
) {
97 var w
= this . getWindow ( client
, type
, name
);
101 var wId
= this . getWindowIdentifier ( client
, type
, name
);
102 var w
= new this . windowClass ( this , client
, type
, name
, wId
);
103 this . windows
. get ( this . getClientId ( client
)). put ( wId
, w
);
104 this . windowArray
. push ( w
);
108 getWindow : function ( client
, type
, name
) {
109 var c
= this . windows
. get ( this . getClientId ( client
));
113 return c
[ this . getWindowIdentifier ( client
, type
, name
)];
115 getActiveWindow : function () {
118 getActiveIRCWindow : function ( client
) {
119 if (! this . active
|| this . active
. type
== qwebirc
. ui
. WINDOW_CUSTOM
) {
120 return this . windows
. get ( this . getClientId ( client
)). get ( this . getWindowIdentifier ( client
, qwebirc
. ui
. WINDOW_STATUS
));
125 __setActiveWindow : function ( window
) {
126 this . active
= window
;
128 renameWindow : function ( window
, name
) {
129 if ( this . getWindow ( window
. client
, window
. type
, name
))
132 var clientId
= this . getClientId ( window
. client
);
133 var index
= this . windowArray
. indexOf ( window
);
137 this . windows
. get ( clientId
). remove ( window
. identifier
);
139 var window
= this . windowArray
[ index
];
141 window
. identifier
= this . getWindowIdentifier ( window
. client
, window
. type
, window
. name
);
143 this . windows
. get ( clientId
). put ( window
. identifier
, this . windowArray
[ index
]);
146 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
148 window
. rename ( window
. name
);
151 selectWindow : function ( window
) {
153 this . active
. deselect ();
154 window
. select (); /* calls setActiveWindow */
155 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
157 updateTitle : function ( text
) {
158 document
. title
= text
;
160 nextWindow : function ( direction
) {
161 if ( this . windowArray
. length
== 0 || ! this . active
)
167 var index
= this . windowArray
. indexOf ( this . active
);
171 index
= index
+ direction
;
173 index
= this . windowArray
. length
- 1 ;
174 } else if ( index
>= this . windowArray
. length
) {
178 this . selectWindow ( this . windowArray
[ index
]);
180 prevWindow : function () {
183 __closed : function ( window
) {
185 this . active
= undefined ;
186 if ( this . windowArray
. length
== 1 ) {
187 this . windowArray
= [];
189 var index
= this . windowArray
. indexOf ( window
);
192 } else if ( index
== 0 ) {
193 this . selectWindow ( this . windowArray
[ 1 ]);
195 this . selectWindow ( this . windowArray
[ index
- 1 ]);
200 this . windowArray
= this . windowArray
. erase ( window
);
201 this . windows
. get ( this . getClientId ( window
. client
)). remove ( window
. identifier
);
204 this shouldn't be called by overriding classes!
205 they should implement their own!
206 some form of user input MUST be received before an
207 IRC connection is made, else users are going to get
208 tricked into getting themselves glined
210 loginBox : function ( callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
211 qwebirc
. ui
. GenericLoginBox ( this . parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this . options
. networkName
);
213 focusChange : function ( newValue
) {
214 var window_
= this . getActiveWindow ();
215 if ($ defined ( window_
))
216 window_
. focusChange ( newValue
);
220 qwebirc
. ui
. StandardUI
= new Class ({
221 Extends : qwebirc
. ui
. BaseUI
,
222 UICommands : qwebirc
. ui
. UI_COMMANDS
,
223 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
224 this . parent ( parentElement
, windowClass
, uiName
, options
);
226 this . tabCompleter
= new qwebirc
. ui
. TabCompleterFactory ( this );
227 this . uiOptions
= new qwebirc
. ui
. DefaultOptionsClass ( this , options
. uiOptionsArg
);
228 this . customWindows
= new QHash ();
230 this . __styleValues
= { hue : this . uiOptions
. STYLE_HUE
, saturation : 0 , lightness : 0 };
231 if ($ defined ( this . options
. hue
)) this . __styleValues
. hue
= this . options
. hue
;
232 if ($ defined ( this . options
. saturation
)) this . __styleValues
. saturation
= this . options
. saturation
;
233 if ($ defined ( this . options
. lightness
)) this . __styleValues
. lightness
= this . options
. lightness
;
235 if ( this . options
. thue
!== null ) this . __styleValues
. textHue
= this . options
. thue
;
236 if ( this . options
. tsaturation
!== null ) this . __styleValues
. textSaturation
= this . options
. tsaturation
;
237 if ( this . options
. tlightness
!== null ) this . __styleValues
. textLightness
= this . options
. tlightness
;
239 document
. addEvent ( "keydown" , this . __handleHotkey
. bind ( this ));
241 __handleHotkey : function ( x
) {
243 if (! x
. alt
|| x
. control
) {
244 if (( x
. key
== "backspace" || x
. key
== "/" ) && ! this . getInputFocused ( x
)) {
247 } else if ( x
. key
== "a" || x
. key
== "A" ) {
249 var highestIndex
= - 1 ;
252 for ( var i
= 0 ; i
< this . windowArray
. length
; i
++) {
253 var h
= this . windowArray
[ i
]. hilighted
;
259 if ( highestIndex
> - 1 )
260 this . selectWindow ( this . windowArray
[ highestIndex
]);
261 } else if ( x
. key
>= '0' && x
. key
<= '9' ) {
264 number
= x
. key
- '0' ;
270 if ( number
>= this . windowArray
. length
)
273 this . selectWindow ( this . windowArray
[ number
]);
274 } else if ( x
. key
== "left" ) {
277 } else if ( x
. key
== "right" ) {
286 getInputFocused : function ( x
) {
287 if ($$( "input" ). indexOf ( x
. target
) == - 1 && $$( "textarea" ). indexOf ( x
. target
) == - 1 )
291 newCustomWindow : function ( name
, select
, type
) {
293 type
= qwebirc
. ui
. WINDOW_CUSTOM
;
295 var w
= this . newWindow ( qwebirc
. ui
. CUSTOM_CLIENT
, type
, name
);
296 w
. addEvent ( "close" , function ( w
) {
297 this . windows
. get ( qwebirc
. ui
. CUSTOM_CLIENT
). remove ( w
. identifier
);
301 this . selectWindow ( w
);
305 addCustomWindow : function ( windowName
, class_
, cssClass
, options
) {
306 if (!$ defined ( options
))
309 if ( this . customWindows
. contains ( windowName
)) {
310 this . selectWindow ( this . customWindows
. get ( windowName
));
314 var d
= this . newCustomWindow ( windowName
, true );
315 this . customWindows
. put ( windowName
, d
);
317 d
. addEvent ( "close" , function () {
318 this . customWindows
. remove ( windowName
);
322 d
. lines
. addClass ( "qwebirc-" + cssClass
);
324 var ew
= new class_ ( d
. lines
, options
);
325 ew
. addEvent ( "close" , function () {
331 embeddedWindow : function () {
332 this . addCustomWindow ( "Add webchat to your site" , qwebirc
. ui
. EmbedWizard
, "embeddedwizard" , { baseURL : this . options
. baseURL
, uiOptions : this . uiOptions
, optionsCallback : function () {
333 this . optionsWindow ();
336 optionsWindow : function () {
337 this . addCustomWindow ( "Options" , qwebirc
. ui
. OptionsPane
, "optionspane" , this . uiOptions
);
339 aboutWindow : function () {
340 this . addCustomWindow ( "About" , qwebirc
. ui
. AboutPane
, "aboutpane" , this . uiOptions
);
342 privacyWindow : function () {
343 this . addCustomWindow ( "Privacy policy" , qwebirc
. ui
. PrivacyPolicyPane
, "privacypolicypane" , this . uiOptions
);
345 feedbackWindow : function () {
346 this . addCustomWindow ( "Feedback" , qwebirc
. ui
. FeedbackPane
, "feedbackpane" , this . uiOptions
);
348 helpWindow : function () {
349 this . addCustomWindow ( "Help!" , qwebirc
. ui
. HelpPane
, "helppane" , this . uiOptions
);
351 urlDispatcher : function ( name
, window
) {
352 if ( name
== "embedded" )
353 return [ "a" , this . embeddedWindow
. bind ( this )];
355 if ( name
== "options" )
356 return [ "a" , this . optionsWindow
. bind ( this )];
358 /* doesn't really belong here */
359 if ( name
== "whois" ) {
360 return [ "span" , function ( nick
) {
361 if ( this . uiOptions
. QUERY_ON_NICK_CLICK
) {
362 window
. client
. exec ( "/QUERY " + nick
);
364 window
. client
. exec ( "/WHOIS " + nick
);
371 tabComplete : function ( element
) {
372 this . tabCompleter
. tabComplete ( element
);
374 resetTabComplete : function () {
375 this . tabCompleter
. reset ();
377 setModifiableStylesheet : function ( name
) {
378 this . __styleSheet
= new qwebirc
. ui
. style
. ModifiableStylesheet ( qwebirc
. global
. staticBaseURL
+ "css/" + ( QWEBIRC_DEBUG
? "debug/" : "" ) + name
+ qwebirc
. FILE_SUFFIX
+ ".mcss" );
379 this . setModifiableStylesheetValues ({});
381 setModifiableStylesheetValues : function ( values
) {
383 this . __styleValues
[ k
] = values
[ k
];
385 if (!$ defined ( this . __styleSheet
))
388 var back
= { hue : this . __styleValues
. hue
, lightness : this . __styleValues
. lightness
, saturation : this . __styleValues
. saturation
};
389 var front
= { hue : this . __styleValues
. textHue
, lightness : this . __styleValues
. textLightness
, saturation : this . __styleValues
. textSaturation
};
391 if (! this . __styleValues
. textHue
&& ! this . __styleValues
. textLightness
&& ! this . __styleValues
. textSaturation
)
399 this . __styleSheet
. set ( function () {
400 var mode
= arguments
[ 0 ];
402 var t
= colours
[ arguments
[ 2 ]];
403 var x
= new Color ( arguments
[ 1 ]);
404 var c
= x
. setHue ( t
. hue
). setSaturation ( x
. hsb
[ 1 ] + t
. saturation
). setBrightness ( x
. hsb
[ 2 ] + t
. lightness
);
405 if ( c
== "255,255,255" ) /* IE confuses white with transparent... */
408 return "rgb(" + c
+ ")" ;
409 } else if ( mode
== "o" ) {
410 return this . uiOptions
[ arguments
[ 1 ]] ? arguments
[ 2 ] : arguments
[ 3 ];
416 qwebirc
. ui
. NotificationUI
= new Class ({
417 Extends : qwebirc
. ui
. StandardUI
,
418 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
419 this . parent ( parentElement
, windowClass
, uiName
, options
);
421 this . __beeper
= new qwebirc
. ui
. Beeper ( this . uiOptions
);
422 this . __flasher
= new qwebirc
. ui
. Flasher ( this . uiOptions
);
423 this . __notifier
= new qwebirc
. ui
. Notifier ( this . uiOptions
);
425 this . cancelFlash
= this . __flasher
. cancelFlash
. bind ( this . __flasher
);
428 this . __beeper
. beep ();
430 notify : function ( title
, message
, callback
) {
431 this . __beeper
. beep ();
432 this . __flasher
. flash ();
433 this . __notifier
. notify ( title
, message
, callback
);
435 setBeepOnMention : function ( value
) {
437 this . __beeper
. soundInit ();
439 setNotifications : function ( value
) {
440 this . __notifier
. setEnabled ( value
);
442 updateTitle : function ( text
) {
443 if ( this . __flasher
. updateTitle ( text
))
446 focusChange : function ( value
) {
448 this . __flasher
. focusChange ( value
);
449 this . __notifier
. focusChange ( value
);
453 qwebirc
. ui
. NewLoginUI
= new Class ({
454 Extends : qwebirc
. ui
. NotificationUI
,
455 loginBox : function ( callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
456 this . postInitialize ();
458 /* I'd prefer something shorter and snappier! */
459 var w
= this . newCustomWindow ( "Connect" , true , qwebirc
. ui
. WINDOW_CONNECT
);
460 var callback = function ( args
) {
465 qwebirc
. ui
. GenericLoginBox ( w
. lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this . options
. networkName
);
469 qwebirc
. ui
. QuakeNetUI
= new Class ({
470 Extends : qwebirc
. ui
. NewLoginUI
,
471 urlDispatcher : function ( name
, window
) {
472 if ( name
== "qwhois" ) {
473 return [ "span" , function ( auth
) {
474 this . client
. exec ( "/MSG Q whois #" + auth
);
477 return this . parent ( name
, window
);
480 if (! qwebirc
. auth
. loggedin ())
482 if ( confirm ( "Log out?" )) {
483 this . clients
. each ( function ( k
, v
) {
484 v
. quit ( "Logged out" );
488 var foo = function () { document
. location
= qwebirc
. global
. dynamicBaseURL
+ "auth?logout=1" ; };
494 qwebirc
. ui
. RootUI
= qwebirc
. ui
. QuakeNetUI
;
496 qwebirc
. ui
. RequestTransformHTML = function ( options
) {
497 var HREF_ELEMENTS
= {
501 var update
= options
. update
;
502 var onSuccess
= options
. onSuccess
;
504 var fixUp = function ( node
) {
505 if ( node
. nodeType
!= 1 )
508 var tagName
= node
. nodeName
. toUpperCase ();
509 if ( HREF_ELEMENTS
[ tagName
]) {
510 var attr
= node
. getAttribute ( "transform_attr" );
511 var value
= node
. getAttribute ( "transform_value" );
512 if ($ defined ( attr
) && $ defined ( value
)) {
513 node
. removeAttribute ( "transform_attr" );
514 node
. removeAttribute ( "transform_value" );
515 node
. setAttribute ( attr
, qwebirc
. global
. staticBaseURL
+ value
);
519 for ( var i
= 0 ; i
< node
. childNodes
. length
; i
++)
520 fixUp ( node
. childNodes
[ i
]);
523 delete options
[ "update" ];
524 options
. onSuccess = function ( tree
, elements
, html
, js
) {
525 var container
= new Element ( "div" );
526 container
. set ( "html" , html
);
530 while ( container
. childNodes
. length
> 0 ) {
531 var x
= container
. firstChild
;
532 container
. removeChild ( x
);
533 update
. appendChild ( x
);
538 return new Request
. HTML ( options
);