Esempio n. 1
0
        delete:function(option){
            $.ajax({
                url:HOST+"montages.json",
                type:"delete",
                data:option.data,
                success:function(){
                    option.success();
                },
                error:function(){

                }
            })
        }
Esempio n. 2
0
 getTemplate:function(option){
     $.ajax({
         url:HOST + 'themes.json',
         type:"get",
         success:function(data){
             window.temData=data;
             var html="",template='<li data-id={id}><a href="javascript:void(0)"> <img src="{pic}" alt="{name}"/> </a></li>';
             var len=data.length;
             for(var i=0;i<len;i++){
                 html+=template.replace("{pic}",HOST+data[i].thumb_path).replace("{name}",data[i].name)
                     .replace("{id}",data[i].id);
             }
             $(option.element).html(html);
             $('#scrollbar1').tinyscrollbar();
         }
     })
 }
Esempio n. 3
0
        collect:function(option){
            $.ajax({
                url:HOST+"collect.json",
                type:"post",
                data:option.data,
                success:function(data){
                    if(data.result=="ok"){
                       option.success();
                    }else{
                        alert("收藏失败");
                    }
                },
                error:function(){

                }
            })
        },
Esempio n. 4
0
        get:function(options){
        var self=this;
        var option=$.extend({},options);
        switch (option.type){
            case "index": //index
                $.ajax({
                    url:HOST + 'montages.json',
                    type:"get",
                    data:option.param,
                    success:function(result){
                        var data=result.montages,templateData={montages:[]};
                        var page=0,len=(page+option.pageItems)<=data.length?page+option.pageItems:data.length;

                        for(var i=0;i<len;i++){
                            templateData.montages.push(data[i]);
                        }
                        var template = Handlebars.compile($("#montages-template").html());
                        $(option.element).html(template(templateData));

                        page=len;
                        len<data.length?$("#loadmore").removeClass("gray").addClass("ui-btn-green"):$("#loadmore").removeClass("ui-btn-green").addClass("gray").find("span").text("没有更多");
                        option.callback();
                        if(option.callback!==""){
                            setTimeout(function(){
                                option.callback();
                            },2000)
                        }
                        $("#loadmore").on("click",function(){
                            var len=(page+option.pageItems)<=data.length?page+option.pageItems:data.length;
                            for(var i=page;i<len;i++){
                                templateData.montages.push(data[i]);
                            }
                            var template = Handlebars.compile($("#montages-template").html());
                            $(option.element).html(template(templateData));
                            page=len;
                            len<data.length?$(this).removeClass("gray").addClass("ui-btn-green"):$(this).removeClass("ui-btn-green").addClass("gray").find("span").text("没有更多");
                        });
                    }
                });
                break;
            case "show":
                $.ajax({
                    url:HOST + 'montages/'+option.id+'.json',
                    type:"get",
                    data:option.param,
                    success:function(result){
                        var data=result,output="",height=WindowSize.height-160;
                        $("#introduction").text(data.introduction);
                        var htmlTem='<li><div class="img-wrap"><a class="fancybox" rel="gallery1" href="'+HOST+'{pic}" data-width="{width}" data-height="{height}" style="height:{adjustHeight}px;width:{adjustWidth}px;"></a><div class="hover-panel"> <div class="share-btn"></div> <div class="description">{des}</div> <div class="btns"> <a class="sina" href="javascript:;"><span>sina</span></a> <a class="qq" href="javascript:;"><span>qq</span></a> <a class="tt" href="javascript:;"><span>tt</span></a> </div> </div></div></li>';
                        for(var i=0;i<data.photos.length;i++){
                            output+=htmlTem.replace('{pic}',data.photos[i].path).replace("{des}",data.photos[i].title)
                                .replace("{width}",data.photos[i].width).replace("{height}",data.photos[i].height)
                                .replace("{adjustWidth}",height*data.photos[i].width/data.photos[i].height)
                                .replace("{adjustHeight}",height);
                        }
                        $(option.element).after(output);
                        $frame.reload();

                        for(var j=0;j<data.photos.length;j++){
                            var img=new Image();
                            img.src=HOST+data.photos[j].path;
                            img.index=j;
                            img.onload=function(){
                                var item= $(".fancybox").eq(this.index);
                                item.append($(this));
                                item.parent().width($(this).width());
                                $frame.reload();
                                item.removeAttr("style").css({"background":"#fff","display":"inline"});
                            };
                        }
                        $(".img-wrap").each(function(){
                            $(".img-wrap").height(WindowSize.height-160);
                        });
                        $("#montageTitle").text(data.title);
                        $("#commentBack").text(data.discussion_count);
                        $("#favBtn").text(data.collect_count);
                        $("#sAvatar").attr("src",data.user.avatar.indexOf("http") == 0 ? data.user.avatar : HOST + data.user.avatar);
                        $("#username").text(data.user.nick);
                        $("#montageEnding").text(data.ending);
                        if(!!data.collected){
                            $("#favBtn").addClass("faved");
                            option.tip.set("content","已收藏");
                        }else{
                            $("#favBtn").on("click",function(){
                                self.collect({
                                    data:{
                                        montage_id:option.id,
                                        user_id:24,
                                        japan:"nihong"
                                    },
                                    success:function(){
                                        $("#favBtn").addClass("faved").text(++data.collect_count);
                                        option.tip.set("content","已收藏");
                                        $("#favBtn").off("click");
                                    }
                                });
                            });
                        }

                    }
                });
                break;
            case "include":
                $.ajax({
                    url:HOST + 'montages.json',
                    type:"get",
                    data:option.data,
                    success:function(result){
                        var data=result.montages,templateData={montages:[]};
                        for(var i=0;i<option.data.pageNumber;i++){
                            templateData.montages.push(data[i]);
                        }
                        var template = Handlebars.compile($("#montage-template").html());
                        $(option.element).html(template(templateData));
                        var height,oWidth,oHeight;
                        for(var j=0;j<option.data.pageNumber;j++){
                            var img=new Image();
                            img.src=HOST+data[j].image_path,
                            img.index=j;
                            img.onload=function(){
                                var item= $(".ui-pic-item header").eq(this.index);
                                oWidth=this.width;
                                oHeight=this.height;
                                height=oHeight/ oWidth*300<200?200:oHeight/ oWidth*300;
                                item.after($(this));
                                $(this).css({"height":height});
                                $(this).css({"marginTop":-height/2,"top":92});
                            };
                        }
                        adjustFootPos();
                    }
                });
                break;
            case "recommend":
                $.ajax({
                    url:HOST+"montages.json?per_page="+option.itemNumber,
                    type:"get",
                    data:option.data,
                    success:function(result){
                        var data=result.montages,templateData={montages:[]};
                        if(data.length===0){
                            adjustFootPos();
                            $("#ellipsis").remove();
                            return $("#next").remove();
                        }
                        var len=(data.length<option.itemNumber?data.length:option.itemNumber);
                        for(var i=0;i<len;i++)
                        {
                            templateData.montages.push(data[i]);
                        }
                        var template = Handlebars.compile($("#montage-template").html());
                        $(option.element).html(template(templateData));

                        var height,oWidth,oHeight;
                        for(var j=0;j<len;j++){
                            var img=new Image();
                            img.src=HOST+data[j].image_path;
                            img.index=j;
                            img.onload=function(){
                                var item= $(".marry-list-item header").eq(this.index);
                                oWidth=this.width;
                                oHeight=this.height;
                                height=oHeight/ oWidth*314<190?190:oHeight/ oWidth*314;
                                item.after($(this));
                                $(this).css({"height":height});
                                $(this).css({"marginTop":-height/2,"top":90});
                            };
                        }
                        if(len===option.itemNumber){
                            $("#montagePage").val(parseInt(option.data.page)+1);
                        }
                        $("#pages a").removeClass("ui-paging-current");
                        $('<a href="javascript:;" data-page="'+option.data.page+'" class="ui-paging-item ui-paging-current">'+option.data.page+'</a>').insertBefore("#ellipsis");
                        if(len<option.itemNumber){
                            $("#ellipsis").remove();
                            $("#next").remove();
                        }else{
                            $("#next").text(">").removeClass("ui-paging-current");
                        }

                        if($.isFunction(option.callback)){
                            option.callback();
                        }
                        $(".marry-list-item img").on("load",function(){
                            adjustFootPos();
                        });
                    }
                });

                break;
            case "recommendPage":
                $.ajax({
                    url:HOST+"montages.json?per_page="+option.itemNumber,
                    type:"get",
                    data:option.data,
                    success:function(result){
                        var data=result.montages,templateData={montages:[]};
                        var len=(data.length<option.itemNumber?data.length:option.itemNumber);
                        for(var i=0;i<len;i++)
                        {
                            templateData.montages.push(data[i]);
                        }
                        var template = Handlebars.compile($("#montage-template").html());
                        $(option.element).html(template(templateData));

                        $("#pages a").removeClass("ui-paging-current");

                        var height,oWidth,oHeight;
                        for(var j=0;j<data.length;j++){
                            var img=new Image();
                            img.src=HOST+data[j].image_path,
                            img.index=j;
                            img.onload=function(){
                                var item= $(".marry-list-item header").eq(this.index);
                                item.after($(this));
                                oWidth=this.width;
                                oHeight=this.height;
                                height=oHeight/ oWidth*300<200?200:oHeight/ oWidth*300;
                                item.after($(this));
                                $(this).css({"height":height});
                                $(this).css({"marginTop":-height/2,"top":92});
                            };
                        }

                        if(len===option.itemNumber){
                            $("#montagePage").val(parseInt(option.page)+1);
                        }

                        if($.isFunction(option.callback)){
                            option.callback();
                        }
                        adjustFootPos();
                    }
                });
                break;
            case "favRecommend":
                $.ajax({
                    url:HOST + 'montages.json',
                    type:"get",
                    success:function(result){
                        var data=result.montages,templateData={montages:[]};
                        for(var i=0;i<option.pageItems;i++){
                            templateData.montages.push(data[i]);
                        }
                        var template = Handlebars.compile($("#mRecommend").html());
                        $(option.element).html(template(templateData));
                        return false;
                    }
                });
                break;
            default:
                return null;
        }
    },