Dotclear

source: admin/js/_plugins.js @ 2222:30fe556de226

Revision 2222:30fe556de226, 6.6 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Enhance repository search engine (and some fix)

Line 
1dotclear.moduleExpander = function(line) {
2        var td = line.firstChild;
3       
4        var img = document.createElement('img');
5        img.src = dotclear.img_plus_src;
6        img.alt = dotclear.img_plus_alt;
7        img.className = 'expand';
8        $(img).css('cursor','pointer');
9        img.line = line;
10        img.onclick = function() { dotclear.viewModuleContent(this,this.line); };
11       
12        td.insertBefore(img,td.firstChild);
13};
14
15dotclear.modulesExpander = function(line,lines) {
16        var td = line.firstChild;
17
18        var img = document.createElement('img');
19        img.src = dotclear.img_plus_src;
20        img.alt = dotclear.img_plus_alt;
21        img.className = 'expand';
22        $(img).css('cursor','pointer');
23        img.lines = lines;
24        img.onclick = function() { dotclear.viewModulesContent(this,this.lines); };
25
26        td.insertBefore(img,td.firstChild);
27};
28
29dotclear.viewModulesContent = function(img,lines) {
30       
31        action = 'toggle';
32
33        if (img.alt == dotclear.img_plus_alt) {
34                img.src = dotclear.img_minus_src;
35                img.alt = dotclear.img_minus_alt;
36                action = 'open';
37        } else {
38                img.src = dotclear.img_plus_src;
39                img.alt = dotclear.img_plus_alt;
40                action = 'close';
41        }
42       
43        lines.each(function() {
44                var td = this.firstChild;
45                dotclear.viewModuleContent(td.firstChild,td.firstChild.line,action);
46        });
47};
48
49dotclear.viewModuleContent = function(img,line,action) {
50
51        var action = action || 'toggle';
52          var cols = $('td',$(line)).length
53        var sp = line.id.split('_m_');
54          var listId=sp[0];
55          var moduleId= sp[1];
56
57        var tr = document.getElementById('pe'+moduleId);
58       
59          if ( !tr && ( action == 'toggle' || action == 'open' ) ) {
60                tr = document.createElement('tr');
61                tr.id = 'pe'+moduleId;
62
63                var td = document.createElement('td');
64                td.colSpan = cols;
65                td.className = 'expand';
66                tr.appendChild(td);
67               
68                img.src = dotclear.img_minus_src;
69                img.alt = dotclear.img_minus_alt;
70               
71                // Get post content
72                $.get('services.php',{f:'getModuleById', id: moduleId, list: listId},function(data) {
73                        var rsp = $(data).children('rsp')[0];
74                       
75                        if (rsp.attributes[0].value == 'ok') {
76                                var author = $(rsp).find('author').text();
77                                var details = $(rsp).find('details').text();
78                                var support = $(rsp).find('support').text();
79                                        var box = document.createElement('div');
80                                var bloc = document.createElement('ul');
81                                bloc.className = "mod-more";
82                               
83                                if (author) {
84                                        $(bloc).append($('<li class="module-author">'+dotclear.msg.module_author+' '+author+'</li>'));
85                                }
86                                if (details) {
87                                        var dd = '';
88                                        dd += '<a class="module-details" href="'+details+'">'+dotclear.msg.module_details+'</a>';
89                                        if (support) {
90                                                dd += ' - ';
91                                                dd += '<a class="module-support" href="'+support+'">'+dotclear.msg.module_support+'</a>';
92                                        }
93                                        $(bloc).append($('<li>'+dotclear.msg.module_help+' '+dd+'</li>'));
94                                }
95
96                                $(td).append($(box).addClass('two-boxes').append(bloc));
97                               
98                                var section = $(rsp).find('section').text();
99                                var tags = $(rsp).find('tags').text();
100                               
101                                        var boxb = document.createElement('div');
102                                var blocb = document.createElement('ul');
103                                blocb.className = "mod-more";
104                               
105                                if (section) {
106                                        $(blocb).append($('<li class="module-section">'+dotclear.msg.module_section+' '+section+'</li>'));
107                                }
108                                if (tags) {
109                                        $(blocb).append($('<li class="module-tags">'+dotclear.msg.module_tags+' '+tags+'</li>'));
110                                }
111                                $(td).append($(boxb).addClass('two-boxes').append(blocb));
112                        } else {
113                                alert($(rsp).find('message').text());
114                        }
115                });
116               
117                $(line).addClass('expand');
118                line.parentNode.insertBefore(tr,line.nextSibling);
119        }
120        else if (tr && tr.style.display == 'none' && ( action == 'toggle' || action == 'open' ) )
121        {
122                $(tr).css('display', 'table-row');
123                $(line).addClass('expand');
124                img.src = dotclear.img_minus_src;
125                img.alt = dotclear.img_minus_alt;
126        }
127        else if (tr && tr.style.display != 'none' && ( action == 'toggle' || action == 'close' ) )
128        {
129                $(tr).css('display', 'none');
130                $(line).removeClass('expand');
131                img.src = dotclear.img_plus_src;
132                img.alt = dotclear.img_plus_alt;
133        }
134       
135        parentTable = $(line).parents('table');
136        if( parentTable.find('tr.expand').length == parentTable.find('tr.line').length ) {
137                img = parentTable.find('tr:not(.line) th:first img');
138                img.attr('src',dotclear.img_minus_src);
139                img.attr('alt',dotclear.img_minus_alt);
140        }
141       
142        if( parentTable.find('tr.expand').length == 0 ) {
143                img = parentTable.find('tr:not(.line) th:first img');
144                img.attr('src',dotclear.img_plus_src);
145                img.attr('alt',dotclear.img_plus_alt);
146        }
147       
148};
149
150
151$(function() {
152        $('table.modules.expandable tr:not(.line)').each(function() {
153                dotclear.modulesExpander(this,$('table.modules.expandable tr.line'));
154        });
155        $('table.modules.expandable tr.line').each(function() {
156                dotclear.moduleExpander(this);
157        });
158});
Note: See TracBrowser for help on using the repository browser.

Sites map