]>
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
);
91 var r
= qwebirc
. util
. createInput ( "radio" , p
, name
, selected
);
92 p
. appendChild ( document
. createTextNode ( text
));
96 addSteps : function () {
97 var af = function ( select
) {
98 if ( Browser
. Engine
. trident
) {
104 f
. delay ( 100 , this , []);
111 this . welcome
= this . newStep ({
113 "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."
116 this . chanBox
= new Element ( "input" );
117 this . chanBox
. addClass ( "text" );
118 this . chans
= this . newStep ({
119 "title" : "Set channels" ,
120 "first" : "Enter the channels you would like the client to join on startup:" ,
121 "hint" : "You can supply multiple channels by seperating them with a comma, e.g.:" ,
122 "example" : "#rogue,#eu-mage" ,
124 }). addEvent ( "show" , af
. bind ( this . chanBox
));
126 var customnickDiv
= new Element ( "div" );
127 this . customnick
= this . newStep ({
128 "title" : "Nickname mode" ,
129 "first" : "At startup would you like the client to use a random nickname, a preset nickname or a nickname of the users choice?" ,
130 "hint" : "It is recommended that you only use a preset nickname if the client is for your own personal use." ,
131 middle : customnickDiv
134 this . choosenick
= this . newRadio ( customnickDiv
, "Make the user choose a nickname." , "nick" , true );
135 this . randnick
= this . newRadio ( customnickDiv
, "Use a random nickname, e.g. qwebirc12883." , "nick" );
136 this . presetnick
= this . newRadio ( customnickDiv
, "Use a preset nickname of your choice." , "nick" );
138 var promptdiv
= new Element ( "form" );
139 this . connectdialog
= this . newStep ({
140 "title" : "Display connect dialog?" ,
141 "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?" ,
143 "hint" : "You need to display the dialog if you want the user to be able to set their nickname before connecting."
146 var autoconnect
= this . newRadio ( promptdiv
, "Connect without displaying the dialog." , "prompt" , true );
147 this . connectdialogr
= this . newRadio ( promptdiv
, "Show the connect dialog." , "prompt" );
149 this . nicknameBox
= new Element ( "input" );
150 this . nicknameBox
. addClass ( "text" );
151 this . nickname
= this . newStep ({
152 "title" : "Set nickname" ,
153 "first" : "Enter the nickname you would like the client to use by default:" ,
154 "premove" : function () {
155 if ( this . nicknameBox
. value
== "" ) {
156 alert ( "You must supply a nickname." );
157 this . nicknameBox
. focus ();
162 middle : this . nicknameBox
163 }). addEvent ( "show" , af
. bind ( this . nicknameBox
));
165 var codeDiv
= new Element ( "div" );
166 this . finish
= this . newStep ({
167 "title" : "Finished!" ,
168 "first" : "Your custom link is:" ,
170 }). addEvent ( "show" , function () {
171 var alink
= new Element ( "a" );
172 var abox
= new Element ( "input" );
173 abox
. addClass ( "iframetext" );
174 var url
= this . generateURL ( false );
177 alink
. target
= "new" ;
178 alink
. appendChild ( document
. createTextNode ( url
));
179 abox
. value
= "<iframe src= \" " + url
+ " \" width= \" 647 \" height= \" 400 \" ></iframe>" ;
183 new Element ( "br" ), new Element ( "br" ),
184 document
. createTextNode ( "You can embed this into your page with the following code:" ),
189 while ( codeDiv
. childNodes
. length
> 0 )
190 codeDiv
. removeChild ( codeDiv
. childNodes
[ 0 ]);
192 mBox
. forEach ( function ( x
) {
193 codeDiv
. appendChild ( x
);
197 abox
. addEvent ( "click" , function () {
207 updateSteps : function () {
208 this . steps
= [ this . welcome
, this . customnick
];
210 if ( this . presetnick
. checked
)
211 this . steps
. push ( this . nickname
);
213 this . steps
. push ( this . chans
);
215 if ( this . chanBox
. value
!= "" && ! this . choosenick
. checked
)
216 this . steps
. push ( this . connectdialog
);
218 this . steps
. push ( this . finish
);
220 showStep : function () {
221 this . backBtn
. disabled
= !( this . step
> 0 );
223 this . nextBtn
. value
= ( this . step
>= this . steps
. length
- 1 )? "Close" : "Next >" ;
225 this . steps
[ this . step
]. show ();
228 var pm
= this . steps
[ this . step
]. options
. premove
;
234 if ( this . step
>= this . steps
. length
- 1 ) {
238 this . step
= this . step
+ 1 ;
242 this . fireEvent ( "close" );
248 this . step
= this . step
- 1 ;
251 generateURL : function () {
252 var chans
= this . chanBox
. value
;
253 var nick
= this . nicknameBox
. value
;
254 var connectdialog
= this . connectdialogr
. checked
&& chans
!= "" && ! this . choosenick
. checked
;
257 if ( this . presetnick
. checked
) {
258 URL
. push ( "nick=" + escape ( nick
));
259 } else if (! this . choosenick
. checked
) {
260 URL
. push ( "randomnick=1" );
264 var d
= chans
. split ( "," );
267 d
. forEach ( function ( x
) {
268 if ( x
. charAt ( 0 ) == '#' )
274 URL
. push ( "channels=" + escape ( d2
. join ( "," )));
278 URL
. push ( "prompt=1" );
280 return this . options
. baseURL
+ ( URL
. length
> 0 ? "?" : "" ) + URL
. join ( "&" );