Dotclear

Changeset 2531:2daf216ff255


Ignore:
Timestamp:
11/09/13 11:40:06 (12 years ago)
Author:
Nicolas <nikrou77@…>
Branch:
2.6
Message:

Refactoring of expandContent for list (entries, comments, trackback).
Addresses #1848

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • admin/js/_comments.js

    r2527 r2531  
    1 dotclear.commentExpander = function(line) { 
    2      $('<a href="#"><img src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/></a>') 
    3           .click(function(e) { 
    4                dotclear.toggleArrow(this); 
    5                dotclear.viewCommentContent(line); 
    6                e.preventDefault(); 
    7           }) 
    8           .prependTo($(line).children().get(0)); // first td 
    9 }; 
    10  
    11 dotclear.commentsExpander = function(line,lines) { 
    12      $('<a href="#"><img src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/></a>') 
    13           .click(function(e) { 
    14                dotclear.toggleArrow(this); 
    15                lines.each(function() { 
    16                     var action = dotclear.toggleArrow(this.firstChild.firstChild); 
    17                     dotclear.viewCommentContent(this,action); 
    18                }); 
    19                e.preventDefault(); 
    20           }) 
    21           .prependTo($(line).children().get(0)); // first td 
    22 }; 
    23  
    24 dotclear.toggleArrow = function(link,action) { 
    25      action = action || ''; 
    26      var img = $(link).children().get(0); 
    27      if (action=='') { 
    28           if (img.alt==dotclear.img_plus_alt) { 
    29                action = 'open'; 
    30           } else { 
    31                action = 'close'; 
    32           } 
    33      } 
    34  
    35      if (action=='open') { 
    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      return action; 
    44 } 
    45  
    461dotclear.viewCommentContent = function(line,action) { 
     2     var action = action || 'toggle'; 
    473     var commentId = $(line).attr('id').substr(1);      
    484     var tr = document.getElementById('ce'+commentId); 
    49       
    50      if (!tr) { 
     5 
     6     if ( !tr && ( action == 'toggle' || action == 'open' ) ) { 
    517          tr = document.createElement('tr'); 
    528          tr.id = 'ce'+commentId; 
     
    8541          line.parentNode.insertBefore(tr,line.nextSibling); 
    8642     } 
    87      else if (tr.style.display == 'none') 
     43     else if (tr && tr.style.display == 'none' && ( action == 'toggle' || action == 'open' ) ) 
    8844     { 
    89           $(tr).toggle(); 
    90           $(line).toggleClass('expand'); 
     45          $(tr).css('display', 'table-row'); 
     46          $(line).addClass('expand'); 
    9147     } 
    92      else 
     48     else if (tr && tr.style.display != 'none' && ( action == 'toggle' || action == 'close' ) ) 
    9349     { 
    94           $(tr).toggle(); 
    95           $(line).toggleClass('expand'); 
     50          $(tr).css('display', 'none'); 
     51          $(line).removeClass('expand'); 
    9652     } 
    9753}; 
    9854 
    9955$(function() { 
    100      $('#form-comments tr:not(.line)').each(function() { 
    101           dotclear.commentsExpander(this,$('#form-comments tr.line')); 
    102      }); 
    103      $('#form-comments tr.line').each(function() { 
    104           dotclear.commentExpander(this); 
     56     $.expandContent({ 
     57          line:$('#form-comments tr:not(.line)'), 
     58          lines:$('#form-comments tr.line'), 
     59          callback:dotclear.viewCommentContent 
    10560     }); 
    10661     $('.checkboxes-helpers').each(function() { 
  • admin/js/_post.js

    r2527 r2531  
    1 dotclear.commentExpander = function(line) { 
    2      $('<a href="#"><img src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/></a>') 
    3           .click(function(e) { 
    4                dotclear.toggleArrow(this); 
    5                dotclear.viewCommentContent(line); 
    6                e.preventDefault(); 
    7           }) 
    8           .prependTo($(line).children().get(0)); // first td 
    9 }; 
    10  
    11 dotclear.toggleArrow = function(link,action) { 
    12      action = action || ''; 
    13      var img = $(link).children().get(0); 
    14      if (action=='') { 
    15           if (img.alt==dotclear.img_plus_alt) { 
    16                action = 'open'; 
    17           } else { 
    18                action = 'close'; 
    19           } 
    20      } 
    21  
    22      if (action=='open') { 
    23           img.src = dotclear.img_minus_src; 
    24           img.alt = dotclear.img_minus_alt; 
    25      } else { 
    26           img.src = dotclear.img_plus_src; 
    27           img.alt = dotclear.img_plus_alt; 
    28      } 
    29  
    30      return action; 
    31 } 
    32  
    331dotclear.viewCommentContent = function(line,action) { 
    342     var commentId = $(line).attr('id').substr(1); 
     
    140108                
    141109               excerpt_content = $('#post_excerpt').css('display') != 'none' ? $('#post_excerpt').val() : $('#excerpt-area iframe').contents().find('body').html(); 
    142                post_content    = $('#post_content').css('display') != 'none' ? $('#post_content').val() : $('#content-area iframe').contents().find('body').html(); 
     110               post_content   = $('#post_content').css('display') != 'none' ? $('#post_content').val() : $('#content-area iframe').contents().find('body').html(); 
    143111                
    144112               var params = { 
     
    276244 
    277245     $('#comments').onetabload(function() { 
    278           $('#form-comments .comments-list tr.line').each(function() { 
    279                dotclear.commentExpander(this); 
     246          $.expandContent({ 
     247               lines:$('#form-comments .comments-list tr.line'), 
     248               callback:dotclear.viewCommentContent 
    280249          }); 
    281250          $('#form-comments .checkboxes-helpers').each(function() { 
     
    287256 
    288257     $('#trackbacks').onetabload(function() { 
    289           $('#form-trackbacks .comments-list tr.line').each(function() { 
    290                dotclear.commentExpander(this); 
     258          $.expandContent({ 
     259               lines:$('#form-trackbacks .comments-list tr.line'), 
     260               callback:dotclear.viewCommentContent 
    291261          }); 
    292262          $('#form-trackbacks .checkboxes-helpers').each(function() { 
  • admin/js/_posts_list.js

    r2527 r2531  
    1 dotclear.postExpander = function(line) { 
    2      $('<a href="#"><img src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/></a>') 
    3           .click(function(e) { 
    4                dotclear.toggleArrow(this); 
    5                dotclear.viewPostContent(line); 
    6                e.preventDefault(); 
    7           }) 
    8           .prependTo($(line).children().get(0)); // first td 
    9 }; 
    10  
    11 dotclear.postsExpander = function(line,lines) { 
    12      $('<a href="#"><img src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/></a>') 
    13           .click(function(e) { 
    14                dotclear.toggleArrow(this); 
    15                lines.each(function() { 
    16                     var action = dotclear.toggleArrow(this.firstChild.firstChild); 
    17                     dotclear.viewPostContent(this,action); 
    18                }); 
    19                e.preventDefault(); 
    20           }) 
    21           .prependTo($(line).children().get(0)); // first td 
    22 }; 
    23  
    24 dotclear.toggleArrow = function(link,action) { 
    25      action = action || ''; 
    26      var img = $(link).children().get(0); 
    27      if (action=='') { 
    28           if (img.alt==dotclear.img_plus_alt) { 
    29                action = 'open'; 
    30           } else { 
    31                action = 'close'; 
    32           } 
    33      } 
    34  
    35      if (action=='open') { 
    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      return action; 
    44 } 
    45  
    46  
    471dotclear.viewPostContent = function(line,action) { 
    482     var action = action || 'toggle'; 
     
    9246          $(line).removeClass('expand'); 
    9347     } 
    94       
    95      parentTable = $(line).parents('table'); 
    96      if( parentTable.find('tr.expand').length == parentTable.find('tr.line').length ) { 
    97           img = parentTable.find('tr:not(.line) th:first img'); 
    98      } 
    99       
    100      if( parentTable.find('tr.expand').length == 0 ) { 
    101           img = parentTable.find('tr:not(.line) th:first img'); 
    102      }     
    10348}; 
    10449 
     
    10954     }); 
    11055 
    111      $('#form-entries tr:not(.line)').each(function() { 
    112           dotclear.postsExpander(this,$('#form-entries tr.line')); 
    113      }); 
    114      $('#form-entries tr.line').each(function() { 
    115           dotclear.postExpander(this); 
     56     $.expandContent({ 
     57          line:$('#form-entries tr:not(.line)'), 
     58          lines:$('#form-entries tr.line'), 
     59          callback:dotclear.viewPostContent 
    11660     }); 
    11761     $('.checkboxes-helpers').each(function() { 
  • admin/js/common.js

    r2486 r2531  
    150150     }); 
    151151}; 
     152 
     153(function($) { 
     154     'use strict'; 
     155 
     156     $.expandContent = function(opts) { 
     157          var defaults = {}; 
     158          $.expandContent.options = $.extend({},defaults,opts); 
     159 
     160          if (opts==undefined || opts.callback==undefined || !$.isFunction(opts.callback)) { 
     161               return; 
     162          } 
     163          if (opts.line!=undefined) { 
     164               multipleExpander(opts.line,opts.lines); 
     165          } 
     166          opts.lines.each(function() { 
     167               singleExpander(this); 
     168          }); 
     169     } 
     170      
     171     var singleExpander = function singleExpander(line) { 
     172          $('<input type="image" src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/>') 
     173               .click(function(e) { 
     174                    toggleArrow(this); 
     175                    $.expandContent.options.callback.call(this,line); 
     176                    e.preventDefault(); 
     177               }) 
     178               .prependTo($(line).children().get(0)); // first td 
     179     }; 
     180      
     181     var multipleExpander = function multipleExpander(line,lines) { 
     182          $('<input type="image" src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/>') 
     183               .click(function(e) { 
     184                    var that = this; 
     185                    var action = toggleArrow(this); 
     186                    lines.each(function() { 
     187                         toggleArrow(this.firstChild.firstChild,action); 
     188                         $.expandContent.options.callback.call(that,this,action); 
     189 
     190                    }); 
     191                    e.preventDefault(); 
     192               }) 
     193               .prependTo($(line).children().get(0)); // first td 
     194     }; 
     195 
     196     var toggleArrow = function toggleArrow(button,action) { 
     197          action = action || ''; 
     198          if (action=='') { 
     199               if (button.alt==dotclear.img_plus_alt) { 
     200                    action = 'open'; 
     201               } else { 
     202                    action = 'close'; 
     203               } 
     204          } 
     205           
     206          if (action=='open') { 
     207               button.src = dotclear.img_minus_src; 
     208               button.alt = dotclear.img_minus_alt; 
     209          } else { 
     210               button.src = dotclear.img_plus_src; 
     211               button.alt = dotclear.img_plus_alt; 
     212          } 
     213           
     214          return action; 
     215     } 
     216})(jQuery); 
    152217 
    153218jQuery.fn.helpViewer = function() { 
  • admin/style/default.css

    r2530 r2531  
    12921292     padding-right: 1.5em; 
    12931293     } 
    1294 th.first img { 
     1294th.first input { 
    12951295     padding-right: 34px; 
    12961296     } 
  • plugins/pages/list.js

    r2527 r2531  
    1 dotclear.postExpander = function(line) { 
    2      $('<a href="#"><img src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/></a>') 
    3           .click(function(e) { 
    4                dotclear.toggleArrow(this); 
    5                dotclear.viewPostContent(line); 
    6                e.preventDefault(); 
    7           }) 
    8           .prependTo($(line).children().get(0)); // first td 
    9 }; 
    10  
    11 dotclear.postsExpander = function(line,lines) { 
    12      $('<a href="#"><img src="'+dotclear.img_plus_src+'" alt="'+dotclear.img_plus_alt+'"/></a>') 
    13           .click(function(e) { 
    14                dotclear.toggleArrow(this); 
    15                lines.each(function() { 
    16                     var action = dotclear.toggleArrow(this.firstChild.firstChild); 
    17                     dotclear.viewPostContent(this,action); 
    18                }); 
    19                e.preventDefault(); 
    20           }) 
    21           .prependTo($(line).children().get(0)); // first td 
    22 }; 
    23  
    24 dotclear.toggleArrow = function(link,action) { 
    25      action = action || ''; 
    26      var img = $(link).children().get(0); 
    27      if (action=='') { 
    28           if (img.alt==dotclear.img_plus_alt) { 
    29                action = 'open'; 
    30           } else { 
    31                action = 'close'; 
    32           } 
    33      } 
    34  
    35      if (action=='open') { 
    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      return action; 
    44 } 
    45  
    461dotclear.viewPostContent = function(line,action) { 
    472     var action = action || 'toggle'; 
     
    9146          $(line).removeClass('expand'); 
    9247     } 
    93       
    94      parentTable = $(line).parents('table'); 
    95      if( parentTable.find('tr.expand').length == parentTable.find('tr.line').length ) { 
    96           img = parentTable.find('tr:not(.line) th:first img'); 
    97      } 
    98       
    99      if( parentTable.find('tr.expand').length == 0 ) { 
    100           img = parentTable.find('tr:not(.line) th:first img'); 
    101      } 
    102       
    10348}; 
    10449 
    10550$(function() { 
    106  
    10751     $('#pageslist tr.line').prepend('<td class="expander"></td>'); 
    10852     $('#form-entries tr:not(.line) th:first').attr('colspan',4); 
    109      $('#form-entries tr:not(.line)').each(function() { 
    110           dotclear.postsExpander(this,$('#form-entries tr.line')); 
    111      }); 
    112      $('#pageslist tr.line').each(function() { 
    113           dotclear.postExpander(this); 
     53     $.expandContent({ 
     54          line:$('#form-entries tr:not(.line)'), 
     55          lines:$('#form-entries tr.line'), 
     56          callback:dotclear.viewPostContent 
    11457     }); 
    11558     $('.checkboxes-helpers').each(function() { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map