]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/embedwizard.js
1 qwebirc
. ui
. EmbedWizardStep
= new Class ({
2 Implements : [ Options
, Events
],
11 initialize : function ( parent
, options
) {
12 this . setOptions ( options
);
16 this . parent
. title
. set ( "html" , this . options
. title
);
17 this . parent
. firstRow
. set ( "html" , this . options
. first
);
18 this . parent
. hint
. set ( "html" , this . options
. hint
);
19 this . parent
. example
. set ( "text" , this . options
. example
);
21 while ( this . parent
. middleRow
. childNodes
. length
> 0 )
22 this . parent
. middleRow
. removeChild ( this . parent
. middleRow
. childNodes
[ 0 ]);
24 if ($ defined ( this . options
. middle
))
25 this . parent
. middleRow
. appendChild ( this . options
. middle
);
27 this . fireEvent ( "show" );
31 qwebirc
. ui
. EmbedWizard
= new Class ({
32 Implements : [ Options
, Events
],
35 baseURL : "http://webchat.quakenet.org/"
37 initialize : function ( parent
, options
) {
38 this . setOptions ( options
);
42 create : function ( parent
) {
45 var titleRow
= this . newRow ();
46 this . title
= new Element ( "h2" );
47 this . title
. setStyle ( "margin-top" , "0px" );
48 this . title
. setStyle ( "margin-bottom" , "5px" );
49 titleRow
. appendChild ( this . title
);
51 this . firstRow
= this . newRow ();
52 this . middleRow
= this . newRow ();
53 var hintRow
= this . newRow ();
54 this . hint
= new Element ( "div" );
55 this . hint
. setStyle ( "font-size" , "0.8em" );
56 this . hint
. setStyle ( "font-style" , "italic" );
57 hintRow
. appendChild ( this . hint
);
58 var exampleRow
= this . newRow ();
59 this . example
= new Element ( "pre" );
60 exampleRow
. appendChild ( this . example
);
62 var nextRow
= this . newRow ();
63 nextRow
. addClass ( "wizardcontrols" );
64 var backBtn
= new Element ( "input" );
65 backBtn
. type
= "submit" ;
66 backBtn
. value
= "< Back" ;
67 backBtn
. addEvent ( "click" , this . back
. bind ( this ));
68 nextRow
. appendChild ( backBtn
);
70 var nextBtn
= new Element ( "input" );
71 nextBtn
. type
= "submit" ;
72 nextBtn
. value
= "Next >" ;
73 nextRow
. appendChild ( nextBtn
);
74 nextBtn
. addEvent ( "click" , this . next
. bind ( this ));
76 this . nextBtn
= nextBtn
;
77 this . backBtn
= backBtn
;
80 var cell
= new Element ( "div" );
81 this . t
. appendChild ( cell
);
84 newStep : function ( options
) {
85 return new qwebirc
. ui
. EmbedWizardStep ( this , options
);
87 newRadio : function ( parent
, text
, name
, selected
) {
88 var p
= new Element ( "div" );
89 parent
. appendChild ( p
);
92 if ( Browser
. Engine
. trident
) {
93 r
= document
. createElement ( "<input type= \" radio \" name= \" + escape(name) + \" " + ( selected
? " checked" : "" ) + "/>" );
95 r
= new Element ( "input" );
104 p
. appendChild ( document
. createTextNode ( text
));
108 addSteps : function () {
109 var af = function ( select
) {
110 if ( Browser
. Engine
. trident
) {
116 f
. delay ( 100 , this , []);
123 this . welcome
= this . newStep ({
125 "first" : "This wizard will help you create an embedded client by asking you questions then giving you the code to add to your website.<br/><br/>You can use the <b>Next</b> and <b>Back</b> buttons to navigate through the wizard; click <b>Next</b> to continue."
128 this . chanBox
= new Element ( "input" );
129 this . chanBox
. addClass ( "text" );
130 this . chans
= this . newStep ({
131 "title" : "Set channels" ,
132 "first" : "Enter the channels you would like the client to join on startup:" ,
133 "hint" : "You can supply multiple channels by seperating them with a comma, e.g.:" ,
134 "example" : "#rogue,#eu-mage" ,
136 }). addEvent ( "show" , af
. bind ( this . chanBox
));
138 var customnickDiv
= new Element ( "div" );
139 this . customnick
= this . newStep ({
140 "title" : "Nickname mode" ,
141 "first" : "At startup would you like the client to use a random nickname, a preset nickname or a nickname of the users choice?" ,
142 "hint" : "It is recommended that you only use a preset nickname if the client is for your own personal use." ,
143 middle : customnickDiv
146 this . choosenick
= this . newRadio ( customnickDiv
, "Make the user choose a nickname." , "nick" , true );
147 this . randnick
= this . newRadio ( customnickDiv
, "Use a random nickname, e.g. qwebirc12883." , "nick" );
148 this . presetnick
= this . newRadio ( customnickDiv
, "Use a preset nickname of your choice." , "nick" );
150 var promptdiv
= new Element ( "form" );
151 this . connectdialog
= this . newStep ({
152 "title" : "Display connect dialog?" ,
153 "first" : "Do you want the user to be shown the connect dialog (with the values you have supplied pre-entered) or just a connect confirmation?" ,
155 "hint" : "You need to display the dialog if you want the user to be able to set their nickname before connecting."
158 var autoconnect
= this . newRadio ( promptdiv
, "Connect without displaying the dialog." , "prompt" , true );
159 this . connectdialogr
= this . newRadio ( promptdiv
, "Show the connect dialog." , "prompt" );
161 this . nicknameBox
= new Element ( "input" );
162 this . nicknameBox
. addClass ( "text" );
163 this . nickname
= this . newStep ({
164 "title" : "Set nickname" ,
165 "first" : "Enter the nickname you would like the client to use by default:" ,
166 "premove" : function () {
167 if ( this . nicknameBox
. value
== "" ) {
168 alert ( "You must supply a nickname." );
169 this . nicknameBox
. focus ();
174 middle : this . nicknameBox
175 }). addEvent ( "show" , af
. bind ( this . nicknameBox
));
177 var codeDiv
= new Element ( "div" );
178 this . finish
= this . newStep ({
179 "title" : "Finished!" ,
180 "first" : "Your custom link is:" ,
182 }). addEvent ( "show" , function () {
183 var alink
= new Element ( "a" );
184 var abox
= new Element ( "input" );
185 abox
. addClass ( "iframetext" );
186 var url
= this . generateURL ( false );
189 alink
. target
= "new" ;
190 alink
. appendChild ( document
. createTextNode ( url
));
191 abox
. value
= "<iframe src= \" " + url
+ " \" width= \" 647 \" height= \" 400 \" ></iframe>" ;
195 new Element ( "br" ), new Element ( "br" ),
196 document
. createTextNode ( "You can embed this into your page with the following code:" ),
201 while ( codeDiv
. childNodes
. length
> 0 )
202 codeDiv
. removeChild ( codeDiv
. childNodes
[ 0 ]);
204 mBox
. forEach ( function ( x
) {
205 codeDiv
. appendChild ( x
);
209 abox
. addEvent ( "click" , function () {
219 updateSteps : function () {
220 this . steps
= [ this . welcome
, this . customnick
];
222 if ( this . presetnick
. checked
)
223 this . steps
. push ( this . nickname
);
225 this . steps
. push ( this . chans
);
227 if ( this . chanBox
. value
!= "" && ! this . choosenick
. checked
)
228 this . steps
. push ( this . connectdialog
);
230 this . steps
. push ( this . finish
);
232 showStep : function () {
233 this . backBtn
. disabled
= !( this . step
> 0 );
235 this . nextBtn
. value
= ( this . step
>= this . steps
. length
- 1 )? "Close" : "Next >" ;
237 this . steps
[ this . step
]. show ();
240 var pm
= this . steps
[ this . step
]. options
. premove
;
246 if ( this . step
>= this . steps
. length
- 1 ) {
250 this . step
= this . step
+ 1 ;
254 this . fireEvent ( "close" );
260 this . step
= this . step
- 1 ;
263 generateURL : function () {
264 var chans
= this . chanBox
. value
;
265 var nick
= this . nicknameBox
. value
;
266 var connectdialog
= this . connectdialogr
. checked
&& chans
!= "" && ! this . choosenick
. checked
;
269 if ( this . presetnick
. checked
) {
270 URL
. push ( "nick=" + escape ( nick
));
271 } else if (! this . choosenick
. checked
) {
272 URL
. push ( "randomnick=1" );
276 var d
= chans
. split ( "," );
279 d
. forEach ( function ( x
) {
280 if ( x
. charAt ( 0 ) == '#' )
286 URL
. push ( "channels=" + escape ( d2
. join ( "," )));
290 URL
. push ( "prompt=1" );
292 return this . options
. baseURL
+ ( URL
. length
> 0 ? "?" : "" ) + URL
. join ( "&" );