Changeset 656

Show
Ignore:
Timestamp:
2008-06-29 23:06:21 (2 months ago)
Author:
arthus
Message:

Sorted archives by QS string rank
TODO: speed things up

Location:
plugins/magic_archives/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • plugins/magic_archives/trunk/archives.php

    r653 r656  
    6565            <span class="tags section"><?php echo _t('Tags'); ?></span> 
    6666        </div></li> 
    67     <?php foreach($magic_archives as $post) { ?> 
     67    <?php foreach(MagicArchives::get_magic_archives() as $post) { ?> 
    6868        <li id="post-<?php echo $post->id; ?>" class="<?php echo Post::type_name($post->content_type); ?> <?php echo Post::status_name($post->status); ?>"> 
    6969            <a href="<?php echo $post->permalink; ?>" title="<?php echo sprintf( _t('Read %s'), $post->title ); ?>"> 
  • plugins/magic_archives/trunk/magic_archives.plugin.php

    r653 r656  
    2121    } 
    2222     
    23     public function action_add_template_vars($theme, $handler_vars) { 
    24         $archives = Posts::get(array('nolimit' => true)); 
     23    public function get_magic_archives() { 
     24        $cache = 'magicarchives__posts'; 
    2525         
    26         $theme->magic_archives = $archives; 
     26        if(Cache::has($cache)) { 
     27            $archives = Cache::get($cache); 
     28 
     29        } else { 
     30            $archives = Posts::get(array('nolimit' => true)); 
     31            Cache::set( $cache, $archives, 4000); 
     32     
     33        } 
     34         
     35        return $archives; 
    2736    } 
    2837     
  • plugins/magic_archives/trunk/magicarchives.css

    r652 r656  
    6666} 
    6767ol#archiveItems li span.comments { 
    68     margin-left:5px; 
    69     width:15px; 
     68    width:5%; 
     69    text-align:center; 
    7070} 
    7171ol#archiveItems li span.comments strong { 
     
    8484    display:none; 
    8585} 
     86ol#archiveItems li span.tags { 
     87    width:30%; 
     88} 
    8689ol#archiveItems li.headings { 
    8790    background:#DEDCDE; 
  • plugins/magic_archives/trunk/magicarchives.js

    r653 r656  
    2020         
    2121        magicArchives.search.keyup(function() { 
    22             magicArchives.filter(); 
     22            magicArchives.doSearch(); 
    2323        }); 
     24         
     25        magicArchives.posts.addClass('unfiltered'); 
    2426         
    2527        magicArchives.createFilters(); 
     
    5456        }); 
    5557    }, 
     58    doSearch: function() { 
     59        var scores = []; 
     60 
     61         
     62        magicArchives.posts.filter('.unfiltered').each(function() { 
     63             
     64            $(this).show(); 
     65             
     66            var score = 0; 
     67 
     68            score = $(this).text().toLowerCase().score( magicArchives.search.val() ); 
     69 
     70            if(score == 0) { 
     71                $(this).hide(); 
     72            } 
     73             
     74            scores.push([score, $(this)]); 
     75             
     76        }); 
     77         
     78        magicArchives.posts.remove(); 
     79         
     80        scores = scores.sort(function(a, b) { 
     81            return b[0] - a[0]; 
     82        }); 
     83         
     84        $(scores).each(function() { 
     85            if($(this[1]).is(':visible')) { 
     86                console.log(this); 
     87            } 
     88            $(this[1]).appendTo($('#archiveItems')); 
     89        }); 
     90         
     91    }, 
    5692    filter: function() { 
    5793        var month = $('.active', magicArchives.month); 
     
    6096        var tag = $('.active', magicArchives.tag); 
    6197         
    62         magicArchives.posts.show(); 
     98        magicArchives.posts.show().addClass('unfiltered'); 
    6399         
    64100        var i = 0; 
     
    67103            if(month.hasClass('allofthestuff') == false) { 
    68104                if(month.text() != $('.month', $(this)).text()) { 
    69                     $(this).hide(); 
     105                    $(this).hide().removeClass('unfiltered'); 
    70106                } 
    71107            } 
    72108            if(year.hasClass('allofthestuff') == false) { 
    73109                if(year.text() != $('.year', $(this)).text()) { 
    74                     $(this).hide(); 
     110                    $(this).hide().removeClass('unfiltered'); 
    75111                } 
    76112            } 
    77113            if(type.hasClass('allofthestuff') == false) { 
    78114                if(type.text() != $('.type', $(this)).text()) { 
    79                     $(this).hide(); 
     115                    $(this).hide().removeClass('unfiltered'); 
    80116                } 
    81117            } 
     
    91127                 
    92128                if(hide) { 
    93                     $(this).hide(); 
     129                    $(this).hide().removeClass('visible'); 
    94130                } 
    95131            } 
    96              
    97             var score = 0; 
    98              
    99             $('.tags .tag', $(this)).each(function() { 
    100                 score = score + $(this).text().score(magicArchives.search.val()); 
    101             }); 
    102              
    103             score = score + $('.month', $(this)).text().toLowerCase().score(magicArchives.search.val()); 
    104             score = score + $('.title', $(this)).text().toLowerCase().score(magicArchives.search.val()); 
    105             score = score + $('.year', $(this)).text().toLowerCase().score(magicArchives.search.val()); 
    106                          
    107             if(score == 0) { 
    108                 $(this).hide(); 
    109             } 
     132 
    110133        }); 
    111134         
    112          
     135        magicArchives.doSearch(); 
     136             
    113137    } 
    114138};