{"action":"created","comment":{"url":"https://api.github.com/repos/opendatateam/udata/pulls/comments/67199004","id":67199004,"diff_hunk":"@@ -1,108 +1,172 @@\n-Array.range = function(n) {\n-    // Array.range(5) --> [0,1,2,3,4]\n-    return Array.apply(null, Array(n)).map((x, i) => i);\n-};\n+/* This file is using http://standardjs.com/ */\n+// `fetch` polyfill added by webpack.\n+/* global fetch */\n \n-Object.defineProperty(Array.prototype, 'chunk', {\n-    // Chunking an Array given the numeric parameter.\n-    value: function(n) {\n-        return Array.range(Math.ceil(this.length / n)).map((x, i) => this.slice( i * n, i * n + n));\n-    }\n-});\n+// Constants in use within the HTML.\n+const TERRITORY = 'data-udata-territory'\n+const TERRITORY_ID = 'data-udata-territory-id'\n+const DATASET_ID = 'data-udata-dataset-id'\n \n-function checkStatus(response) {\n-    // `fetch` doesn't provide an error handling based on status code.\n-    if (response.status >= 200 && response.status < 300) {\n-        return response;\n-    } else {\n-        const error = new Error(response.statusText);\n-        error.response = response;\n-        throw error;\n-    }\n+// Helpers\n+const qS = document.querySelector.bind(document)\n+const qSA = document.querySelectorAll.bind(document)\n+\n+// Extract the base URL from the URL of that script.\n+const parser = document.createElement('a')\n+const scriptURI = qS('script#udata').src\n+parser.href = scriptURI\n+const baseURL = `${parser.protocol}//${parser.host}`\n+\n+function chunk (array, n) {\n+  // Return the `array` chunked by `n`, useful to retrieve all datasets\n+  // with a minimum of requests.\n+  // TODO: more clever chunk to retrieve n, then n * 2, then n * 4, etc?\n+  // in order to display first datasets quickly then load on a minimum\n+  // of requests.\n+  return Array\n+    .apply(null, Array(Math.ceil(array.length / n))).map((x, i) => i) // range\n+    .map((x, i) => array.slice(i * n, i * n + n))\n+}\n+\n+function checkStatus (response) {\n+  // `fetch` doesn't provide an error handling based on status code.\n+  if (response.status >= 200 && response.status < 300) {\n+    return response\n+  } else {\n+    const error = new Error(response.statusText)\n+    error.response = response\n+    throw error\n+  }\n }\n-function zip(arrays) {\n-    // Equivalent to `zip()` in Python.\n-    return arrays[0].map((_, i) => {\n-        return arrays.map((array) => array[i]);\n-    });\n+\n+function zip (arrays) {\n+  // Equivalent to `zip()` in Python.\n+  return arrays[0].map((_, i) => arrays.map((array) => array[i]))\n }\n-function buildIntegrationFragment(reference) {\n-    const [kind, ...ids] = reference.split('-');\n-    const id = ids.join('-');\n-    const fragment = document.createElement('div');\n-    fragment.classList.add('embed');\n-    const help = document.createElement('p');\n-    help.classList.add('udata-help');\n-    help.innerHTML = `<a href=\"#\">Copy-paste</a> that code into your\n-    own HTML and/or <a href=\"${baseURL}/faq/developer/\">read the documentation</a>.`;\n-    fragment.appendChild(help);\n-    const textarea = document.createElement('textarea');\n-    textarea.innerHTML = `<div data-udata-${kind}-id=\"${id}\"></div>\n-<script src=\"${scriptURI}\" id=\"udata\" async defer></script>`;\n-    fragment.appendChild(textarea);\n-    return fragment;\n+\n+function buildIntegrationFragment (reference) {\n+  // Return the fragment to embed the current dataset in another page.\n+  const [kind, ...ids] = reference.split('-')\n+  const id = ids.join('-')\n+  const fragment = document.createElement('div')\n+  fragment.classList.add('embed')\n+  const help = document.createElement('p')\n+  help.classList.add('udata-help')\n+  help.innerHTML = `<a href=\"#\">Copy-paste</a> that code into your\n+    own HTML and/or <a href=\"${baseURL}/faq/developer/\">read the documentation</a>.`\n+  fragment.appendChild(help)\n+  const textarea = document.createElement('textarea')\n+  textarea.innerHTML = `<div data-udata-${kind}-id=\"${id}\"></div>\n+<script src=\"${scriptURI}\" id=\"udata\" async defer></script>`\n+  fragment.appendChild(textarea)\n+  return fragment\n }\n-function easeCopyPasting(content) {\n-    const textarea = content.querySelector('textarea');\n-    textarea.focus();\n-    textarea.select();\n-    const help = content.querySelector('.udata-help');\n-    help.firstChild.addEventListener('click', (e) => {\n-        e.preventDefault();\n-        textarea.select();\n-        document.execCommand('copy');\n-    });\n+\n+function easeCopyPasting (content) {\n+  // Handle the \"save on clipboard\" capability.\n+  const textarea = content.querySelector('textarea')\n+  textarea.focus()\n+  textarea.select()\n+  const help = content.querySelector('.udata-help')\n+  help.firstChild.addEventListener('click', (e) => {\n+    e.preventDefault()\n+    textarea.select()\n+    document.execCommand('copy')\n+  })\n }\n-function handleIntegration(event) {\n-    event.preventDefault();\n-    const element = event.target;\n-    const paragraph = element.parentNode;\n-    const aside = paragraph.parentNode;\n-    const content = aside.previousElementSibling;\n-    const article = aside.parentNode;\n-    const label = element.dataset.label;\n-    element.dataset.label = element.innerHTML;\n-    element.innerHTML = label;\n-    paragraph.classList.toggle('udata-close');\n-    paragraph.classList.toggle('udata-retweet');\n-    content.classList.toggle('shrink');\n-    if (!paragraph.classList.contains('udata-close')) {\n-        content.removeChild(content.querySelector('.embed'));\n-    } else {\n-        content.appendChild(buildIntegrationFragment(article.id));\n-        easeCopyPasting(content);\n-    }\n+\n+function handleIntegration (event) {\n+  // Display/hide the integration box for embeds.\n+  event.preventDefault()\n+  const element = event.target\n+  const paragraph = element.parentNode\n+  const aside = paragraph.parentNode\n+  const content = aside.previousElementSibling\n+  const article = aside.parentNode\n+  const label = element.dataset.label\n+  element.dataset.label = element.innerHTML\n+  element.innerHTML = label\n+  paragraph.classList.toggle('udata-close')\n+  paragraph.classList.toggle('udata-retweet')\n+  content.classList.toggle('shrink')\n+  if (!paragraph.classList.contains('udata-close')) {\n+    content.removeChild(content.querySelector('.embed'))\n+  } else {\n+    content.appendChild(buildIntegrationFragment(article.id))\n+    easeCopyPasting(content)\n+  }\n }\n \n-// Warning: using `Array.from` adds 700 lines once converted through Babel.\n-const territories = [].slice.call(document.querySelectorAll('[data-udata-territory-id]'));\n-const datasets = [].slice.call(document.querySelectorAll('[data-udata-dataset-id]'));\n-// Extract the base URL from the URL to that script.\n-const parser = document.createElement('a');\n-const scriptURI = document.querySelector('script#udata').src\n-parser.href = scriptURI;\n-const baseURL = `${parser.protocol}//${parser.host}`;\n-// Keep the chunk > 9 otherwise territories pages will issue more than one query.\n-territories.concat(datasets).chunk(9).forEach((elements) => {\n+const embedDatasets = (territories, datasets) => {","path":"js/widgets.js","position":178,"original_position":178,"commit_id":"4b7aef43f48e491de81dce9a22f4ed0efe597455","original_commit_id":"4b7aef43f48e491de81dce9a22f4ed0efe597455","user":{"login":"noirbizarre","id":15725,"avatar_url":"https://avatars.githubusercontent.com/u/15725?v=3","gravatar_id":"","url":"https://api.github.com/users/noirbizarre","html_url":"https://github.com/noirbizarre","followers_url":"https://api.github.com/users/noirbizarre/followers","following_url":"https://api.github.com/users/noirbizarre/following{/other_user}","gists_url":"https://api.github.com/users/noirbizarre/gists{/gist_id}","starred_url":"https://api.github.com/users/noirbizarre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noirbizarre/subscriptions","organizations_url":"https://api.github.com/users/noirbizarre/orgs","repos_url":"https://api.github.com/users/noirbizarre/repos","events_url":"https://api.github.com/users/noirbizarre/events{/privacy}","received_events_url":"https://api.github.com/users/noirbizarre/received_events","type":"User","site_admin":false},"body":"Why an arrow function here ?","created_at":"2016-06-15T16:42:16Z","updated_at":"2016-06-15T16:42:16Z","html_url":"https://github.com/opendatateam/udata/pull/483#discussion_r67199004","pull_request_url":"https://api.github.com/repos/opendatateam/udata/pulls/483","_links":{"self":{"href":"https://api.github.com/repos/opendatateam/udata/pulls/comments/67199004"},"html":{"href":"https://github.com/opendatateam/udata/pull/483#discussion_r67199004"},"pull_request":{"href":"https://api.github.com/repos/opendatateam/udata/pulls/483"}}},"pull_request":{"url":"https://api.github.com/repos/opendatateam/udata/pulls/483","id":72890261,"html_url":"https://github.com/opendatateam/udata/pull/483","diff_url":"https://github.com/opendatateam/udata/pull/483.diff","patch_url":"https://github.com/opendatateam/udata/pull/483.patch","issue_url":"https://api.github.com/repos/opendatateam/udata/issues/483","number":483,"state":"open","locked":false,"title":"Add counties and regions to territories, fix #466","user":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"body":"Replace https://github.com/opendatateam/udata/pull/467 because my git history wasn't clean.\r\n\r\nOnce merged, the command `territories collect_references_files` must be run on subsequent deployments.\r\n\r\nPlease review https://github.com/etalab/udata-gouvfr/pull/110 too.","created_at":"2016-06-07T14:55:14Z","updated_at":"2016-06-15T16:42:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d1235656399bf6727df45111bc1fd71544757ff","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/opendatateam/udata/pulls/483/commits","review_comments_url":"https://api.github.com/repos/opendatateam/udata/pulls/483/comments","review_comment_url":"https://api.github.com/repos/opendatateam/udata/pulls/comments{/number}","comments_url":"https://api.github.com/repos/opendatateam/udata/issues/483/comments","statuses_url":"https://api.github.com/repos/opendatateam/udata/statuses/4b7aef43f48e491de81dce9a22f4ed0efe597455","head":{"label":"davidbgk:466-2-new-territories","ref":"466-2-new-territories","sha":"4b7aef43f48e491de81dce9a22f4ed0efe597455","user":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"repo":{"id":33595552,"name":"udata","full_name":"davidbgk/udata","owner":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davidbgk/udata","description":"Social data platform","fork":true,"url":"https://api.github.com/repos/davidbgk/udata","forks_url":"https://api.github.com/repos/davidbgk/udata/forks","keys_url":"https://api.github.com/repos/davidbgk/udata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davidbgk/udata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davidbgk/udata/teams","hooks_url":"https://api.github.com/repos/davidbgk/udata/hooks","issue_events_url":"https://api.github.com/repos/davidbgk/udata/issues/events{/number}","events_url":"https://api.github.com/repos/davidbgk/udata/events","assignees_url":"https://api.github.com/repos/davidbgk/udata/assignees{/user}","branches_url":"https://api.github.com/repos/davidbgk/udata/branches{/branch}","tags_url":"https://api.github.com/repos/davidbgk/udata/tags","blobs_url":"https://api.github.com/repos/davidbgk/udata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davidbgk/udata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davidbgk/udata/git/refs{/sha}","trees_url":"https://api.github.com/repos/davidbgk/udata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davidbgk/udata/statuses/{sha}","languages_url":"https://api.github.com/repos/davidbgk/udata/languages","stargazers_url":"https://api.github.com/repos/davidbgk/udata/stargazers","contributors_url":"https://api.github.com/repos/davidbgk/udata/contributors","subscribers_url":"https://api.github.com/repos/davidbgk/udata/subscribers","subscription_url":"https://api.github.com/repos/davidbgk/udata/subscription","commits_url":"https://api.github.com/repos/davidbgk/udata/commits{/sha}","git_commits_url":"https://api.github.com/repos/davidbgk/udata/git/commits{/sha}","comments_url":"https://api.github.com/repos/davidbgk/udata/comments{/number}","issue_comment_url":"https://api.github.com/repos/davidbgk/udata/issues/comments{/number}","contents_url":"https://api.github.com/repos/davidbgk/udata/contents/{+path}","compare_url":"https://api.github.com/repos/davidbgk/udata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davidbgk/udata/merges","archive_url":"https://api.github.com/repos/davidbgk/udata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davidbgk/udata/downloads","issues_url":"https://api.github.com/repos/davidbgk/udata/issues{/number}","pulls_url":"https://api.github.com/repos/davidbgk/udata/pulls{/number}","milestones_url":"https://api.github.com/repos/davidbgk/udata/milestones{/number}","notifications_url":"https://api.github.com/repos/davidbgk/udata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davidbgk/udata/labels{/name}","releases_url":"https://api.github.com/repos/davidbgk/udata/releases{/id}","deployments_url":"https://api.github.com/repos/davidbgk/udata/deployments","created_at":"2015-04-08T08:51:08Z","updated_at":"2016-01-21T22:06:38Z","pushed_at":"2016-06-15T15:06:22Z","git_url":"git://github.com/davidbgk/udata.git","ssh_url":"git@github.com:davidbgk/udata.git","clone_url":"https://github.com/davidbgk/udata.git","svn_url":"https://github.com/davidbgk/udata","homepage":null,"size":6285,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"opendatateam:dev","ref":"dev","sha":"9ddc5604547c5c7157ef2ad2af007b7f1f67dbd8","user":{"login":"opendatateam","id":19330690,"avatar_url":"https://avatars.githubusercontent.com/u/19330690?v=3","gravatar_id":"","url":"https://api.github.com/users/opendatateam","html_url":"https://github.com/opendatateam","followers_url":"https://api.github.com/users/opendatateam/followers","following_url":"https://api.github.com/users/opendatateam/following{/other_user}","gists_url":"https://api.github.com/users/opendatateam/gists{/gist_id}","starred_url":"https://api.github.com/users/opendatateam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opendatateam/subscriptions","organizations_url":"https://api.github.com/users/opendatateam/orgs","repos_url":"https://api.github.com/users/opendatateam/repos","events_url":"https://api.github.com/users/opendatateam/events{/privacy}","received_events_url":"https://api.github.com/users/opendatateam/received_events","type":"Organization","site_admin":false},"repo":{"id":19141754,"name":"udata","full_name":"opendatateam/udata","owner":{"login":"opendatateam","id":19330690,"avatar_url":"https://avatars.githubusercontent.com/u/19330690?v=3","gravatar_id":"","url":"https://api.github.com/users/opendatateam","html_url":"https://github.com/opendatateam","followers_url":"https://api.github.com/users/opendatateam/followers","following_url":"https://api.github.com/users/opendatateam/following{/other_user}","gists_url":"https://api.github.com/users/opendatateam/gists{/gist_id}","starred_url":"https://api.github.com/users/opendatateam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opendatateam/subscriptions","organizations_url":"https://api.github.com/users/opendatateam/orgs","repos_url":"https://api.github.com/users/opendatateam/repos","events_url":"https://api.github.com/users/opendatateam/events{/privacy}","received_events_url":"https://api.github.com/users/opendatateam/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opendatateam/udata","description":"Customizable and skinnable social platform dedicated to (open)data.","fork":false,"url":"https://api.github.com/repos/opendatateam/udata","forks_url":"https://api.github.com/repos/opendatateam/udata/forks","keys_url":"https://api.github.com/repos/opendatateam/udata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opendatateam/udata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opendatateam/udata/teams","hooks_url":"https://api.github.com/repos/opendatateam/udata/hooks","issue_events_url":"https://api.github.com/repos/opendatateam/udata/issues/events{/number}","events_url":"https://api.github.com/repos/opendatateam/udata/events","assignees_url":"https://api.github.com/repos/opendatateam/udata/assignees{/user}","branches_url":"https://api.github.com/repos/opendatateam/udata/branches{/branch}","tags_url":"https://api.github.com/repos/opendatateam/udata/tags","blobs_url":"https://api.github.com/repos/opendatateam/udata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opendatateam/udata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opendatateam/udata/git/refs{/sha}","trees_url":"https://api.github.com/repos/opendatateam/udata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opendatateam/udata/statuses/{sha}","languages_url":"https://api.github.com/repos/opendatateam/udata/languages","stargazers_url":"https://api.github.com/repos/opendatateam/udata/stargazers","contributors_url":"https://api.github.com/repos/opendatateam/udata/contributors","subscribers_url":"https://api.github.com/repos/opendatateam/udata/subscribers","subscription_url":"https://api.github.com/repos/opendatateam/udata/subscription","commits_url":"https://api.github.com/repos/opendatateam/udata/commits{/sha}","git_commits_url":"https://api.github.com/repos/opendatateam/udata/git/commits{/sha}","comments_url":"https://api.github.com/repos/opendatateam/udata/comments{/number}","issue_comment_url":"https://api.github.com/repos/opendatateam/udata/issues/comments{/number}","contents_url":"https://api.github.com/repos/opendatateam/udata/contents/{+path}","compare_url":"https://api.github.com/repos/opendatateam/udata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opendatateam/udata/merges","archive_url":"https://api.github.com/repos/opendatateam/udata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opendatateam/udata/downloads","issues_url":"https://api.github.com/repos/opendatateam/udata/issues{/number}","pulls_url":"https://api.github.com/repos/opendatateam/udata/pulls{/number}","milestones_url":"https://api.github.com/repos/opendatateam/udata/milestones{/number}","notifications_url":"https://api.github.com/repos/opendatateam/udata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opendatateam/udata/labels{/name}","releases_url":"https://api.github.com/repos/opendatateam/udata/releases{/id}","deployments_url":"https://api.github.com/repos/opendatateam/udata/deployments","created_at":"2014-04-25T09:57:34Z","updated_at":"2016-05-26T20:19:51Z","pushed_at":"2016-06-15T15:06:22Z","git_url":"git://github.com/opendatateam/udata.git","ssh_url":"git@github.com:opendatateam/udata.git","clone_url":"https://github.com/opendatateam/udata.git","svn_url":"https://github.com/opendatateam/udata","homepage":"http://udata.readthedocs.org","size":7415,"stargazers_count":38,"watchers_count":38,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":16,"forks":16,"open_issues":16,"watchers":38,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/opendatateam/udata/pulls/483"},"html":{"href":"https://github.com/opendatateam/udata/pull/483"},"issue":{"href":"https://api.github.com/repos/opendatateam/udata/issues/483"},"comments":{"href":"https://api.github.com/repos/opendatateam/udata/issues/483/comments"},"review_comments":{"href":"https://api.github.com/repos/opendatateam/udata/pulls/483/comments"},"review_comment":{"href":"https://api.github.com/repos/opendatateam/udata/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/opendatateam/udata/pulls/483/commits"},"statuses":{"href":"https://api.github.com/repos/opendatateam/udata/statuses/4b7aef43f48e491de81dce9a22f4ed0efe597455"}}}}
{"actor":{"display_login":"noirbizarre"}}