GitHub PullRequestReviewCommentEvent at 2014-05-25 04:29:06
Repository: gaia
Actor: jimporter
Payload: {"comment":{"url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/13029211","id":13029211,"diff_hunk":"@@ -0,0 +1,150 @@\n+/* exported ToneList */\n+/* global domify, Template, Promise */\n+'use strict';\n+\n+var ToneList = (function() {\n+\n+  var listTemplate = new Template('sound-list-template');\n+  var itemTemplate = new Template('sound-item-template');\n+\n+  function toneCompare(a, b) {\n+    var aName = a.name.toLocaleLowerCase();\n+    var bName = b.name.toLocaleLowerCase();\n+    var cmp = aName.localeCompare(bName);\n+    if (cmp) {\n+      return cmp;\n+    }\n+\n+    var aSubtitle = (a.subtitle || '').toLocaleLowerCase();\n+    var bSubtitle = (b.subtitle || '').toLocaleLowerCase();\n+    return aSubtitle.localeCompare(bSubtitle);\n+  }\n+\n+\n+  /**\n+   * Create a new list of tones.\n+   *\n+   * @param {String} l10nID The l10n ID of the list's header\n+   */\n+  function ToneList(l10nID) {\n+    this.element = domify(listTemplate.interpolate({l10nID: l10nID}));\n+    navigator.mozL10n.once(function() {\n+      navigator.mozL10n.translate(this.element);\n+    }.bind(this));\n+\n+    this._ul = this.element.querySelector('ul');\n+  }\n+\n+  ToneList.prototype = {\n+    /**\n+     * Create and return a list item for a tone.\n+     *\n+     * @param {Object} tone The tone to use for the list item.\n+     * @return {Node} The list item.\n+     */\n+    makeItem: function(tone) {\n+      var templateArgs = {};\n+      if (tone.l10nID) {\n+        templateArgs.l10nID = tone.l10nID;\n+      } else {\n+        templateArgs.name = tone.name;\n+      }\n+\n+      var item = domify(itemTemplate.interpolate(templateArgs));\n+      if (templateArgs.l10nID) {\n+        navigator.mozL10n.once(function() {\n+          navigator.mozL10n.translate(item);\n+        });\n+      }\n+\n+      if (tone.subtitle) {\n+        var subtitle = document.createElement('p');\n+        subtitle.classList.add('subtitle');\n+        subtitle.textContent = tone.subtitle;\n+        item.querySelector('.name').parentNode.appendChild(subtitle);\n+      }\n+\n+      return item;\n+    },\n+\n+    /**\n+     * Append a tone or array of tones to the list. If an array, the elements\n+     * will first be sorted by their name. Array calls may be async; passing a\n+     * single tone is guaranteed to be synchronous.\n+     *\n+     * @param {Object} tones A single tone object or an array thereof.\n+     * @return {Promise} A promise for when the operation completes.\n+     */\n+    append: function(tones) {\n+      var toneList = this;\n+      return new Promise(function(resolve, reject) {\n+        if (!Array.isArray(tones)) {\n+          toneList.element.hidden = false;\n+          toneList._ul.appendChild(toneList.makeItem(tones));\n+          resolve();\n+          return;\n+        }\n+\n+        navigator.mozL10n.once(function() {\n+          tones.sort(toneCompare);\n+          tones.forEach(function(tone) {\n+            toneList._ul.appendChild(toneList.makeItem(tone));\n+          });\n+          if (tones.length) {\n+            toneList.element.hidden = false;\n+          }\n+          resolve();\n+        });\n+      });\n+    },\n+\n+    /**\n+     * Insert a tone or array of tones in sorted order into the list.\n+     *\n+     * @param {Object} tones A single tone object or an array thereof.\n+     * @return {Promise} A promise for when the operation completes.","path":"apps/ringtones/js/tone_list.js","position":null,"original_position":105,"commit_id":"3efb3a3f1932ce05718f098cefc651ac77bed1f7","original_commit_id":"0c110a1ad9b7fd581afa44107183a071ccc82be8","user":{"login":"jimporter","id":826865,"avatar_url":"https://avatars.githubusercontent.com/u/826865?","gravatar_id":"e8c0d7de9a9f08cd1d66c6d99c49728f","url":"https://api.github.com/users/jimporter","html_url":"https://github.com/jimporter","followers_url":"https://api.github.com/users/jimporter/followers","following_url":"https://api.github.com/users/jimporter/following{/other_user}","gists_url":"https://api.github.com/users/jimporter/gists{/gist_id}","starred_url":"https://api.github.com/users/jimporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimporter/subscriptions","organizations_url":"https://api.github.com/users/jimporter/orgs","repos_url":"https://api.github.com/users/jimporter/repos","events_url":"https://api.github.com/users/jimporter/events{/privacy}","received_events_url":"https://api.github.com/users/jimporter/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2014-05-25T04:29:06Z","updated_at":"2014-05-25T04:29:06Z","html_url":"https://github.com/mozilla-b2g/gaia/pull/16151#discussion_r13029211","pull_request_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/16151","_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/13029211"},"html":{"href":"https://github.com/mozilla-b2g/gaia/pull/16151#discussion_r13029211"},"pull_request":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/16151"}}}}