]>
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 newClient : function ( client
) {
52 client
. id
= this . clientId
++;
53 client
. hilightController
= new qwebirc
. ui
. HilightController ( client
);
55 this . windows
[ client
. id
] = {}
56 this . clients
[ client
. id
] = client
;
57 var w
= this . newWindow ( client
, qwebirc
. ui
. WINDOW_STATUS
, "Status" );
59 if (! this . firstClient
) {
60 this . firstClient
= true ;
61 w
. addLine ( "" , "qwebirc v" + qwebirc
. VERSION
);
62 w
. addLine ( "" , "Copyright (C) 2008-2010 Chris Porter and the qwebirc project." );
63 w
. addLine ( "" , "http://www.qwebirc.org" );
64 w
. addLine ( "" , "Licensed under the GNU General Public License, Version 2." );
68 getClientId : function ( client
) {
69 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) {
70 return qwebirc
. ui
. CUSTOM_CLIENT
;
75 getWindowIdentifier : function ( client
, type
, name
) {
76 if ( type
== qwebirc
. ui
. WINDOW_MESSAGES
)
78 if ( type
== qwebirc
. ui
. WINDOW_STATUS
)
81 if ( client
== qwebirc
. ui
. CUSTOM_CLIENT
) /* HACK */
84 return "_" + client
. toIRCLower ( name
);
86 newWindow : function ( client
, type
, name
) {
87 var w
= this . getWindow ( client
, type
, name
);
91 var wId
= this . getWindowIdentifier ( client
, type
, name
);
92 var w
= this . windows
[ this . getClientId ( client
)][ wId
] = new this . windowClass ( this , client
, type
, name
, wId
);
93 this . windowArray
. push ( w
);
97 getWindow : function ( client
, type
, name
) {
98 var c
= this . windows
[ this . getClientId ( client
)];
102 return c
[ this . getWindowIdentifier ( client
, type
, name
)];
104 getActiveWindow : function () {
107 getActiveIRCWindow : function ( client
) {
108 if (! this . active
|| this . active
. type
== qwebirc
. ui
. WINDOW_CUSTOM
) {
109 return this . windows
[ this . getClientId ( client
)][ this . getWindowIdentifier ( client
, qwebirc
. ui
. WINDOW_STATUS
)];
114 __setActiveWindow : function ( window
) {
115 this . active
= window
;
117 selectWindow : function ( window
) {
119 this . active
. deselect ();
120 window
. select (); /* calls setActiveWindow */
121 this . updateTitle ( window
. name
+ " - " + this . options
. appTitle
);
123 updateTitle : function ( text
) {
124 document
. title
= text
;
126 nextWindow : function ( direction
) {
127 if ( this . windowArray
. length
== 0 || ! this . active
)
133 var index
= this . windowArray
. indexOf ( this . active
);
137 index
= index
+ direction
;
139 index
= this . windowArray
. length
- 1 ;
140 } else if ( index
>= this . windowArray
. length
) {
144 this . selectWindow ( this . windowArray
[ index
]);
146 prevWindow : function () {
149 __closed : function ( window
) {
151 this . active
= undefined ;
152 if ( this . windowArray
. length
== 1 ) {
153 this . windowArray
= [];
155 var index
= this . windowArray
. indexOf ( window
);
158 } else if ( index
== 0 ) {
159 this . selectWindow ( this . windowArray
[ 1 ]);
161 this . selectWindow ( this . windowArray
[ index
- 1 ]);
166 this . windowArray
= this . windowArray
. erase ( window
);
167 delete this . windows
[ this . getClientId ( window
. client
)][ window
. identifier
];
170 this shouldn't be called by overriding classes!
171 they should implement their own!
172 some form of user input MUST be received before an
173 IRC connection is made, else users are going to get
174 tricked into getting themselves glined
176 loginBox : function ( callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
177 qwebirc
. ui
. GenericLoginBox ( this . parentElement
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this . options
. networkName
);
179 focusChange : function ( newValue
) {
180 var window_
= this . getActiveWindow ();
181 if ($ defined ( window_
))
182 window_
. focusChange ( newValue
);
184 signedOn : function () {
185 this . poller
= new qwebirc
. xdomain
. Poller ( this . oobMessage
. bind ( this ));
187 oobMessage : function ( message
) {
188 var c
= message
. splitMax ( " " , 2 );
196 var d
= c
[ 1 ]. splitMax ( " " , 2 );
202 if ( command
== "SAY" ) {
203 var w
= this . getActiveIRCWindow ();
204 if ($ defined ( w
) && w
. type
== qwebirc
. ui
. WINDOW_CHANNEL
) {
205 w
. client
. exec ( "/SAY " + args
);
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
= {};
223 if ( Browser
. Engine
. trident
) {
228 document
. addEvent ( ev
, this . __handleHotkey
. bind ( this ));
230 __handleHotkey : function ( x
) {
231 if (! x
. alt
|| x
. control
) {
232 if ( x
. key
== "backspace" || x
. key
== "/" )
233 if (! this . getInputFocused ( x
))
238 if ( x
. key
== "a" || x
. key
== "A" ) {
240 var highestIndex
= - 1 ;
244 for ( var i
= 0 ; i
< this . windowArray
. length
; i
++) {
245 var h
= this . windowArray
[ i
]. hilighted
;
251 if ( highestIndex
> - 1 )
252 this . selectWindow ( this . windowArray
[ highestIndex
]);
253 } else if ( x
. key
>= '0' && x
. key
<= '9' ) {
256 number
= x
. key
- '0' ;
262 if ( number
>= this . windowArray
. length
)
265 this . selectWindow ( this . windowArray
[ number
]);
266 } else if ( x
. key
== "left" ) {
269 } else if ( x
. key
== "right" ) {
276 getInputFocused : function ( x
) {
277 if ($$( "input" ). indexOf ( x
. target
) == - 1 && $$( "textarea" ). indexOf ( x
. target
) == - 1 )
281 newCustomWindow : function ( name
, select
, type
) {
283 type
= qwebirc
. ui
. WINDOW_CUSTOM
;
285 var w
= this . newWindow ( qwebirc
. ui
. CUSTOM_CLIENT
, type
, name
);
286 w
. addEvent ( "close" , function ( w
) {
287 delete this . windows
[ qwebirc
. ui
. CUSTOM_CLIENT
][ w
. identifier
];
291 this . selectWindow ( w
);
295 addCustomWindow : function ( windowName
, class_
, cssClass
, options
) {
296 if (!$ defined ( options
))
299 if ( this . customWindows
[ windowName
]) {
300 this . selectWindow ( this . customWindows
[ windowName
]);
304 var d
= this . newCustomWindow ( windowName
, true );
305 this . customWindows
[ windowName
] = d
;
307 d
. addEvent ( "close" , function () {
308 this . customWindows
[ windowName
] = null ;
312 d
. lines
. addClass ( "qwebirc-" + cssClass
);
314 var ew
= new class_ ( d
. lines
, options
);
315 ew
. addEvent ( "close" , function () {
321 embeddedWindow : function () {
322 this . addCustomWindow ( "Add webchat to your site" , qwebirc
. ui
. EmbedWizard
, "embeddedwizard" , { baseURL : this . options
. baseURL
, uiOptions : this . uiOptions
, optionsCallback : function () {
323 this . optionsWindow ();
326 optionsWindow : function () {
327 this . addCustomWindow ( "Options" , qwebirc
. ui
. OptionsPane
, "optionspane" , this . uiOptions
);
329 aboutWindow : function () {
330 this . addCustomWindow ( "About" , qwebirc
. ui
. AboutPane
, "aboutpane" , this . uiOptions
);
332 privacyWindow : function () {
333 this . addCustomWindow ( "Privacy policy" , qwebirc
. ui
. PrivacyPolicyPane
, "privacypolicypane" , this . uiOptions
);
335 feedbackWindow : function () {
336 this . addCustomWindow ( "Feedback" , qwebirc
. ui
. FeedbackPane
, "feedbackpane" , this . uiOptions
);
338 faqWindow : function () {
339 this . addCustomWindow ( "FAQ" , qwebirc
. ui
. FAQPane
, "faqpane" , this . uiOptions
);
341 urlDispatcher : function ( name
, window
) {
342 if ( name
== "embedded" )
343 return [ "a" , this . embeddedWindow
. bind ( this )];
345 if ( name
== "options" )
346 return [ "a" , this . optionsWindow
. bind ( this )];
348 /* doesn't really belong here */
349 if ( name
== "whois" ) {
350 return [ "span" , function ( nick
) {
351 if ( this . uiOptions
. QUERY_ON_NICK_CLICK
) {
352 window
. client
. exec ( "/QUERY " + nick
);
354 window
. client
. exec ( "/WHOIS " + nick
);
361 tabComplete : function ( element
) {
362 this . tabCompleter
. tabComplete ( element
);
364 resetTabComplete : function () {
365 this . tabCompleter
. reset ();
367 setModifiableStylesheet : function ( name
) {
368 this . __styleSheet
= new qwebirc
. ui
. style
. ModifiableStylesheet ( qwebirc
. global
. staticBaseURL
+ "css/" + name
+ qwebirc
. FILE_SUFFIX
+ ".mcss" );
370 if ($ defined ( this . options
. hue
)) {
371 this . setModifiableStylesheetValues ( this . options
. hue
, 0 , 0 );
373 this . setModifiableStylesheetValues ( this . uiOptions
. STYLE_HUE
, 0 , 0 );
376 setModifiableStylesheetValues : function ( hue
, saturation
, lightness
) {
377 if (!$ defined ( this . __styleSheet
))
379 this . __styleSheet
. set ( function ( x
) {
380 return x
. setHue ( hue
). setSaturation ( x
. hsb
[ 1 ] + saturation
). setBrightness ( x
. hsb
[ 2 ] + lightness
);
385 qwebirc
. ui
. NotificationUI
= new Class ({
386 Extends : qwebirc
. ui
. StandardUI
,
387 initialize : function ( parentElement
, windowClass
, uiName
, options
) {
388 this . parent ( parentElement
, windowClass
, uiName
, options
);
390 this . __beeper
= new qwebirc
. ui
. Beeper ( this . uiOptions
);
391 this . __flasher
= new qwebirc
. ui
. Flasher ( this . uiOptions
);
393 this . beep
= this . __beeper
. beep
. bind ( this . __beeper
);
395 this . flash
= this . __flasher
. flash
. bind ( this . __flasher
);
396 this . cancelFlash
= this . __flasher
. cancelFlash
. bind ( this . __flasher
);
398 setBeepOnMention : function ( value
) {
400 this . __beeper
. soundInit ();
402 updateTitle : function ( text
) {
403 if ( this . __flasher
. updateTitle ( text
))
406 focusChange : function ( value
) {
408 this . __flasher
. focusChange ( value
);
412 qwebirc
. ui
. NewLoginUI
= new Class ({
413 Extends : qwebirc
. ui
. NotificationUI
,
414 loginBox : function ( callbackfn
, initialNickname
, initialChannels
, autoConnect
, autoNick
) {
415 this . postInitialize ();
417 /* I'd prefer something shorter and snappier! */
418 var w
= this . newCustomWindow ( "Connection details" , true , qwebirc
. ui
. WINDOW_CONNECT
);
419 var callback = function ( args
) {
424 qwebirc
. ui
. GenericLoginBox ( w
. lines
, callback
, initialNickname
, initialChannels
, autoConnect
, autoNick
, this . options
. networkName
);
428 qwebirc
. ui
. QuakeNetUI
= new Class ({
429 Extends : qwebirc
. ui
. NewLoginUI
,
430 urlDispatcher : function ( name
, window
) {
431 if ( name
== "qwhois" ) {
432 return [ "span" , function ( auth
) {
433 this . client
. exec ( "/MSG Q whois #" + auth
);
436 return this . parent ( name
, window
);
439 if (! qwebirc
. auth
. loggedin ())
441 if ( confirm ( "Log out?" )) {
442 for ( var client
in this . clients
) {
443 this . clients
[ client
]. quit ( "Logged out" );
447 var foo = function () { document
. location
= qwebirc
. global
. dynamicBaseURL
+ "auth?logout=1" ; };
453 qwebirc
. ui
. RootUI
= qwebirc
. ui
. QuakeNetUI
;
455 qwebirc
. ui
. RequestTransformHTML = function ( options
) {
456 var HREF_ELEMENTS
= {
460 var update
= options
. update
;
461 var onSuccess
= options
. onSuccess
;
463 var fixUp = function ( node
) {
464 if ( node
. nodeType
!= 1 )
467 var tagName
= node
. nodeName
. toUpperCase ();
468 if ( HREF_ELEMENTS
[ tagName
]) {
469 var attr
= node
. getAttribute ( "transform_attr" );
470 var value
= node
. getAttribute ( "transform_value" );
471 if ($ defined ( attr
) && $ defined ( value
)) {
472 node
. removeAttribute ( "transform_attr" );
473 node
. removeAttribute ( "transform_value" );
474 node
. setAttribute ( attr
, qwebirc
. global
. staticBaseURL
+ value
);
478 for ( var i
= 0 ; i
< node
. childNodes
. length
; i
++)
479 fixUp ( node
. childNodes
[ i
]);
482 delete options
[ "update" ];
483 options
. onSuccess = function ( tree
, elements
, html
, js
) {
484 var container
= new Element ( "div" );
485 container
. set ( "html" , html
);
489 while ( container
. childNodes
. length
> 0 ) {
490 var x
= container
. firstChild
;
491 container
. removeChild ( x
);
492 update
. appendChild ( x
);
497 return new Request
. HTML ( options
);