Dotclear

source: admin/js/_posts_list.js @ 1034:b11afd216931

Revision 1034:b11afd216931, 2.8 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

A little bit more elegant code

Line 
1dotclear.postExpander = 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.viewPostContent(this,this.line); };
11     
12     td.insertBefore(img,td.firstChild);
13};
14
15dotclear.postsExpander = 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.viewPostsContent(this,this.lines); };
25
26     td.insertBefore(img,td.firstChild);
27};
28
29dotclear.viewPostsContent = function(img,lines) {
30     lines.each(function() {
31          var td = this.firstChild;
32          td.firstChild.click();
33     });
34
35     if (img.alt == dotclear.img_plus_alt) {
36          img.src = dotclear.img_minus_src;
37          img.alt = dotclear.img_minus_alt;
38     } else {
39          img.src = dotclear.img_plus_src;
40          img.alt = dotclear.img_plus_alt;
41     }
42};
43
44dotclear.viewPostContent = function(img,line) {
45     var postId = line.id.substr(1);
46     var tr = document.getElementById('pe'+postId);
47     
48     if (!tr) {
49          tr = document.createElement('tr');
50          tr.id = 'pe'+postId;
51          var td = document.createElement('td');
52          td.colSpan = 8;
53          td.className = 'expand';
54          tr.appendChild(td);
55         
56          img.src = dotclear.img_minus_src;
57          img.alt = dotclear.img_minus_alt;
58         
59          // Get post content
60          $.get('services.php',{f:'getPostById', id: postId, post_type: ''},function(data) {
61               var rsp = $(data).children('rsp')[0];
62               
63               if (rsp.attributes[0].value == 'ok') {
64                    var post = $(rsp).find('post_display_content').text();
65                    var post_excerpt = $(rsp).find('post_display_excerpt').text();
66                    var res = '';
67                   
68                    if (post) {
69                         if (post_excerpt) {
70                              res += post_excerpt + '<hr />';
71                         }
72                         res += post;
73                         $(td).append(res);
74                    }
75               } else {
76                    alert($(rsp).find('message').text());
77               }
78          });
79         
80          $(line).toggleClass('expand');
81          line.parentNode.insertBefore(tr,line.nextSibling);
82     }
83     else if (tr.style.display == 'none')
84     {
85          $(tr).toggle();
86          $(line).toggleClass('expand');
87          img.src = dotclear.img_minus_src;
88          img.alt = dotclear.img_minus_alt;
89     }
90     else
91     {
92          $(tr).toggle();
93          $(line).toggleClass('expand');
94          img.src = dotclear.img_plus_src;
95          img.alt = dotclear.img_plus_alt;
96     }
97};
98
99$(function() {
100     // Entry type switcher
101     $('#type').change(function() {
102          this.form.submit();
103     });
104
105     $('#form-entries tr:not(.line)').each(function() {
106          dotclear.postsExpander(this,$('#form-entries tr.line'));
107     });
108     $('#form-entries tr.line').each(function() {
109          dotclear.postExpander(this);
110     });
111     $('.checkboxes-helpers').each(function() {
112          dotclear.checkboxesHelpers(this);
113     });
114     $('#form-entries td input[type=checkbox]').enableShiftClick();
115     dotclear.postsActionsHelper();
116});
Note: See TracBrowser for help on using the repository browser.

Sites map