/**
 * Created by ttang on 2016/8/22.
 */
app.directive('iphoneRecognize',["$timeout",function(timer){
    return{
        restrict: 'A',
        scope: {},
        link: function(scope, element){
           timer(function(){
               var contentHeight = $(".post-container").height();
               var toBottom = function(){
                   element.css({"position":"absolute","padding":"1px 0","marginBottom":"-50px"});
                   $(".post-wrapper").css({"marginBottom":"0","position":"relative"});
                   $("#all_homework_reply,#all_blog_reply,#all_course_message_reply,#all_message_reply").css("marginBottom","0");
                       window.scrollTo(0,contentHeight)
               };
               if (/ipad|iphone|mac/i.test(navigator.userAgent)){
                   $("#postInput1").bind('focus',function(){
                       setTimeout(function(){
                           toBottom();
                       },200);
                   });
                   $("#postInput1,#replyBlock").bind("click",function(){
                       setTimeout(function(){
                           toBottom();
                       },200);
                   });
                   $("#postInput1").bind('blur',function(){
                       element.css({"position":"fixed","marginBottom":"0"});
                       $(".post-wrapper").css({"marginBottom":"10px","position":""});
                       $("#all_homework_reply,#all_blog_reply,#all_course_message_reply,#all_message_reply").css("marginBottom","52px");
                   });
               }
           })
        }
    }
}]);