「MediaWiki:Gadget-tablesort.js」の版間の差分

No.name2 (トーク | 投稿記録)
rowspanで不具合があったので分割するように処置(とりあえず)
No.name2 (トーク | 投稿記録)
tr.unsortable, tr.sorthiddenを追加
24行目: 24行目:
       });
       });


       /* ソートキー */
       /* based on jquery.tablesort.js (MediaWiki) */
       function getElementSortKey(node) {
       function getElementSortKey(node) {
         var $node = $(node),
         var $node = $(node),
44行目: 44行目:
         priority: 80,
         priority: 80,
         format: function(table) {
         format: function(table) {
           var $rows = $('> tbody > tr:not(.remove-me)', table);
           var $rows = $('> tbody > tr:not(.remove-me)', table),
           table.$sortbottoms.each(function() {
              $target = table.$fixedRows;
           if (table.hasInitialized) {
            table.$fixedRows.filter('.sortbottom').prependTo(table.tFoot);
            table.$fixedRows.filter('.sorthidden').remove();
            $target = $target.filter('.sortmiddle');
          }
          $target.each(function() {
             var $before = $rows.eq(this.insertPosition);
             var $before = $rows.eq(this.insertPosition);
             if ($before.length) {
             if ($before.length) {
               $before.before(this);
               $before.before(this);
             } else {
             } else {
               $('> tbody', table).append(this);
               $rows.last().after(this);
             }
             }
           });
           });
56行目: 62行目:
       });
       });


       /* tablesorterに必要なthead要素とtfoot要素を生成する */
       /* tablesorterに必要なテーブル要素を生成する */
       $sortableTables.each(function() {
       $sortableTables.each(function() {
         var $thead = $('<thead></thead>'),
         var $thead = $('<thead></thead>'),
             $tfoot = $('<tfoot></tfoot>'),
             $tfoot = $('<tfoot></tfoot>'),
             rows = this.tBodies[0].rows;
             rows = this.tBodies[0].rows, $tr;
        /* thead要素 */
         while (rows.length) {
         while (rows.length) {
           var $tr = $(rows[0]);
           $tr = $(rows[0]);
           if ($tr.children('td').length) break;
           if ($tr.children('td').length || $tr.hasClass('sorthidden')) break;
           $tr.children().each(function() {
           if ($tr.hasClass('unsortable')) {
            var $cell = $(this),
            $tr.children().data('sorter', false);
                sortType = $cell.data('sortType');
          } else {
            if ($cell.hasClass('unsortable')) {
            $tr.children().each(function() {
              $cell.data('sorter', false);
              var $cell = $(this);
            } else if (sortType === 'number') {
              if ($cell.hasClass('unsortable')) {
              $cell.data('sorter', 'digit');
                $cell.data('sorter', false);
             }
              } else if ($cell.data('sortType') === 'number') {
           });
                $cell.data('sorter', 'digit');
              }
             });
           }
           $thead.append($tr);
           $thead.append($tr);
         }
         }
         $thead.insertBefore(this.tBodies[0]);
         $thead.insertBefore(this.tBodies[0]);
        /* tfoot要素 */
         for (var i = rows.length - 1; 0 < i; i--) {
         for (var i = rows.length - 1; 0 < i; i--) {
           if ($(rows[i]).children('td').length) break;
           if ($(rows[i]).children('td').length) break;
82行目: 94行目:
         $tfoot.appendTo(this);
         $tfoot.appendTo(this);


        /* .sortmiddle, .sortbottom */
         var $rows = $(rows);
         var $rows = $(rows);
         this.$sortbottoms = $rows.filter('.sortmiddle, .sortbottom').each(function(i) {
        /* 固定行をソート用にキャッシュしないよう一旦削除する */
          this.insertPosition = $rows.index(this) - i;
         this.$fixedRows = $rows.filter('.sortbottom, .sorthidden, .sortmiddle')
        }).addClass('remove-me').remove();
          .each(function(i) {
            this.insertPosition = $rows.index(this) - i;
          }).addClass('remove-me').remove();


         /* rowspanを持つセルを分割する(暫定) */
         /* rowspanを持つセルを分割する(暫定) */
99行目: 112行目:
           }
           }
         });
         });
       })
       })
       .tablesorter({
       .tablesorter({