]>
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 ( options
) {
38 this . setOptions ( options
);
39 this . create ( options
. parent
);
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
. setStyle ( "position" , "absolute" );
64 nextRow
. setStyle ( "bottom" , "0px" );
65 nextRow
. setStyle ( "right" , "0px" );
66 nextRow
. setStyle ( "margin" , "3px" );
67 var backBtn
= new Element ( "input" );
68 backBtn
. type
= "submit" ;
69 backBtn
. value
= "< Back" ;
70 backBtn
. addEvent ( "click" , this . back
. bind ( this ));
71 nextRow
. appendChild ( backBtn
);
73 var nextBtn
= new Element ( "input" );
74 nextBtn
. type
= "submit" ;
75 nextBtn
. value
= "Next >" ;
76 nextRow
. appendChild ( nextBtn
);
77 nextBtn
. addEvent ( "click" , this . next
. bind ( this ));
79 this . nextBtn
= nextBtn
;
80 this . backBtn
= backBtn
;
83 var cell
= new Element ( "div" );
84 this . t
. appendChild ( cell
);
87 newStep : function ( options
) {
88 return new qwebirc
. ui
. EmbedWizardStep ( this , options
);
90 newRadio : function ( parent
, text
, name
, selected
) {
91 var p
= new Element ( "div" );
92 parent
. appendChild ( p
);
94 var r
= new Element ( "input" );
102 p
. appendChild ( document
. createTextNode ( text
));
106 addSteps : function () {
107 var af = function () { this . options
. middle
. focus (); };
109 this . welcome
= this . newStep ({
111 "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."
114 this . chanBox
= new Element ( "input" );
115 this . chans
= this . newStep ({
116 "title" : "Set channels" ,
117 "first" : "Enter the channels you would like the client to join on startup:" ,
118 "hint" : "You can supply multiple channels by seperating them with a comma, e.g.:" ,
119 "example" : "#rogue,#eu-mage" ,
121 }). addEvent ( "show" , af
);
123 var customnickDiv
= new Element ( "div" );
124 this . customnick
= this . newStep ({
125 "title" : "Nickname mode" ,
126 "first" : "At startup would you like the client to use a random nickname, a preset nickname or a nickname of the users choice?" ,
127 "hint" : "It is recommended that you only use a preset nickname if the client is for your own personal use." ,
128 middle : customnickDiv
131 this . choosenick
= this . newRadio ( customnickDiv
, "Make the user choose a nickname." , "nick" , true );
132 this . randnick
= this . newRadio ( customnickDiv
, "Use a random nickname, e.g. qwebirc12883." , "nick" );
133 this . presetnick
= this . newRadio ( customnickDiv
, "Use a preset nickname of your choice." , "nick" );
135 var promptdiv
= new Element ( "form" );
136 this . connectdialog
= this . newStep ({
137 "title" : "Display connect dialog?" ,
138 "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?" ,
140 "hint" : "You need to display the dialog if you want the user to be able to set their nickname before connecting."
143 var autoconnect
= this . newRadio ( promptdiv
, "Connect without displaying the dialog." , "prompt" , true );
144 this . connectdialogr
= this . newRadio ( promptdiv
, "Show the connect dialog." , "prompt" );
146 this . nicknameBox
= new Element ( "input" );
147 this . nickname
= this . newStep ({
148 "title" : "Set nickname" ,
149 "first" : "Enter the nickname you would like the client to use by default:" ,
150 "premove" : function () {
151 if ( this . nicknameBox
. value
== "" ) {
152 alert ( "You must supply a nickname." );
153 this . nicknameBox
. focus ();
158 middle : this . nicknameBox
159 }). addEvent ( "show" , af
);
161 var codeDiv
= new Element ( "div" );
162 this . finish
= this . newStep ({
163 "title" : "Finished!" ,
164 "first" : "Your custom link is:" ,
166 }). addEvent ( "show" , function () {
167 var alink
= new Element ( "a" );
168 var abox
= new Element ( "input" );
169 var url
= this . generateURL ();
172 alink
. target
= "new" ;
173 alink
. appendChild ( document
. createTextNode ( url
));
174 abox
. value
= "<iframe src= \" " + url
+ " \" ></iframe>" ;
178 new Element ( "br" ), new Element ( "br" ),
179 document
. createTextNode ( "You can embed this into your page with the following code:" ),
184 while ( codeDiv
. childNodes
. length
> 0 )
185 codeDiv
. removeChild ( codeDiv
. childNodes
[ 0 ]);
187 mBox
. forEach ( function ( x
) {
188 codeDiv
. appendChild ( x
);
197 updateSteps : function () {
198 this . steps
= [ this . welcome
, this . customnick
];
200 if ( this . presetnick
. checked
)
201 this . steps
. push ( this . nickname
);
203 this . steps
. push ( this . chans
);
205 if ( this . chanBox
. value
!= "" && ! this . choosenick
. checked
)
206 this . steps
. push ( this . connectdialog
);
208 this . steps
. push ( this . finish
);
210 showStep : function () {
211 this . backBtn
. disabled
= !( this . step
> 0 );
213 this . nextBtn
. value
= ( this . step
>= this . steps
. length
- 1 )? "Close" : "Next >" ;
215 this . steps
[ this . step
]. show ();
218 var pm
= this . steps
[ this . step
]. options
. premove
;
224 if ( this . step
>= this . steps
. length
- 1 ) {
228 this . step
= this . step
+ 1 ;
232 this . fireEvent ( "close" );
238 this . step
= this . step
- 1 ;
241 generateURL : function () {
242 var chans
= this . chanBox
. value
;
243 var nick
= this . nicknameBox
. value
;
244 var connectdialog
= this . connectdialogr
. checked
&& chans
!= "" && ! this . choosenick
. checked
;
247 if ( this . presetnick
. checked
) {
248 URL
. push ( "nick=" + escape ( nick
));
249 } else if (! this . choosenick
. checked
) {
250 URL
. push ( "randomnick=1" );
254 var d
= chans
. split ( "," );
257 d
. forEach ( function ( x
) {
258 if ( x
. charAt ( 0 ) == '#' )
264 URL
. push ( "channels=" + escape ( d2
. join ( "," )));
268 URL
. push ( "prompt=1" );
270 return this . options
. baseURL
+ ( URL
. length
> 0 ? "?" : "" ) + URL
. join ( "&" );