6b0d901d6035ade75cef9e5bad2ab355c4b9dcc9
1 /*jslint browser: true, devel: true, sloppy: true, plusplus: true, nomen: true, forin: true, continue: true */
2 /*globals kiwi, $, _, Tabview, Userlist, User, Box */
5 doLayoutSize: function () {
6 var kiwi
, toolbars
, ul
, n_top
, n_bottom
, nl
;
9 if (kiwi
.width() < 330 && !kiwi
.hasClass('small_kiwi')) {
10 console
.log("switching to small kiwi");
11 kiwi
.removeClass('large_kiwi');
12 kiwi
.addClass('small_kiwi');
13 } else if (kiwi
.width() >= 330 && !kiwi
.hasClass('large_kiwi')) {
14 kiwi
.removeClass('small_kiwi');
15 kiwi
.addClass('large_kiwi');
18 toolbars
= $('#kiwi .toolbars');
19 ul
= $('#kiwi .userlist');
21 n_top
= parseInt(toolbars
.offset().top
, 10) + parseInt(toolbars
.outerHeight(true), 10);
22 n_bottom
= $(document
).height() - parseInt($('#kiwi .control').offset().top
, 10);
24 $('#kiwi .windows').css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px'});
25 ul
.css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px'});
27 nl
= $('#nicklist_resize');
28 nl
.css({top
: n_top
+ 'px', bottom
: n_bottom
+ 'px', left
: $(document
).width() - ul
.outerWidth(true)});
32 doLayout: function () {
33 $('#kiwi .msginput .nick a').text(kiwi
.gateway
.nick
);
34 $('#kiwi_msginput').val(' ');
35 $('#kiwi_msginput').focus();
39 registerKeys: function () {
40 var tabcomplete
= {active
: false, data
: [], prefix
: ''};
41 $('#kiwi_msginput').bind('keydown', function (e
) {
42 var windows
, meta
, num
, msg
, data
, self
;
43 windows
= $('#windows');
44 //var meta = e.altKey;
48 tabcomplete
.active
= false;
49 tabcomplete
.data
= [];
50 tabcomplete
.prefix
= '';
54 case (e
.which
>= 48) && (e
.which
<= 57):
61 kiwi
.front
.ui
.windowsShow(num
);
65 case e
.which
=== 27: // escape
67 case e
.which
=== 13: // return
68 msg
= $('#kiwi_msginput').val();
71 kiwi
.front
.buffer
.push(msg
);
72 kiwi
.front
.buffer_pos
= kiwi
.front
.buffer
.length
;
75 $('#kiwi_msginput').val('');
78 case e
.which
=== 33: // page up
79 console
.log("page up");
80 windows
[0].scrollTop
= windows
[0].scrollTop
- windows
.height();
82 case e
.which
=== 34: // page down
83 windows
[0].scrollTop
= windows
[0].scrollTop
+ windows
.height();
85 case e
.which
=== 37: // left
87 kiwi
.front
.ui
.windowsPrevious();
91 case e
.which
=== 38: // up
92 if (kiwi
.front
.buffer_pos
> 0) {
93 kiwi
.front
.buffer_pos
--;
94 $('#kiwi_msginput').val(kiwi
.front
.buffer
[kiwi
.front
.buffer_pos
]);
97 case e
.which
=== 39: // right
99 kiwi
.front
.ui
.windowsNext();
103 case e
.which
=== 40: // down
104 if (kiwi
.front
.buffer_pos
< kiwi
.front
.buffer
.length
) {
105 kiwi
.front
.buffer_pos
++;
106 $('#kiwi_msginput').val(kiwi
.front
.buffer
[kiwi
.front
.buffer_pos
]);
110 case e
.which
=== 9: // tab
111 tabcomplete
.active
= true;
112 if (_
.isEqual(tabcomplete
.data
, [])) {
113 // Get possible autocompletions
115 $.each(Tabview
.getCurrentTab().userlist
.listUsers(false), function () {
117 nick
= User
.stripPrefix(this.nick
);
120 data
= _
.sortBy(data
, function (nick
) {
123 tabcomplete
.data
= data
;
126 if (this.value
[this.selectionStart
- 1] === ' ') {
131 var tokens
= self
.value
.substring(0, self
.selectionStart
).split(" "),
136 nick
= tokens
[tokens
.length
- 1];
137 if (tabcomplete
.prefix
=== '') {
138 tabcomplete
.prefix
= nick
;
141 tabcomplete
.data
= _
.select(tabcomplete
.data
, function (n
) {
142 return (n
.toLowerCase().indexOf(tabcomplete
.prefix
.toLowerCase()) === 0);
145 if (tabcomplete
.data
.length
> 0) {
146 p1
= self
.selectionStart
- (nick
.length
);
147 val
= self
.value
.substr(0, p1
);
148 newnick
= tabcomplete
.data
.shift();
149 tabcomplete
.data
.push(newnick
);
151 val
+= self
.value
.substr(self
.selectionStart
);
153 if (self
.setSelectionRange
) {
154 self
.setSelectionRange(p1
+ newnick
.length
, p1
+ newnick
.length
);
155 } else if (self
.createTextRange
) { // not sure if this bit is actually needed....
156 range
= self
.createTextRange();
157 range
.collapse(true);
158 range
.moveEnd('character', p1
+ newnick
.length
);
159 range
.moveStart('character', p1
+ newnick
.length
);
169 $('#kiwi .control .msginput .nick').click(function () {
170 kiwi
.front
.ui
.showChangeNick();
177 $('#kiwi .plugins .load_plugin_file').click(function () {
178 if (typeof kiwi
.front
.boxes
.plugins
!== "undefined") {
182 kiwi
.front
.boxes
.plugins
= new Box("plugin_file");
183 $('#tmpl_plugins').tmpl({}).appendTo(kiwi
.front
.boxes
.plugins
.content
);
184 kiwi
.front
.boxes
.plugins
.box
.css('top', -(kiwi
.front
.boxes
.plugins
.height
+ 40));
186 // Populate the plugin list..
187 function enumPlugins() {
189 lst
= $('#plugin_list');
190 lst
.find('option').remove();
191 for (j
in kiwi
.plugs
.loaded
) {
192 txt
= kiwi
.plugs
.loaded
[j
].name
;
193 lst
.append('<option value="' + txt
+ '">' + txt
+ '</option>');
199 $('#kiwi .plugin_file').submit(function () {
200 $('<div></div>').load($('.txtpluginfile').val(), function (e
) {
205 $('#kiwi .cancelpluginfile').click(function () {
206 kiwi
.front
.boxes
.plugins
.destroy();
209 $('#kiwi #plugins_list_unload').click(function () {
211 selected_plugin
= $('#plugin_list').val();
212 kiwi
.plugs
.unloadPlugin(selected_plugin
);
216 $('#kiwi .txtpluginfile').focus();
220 $('#kiwi .plugins .reload_css').click(function () {
221 var links
= document
.getElementsByTagName("link"),
223 for (i
= 0; i
< links
.length
; i
++) {
224 if (links
[i
].rel
=== "stylesheet") {
225 if (links
[i
].href
.indexOf("?") === -1) {
226 links
[i
].href
+= "?";
228 links
[i
].href
+= "x";
234 $('#kiwi .about .about_close').click(function () {
235 $('#kiwi .about').css('display', 'none');
239 $('#kiwi .poweredby').click(function () {
240 $('#kiwi .about').css('display', 'block');
246 showChangeNick: function (caption
) {
247 caption
= (typeof caption
!== 'undefined') ? caption
: '';
249 $('#kiwi').append($('#tmpl_change_nick').tmpl({}));
251 $('#kiwi .newnick .caption').text(caption
);
253 $('#kiwi .form_newnick').submit(function () {
254 kiwi
.front
.run('/NICK ' + $('#kiwi .txtnewnick').val());
255 $('#kiwi .newnick').remove();
259 $('#kiwi .txtnewnick').keypress(function (ev
) {
260 if (!this.first_press
) {
261 this.first_press
= true;
266 $('#kiwi .txtnewnick').keydown(function (ev
) {
267 if (ev
.which
=== 27) { // ESC
268 $('#kiwi_msginput').focus();
269 $('#kiwi .newnick').remove();
273 $('#kiwi .cancelnewnick').click(function () {
274 $('#kiwi .newnick').remove();
277 $('#kiwi .txtnewnick').focus();
282 setTopicText: function (new_topic
) {
283 kiwi
.front
.cache
.original_topic
= new_topic
;
284 $('#kiwi .cur_topic .topic').text(new_topic
);
285 kiwi
.front
.ui
.doLayoutSize();
291 tabviewsNext: function () {
292 var wl
= $('#kiwi .windowlist ul'),
293 next_left
= parseInt(wl
.css('text-indent').replace('px', ''), 10) + 170;
294 wl
.css('text-indent', next_left
);
297 tabviewsPrevious: function () {
298 var wl
= $('#kiwi .windowlist ul'),
299 next_left
= parseInt(wl
.css('text-indent').replace('px', ''), 10) - 170;
300 wl
.css('text-indent', next_left
);
303 windowsNext: function () {
304 var tab
, tabs
, curTab
, next
;
306 tabs
= Tabview
.getAllTabs();
307 curTab
= Tabview
.getCurrentTab();
310 if (tabs
[tab
] === curTab
) {
321 windowsPrevious: function () {
322 var tab
, tabs
, curTab
, prev_tab
, next
;
324 tabs
= Tabview
.getAllTabs();
325 curTab
= Tabview
.getCurrentTab();
327 if (tabs
[tab
] === curTab
) {
333 prev_tab
= tabs
[tab
];
337 windowsShow: function (num
) {
338 num
= parseInt(num
, 10);
339 console
.log('Showing window ' + num
.toString());
340 var i
= 0, tab
, tabs
;
341 tabs
= Tabview
.getAllTabs();
353 barsShow: function () {
354 $('#kiwi .control').slideDown();
355 $('#kiwi .toolbars').slideDown(400, function () {
356 kiwi
.front
.ui
.doLayoutSize();
360 barsHide: function () {
361 $('#kiwi .control').slideUp();
362 $('#kiwi .toolbars').slideUp(400, function () {
363 kiwi
.front
.ui
.doLayoutSize();
374 tutorial: function () {
375 var b
= $('<div id="tutorial_box" style="border:3px solid blue;"></div>'),
380 b
.css({display
: 'block', position
: 'absolute', height
:'100%', width
:'100%'});
381 $('#kiwi').append(b
);
383 bounds = function (el
) {
385 ret
.top
= el
.offset().top
;
386 ret
.left
= el
.offset().left
;
387 ret
.width
= parseInt(el
.outerWidth(true), 10) - (b
*2);
388 ret
.height
= parseInt(el
.outerHeight(true), 10) - (b
*2);
394 b
.animate(bounds($('#kiwi .msginput')), 2000, '', next_s
);
398 b
.animate(bounds($('#kiwi .userlist')), 2000, '', next_s
);
402 b
.animate(bounds($('#panel1')), 2000, '', next_s
);
406 b
.animate(bounds($('#kiwi .cur_topic')), 2000, '', next_s
);
410 b
.animate(bounds($('#kiwi .windowlist')), 2000, '', next_s
);
416 next_s = function () {
418 if (typeof s
[current_s
] === 'function') {
419 console
.log('Animating ' + current_s
.toString());