{"action":"created","comment":{"url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/comments/46115009","id":46115009,"diff_hunk":"@@ -3,21 +3,59 @@\n  */\n 'use strict';\n \n-document.getElementsByClassName('filters')[0].classList.add('hidden');\n+var filtersContainer = document.getElementsByClassName('filters')[0];\n+filtersContainer.classList.add('hidden');\n var template = document.querySelector('#picture-template');\n-var fragment = new DocumentFragment();\n var container = document.querySelector('.pictures');\n+var activeFilter = 'filter-all';\n+var pictures = [];\n \n-window.pictures.forEach(function(picture) {\n-  var element = getElementFromTemplate(picture);\n-  fragment.appendChild(element);\n-});\n-container.appendChild(fragment);\n-document.getElementsByClassName('filters')[0].classList.remove('hidden');\n-/**\n- *@param {Object} data\n- *@return {Element}\n- */\n+var filters = document.querySelectorAll('.filters-radio');\n+for (var i = 0; i < filters.length; i++) {\n+  filters[i].onclick = function(evt) {\n+    var clickedElementID = evt.target.id;\n+    setActiveFilter(clickedElementID);\n+  };\n+}\n+\n+getPictures();\n+\n+function renderPictures(picturesToRender) {\n+  container.innerHTML = '';\n+  var fragmentNew = document.createDocumentFragment();\n+  picturesToRender.forEach(function(picture) {\n+    var element = getElementFromTemplate(picture);\n+    fragmentNew.appendChild(element);\n+  });\n+  container.appendChild(fragmentNew);\n+}\n+function setActiveFilter(id, force) {\n+  if (activeFilter === id && !force) {\n+    return;\n+  }\n+  var filteredPictures = pictures.slice(0); // Копирование массива\n+\n+  switch (id) {\n+    case 'filter-new':\n+      filteredPictures = filteredPictures.sort(function(a, b) {\n+        return b.date - a.date;\n+      });\n+      break;\n+\n+    case 'filter-discussed':\n+      filteredPictures = filteredPictures.sort(function(a, b) {","path":"js/pictures.js","position":56,"original_position":56,"commit_id":"b64bbd5ba5473be27f54468242086c09f864ecfe","original_commit_id":"b64bbd5ba5473be27f54468242086c09f864ecfe","user":{"login":"fiskus","id":533229,"avatar_url":"https://avatars.githubusercontent.com/u/533229?v=3","gravatar_id":"","url":"https://api.github.com/users/fiskus","html_url":"https://github.com/fiskus","followers_url":"https://api.github.com/users/fiskus/followers","following_url":"https://api.github.com/users/fiskus/following{/other_user}","gists_url":"https://api.github.com/users/fiskus/gists{/gist_id}","starred_url":"https://api.github.com/users/fiskus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fiskus/subscriptions","organizations_url":"https://api.github.com/users/fiskus/orgs","repos_url":"https://api.github.com/users/fiskus/repos","events_url":"https://api.github.com/users/fiskus/events{/privacy}","received_events_url":"https://api.github.com/users/fiskus/received_events","type":"User","site_admin":false},"body":"Метод sort так не работает. Функция, которая в него передается, должна возвращать -1, 0 или 1, иначе она сортировать не будет.\r\nhttps://learn.javascript.ru/array-methods#%D1%81%D0%BE%D1%80%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B0-%D0%BC%D0%B5%D1%82%D0%BE%D0%B4-sort-fn","created_at":"2015-11-30T07:44:05Z","updated_at":"2015-11-30T07:44:05Z","html_url":"https://github.com/js-htmlacademy/47843-keksogram/pull/8#discussion_r46115009","pull_request_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/comments/46115009"},"html":{"href":"https://github.com/js-htmlacademy/47843-keksogram/pull/8#discussion_r46115009"},"pull_request":{"href":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/8","id":51981991,"html_url":"https://github.com/js-htmlacademy/47843-keksogram/pull/8","diff_url":"https://github.com/js-htmlacademy/47843-keksogram/pull/8.diff","patch_url":"https://github.com/js-htmlacademy/47843-keksogram/pull/8.patch","issue_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/issues/8","number":8,"state":"open","locked":false,"title":"Робкое знакомство с AJAX","user":{"login":"juliatalashova","id":15787967,"avatar_url":"https://avatars.githubusercontent.com/u/15787967?v=3","gravatar_id":"","url":"https://api.github.com/users/juliatalashova","html_url":"https://github.com/juliatalashova","followers_url":"https://api.github.com/users/juliatalashova/followers","following_url":"https://api.github.com/users/juliatalashova/following{/other_user}","gists_url":"https://api.github.com/users/juliatalashova/gists{/gist_id}","starred_url":"https://api.github.com/users/juliatalashova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliatalashova/subscriptions","organizations_url":"https://api.github.com/users/juliatalashova/orgs","repos_url":"https://api.github.com/users/juliatalashova/repos","events_url":"https://api.github.com/users/juliatalashova/events{/privacy}","received_events_url":"https://api.github.com/users/juliatalashova/received_events","type":"User","site_admin":false},"body":"\n\n--\n:boom: https://js-htmlacademy.github.io/47843-keksogram/8/","created_at":"2015-11-27T10:51:11Z","updated_at":"2015-11-30T07:44:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8b6a44ee6720dd559cb9ecfbac312f9ec64f99ec","assignee":{"login":"fiskus","id":533229,"avatar_url":"https://avatars.githubusercontent.com/u/533229?v=3","gravatar_id":"","url":"https://api.github.com/users/fiskus","html_url":"https://github.com/fiskus","followers_url":"https://api.github.com/users/fiskus/followers","following_url":"https://api.github.com/users/fiskus/following{/other_user}","gists_url":"https://api.github.com/users/fiskus/gists{/gist_id}","starred_url":"https://api.github.com/users/fiskus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fiskus/subscriptions","organizations_url":"https://api.github.com/users/fiskus/orgs","repos_url":"https://api.github.com/users/fiskus/repos","events_url":"https://api.github.com/users/fiskus/events{/privacy}","received_events_url":"https://api.github.com/users/fiskus/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/8/commits","review_comments_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/8/comments","review_comment_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/comments{/number}","comments_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/issues/8/comments","statuses_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/statuses/b64bbd5ba5473be27f54468242086c09f864ecfe","head":{"label":"juliatalashova:module5-task1","ref":"module5-task1","sha":"b64bbd5ba5473be27f54468242086c09f864ecfe","user":{"login":"juliatalashova","id":15787967,"avatar_url":"https://avatars.githubusercontent.com/u/15787967?v=3","gravatar_id":"","url":"https://api.github.com/users/juliatalashova","html_url":"https://github.com/juliatalashova","followers_url":"https://api.github.com/users/juliatalashova/followers","following_url":"https://api.github.com/users/juliatalashova/following{/other_user}","gists_url":"https://api.github.com/users/juliatalashova/gists{/gist_id}","starred_url":"https://api.github.com/users/juliatalashova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliatalashova/subscriptions","organizations_url":"https://api.github.com/users/juliatalashova/orgs","repos_url":"https://api.github.com/users/juliatalashova/repos","events_url":"https://api.github.com/users/juliatalashova/events{/privacy}","received_events_url":"https://api.github.com/users/juliatalashova/received_events","type":"User","site_admin":false},"repo":{"id":45932692,"name":"47843-keksogram","full_name":"juliatalashova/47843-keksogram","owner":{"login":"juliatalashova","id":15787967,"avatar_url":"https://avatars.githubusercontent.com/u/15787967?v=3","gravatar_id":"","url":"https://api.github.com/users/juliatalashova","html_url":"https://github.com/juliatalashova","followers_url":"https://api.github.com/users/juliatalashova/followers","following_url":"https://api.github.com/users/juliatalashova/following{/other_user}","gists_url":"https://api.github.com/users/juliatalashova/gists{/gist_id}","starred_url":"https://api.github.com/users/juliatalashova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliatalashova/subscriptions","organizations_url":"https://api.github.com/users/juliatalashova/orgs","repos_url":"https://api.github.com/users/juliatalashova/repos","events_url":"https://api.github.com/users/juliatalashova/events{/privacy}","received_events_url":"https://api.github.com/users/juliatalashova/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/juliatalashova/47843-keksogram","description":"Julia Talashova","fork":true,"url":"https://api.github.com/repos/juliatalashova/47843-keksogram","forks_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/forks","keys_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/keys{/key_id}","collaborators_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/teams","hooks_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/hooks","issue_events_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/issues/events{/number}","events_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/events","assignees_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/assignees{/user}","branches_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/branches{/branch}","tags_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/tags","blobs_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/git/refs{/sha}","trees_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/git/trees{/sha}","statuses_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/statuses/{sha}","languages_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/languages","stargazers_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/stargazers","contributors_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/contributors","subscribers_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/subscribers","subscription_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/subscription","commits_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/commits{/sha}","git_commits_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/git/commits{/sha}","comments_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/comments{/number}","issue_comment_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/issues/comments{/number}","contents_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/contents/{+path}","compare_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/compare/{base}...{head}","merges_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/merges","archive_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/downloads","issues_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/issues{/number}","pulls_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/pulls{/number}","milestones_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/milestones{/number}","notifications_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/labels{/name}","releases_url":"https://api.github.com/repos/juliatalashova/47843-keksogram/releases{/id}","created_at":"2015-11-10T18:43:51Z","updated_at":"2015-11-10T18:43:52Z","pushed_at":"2015-11-27T10:50:16Z","git_url":"git://github.com/juliatalashova/47843-keksogram.git","ssh_url":"git@github.com:juliatalashova/47843-keksogram.git","clone_url":"https://github.com/juliatalashova/47843-keksogram.git","svn_url":"https://github.com/juliatalashova/47843-keksogram","homepage":null,"size":3774,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"js-htmlacademy:master","ref":"master","sha":"4ccd62e7ee6735bfbebbc050323f5adad4da9fdd","user":{"login":"js-htmlacademy","id":14179712,"avatar_url":"https://avatars.githubusercontent.com/u/14179712?v=3","gravatar_id":"","url":"https://api.github.com/users/js-htmlacademy","html_url":"https://github.com/js-htmlacademy","followers_url":"https://api.github.com/users/js-htmlacademy/followers","following_url":"https://api.github.com/users/js-htmlacademy/following{/other_user}","gists_url":"https://api.github.com/users/js-htmlacademy/gists{/gist_id}","starred_url":"https://api.github.com/users/js-htmlacademy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/js-htmlacademy/subscriptions","organizations_url":"https://api.github.com/users/js-htmlacademy/orgs","repos_url":"https://api.github.com/users/js-htmlacademy/repos","events_url":"https://api.github.com/users/js-htmlacademy/events{/privacy}","received_events_url":"https://api.github.com/users/js-htmlacademy/received_events","type":"Organization","site_admin":false},"repo":{"id":45932129,"name":"47843-keksogram","full_name":"js-htmlacademy/47843-keksogram","owner":{"login":"js-htmlacademy","id":14179712,"avatar_url":"https://avatars.githubusercontent.com/u/14179712?v=3","gravatar_id":"","url":"https://api.github.com/users/js-htmlacademy","html_url":"https://github.com/js-htmlacademy","followers_url":"https://api.github.com/users/js-htmlacademy/followers","following_url":"https://api.github.com/users/js-htmlacademy/following{/other_user}","gists_url":"https://api.github.com/users/js-htmlacademy/gists{/gist_id}","starred_url":"https://api.github.com/users/js-htmlacademy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/js-htmlacademy/subscriptions","organizations_url":"https://api.github.com/users/js-htmlacademy/orgs","repos_url":"https://api.github.com/users/js-htmlacademy/repos","events_url":"https://api.github.com/users/js-htmlacademy/events{/privacy}","received_events_url":"https://api.github.com/users/js-htmlacademy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/js-htmlacademy/47843-keksogram","description":"Julia Talashova","fork":false,"url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram","forks_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/forks","keys_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/keys{/key_id}","collaborators_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/teams","hooks_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/hooks","issue_events_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/issues/events{/number}","events_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/events","assignees_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/assignees{/user}","branches_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/branches{/branch}","tags_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/tags","blobs_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/git/refs{/sha}","trees_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/git/trees{/sha}","statuses_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/statuses/{sha}","languages_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/languages","stargazers_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/stargazers","contributors_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/contributors","subscribers_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/subscribers","subscription_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/subscription","commits_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/commits{/sha}","git_commits_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/git/commits{/sha}","comments_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/comments{/number}","issue_comment_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/issues/comments{/number}","contents_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/contents/{+path}","compare_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/compare/{base}...{head}","merges_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/merges","archive_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/downloads","issues_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/issues{/number}","pulls_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls{/number}","milestones_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/milestones{/number}","notifications_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/labels{/name}","releases_url":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/releases{/id}","created_at":"2015-11-10T18:33:22Z","updated_at":"2015-11-13T09:44:05Z","pushed_at":"2015-11-27T10:52:48Z","git_url":"git://github.com/js-htmlacademy/47843-keksogram.git","ssh_url":"git@github.com:js-htmlacademy/47843-keksogram.git","clone_url":"https://github.com/js-htmlacademy/47843-keksogram.git","svn_url":"https://github.com/js-htmlacademy/47843-keksogram","homepage":"https://github.com/juliatalashova/47843-keksogram","size":3781,"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/js-htmlacademy/47843-keksogram/pulls/8"},"html":{"href":"https://github.com/js-htmlacademy/47843-keksogram/pull/8"},"issue":{"href":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/issues/8"},"comments":{"href":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/js-htmlacademy/47843-keksogram/statuses/b64bbd5ba5473be27f54468242086c09f864ecfe"}}}}