{"action":"created","comment":{"url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/comments/35105397","id":35105397,"diff_hunk":"@@ -1,67 +1,83 @@\n+/* global config, _ */\n var RiseVision = RiseVision || {};\n RiseVision.ImageFolder = RiseVision.ImageFolder || {};\n \n RiseVision.ImageFolder.Storage = function (params) {\n   \"use strict\";\n \n-  var isLoading = true;\n+  var isLoading = true,\n+    files = [],\n+    timer = null;\n \n   /*\n    *  Public Methods\n    */\n   function init() {\n-    var storage = document.querySelector(\"rise-storage\"),\n-      sort = \"\",\n-      sortDirection = \"\";\n+    var storage = document.querySelector(\"rise-storage\");\n \n-    storage.addEventListener(\"rise-storage-response\", function(e) {\n-      var urls = [];\n+    storage.addEventListener(\"rise-storage-response\", handleResponse);\n+    storage.setAttribute(\"companyId\", params.storage.companyId);\n+    storage.setAttribute(\"folder\", params.storage.folder);\n+    storage.setAttribute(\"env\", config.STORAGE_ENV);\n+    storage.go();\n+  }\n \n-      e.detail.files.forEach(function(file) {\n-        urls.push(file.url);\n-      });\n+  function handleResponse(e) {\n+    processUrl(e);\n \n-      if (isLoading) {\n-        RiseVision.ImageFolder.initSlider(urls);\n+    if (isLoading) {\n+      // Need to wait for at least 2 images to load before initializing the slider.\n+      // Otherwise, the revolution.slide.onchange event will never fire, and this event is used\n+      // to check whether or not the slider should refresh.\n+      if (files.length > 1) {\n         isLoading = false;\n+\n+        clearTimeout(timer);\n+        RiseVision.ImageFolder.initSlider(files);\n       }\n+      // Set a timeout in case there is only one image in the folder.\n       else {\n-        RiseVision.ImageFolder.refreshSlider(urls);\n+        timer = setTimeout(function() {\n+          isLoading = false;\n+          RiseVision.ImageFolder.initSlider(files);\n+        }, 5000);\n       }\n-    });\n+    }\n+    else {\n+      RiseVision.ImageFolder.refreshSlider(files);\n+    }\n+  }\n \n-    storage.setAttribute(\"companyId\", params.storage.companyId);\n-    storage.setAttribute(\"folder\", params.storage.folder);\n+  function processUrl(e) {\n+    var file;\n+\n+    if (e.detail) {\n+      // Image has been added.\n+      if (e.detail.hasOwnProperty(\"added\") && e.detail.added) {\n+        files.push({\n+          \"name\": e.detail.name,\n+          \"url\": e.detail.url\n+        });\n+      }\n+      // Image has been changed.\n+      else if (e.detail.hasOwnProperty(\"changed\") && e.detail.changed) {\n+        file = _.find(files, function(file) {\n+          return file.name === e.detail.name;\n+        });\n \n-    // Sorting\n-    switch (params.order) {\n-      case \"alpha-asc\":\n-        sort = \"name\";\n-        sortDirection = \"asc\";\n-        break;\n-      case \"alpha-desc\":\n-        sort = \"name\";\n-        sortDirection = \"desc\";\n-        break;\n-      case \"date-asc\":\n-        sort = \"date\";\n-        sortDirection = \"asc\";\n-        break;\n-      case \"date-desc\":\n-        sort = \"date\";\n-        sortDirection = \"desc\";\n-        break;\n-      case \"random\":\n-        sort = \"random\";\n-        break;\n-      default:\n-        sort = \"name\";\n-        sortDirection = \"asc\";\n+        file.url = e.detail.url;\n+      }\n+      // Image has been deleted.\n+      else if (e.detail.hasOwnProperty(\"deleted\") && e.detail.deleted) {\n+        files = _.reject(files, function(file) {\n+          return file.url === e.detail.url;\n+        });\n+      }\n     }\n \n-    storage.setAttribute(\"sort\", sort);\n-    storage.setAttribute(\"sortDirection\", sortDirection);\n-    storage.go();\n+    files = _.sortBy(files, function(url) {\n+      return url.name;","path":"src/widget/storage.js","position":null,"original_position":121,"commit_id":"e80969931e3cc3227cd4b80ffea3439b45fd81c1","original_commit_id":"65eb52b4eb7f45a5aa3ce1d838d74d9a86c2a1dc","user":{"login":"donnapep","id":1190420,"avatar_url":"https://avatars.githubusercontent.com/u/1190420?v=3","gravatar_id":"","url":"https://api.github.com/users/donnapep","html_url":"https://github.com/donnapep","followers_url":"https://api.github.com/users/donnapep/followers","following_url":"https://api.github.com/users/donnapep/following{/other_user}","gists_url":"https://api.github.com/users/donnapep/gists{/gist_id}","starred_url":"https://api.github.com/users/donnapep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/donnapep/subscriptions","organizations_url":"https://api.github.com/users/donnapep/orgs","repos_url":"https://api.github.com/users/donnapep/repos","events_url":"https://api.github.com/users/donnapep/events{/privacy}","received_events_url":"https://api.github.com/users/donnapep/received_events","type":"User","site_admin":false},"body":"@stulees Good catch on the upper / lower case. I changed the compare to use lowercase. I don't see the point of extracting the folder from the name since all files are going to be in the same folder and start with the same name, so I'm leaving that.","created_at":"2015-07-21T14:09:22Z","updated_at":"2015-07-21T14:09:22Z","html_url":"https://github.com/Rise-Vision/widget-image-folder/pull/18#discussion_r35105397","pull_request_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/comments/35105397"},"html":{"href":"https://github.com/Rise-Vision/widget-image-folder/pull/18#discussion_r35105397"},"pull_request":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/18","id":40446300,"html_url":"https://github.com/Rise-Vision/widget-image-folder/pull/18","diff_url":"https://github.com/Rise-Vision/widget-image-folder/pull/18.diff","patch_url":"https://github.com/Rise-Vision/widget-image-folder/pull/18.patch","issue_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues/18","number":18,"state":"open","locked":false,"title":"Fix/issue 16","user":{"login":"donnapep","id":1190420,"avatar_url":"https://avatars.githubusercontent.com/u/1190420?v=3","gravatar_id":"","url":"https://api.github.com/users/donnapep","html_url":"https://github.com/donnapep","followers_url":"https://api.github.com/users/donnapep/followers","following_url":"https://api.github.com/users/donnapep/following{/other_user}","gists_url":"https://api.github.com/users/donnapep/gists{/gist_id}","starred_url":"https://api.github.com/users/donnapep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/donnapep/subscriptions","organizations_url":"https://api.github.com/users/donnapep/orgs","repos_url":"https://api.github.com/users/donnapep/repos","events_url":"https://api.github.com/users/donnapep/events{/privacy}","received_events_url":"https://api.github.com/users/donnapep/received_events","type":"User","site_admin":false},"body":"* Upgrade to latest version of storage component.\r\n* Remove \"Order\" setting.\r\n* Sort files alphabetically by default. Fixes issue #14. \r\n* Widget tests can now be found in the `test/integration` folder.","created_at":"2015-07-21T11:17:35Z","updated_at":"2015-07-21T14:09:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"286e91b297d8f256bc631c04237c784745ee7f2f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/18/commits","review_comments_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/18/comments","review_comment_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues/18/comments","statuses_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/statuses/e80969931e3cc3227cd4b80ffea3439b45fd81c1","head":{"label":"Rise-Vision:fix/issue-16","ref":"fix/issue-16","sha":"e80969931e3cc3227cd4b80ffea3439b45fd81c1","user":{"login":"Rise-Vision","id":6840223,"avatar_url":"https://avatars.githubusercontent.com/u/6840223?v=3","gravatar_id":"","url":"https://api.github.com/users/Rise-Vision","html_url":"https://github.com/Rise-Vision","followers_url":"https://api.github.com/users/Rise-Vision/followers","following_url":"https://api.github.com/users/Rise-Vision/following{/other_user}","gists_url":"https://api.github.com/users/Rise-Vision/gists{/gist_id}","starred_url":"https://api.github.com/users/Rise-Vision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rise-Vision/subscriptions","organizations_url":"https://api.github.com/users/Rise-Vision/orgs","repos_url":"https://api.github.com/users/Rise-Vision/repos","events_url":"https://api.github.com/users/Rise-Vision/events{/privacy}","received_events_url":"https://api.github.com/users/Rise-Vision/received_events","type":"Organization","site_admin":false},"repo":{"id":30305150,"name":"widget-image-folder","full_name":"Rise-Vision/widget-image-folder","owner":{"login":"Rise-Vision","id":6840223,"avatar_url":"https://avatars.githubusercontent.com/u/6840223?v=3","gravatar_id":"","url":"https://api.github.com/users/Rise-Vision","html_url":"https://github.com/Rise-Vision","followers_url":"https://api.github.com/users/Rise-Vision/followers","following_url":"https://api.github.com/users/Rise-Vision/following{/other_user}","gists_url":"https://api.github.com/users/Rise-Vision/gists{/gist_id}","starred_url":"https://api.github.com/users/Rise-Vision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rise-Vision/subscriptions","organizations_url":"https://api.github.com/users/Rise-Vision/orgs","repos_url":"https://api.github.com/users/Rise-Vision/repos","events_url":"https://api.github.com/users/Rise-Vision/events{/privacy}","received_events_url":"https://api.github.com/users/Rise-Vision/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Rise-Vision/widget-image-folder","description":"Rise Vision Image Folder Widget","fork":false,"url":"https://api.github.com/repos/Rise-Vision/widget-image-folder","forks_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/forks","keys_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/teams","hooks_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/hooks","issue_events_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues/events{/number}","events_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/events","assignees_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/assignees{/user}","branches_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/branches{/branch}","tags_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/tags","blobs_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/refs{/sha}","trees_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/statuses/{sha}","languages_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/languages","stargazers_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/stargazers","contributors_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/contributors","subscribers_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/subscribers","subscription_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/subscription","commits_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/commits{/sha}","git_commits_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/commits{/sha}","comments_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/comments{/number}","issue_comment_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues/comments{/number}","contents_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/contents/{+path}","compare_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/merges","archive_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/downloads","issues_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues{/number}","pulls_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls{/number}","milestones_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/milestones{/number}","notifications_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/labels{/name}","releases_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/releases{/id}","created_at":"2015-02-04T15:19:48Z","updated_at":"2015-03-25T13:19:10Z","pushed_at":"2015-07-21T14:01:58Z","git_url":"git://github.com/Rise-Vision/widget-image-folder.git","ssh_url":"git@github.com:Rise-Vision/widget-image-folder.git","clone_url":"https://github.com/Rise-Vision/widget-image-folder.git","svn_url":"https://github.com/Rise-Vision/widget-image-folder","homepage":null,"size":2458,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":4,"forks":2,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"Rise-Vision:master","ref":"master","sha":"f96f9760fcf0ec2f040bcabb9a24e5a30221ab68","user":{"login":"Rise-Vision","id":6840223,"avatar_url":"https://avatars.githubusercontent.com/u/6840223?v=3","gravatar_id":"","url":"https://api.github.com/users/Rise-Vision","html_url":"https://github.com/Rise-Vision","followers_url":"https://api.github.com/users/Rise-Vision/followers","following_url":"https://api.github.com/users/Rise-Vision/following{/other_user}","gists_url":"https://api.github.com/users/Rise-Vision/gists{/gist_id}","starred_url":"https://api.github.com/users/Rise-Vision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rise-Vision/subscriptions","organizations_url":"https://api.github.com/users/Rise-Vision/orgs","repos_url":"https://api.github.com/users/Rise-Vision/repos","events_url":"https://api.github.com/users/Rise-Vision/events{/privacy}","received_events_url":"https://api.github.com/users/Rise-Vision/received_events","type":"Organization","site_admin":false},"repo":{"id":30305150,"name":"widget-image-folder","full_name":"Rise-Vision/widget-image-folder","owner":{"login":"Rise-Vision","id":6840223,"avatar_url":"https://avatars.githubusercontent.com/u/6840223?v=3","gravatar_id":"","url":"https://api.github.com/users/Rise-Vision","html_url":"https://github.com/Rise-Vision","followers_url":"https://api.github.com/users/Rise-Vision/followers","following_url":"https://api.github.com/users/Rise-Vision/following{/other_user}","gists_url":"https://api.github.com/users/Rise-Vision/gists{/gist_id}","starred_url":"https://api.github.com/users/Rise-Vision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rise-Vision/subscriptions","organizations_url":"https://api.github.com/users/Rise-Vision/orgs","repos_url":"https://api.github.com/users/Rise-Vision/repos","events_url":"https://api.github.com/users/Rise-Vision/events{/privacy}","received_events_url":"https://api.github.com/users/Rise-Vision/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Rise-Vision/widget-image-folder","description":"Rise Vision Image Folder Widget","fork":false,"url":"https://api.github.com/repos/Rise-Vision/widget-image-folder","forks_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/forks","keys_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/teams","hooks_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/hooks","issue_events_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues/events{/number}","events_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/events","assignees_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/assignees{/user}","branches_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/branches{/branch}","tags_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/tags","blobs_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/refs{/sha}","trees_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/statuses/{sha}","languages_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/languages","stargazers_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/stargazers","contributors_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/contributors","subscribers_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/subscribers","subscription_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/subscription","commits_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/commits{/sha}","git_commits_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/git/commits{/sha}","comments_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/comments{/number}","issue_comment_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues/comments{/number}","contents_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/contents/{+path}","compare_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/merges","archive_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/downloads","issues_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues{/number}","pulls_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls{/number}","milestones_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/milestones{/number}","notifications_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/labels{/name}","releases_url":"https://api.github.com/repos/Rise-Vision/widget-image-folder/releases{/id}","created_at":"2015-02-04T15:19:48Z","updated_at":"2015-03-25T13:19:10Z","pushed_at":"2015-07-21T14:01:58Z","git_url":"git://github.com/Rise-Vision/widget-image-folder.git","ssh_url":"git@github.com:Rise-Vision/widget-image-folder.git","clone_url":"https://github.com/Rise-Vision/widget-image-folder.git","svn_url":"https://github.com/Rise-Vision/widget-image-folder","homepage":null,"size":2458,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":4,"forks":2,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/18"},"html":{"href":"https://github.com/Rise-Vision/widget-image-folder/pull/18"},"issue":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues/18"},"comments":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/Rise-Vision/widget-image-folder/statuses/e80969931e3cc3227cd4b80ffea3439b45fd81c1"}}}}