{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/24274070","id":24274070,"diff_hunk":"@@ -3,56 +3,150 @@\n * leaving the page with unsaved changes.\n */\n 'use strict';\n-// TODO: Use commonjs+webpack to load pagedown modules\n var ko = require('knockout');\n var $ = require('jquery');\n var $osf = require('osfHelpers');\n var Raven = require('raven-js');\n require('bootstrap-editable');\n+var Markdown = require('pagedown-ace-converter');\n+Markdown.getSanitizingConverter = require('pagedown-ace-sanitizer').getSanitizingConverter;\n+require('imports?Markdown=pagedown-ace-converter!pagedown-ace-editor');\n+\n+var editor;\n+\n+ko.bindingHandlers.ace = {\n+    init: function(element, valueAccessor) {\n+        editor = ace.edit(element.id);\n+\n+        // Updates the view model based on changes to the editor\n+        editor.getSession().on('change', function () {\n+            valueAccessor()(editor.getValue());\n+        });\n+    },\n+    update: function (element, valueAccessor) {\n+        var content = editor.getValue();        // Content of ace editor\n+        var value = ko.unwrap(valueAccessor()); // Value from view model\n+\n+        // Updates the editor based on changes to the view model\n+        if (value !== undefined && content !== value) {\n+            var cursorPosition = editor.getCursorPosition();\n+            editor.setValue(value);\n+            editor.gotoLine(cursorPosition.row + 1, cursorPosition.column);\n+        }\n+    }\n+};\n \n function ViewModel(url) {\n     var self = this;\n \n-    self.initText = '';\n-    self.wikiText = ko.observable();\n+    self.publishedText = ko.observable('');\n+    self.currentText = ko.observable('');\n+    self.activeUsers = ko.observableArray([]);\n+    self.status = ko.observable('connecting');\n+\n+    self.displayCollaborators = ko.computed(function() {\n+       return self.activeUsers().length > 1;\n+    });\n+\n+    self.statusDisplay = ko.computed(function() {\n+        switch(self.status()) {\n+            case 'connected':\n+                return 'Live Editing Mode';\n+            case 'connecting':\n+                return 'Attempting to Connect';\n+            case 'noWebSocket':\n+                return 'Your browser does not support Live Editing';\n+            default:\n+                return 'Live Editing Unavailable';\n+        }\n+    });\n \n-    self.changed = ko.computed(function() {\n-        return self.initText !== self.wikiText();\n+    self.progressBar = ko.computed(function() {\n+        switch(self.status()) {\n+            case 'connected':\n+                return {\n+                    class: \"progress-bar progress-bar-success\",\n+                    style: \"width: 100%\"\n+                };\n+            case 'connecting':\n+                return {\n+                    class: \"progress-bar progress-bar-warning progress-bar-striped active\",\n+                    style: \"width: 100%\"\n+                };\n+            default:\n+                return {\n+                    class: \"progress-bar progress-bar-danger\",\n+                    style: \"width: 100%\"\n+                };\n+        }\n     });\n \n-    //Fetch initial wiki text\n-    $.ajax({\n-        type: 'GET',\n-        url: url,\n-        dataType: 'json',\n-        cache: false,\n-        success: function(response) {\n-            self.initText = response.wiki_content;\n-            self.wikiText(response.wiki_content);\n-        },\n-        error: function(xhr, textStatus, error) {\n-            $osf.growl('Error','The wiki content could not be loaded.');\n-            Raven.captureMessage('Could not GET get wiki contents.', {\n-                url: url,\n-                textStatus: textStatus,\n-                error: error\n-            });\n+    self.modalTarget = ko.computed(function() {\n+        switch(self.status()) {\n+            case 'connected':\n+                return '#connected-modal';\n+            case 'connecting':\n+                return '#connecting-modal';\n+            default:\n+                return '#disconnected-modal';\n         }\n     });\n \n+    self.wikisDiffer = function(wiki1, wiki2) {\n+        // Handle inconsistencies in newline notation\n+        var clean1 = typeof wiki1 === 'string' ?\n+            wiki1.replace(/(\\r\\n|\\n|\\r)/gm, '\\n') : '';\n+        var clean2 = typeof wiki2 === 'string' ?\n+            wiki2.replace(/(\\r\\n|\\n|\\r)/gm, '\\n') : '';\n+\n+        return clean1 !== clean2;\n+    };\n+\n+    self.changed = function() {\n+        return self.wikisDiffer(self.publishedText(), self.currentText());\n+    };\n+\n+    // Fetch initial wiki text\n+    self.fetchData = function(callback) {\n+        $.ajax({\n+            type: 'GET',\n+            url: url,\n+            dataType: 'json',\n+            success: function (response) {\n+                self.publishedText(response.wiki_content);\n+                if (callback) callback(response);\n+            },\n+            error: function (xhr, textStatus, error) {\n+                $.osf.growl('Error','The wiki content could not be loaded.');","path":"website/addons/wiki/static/WikiEditor.js","position":null,"original_position":140,"commit_id":"63f29a67ac68604fa639c34899a7d920c281e65e","original_commit_id":"7b7d48997582621fbd960eb14fd44341447dc0d0","user":{"login":"icereval","id":3111541,"avatar_url":"https://avatars.githubusercontent.com/u/3111541?v=3","gravatar_id":"","url":"https://api.github.com/users/icereval","html_url":"https://github.com/icereval","followers_url":"https://api.github.com/users/icereval/followers","following_url":"https://api.github.com/users/icereval/following{/other_user}","gists_url":"https://api.github.com/users/icereval/gists{/gist_id}","starred_url":"https://api.github.com/users/icereval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/icereval/subscriptions","organizations_url":"https://api.github.com/users/icereval/orgs","repos_url":"https://api.github.com/users/icereval/repos","events_url":"https://api.github.com/users/icereval/events{/privacy}","received_events_url":"https://api.github.com/users/icereval/received_events","type":"User","site_admin":false},"body":"done","created_at":"2015-02-06T21:38:00Z","updated_at":"2015-02-06T21:38:00Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/1699#discussion_r24274070","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1699","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/24274070"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/1699#discussion_r24274070"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1699"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1699","id":28499071,"html_url":"https://github.com/CenterForOpenScience/osf.io/pull/1699","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/1699.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/1699.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/1699","number":1699,"state":"open","locked":false,"title":"[WIP] [Feature] collaborative wiki","user":{"login":"icereval","id":3111541,"avatar_url":"https://avatars.githubusercontent.com/u/3111541?v=3","gravatar_id":"","url":"https://api.github.com/users/icereval","html_url":"https://github.com/icereval","followers_url":"https://api.github.com/users/icereval/followers","following_url":"https://api.github.com/users/icereval/following{/other_user}","gists_url":"https://api.github.com/users/icereval/gists{/gist_id}","starred_url":"https://api.github.com/users/icereval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/icereval/subscriptions","organizations_url":"https://api.github.com/users/icereval/orgs","repos_url":"https://api.github.com/users/icereval/repos","events_url":"https://api.github.com/users/icereval/events{/privacy}","received_events_url":"https://api.github.com/users/icereval/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-02T20:17:14Z","updated_at":"2015-02-06T21:38:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d74ac7a59d79f6b690090edeb683cf3b827714d8","assignee":null,"milestone":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones/22","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones/22/labels","id":958761,"number":22,"title":"0.25.0","description":"Collaborative Wiki\r\nAdmin view of 'private' components\r\nMendeley / Zotero / Citations\r\nFiles View (WaterButler)","creator":{"login":"sloria","id":2379650,"avatar_url":"https://avatars.githubusercontent.com/u/2379650?v=3","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":17,"state":"open","created_at":"2015-01-30T19:45:52Z","updated_at":"2015-02-06T21:21:19Z","due_on":"2015-02-11T05:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1699/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1699/comments","review_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/{number}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/1699/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/63f29a67ac68604fa639c34899a7d920c281e65e","head":{"label":"icereval:feature/collab-dev","ref":"feature/collab-dev","sha":"63f29a67ac68604fa639c34899a7d920c281e65e","user":{"login":"icereval","id":3111541,"avatar_url":"https://avatars.githubusercontent.com/u/3111541?v=3","gravatar_id":"","url":"https://api.github.com/users/icereval","html_url":"https://github.com/icereval","followers_url":"https://api.github.com/users/icereval/followers","following_url":"https://api.github.com/users/icereval/following{/other_user}","gists_url":"https://api.github.com/users/icereval/gists{/gist_id}","starred_url":"https://api.github.com/users/icereval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/icereval/subscriptions","organizations_url":"https://api.github.com/users/icereval/orgs","repos_url":"https://api.github.com/users/icereval/repos","events_url":"https://api.github.com/users/icereval/events{/privacy}","received_events_url":"https://api.github.com/users/icereval/received_events","type":"User","site_admin":false},"repo":{"id":26919847,"name":"osf.io","full_name":"icereval/osf.io","owner":{"login":"icereval","id":3111541,"avatar_url":"https://avatars.githubusercontent.com/u/3111541?v=3","gravatar_id":"","url":"https://api.github.com/users/icereval","html_url":"https://github.com/icereval","followers_url":"https://api.github.com/users/icereval/followers","following_url":"https://api.github.com/users/icereval/following{/other_user}","gists_url":"https://api.github.com/users/icereval/gists{/gist_id}","starred_url":"https://api.github.com/users/icereval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/icereval/subscriptions","organizations_url":"https://api.github.com/users/icereval/orgs","repos_url":"https://api.github.com/users/icereval/repos","events_url":"https://api.github.com/users/icereval/events{/privacy}","received_events_url":"https://api.github.com/users/icereval/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/icereval/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/icereval/osf.io","forks_url":"https://api.github.com/repos/icereval/osf.io/forks","keys_url":"https://api.github.com/repos/icereval/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/icereval/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/icereval/osf.io/teams","hooks_url":"https://api.github.com/repos/icereval/osf.io/hooks","issue_events_url":"https://api.github.com/repos/icereval/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/icereval/osf.io/events","assignees_url":"https://api.github.com/repos/icereval/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/icereval/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/icereval/osf.io/tags","blobs_url":"https://api.github.com/repos/icereval/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/icereval/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/icereval/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/icereval/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/icereval/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/icereval/osf.io/languages","stargazers_url":"https://api.github.com/repos/icereval/osf.io/stargazers","contributors_url":"https://api.github.com/repos/icereval/osf.io/contributors","subscribers_url":"https://api.github.com/repos/icereval/osf.io/subscribers","subscription_url":"https://api.github.com/repos/icereval/osf.io/subscription","commits_url":"https://api.github.com/repos/icereval/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/icereval/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/icereval/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/icereval/osf.io/issues/comments/{number}","contents_url":"https://api.github.com/repos/icereval/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/icereval/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/icereval/osf.io/merges","archive_url":"https://api.github.com/repos/icereval/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/icereval/osf.io/downloads","issues_url":"https://api.github.com/repos/icereval/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/icereval/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/icereval/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/icereval/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/icereval/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/icereval/osf.io/releases{/id}","created_at":"2014-11-20T15:59:03Z","updated_at":"2014-12-30T17:04:26Z","pushed_at":"2015-02-06T21:37:14Z","git_url":"git://github.com/icereval/osf.io.git","ssh_url":"git@github.com:icereval/osf.io.git","clone_url":"https://github.com/icereval/osf.io.git","svn_url":"https://github.com/icereval/osf.io","homepage":"http://osf.io","size":75512,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"CenterForOpenScience:develop","ref":"develop","sha":"a3d0588b9de435dfb2a9d3cd9617e7afdf309b6f","user":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"repo":{"id":10199599,"name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CenterForOpenScience/osf.io","description":"Facilitating Open Science","fork":false,"url":"https://api.github.com/repos/CenterForOpenScience/osf.io","forks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/forks","keys_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/teams","hooks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/hooks","issue_events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/events","assignees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/tags","blobs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/languages","stargazers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/stargazers","contributors_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contributors","subscribers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscribers","subscription_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscription","commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/comments/{number}","contents_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/merges","archive_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/downloads","issues_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/releases{/id}","created_at":"2013-05-21T15:53:37Z","updated_at":"2015-02-06T21:21:23Z","pushed_at":"2015-02-06T21:21:21Z","git_url":"git://github.com/CenterForOpenScience/osf.io.git","ssh_url":"git@github.com:CenterForOpenScience/osf.io.git","clone_url":"https://github.com/CenterForOpenScience/osf.io.git","svn_url":"https://github.com/CenterForOpenScience/osf.io","homepage":"http://osf.io","size":82037,"stargazers_count":68,"watchers_count":68,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":43,"mirror_url":null,"open_issues_count":331,"forks":43,"open_issues":331,"watchers":68,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1699"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/1699"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/1699"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/1699/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1699/comments"},"review_comment":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1699/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/63f29a67ac68604fa639c34899a7d920c281e65e"}}}}