/* js/lib/help.js */
/**
 *
 */
var helper = {};
helper.formatTime = function(time) {
    var t = new Date(time);
    var y = t.getFullYear();
    var m = t.getMonth() + 1;
    m = (m < 10) ? "0" + m : m;
    var d = t.getDate();
    d = (d < 10) ? "0" + d : d;
    var h = t.getHours();
    h = (h < 10) ? "0" + h : h;
    return y + "-" + m + "-" + d + " " + h + ":" + "00:00";
};
helper.nextTime = function(str) {
    tmp = [];
    console.log(str)
    var ts = str.split("-");
    ts.forEach(function(s) {
        tmp.push(parseInt(s));
    });
    var time = new Date(tmp[0], tmp[1] - 1, tmp[2], (tmp[3] - 1), 0, 0);
    return this.formatTime(time.getTime());
};
helper.getTime = function(str) {
    tmp = [];
    var ts = str.split("-");
    ts.forEach(function(s) {
        tmp.push(parseInt(s));
    });
    var time = new Date(tmp[0], tmp[1] - 1, tmp[2], tmp[3], 0, 0);
    return this.formatTime(time.getTime());
};
helper.getTimeStamp = function(str) {
    tmp = [];
    str = str.replace(" ", "-");
    var ts = str.split("-");
    ts.forEach(function(s) {
        tmp.push(parseInt(s));
    });
    var time = new Date(tmp[0], tmp[1] - 1, tmp[2], tmp[3], 0, 0);
    return time.getTime();
}
helper.getFulltimePoint = function(str) {
    var tmp = [];
    str = str.replace(" ", "-");
    str = str.replace(/:/g, "-");
    ts = str.split("-");
    ts.forEach(function(s) {
        tmp.push(parseInt(s));
    });
    var time = new Date(tmp[0], tmp[1] - 1, tmp[2], tmp[3], tmp[4], tmp[5]);
    console.log(tmp, time)
    var h = time.getHours();
    if (h == 0) {
        var time = new Date(time.getTime() - 60 * 60 * 1000);
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        m = (m < 10) ? "0" + m : m;
        var d = time.getDate();
        d = (d < 10) ? "0" + d : d;
        var h = time.getHours();
        return y + "-" + m + "-" + d + " " + h + "点至24点";
    } else {
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        m = (m < 10) ? "0" + m : m;
        var d = time.getDate();
        d = (d < 10) ? "0" + d : d;
        var h = time.getHours();
        //h=(h<10)?"0"+h:h;
        return y + "-" + m + "-" + d + " " + (h - 1) + "点至" + h + "点";
    }
};
helper.getPoint = function(str) {
    tmp = [];
    str = str.replace(" ", "-");
    var ts = str.split("-");
    ts.forEach(function(s) {
        tmp.push(parseInt(s));
    });
    var time = new Date(tmp[0], tmp[1] - 1, tmp[2], tmp[3], 0, 0);
    var h = time.getHours();
    if (h == 0) {
        var time = new Date(time.getTime() - 60 * 60 * 1000);
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        m = (m < 10) ? "0" + m : m;
        var d = time.getDate();
        d = (d < 10) ? "0" + d : d;
        var h = time.getHours();
        return y + "-" + m + "-" + d + " " + h + "点至24点";
    } else {
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        m = (m < 10) ? "0" + m : m;
        var d = time.getDate();
        d = (d < 10) ? "0" + d : d;
        var h = time.getHours();
        //h=(h<10)?"0"+h:h;
        return y + "-" + m + "-" + d + " " + (h - 1) + "点至" + h + "点";
    }
};
/* js/templates/templates.js */
var app = app || {};
  app.navigate = function(route, options) {
     options || (options = {});
     Backbone.history.navigate(route, options);
 	};
app.tpls = {};
$("script.template").each(function() {
    app.tpls[$(this).attr("id")] = _.template($(this).html());
    $(this).remove();
});
/* js/models/models.min.js */
/*! myproject - v0.0.0 - 2016-01-13 */
var RealTimeModel = Backbone.Model.extend({
        defaults: {
            name: "realtime",
            theme: "全部",
            page: 1
        }
    }),
 KeywordModel=Backbone.Model.extend({
		defaults:{
			name:"keyword",
			page:1,
			time:function() {
                var time = "",
                    t = new Date,
                    y = t.getFullYear(),
                    m = t.getMonth() + 1;
                m = 10 > m ? "0" + m : m;
                var d = t.getDate();
                d = 10 > d ? "0" + d : d;
                var h = t.getHours();
                return h = 10 > h ? "0" + h : h, time = y + "-" + m + "-" + d + " " + h + ":00:00"
            }(),
		},
		parse:function(data){
			this.set("list",data);
		},
		 url:"servlet/KeyWord.do"
	});


    ThemeModel = Backbone.Model.extend({
        defaults: {
            name: "theme",
            active: "全部"
        },
        url: "servlet/Theme.do"
    }),
    TopModel = Backbone.Model.extend({
        defaults: {
            name: "top10",
            tpl: "indexTpl",
            now: function() {
                var time = new Date,
                    h = time.getHours();
                if (0 == h) {
                    var time = new Date(time.getTime() - 60 * 60 * 1e3),
                        y = time.getFullYear(),
                        m = time.getMonth() + 1;
                    m = 10 > m ? "0" + m : m;
                    var d = time.getDate();
                    d = 10 > d ? "0" + d : d;
                    var h = time.getHours();
                    return y + "-" + m + "-" + d + " " + h + "点至24点"
                }
                var y = time.getFullYear(),
                    m = time.getMonth() + 1;
                m = 10 > m ? "0" + m : m;
                var d = time.getDate();
                d = 10 > d ? "0" + d : d;
                var h = time.getHours();
                return y + "-" + m + "-" + d + " " + (h - 1) + "点至" + h + "点"
            }(),
            time: function() {
                var time = "",
                    t = new Date,
                    y = t.getFullYear(),
                    m = t.getMonth() + 1;
                m = 10 > m ? "0" + m : m;
                var d = t.getDate();
                d = 10 > d ? "0" + d : d;
                var h = t.getHours();
                return h = 10 > h ? "0" + h : h, time = y + "-" + m + "-" + d + " " + h + ":00:00"
            }()
        },
        initialize: function() {
            this.on("change:time", function(a, b) {
                var t = helper.getFulltimePoint(b);
                this.set("now", t)
            })
        },
        url: "servlet/Index.do"
    });
//# sourceMappingURL=models.min.js.map
/* js/collections/realtime.min.js */
/*! myproject - v0.0.0 - 2016-01-13 */
 RealTimeCollection = Backbone.Collection.extend({
    model: RealTimeModel,
    url: "servlet/Realtime.do"
}),



KeywordView=Backbone.View.extend({
	el:".wrap",
	template:app.tpls.keywordTpl,
	templateLi:app.tpls.realtimeLiTpl,
	initialize:function(){
		this.render();
	},
	render:function(){
		
		$(this.el).html(this.template({
				"keyword":this.model.get("word"),
				"list":this.model.get("list"),
				"time":this.model.get("time")
		}));

		this.iscorller();
	},
	iscorller: function() {
	  	var loading = '<div class="loading"></div>';
        var nomore = '<div class="nomore">没有更多数据</div>';
	  	var self=this;
	  	var myScroll = new IScroll('#wrapper', { mouseWheel: true });
	
	

		myScroll.on('scrollEnd', function() {
			  	var page=self.model.get("page");
                 if (this.y <= this.maxScrollY) {
                 	

                 	if(page && page<10){
                 		if (!$(this.wrapper).find(".loading").length) {
                 			 $(this.wrapper).find(".events").append(loading);
                 			  self.loadMore(myScroll);
                 			}
                 	}else{
                 			 $(this.wrapper).find(".loading").remove();
                             if (!$(this.wrapper).find(".nomore").length) {
                                 $(this.wrapper).find(".events").append(nomore);
                             }
                 	}


                 	/*	console.log($(this.wrapper).html())
                     if (!$(this.wrapper).find(".loading").length) {
                         $(this.wrapper).find(".events").append(loading);
                         console.log(page)
                         if (page > 10) {
                             $(this.wrapper).find(".loading").remove();
                             if (!$(this.wrapper).find(".nomore").length) {
                                 $(this.wrapper).find(".events").append(nomore);
                             }

                             return;
                         }
                        self.loadMore(myScroll);
                     }*/
                 }
             });
        	
    },
    loadMore: function(iscroller) {
    	var self=this;
    	var page= this.model.get("page");
    		this.model.set("page",(page+1))
    		console.log(this.model)
  		var data={
  			"page":this.model.get("page"),
  			"time":this.model.get("time"),
  			"word":this.model.get("word")
  		};
       var  nomore = '<div class="nomore">没有更多数据</div>';
    
        $.ajax({
            url: "servlet/KeyWord.do",
            data: data,
            type: "GET",
            dataType: "json",
            success: function(data) {
              	if(data.length){
            	     var html = self.templateLi({"data":data});
                     $(self.el).find(".events").append(html);
                     $(self.el).find(".loading").remove();
            	}else{
            		  $(self.el).find(".events").append(nomore);
                	  $(self.el).find(".loading").remove();
            	}

            	if(data.length<5){
            		self.model.set("page",null);
            	}
            	iscroller.refresh();
     	
            },
            error: function(e) {}
        })
    }

});

//# sourceMappingURL=realtime.min.js.map
/* js/views/views.min.js */
/*! myproject - v0.0.0 - 2016-01-13 */
RealTimeView = Backbone.View.extend({
    el: ".wrap",
    template: app.tpls.realtimeTpl,
    initialize: function() {
        this.render()
    },
    templateLi: app.tpls.realtimeLiTpl,
    templateWrap: app.tpls.realtimeWrapTpl,
    render: function() {
        var theme = "全部";
        if (app.themeModel) var theme = app.themeModel.get("active");
        this.$el.html(this.template({
            data: this.collection.models,
            theme: theme,
            realtime: app.realTimeModel.get("realtime")
        })), this.swiper(), this.iscorller()
    },
    iscorller: function() {
        this.scorllers = {};
        var self = this,
            h = $(".swiper-slide").height(),
            loading = '<div class="loading"></div>',
            nomore = '<div class="nomore">没有更多数据</div>';
        _.each(this.collection.models, function(m) {
            e = m.toJSON(), self.scorllers[m.cid] = new IScroll(".wrapper" + e.time.replace(" ", "-")), self.scorllers[m.cid].on("scrollEnd", function() {
                if (this.y <= this.maxScrollY && !$(this.wrapper).find(".loading").length) {
                    $(this.wrapper).find(".events").append(loading);
                    var time = $(this.wrapper).attr("data-time"),
                        theme = (m.get(m.cid), m.get("theme")),
                        page = m.get("page") + 1;
                    if (m.set("page", page), page > 10) return $(this.wrapper).find(".loading").remove(), $(this.wrapper).find(".nomore").length || $(this.wrapper).find(".events").append(nomore), !1;
                    time = helper.getTime(time), self.loadMore(theme, time, page, this.wrapper, self.scorllers[m.cid])
                }
            })
        }), $(".wrapper").height(h - 37)
    },
    swiper: function() {
        var cache = [],
            self = this;
        this.mySwiper = new Swiper(".swiper-container", {
            initialSlide: 0,
            prevButton: ".swiper-button-prev",
            nextButton: ".swiper-button-next",
            onSlideChangeEnd: function(swiper) {
                var time = $(".swiper-slide-next").find(".wrapper").attr("data-time"),
                    id = $(".swiper-slide-next").find(".wrapper").attr("data-id");
                if (time && swiper.activeIndex == swiper.slides.length - 2) {
                    var model = self.collection.get(id),
                        theme = model.get("theme"),
                        datas = {
                            theme: theme,
                            time: helper.nextTime(time),
                            loadPage: "1",
                            page: 1
                        };
                    if (id in cache) return !1;
                    cache.push(id), self.loadPage(datas)
                }
            }
        })
    },
    loadPage: function(datas) {
        var self = this;
        $.ajax({
            url: "servlet/Realtime.do",
            type: "GET",
            data: datas,
            dataType: "json",
            success: function(data) {
                self.collection.add(data);
                for (var html = [], i = self.collection.models.length, j = i - data.length; i > j; j++) {
                    var tmp = self.templateWrap({
                        data: self.collection.models[j]
                    });
                    html.push(tmp)
                }
                self.mySwiper.appendSlide(html), self.iscorller()
            },
            error: function(e) {}
        })
    },
    loadMore: function(theme, time, page, target, iscroller) {
        var datas = {
                theme: theme,
                time: time,
                page: page,
                loadPage: "0"
            },
            nomore = '<div class="nomore">没有更多数据</div>';
        $(target).find(".events .nomore").remove();
        var self = (this.collection.get(time), this);
        $.ajax({
            url: "servlet/Realtime.do",
            data: datas,
            type: "GET",
            dataType: "json",
            success: function(data) {
                if (data.length) {
                    var html = self.templateLi({
                        data: data
                    });
                    $(target).find(".events").append(html), $(target).find(".loading").remove(), iscroller.refresh();
                } else $(target).find(".events").append(nomore), $(target).find(".loading").remove();
                iscroller.refresh()
            },
            error: function(e) {}
        })
    }
});
var ThemeView = Backbone.View.extend({
        el: ".wrap",
        template: app.tpls.themeTpl,
        initialize: function() {
            this.render()
        },
        render: function() {
            this.model.get("realtime") ? this.$el.html(this.template({
                themes: this.model.get("themes"),
                active: this.model.get("active"),
                realtime: this.model.get("realtime")
            })) : this.$el.html(this.template({
                themes: this.model.get("themes"),
                active: this.model.get("active")
            }))
        },
        events: {
            "click a": "select"
        },
        select: function(e) {
            var e = $(e.target).text();
            this.model.set("active", e)
        }
    }),
    app = app || {},
    TopView = Backbone.View.extend({
        el: ".wrap",
        template: app.tpls.indexTpl,
        initialize: function() {
            this.render()
        },
        render: function() {
            var time = this.model.get("time"),
                now = this.model.get("now");
            this.$el.html(this.template({
                time: time,
                now: now
            }));
            var h = $(".index").height();
            $(".barChartWrap").height(h - 160);
            var top10 = this.model.get("top10");
            this.showBar(top10,time)
        },
        showBar: function(data,time) {
            require.config({
                paths: {
                    echarts: "js/lib/echart/dist"
                }
            }), require(["echarts", "echarts/chart/bar"], function(ec) {
                var myChart = ec.init(document.getElementById("barChart")),
                    dataOrder = _.sortBy(data, "value"),
                    names = _.pluck(dataOrder, "name"),


                
                  /*  names = _.map(names, function(name) {
                        return name.length < 5 ? name : name.substring(0, 6) + "..."
                    }),*/
                    values = _.pluck(dataOrder, "value"),
                    option = {
                        color: ["#00b1f1"],
                        grid: {
                            x: 100,
                            y: 20,
                            x2: 50,
                            y2: 0,
                            borderWidth: 0
                        },
                        xAxis: [{
                            type: "value",
                            position: "top",
                            axisLine: {
                                lineStyle: {
                                    color: "#00b1f1",
                                    width: 2,
                                    type: "solid"
                                }
                            },
                            axisTick: {
                                show: !0,
                                inside: !0,
                                lineStyle: {
                                    color: "#00b1f1",
                                    width: 2,
                                    type: "solid"
                                }
                            },
                            axisLabel: {
                                show: !0,
                            },
                            splitLine: {
                                show: !1
                            }
                        }],
                        yAxis: [{
                            type: "category",
                            data: names,
                            barCategoryGap: "40",
                          	axisLabel:{
                                clickable:true,
                          		formatter:function(name){
                                	 return name.length < 5 ? name : name.substring(0, 6) + "..."
                                }
                          	},
                            axisLine: {
                                lineStyle: {
                                    color: "#00b1f1",
                                    width: 2,
                                    type: "solid"
                                }
                            },
                            axisTick: {
                                show: !0,
                                inside: !0,
                                lineStyle: {
                                    color: "#00b1f1",
                                    width: 2,
                                    type: "solid"
                                }
                            },
                            splitLine: {
                                show: !1
                            }
                        }],
                        series: [{
                            type: "bar",
                            itemStyle: {
                                normal: {
                                    label: {
                                        show: !0,
                                        position: "right",
                                        textStyle: {
                                            color: "#000"
                                        }
                                    }
                                }
                            },
                            barWidth: 15,
                            data: values
                        }]
                    };
                myChart.setOption(option);
                myChart.on("click", function(e){
                   

                   if(e.name){
                       
                   var v=e.name.replace("...","");

                   }
                   var word;
                   _.each(names,function(name,index){

                      if(name.indexOf(v)>-1){
                        word=names[index];
                      }
                   })
                    app.navigate("keyword/"+word+"/t"+time,{trigger:true});
                  
               	
                 });







           	    });
        }
    });
//# sourceMappingURL=views.min.js.map
/* js/route/route.min.js */
/*! myproject - v0.0.0 - 2016-01-13 */
var app = app || {},
    Route = Backbone.Router.extend({
        routes: {
            "": "index",
            "index(/t:time)": "index",
            "realtime/:theme(/p:page)(/t:time)": "realtime",
            "theme(/t:time)": "theme",
            "keyword/:words(/t:time)":"keyword",
            "*other": "index"
        },
        index: function(t) {
            app.topModel = new TopModel({}), t && app.topModel.set("time", t);
            var datas = {
                time: app.topModel.get("time")
            };

            app.topModel.fetch({
                data: datas,
                success: function(model, res, opt) {
                    app.topView = new TopView({
                        model: model
                    })
                },
                error: function(err) {}
            })
        },
        realtime: function(theme, p, t) {
            $(".wrap").html(app.tpls.loadTpl());
            var nowPage = p || 1,
                time = helper.formatTime((new Date).getTime());
            t && (t = helper.getTimeStamp(t), time = helper.formatTime(t));
            var datas = {
                theme: theme,
                time: time,
                loadPage: "1",
                page: nowPage
            };
            t ? (app.realTimeModel = new RealTimeModel({
                theme: theme,
                realtime: time
            }), app.themeModel = new ThemeModel({
                active: theme,
                realtime: time
            })) : (app.realTimeModel = new RealTimeModel({
                theme: theme
            }), app.themeModel = new ThemeModel({
                active: theme
            })), app.realTimeCollection = new RealTimeCollection, app.realTimeCollection.reset(), app.realTimeCollection.fetch({
                data: datas,
                success: function(collections, res, opt) {
                    app.realTimeView = new RealTimeView({
                        collection: collections
                    })
                }
            })
        },
        theme: function(t) {
            if (!app.themeModel)
                if (t) {
                    t = helper.getTimeStamp(t);
                    var time = helper.formatTime(t);
                    app.themeModel = new ThemeModel({
                        realtime: time
                    })
                } else app.themeModel = new ThemeModel({});
            app.themeModel.fetch({
                success: function(model, res, opt) {
                    app.themeView = new ThemeView({
                        model: model
                    })
                },
                error: function(err) {}
            })
        },
        keyword:function(word,time){
       		app.keywordModel=new KeywordModel({

       		});
       		
       		app.keywordModel.set("word",word);
       		var nowtime=app.keywordModel.get("time");
       		if(time!=undefined){
       		
       			nowtime=time;
       			app.keywordModel.set("time",nowtime);
       		}
       		var page=app.keywordModel.get("page");
       		var data={
       			"time":nowtime,
       			"word":word,
       			"page":page
       		};
       		app.keywordModel.fetch({
       			data:data,
       			success:function(model,res,opt){
       				app.keywordView=new KeywordView({
       					model:model
       				});
       			},
       			error:function(err){
       				console.log(err);
       			}
       		})

        }
    });
//# sourceMappingURL=route.min.js.map
/* js/app.js */
$(function() {
    //300ms延遲
    console.log(window)
    FastClick.attach(document.body);
    var app = app || {};
    app.route = new Route();
    Backbone.history.start();

});