{"action":"created","comment":{"url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/comments/72385545","id":72385545,"diff_hunk":"@@ -21,67 +21,78 @@\n  *   reader: an existing FileReader object. If not defined, creates a new\n  *     one internally.\n  */\n+ \n+(function () {\n+  var factory = function (ko) {\n \n-ko.bindingHandlers['file'] = {\n-  init: function(element, valueAccessor, allBindings) {\n-    var fileContents, fileName, allowed, prohibited, reader;\n-\n-    if ((typeof valueAccessor()) === \"function\") {\n-      fileContents = valueAccessor();\n-    } else {\n-      fileContents = valueAccessor()['data'];\n-      fileName = valueAccessor()['name'];\n-\n-      allowed = valueAccessor()['allowed'];\n-      if ((typeof allowed) === 'string') {\n-        allowed = [allowed];\n-      }\n-\n-      prohibited = valueAccessor()['prohibited'];\n-      if ((typeof prohibited) === 'string') {\n-        prohibited = [prohibited];\n-      }\n-\n-      reader = (valueAccessor()['reader']);\n-    }\n-\n-    reader || (reader = new FileReader());\n-    reader.onloadend = function() {\n-      fileContents(reader.result);\n-    }\n-\n-    var handler = function() {\n-      var file = element.files[0];\n-\n-      // Opening the file picker then canceling will trigger a 'change'\n-      // event without actually picking a file.\n-      if (file === undefined) {\n-        fileContents(null)\n-        return;\n-      }\n-\n-      if (allowed) {\n-        if (!allowed.some(function(type) { return type === file.type })) {\n-          console.log(\"File \"+file.name+\" is not an allowed type, ignoring.\")\n-          fileContents(null)\n-          return;\n+    ko.bindingHandlers['file'] = {\n+      init: function(element, valueAccessor, allBindings) {\n+        var fileContents, fileName, allowed, prohibited, reader;\n+    \n+        if ((typeof valueAccessor()) === \"function\") {\n+          fileContents = valueAccessor();\n+        } else {\n+          fileContents = valueAccessor()['data'];\n+          fileName = valueAccessor()['name'];\n+    \n+          allowed = valueAccessor()['allowed'];\n+          if ((typeof allowed) === 'string') {\n+            allowed = [allowed];\n+          }\n+    \n+          prohibited = valueAccessor()['prohibited'];\n+          if ((typeof prohibited) === 'string') {\n+            prohibited = [prohibited];\n+          }\n+    \n+          reader = (valueAccessor()['reader']);\n         }\n-      }\n-\n-      if (prohibited) {\n-        if (prohibited.some(function(type) { return type === file.type })) {\n-          console.log(\"File \"+file.name+\" is a prohibited type, ignoring.\")\n-          fileContents(null)\n-          return;\n+    \n+        reader || (reader = new FileReader());\n+        reader.onloadend = function() {\n+          fileContents(reader.result);\n         }\n-      }\n-\n-      reader.readAsDataURL(file); // A callback (above) will set fileContents\n-      if (typeof fileName === \"function\") {\n-        fileName(file.name)\n+    \n+        var handler = function() {\n+          var file = element.files[0];\n+    \n+          // Opening the file picker then canceling will trigger a 'change'\n+          // event without actually picking a file.\n+          if (file === undefined) {\n+            fileContents(null)\n+            return;\n+          }\n+    \n+          if (allowed) {\n+            if (!allowed.some(function(type) { return type === file.type })) {\n+              console.log(\"File \"+file.name+\" is not an allowed type, ignoring.\")\n+              fileContents(null)\n+              return;\n+            }\n+          }\n+    \n+          if (prohibited) {\n+            if (prohibited.some(function(type) { return type === file.type })) {\n+              console.log(\"File \"+file.name+\" is a prohibited type, ignoring.\")\n+              fileContents(null)\n+              return;\n+            }\n+          }\n+    \n+          reader.readAsDataURL(file); // A callback (above) will set fileContents\n+          if (typeof fileName === \"function\") {\n+            fileName(file.name)\n+          }\n+        }\n+    \n+        ko.utils.registerEventHandler(element, 'change', handler);\n       }\n     }\n+  }\n \n-    ko.utils.registerEventHandler(element, 'change', handler);\n+  if (define) {","path":"knockout-file-bind.js","position":129,"original_position":129,"commit_id":"38e6616a33bf9aa46ad6622f665ffd4d92cf188a","original_commit_id":"38e6616a33bf9aa46ad6622f665ffd4d92cf188a","user":{"login":"ivaylo5ev","id":1716141,"avatar_url":"https://avatars.githubusercontent.com/u/1716141?v=3","gravatar_id":"","url":"https://api.github.com/users/ivaylo5ev","html_url":"https://github.com/ivaylo5ev","followers_url":"https://api.github.com/users/ivaylo5ev/followers","following_url":"https://api.github.com/users/ivaylo5ev/following{/other_user}","gists_url":"https://api.github.com/users/ivaylo5ev/gists{/gist_id}","starred_url":"https://api.github.com/users/ivaylo5ev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivaylo5ev/subscriptions","organizations_url":"https://api.github.com/users/ivaylo5ev/orgs","repos_url":"https://api.github.com/users/ivaylo5ev/repos","events_url":"https://api.github.com/users/ivaylo5ev/events{/privacy}","received_events_url":"https://api.github.com/users/ivaylo5ev/received_events","type":"User","site_admin":false},"body":"if not present it would be `undefined`, which I assume would result to `false` in a boolean condition.  The values `false`, `null`, `0` and `undefined` are treated all as `false` in if-else logic.\r\n\r\nIf you have observed otherwise, I will change that line to something more meaningful. For example `if (define && typeof define === 'function')` is indeed more accurate.","created_at":"2016-07-27T06:14:56Z","updated_at":"2016-07-27T06:14:56Z","html_url":"https://github.com/TooManyBees/knockoutjs-file-binding/pull/2#discussion_r72385545","pull_request_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/comments/72385545"},"html":{"href":"https://github.com/TooManyBees/knockoutjs-file-binding/pull/2#discussion_r72385545"},"pull_request":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/2","id":78590555,"html_url":"https://github.com/TooManyBees/knockoutjs-file-binding/pull/2","diff_url":"https://github.com/TooManyBees/knockoutjs-file-binding/pull/2.diff","patch_url":"https://github.com/TooManyBees/knockoutjs-file-binding/pull/2.patch","issue_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/issues/2","number":2,"state":"open","locked":false,"title":"Added AMD support","user":{"login":"ivaylo5ev","id":1716141,"avatar_url":"https://avatars.githubusercontent.com/u/1716141?v=3","gravatar_id":"","url":"https://api.github.com/users/ivaylo5ev","html_url":"https://github.com/ivaylo5ev","followers_url":"https://api.github.com/users/ivaylo5ev/followers","following_url":"https://api.github.com/users/ivaylo5ev/following{/other_user}","gists_url":"https://api.github.com/users/ivaylo5ev/gists{/gist_id}","starred_url":"https://api.github.com/users/ivaylo5ev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivaylo5ev/subscriptions","organizations_url":"https://api.github.com/users/ivaylo5ev/orgs","repos_url":"https://api.github.com/users/ivaylo5ev/repos","events_url":"https://api.github.com/users/ivaylo5ev/events{/privacy}","received_events_url":"https://api.github.com/users/ivaylo5ev/received_events","type":"User","site_admin":false},"body":"Added AMD support - now the library can be used with requirejs or other AMD js library.  This is useful, as when knockout us used with requirejs for example, it is not necessary for it to expose the global `ko` variable. It's absence however causes this script to fail.\r\n\r\nThe submitted fix would assume that if an AMD library is used, the knockout dependency is named \"knockout\" - which is already a standard among a number of knockout-related modules I have worked with (for example [knockout-amd-helpers](https://github.com/rniemeyer/knockout-amd-helpers) ).\r\n\r\nIf no AMD is available, the library will rely on the global `ko` object exposed by the knockout.js library if directly referenced by a script tag, which it currently does.","created_at":"2016-07-24T05:52:42Z","updated_at":"2016-07-27T06:14:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e6f25d6026a77f0b3a153652f69fd495c2e879b3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/2/commits","review_comments_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/2/comments","review_comment_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/comments{/number}","comments_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/issues/2/comments","statuses_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/statuses/38e6616a33bf9aa46ad6622f665ffd4d92cf188a","head":{"label":"ivaylo5ev:master","ref":"master","sha":"38e6616a33bf9aa46ad6622f665ffd4d92cf188a","user":{"login":"ivaylo5ev","id":1716141,"avatar_url":"https://avatars.githubusercontent.com/u/1716141?v=3","gravatar_id":"","url":"https://api.github.com/users/ivaylo5ev","html_url":"https://github.com/ivaylo5ev","followers_url":"https://api.github.com/users/ivaylo5ev/followers","following_url":"https://api.github.com/users/ivaylo5ev/following{/other_user}","gists_url":"https://api.github.com/users/ivaylo5ev/gists{/gist_id}","starred_url":"https://api.github.com/users/ivaylo5ev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivaylo5ev/subscriptions","organizations_url":"https://api.github.com/users/ivaylo5ev/orgs","repos_url":"https://api.github.com/users/ivaylo5ev/repos","events_url":"https://api.github.com/users/ivaylo5ev/events{/privacy}","received_events_url":"https://api.github.com/users/ivaylo5ev/received_events","type":"User","site_admin":false},"repo":{"id":64050659,"name":"knockoutjs-file-binding","full_name":"ivaylo5ev/knockoutjs-file-binding","owner":{"login":"ivaylo5ev","id":1716141,"avatar_url":"https://avatars.githubusercontent.com/u/1716141?v=3","gravatar_id":"","url":"https://api.github.com/users/ivaylo5ev","html_url":"https://github.com/ivaylo5ev","followers_url":"https://api.github.com/users/ivaylo5ev/followers","following_url":"https://api.github.com/users/ivaylo5ev/following{/other_user}","gists_url":"https://api.github.com/users/ivaylo5ev/gists{/gist_id}","starred_url":"https://api.github.com/users/ivaylo5ev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivaylo5ev/subscriptions","organizations_url":"https://api.github.com/users/ivaylo5ev/orgs","repos_url":"https://api.github.com/users/ivaylo5ev/repos","events_url":"https://api.github.com/users/ivaylo5ev/events{/privacy}","received_events_url":"https://api.github.com/users/ivaylo5ev/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ivaylo5ev/knockoutjs-file-binding","description":"A binding that stores an encoded file (from an input element) in an observable.","fork":true,"url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding","forks_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/forks","keys_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/teams","hooks_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/hooks","issue_events_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/issues/events{/number}","events_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/events","assignees_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/assignees{/user}","branches_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/branches{/branch}","tags_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/tags","blobs_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/git/refs{/sha}","trees_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/statuses/{sha}","languages_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/languages","stargazers_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/stargazers","contributors_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/contributors","subscribers_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/subscribers","subscription_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/subscription","commits_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/commits{/sha}","git_commits_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/git/commits{/sha}","comments_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/comments{/number}","issue_comment_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/issues/comments{/number}","contents_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/contents/{+path}","compare_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/merges","archive_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/downloads","issues_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/issues{/number}","pulls_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/pulls{/number}","milestones_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/milestones{/number}","notifications_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/labels{/name}","releases_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/releases{/id}","deployments_url":"https://api.github.com/repos/ivaylo5ev/knockoutjs-file-binding/deployments","created_at":"2016-07-24T05:41:26Z","updated_at":"2016-07-24T05:41:28Z","pushed_at":"2016-07-24T05:46:49Z","git_url":"git://github.com/ivaylo5ev/knockoutjs-file-binding.git","ssh_url":"git@github.com:ivaylo5ev/knockoutjs-file-binding.git","clone_url":"https://github.com/ivaylo5ev/knockoutjs-file-binding.git","svn_url":"https://github.com/ivaylo5ev/knockoutjs-file-binding","homepage":null,"size":4,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"TooManyBees:master","ref":"master","sha":"ef68360d4c66e15de54d0613ec30c5cdb33521e7","user":{"login":"TooManyBees","id":5176286,"avatar_url":"https://avatars.githubusercontent.com/u/5176286?v=3","gravatar_id":"","url":"https://api.github.com/users/TooManyBees","html_url":"https://github.com/TooManyBees","followers_url":"https://api.github.com/users/TooManyBees/followers","following_url":"https://api.github.com/users/TooManyBees/following{/other_user}","gists_url":"https://api.github.com/users/TooManyBees/gists{/gist_id}","starred_url":"https://api.github.com/users/TooManyBees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TooManyBees/subscriptions","organizations_url":"https://api.github.com/users/TooManyBees/orgs","repos_url":"https://api.github.com/users/TooManyBees/repos","events_url":"https://api.github.com/users/TooManyBees/events{/privacy}","received_events_url":"https://api.github.com/users/TooManyBees/received_events","type":"User","site_admin":false},"repo":{"id":14415935,"name":"knockoutjs-file-binding","full_name":"TooManyBees/knockoutjs-file-binding","owner":{"login":"TooManyBees","id":5176286,"avatar_url":"https://avatars.githubusercontent.com/u/5176286?v=3","gravatar_id":"","url":"https://api.github.com/users/TooManyBees","html_url":"https://github.com/TooManyBees","followers_url":"https://api.github.com/users/TooManyBees/followers","following_url":"https://api.github.com/users/TooManyBees/following{/other_user}","gists_url":"https://api.github.com/users/TooManyBees/gists{/gist_id}","starred_url":"https://api.github.com/users/TooManyBees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TooManyBees/subscriptions","organizations_url":"https://api.github.com/users/TooManyBees/orgs","repos_url":"https://api.github.com/users/TooManyBees/repos","events_url":"https://api.github.com/users/TooManyBees/events{/privacy}","received_events_url":"https://api.github.com/users/TooManyBees/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TooManyBees/knockoutjs-file-binding","description":"A binding that stores an encoded file (from an input element) in an observable.","fork":false,"url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding","forks_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/forks","keys_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/teams","hooks_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/hooks","issue_events_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/issues/events{/number}","events_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/events","assignees_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/assignees{/user}","branches_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/branches{/branch}","tags_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/tags","blobs_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/git/refs{/sha}","trees_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/statuses/{sha}","languages_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/languages","stargazers_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/stargazers","contributors_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/contributors","subscribers_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/subscribers","subscription_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/subscription","commits_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/commits{/sha}","git_commits_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/git/commits{/sha}","comments_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/comments{/number}","issue_comment_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/issues/comments{/number}","contents_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/contents/{+path}","compare_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/merges","archive_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/downloads","issues_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/issues{/number}","pulls_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls{/number}","milestones_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/milestones{/number}","notifications_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/labels{/name}","releases_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/releases{/id}","deployments_url":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/deployments","created_at":"2013-11-15T05:27:18Z","updated_at":"2016-07-05T23:03:08Z","pushed_at":"2016-07-24T05:52:42Z","git_url":"git://github.com/TooManyBees/knockoutjs-file-binding.git","ssh_url":"git@github.com:TooManyBees/knockoutjs-file-binding.git","clone_url":"https://github.com/TooManyBees/knockoutjs-file-binding.git","svn_url":"https://github.com/TooManyBees/knockoutjs-file-binding","homepage":null,"size":112,"stargazers_count":13,"watchers_count":13,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/2"},"html":{"href":"https://github.com/TooManyBees/knockoutjs-file-binding/pull/2"},"issue":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/issues/2"},"comments":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/TooManyBees/knockoutjs-file-binding/statuses/38e6616a33bf9aa46ad6622f665ffd4d92cf188a"}}}}
{"actor":{"display_login":"ivaylo5ev"}}