]>
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 . poller
= new qwebirc
. xdomain
. Poller ( this . oobMessage
. bind ( this ));
64 this . fireEvent ( "signedOn" , client
);
66 this . windows
. put ( client
. id
, new QHash ());
67 this . clients
. put ( client
. id
, client
);
68 var w
= this . newWindow ( client
, qwebirc
. ui
. WINDOW_STATUS
, "Status" );
70 if (! this . firstClient
) {
71 this . firstClient
= true ;
72 w
. addLine ( "" , "qwebirc v" + qwebirc
. VERSION
);
73 w
. addLine ( "" , "Copyright (C) 2008-2014 Chris Porter and the qwebirc project." );
74 w
. addLine ( "" , "http://www.qwebirc.org" );
75 w
. addLine ( "" , "Licensed under the GNU General Public License, Version 2." );
79 getClientId : function ( client
) {
80 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) {
81 return qwebirc
. ui
. CUSTOM_CLIENT
;
86 getWindowIdentifier : function ( client
, type
, name
) {
87 if ( type
== qwebirc
. ui
. WINDOW_MESSAGES
)
89 if ( type
== qwebirc
. ui
. WINDOW_STATUS
)
92 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) /* HACK */
95 return "_" + client
. toIRCLower ( name
);
97 newWindow : function ( client
, type
, name
) {
98 var w
= this . getWindow ( client
, type
, name
);
102 var wId
= this . getWindowIdentifier ( client
, type
, name
);
103 var w
= new this . windowClass ( this , client
, type
, name
, wId
);
104 this . windows
. get ( this . getClientId ( client
)). put ( wId
, w
);
105 this . windowArray
. push ( w
);
109 getWindow : function ( client
, type
, name
) {
110 var c
= this . windows
. get ( this . getClientId ( client
));
114 return c
[ this . getWindowIdentifier ( client
, type
, name
)];
116 getActiveWindow : function () {
119 getActiveIRCWindow : function ( client
) {
120 if (! this . active
|| this . active
. type
== qwebirc
. ui
. WINDOW_CUSTOM
) {
121 return this . windows
. get ( this . getClientId ( client
)). get ( this . getWindowIdentifier ( client
, qwebirc
. ui
. WINDOW_STATUS
));
126 __setActiveWindow : function ( window
) {
127 this . active
= window
;
129 renameWindow : function ( window
, name
) {
130 if ( this . getWindow ( window
. client
, window
. type
, name
))
133 var clientId
= this . getClientId ( window
. client
);
134 var index
= this . windowArray
. indexOf ( window
);
138 this . windows
. get ( clientId
). remove ( window
. identifier
);
140 var window
= this . windowArray
[ index
];
142 window
. identifier
= this . getWindowIdentifier ( window
. client
, window
. type
, window
. name
);
144 this . windows
. get ( clientId
). put ( window
. identifier
, this . windowArray
[ index
]);
147 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
149 window
. rename ( window
. name
);
152 selectWindow : function ( window
) {
154 this . active
. deselect ();
155 window
. select (); /* calls setActiveWindow */
156 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
158 updateTitle : function ( text
) {
159 document
. title
= text
;
161 nextWindow : function ( direction
) {
162 if ( this . windowArray
. length
== 0 || ! this . active
)
168 var index
= this . windowArray
. indexOf ( this . active
);
172 index
= index
+ direction
;
174 index
= this . windowArray
. length
- 1 ;
175 } else if ( index
>= this . windowArray
. length
) {
179 this . selectWindow ( this . windowArray
[ index
]);
181 prevWindow : function () {
184 __closed : function ( window
) {
186 this . active
= undefined ;
187 if ( this . windowArray
. length
== 1 ) {
188 this . windowArray
= [];
190 var index
= this . windowArray
. indexOf ( window
);
193 } else if ( index
== 0 ) {
194 this . selectWindow ( this . windowArray
[ 1 ]);
196 this . selectWindow ( this . windowArray
[ index
- 1 ]);
201 this . windowArray
= this . windowArray
. erase ( window
);
202 this . windows
. get ( this . getClientId ( window
. client
)). remove ( window
. identifier
);
205 this shouldn't be called by overriding classes!
206 they should implement their own!
207 some form of user input MUST be received before an
208 IRC connection is made, else users are going to get
209 tricked into getting themselves glined
211 loginBox : function ( callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
212 this . postInitialize ();
214 this . addCustomWindow ( "Connect" , qwebirc
. ui
. ConnectPane
, "connectpane" , {
215 initialNickname : initialNickname
, initialChannels : initialChannels
, autoConnect : autoConnect
, networkName : this . options
. networkName
, callback : callback
, autoNick : autoNick
216 }, qwebirc
. ui
. WINDOW_CONNECT
);
218 focusChange : function ( newValue
) {
219 var window_
= this . getActiveWindow ();
220 if ($ defined ( window_
))
221 window_
. focusChange ( newValue
);
223 oobMessage : function ( message
) {
224 var c
= message
. splitMax ( " " , 2 );
232 var d
= c
[ 1 ]. splitMax ( " " , 2 );
238 if ( command
== "SAY" ) {
239 var w
= this . getActiveIRCWindow ();
240 if ($ defined ( w
) && ( w
. type
== qwebirc
. ui
. WINDOW_CHANNEL
|| w
. type
== qwebirc
. ui
. WINDOW_QUERY
)) {
241 w
. client
. exec ( "/SAY " + args
);
248 qwebirc
. ui
. StandardUI
= new Class ({
249 Extends : qwebirc
. ui
. BaseUI
,
250 UICommands : qwebirc
. ui
. UI_COMMANDS
,
251 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
252 this . parent ( parentElement
, windowClass
, uiName
, options
);
254 this . tabCompleter
= new qwebirc
. ui
. TabCompleterFactory ( this );
255 this . uiOptions
= new qwebirc
. ui
. DefaultOptionsClass ( this , options
. uiOptionsArg
);
256 this . customWindows
= new QHash ();
258 this . __styleValues
= { hue : this . uiOptions
. STYLE_HUE
, saturation : 0 , lightness : 0 };
259 if ($ defined ( this . options
. hue
)) this . __styleValues
. hue
= this . options
. hue
;
260 if ($ defined ( this . options
. saturation
)) this . __styleValues
. saturation
= this . options
. saturation
;
261 if ($ defined ( this . options
. lightness
)) this . __styleValues
. lightness
= this . options
. lightness
;
263 if ( this . options
. thue
!== null ) this . __styleValues
. textHue
= this . options
. thue
;
264 if ( this . options
. tsaturation
!== null ) this . __styleValues
. textSaturation
= this . options
. tsaturation
;
265 if ( this . options
. tlightness
!== null ) this . __styleValues
. textLightness
= this . options
. tlightness
;
267 document
. addEvent ( "keydown" , this . __handleHotkey
. bind ( this ));
269 __handleHotkey : function ( x
) {
271 if (! x
. alt
|| x
. control
) {
272 if (( x
. key
== "backspace" || x
. key
== "/" ) && ! this . getInputFocused ( x
)) {
275 } else if ( x
. key
== "a" || x
. key
== "A" ) {
277 var highestIndex
= - 1 ;
280 for ( var i
= 0 ; i
< this . windowArray
. length
; i
++) {
281 var h
= this . windowArray
[ i
]. hilighted
;
287 if ( highestIndex
> - 1 )
288 this . selectWindow ( this . windowArray
[ highestIndex
]);
289 } else if ( x
. key
>= '0' && x
. key
<= '9' ) {
292 number
= x
. key
- '0' ;
298 if ( number
>= this . windowArray
. length
)
301 this . selectWindow ( this . windowArray
[ number
]);
302 } else if ( x
. key
== "left" ) {
305 } else if ( x
. key
== "right" ) {
314 getInputFocused : function ( x
) {
315 if ($$( "input" ). indexOf ( x
. target
) == - 1 && $$( "textarea" ). indexOf ( x
. target
) == - 1 )
319 newCustomWindow : function ( name
, select
, type
) {
321 type
= qwebirc
. ui
. WINDOW_CUSTOM
;
323 var w
= this . newWindow ( qwebirc
. ui
. CUSTOM_CLIENT
, type
, name
);
324 w
. addEvent ( "close" , function ( w
) {
325 this . windows
. get ( qwebirc
. ui
. CUSTOM_CLIENT
). remove ( w
. identifier
);
329 this . selectWindow ( w
);
333 addCustomWindow : function ( windowName
, class_
, cssClass
, options
, type
) {
334 if (!$ defined ( options
))
337 if ( this . customWindows
. contains ( windowName
)) {
338 this . selectWindow ( this . customWindows
. get ( windowName
));
342 var d
= this . newCustomWindow ( windowName
, true , type
);
343 this . customWindows
. put ( windowName
, d
);
345 d
. addEvent ( "close" , function () {
346 this . customWindows
. remove ( windowName
);
350 d
. lines
. addClass ( "qwebirc-" + cssClass
);
352 var ew
= new class_ ( d
. lines
, options
);
353 ew
. addEvent ( "close" , function () {
359 embeddedWindow : function () {
360 this . addCustomWindow ( "Add webchat to your site" , qwebirc
. ui
. EmbedWizard
, "embeddedwizard" , { baseURL : this . options
. baseURL
, uiOptions : this . uiOptions
, optionsCallback : function () {
361 this . optionsWindow ();
364 optionsWindow : function () {
365 this . addCustomWindow ( "Options" , qwebirc
. ui
. OptionsPane
, "optionspane" , this . uiOptions
);
367 aboutWindow : function () {
368 this . addCustomWindow ( "About" , qwebirc
. ui
. AboutPane
, "aboutpane" , this . uiOptions
);
370 privacyWindow : function () {
371 this . addCustomWindow ( "Privacy policy" , qwebirc
. ui
. PrivacyPolicyPane
, "privacypolicypane" , this . uiOptions
);
373 feedbackWindow : function () {
374 this . addCustomWindow ( "Feedback" , qwebirc
. ui
. FeedbackPane
, "feedbackpane" , this . uiOptions
);
376 helpWindow : function () {
377 this . addCustomWindow ( "Help!" , qwebirc
. ui
. HelpPane
, "helppane" , this . uiOptions
);
379 urlDispatcher : function ( name
, window
) {
380 if ( name
== "embedded" )
381 return [ "a" , this . embeddedWindow
. bind ( this )];
383 if ( name
== "options" )
384 return [ "a" , this . optionsWindow
. bind ( this )];
386 /* doesn't really belong here */
387 if ( name
== "whois" ) {
388 return [ "span" , function ( nick
) {
389 if ( this . uiOptions
. QUERY_ON_NICK_CLICK
) {
390 window
. client
. exec ( "/QUERY " + nick
);
392 window
. client
. exec ( "/WHOIS " + nick
);
399 tabComplete : function ( element
) {
400 this . tabCompleter
. tabComplete ( element
);
402 resetTabComplete : function () {
403 this . tabCompleter
. reset ();
405 setModifiableStylesheet : function ( name
) {
406 this . __styleSheet
= new qwebirc
. ui
. style
. ModifiableStylesheet ( qwebirc
. global
. staticBaseURL
+ "css/" + ( QWEBIRC_DEBUG
? "debug/" : "" ) + name
+ qwebirc
. FILE_SUFFIX
+ ".mcss" );
407 this . setModifiableStylesheetValues ({});
409 setModifiableStylesheetValues : function ( values
) {
411 this . __styleValues
[ k
] = values
[ k
];
413 if (!$ defined ( this . __styleSheet
))
416 var back
= { hue : this . __styleValues
. hue
, lightness : this . __styleValues
. lightness
, saturation : this . __styleValues
. saturation
};
417 var front
= { hue : this . __styleValues
. textHue
, lightness : this . __styleValues
. textLightness
, saturation : this . __styleValues
. textSaturation
};
419 if (! this . __styleValues
. textHue
&& ! this . __styleValues
. textLightness
&& ! this . __styleValues
. textSaturation
)
427 this . __styleSheet
. set ( function () {
428 var mode
= arguments
[ 0 ];
430 var t
= colours
[ arguments
[ 2 ]];
431 var x
= new Color ( arguments
[ 1 ]);
432 var c
= x
. setHue ( t
. hue
). setSaturation ( x
. hsb
[ 1 ] + t
. saturation
). setBrightness ( x
. hsb
[ 2 ] + t
. lightness
);
433 if ( c
== "255,255,255" ) /* IE confuses white with transparent... */
436 return "rgb(" + c
+ ")" ;
437 } else if ( mode
== "o" ) {
438 return this . uiOptions
[ arguments
[ 1 ]] ? arguments
[ 2 ] : arguments
[ 3 ];
444 qwebirc
. ui
. NotificationUI
= new Class ({
445 Extends : qwebirc
. ui
. StandardUI
,
446 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
447 this . parent ( parentElement
, windowClass
, uiName
, options
);
449 this . __beeper
= new qwebirc
. ui
. Beeper ( this . uiOptions
);
450 this . __flasher
= new qwebirc
. ui
. Flasher ( this . uiOptions
);
451 this . __notifier
= new qwebirc
. ui
. Notifier ( this . uiOptions
);
453 this . cancelFlash
= this . __flasher
. cancelFlash
. bind ( this . __flasher
);
456 this . __beeper
. beep ();
458 notify : function ( title
, message
, callback
) {
459 this . __beeper
. beep ();
460 this . __flasher
. flash ();
461 this . __notifier
. notify ( title
, message
, callback
);
463 setBeepOnMention : function ( value
) {
465 this . __beeper
. soundInit ();
467 setNotifications : function ( value
) {
468 this . __notifier
. setEnabled ( value
);
470 updateTitle : function ( text
) {
471 if ( this . __flasher
. updateTitle ( text
))
474 focusChange : function ( value
) {
476 this . __flasher
. focusChange ( value
);
477 this . __notifier
. focusChange ( value
);
481 qwebirc
. ui
. QuakeNetUI
= new Class ({
482 Extends : qwebirc
. ui
. NotificationUI
,
483 urlDispatcher : function ( name
, window
) {
484 if ( name
== "qwhois" ) {
485 return [ "span" , function ( auth
) {
486 this . client
. exec ( "/MSG Q whois #" + auth
);
489 return this . parent ( name
, window
);
492 if (! qwebirc
. auth
. loggedin ())
494 if ( confirm ( "Log out?" )) {
495 this . clients
. each ( function ( k
, v
) {
496 v
. quit ( "Logged out" );
500 var foo = function () { document
. location
= qwebirc
. global
. dynamicBaseURL
+ "auth?logout=1" ; };
506 qwebirc
. ui
. RootUI
= qwebirc
. ui
. QuakeNetUI
;
508 qwebirc
. ui
. RequestTransformHTML = function ( options
) {
509 var HREF_ELEMENTS
= {
513 var update
= options
. update
;
514 var onSuccess
= options
. onSuccess
;
516 var fixUp = function ( node
) {
517 if ( node
. nodeType
!= 1 )
520 var tagName
= node
. nodeName
. toUpperCase ();
521 if ( HREF_ELEMENTS
[ tagName
]) {
522 var attr
= node
. getAttribute ( "transform_attr" );
523 var value
= node
. getAttribute ( "transform_value" );
524 if ($ defined ( attr
) && $ defined ( value
)) {
525 node
. removeAttribute ( "transform_attr" );
526 node
. removeAttribute ( "transform_value" );
527 node
. setAttribute ( attr
, qwebirc
. global
. staticBaseURL
+ value
);
531 for ( var i
= 0 ; i
< node
. childNodes
. length
; i
++)
532 fixUp ( node
. childNodes
[ i
]);
535 delete options
[ "update" ];
536 options
. onSuccess = function ( tree
, elements
, html
, js
) {
537 var container
= new Element ( "div" );
538 container
. set ( "html" , html
);
542 while ( container
. childNodes
. length
> 0 ) {
543 var x
= container
. firstChild
;
544 container
. removeChild ( x
);
545 update
. appendChild ( x
);
550 return new Request
. HTML ( options
);