---
---
// menus.js
// init menus for filter
// in order to get the postTags
// we use liquid in javascript 

define(function(){

    var labs = [],menus={};

    {% for post in site.posts %}
        {% for tag in post.tags%}
            labs.push("{{tag}}");
        {% endfor %}
    {% endfor %}

    labs.map(function(current,index){
        current = current.toLowerCase();
        if(menus[current]){
            menus[current] += 1;
        }else{
            menus[current] = 1;
        }
    });

    console.log(menus);

    var initMenu = function(){
        var menusWrapper = document.getElementById('menus-tags');
        var codes ="";

        for(var key in menus){
            codes += "<li>"+key+"</li>";
        }
        codes += "<li>others</li>";

        menusWrapper.innerHTML = codes;
    };

    var filter = function(e){
        console.log(e);
        var tag = e.target.innerHTML;
        //firefox not support innerText;
        //var tag = e.target.innerText;
        
        var code = '';
        
        code += '<div class="posts">';
        {% for post in site.posts %}
            {% for tag in post.tags%}
                if(("{{tag}}").toLowerCase() == tag){

                    code += '<article class="post">';

                        code += '<h2><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></h2>';

                        code += '<div class="entry">';
            
                            code += "{{ post.my_excerpt }}";

                        code += '</div>';

                        code += '<a href="{{ site.baseurl }}{{ post.url }}" class="read-more">Read More</a>';

                        code += '<ul class="page-tags">';

                        {% for tag in post.tags%}
                            code += '<li>{{tag}}</li>';
                        {% endfor %}
                        
                    code += '</ul></article>';
                }

            {% endfor %}
        {% endfor %}
        code += '</div>';

        document.getElementById('main').innerHTML = code;
        return false; 
    };

    return{
        filter:filter,
        menus:menus,
        initMenu:initMenu
    }
});

@@ -1064,24 +1064,25 @@
 sts%22%3E';%0A
+%0A
         
 %7B%25 for p
@@ -1077,36 +1077,28 @@
     
-%7B%25 for post in site.posts %25%7D
+if(tag == %22others%22)%7B
 %0A   
@@ -1113,32 +1113,35 @@
  %7B%25 for 
-tag in post.tags
+post in site.posts 
 %25%7D%0A     
@@ -1162,36 +1162,33 @@
 (%22%7B%7B
+post.
 tag
+s
 %7D%7D%22).
-toLowerCase()
+length
  == 
-tag
+0
 )%7B%0A%0A
@@ -1957,35 +1957,1041 @@
  %25%7D%0A        
-%7B%25 endfor %25
+%0A        %7Delse%7B%0A            %7B%25 for post in site.posts %25%7D%0A                %7B%25 for tag in post.tags%25%7D%0A                    if((%22%7B%7Btag%7D%7D%22).toLowerCase() == tag)%7B%0A%0A                        code += '%3Carticle class=%22post%22%3E';%0A%0A                            code += '%3Ch2%3E%3Ca href=%22%7B%7B site.baseurl %7D%7D%7B%7B post.url %7D%7D%22%3E%7B%7B post.title %7D%7D%3C/a%3E%3C/h2%3E';%0A%0A                            code += '%3Cdiv class=%22entry%22%3E';%0A                %0A                                code += %22%7B%7B post.my_excerpt %7D%7D%22;%0A%0A                            code += '%3C/div%3E';%0A%0A                            code += '%3Ca href=%22%7B%7B site.baseurl %7D%7D%7B%7B post.url %7D%7D%22 class=%22read-more%22%3ERead More%3C/a%3E';%0A%0A                            code += '%3Cul class=%22page-tags%22%3E';%0A%0A                            %7B%25 for tag in post.tags%25%7D%0A                                code += '%3Cli%3E%7B%7Btag%7D%7D%3C/li%3E';%0A                            %7B%25 endfor %25%7D%0A                            %0A                        code += '%3C/ul%3E%3C/article%3E';%0A                    %7D%0A%0A                %7B%25 endfor %25%7D%0A            %7B%25 endfor %25%7D%0A        
 %7D%0A        co

debug menu