]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/embed.js
1 /* NEEDS converting to plain HTML! */
2 qwebirc
. ui
. EmbedWizardStep
= new Class ({
3 Implements : [ Options
, Events
],
12 initialize : function ( parent
, options
) {
13 this . setOptions ( options
);
17 this . parent
. title
. set ( "html" , this . options
. title
);
18 this . parent
. firstRow
. set ( "html" , this . options
. first
);
19 this . parent
. hint
. set ( "html" , this . options
. hint
);
20 this . parent
. example
. set ( "text" , this . options
. example
);
22 while ( this . parent
. middleRow
. childNodes
. length
> 0 )
23 this . parent
. middleRow
. removeChild ( this . parent
. middleRow
. childNodes
[ 0 ]);
25 if ($ defined ( this . options
. middle
))
26 this . parent
. middleRow
. appendChild ( this . options
. middle
);
28 this . fireEvent ( "show" );
32 qwebirc
. ui
. EmbedWizard
= new Class ({
33 Implements : [ Options
, Events
],
36 optionsCallback : null ,
37 baseURL : "http://webchat.quakenet.org/"
39 initialize : function ( parent
, options
) {
40 /* for some unknown reason setOptions doesn't work... */
41 this . options
. uiOptions
= options
. uiOptions
;
42 this . options
. baseURL
= options
. baseURL
;
43 this . options
. optionsCallback
= options
. optionsCallback
;
47 create : function ( parent
) {
50 var titleRow
= this . newRow ();
51 this . title
= new Element ( "h2" );
52 this . title
. setStyle ( "margin-top" , "0px" );
53 this . title
. setStyle ( "margin-bottom" , "5px" );
54 titleRow
. appendChild ( this . title
);
56 this . firstRow
= this . newRow ();
57 this . middleRow
= this . newRow ();
58 var hintRow
= this . newRow ();
59 this . hint
= new Element ( "div" );
60 this . hint
. setStyle ( "font-size" , "0.8em" );
61 this . hint
. setStyle ( "font-style" , "italic" );
62 hintRow
. appendChild ( this . hint
);
63 var exampleRow
= this . newRow ();
64 this . example
= new Element ( "pre" );
65 exampleRow
. appendChild ( this . example
);
67 var nextRow
= this . newRow ();
68 nextRow
. addClass ( "wizardcontrols" );
69 var backBtn
= new Element ( "input" );
70 backBtn
. type
= "submit" ;
71 backBtn
. value
= "< Back" ;
72 backBtn
. addEvent ( "click" , this . back
. bind ( this ));
73 nextRow
. appendChild ( backBtn
);
75 var nextBtn
= new Element ( "input" );
76 nextBtn
. type
= "submit" ;
77 nextBtn
. value
= "Next >" ;
78 nextRow
. appendChild ( nextBtn
);
79 nextBtn
. addEvent ( "click" , this . next
. bind ( this ));
81 this . nextBtn
= nextBtn
;
82 this . backBtn
= backBtn
;
85 var cell
= new Element ( "div" );
86 this . t
. appendChild ( cell
);
89 newStep : function ( options
) {
90 return new qwebirc
. ui
. EmbedWizardStep ( this , options
);
92 newRadio : function ( parent
, text
, name
, selected
) {
93 var p
= new Element ( "div" );
94 parent
. appendChild ( p
);
96 var id
= qwebirc
. util
. generateID ();
97 var r
= qwebirc
. util
. createInput ( "radio" , p
, name
, selected
, id
);
99 var label
= new Element ( "label" , { "for" : id
});
100 label
. appendChild ( document
. createTextNode ( text
));
101 p
. appendChild ( label
);
105 addSteps : function () {
106 var af = function ( select
) {
107 if ( Browser
. Engine
. trident
) {
113 f
. delay ( 100 , this , []);
120 this . welcome
= this . newStep ({
121 "title" : "Add webchat to your website" ,
122 "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."
125 this . chanBox
= new Element ( "input" );
126 this . chanBox
. addClass ( "text" );
127 this . chans
= this . newStep ({
128 "title" : "Set channels" ,
129 "first" : "Enter the channels you would like the client to join on startup:" ,
130 "hint" : "You can supply multiple channels by seperating them with a comma, e.g.:" ,
131 "example" : "#rogue,#eu-mage" ,
133 }). addEvent ( "show" , af
. bind ( this . chanBox
));
135 var customnickDiv
= new Element ( "div" );
136 this . customnick
= this . newStep ({
137 "title" : "Choose a nickname mode" ,
138 "first" : "At startup would you like the client to use a random nickname, a preset nickname or a nickname of the users choice?" ,
139 "hint" : "It is recommended that you only use a preset nickname if the client is for your own personal use." ,
140 middle : customnickDiv
143 this . choosenick
= this . newRadio ( customnickDiv
, "Make the user choose a nickname." , "nick" , true );
144 this . randnick
= this . newRadio ( customnickDiv
, "Use a random nickname, e.g. qwebirc12883." , "nick" );
145 this . presetnick
= this . newRadio ( customnickDiv
, "Use a preset nickname of your choice." , "nick" );
147 var promptdiv
= new Element ( "form" );
148 this . connectdialog
= this . newStep ({
149 "title" : "Display connect dialog?" ,
150 "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?" ,
152 "hint" : "You need to display the dialog if you want the user to be able to set their nickname before connecting."
155 var changeOptions
= new Element ( "div" );
156 this . currentLF
= this . newRadio ( changeOptions
, "Use the current look and feel (" , "lookandfeel" , true );
158 var alterButton
= new Element ( "input" );
159 alterButton
. type
= "submit" ;
160 alterButton
. value
= "alter" ;
161 alterButton
. addEvent ( "click" , this . options
. optionsCallback
);
162 changeOptions
. firstChild
. appendChild ( alterButton
);
163 changeOptions
. firstChild
. appendChild ( document
. createTextNode ( ")." ));
165 this . defaultLF
= this . newRadio ( changeOptions
, "Use the default look and feel." , "lookandfeel" );
167 this . lookandfeel
= this . newStep ({
168 "title" : "Configure look and feel" ,
169 "first" : "The look and feel will be copied from the current settings." ,
170 middle : changeOptions
173 var autoconnect
= this . newRadio ( promptdiv
, "Connect without displaying the dialog." , "prompt" , true );
174 this . connectdialogr
= this . newRadio ( promptdiv
, "Show the connect dialog." , "prompt" );
176 this . nicknameBox
= new Element ( "input" );
177 this . nicknameBox
. addClass ( "text" );
178 this . nickname
= this . newStep ({
179 "title" : "Set nickname" ,
180 "first" : "Enter the nickname you would like the client to use by default:" ,
181 "premove" : function () {
182 if ( this . nicknameBox
. value
== "" ) {
183 alert ( "You must supply a nickname." );
184 this . nicknameBox
. focus ();
189 middle : this . nicknameBox
,
190 hint : "If you use a . (dot/period) then it will be substituted with a random number."
191 }). addEvent ( "show" , af
. bind ( this . nicknameBox
));
193 var codeDiv
= new Element ( "div" );
194 this . finish
= this . newStep ({
195 "title" : "Finished!" ,
196 "first" : "Your custom link is:" ,
198 }). addEvent ( "show" , function () {
199 var alink
= new Element ( "a" );
200 var abox
= new Element ( "input" );
201 abox
. addClass ( "iframetext" );
202 var url
= this . generateURL ( false );
205 alink
. target
= "new" ;
206 alink
. appendChild ( document
. createTextNode ( url
));
207 abox
. value
= "<iframe src= \" " + url
+ " \" width= \" 647 \" height= \" 400 \" ></iframe>" ;
211 new Element ( "br" ), new Element ( "br" ),
212 document
. createTextNode ( "You can embed this into your page with the following code:" ),
217 while ( codeDiv
. childNodes
. length
> 0 )
218 codeDiv
. removeChild ( codeDiv
. childNodes
[ 0 ]);
220 mBox
. forEach ( function ( x
) {
221 codeDiv
. appendChild ( x
);
225 abox
. addEvent ( "click" , function () {
235 updateSteps : function () {
236 this . steps
= [ this . welcome
, this . customnick
];
238 if ( this . presetnick
. checked
)
239 this . steps
. push ( this . nickname
);
241 this . steps
. push ( this . chans
);
243 if ( this . chanBox
. value
!= "" && ! this . choosenick
. checked
)
244 this . steps
. push ( this . connectdialog
);
246 this . steps
. push ( this . lookandfeel
);
247 this . steps
. push ( this . finish
);
249 showStep : function () {
250 this . backBtn
. disabled
= !( this . step
> 0 );
252 this . nextBtn
. value
= ( this . step
>= this . steps
. length
- 1 )? "Close" : "Next >" ;
254 this . steps
[ this . step
]. show ();
257 var pm
= this . steps
[ this . step
]. options
. premove
;
263 if ( this . step
>= this . steps
. length
- 1 ) {
267 this . step
= this . step
+ 1 ;
271 this . fireEvent ( "close" );
277 this . step
= this . step
- 1 ;
280 generateURL : function () {
281 var chans
= this . chanBox
. value
;
282 var nick
= this . nicknameBox
. value
;
283 var connectdialog
= this . connectdialogr
. checked
&& chans
!= "" && ! this . choosenick
. checked
;
286 if ( this . presetnick
. checked
) {
287 URL
. push ( "nick=" + escape ( nick
));
288 } else if (! this . choosenick
. checked
) {
289 URL
. push ( "randomnick=1" );
293 var d
= chans
. split ( "," );
296 d
. forEach ( function ( x
) {
297 if ( x
. charAt ( 0 ) == '#' )
303 URL
. push ( "channels=" + escape ( d2
. join ( "," )));
307 URL
. push ( "prompt=1" );
309 if ( this . currentLF
. checked
) {
310 var uioptions
= this . options
. uiOptions
. serialise ();
312 URL
. push ( "uio=" + uioptions
);
315 return this . options
. baseURL
+ ( URL
. length
> 0 ? "?" : "" ) + URL
. join ( "&" );