Dotclear

source: admin/js/_posts_list.js @ 2526:a96260306d4e

Revision 2526:a96260306d4e, 3.2 KB checked in by Nicolas <nikrou77@…>, 12 years ago (diff)

Add link around expand image for a11y; comments list. Addresses #1848
Fix toggle status (open or close) when clicking main arrow

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

Sites map