{"action":"created","comment":{"url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/comments/59018733","id":59018733,"diff_hunk":"@@ -92,9 +114,151 @@\n     image.src = source;\n   }\n \n-  toggleBlock(reviewsFilter, false);\n+  /**\n+   * loadingMark - modify container\n+   *\n+   * @param  {Boolean} event - show/hide loading mark\n+   */\n+  function loadingMark(event) {\n+    reviewsContainer.classList.toggle('reviews-list-loading', event);\n+  }\n \n-  window.reviews.forEach(createReview);\n+  /**\n+   * @callback OnXHRLoad\n+   * @param {*} error - error trigger.\n+   * @param {Review[]} loadedData\n+   */\n+\n+  /**\n+   * callServer - making ajax response;\n+   *\n+   * @param  {ReviewsLoad} callback\n+   */\n+  function callServer(callback) {\n+    var xhr = new XMLHttpRequest();\n+\n+    loadingMark(true);\n+\n+    xhr.addEventListener('load', function(evt) {\n+      var loadedData = JSON.parse(evt.target.response);\n+      callback(null, loadedData);\n+      loadingMark(false);\n+    });\n+\n+    xhr.addEventListener('error', function() {\n+      callback(true, null);\n+    });\n+\n+    xhr.timeout = 10000;\n+    xhr.addEventListener('timeout', function() {\n+      callback(true, null);\n+    });\n+\n+    xhr.open('GET', serverUrl);\n+    xhr.send();\n+  }\n+\n+  /**\n+   * loadedReviews - download process\n+   *\n+   * @param  {*} error - error event mark\n+   * @param  {Review[]} success - loaded reviews\n+   */\n+  function loadedReviews(error, success) {\n+    if (error) {\n+      console.log('error');\n+      reviewsContainer.classList.remove('reviews-list-loading');\n+      reviewsContainer.classList.add('reviews-load-failure');\n+    } else {\n+      reviews = success;\n+      setFiltrationEnabled();\n+      renderReviews(reviews);\n+    }\n+  }\n+\n+  /**\n+   * renderReviews - render reviews in the page\n+   *\n+   * @param  {Review} reviewList - list of reviews\n+   */\n+  function renderReviews(reviewList) {\n+    reviewsList.innerHTML = '';\n+    reviewList.forEach(createReview);\n+  }\n+\n+  /**\n+   * getFilteredReviews - filtering and sorting reviews\n+   *\n+   * @param  {Review} sortReviews - list of reviews\n+   * @param  {String} filter - name of filter\n+   * @return {Review} reviewsToFilter - list of sorted and filtered reviews\n+   */\n+  function getFilteredReviews(sortReviews, filter) {\n+    var reviewsToFilter = sortReviews.slice(0);\n+\n+    switch (filter) {\n+      case 'reviews-recent':\n+        reviewsToFilter.sort(function(curr, next) {\n+          var currDate = new Date(curr.date);\n+          var nextDate = new Date(next.date);\n+          return nextDate - currDate;\n+        });\n+        reviewsToFilter = reviewsToFilter.slice(0, 14);\n+        break;\n+\n+      case 'reviews-good':\n+        reviewsToFilter = reviewsToFilter.filter(function(review) {\n+          return review.rating >= 3;\n+        });\n+        reviewsToFilter.sort(function(curr, next) {\n+          return next.rating - curr.rating;\n+        });\n+        break;\n+\n+      case 'reviews-bad':\n+        reviewsToFilter = reviewsToFilter.filter(function(review) {\n+          return review.rating < 3;\n+        });\n+        reviewsToFilter.sort(function(curr, next) {\n+          return curr.rating - next.rating;\n+        });\n+        break;\n+\n+      case 'reviews-popular':\n+        reviewsToFilter = reviewsToFilter.sort(function(curr, next) {\n+          return next.review_usefulness - curr.rating;","path":"src/reviews.js","position":177,"original_position":177,"commit_id":"8f3a74a8cbcd8151384cfcbe9425c138fcf2a335","original_commit_id":"8f3a74a8cbcd8151384cfcbe9425c138fcf2a335","user":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"body":"В этой строке что-то не так!","created_at":"2016-04-08T12:43:29Z","updated_at":"2016-04-08T12:43:29Z","html_url":"https://github.com/htmlacademy-javascript/42390-code-and-magick/pull/10#discussion_r59018733","pull_request_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/comments/59018733"},"html":{"href":"https://github.com/htmlacademy-javascript/42390-code-and-magick/pull/10#discussion_r59018733"},"pull_request":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/10","id":65746034,"html_url":"https://github.com/htmlacademy-javascript/42390-code-and-magick/pull/10","diff_url":"https://github.com/htmlacademy-javascript/42390-code-and-magick/pull/10.diff","patch_url":"https://github.com/htmlacademy-javascript/42390-code-and-magick/pull/10.patch","issue_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/issues/10","number":10,"state":"open","locked":false,"title":"Робкое знакомство с AJAX","user":{"login":"fyvfyv","id":3251438,"avatar_url":"https://avatars.githubusercontent.com/u/3251438?v=3","gravatar_id":"","url":"https://api.github.com/users/fyvfyv","html_url":"https://github.com/fyvfyv","followers_url":"https://api.github.com/users/fyvfyv/followers","following_url":"https://api.github.com/users/fyvfyv/following{/other_user}","gists_url":"https://api.github.com/users/fyvfyv/gists{/gist_id}","starred_url":"https://api.github.com/users/fyvfyv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fyvfyv/subscriptions","organizations_url":"https://api.github.com/users/fyvfyv/orgs","repos_url":"https://api.github.com/users/fyvfyv/repos","events_url":"https://api.github.com/users/fyvfyv/events{/privacy}","received_events_url":"https://api.github.com/users/fyvfyv/received_events","type":"User","site_admin":false},"body":"\n\n--\n:boom: https://htmlacademy-javascript.github.io/42390-code-and-magick/10/","created_at":"2016-04-08T07:20:52Z","updated_at":"2016-04-08T12:43:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a7a162f89d4b6f8f1f06d47a962fe916ae8e664","assignee":{"login":"isqua","id":529247,"avatar_url":"https://avatars.githubusercontent.com/u/529247?v=3","gravatar_id":"","url":"https://api.github.com/users/isqua","html_url":"https://github.com/isqua","followers_url":"https://api.github.com/users/isqua/followers","following_url":"https://api.github.com/users/isqua/following{/other_user}","gists_url":"https://api.github.com/users/isqua/gists{/gist_id}","starred_url":"https://api.github.com/users/isqua/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/isqua/subscriptions","organizations_url":"https://api.github.com/users/isqua/orgs","repos_url":"https://api.github.com/users/isqua/repos","events_url":"https://api.github.com/users/isqua/events{/privacy}","received_events_url":"https://api.github.com/users/isqua/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/10/commits","review_comments_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/10/comments","review_comment_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/comments{/number}","comments_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/issues/10/comments","statuses_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/statuses/8f3a74a8cbcd8151384cfcbe9425c138fcf2a335","head":{"label":"fyvfyv:module5-task1","ref":"module5-task1","sha":"8f3a74a8cbcd8151384cfcbe9425c138fcf2a335","user":{"login":"fyvfyv","id":3251438,"avatar_url":"https://avatars.githubusercontent.com/u/3251438?v=3","gravatar_id":"","url":"https://api.github.com/users/fyvfyv","html_url":"https://github.com/fyvfyv","followers_url":"https://api.github.com/users/fyvfyv/followers","following_url":"https://api.github.com/users/fyvfyv/following{/other_user}","gists_url":"https://api.github.com/users/fyvfyv/gists{/gist_id}","starred_url":"https://api.github.com/users/fyvfyv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fyvfyv/subscriptions","organizations_url":"https://api.github.com/users/fyvfyv/orgs","repos_url":"https://api.github.com/users/fyvfyv/repos","events_url":"https://api.github.com/users/fyvfyv/events{/privacy}","received_events_url":"https://api.github.com/users/fyvfyv/received_events","type":"User","site_admin":false},"repo":{"id":54500671,"name":"42390-code-and-magick","full_name":"fyvfyv/42390-code-and-magick","owner":{"login":"fyvfyv","id":3251438,"avatar_url":"https://avatars.githubusercontent.com/u/3251438?v=3","gravatar_id":"","url":"https://api.github.com/users/fyvfyv","html_url":"https://github.com/fyvfyv","followers_url":"https://api.github.com/users/fyvfyv/followers","following_url":"https://api.github.com/users/fyvfyv/following{/other_user}","gists_url":"https://api.github.com/users/fyvfyv/gists{/gist_id}","starred_url":"https://api.github.com/users/fyvfyv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fyvfyv/subscriptions","organizations_url":"https://api.github.com/users/fyvfyv/orgs","repos_url":"https://api.github.com/users/fyvfyv/repos","events_url":"https://api.github.com/users/fyvfyv/events{/privacy}","received_events_url":"https://api.github.com/users/fyvfyv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fyvfyv/42390-code-and-magick","description":"Олег Петров","fork":true,"url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick","forks_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/forks","keys_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/teams","hooks_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/hooks","issue_events_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/issues/events{/number}","events_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/events","assignees_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/assignees{/user}","branches_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/branches{/branch}","tags_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/tags","blobs_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/git/refs{/sha}","trees_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/statuses/{sha}","languages_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/languages","stargazers_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/stargazers","contributors_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/contributors","subscribers_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/subscribers","subscription_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/subscription","commits_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/commits{/sha}","git_commits_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/git/commits{/sha}","comments_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/comments{/number}","issue_comment_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/issues/comments{/number}","contents_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/contents/{+path}","compare_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/merges","archive_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/downloads","issues_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/issues{/number}","pulls_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/pulls{/number}","milestones_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/milestones{/number}","notifications_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/labels{/name}","releases_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/releases{/id}","deployments_url":"https://api.github.com/repos/fyvfyv/42390-code-and-magick/deployments","created_at":"2016-03-22T18:52:07Z","updated_at":"2016-03-22T18:52:08Z","pushed_at":"2016-04-08T09:43:53Z","git_url":"git://github.com/fyvfyv/42390-code-and-magick.git","ssh_url":"git@github.com:fyvfyv/42390-code-and-magick.git","clone_url":"https://github.com/fyvfyv/42390-code-and-magick.git","svn_url":"https://github.com/fyvfyv/42390-code-and-magick","homepage":null,"size":1076,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"htmlacademy-javascript:master","ref":"master","sha":"284079974aaca520b4a0d43a18d0d6ae828431ae","user":{"login":"htmlacademy-javascript","id":14179712,"avatar_url":"https://avatars.githubusercontent.com/u/14179712?v=3","gravatar_id":"","url":"https://api.github.com/users/htmlacademy-javascript","html_url":"https://github.com/htmlacademy-javascript","followers_url":"https://api.github.com/users/htmlacademy-javascript/followers","following_url":"https://api.github.com/users/htmlacademy-javascript/following{/other_user}","gists_url":"https://api.github.com/users/htmlacademy-javascript/gists{/gist_id}","starred_url":"https://api.github.com/users/htmlacademy-javascript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/htmlacademy-javascript/subscriptions","organizations_url":"https://api.github.com/users/htmlacademy-javascript/orgs","repos_url":"https://api.github.com/users/htmlacademy-javascript/repos","events_url":"https://api.github.com/users/htmlacademy-javascript/events{/privacy}","received_events_url":"https://api.github.com/users/htmlacademy-javascript/received_events","type":"Organization","site_admin":false},"repo":{"id":54500257,"name":"42390-code-and-magick","full_name":"htmlacademy-javascript/42390-code-and-magick","owner":{"login":"htmlacademy-javascript","id":14179712,"avatar_url":"https://avatars.githubusercontent.com/u/14179712?v=3","gravatar_id":"","url":"https://api.github.com/users/htmlacademy-javascript","html_url":"https://github.com/htmlacademy-javascript","followers_url":"https://api.github.com/users/htmlacademy-javascript/followers","following_url":"https://api.github.com/users/htmlacademy-javascript/following{/other_user}","gists_url":"https://api.github.com/users/htmlacademy-javascript/gists{/gist_id}","starred_url":"https://api.github.com/users/htmlacademy-javascript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/htmlacademy-javascript/subscriptions","organizations_url":"https://api.github.com/users/htmlacademy-javascript/orgs","repos_url":"https://api.github.com/users/htmlacademy-javascript/repos","events_url":"https://api.github.com/users/htmlacademy-javascript/events{/privacy}","received_events_url":"https://api.github.com/users/htmlacademy-javascript/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/htmlacademy-javascript/42390-code-and-magick","description":"Олег Петров","fork":false,"url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick","forks_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/forks","keys_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/keys{/key_id}","collaborators_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/teams","hooks_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/hooks","issue_events_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/issues/events{/number}","events_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/events","assignees_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/assignees{/user}","branches_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/branches{/branch}","tags_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/tags","blobs_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/git/refs{/sha}","trees_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/git/trees{/sha}","statuses_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/statuses/{sha}","languages_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/languages","stargazers_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/stargazers","contributors_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/contributors","subscribers_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/subscribers","subscription_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/subscription","commits_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/commits{/sha}","git_commits_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/git/commits{/sha}","comments_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/comments{/number}","issue_comment_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/issues/comments{/number}","contents_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/contents/{+path}","compare_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/compare/{base}...{head}","merges_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/merges","archive_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/downloads","issues_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/issues{/number}","pulls_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls{/number}","milestones_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/milestones{/number}","notifications_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/labels{/name}","releases_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/releases{/id}","deployments_url":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/deployments","created_at":"2016-03-22T18:45:29Z","updated_at":"2016-03-22T19:01:06Z","pushed_at":"2016-04-08T09:43:54Z","git_url":"git://github.com/htmlacademy-javascript/42390-code-and-magick.git","ssh_url":"git@github.com:htmlacademy-javascript/42390-code-and-magick.git","clone_url":"https://github.com/htmlacademy-javascript/42390-code-and-magick.git","svn_url":"https://github.com/htmlacademy-javascript/42390-code-and-magick","homepage":"https://github.com/fyvfyv/42390-code-and-magick","size":1131,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/10"},"html":{"href":"https://github.com/htmlacademy-javascript/42390-code-and-magick/pull/10"},"issue":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/issues/10"},"comments":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/htmlacademy-javascript/42390-code-and-magick/statuses/8f3a74a8cbcd8151384cfcbe9425c138fcf2a335"}}}}