Guest User

Untitled

a guest
May 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var thisUser;
  2. var currentPage = -1;
  3. var currentPanel;
  4.  
  5. $(document).ready(function () {
  6.     thisUser = new User(uid);
  7.     change("clossit", "#clossit");
  8. });
  9.  
  10. function User(id) {
  11.     this.id = id;
  12.  
  13.     this.getClossit = function(page, results) {
  14.         this.pagedApiCall(page, results, new Query("q=clossit"), function(json) {
  15.             setStream(renderClothingList(json));
  16.         });
  17.     };
  18.  
  19.     this.getFollowing = function(page, results) {
  20.         this.pagedApiCall(page, results, new Query("q=following"), function(json) {
  21.             setStream(renderFollowing(json));
  22.         });
  23.     };
  24.  
  25.     this.getSuggestions = function(page, results) {
  26.         this.pagedApiCall(page, results, new Query("q=suggestions"), function(json) {
  27.             setStream(renderClothingList(json));
  28.         });
  29.     };
  30.  
  31.     this.getStream = function(page, results) {
  32.         this.pagedApiCall(page, results, new Query("q=stream"), function(json) {
  33.             setStream(renderStream(json));
  34.         });
  35.     };
  36.  
  37.     this.comment = function (e, clothing) {
  38.         if (event.keyCode != 13) return null;
  39.         apiCall(new Query("q=comment").a("user", this.id).a("clothing", clothing).a("message", $(e).val()), function (json) {
  40.             var html = renderComment(json.comment);
  41.             $(".commentWrap." + clothing).append(html);
  42.         });
  43.         $(e).val(null);
  44.         return false;
  45.     };
  46.  
  47.     this.getInfo = function() {
  48.         this.apiCall(new Query("q=basic"), function(json) {
  49.             document.write(JSON.stringify(json));
  50.         });
  51.     };
  52.  
  53.     this.follow = function() {
  54.         $(".follow").animate({ opacity: '0' }, 250, function() {
  55.             apiCall(new Query("q=follow").a("user", this.id), function(json) {
  56.                 if (json.response == json.undefined)
  57.                     $("#login").trigger('click');
  58.                 else if (json.response) $(".follow").attr("src", "/media/follow.png");
  59.                 else $(".follow").attr("src", "/media/unfollow.png");
  60.                 $(".follow").animate({ opacity: '1' }, 500);
  61.             });
  62.         });
  63.     };
  64.  
  65.     this.apiCall = function(params, callback) {
  66.         apiCall(params.a("id", this.id), callback);
  67.     };
  68.  
  69.     this.pagedApiCall = function(page, results, params, callback) {
  70.         this.apiCall(params.a("page", page).a("results", results), callback);
  71.     };
  72. }
  73.  
  74. function setStream(html) {
  75.     $('.stream').append(html).fadeTo(250, 1.0);
  76. }
  77.  
  78. function change(panel, e) {
  79.     panel = panel.toLowerCase();
  80.     switch (panel) {
  81.         case "clossit":
  82.             currentPanel = function() { thisUser.getClossit(currentPage, 60); };
  83.             break;
  84.         case "suggestions":
  85.             currentPanel = function() { thisUser.getSuggestions(currentPage, 60); };
  86.             break;
  87.         case "stream":
  88.             currentPanel = function() { thisUser.getStream(currentPage, 60); };
  89.             break;
  90.         case "following":
  91.             currentPanel = function() { thisUser.getFollowing(currentPage, 60); };
  92.             break;
  93.     }
  94.     $(".links.content span").removeClass("active");
  95.     $(e).addClass("active");
  96.     currentPage = -1;
  97.     $('.stream').fadeTo(250, 0.0, function () {
  98.         $('.stream').html('');
  99.         more();
  100.     });
  101. }
  102.  
  103. function more() {
  104.     currentPage++;
  105.     currentPanel();
  106. }
  107.  
  108. function renderStream(json) {
  109.     var html = "";
  110.     $.each(json, function (key, val) {
  111.         html += renderStreamItem(val.clothing, val.owner, val.added, val.comments);
  112.     });
  113.     return html;
  114. }
  115.  
  116. function renderFollowing(json) {
  117.     var html = "";
  118.     $.each(json, function (key, val) {
  119.         html += renderUser(val);
  120.     });
  121.     return html;
  122. }
  123.  
  124. function renderClothingList(json) {
  125.     var html = "";
  126.     $.each(json, function (key, val) {
  127.         var img = val.wearing ? "/media/remove.png" : "/media/add.png";
  128.         html += renderClothing(val.clothing, img);
  129.     });
  130.     return html;
  131. }
  132.  
  133. function renderClothing(clothing, wearing) {
  134.     var html = "";
  135.     html += "<div class='box'>";
  136.     html += "<a href='" + clothing.page + "'>";
  137.     html += "<img class='productImage' src='" + thumb(clothing.image, 150) + "'>";
  138.     html += "<div class='label'>" + clothing.name + "</div>";
  139.     html += "</a>";
  140.     html += "<div class='like'>";
  141.     html += "<img onclick='wear(" + clothing.id + ",this)' width='38' height='38' src='" + wearing + "'>";
  142.     html += "</div>";
  143.     html += "</div>";
  144.     return html;
  145. }
  146.  
  147. function renderStreamItem(clothing, owner, added, comments) {
  148.     var html = "";
  149.     html += "<div class='post'>";
  150.     html += "   <div class='postContent'>";
  151.     html += "       <a href='" + owner.page + "'>";
  152.     html += "           <img class='postAvatar' src='" + gravatar(owner.avatar, 50) + "'>";
  153.     html += "       </a>";
  154.     html += "        <div class='message'>";
  155.     html += "            <a href='" + owner.page + "'>" + owner.name + "</a><br> added <a href='" + clothing.page + "'>" + clothing.name + "</a>";
  156.     html += "        </div>";
  157.     html += "       <div class='triangle right'></div>";
  158.     html += "   </div>";
  159.     html += "   <a href='" + clothing.page + "'>";
  160.     html += "       <img class='postImage' src='" + thumb(clothing.image, 150) + "'>";
  161.     html += "   </a>";
  162.     html += "   <div class='commentBox'>";
  163.     html += "       <div class='triangle left'></div>";
  164.     html += "       <div class='comments'>";
  165.     html += "           <div class='commentWrap " + clothing.id + "' >";
  166.     $.each(comments, function (key, val) {
  167.         html += renderComment(val);
  168.     });
  169.     html += "           </div>";
  170.     html += "           <textarea onKeyPress='return thisUser.comment(this, " + clothing.id + ", " + owner.id + ")'/>";
  171.     html += "       </div>";
  172.     html += "   </div>";
  173.     html += "</div>";
  174.     return html;
  175. }
  176.  
  177. function renderComment(comment) {
  178.     var html = "";
  179.     html += "<div class='comment'>";
  180.     html += "   <a href='/u/" + comment.commenter + "/" + comment.commenterID + "'>" + comment.commenter + "</a>";
  181.     html += "   <img class='' src='" + gravatar(comment.commenterAvatar, 30) + "'>";
  182.     html += "   <div>" + comment.message + "</div>";
  183.     html += "</div>";
  184.     return html;
  185. }
  186.  
  187. function renderUser(user) {
  188.     var html = "";
  189.     html += "<div class='friendBox'>";
  190.     html += "    <a href='" + user.page + "'>";
  191.     html += "    <img class='friendImage' src='" + gravatar(user.avatar, 178) + "'>";
  192.     html += "        <div class='friendLabel'>" + user.name + "</div>";
  193.     html += "    </a>";
  194.     html += "</div>";
  195.     return html;
  196. }
Add Comment
Please, Sign In to add comment