]>
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
;
17 this . windows
[ qwebirc
. ui
. CUSTOM_CLIENT
] = {};
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
= this . clientId
++;
61 client
. hilightController
= new qwebirc
. ui
. HilightController ( client
);
63 this . windows
[ client
. id
] = {}
64 this . clients
[ client
. id
] = client
;
65 var w
= this . newWindow ( client
, qwebirc
. ui
. WINDOW_STATUS
, "Status" );
67 if (! this . firstClient
) {
68 this . firstClient
= true ;
69 w
. addLine ( "" , "qwebirc v" + qwebirc
. VERSION
);
70 w
. addLine ( "" , "Copyright (C) 2008-2014 Chris Porter and the qwebirc project." );
71 w
. addLine ( "" , "http://www.qwebirc.org" );
72 w
. addLine ( "" , "Licensed under the GNU General Public License, Version 2." );
76 getClientId : function ( client
) {
77 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) {
78 return qwebirc
. ui
. CUSTOM_CLIENT
;
83 getWindowIdentifier : function ( client
, type
, name
) {
84 if ( type
== qwebirc
. ui
. WINDOW_MESSAGES
)
86 if ( type
== qwebirc
. ui
. WINDOW_STATUS
)
89 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) /* HACK */
92 return "_" + client
. toIRCLower ( name
);
94 newWindow : function ( client
, type
, name
) {
95 var w
= this . getWindow ( client
, type
, name
);
99 var wId
= this . getWindowIdentifier ( client
, type
, name
);
100 var w
= this . windows
[ this . getClientId ( client
)][ wId
] = new this . windowClass ( this , client
, type
, name
, wId
);
101 this . windowArray
. push ( w
);
105 getWindow : function ( client
, type
, name
) {
106 var c
= this . windows
[ this . getClientId ( client
)];
110 return c
[ this . getWindowIdentifier ( client
, type
, name
)];
112 getActiveWindow : function () {
115 getActiveIRCWindow : function ( client
) {
116 if (! this . active
|| this . active
. type
== qwebirc
. ui
. WINDOW_CUSTOM
) {
117 return this . windows
[ this . getClientId ( client
)][ this . getWindowIdentifier ( client
, qwebirc
. ui
. WINDOW_STATUS
)];
122 __setActiveWindow : function ( window
) {
123 this . active
= window
;
125 renameWindow : function ( window
, name
) {
126 if ( this . getWindow ( window
. client
, window
. type
, name
))
129 var clientId
= this . getClientId ( window
. client
);
130 var index
= this . windowArray
. indexOf ( window
);
134 delete this . windows
[ clientId
][ window
. identifier
];
136 var window
= this . windowArray
[ index
];
138 window
. identifier
= this . getWindowIdentifier ( window
. client
, window
. type
, window
. name
);
140 this . windows
[ clientId
][ window
. identifier
] = this . windowArray
[ index
];
143 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
145 window
. rename ( window
. name
);
148 selectWindow : function ( window
) {
150 this . active
. deselect ();
151 window
. select (); /* calls setActiveWindow */
152 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
154 updateTitle : function ( text
) {
155 document
. title
= text
;
157 nextWindow : function ( direction
) {
158 if ( this . windowArray
. length
== 0 || ! this . active
)
164 var index
= this . windowArray
. indexOf ( this . active
);
168 index
= index
+ direction
;
170 index
= this . windowArray
. length
- 1 ;
171 } else if ( index
>= this . windowArray
. length
) {
175 this . selectWindow ( this . windowArray
[ index
]);
177 prevWindow : function () {
180 __closed : function ( window
) {
182 this . active
= undefined ;
183 if ( this . windowArray
. length
== 1 ) {
184 this . windowArray
= [];
186 var index
= this . windowArray
. indexOf ( window
);
189 } else if ( index
== 0 ) {
190 this . selectWindow ( this . windowArray
[ 1 ]);
192 this . selectWindow ( this . windowArray
[ index
- 1 ]);
197 this . windowArray
= this . windowArray
. erase ( window
);
198 delete this . windows
[ this . getClientId ( window
. client
)][ window
. identifier
];
201 this shouldn't be called by overriding classes!
202 they should implement their own!
203 some form of user input MUST be received before an
204 IRC connection is made, else users are going to get
205 tricked into getting themselves glined
207 loginBox : function ( callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
208 qwebirc
. ui
. GenericLoginBox ( this . parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this . options
. networkName
);
210 focusChange : function ( newValue
) {
211 var window_
= this . getActiveWindow ();
212 if ($ defined ( window_
))
213 window_
. focusChange ( newValue
);
217 qwebirc
. ui
. StandardUI
= new Class ({
218 Extends : qwebirc
. ui
. BaseUI
,
219 UICommands : qwebirc
. ui
. UI_COMMANDS
,
220 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
221 this . parent ( parentElement
, windowClass
, uiName
, options
);
223 this . tabCompleter
= new qwebirc
. ui
. TabCompleterFactory ( this );
224 this . uiOptions
= new qwebirc
. ui
. DefaultOptionsClass ( this , options
. uiOptionsArg
);
225 this . customWindows
= {};
227 this . __styleValues
= { hue : this . uiOptions
. STYLE_HUE
, saturation : 0 , lightness : 0 };
228 if ($ defined ( this . options
. hue
)) this . __styleValues
. hue
= this . options
. hue
;
229 if ($ defined ( this . options
. saturation
)) this . __styleValues
. saturation
= this . options
. saturation
;
230 if ($ defined ( this . options
. lightness
)) this . __styleValues
. lightness
= this . options
. lightness
;
232 if ( this . options
. thue
!== null ) this . __styleValues
. textHue
= this . options
. thue
;
233 if ( this . options
. tsaturation
!== null ) this . __styleValues
. textSaturation
= this . options
. tsaturation
;
234 if ( this . options
. tlightness
!== null ) this . __styleValues
. textLightness
= this . options
. tlightness
;
237 if ( Browser
. Engine
. trident
) {
242 document
. addEvent ( ev
, this . __handleHotkey
. bind ( this ));
244 __handleHotkey : function ( x
) {
245 if (! x
. alt
|| x
. control
) {
246 if ( x
. key
== "backspace" || x
. key
== "/" )
247 if (! this . getInputFocused ( x
))
252 if ( x
. key
== "a" || x
. key
== "A" ) {
254 var highestIndex
= - 1 ;
258 for ( var i
= 0 ; i
< this . windowArray
. length
; i
++) {
259 var h
= this . windowArray
[ i
]. hilighted
;
265 if ( highestIndex
> - 1 )
266 this . selectWindow ( this . windowArray
[ highestIndex
]);
267 } else if ( x
. key
>= '0' && x
. key
<= '9' ) {
270 number
= x
. key
- '0' ;
276 if ( number
>= this . windowArray
. length
)
279 this . selectWindow ( this . windowArray
[ number
]);
280 } else if ( x
. key
== "left" ) {
283 } else if ( x
. key
== "right" ) {
290 getInputFocused : function ( x
) {
291 if ($$( "input" ). indexOf ( x
. target
) == - 1 && $$( "textarea" ). indexOf ( x
. target
) == - 1 )
295 newCustomWindow : function ( name
, select
, type
) {
297 type
= qwebirc
. ui
. WINDOW_CUSTOM
;
299 var w
= this . newWindow ( qwebirc
. ui
. CUSTOM_CLIENT
, type
, name
);
300 w
. addEvent ( "close" , function ( w
) {
301 delete this . windows
[ qwebirc
. ui
. CUSTOM_CLIENT
][ w
. identifier
];
305 this . selectWindow ( w
);
309 addCustomWindow : function ( windowName
, class_
, cssClass
, options
) {
310 if (!$ defined ( options
))
313 if ( this . customWindows
[ windowName
]) {
314 this . selectWindow ( this . customWindows
[ windowName
]);
318 var d
= this . newCustomWindow ( windowName
, true );
319 this . customWindows
[ windowName
] = d
;
321 d
. addEvent ( "close" , function () {
322 this . customWindows
[ windowName
] = null ;
326 d
. lines
. addClass ( "qwebirc-" + cssClass
);
328 var ew
= new class_ ( d
. lines
, options
);
329 ew
. addEvent ( "close" , function () {
335 embeddedWindow : function () {
336 this . addCustomWindow ( "Add webchat to your site" , qwebirc
. ui
. EmbedWizard
, "embeddedwizard" , { baseURL : this . options
. baseURL
, uiOptions : this . uiOptions
, optionsCallback : function () {
337 this . optionsWindow ();
340 optionsWindow : function () {
341 this . addCustomWindow ( "Options" , qwebirc
. ui
. OptionsPane
, "optionspane" , this . uiOptions
);
343 aboutWindow : function () {
344 this . addCustomWindow ( "About" , qwebirc
. ui
. AboutPane
, "aboutpane" , this . uiOptions
);
346 privacyWindow : function () {
347 this . addCustomWindow ( "Privacy policy" , qwebirc
. ui
. PrivacyPolicyPane
, "privacypolicypane" , this . uiOptions
);
349 feedbackWindow : function () {
350 this . addCustomWindow ( "Feedback" , qwebirc
. ui
. FeedbackPane
, "feedbackpane" , this . uiOptions
);
352 faqWindow : function () {
353 this . addCustomWindow ( "FAQ" , qwebirc
. ui
. FAQPane
, "faqpane" , this . uiOptions
);
355 urlDispatcher : function ( name
, window
) {
356 if ( name
== "embedded" )
357 return [ "a" , this . embeddedWindow
. bind ( this )];
359 if ( name
== "options" )
360 return [ "a" , this . optionsWindow
. bind ( this )];
362 /* doesn't really belong here */
363 if ( name
== "whois" ) {
364 return [ "span" , function ( nick
) {
365 if ( this . uiOptions
. QUERY_ON_NICK_CLICK
) {
366 window
. client
. exec ( "/QUERY " + nick
);
368 window
. client
. exec ( "/WHOIS " + nick
);
375 tabComplete : function ( element
) {
376 this . tabCompleter
. tabComplete ( element
);
378 resetTabComplete : function () {
379 this . tabCompleter
. reset ();
381 setModifiableStylesheet : function ( name
) {
382 this . __styleSheet
= new qwebirc
. ui
. style
. ModifiableStylesheet ( qwebirc
. global
. staticBaseURL
+ "css/" + name
+ qwebirc
. FILE_SUFFIX
+ ".mcss" );
383 this . setModifiableStylesheetValues ({});
385 setModifiableStylesheetValues : function ( values
) {
387 this . __styleValues
[ k
] = values
[ k
];
389 if (!$ defined ( this . __styleSheet
))
392 var back
= { hue : this . __styleValues
. hue
, lightness : this . __styleValues
. lightness
, saturation : this . __styleValues
. saturation
};
393 var front
= { hue : this . __styleValues
. textHue
, lightness : this . __styleValues
. textLightness
, saturation : this . __styleValues
. textSaturation
};
395 if (! this . __styleValues
. textHue
&& ! this . __styleValues
. textLightness
&& ! this . __styleValues
. textSaturation
)
403 this . __styleSheet
. set ( function () {
404 var mode
= arguments
[ 0 ];
406 var t
= colours
[ arguments
[ 2 ]];
407 var x
= new Color ( arguments
[ 1 ]);
408 var c
= x
. setHue ( t
. hue
). setSaturation ( x
. hsb
[ 1 ] + t
. saturation
). setBrightness ( x
. hsb
[ 2 ] + t
. lightness
);
409 if ( c
== "255,255,255" ) /* IE confuses white with transparent... */
412 return "rgb(" + c
+ ")" ;
413 } else if ( mode
== "o" ) {
414 return this . uiOptions
[ arguments
[ 1 ]] ? arguments
[ 2 ] : arguments
[ 3 ];
420 qwebirc
. ui
. NotificationUI
= new Class ({
421 Extends : qwebirc
. ui
. StandardUI
,
422 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
423 this . parent ( parentElement
, windowClass
, uiName
, options
);
425 this . __beeper
= new qwebirc
. ui
. Beeper ( this . uiOptions
);
426 this . __flasher
= new qwebirc
. ui
. Flasher ( this . uiOptions
);
428 this . beep
= this . __beeper
. beep
. bind ( this . __beeper
);
430 this . flash
= this . __flasher
. flash
. bind ( this . __flasher
);
431 this . cancelFlash
= this . __flasher
. cancelFlash
. bind ( this . __flasher
);
433 setBeepOnMention : function ( value
) {
435 this . __beeper
. soundInit ();
437 updateTitle : function ( text
) {
438 if ( this . __flasher
. updateTitle ( text
))
441 focusChange : function ( value
) {
443 this . __flasher
. focusChange ( value
);
447 qwebirc
. ui
. NewLoginUI
= new Class ({
448 Extends : qwebirc
. ui
. NotificationUI
,
449 loginBox : function ( callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
450 this . postInitialize ();
452 /* I'd prefer something shorter and snappier! */
453 var w
= this . newCustomWindow ( "Connection details" , true , qwebirc
. ui
. WINDOW_CONNECT
);
454 var callback = function ( args
) {
459 qwebirc
. ui
. GenericLoginBox ( w
. lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this . options
. networkName
);
463 qwebirc
. ui
. QuakeNetUI
= new Class ({
464 Extends : qwebirc
. ui
. NewLoginUI
,
465 urlDispatcher : function ( name
, window
) {
466 if ( name
== "qwhois" ) {
467 return [ "span" , function ( auth
) {
468 this . client
. exec ( "/MSG Q whois #" + auth
);
471 return this . parent ( name
, window
);
474 if (! qwebirc
. auth
. loggedin ())
476 if ( confirm ( "Log out?" )) {
477 for ( var client
in this . clients
) {
478 this . clients
[ client
]. quit ( "Logged out" );
482 var foo = function () { document
. location
= qwebirc
. global
. dynamicBaseURL
+ "auth?logout=1" ; };
488 qwebirc
. ui
. RootUI
= qwebirc
. ui
. QuakeNetUI
;
490 qwebirc
. ui
. RequestTransformHTML = function ( options
) {
491 var HREF_ELEMENTS
= {
495 var update
= options
. update
;
496 var onSuccess
= options
. onSuccess
;
498 var fixUp = function ( node
) {
499 if ( node
. nodeType
!= 1 )
502 var tagName
= node
. nodeName
. toUpperCase ();
503 if ( HREF_ELEMENTS
[ tagName
]) {
504 var attr
= node
. getAttribute ( "transform_attr" );
505 var value
= node
. getAttribute ( "transform_value" );
506 if ($ defined ( attr
) && $ defined ( value
)) {
507 node
. removeAttribute ( "transform_attr" );
508 node
. removeAttribute ( "transform_value" );
509 node
. setAttribute ( attr
, qwebirc
. global
. staticBaseURL
+ value
);
513 for ( var i
= 0 ; i
< node
. childNodes
. length
; i
++)
514 fixUp ( node
. childNodes
[ i
]);
517 delete options
[ "update" ];
518 options
. onSuccess = function ( tree
, elements
, html
, js
) {
519 var container
= new Element ( "div" );
520 container
. set ( "html" , html
);
524 while ( container
. childNodes
. length
> 0 ) {
525 var x
= container
. firstChild
;
526 container
. removeChild ( x
);
527 update
. appendChild ( x
);
532 return new Request
. HTML ( options
);