Advertisement
Guest User

Limiter la hauteur des citations (script)

a guest
Apr 25th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* globals jQuery */
  2. /**
  3.  * Make tall quotes on topics collapsed.
  4.  *
  5.  * @see <a href="http://ajuda.forumeiros.com">Fórum dos Fóruns</a>
  6.  * @license MIT
  7.  */
  8. var FA = FA || {};
  9.  
  10. FA.Topic = FA.Topic || {};
  11.  
  12. FA.Topic.QuoteCollapse = (function($, settings) {
  13.     'use strict';
  14.  
  15.     var $quotes;
  16.     var version;
  17.  
  18.     /**
  19.      * Initialization function
  20.      */
  21.     function QuoteCollapse() {
  22.         var self = this;
  23.  
  24.         $(function() {
  25.             $.each({
  26.                 'phpbb2': 'table.bodylinewidth',
  27.                 'phpbb3': 'body#phpbb',
  28.                 'punbb': 'div.pun',
  29.                 'invision': 'div#ipbwrapper',
  30.                 'modernbb': 'body#modernbb',
  31.                 'mobile': 'div#mpage-body',
  32.                 'mobile-modern': 'body#mpage-body-modern',
  33.             }, function(key, selector) {
  34.                 if ($(selector).length !== 0) {
  35.                     version = key;
  36.                 }
  37.             });
  38.  
  39.             if (!version) {
  40.                 return;
  41.             }
  42.  
  43.             self.init();
  44.             self.collapse();
  45.         });
  46.     }
  47.  
  48.     QuoteCollapse.prototype.init = function() {
  49.         switch (version) {
  50.             case 'phpbb2':
  51.                 $quotes = $('.postbody dl.codebox > dd');
  52.                 break;
  53.             case 'phpbb3':
  54.                 $quotes = $('.postbody blockquote');
  55.                 break;
  56.             case 'punbb':
  57.                 $quotes = $('.postbody blockquote');
  58.                 break;
  59.             case 'invision':
  60.                 $quotes = $('.postbody blockquote');
  61.                 break;
  62.             case 'modernbb':
  63.                 $quotes = $('.postbody blockquote');
  64.                 break;
  65.             case 'mobile':
  66.                 $quotes = $('.content blockquote .quote_content');
  67.                 break;
  68.             case 'mobile-modern':
  69.                 $quotes = $('.post-content blockquote .quote_content');
  70.                 break;
  71.             default:
  72.                 return;
  73.         }
  74.  
  75.         $quotes
  76.             .addClass('fa-quote')
  77.             .append($('<a>', {
  78.                 href: '#',
  79.                 class: 'fa-quote-expand',
  80.                 text: settings.label,
  81.             }));
  82.  
  83.         $quotes.on('click', '.fa-quote-expand', function(event) {
  84.             event.preventDefault();
  85.  
  86.             $(this)
  87.                 .closest('.fa-quote')
  88.                 .removeClass('fa-quote-collapsed');
  89.         });
  90.     };
  91.  
  92.     QuoteCollapse.prototype.collapse = function() {
  93.         $quotes.each(function() {
  94.             var $self = $(this);
  95.  
  96.             if ($self.height() > settings.height) {
  97.                 $self.addClass('fa-quote-collapsed');
  98.             }
  99.         });
  100.     };
  101.  
  102.     return new QuoteCollapse();
  103. }(jQuery, {
  104.     height: 400,
  105.     label: 'Continuer la lecture',
  106. }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement