1171b1acc8b1cbc23c101abba7e2ff3093a87515
[phorkie.git] / www / phorkie.js
1 function filenameChange(elem, id) {
2     var filename = elem.value;
3     var hasExt = filename.indexOf(".") != -1;
4     if (hasExt) {
5         $('#typeselect_' + id).hide();
6         $('#typetext_' + id).show();
7     } else {
8         $('#typeselect_' + id).show();
9         $('#typetext_' + id).hide();
10     }
11 }
12
13 function initEdit()
14 {
15     initFilenames();
16     initAdditionals();
17     $('.filegroup:visible:last textarea').focus();
18 }
19 function initFilenames()
20 {
21     $('input.filename').each(
22         function(num, elem) {
23             var id = elem.id;
24             var pos = id.indexOf('_');
25             if (pos != -1) {
26                 var elemNum = id.substr(pos + 1);
27                 if (elemNum != 'new') {
28                     filenameChange(elem, elemNum);
29                 }
30             }
31         }
32     );
33 }
34 function initAdditionals()
35 {
36     $('a.additional-btn').each(
37         function(num, elem) {
38             toggleAdditional(elem, 0);
39             $(elem).show();
40         }
41     );
42 }
43
44 function toggleAdditional(elem, time)
45 {
46     if (undefined == time) {
47         time = 'fast';
48     }
49     var jt = jQuery(elem);
50     jt.children('i').toggleClass('icon-chevron-down')
51         .toggleClass('icon-chevron-up');
52     jt.parents('.row-fluid').children('.additional').toggle(time);
53 }