From 0468cbc300b3fb3f95bf17142f9340b70af20f80 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 5 Mar 2014 16:31:52 +0000 Subject: [PATCH 01/10] Add in proxy to track changes api --- .../TrackChangesController.coffee | 13 ++++++ services/web/app/coffee/router.coffee | 4 ++ .../TrackChangesControllerTests.coffee | 46 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee create mode 100644 services/web/test/UnitTests/coffee/TrackChanges/TrackChangesControllerTests.coffee diff --git a/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee b/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee new file mode 100644 index 0000000000..bb7193b5a7 --- /dev/null +++ b/services/web/app/coffee/Features/TrackChanges/TrackChangesController.coffee @@ -0,0 +1,13 @@ +logger = require "logger-sharelatex" +request = require "request" +settings = require "settings-sharelatex" + +module.exports = TrackChangesController = + proxyToTrackChangesApi: (req, res, next = (error) ->) -> + url = settings.apis.trackchanges.url + req.url + logger.log url: url, "proxying to track-changes api" + getReq = request.get(url) + getReq.pipe(res) + getReq.on "error", (error) -> + logger.error err: error, "track-changes API error" + next(error) \ No newline at end of file diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index c724173e3d..4c9f88b31a 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -32,6 +32,7 @@ CompileController = require("./Features/Compile/CompileController") HealthCheckController = require("./Features/HealthCheck/HealthCheckController") ProjectDownloadsController = require "./Features/Downloads/ProjectDownloadsController" FileStoreController = require("./Features/FileStore/FileStoreController") +TrackChangesController = require("./Features/TrackChanges/TrackChangesController") logger = require("logger-sharelatex") httpAuth = require('express').basicAuth (user, pass)-> @@ -122,6 +123,9 @@ module.exports = class Router app.get '/Project/:Project_id/version', SecutiryManager.requestCanAccessProject, versioningController.listVersions app.get '/Project/:Project_id/version/:Version_id', SecutiryManager.requestCanAccessProject, versioningController.getVersion + app.get "/project/:Project_id/doc/:doc_id/updates", SecutiryManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi + app.get "/project/:Project_id/doc/:doc_id/diff", SecutiryManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi + app.post '/project/:project_id/leave', AuthenticationController.requireLogin(), CollaboratorsController.removeSelfFromProject app.get '/project/:Project_id/collaborators', SecutiryManager.requestCanAccessProject(allow_auth_token: true), CollaboratorsController.getCollaborators diff --git a/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesControllerTests.coffee b/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesControllerTests.coffee new file mode 100644 index 0000000000..e98305b939 --- /dev/null +++ b/services/web/test/UnitTests/coffee/TrackChanges/TrackChangesControllerTests.coffee @@ -0,0 +1,46 @@ +chai = require('chai') +chai.should() +sinon = require("sinon") +modulePath = "../../../../app/js/Features/TrackChanges/TrackChangesController" +SandboxedModule = require('sandboxed-module') + +describe "TrackChangesController", -> + beforeEach -> + @TrackChangesController = SandboxedModule.require modulePath, requires: + "request" : @request = {} + "settings-sharelatex": @settings = {} + "logger-sharelatex": @logger = {log: sinon.stub(), error: sinon.stub()} + + describe "proxyToTrackChangesApi", -> + beforeEach -> + @req = { url: "/mock/url" } + @res = "mock-res" + @next = sinon.stub() + @settings.apis = + trackchanges: + url: "http://trackchanges.example.com" + @proxy = + events: {} + pipe: sinon.stub() + on: (event, handler) -> @events[event] = handler + @request.get = sinon.stub().returns @proxy + @TrackChangesController.proxyToTrackChangesApi @req, @res, @next + + describe "successfully", -> + it "should call the track changes api", -> + @request.get + .calledWith("#{@settings.apis.trackchanges.url}#{@req.url}") + .should.equal true + + it "should pipe the response to the client", -> + @proxy.pipe + .calledWith(@res) + .should.equal true + + describe "with an error", -> + beforeEach -> + @proxy.events["error"].call(@proxy, @error = new Error("oops")) + + it "should pass the error up the call chain", -> + @next.calledWith(@error).should.equal true + From 8bf12f32864c2e70c76b073ef8eef8b3d4cf88e7 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 5 Mar 2014 16:54:46 +0000 Subject: [PATCH 02/10] Wrap editor in wrapper div and remove orchard CSS --- services/web/app/views/templates.jade | 9 +- .../web/public/coffee/editor/Editor.coffee | 4 +- .../web/public/stylesheets/less/editor.less | 34 +-- .../web/public/stylesheets/less/orchard.less | 236 ------------------ 4 files changed, 11 insertions(+), 272 deletions(-) delete mode 100644 services/web/public/stylesheets/less/orchard.less diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index 18c0712731..c9e6c0a8cb 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -147,10 +147,11 @@ #editorArea(style='display: none;') #editorSplitter #leftEditorPanel.ui-layout-center - #editor - #undoConflictWarning(style="display: none") - | Watch out! We had to undo some of your collaborators changes before we could undo yours. - a(href="#").js-hide Hide + #editorWrapper + #editor + #undoConflictWarning(style="display: none") + | Watch out! We had to undo some of your collaborators changes before we could undo yours. + a(href="#").js-hide Hide #rightEditorPanel.ui-layout-east script(type="text/template")#loadingIndicatorTemplate diff --git a/services/web/public/coffee/editor/Editor.coffee b/services/web/public/coffee/editor/Editor.coffee index 7c2da966c9..d0894ddc8f 100644 --- a/services/web/public/coffee/editor/Editor.coffee +++ b/services/web/public/coffee/editor/Editor.coffee @@ -73,7 +73,7 @@ define [ if @currentViewState != @viewOptions.splitView @currentViewState = @viewOptions.splitView @leftPanel.prepend( - @editorPanel.find("#editor") + @editorPanel.find("#editorWrapper") ) splitter = @editorPanel.find("#editorSplitter") splitter.show() @@ -84,7 +84,7 @@ define [ @_saveSplitterState() @currentViewState = @viewOptions.flatView @editorPanel.prepend( - @editorPanel.find("#editor") + @editorPanel.find("#editorWrapper") ) @editorPanel.find("#editorSplitter").hide() @aceEditor.resize(true) diff --git a/services/web/public/stylesheets/less/editor.less b/services/web/public/stylesheets/less/editor.less index 3cf8b012b9..7d3fedda03 100644 --- a/services/web/public/stylesheets/less/editor.less +++ b/services/web/public/stylesheets/less/editor.less @@ -177,25 +177,13 @@ body.editor { width: 100%; height: 100%; } - #editor, #orchard { + #editor { width: 100%; height: 100%; } - #orchard-toolbar { - height: 28px; - padding: 5px; - background-color: white; - border-bottom: 1px solid #aaa; - select { - margin-bottom: 0; - } - } - #orchard-editor { - position: absolute; - top: 39px; - bottom: 0; - left: 0; - right: 0; + #editorWrapper { + height: 100%; + width: 100%; } #rightEditorPanel { border-left: 1px solid #aaa; @@ -964,18 +952,6 @@ i[class*="sprite-"] { background-color: #9a2b1f \9; } -#orchard-editor { - background: white; - > .CodeMirror > .CodeMirror-scroll > .CodeMirror-sizer > div > .CodeMirror-lines { - background-color: white; - margin: auto; - max-width: 390pt; - min-height: 592pt; - margin-top: 20px; - margin-bottom: 20px; - } -} - #errorMessages { z-index: 10000; top: 4px; @@ -998,5 +974,3 @@ i[class*="sprite-"] { margin-bottom: 6px; } } - -@import "./orchard"; diff --git a/services/web/public/stylesheets/less/orchard.less b/services/web/public/stylesheets/less/orchard.less deleted file mode 100644 index e39df5c11c..0000000000 --- a/services/web/public/stylesheets/less/orchard.less +++ /dev/null @@ -1,236 +0,0 @@ -.editor-font { - font-size: 11pt; - line-height: 1.4em; - font-family: "Computer Modern", serif; - font-weight: normal; -} -@font-face { - font-family: "Computer Modern"; - src: url('../font/cmunrm.otf'); -} -@font-face { - font-family: "Computer Modern"; - src: url('../font/cmunrb.otf'); - font-weight: bold; -} -@font-face { - font-family: "Computer Modern Monospace"; - src: url('../font/cmuntt.otf'); - font-weight: bold; -} - - -.CodeMirror { - .CodeMirror-placeholder { - color: #999; - } - height: auto; - background: none; - .editor-font; - - .cm-command, .cm-bracket { - color: green; - } - .cm-math { - color: purple; - font-family: "Computer Modern Monospace", monospace; - } - - .CodeMirror-lines { - padding: 10px; - } - .oe-chapter { - font-weight: bold; - font-size: 1.8em !important; - line-height: 2em !important; - } - .oe-section { - font-weight: bold; - font-size: 1.5em !important; - line-height: 2em !important; - } - .oe-subsection { - font-weight: bold; - font-size: 1.3em !important; - line-height: 2em !important; - } - .oe-widget-line { - display: none; - } - .oe-figure { - margin: 0 5px; - padding: 12px 0 4px 0; - text-align: center; - position: relative; - .ui-wrapper { - position: relative; - display: inline-block; - } - .oe-figure-image-wrapper { - display: inline-block; - } - .oe-figure-image-placeholder { - background-color: rgb(200,200,200); - } - .oe-figure-image-placeholder.droppable-hover { - background-color: rgb(200,200,255); - } - .oe-figure-toolbar { - display: none; - text-align: right; - padding: 4px; - position: absolute; - top: 0; - left: 0; - right: 0; - } - } - - .oe-title { - .CodeMirror-lines { - padding: 0; - } - .oe-title-title { - text-align: center; - margin-top: 40px; - margin-bottom: 20px; - .CodeMirror { - font-size: 1.6em; - line-height: 1.3em; - } - } - - .oe-title-author { - text-align: center; - margin-bottom: 10px; - .CodeMirror { - font-size: 1.2em; - line-height: 1.3em; - } - } - - .oe-title-abstract { - margin-top: 40px; - margin-bottom: 30px; - .oe-title-abstract-label { - text-align: center; - font-weight: bold; - margin-bottom: 6px; - font-size: 0.9em; - line-height: 1.3em; - } - - .oe-title-abstract-content { - width: 80%; - margin: auto; - .CodeMirror { - font-size: 0.9em; - line-height: 1.3em; - - } - } - } - } - - - .oe-widget { - border: 1px solid transparent; - margin: 6px 0; - } - .oe-widget-selected { - border: 1px dashed #bbb; - .oe-figure-toolbar { - display: block; - } - .ui-wrapper { - border: 1px dashed gray; - } - } - - .oe-block-math { - .MathJax_Display { - margin: 12px 0; - } - - .oe-block-math-toolbar { - text-align: right; - padding: 4px; - z-index: 100; - .bootstrap-select.btn-group { - margin: 0; - } - } - .CodeMirror { - font-family: "Computer Modern Monospace", monospace; - text-align: center; - } - } - .oe-non-editable { - color: gray; - cursor: default; - } - - .oe-bibliography { - padding: 4px; - cursor: pointer; - } -} - - -// These are needed by the citation drop down too, so -// don't wrap them in .oe-bibliography -.oe-bibliography-entry { - display: inline-block; -} - -.oe-bibliography-year { - font-weight: bold; -} -.oe-bibliography-author { - font-weight: bold; -} -.oe-bibliography-title { - display: block; - margin-left: 10px; -} - -.oe-bibliography { - .oe-bibliography-header { - font-weight: bold; - font-size: 1.8em !important; - line-height: 2em !important; - } - - .oe-bibliography-entry-wrapper { - margin-top: 6px; - } - - .CodeMirror { - font-family: "Computer Modern Monospace", monospace; - color: green; - height: 400px; - } - - .oe-bibliography-no-entries { - font-style: italic; - } - - .oe-bibliography-error { - color: red; - } -} - - -.bootstrap-select.oe-inline-select { - margin: 0; - vertical-align: bottom; - > .btn { - border: none; - background: none; - box-shadow: none; - padding: 0; - margin: 0; - .editor-font; - color: rgb(2, 151, 172); - } -} From bf21305c68e847e2de6ccf89b1830e1a49bba757 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 5 Mar 2014 17:55:47 +0000 Subject: [PATCH 03/10] Add in basic list of changes in track changes view --- services/web/app/views/templates.jade | 22 +++- .../web/public/coffee/editor/Editor.coffee | 6 ++ services/web/public/coffee/ide.coffee | 5 +- .../track-changes/ChangeListView.coffee | 101 ++++++++++++++++++ .../track-changes/TrackChangesManager.coffee | 35 ++++++ .../coffee/track-changes/models/Change.coffee | 10 ++ .../track-changes/models/ChangeList.coffee | 26 +++++ .../web/public/stylesheets/less/editor.less | 4 + .../public/stylesheets/less/trackchanges.less | 30 ++++++ .../web/public/stylesheets/mainStyle.less | 1 + 10 files changed, 234 insertions(+), 6 deletions(-) create mode 100644 services/web/public/coffee/track-changes/ChangeListView.coffee create mode 100644 services/web/public/coffee/track-changes/TrackChangesManager.coffee create mode 100644 services/web/public/coffee/track-changes/models/Change.coffee create mode 100644 services/web/public/coffee/track-changes/models/ChangeList.coffee create mode 100644 services/web/public/stylesheets/less/trackchanges.less diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index c9e6c0a8cb..e692d86b42 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -404,11 +404,6 @@ div(class='version-message') {{message}} div(class='version-date') {{date}} - script(type='text/template')#autoCompleteSuggestionTemplate - li - strong {{base}} - | {{completion}} - script(type='text/template')#versionListTemplate ul#version-list.nav.nav-pills.nav-stacked li.loading Loading... @@ -428,6 +423,23 @@ div a(href="#", title='Show Hot Keys List') Hot keys + script(type='text/template')#trackChangesPanelTemplate + #trackChangesPanel + .track-changes-side-bar + .change-list-area + .track-changes-diff + + script(type='text/template')#changeListItemTemplate + a(href="#") + div(class='change-message') {{user_id}} + div(class='change-date') {{end_ts}} + div(class='change-date') {{start_ts}} + + script(type='text/template')#changeListTemplate + ul.change-list.nav.nav-pills.nav-stacked + li.loading-changes Loading... + li.empty-message You haven't made any changes yet! + script(type='text/template')#hotKeysListTemplate .hotkeys h3 Common diff --git a/services/web/public/coffee/editor/Editor.coffee b/services/web/public/coffee/editor/Editor.coffee index d0894ddc8f..7c86598ad6 100644 --- a/services/web/public/coffee/editor/Editor.coffee +++ b/services/web/public/coffee/editor/Editor.coffee @@ -352,3 +352,9 @@ define [ getCurrentDocId: () -> @current_doc_id + show: () -> + $("#editor").show() + + hide: () -> + $("#editor").hide() + diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index d15252d32c..5db490d2f3 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -25,6 +25,7 @@ define [ "file-view/FileViewManager" "tour/IdeTour" "analytics/AnalyticsManager" + "track-changes/TrackChangesManager" "ace/ace" "libs/jquery.color" "libs/jquery-layout" @@ -56,7 +57,8 @@ define [ BackspaceHighjack, FileViewManager, IdeTour, - AnalyticsManager + AnalyticsManager, + TrackChangesManager ) -> @@ -117,6 +119,7 @@ define [ @cursorManager = new CursorManager(@) @fileViewManager = new FileViewManager(@) @analyticsManager = new AnalyticsManager(@) + @trackChangesManager = new TrackChangesManager(@) @setLoadingMessage("Connecting") firstConnect = true diff --git a/services/web/public/coffee/track-changes/ChangeListView.coffee b/services/web/public/coffee/track-changes/ChangeListView.coffee new file mode 100644 index 0000000000..579d4cf13c --- /dev/null +++ b/services/web/public/coffee/track-changes/ChangeListView.coffee @@ -0,0 +1,101 @@ +define [ + "history/util" + "libs/mustache" + "libs/backbone" +], (util)-> + ChangeListView = Backbone.View.extend + template: $("#changeListTemplate").html() + + events: + "scroll" : "loadUntilFull" + + initialize: -> + @itemViews = [] + @atEndOfCollection = false + + self = this + @collection.on "add", (model) -> + self.addItem model + @collection.on "reset", (collection) -> + self.addItem model for model in collection.models + + @render() + @hideLoading() + + render: -> + @$el.html Mustache.to_html @template + @$el.css + overflow: "scroll" + this + + addItem: (model) -> + view = new ChangeListItemView(model : model) + @itemViews.push view + index = @collection.indexOf(model) + elementAtIndex = @$(".change-list").children()[index] + view.$el.insertBefore(elementAtIndex) + + listShorterThanContainer: -> + @$el.height() > @$(".change-list").height() + + atEndOfListView: -> + @$el.scrollTop() + @$el.height() >= @$(".change-list").height() - 30 + + loadUntilFull: (e, callback) -> + if (@listShorterThanContainer() or @atEndOfListView()) and not @atEndOfCollection and not @loading + @showLoading() + @hideEmptyMessage() + @collection.fetchNextBatch + error: => + @hideLoading() + @showEmptyMessageIfCollectionEmpty() + callback() if callback? + success: (collection, response) => + @hideLoading() + if response.updates.length == @collection.batchSize + @loadUntilFull(e, callback) + else + @atEndOfCollection = true + @showEmptyMessageIfCollectionEmpty() + callback() if callback? + + else + callback() if callback? + + showEmptyMessageIfCollectionEmpty: ()-> + if @collection.isEmpty() + @$(".empty-message").show() + else + @$(".empty-message").hide() + + hideEmptyMessage: () -> + @$(".empty-message").hide() + + showLoading: -> + @loading = true + @$(".loading-changes").show() + + hideLoading: -> + @loading = false + @$(".loading-changes").hide() + + ChangeListItemView = Backbone.View.extend + tagName: "li" + + template : $("#changeListItemTemplate").html() + + initialize: -> + @render() + + render: -> + @$el.html Mustache.to_html(@template, @modelView()) + return this + + modelView: -> + modelView = @model.toJSON() + # modelView.start_ts = util.formatDate(modelView.start_ts) + # modelView.end_ts = util.formatDate(modelView.end_ts) + return modelView + + return ChangeListView + diff --git a/services/web/public/coffee/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/track-changes/TrackChangesManager.coffee new file mode 100644 index 0000000000..15d44e299b --- /dev/null +++ b/services/web/public/coffee/track-changes/TrackChangesManager.coffee @@ -0,0 +1,35 @@ +define [ + "track-changes/models/ChangeList" + "track-changes/ChangeListView" +], (ChangeList, ChangeListView) -> + class TrackChangesManager + template: $("#trackChangesPanelTemplate").html() + + constructor: (@ide) -> + @$el = $(@template) + $("#editorWrapper").append(@$el) + @hideEl() + + show: () -> + project_id = window.userSettings.project_id + doc_id = @ide.editor.current_doc_id + @changes = new ChangeList([], doc_id: doc_id, project_id: project_id) + + @changeListView = new ChangeListView( + collection : @changes, + el : @$el.find(".change-list-area") + ) + @changeListView.render() + @changeListView.loadUntilFull() + + @showEl() + + showEl: -> + @ide.editor.hide() + @$el.show() + + hideEl: () -> + @ide.editor.show() + @$el.hide() + + return TrackChangesManager diff --git a/services/web/public/coffee/track-changes/models/Change.coffee b/services/web/public/coffee/track-changes/models/Change.coffee new file mode 100644 index 0000000000..749e8def82 --- /dev/null +++ b/services/web/public/coffee/track-changes/models/Change.coffee @@ -0,0 +1,10 @@ +define [ + "libs/backbone" +], ()-> + Change = Backbone.Model.extend + parse: (change) -> + return { + start_ts: change.meta.start_ts + end_ts: change.meta.end_ts + user_id: change.meta.user_id + } \ No newline at end of file diff --git a/services/web/public/coffee/track-changes/models/ChangeList.coffee b/services/web/public/coffee/track-changes/models/ChangeList.coffee new file mode 100644 index 0000000000..da392d24d8 --- /dev/null +++ b/services/web/public/coffee/track-changes/models/ChangeList.coffee @@ -0,0 +1,26 @@ +define [ + "track-changes/models/Change" + "libs/backbone" +], (Change)-> + ChangeList = Backbone.Collection.extend + model: Change + batchSize: 3 + + initialize: (models, @options) -> + console.log arguments + + url: () -> + url = "/project/#{@options.project_id}/doc/#{@options.doc_id}/updates?limit=#{@batchSize}" + if @models.length > 0 + last = @models[@models.length - 1] + url += "&to=#{last.get("start_ts") - 1}" + return url + + parse: (json) -> + return json.updates + + fetchNextBatch: (options = {}) -> + options.add = true + @fetch options + + diff --git a/services/web/public/stylesheets/less/editor.less b/services/web/public/stylesheets/less/editor.less index 7d3fedda03..c1b93552aa 100644 --- a/services/web/public/stylesheets/less/editor.less +++ b/services/web/public/stylesheets/less/editor.less @@ -200,6 +200,10 @@ body.editor { bottom: 0; z-index: 100; } + #trackChangesPanel { + width: 100%; + height: 100%; + } } #undoConflictWarning { diff --git a/services/web/public/stylesheets/less/trackchanges.less b/services/web/public/stylesheets/less/trackchanges.less new file mode 100644 index 0000000000..94250847e0 --- /dev/null +++ b/services/web/public/stylesheets/less/trackchanges.less @@ -0,0 +1,30 @@ +@changesListWidth: 200px; +@versionsListPadding: 10px; + +#trackChangesPanel { + .track-changes-diff { + position: absolute; + right: @versionsListWidth + 1px; + right: 0; + padding: 0px 12px; + overflow: scroll; + height: 100%; + } + + .track-changes-side-bar { + border-left: 1px solid #999; + height: 100%; + width: @versionsListWidth; + position: absolute; + right: 0; + } + + .change-list-area { + overflow: scroll; + position: absolute; + left: 0px; + right: 0px; + top: 0px; + bottom: 0px; + } +} \ No newline at end of file diff --git a/services/web/public/stylesheets/mainStyle.less b/services/web/public/stylesheets/mainStyle.less index 3a3f3f7115..b3578e7134 100644 --- a/services/web/public/stylesheets/mainStyle.less +++ b/services/web/public/stylesheets/mainStyle.less @@ -49,6 +49,7 @@ @import "public/stylesheets/less/navbar.less"; @import "public/stylesheets/less/footer.less"; @import "public/stylesheets/less/list.less"; +@import "public/stylesheets/less/trackchanges.less"; @import "public/stylesheets/less/fileuploader.less"; From 1a91036bb66405d1f397727a0174846c7b677ef4 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 6 Mar 2014 14:08:12 +0000 Subject: [PATCH 04/10] Show nice diffs using ace and markers --- .../track-changes/ChangeListView.coffee | 12 +- .../coffee/track-changes/DiffView.coffee | 139 ++++++++++++++++++ .../track-changes/TrackChangesManager.coffee | 23 ++- .../coffee/track-changes/models/Change.coffee | 1 + .../track-changes/models/ChangeList.coffee | 3 +- .../coffee/track-changes/models/Diff.coffee | 6 + .../public/stylesheets/less/trackchanges.less | 27 +++- 7 files changed, 201 insertions(+), 10 deletions(-) create mode 100644 services/web/public/coffee/track-changes/DiffView.coffee create mode 100644 services/web/public/coffee/track-changes/models/Diff.coffee diff --git a/services/web/public/coffee/track-changes/ChangeListView.coffee b/services/web/public/coffee/track-changes/ChangeListView.coffee index 579d4cf13c..4565fcd5d7 100644 --- a/services/web/public/coffee/track-changes/ChangeListView.coffee +++ b/services/web/public/coffee/track-changes/ChangeListView.coffee @@ -1,5 +1,4 @@ define [ - "history/util" "libs/mustache" "libs/backbone" ], (util)-> @@ -9,7 +8,7 @@ define [ events: "scroll" : "loadUntilFull" - initialize: -> + initialize: () -> @itemViews = [] @atEndOfCollection = false @@ -34,6 +33,8 @@ define [ index = @collection.indexOf(model) elementAtIndex = @$(".change-list").children()[index] view.$el.insertBefore(elementAtIndex) + view.on "click", (e, v) => + @trigger "change_diff", v.model.get("version") listShorterThanContainer: -> @$el.height() > @$(".change-list").height() @@ -81,6 +82,9 @@ define [ ChangeListItemView = Backbone.View.extend tagName: "li" + + events: + "click a": "onClick" template : $("#changeListItemTemplate").html() @@ -97,5 +101,9 @@ define [ # modelView.end_ts = util.formatDate(modelView.end_ts) return modelView + onClick: (e) -> + e.preventDefault() + @trigger "click", e, @ + return ChangeListView diff --git a/services/web/public/coffee/track-changes/DiffView.coffee b/services/web/public/coffee/track-changes/DiffView.coffee new file mode 100644 index 0000000000..70e6046507 --- /dev/null +++ b/services/web/public/coffee/track-changes/DiffView.coffee @@ -0,0 +1,139 @@ +define [ + "ace/ace" + "ace/mode/latex" + "ace/range" + "libs/backbone" +], (Ace, LatexMode, Range)-> + DiffView = Backbone.View.extend + initialize: () -> + @model.on "change:diff", () => @render() + @render() + + render: -> + diff = @model.get("diff") + return unless diff? + @createAceEditor() + @aceEditor.setValue(@getPlainDiffContent()) + @aceEditor.clearSelection() + session = @aceEditor.getSession() + session.setMode(new LatexMode.Mode()) + session.setUseWrapMode(true) + @insertMarkers() + return @ + + createAceEditor: () -> + @$el.empty() + $editor = $("
") + @$el.append($editor) + @aceEditor = Ace.edit($editor[0]) + @aceEditor.setTheme("ace/theme/#{window.userSettings.theme}") + @aceEditor.setReadOnly true + @aceEditor.setShowPrintMargin(false) + + @aceEditor.on "mousemove", (e) => + position = @aceEditor.renderer.screenToTextCoordinates(e.clientX, e.clientY) + e.position = position + @updateVisibleNames(e) + + getPlainDiffContent: () -> + content = "" + for entry in @model.get("diff") or [] + content += entry.u or entry.i or entry.d or "" + return content + + insertMarkers: () -> + row = 0 + column = 0 + for entry, i in @model.get("diff") or [] + content = entry.u or entry.i or entry.d + lines = content.split("\n") + startRow = row + startColumn = column + if lines.length > 1 + endRow = startRow + lines.length - 1 + endColumn = lines[lines.length - 1].length + else + endRow = startRow + endColumn = startColumn + lines[0].length + row = endRow + column = endColumn + + range = new Range.Range( + startRow, startColumn, endRow, endColumn + ) + @addMarker(range, "change-marker-#{i}", entry) + + addMarker: (range, id, entry) -> + session = @aceEditor.getSession() + markerBackLayer = @aceEditor.renderer.$markerBack + markerFrontLayer = @aceEditor.renderer.$markerFront + lineHeight = @aceEditor.renderer.lineHeight + if entry.i? or entry.d? + hue = 200 + if entry.i? + @_addMarkerWithCustomStyle session, markerBackLayer, range, "deleted-change-background", false, """ + background-color : hsl(#{hue}, 70%, 85%); + """ + tag = "Added by #{entry.meta.user_id}" + if entry.d? + @_addMarkerWithCustomStyle session, markerBackLayer, range, "deleted-change-background", false, """ + background-color : hsl(#{hue}, 70%, 95%); + """ + @_addMarkerWithCustomStyle session, markerBackLayer, range, "deleted-change-foreground", true, """ + height: #{Math.round(lineHeight/2) - 1}px; + border-bottom: 2px solid hsl(#{hue}, 70%, 40%); + """ + tag = "Deleted by #{entry.meta.user_id}" + + tag += " on #{entry.meta.end_ts}" + @_addNameTag session, id, range, tag, """ + background-color : hsl(#{hue}, 70%, 85%); + """ + + _addMarkerWithCustomStyle: (session, markerLayer, range, klass, foreground, style) -> + session.addMarker range, klass, (html, range, left, top, config) -> + if range.isMultiLine() + markerLayer.drawTextMarker(html, range, klass, config, style) + else + markerLayer.drawSingleLineMarker(html, range, "#{klass} ace_start", config, 0, style) + , foreground + + _addNameTag: (session, id, range, content, style) -> + @nameMarkers ||= [] + @nameMarkers.push + range: range + id: id + startRange = new Range.Range( + range.start.row, range.start.column + range.start.row, session.getScreenLastRowColumn(range.start.row) + ) + session.addMarker startRange, "change-name-marker", (html, range, left, top, config) -> + html.push """ +
+
#{content}
+
+ """ + , true + + updateVisibleNames: (e) -> + for marker in @nameMarkers or [] + if marker.range.contains(e.position.row, e.position.column) + $("##{marker.id}").find(".name").show() + else + $("##{marker.id}").find(".name").hide() + + return DiffView + diff --git a/services/web/public/coffee/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/track-changes/TrackChangesManager.coffee index 15d44e299b..a7588169b5 100644 --- a/services/web/public/coffee/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/track-changes/TrackChangesManager.coffee @@ -1,7 +1,9 @@ define [ "track-changes/models/ChangeList" + "track-changes/models/Diff" "track-changes/ChangeListView" -], (ChangeList, ChangeListView) -> + "track-changes/DiffView" +], (ChangeList, Diff, ChangeListView, DiffView) -> class TrackChangesManager template: $("#trackChangesPanelTemplate").html() @@ -11,9 +13,9 @@ define [ @hideEl() show: () -> - project_id = window.userSettings.project_id - doc_id = @ide.editor.current_doc_id - @changes = new ChangeList([], doc_id: doc_id, project_id: project_id) + @project_id = window.userSettings.project_id + @doc_id = @ide.editor.current_doc_id + @changes = new ChangeList([], doc_id: @doc_id, project_id: @project_id) @changeListView = new ChangeListView( collection : @changes, @@ -22,6 +24,19 @@ define [ @changeListView.render() @changeListView.loadUntilFull() + @changeListView.on "change_diff", (version) => + @diff = new Diff({ + project_id: @project_id + doc_id: @doc_id + from: version + to: version + }) + @diffView = new DiffView( + model: @diff + el: @$el.find(".track-changes-diff") + ) + @diff.fetch() + @showEl() showEl: -> diff --git a/services/web/public/coffee/track-changes/models/Change.coffee b/services/web/public/coffee/track-changes/models/Change.coffee index 749e8def82..4c1187dd5b 100644 --- a/services/web/public/coffee/track-changes/models/Change.coffee +++ b/services/web/public/coffee/track-changes/models/Change.coffee @@ -7,4 +7,5 @@ define [ start_ts: change.meta.start_ts end_ts: change.meta.end_ts user_id: change.meta.user_id + version: change.v } \ No newline at end of file diff --git a/services/web/public/coffee/track-changes/models/ChangeList.coffee b/services/web/public/coffee/track-changes/models/ChangeList.coffee index da392d24d8..92e9af8ee7 100644 --- a/services/web/public/coffee/track-changes/models/ChangeList.coffee +++ b/services/web/public/coffee/track-changes/models/ChangeList.coffee @@ -7,13 +7,12 @@ define [ batchSize: 3 initialize: (models, @options) -> - console.log arguments url: () -> url = "/project/#{@options.project_id}/doc/#{@options.doc_id}/updates?limit=#{@batchSize}" if @models.length > 0 last = @models[@models.length - 1] - url += "&to=#{last.get("start_ts") - 1}" + url += "&to=#{last.get("version") - 1}" return url parse: (json) -> diff --git a/services/web/public/coffee/track-changes/models/Diff.coffee b/services/web/public/coffee/track-changes/models/Diff.coffee new file mode 100644 index 0000000000..13f3b79c10 --- /dev/null +++ b/services/web/public/coffee/track-changes/models/Diff.coffee @@ -0,0 +1,6 @@ +define [ + "libs/backbone" +], ()-> + Diff = Backbone.Model.extend + url: () -> + "/project/#{@get("project_id")}/doc/#{@get("doc_id")}/diff?from=#{@get("from")}&to=#{@get("to")}" diff --git a/services/web/public/stylesheets/less/trackchanges.less b/services/web/public/stylesheets/less/trackchanges.less index 94250847e0..2423530631 100644 --- a/services/web/public/stylesheets/less/trackchanges.less +++ b/services/web/public/stylesheets/less/trackchanges.less @@ -5,10 +5,18 @@ .track-changes-diff { position: absolute; right: @versionsListWidth + 1px; - right: 0; + left: 0; + top: 0; + bottom: 0; padding: 0px 12px; - overflow: scroll; height: 100%; + .ace_editor { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + } } .track-changes-side-bar { @@ -27,4 +35,19 @@ top: 0px; bottom: 0px; } + + .deleted-change-background, .deleted-change-foreground, .inserted-change, .change-name-marker { + position: absolute; + z-index: 2; + } + + .change-name-marker { + .name { + font-size: 0.8em; + padding: 2px 6px; + .border-radius(3px 3px 3px 3px); + position: absolute; + left: 0; + } + } } \ No newline at end of file From 9329213d9418d841630212ea8ae563dd59f57bc5 Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 6 Mar 2014 16:32:18 +0000 Subject: [PATCH 05/10] Allow multiple diffs to be selected --- services/web/app/views/templates.jade | 6 +- .../track-changes/ChangeListView.coffee | 90 ++++++++++++++++++- .../track-changes/TrackChangesManager.coffee | 6 +- .../public/stylesheets/less/trackchanges.less | 36 +++++++- 4 files changed, 127 insertions(+), 11 deletions(-) diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index e692d86b42..ee2a4ab165 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -430,7 +430,11 @@ .track-changes-diff script(type='text/template')#changeListItemTemplate - a(href="#") + div(class='change-selectors') + input(type="radio",name="fromVersion").change-selector-from + input(type="radio",name="toVersion").change-selector-to + + div(class='change-description') div(class='change-message') {{user_id}} div(class='change-date') {{end_ts}} div(class='change-date') {{start_ts}} diff --git a/services/web/public/coffee/track-changes/ChangeListView.coffee b/services/web/public/coffee/track-changes/ChangeListView.coffee index 4565fcd5d7..b4a9e1ca13 100644 --- a/services/web/public/coffee/track-changes/ChangeListView.coffee +++ b/services/web/public/coffee/track-changes/ChangeListView.coffee @@ -18,6 +18,9 @@ define [ @collection.on "reset", (collection) -> self.addItem model for model in collection.models + @selectedFromIndex = 0 + @selectedToIndex = 0 + @render() @hideLoading() @@ -28,13 +31,36 @@ define [ this addItem: (model) -> + index = @collection.indexOf(model) view = new ChangeListItemView(model : model) @itemViews.push view - index = @collection.indexOf(model) elementAtIndex = @$(".change-list").children()[index] view.$el.insertBefore(elementAtIndex) + view.on "click", (e, v) => - @trigger "change_diff", v.model.get("version") + @selectedToIndex = index + @selectedFromIndex = index + @resetAllSelectors() + @triggerChangeDiff() + + view.on "selected:to", (e, v) => + @selectedToIndex = index + @resetAllSelectors() + @triggerChangeDiff() + + view.on "selected:from", (e, v) => + @selectedFromIndex = index + @resetAllSelectors() + @triggerChangeDiff() + + view.resetSelector(index, @selectedFromIndex, @selectedToIndex) + + resetAllSelectors: () -> + for view, i in @itemViews + view.resetSelector(i, @selectedFromIndex, @selectedToIndex) + + triggerChangeDiff: () -> + @trigger "change_diff", @collection.models[@selectedFromIndex], @collection.models[@selectedToIndex] listShorterThanContainer: -> @$el.height() > @$(".change-list").height() @@ -84,7 +110,9 @@ define [ tagName: "li" events: - "click a": "onClick" + "click .change-description" : "onClick" + "click .change-selector-from" : "onFromSelectorClick" + "click .change-selector-to" : "onToSelectorClick" template : $("#changeListItemTemplate").html() @@ -105,5 +133,61 @@ define [ e.preventDefault() @trigger "click", e, @ + onToSelectorClick: (e) -> + @trigger "selected:to", e, @ + + onFromSelectorClick: (e) -> + @trigger "selected:from", e, @ + + isSelectedFrom: () -> + @$(".change-selector-from").is(":checked") + + isSelectedTo: () -> + @$(".change-selector-to").is(":checked") + + hideFromSelector: () -> + @$(".change-selector-from").hide() + + showFromSelector: () -> + @$(".change-selector-from").show() + + hideToSelector: () -> + @$(".change-selector-to").hide() + + showToSelector: () -> + @$(".change-selector-to").show() + + setFromChecked: (checked) -> + @$(".change-selector-from").prop("checked", checked) + + setToChecked: (checked) -> + @$(".change-selector-to").prop("checked", checked) + + setSelected: () -> + @$el.addClass("selected") + + setUnselected: () -> + @$el.removeClass("selected") + + resetSelector: (myIndex, selectedFromIndex, selectedToIndex) -> + if myIndex >= selectedToIndex + @showFromSelector() + else + @hideFromSelector() + + if myIndex <= selectedFromIndex + @showToSelector() + else + @hideToSelector() + + if selectedToIndex <= myIndex <= selectedFromIndex + @setSelected() + else + @setUnselected() + + @setFromChecked(myIndex == selectedFromIndex) + @setToChecked(myIndex == selectedToIndex) + + return ChangeListView diff --git a/services/web/public/coffee/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/track-changes/TrackChangesManager.coffee index a7588169b5..a385f56fed 100644 --- a/services/web/public/coffee/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/track-changes/TrackChangesManager.coffee @@ -24,12 +24,12 @@ define [ @changeListView.render() @changeListView.loadUntilFull() - @changeListView.on "change_diff", (version) => + @changeListView.on "change_diff", (fromModel, toModel) => @diff = new Diff({ project_id: @project_id doc_id: @doc_id - from: version - to: version + from: fromModel.get("version") + to: toModel.get("version") }) @diffView = new DiffView( model: @diff diff --git a/services/web/public/stylesheets/less/trackchanges.less b/services/web/public/stylesheets/less/trackchanges.less index 2423530631..77c4169798 100644 --- a/services/web/public/stylesheets/less/trackchanges.less +++ b/services/web/public/stylesheets/less/trackchanges.less @@ -1,10 +1,10 @@ -@changesListWidth: 200px; -@versionsListPadding: 10px; +@changesListWidth: 250px; +@changesListPadding: 10px; #trackChangesPanel { .track-changes-diff { position: absolute; - right: @versionsListWidth + 1px; + right: @changesListWidth + 1px; left: 0; top: 0; bottom: 0; @@ -22,7 +22,7 @@ .track-changes-side-bar { border-left: 1px solid #999; height: 100%; - width: @versionsListWidth; + width: @changesListWidth; position: absolute; right: 0; } @@ -50,4 +50,32 @@ left: 0; } } + + ul.change-list { + li { + padding: 4px; + position: relative; + .change-selectors { + position: absolute; + top: 4px; + left: 4px; + .change-selector-from { + position: absolute; + top: 0; + left: 0; + } + .change-selector-to { + position: absolute; + top: 0; + left: 20px; + } + } + .change-description { + padding-left: 40px; + } + } + li.selected { + background-color: rgb(190, 226, 244); + } + } } \ No newline at end of file From be8035faa84edba576e046426354f59e30b04aff Mon Sep 17 00:00:00 2001 From: James Allen Date: Thu, 6 Mar 2014 18:13:07 +0000 Subject: [PATCH 06/10] Include names in view --- services/web/app/views/templates.jade | 2 +- services/web/public/coffee/track-changes/DiffView.coffee | 4 ++-- services/web/public/coffee/track-changes/models/Change.coffee | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index ee2a4ab165..07be07dc1f 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -435,7 +435,7 @@ input(type="radio",name="toVersion").change-selector-to div(class='change-description') - div(class='change-message') {{user_id}} + div(class='change-message') {{user.first_name}} {{user.last_name}} div(class='change-date') {{end_ts}} div(class='change-date') {{start_ts}} diff --git a/services/web/public/coffee/track-changes/DiffView.coffee b/services/web/public/coffee/track-changes/DiffView.coffee index 70e6046507..4c67dde80f 100644 --- a/services/web/public/coffee/track-changes/DiffView.coffee +++ b/services/web/public/coffee/track-changes/DiffView.coffee @@ -74,7 +74,7 @@ define [ @_addMarkerWithCustomStyle session, markerBackLayer, range, "deleted-change-background", false, """ background-color : hsl(#{hue}, 70%, 85%); """ - tag = "Added by #{entry.meta.user_id}" + tag = "Added by #{entry.meta.user.email}" if entry.d? @_addMarkerWithCustomStyle session, markerBackLayer, range, "deleted-change-background", false, """ background-color : hsl(#{hue}, 70%, 95%); @@ -83,7 +83,7 @@ define [ height: #{Math.round(lineHeight/2) - 1}px; border-bottom: 2px solid hsl(#{hue}, 70%, 40%); """ - tag = "Deleted by #{entry.meta.user_id}" + tag = "Deleted by #{entry.meta.user.email}" tag += " on #{entry.meta.end_ts}" @_addNameTag session, id, range, tag, """ diff --git a/services/web/public/coffee/track-changes/models/Change.coffee b/services/web/public/coffee/track-changes/models/Change.coffee index 4c1187dd5b..a5ea9a546b 100644 --- a/services/web/public/coffee/track-changes/models/Change.coffee +++ b/services/web/public/coffee/track-changes/models/Change.coffee @@ -6,6 +6,6 @@ define [ return { start_ts: change.meta.start_ts end_ts: change.meta.end_ts - user_id: change.meta.user_id + user: change.meta.user version: change.v } \ No newline at end of file From 36faedeeb374758dade9147661e57bb38f344b9a Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 7 Mar 2014 11:24:11 +0000 Subject: [PATCH 07/10] Make the history entries pretty --- services/web/Gruntfile.coffee | 1 + services/web/app/views/project/editor.jade | 3 +- services/web/app/views/templates.jade | 5 +- services/web/public/coffee/models/User.coffee | 8 +- .../track-changes/ChangeListView.coffee | 8 +- .../coffee/track-changes/models/Change.coffee | 5 +- services/web/public/js/libs/md5.js | 19 + services/web/public/js/libs/moment.js | 1668 +---------------- .../public/stylesheets/less/trackchanges.less | 18 +- 9 files changed, 60 insertions(+), 1675 deletions(-) create mode 100644 services/web/public/js/libs/md5.js diff --git a/services/web/Gruntfile.coffee b/services/web/Gruntfile.coffee index 41d5ed8161..e66a0217ce 100644 --- a/services/web/Gruntfile.coffee +++ b/services/web/Gruntfile.coffee @@ -84,6 +84,7 @@ module.exports = (grunt) -> paths: "underscore": "libs/underscore" "jquery": "libs/jquery" + "moment": "libs/moment" shim: "libs/backbone": deps: ["libs/underscore"] diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index 90f27c2349..81c7fbc148 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -38,7 +38,8 @@ block content window.requirejs = { "paths" : { "underscore": "libs/underscore", - "mathjax": "https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" + "mathjax": "https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML", + "moment": "libs/moment" }, "urlArgs" : "fingerprint=#{fingerprint(jsPath + 'ide.js')}", "waitSeconds": 0, diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index 07be07dc1f..980872b1a0 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -435,9 +435,8 @@ input(type="radio",name="toVersion").change-selector-to div(class='change-description') - div(class='change-message') {{user.first_name}} {{user.last_name}} - div(class='change-date') {{end_ts}} - div(class='change-date') {{start_ts}} + div(class='change-date') {{date}} + div(class='change-name') {{name}} script(type='text/template')#changeListTemplate ul.change-list.nav.nav-pills.nav-stacked diff --git a/services/web/public/coffee/models/User.coffee b/services/web/public/coffee/models/User.coffee index 3443d2eb3a..5c90b81d34 100644 --- a/services/web/public/coffee/models/User.coffee +++ b/services/web/public/coffee/models/User.coffee @@ -1,7 +1,13 @@ define [ + "libs/md5" "libs/backbone" ], () -> - User = Backbone.Model.extend {}, { + User = Backbone.Model.extend { + gravatarUrl: (size = 32) -> + email = @get("email").trim().toLowerCase() + hash = CryptoJS.MD5(email) + return "//www.gravatar.com/avatar/#{hash}.jpg?size=#{size}&d=mm" + }, { findOrBuild : (id, attributes) -> model = @find id if !model? diff --git a/services/web/public/coffee/track-changes/ChangeListView.coffee b/services/web/public/coffee/track-changes/ChangeListView.coffee index b4a9e1ca13..296a6d0628 100644 --- a/services/web/public/coffee/track-changes/ChangeListView.coffee +++ b/services/web/public/coffee/track-changes/ChangeListView.coffee @@ -1,7 +1,8 @@ define [ + "moment" "libs/mustache" "libs/backbone" -], (util)-> +], (moment)-> ChangeListView = Backbone.View.extend template: $("#changeListTemplate").html() @@ -124,7 +125,10 @@ define [ return this modelView: -> - modelView = @model.toJSON() + modelView = { + date: moment(parseInt(@model.get("end_ts"), 10)).calendar() + name: @model.get("user").get("first_name") + " " + @model.get("user").get("last_name") + } # modelView.start_ts = util.formatDate(modelView.start_ts) # modelView.end_ts = util.formatDate(modelView.end_ts) return modelView diff --git a/services/web/public/coffee/track-changes/models/Change.coffee b/services/web/public/coffee/track-changes/models/Change.coffee index a5ea9a546b..fcefb43661 100644 --- a/services/web/public/coffee/track-changes/models/Change.coffee +++ b/services/web/public/coffee/track-changes/models/Change.coffee @@ -1,11 +1,12 @@ define [ + "models/User" "libs/backbone" -], ()-> +], (User)-> Change = Backbone.Model.extend parse: (change) -> return { start_ts: change.meta.start_ts end_ts: change.meta.end_ts - user: change.meta.user + user: User.findOrBuild(change.meta.user.id, change.meta.user) version: change.v } \ No newline at end of file diff --git a/services/web/public/js/libs/md5.js b/services/web/public/js/libs/md5.js new file mode 100644 index 0000000000..0fae5ca1d7 --- /dev/null +++ b/services/web/public/js/libs/md5.js @@ -0,0 +1,19 @@ +/* +CryptoJS v3.1.2 +code.google.com/p/crypto-js +(c) 2009-2013 by Jeff Mott. All rights reserved. +code.google.com/p/crypto-js/wiki/License +*/ +var CryptoJS=CryptoJS||function(s,p){var m={},l=m.lib={},n=function(){},r=l.Base={extend:function(b){n.prototype=this;var h=new n;b&&h.mixIn(b);h.hasOwnProperty("init")||(h.init=function(){h.$super.init.apply(this,arguments)});h.init.prototype=h;h.$super=this;return h},create:function(){var b=this.extend();b.init.apply(b,arguments);return b},init:function(){},mixIn:function(b){for(var h in b)b.hasOwnProperty(h)&&(this[h]=b[h]);b.hasOwnProperty("toString")&&(this.toString=b.toString)},clone:function(){return this.init.prototype.extend(this)}}, +q=l.WordArray=r.extend({init:function(b,h){b=this.words=b||[];this.sigBytes=h!=p?h:4*b.length},toString:function(b){return(b||t).stringify(this)},concat:function(b){var h=this.words,a=b.words,j=this.sigBytes;b=b.sigBytes;this.clamp();if(j%4)for(var g=0;g>>2]|=(a[g>>>2]>>>24-8*(g%4)&255)<<24-8*((j+g)%4);else if(65535>>2]=a[g>>>2];else h.push.apply(h,a);this.sigBytes+=b;return this},clamp:function(){var b=this.words,h=this.sigBytes;b[h>>>2]&=4294967295<< +32-8*(h%4);b.length=s.ceil(h/4)},clone:function(){var b=r.clone.call(this);b.words=this.words.slice(0);return b},random:function(b){for(var h=[],a=0;a>>2]>>>24-8*(j%4)&255;g.push((k>>>4).toString(16));g.push((k&15).toString(16))}return g.join("")},parse:function(b){for(var a=b.length,g=[],j=0;j>>3]|=parseInt(b.substr(j, +2),16)<<24-4*(j%8);return new q.init(g,a/2)}},a=v.Latin1={stringify:function(b){var a=b.words;b=b.sigBytes;for(var g=[],j=0;j>>2]>>>24-8*(j%4)&255));return g.join("")},parse:function(b){for(var a=b.length,g=[],j=0;j>>2]|=(b.charCodeAt(j)&255)<<24-8*(j%4);return new q.init(g,a)}},u=v.Utf8={stringify:function(b){try{return decodeURIComponent(escape(a.stringify(b)))}catch(g){throw Error("Malformed UTF-8 data");}},parse:function(b){return a.parse(unescape(encodeURIComponent(b)))}}, +g=l.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new q.init;this._nDataBytes=0},_append:function(b){"string"==typeof b&&(b=u.parse(b));this._data.concat(b);this._nDataBytes+=b.sigBytes},_process:function(b){var a=this._data,g=a.words,j=a.sigBytes,k=this.blockSize,m=j/(4*k),m=b?s.ceil(m):s.max((m|0)-this._minBufferSize,0);b=m*k;j=s.min(4*b,j);if(b){for(var l=0;l>>32-j)+k}function m(a,k,b,h,l,j,m){a=a+(k&h|b&~h)+l+m;return(a<>>32-j)+k}function l(a,k,b,h,l,j,m){a=a+(k^b^h)+l+m;return(a<>>32-j)+k}function n(a,k,b,h,l,j,m){a=a+(b^(k|~h))+l+m;return(a<>>32-j)+k}for(var r=CryptoJS,q=r.lib,v=q.WordArray,t=q.Hasher,q=r.algo,a=[],u=0;64>u;u++)a[u]=4294967296*s.abs(s.sin(u+1))|0;q=q.MD5=t.extend({_doReset:function(){this._hash=new v.init([1732584193,4023233417,2562383102,271733878])}, +_doProcessBlock:function(g,k){for(var b=0;16>b;b++){var h=k+b,w=g[h];g[h]=(w<<8|w>>>24)&16711935|(w<<24|w>>>8)&4278255360}var b=this._hash.words,h=g[k+0],w=g[k+1],j=g[k+2],q=g[k+3],r=g[k+4],s=g[k+5],t=g[k+6],u=g[k+7],v=g[k+8],x=g[k+9],y=g[k+10],z=g[k+11],A=g[k+12],B=g[k+13],C=g[k+14],D=g[k+15],c=b[0],d=b[1],e=b[2],f=b[3],c=p(c,d,e,f,h,7,a[0]),f=p(f,c,d,e,w,12,a[1]),e=p(e,f,c,d,j,17,a[2]),d=p(d,e,f,c,q,22,a[3]),c=p(c,d,e,f,r,7,a[4]),f=p(f,c,d,e,s,12,a[5]),e=p(e,f,c,d,t,17,a[6]),d=p(d,e,f,c,u,22,a[7]), +c=p(c,d,e,f,v,7,a[8]),f=p(f,c,d,e,x,12,a[9]),e=p(e,f,c,d,y,17,a[10]),d=p(d,e,f,c,z,22,a[11]),c=p(c,d,e,f,A,7,a[12]),f=p(f,c,d,e,B,12,a[13]),e=p(e,f,c,d,C,17,a[14]),d=p(d,e,f,c,D,22,a[15]),c=m(c,d,e,f,w,5,a[16]),f=m(f,c,d,e,t,9,a[17]),e=m(e,f,c,d,z,14,a[18]),d=m(d,e,f,c,h,20,a[19]),c=m(c,d,e,f,s,5,a[20]),f=m(f,c,d,e,y,9,a[21]),e=m(e,f,c,d,D,14,a[22]),d=m(d,e,f,c,r,20,a[23]),c=m(c,d,e,f,x,5,a[24]),f=m(f,c,d,e,C,9,a[25]),e=m(e,f,c,d,q,14,a[26]),d=m(d,e,f,c,v,20,a[27]),c=m(c,d,e,f,B,5,a[28]),f=m(f,c, +d,e,j,9,a[29]),e=m(e,f,c,d,u,14,a[30]),d=m(d,e,f,c,A,20,a[31]),c=l(c,d,e,f,s,4,a[32]),f=l(f,c,d,e,v,11,a[33]),e=l(e,f,c,d,z,16,a[34]),d=l(d,e,f,c,C,23,a[35]),c=l(c,d,e,f,w,4,a[36]),f=l(f,c,d,e,r,11,a[37]),e=l(e,f,c,d,u,16,a[38]),d=l(d,e,f,c,y,23,a[39]),c=l(c,d,e,f,B,4,a[40]),f=l(f,c,d,e,h,11,a[41]),e=l(e,f,c,d,q,16,a[42]),d=l(d,e,f,c,t,23,a[43]),c=l(c,d,e,f,x,4,a[44]),f=l(f,c,d,e,A,11,a[45]),e=l(e,f,c,d,D,16,a[46]),d=l(d,e,f,c,j,23,a[47]),c=n(c,d,e,f,h,6,a[48]),f=n(f,c,d,e,u,10,a[49]),e=n(e,f,c,d, +C,15,a[50]),d=n(d,e,f,c,s,21,a[51]),c=n(c,d,e,f,A,6,a[52]),f=n(f,c,d,e,q,10,a[53]),e=n(e,f,c,d,y,15,a[54]),d=n(d,e,f,c,w,21,a[55]),c=n(c,d,e,f,v,6,a[56]),f=n(f,c,d,e,D,10,a[57]),e=n(e,f,c,d,t,15,a[58]),d=n(d,e,f,c,B,21,a[59]),c=n(c,d,e,f,r,6,a[60]),f=n(f,c,d,e,z,10,a[61]),e=n(e,f,c,d,j,15,a[62]),d=n(d,e,f,c,x,21,a[63]);b[0]=b[0]+c|0;b[1]=b[1]+d|0;b[2]=b[2]+e|0;b[3]=b[3]+f|0},_doFinalize:function(){var a=this._data,k=a.words,b=8*this._nDataBytes,h=8*a.sigBytes;k[h>>>5]|=128<<24-h%32;var l=s.floor(b/ +4294967296);k[(h+64>>>9<<4)+15]=(l<<8|l>>>24)&16711935|(l<<24|l>>>8)&4278255360;k[(h+64>>>9<<4)+14]=(b<<8|b>>>24)&16711935|(b<<24|b>>>8)&4278255360;a.sigBytes=4*(k.length+1);this._process();a=this._hash;k=a.words;for(b=0;4>b;b++)h=k[b],k[b]=(h<<8|h>>>24)&16711935|(h<<24|h>>>8)&4278255360;return a},clone:function(){var a=t.clone.call(this);a._hash=this._hash.clone();return a}});r.MD5=t._createHelper(q);r.HmacMD5=t._createHmacHelper(q)})(Math); diff --git a/services/web/public/js/libs/moment.js b/services/web/public/js/libs/moment.js index c8a870e8c1..568ad05cec 100755 --- a/services/web/public/js/libs/moment.js +++ b/services/web/public/js/libs/moment.js @@ -1,1662 +1,6 @@ -// moment.js -// version : 2.1.0 -// author : Tim Wood -// license : MIT -// momentjs.com - -(function (undefined) { - - /************************************ - Constants - ************************************/ - - var moment, - VERSION = "2.1.0", - round = Math.round, i, - // internal storage for language config files - languages = {}, - - // check for nodeJS - hasModule = (typeof module !== 'undefined' && module.exports), - - // ASP.NET json date format regex - aspNetJsonRegex = /^\/?Date\((\-?\d+)/i, - aspNetTimeSpanJsonRegex = /(\-)?(\d*)?\.?(\d+)\:(\d+)\:(\d+)\.?(\d{3})?/, - - // format tokens - formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g, - localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g, - - // parsing token regexes - parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99 - parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999 - parseTokenThreeDigits = /\d{3}/, // 000 - 999 - parseTokenFourDigits = /\d{1,4}/, // 0 - 9999 - parseTokenSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999 - parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i, // any word (or two) characters or numbers including two/three word month in arabic. - parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, // +00:00 -00:00 +0000 -0000 or Z - parseTokenT = /T/i, // T (ISO seperator) - parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123 - - // preliminary iso regex - // 0000-00-00 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 - isoRegex = /^\s*\d{4}-\d\d-\d\d((T| )(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/, - isoFormat = 'YYYY-MM-DDTHH:mm:ssZ', - - // iso time formats and regexes - isoTimes = [ - ['HH:mm:ss.S', /(T| )\d\d:\d\d:\d\d\.\d{1,3}/], - ['HH:mm:ss', /(T| )\d\d:\d\d:\d\d/], - ['HH:mm', /(T| )\d\d:\d\d/], - ['HH', /(T| )\d\d/] - ], - - // timezone chunker "+10:00" > ["10", "00"] or "-1530" > ["-15", "30"] - parseTimezoneChunker = /([\+\-]|\d\d)/gi, - - // getter and setter names - proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'), - unitMillisecondFactors = { - 'Milliseconds' : 1, - 'Seconds' : 1e3, - 'Minutes' : 6e4, - 'Hours' : 36e5, - 'Days' : 864e5, - 'Months' : 2592e6, - 'Years' : 31536e6 - }, - - unitAliases = { - ms : 'millisecond', - s : 'second', - m : 'minute', - h : 'hour', - d : 'day', - w : 'week', - M : 'month', - y : 'year' - }, - - // format function strings - formatFunctions = {}, - - // tokens to ordinalize and pad - ordinalizeTokens = 'DDD w W M D d'.split(' '), - paddedTokens = 'M D H h m s w W'.split(' '), - - formatTokenFunctions = { - M : function () { - return this.month() + 1; - }, - MMM : function (format) { - return this.lang().monthsShort(this, format); - }, - MMMM : function (format) { - return this.lang().months(this, format); - }, - D : function () { - return this.date(); - }, - DDD : function () { - return this.dayOfYear(); - }, - d : function () { - return this.day(); - }, - dd : function (format) { - return this.lang().weekdaysMin(this, format); - }, - ddd : function (format) { - return this.lang().weekdaysShort(this, format); - }, - dddd : function (format) { - return this.lang().weekdays(this, format); - }, - w : function () { - return this.week(); - }, - W : function () { - return this.isoWeek(); - }, - YY : function () { - return leftZeroFill(this.year() % 100, 2); - }, - YYYY : function () { - return leftZeroFill(this.year(), 4); - }, - YYYYY : function () { - return leftZeroFill(this.year(), 5); - }, - gg : function () { - return leftZeroFill(this.weekYear() % 100, 2); - }, - gggg : function () { - return this.weekYear(); - }, - ggggg : function () { - return leftZeroFill(this.weekYear(), 5); - }, - GG : function () { - return leftZeroFill(this.isoWeekYear() % 100, 2); - }, - GGGG : function () { - return this.isoWeekYear(); - }, - GGGGG : function () { - return leftZeroFill(this.isoWeekYear(), 5); - }, - e : function () { - return this.weekday(); - }, - E : function () { - return this.isoWeekday(); - }, - a : function () { - return this.lang().meridiem(this.hours(), this.minutes(), true); - }, - A : function () { - return this.lang().meridiem(this.hours(), this.minutes(), false); - }, - H : function () { - return this.hours(); - }, - h : function () { - return this.hours() % 12 || 12; - }, - m : function () { - return this.minutes(); - }, - s : function () { - return this.seconds(); - }, - S : function () { - return ~~(this.milliseconds() / 100); - }, - SS : function () { - return leftZeroFill(~~(this.milliseconds() / 10), 2); - }, - SSS : function () { - return leftZeroFill(this.milliseconds(), 3); - }, - Z : function () { - var a = -this.zone(), - b = "+"; - if (a < 0) { - a = -a; - b = "-"; - } - return b + leftZeroFill(~~(a / 60), 2) + ":" + leftZeroFill(~~a % 60, 2); - }, - ZZ : function () { - var a = -this.zone(), - b = "+"; - if (a < 0) { - a = -a; - b = "-"; - } - return b + leftZeroFill(~~(10 * a / 6), 4); - }, - z : function () { - return this.zoneAbbr(); - }, - zz : function () { - return this.zoneName(); - }, - X : function () { - return this.unix(); - } - }; - - function padToken(func, count) { - return function (a) { - return leftZeroFill(func.call(this, a), count); - }; - } - function ordinalizeToken(func, period) { - return function (a) { - return this.lang().ordinal(func.call(this, a), period); - }; - } - - while (ordinalizeTokens.length) { - i = ordinalizeTokens.pop(); - formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i); - } - while (paddedTokens.length) { - i = paddedTokens.pop(); - formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2); - } - formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3); - - - /************************************ - Constructors - ************************************/ - - function Language() { - - } - - // Moment prototype object - function Moment(config) { - extend(this, config); - } - - // Duration Constructor - function Duration(duration) { - var years = duration.years || duration.year || duration.y || 0, - months = duration.months || duration.month || duration.M || 0, - weeks = duration.weeks || duration.week || duration.w || 0, - days = duration.days || duration.day || duration.d || 0, - hours = duration.hours || duration.hour || duration.h || 0, - minutes = duration.minutes || duration.minute || duration.m || 0, - seconds = duration.seconds || duration.second || duration.s || 0, - milliseconds = duration.milliseconds || duration.millisecond || duration.ms || 0; - - // store reference to input for deterministic cloning - this._input = duration; - - // representation for dateAddRemove - this._milliseconds = milliseconds + - seconds * 1e3 + // 1000 - minutes * 6e4 + // 1000 * 60 - hours * 36e5; // 1000 * 60 * 60 - // Because of dateAddRemove treats 24 hours as different from a - // day when working around DST, we need to store them separately - this._days = days + - weeks * 7; - // It is impossible translate months into days without knowing - // which months you are are talking about, so we have to store - // it separately. - this._months = months + - years * 12; - - this._data = {}; - - this._bubble(); - } - - - /************************************ - Helpers - ************************************/ - - - function extend(a, b) { - for (var i in b) { - if (b.hasOwnProperty(i)) { - a[i] = b[i]; - } - } - return a; - } - - function absRound(number) { - if (number < 0) { - return Math.ceil(number); - } else { - return Math.floor(number); - } - } - - // left zero fill a number - // see http://jsperf.com/left-zero-filling for performance comparison - function leftZeroFill(number, targetLength) { - var output = number + ''; - while (output.length < targetLength) { - output = '0' + output; - } - return output; - } - - // helper function for _.addTime and _.subtractTime - function addOrSubtractDurationFromMoment(mom, duration, isAdding, ignoreUpdateOffset) { - var milliseconds = duration._milliseconds, - days = duration._days, - months = duration._months, - minutes, - hours, - currentDate; - - if (milliseconds) { - mom._d.setTime(+mom._d + milliseconds * isAdding); - } - // store the minutes and hours so we can restore them - if (days || months) { - minutes = mom.minute(); - hours = mom.hour(); - } - if (days) { - mom.date(mom.date() + days * isAdding); - } - if (months) { - mom.month(mom.month() + months * isAdding); - } - if (milliseconds && !ignoreUpdateOffset) { - moment.updateOffset(mom); - } - // restore the minutes and hours after possibly changing dst - if (days || months) { - mom.minute(minutes); - mom.hour(hours); - } - } - - // check if is an array - function isArray(input) { - return Object.prototype.toString.call(input) === '[object Array]'; - } - - // compare two arrays, return the number of differences - function compareArrays(array1, array2) { - var len = Math.min(array1.length, array2.length), - lengthDiff = Math.abs(array1.length - array2.length), - diffs = 0, - i; - for (i = 0; i < len; i++) { - if (~~array1[i] !== ~~array2[i]) { - diffs++; - } - } - return diffs + lengthDiff; - } - - function normalizeUnits(units) { - return units ? unitAliases[units] || units.toLowerCase().replace(/(.)s$/, '$1') : units; - } - - - /************************************ - Languages - ************************************/ - - - Language.prototype = { - set : function (config) { - var prop, i; - for (i in config) { - prop = config[i]; - if (typeof prop === 'function') { - this[i] = prop; - } else { - this['_' + i] = prop; - } - } - }, - - _months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), - months : function (m) { - return this._months[m.month()]; - }, - - _monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"), - monthsShort : function (m) { - return this._monthsShort[m.month()]; - }, - - monthsParse : function (monthName) { - var i, mom, regex; - - if (!this._monthsParse) { - this._monthsParse = []; - } - - for (i = 0; i < 12; i++) { - // make the regex if we don't have it already - if (!this._monthsParse[i]) { - mom = moment([2000, i]); - regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, ''); - this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i'); - } - // test the regex - if (this._monthsParse[i].test(monthName)) { - return i; - } - } - }, - - _weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), - weekdays : function (m) { - return this._weekdays[m.day()]; - }, - - _weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"), - weekdaysShort : function (m) { - return this._weekdaysShort[m.day()]; - }, - - _weekdaysMin : "Su_Mo_Tu_We_Th_Fr_Sa".split("_"), - weekdaysMin : function (m) { - return this._weekdaysMin[m.day()]; - }, - - weekdaysParse : function (weekdayName) { - var i, mom, regex; - - if (!this._weekdaysParse) { - this._weekdaysParse = []; - } - - for (i = 0; i < 7; i++) { - // make the regex if we don't have it already - if (!this._weekdaysParse[i]) { - mom = moment([2000, 1]).day(i); - regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, ''); - this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i'); - } - // test the regex - if (this._weekdaysParse[i].test(weekdayName)) { - return i; - } - } - }, - - _longDateFormat : { - LT : "h:mm A", - L : "MM/DD/YYYY", - LL : "MMMM D YYYY", - LLL : "MMMM D YYYY LT", - LLLL : "dddd, MMMM D YYYY LT" - }, - longDateFormat : function (key) { - var output = this._longDateFormat[key]; - if (!output && this._longDateFormat[key.toUpperCase()]) { - output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) { - return val.slice(1); - }); - this._longDateFormat[key] = output; - } - return output; - }, - - isPM : function (input) { - return ((input + '').toLowerCase()[0] === 'p'); - }, - - _meridiemParse : /[ap]\.?m?\.?/i, - meridiem : function (hours, minutes, isLower) { - if (hours > 11) { - return isLower ? 'pm' : 'PM'; - } else { - return isLower ? 'am' : 'AM'; - } - }, - - _calendar : { - sameDay : '[Today at] LT', - nextDay : '[Tomorrow at] LT', - nextWeek : 'dddd [at] LT', - lastDay : '[Yesterday at] LT', - lastWeek : '[Last] dddd [at] LT', - sameElse : 'L' - }, - calendar : function (key, mom) { - var output = this._calendar[key]; - return typeof output === 'function' ? output.apply(mom) : output; - }, - - _relativeTime : { - future : "in %s", - past : "%s ago", - s : "a few seconds", - m : "a minute", - mm : "%d minutes", - h : "an hour", - hh : "%d hours", - d : "a day", - dd : "%d days", - M : "a month", - MM : "%d months", - y : "a year", - yy : "%d years" - }, - relativeTime : function (number, withoutSuffix, string, isFuture) { - var output = this._relativeTime[string]; - return (typeof output === 'function') ? - output(number, withoutSuffix, string, isFuture) : - output.replace(/%d/i, number); - }, - pastFuture : function (diff, output) { - var format = this._relativeTime[diff > 0 ? 'future' : 'past']; - return typeof format === 'function' ? format(output) : format.replace(/%s/i, output); - }, - - ordinal : function (number) { - return this._ordinal.replace("%d", number); - }, - _ordinal : "%d", - - preparse : function (string) { - return string; - }, - - postformat : function (string) { - return string; - }, - - week : function (mom) { - return weekOfYear(mom, this._week.dow, this._week.doy).week; - }, - _week : { - dow : 0, // Sunday is the first day of the week. - doy : 6 // The week that contains Jan 1st is the first week of the year. - } - }; - - // Loads a language definition into the `languages` cache. The function - // takes a key and optionally values. If not in the browser and no values - // are provided, it will load the language file module. As a convenience, - // this function also returns the language values. - function loadLang(key, values) { - values.abbr = key; - if (!languages[key]) { - languages[key] = new Language(); - } - languages[key].set(values); - return languages[key]; - } - - // Determines which language definition to use and returns it. - // - // With no parameters, it will return the global language. If you - // pass in a language key, such as 'en', it will return the - // definition for 'en', so long as 'en' has already been loaded using - // moment.lang. - function getLangDefinition(key) { - if (!key) { - return moment.fn._lang; - } - if (!languages[key] && hasModule) { - try { - require('./lang/' + key); - } catch (e) { - // call with no params to set to default - return moment.fn._lang; - } - } - return languages[key]; - } - - - /************************************ - Formatting - ************************************/ - - - function removeFormattingTokens(input) { - if (input.match(/\[.*\]/)) { - return input.replace(/^\[|\]$/g, ""); - } - return input.replace(/\\/g, ""); - } - - function makeFormatFunction(format) { - var array = format.match(formattingTokens), i, length; - - for (i = 0, length = array.length; i < length; i++) { - if (formatTokenFunctions[array[i]]) { - array[i] = formatTokenFunctions[array[i]]; - } else { - array[i] = removeFormattingTokens(array[i]); - } - } - - return function (mom) { - var output = ""; - for (i = 0; i < length; i++) { - output += array[i] instanceof Function ? array[i].call(mom, format) : array[i]; - } - return output; - }; - } - - // format date using native date object - function formatMoment(m, format) { - var i = 5; - - function replaceLongDateFormatTokens(input) { - return m.lang().longDateFormat(input) || input; - } - - while (i-- && localFormattingTokens.test(format)) { - format = format.replace(localFormattingTokens, replaceLongDateFormatTokens); - } - - if (!formatFunctions[format]) { - formatFunctions[format] = makeFormatFunction(format); - } - - return formatFunctions[format](m); - } - - - /************************************ - Parsing - ************************************/ - - - // get the regex to find the next token - function getParseRegexForToken(token, config) { - switch (token) { - case 'DDDD': - return parseTokenThreeDigits; - case 'YYYY': - return parseTokenFourDigits; - case 'YYYYY': - return parseTokenSixDigits; - case 'S': - case 'SS': - case 'SSS': - case 'DDD': - return parseTokenOneToThreeDigits; - case 'MMM': - case 'MMMM': - case 'dd': - case 'ddd': - case 'dddd': - return parseTokenWord; - case 'a': - case 'A': - return getLangDefinition(config._l)._meridiemParse; - case 'X': - return parseTokenTimestampMs; - case 'Z': - case 'ZZ': - return parseTokenTimezone; - case 'T': - return parseTokenT; - case 'MM': - case 'DD': - case 'YY': - case 'HH': - case 'hh': - case 'mm': - case 'ss': - case 'M': - case 'D': - case 'd': - case 'H': - case 'h': - case 'm': - case 's': - return parseTokenOneOrTwoDigits; - default : - return new RegExp(token.replace('\\', '')); - } - } - - function timezoneMinutesFromString(string) { - var tzchunk = (parseTokenTimezone.exec(string) || [])[0], - parts = (tzchunk + '').match(parseTimezoneChunker) || ['-', 0, 0], - minutes = +(parts[1] * 60) + ~~parts[2]; - - return parts[0] === '+' ? -minutes : minutes; - } - - // function to convert string input to date - function addTimeToArrayFromToken(token, input, config) { - var a, datePartArray = config._a; - - switch (token) { - // MONTH - case 'M' : // fall through to MM - case 'MM' : - datePartArray[1] = (input == null) ? 0 : ~~input - 1; - break; - case 'MMM' : // fall through to MMMM - case 'MMMM' : - a = getLangDefinition(config._l).monthsParse(input); - // if we didn't find a month name, mark the date as invalid. - if (a != null) { - datePartArray[1] = a; - } else { - config._isValid = false; - } - break; - // DAY OF MONTH - case 'D' : // fall through to DDDD - case 'DD' : // fall through to DDDD - case 'DDD' : // fall through to DDDD - case 'DDDD' : - if (input != null) { - datePartArray[2] = ~~input; - } - break; - // YEAR - case 'YY' : - datePartArray[0] = ~~input + (~~input > 68 ? 1900 : 2000); - break; - case 'YYYY' : - case 'YYYYY' : - datePartArray[0] = ~~input; - break; - // AM / PM - case 'a' : // fall through to A - case 'A' : - config._isPm = getLangDefinition(config._l).isPM(input); - break; - // 24 HOUR - case 'H' : // fall through to hh - case 'HH' : // fall through to hh - case 'h' : // fall through to hh - case 'hh' : - datePartArray[3] = ~~input; - break; - // MINUTE - case 'm' : // fall through to mm - case 'mm' : - datePartArray[4] = ~~input; - break; - // SECOND - case 's' : // fall through to ss - case 'ss' : - datePartArray[5] = ~~input; - break; - // MILLISECOND - case 'S' : - case 'SS' : - case 'SSS' : - datePartArray[6] = ~~ (('0.' + input) * 1000); - break; - // UNIX TIMESTAMP WITH MS - case 'X': - config._d = new Date(parseFloat(input) * 1000); - break; - // TIMEZONE - case 'Z' : // fall through to ZZ - case 'ZZ' : - config._useUTC = true; - config._tzm = timezoneMinutesFromString(input); - break; - } - - // if the input is null, the date is not valid - if (input == null) { - config._isValid = false; - } - } - - // convert an array to a date. - // the array should mirror the parameters below - // note: all values past the year are optional and will default to the lowest possible value. - // [year, month, day , hour, minute, second, millisecond] - function dateFromArray(config) { - var i, date, input = []; - - if (config._d) { - return; - } - - for (i = 0; i < 7; i++) { - config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i]; - } - - // add the offsets to the time to be parsed so that we can have a clean array for checking isValid - input[3] += ~~((config._tzm || 0) / 60); - input[4] += ~~((config._tzm || 0) % 60); - - date = new Date(0); - - if (config._useUTC) { - date.setUTCFullYear(input[0], input[1], input[2]); - date.setUTCHours(input[3], input[4], input[5], input[6]); - } else { - date.setFullYear(input[0], input[1], input[2]); - date.setHours(input[3], input[4], input[5], input[6]); - } - - config._d = date; - } - - // date from string and format string - function makeDateFromStringAndFormat(config) { - // This array is used to make a Date, either with `new Date` or `Date.UTC` - var tokens = config._f.match(formattingTokens), - string = config._i, - i, parsedInput; - - config._a = []; - - for (i = 0; i < tokens.length; i++) { - parsedInput = (getParseRegexForToken(tokens[i], config).exec(string) || [])[0]; - if (parsedInput) { - string = string.slice(string.indexOf(parsedInput) + parsedInput.length); - } - // don't parse if its not a known token - if (formatTokenFunctions[tokens[i]]) { - addTimeToArrayFromToken(tokens[i], parsedInput, config); - } - } - - // add remaining unparsed input to the string - if (string) { - config._il = string; - } - - // handle am pm - if (config._isPm && config._a[3] < 12) { - config._a[3] += 12; - } - // if is 12 am, change hours to 0 - if (config._isPm === false && config._a[3] === 12) { - config._a[3] = 0; - } - // return - dateFromArray(config); - } - - // date from string and array of format strings - function makeDateFromStringAndArray(config) { - var tempConfig, - tempMoment, - bestMoment, - - scoreToBeat = 99, - i, - currentScore; - - for (i = 0; i < config._f.length; i++) { - tempConfig = extend({}, config); - tempConfig._f = config._f[i]; - makeDateFromStringAndFormat(tempConfig); - tempMoment = new Moment(tempConfig); - - currentScore = compareArrays(tempConfig._a, tempMoment.toArray()); - - // if there is any input that was not parsed - // add a penalty for that format - if (tempMoment._il) { - currentScore += tempMoment._il.length; - } - - if (currentScore < scoreToBeat) { - scoreToBeat = currentScore; - bestMoment = tempMoment; - } - } - - extend(config, bestMoment); - } - - // date from iso format - function makeDateFromString(config) { - var i, - string = config._i, - match = isoRegex.exec(string); - - if (match) { - // match[2] should be "T" or undefined - config._f = 'YYYY-MM-DD' + (match[2] || " "); - for (i = 0; i < 4; i++) { - if (isoTimes[i][1].exec(string)) { - config._f += isoTimes[i][0]; - break; - } - } - if (parseTokenTimezone.exec(string)) { - config._f += " Z"; - } - makeDateFromStringAndFormat(config); - } else { - config._d = new Date(string); - } - } - - function makeDateFromInput(config) { - var input = config._i, - matched = aspNetJsonRegex.exec(input); - - if (input === undefined) { - config._d = new Date(); - } else if (matched) { - config._d = new Date(+matched[1]); - } else if (typeof input === 'string') { - makeDateFromString(config); - } else if (isArray(input)) { - config._a = input.slice(0); - dateFromArray(config); - } else { - config._d = input instanceof Date ? new Date(+input) : new Date(input); - } - } - - - /************************************ - Relative Time - ************************************/ - - - // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize - function substituteTimeAgo(string, number, withoutSuffix, isFuture, lang) { - return lang.relativeTime(number || 1, !!withoutSuffix, string, isFuture); - } - - function relativeTime(milliseconds, withoutSuffix, lang) { - var seconds = round(Math.abs(milliseconds) / 1000), - minutes = round(seconds / 60), - hours = round(minutes / 60), - days = round(hours / 24), - years = round(days / 365), - args = seconds < 45 && ['s', seconds] || - minutes === 1 && ['m'] || - minutes < 45 && ['mm', minutes] || - hours === 1 && ['h'] || - hours < 22 && ['hh', hours] || - days === 1 && ['d'] || - days <= 25 && ['dd', days] || - days <= 45 && ['M'] || - days < 345 && ['MM', round(days / 30)] || - years === 1 && ['y'] || ['yy', years]; - args[2] = withoutSuffix; - args[3] = milliseconds > 0; - args[4] = lang; - return substituteTimeAgo.apply({}, args); - } - - - /************************************ - Week of Year - ************************************/ - - - // firstDayOfWeek 0 = sun, 6 = sat - // the day of the week that starts the week - // (usually sunday or monday) - // firstDayOfWeekOfYear 0 = sun, 6 = sat - // the first week is the week that contains the first - // of this day of the week - // (eg. ISO weeks use thursday (4)) - function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) { - var end = firstDayOfWeekOfYear - firstDayOfWeek, - daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(), - adjustedMoment; - - - if (daysToDayOfWeek > end) { - daysToDayOfWeek -= 7; - } - - if (daysToDayOfWeek < end - 7) { - daysToDayOfWeek += 7; - } - - adjustedMoment = moment(mom).add('d', daysToDayOfWeek); - return { - week: Math.ceil(adjustedMoment.dayOfYear() / 7), - year: adjustedMoment.year() - }; - } - - - /************************************ - Top Level Functions - ************************************/ - - function makeMoment(config) { - var input = config._i, - format = config._f; - - if (input === null || input === '') { - return null; - } - - if (typeof input === 'string') { - config._i = input = getLangDefinition().preparse(input); - } - - if (moment.isMoment(input)) { - config = extend({}, input); - config._d = new Date(+input._d); - } else if (format) { - if (isArray(format)) { - makeDateFromStringAndArray(config); - } else { - makeDateFromStringAndFormat(config); - } - } else { - makeDateFromInput(config); - } - - return new Moment(config); - } - - moment = function (input, format, lang) { - return makeMoment({ - _i : input, - _f : format, - _l : lang, - _isUTC : false - }); - }; - - // creating with utc - moment.utc = function (input, format, lang) { - return makeMoment({ - _useUTC : true, - _isUTC : true, - _l : lang, - _i : input, - _f : format - }); - }; - - // creating with unix timestamp (in seconds) - moment.unix = function (input) { - return moment(input * 1000); - }; - - // duration - moment.duration = function (input, key) { - var isDuration = moment.isDuration(input), - isNumber = (typeof input === 'number'), - duration = (isDuration ? input._input : (isNumber ? {} : input)), - matched = aspNetTimeSpanJsonRegex.exec(input), - sign, - ret; - - if (isNumber) { - if (key) { - duration[key] = input; - } else { - duration.milliseconds = input; - } - } else if (matched) { - sign = (matched[1] === "-") ? -1 : 1; - duration = { - y: 0, - d: ~~matched[2] * sign, - h: ~~matched[3] * sign, - m: ~~matched[4] * sign, - s: ~~matched[5] * sign, - ms: ~~matched[6] * sign - }; - } - - ret = new Duration(duration); - - if (isDuration && input.hasOwnProperty('_lang')) { - ret._lang = input._lang; - } - - return ret; - }; - - // version number - moment.version = VERSION; - - // default format - moment.defaultFormat = isoFormat; - - // This function will be called whenever a moment is mutated. - // It is intended to keep the offset in sync with the timezone. - moment.updateOffset = function () {}; - - // This function will load languages and then set the global language. If - // no arguments are passed in, it will simply return the current global - // language key. - moment.lang = function (key, values) { - if (!key) { - return moment.fn._lang._abbr; - } - if (values) { - loadLang(key, values); - } else if (!languages[key]) { - getLangDefinition(key); - } - moment.duration.fn._lang = moment.fn._lang = getLangDefinition(key); - }; - - // returns language data - moment.langData = function (key) { - if (key && key._lang && key._lang._abbr) { - key = key._lang._abbr; - } - return getLangDefinition(key); - }; - - // compare moment object - moment.isMoment = function (obj) { - return obj instanceof Moment; - }; - - // for typechecking Duration objects - moment.isDuration = function (obj) { - return obj instanceof Duration; - }; - - - /************************************ - Moment Prototype - ************************************/ - - - moment.fn = Moment.prototype = { - - clone : function () { - return moment(this); - }, - - valueOf : function () { - return +this._d + ((this._offset || 0) * 60000); - }, - - unix : function () { - return Math.floor(+this / 1000); - }, - - toString : function () { - return this.format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ"); - }, - - toDate : function () { - return this._offset ? new Date(+this) : this._d; - }, - - toISOString : function () { - return formatMoment(moment(this).utc(), 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]'); - }, - - toArray : function () { - var m = this; - return [ - m.year(), - m.month(), - m.date(), - m.hours(), - m.minutes(), - m.seconds(), - m.milliseconds() - ]; - }, - - isValid : function () { - if (this._isValid == null) { - if (this._a) { - this._isValid = !compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()); - } else { - this._isValid = !isNaN(this._d.getTime()); - } - } - return !!this._isValid; - }, - - utc : function () { - return this.zone(0); - }, - - local : function () { - this.zone(0); - this._isUTC = false; - return this; - }, - - format : function (inputString) { - var output = formatMoment(this, inputString || moment.defaultFormat); - return this.lang().postformat(output); - }, - - add : function (input, val) { - var dur; - // switch args to support add('s', 1) and add(1, 's') - if (typeof input === 'string') { - dur = moment.duration(+val, input); - } else { - dur = moment.duration(input, val); - } - addOrSubtractDurationFromMoment(this, dur, 1); - return this; - }, - - subtract : function (input, val) { - var dur; - // switch args to support subtract('s', 1) and subtract(1, 's') - if (typeof input === 'string') { - dur = moment.duration(+val, input); - } else { - dur = moment.duration(input, val); - } - addOrSubtractDurationFromMoment(this, dur, -1); - return this; - }, - - diff : function (input, units, asFloat) { - var that = this._isUTC ? moment(input).zone(this._offset || 0) : moment(input).local(), - zoneDiff = (this.zone() - that.zone()) * 6e4, - diff, output; - - units = normalizeUnits(units); - - if (units === 'year' || units === 'month') { - // average number of days in the months in the given dates - diff = (this.daysInMonth() + that.daysInMonth()) * 432e5; // 24 * 60 * 60 * 1000 / 2 - // difference in months - output = ((this.year() - that.year()) * 12) + (this.month() - that.month()); - // adjust by taking difference in days, average number of days - // and dst in the given months. - output += ((this - moment(this).startOf('month')) - - (that - moment(that).startOf('month'))) / diff; - // same as above but with zones, to negate all dst - output -= ((this.zone() - moment(this).startOf('month').zone()) - - (that.zone() - moment(that).startOf('month').zone())) * 6e4 / diff; - if (units === 'year') { - output = output / 12; - } - } else { - diff = (this - that); - output = units === 'second' ? diff / 1e3 : // 1000 - units === 'minute' ? diff / 6e4 : // 1000 * 60 - units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60 - units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst - units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst - diff; - } - return asFloat ? output : absRound(output); - }, - - from : function (time, withoutSuffix) { - return moment.duration(this.diff(time)).lang(this.lang()._abbr).humanize(!withoutSuffix); - }, - - fromNow : function (withoutSuffix) { - return this.from(moment(), withoutSuffix); - }, - - calendar : function () { - var diff = this.diff(moment().startOf('day'), 'days', true), - format = diff < -6 ? 'sameElse' : - diff < -1 ? 'lastWeek' : - diff < 0 ? 'lastDay' : - diff < 1 ? 'sameDay' : - diff < 2 ? 'nextDay' : - diff < 7 ? 'nextWeek' : 'sameElse'; - return this.format(this.lang().calendar(format, this)); - }, - - isLeapYear : function () { - var year = this.year(); - return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; - }, - - isDST : function () { - return (this.zone() < this.clone().month(0).zone() || - this.zone() < this.clone().month(5).zone()); - }, - - day : function (input) { - var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay(); - if (input != null) { - if (typeof input === 'string') { - input = this.lang().weekdaysParse(input); - if (typeof input !== 'number') { - return this; - } - } - return this.add({ d : input - day }); - } else { - return day; - } - }, - - month : function (input) { - var utc = this._isUTC ? 'UTC' : '', - dayOfMonth, - daysInMonth; - - if (input != null) { - if (typeof input === 'string') { - input = this.lang().monthsParse(input); - if (typeof input !== 'number') { - return this; - } - } - - dayOfMonth = this.date(); - this.date(1); - this._d['set' + utc + 'Month'](input); - this.date(Math.min(dayOfMonth, this.daysInMonth())); - - moment.updateOffset(this); - return this; - } else { - return this._d['get' + utc + 'Month'](); - } - }, - - startOf: function (units) { - units = normalizeUnits(units); - // the following switch intentionally omits break keywords - // to utilize falling through the cases. - switch (units) { - case 'year': - this.month(0); - /* falls through */ - case 'month': - this.date(1); - /* falls through */ - case 'week': - case 'day': - this.hours(0); - /* falls through */ - case 'hour': - this.minutes(0); - /* falls through */ - case 'minute': - this.seconds(0); - /* falls through */ - case 'second': - this.milliseconds(0); - /* falls through */ - } - - // weeks are a special case - if (units === 'week') { - this.weekday(0); - } - - return this; - }, - - endOf: function (units) { - return this.startOf(units).add(units, 1).subtract('ms', 1); - }, - - isAfter: function (input, units) { - units = typeof units !== 'undefined' ? units : 'millisecond'; - return +this.clone().startOf(units) > +moment(input).startOf(units); - }, - - isBefore: function (input, units) { - units = typeof units !== 'undefined' ? units : 'millisecond'; - return +this.clone().startOf(units) < +moment(input).startOf(units); - }, - - isSame: function (input, units) { - units = typeof units !== 'undefined' ? units : 'millisecond'; - return +this.clone().startOf(units) === +moment(input).startOf(units); - }, - - min: function (other) { - other = moment.apply(null, arguments); - return other < this ? this : other; - }, - - max: function (other) { - other = moment.apply(null, arguments); - return other > this ? this : other; - }, - - zone : function (input) { - var offset = this._offset || 0; - if (input != null) { - if (typeof input === "string") { - input = timezoneMinutesFromString(input); - } - if (Math.abs(input) < 16) { - input = input * 60; - } - this._offset = input; - this._isUTC = true; - if (offset !== input) { - addOrSubtractDurationFromMoment(this, moment.duration(offset - input, 'm'), 1, true); - } - } else { - return this._isUTC ? offset : this._d.getTimezoneOffset(); - } - return this; - }, - - zoneAbbr : function () { - return this._isUTC ? "UTC" : ""; - }, - - zoneName : function () { - return this._isUTC ? "Coordinated Universal Time" : ""; - }, - - daysInMonth : function () { - return moment.utc([this.year(), this.month() + 1, 0]).date(); - }, - - dayOfYear : function (input) { - var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1; - return input == null ? dayOfYear : this.add("d", (input - dayOfYear)); - }, - - weekYear : function (input) { - var year = weekOfYear(this, this.lang()._week.dow, this.lang()._week.doy).year; - return input == null ? year : this.add("y", (input - year)); - }, - - isoWeekYear : function (input) { - var year = weekOfYear(this, 1, 4).year; - return input == null ? year : this.add("y", (input - year)); - }, - - week : function (input) { - var week = this.lang().week(this); - return input == null ? week : this.add("d", (input - week) * 7); - }, - - isoWeek : function (input) { - var week = weekOfYear(this, 1, 4).week; - return input == null ? week : this.add("d", (input - week) * 7); - }, - - weekday : function (input) { - var weekday = (this._d.getDay() + 7 - this.lang()._week.dow) % 7; - return input == null ? weekday : this.add("d", input - weekday); - }, - - isoWeekday : function (input) { - // behaves the same as moment#day except - // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6) - // as a setter, sunday should belong to the previous week. - return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7); - }, - - // If passed a language key, it will set the language for this - // instance. Otherwise, it will return the language configuration - // variables for this instance. - lang : function (key) { - if (key === undefined) { - return this._lang; - } else { - this._lang = getLangDefinition(key); - return this; - } - } - }; - - // helper for adding shortcuts - function makeGetterAndSetter(name, key) { - moment.fn[name] = moment.fn[name + 's'] = function (input) { - var utc = this._isUTC ? 'UTC' : ''; - if (input != null) { - this._d['set' + utc + key](input); - moment.updateOffset(this); - return this; - } else { - return this._d['get' + utc + key](); - } - }; - } - - // loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds) - for (i = 0; i < proxyGettersAndSetters.length; i ++) { - makeGetterAndSetter(proxyGettersAndSetters[i].toLowerCase().replace(/s$/, ''), proxyGettersAndSetters[i]); - } - - // add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear') - makeGetterAndSetter('year', 'FullYear'); - - // add plural methods - moment.fn.days = moment.fn.day; - moment.fn.months = moment.fn.month; - moment.fn.weeks = moment.fn.week; - moment.fn.isoWeeks = moment.fn.isoWeek; - - // add aliased format methods - moment.fn.toJSON = moment.fn.toISOString; - - /************************************ - Duration Prototype - ************************************/ - - - moment.duration.fn = Duration.prototype = { - _bubble : function () { - var milliseconds = this._milliseconds, - days = this._days, - months = this._months, - data = this._data, - seconds, minutes, hours, years; - - // The following code bubbles up values, see the tests for - // examples of what that means. - data.milliseconds = milliseconds % 1000; - - seconds = absRound(milliseconds / 1000); - data.seconds = seconds % 60; - - minutes = absRound(seconds / 60); - data.minutes = minutes % 60; - - hours = absRound(minutes / 60); - data.hours = hours % 24; - - days += absRound(hours / 24); - data.days = days % 30; - - months += absRound(days / 30); - data.months = months % 12; - - years = absRound(months / 12); - data.years = years; - }, - - weeks : function () { - return absRound(this.days() / 7); - }, - - valueOf : function () { - return this._milliseconds + - this._days * 864e5 + - (this._months % 12) * 2592e6 + - ~~(this._months / 12) * 31536e6; - }, - - humanize : function (withSuffix) { - var difference = +this, - output = relativeTime(difference, !withSuffix, this.lang()); - - if (withSuffix) { - output = this.lang().pastFuture(difference, output); - } - - return this.lang().postformat(output); - }, - - add : function (input, val) { - // supports only 2.0-style add(1, 's') or add(moment) - var dur = moment.duration(input, val); - - this._milliseconds += dur._milliseconds; - this._days += dur._days; - this._months += dur._months; - - this._bubble(); - - return this; - }, - - subtract : function (input, val) { - var dur = moment.duration(input, val); - - this._milliseconds -= dur._milliseconds; - this._days -= dur._days; - this._months -= dur._months; - - this._bubble(); - - return this; - }, - - get : function (units) { - units = normalizeUnits(units); - return this[units.toLowerCase() + 's'](); - }, - - as : function (units) { - units = normalizeUnits(units); - return this['as' + units.charAt(0).toUpperCase() + units.slice(1) + 's'](); - }, - - lang : moment.fn.lang - }; - - function makeDurationGetter(name) { - moment.duration.fn[name] = function () { - return this._data[name]; - }; - } - - function makeDurationAsGetter(name, factor) { - moment.duration.fn['as' + name] = function () { - return +this / factor; - }; - } - - for (i in unitMillisecondFactors) { - if (unitMillisecondFactors.hasOwnProperty(i)) { - makeDurationAsGetter(i, unitMillisecondFactors[i]); - makeDurationGetter(i.toLowerCase()); - } - } - - makeDurationAsGetter('Weeks', 6048e5); - moment.duration.fn.asMonths = function () { - return (+this - this.years() * 31536e6) / 2592e6 + this.years() * 12; - }; - - - /************************************ - Default Lang - ************************************/ - - - // Set default language, other languages will inherit from English. - moment.lang('en', { - ordinal : function (number) { - var b = number % 10, - output = (~~ (number % 100 / 10) === 1) ? 'th' : - (b === 1) ? 'st' : - (b === 2) ? 'nd' : - (b === 3) ? 'rd' : 'th'; - return number + output; - } - }); - - - /************************************ - Exposing Moment - ************************************/ - - - // CommonJS module is defined - if (hasModule) { - module.exports = moment; - } - /*global ender:false */ - if (typeof ender === 'undefined') { - // here, `this` means `window` in the browser, or `global` on the server - // add `moment` as a global object via a string identifier, - // for Closure Compiler "advanced" mode - this['moment'] = moment; - } - /*global define:false */ - if (typeof define === "function" && define.amd) { - define("moment", [], function () { - return moment; - }); - } -}).call(this); +//! moment.js +//! version : 2.4.0 +//! authors : Tim Wood, Iskren Chernev, Moment.js contributors +//! license : MIT +//! momentjs.com +(function(a){function b(a,b){return function(c){return i(a.call(this,c),b)}}function c(a,b){return function(c){return this.lang().ordinal(a.call(this,c),b)}}function d(){}function e(a){u(a),g(this,a)}function f(a){var b=o(a),c=b.year||0,d=b.month||0,e=b.week||0,f=b.day||0,g=b.hour||0,h=b.minute||0,i=b.second||0,j=b.millisecond||0;this._input=a,this._milliseconds=+j+1e3*i+6e4*h+36e5*g,this._days=+f+7*e,this._months=+d+12*c,this._data={},this._bubble()}function g(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return b.hasOwnProperty("toString")&&(a.toString=b.toString),b.hasOwnProperty("valueOf")&&(a.valueOf=b.valueOf),a}function h(a){return 0>a?Math.ceil(a):Math.floor(a)}function i(a,b){for(var c=a+"";c.lengthd;d++)(c&&a[d]!==b[d]||!c&&q(a[d])!==q(b[d]))&&g++;return g+f}function n(a){if(a){var b=a.toLowerCase().replace(/(.)s$/,"$1");a=Kb[a]||Lb[b]||b}return a}function o(a){var b,c,d={};for(c in a)a.hasOwnProperty(c)&&(b=n(c),b&&(d[b]=a[c]));return d}function p(b){var c,d;if(0===b.indexOf("week"))c=7,d="day";else{if(0!==b.indexOf("month"))return;c=12,d="month"}bb[b]=function(e,f){var g,h,i=bb.fn._lang[b],j=[];if("number"==typeof e&&(f=e,e=a),h=function(a){var b=bb().utc().set(d,a);return i.call(bb.fn._lang,b,e||"")},null!=f)return h(f);for(g=0;c>g;g++)j.push(h(g));return j}}function q(a){var b=+a,c=0;return 0!==b&&isFinite(b)&&(c=b>=0?Math.floor(b):Math.ceil(b)),c}function r(a,b){return new Date(Date.UTC(a,b+1,0)).getUTCDate()}function s(a){return t(a)?366:365}function t(a){return 0===a%4&&0!==a%100||0===a%400}function u(a){var b;a._a&&-2===a._pf.overflow&&(b=a._a[gb]<0||a._a[gb]>11?gb:a._a[hb]<1||a._a[hb]>r(a._a[fb],a._a[gb])?hb:a._a[ib]<0||a._a[ib]>23?ib:a._a[jb]<0||a._a[jb]>59?jb:a._a[kb]<0||a._a[kb]>59?kb:a._a[lb]<0||a._a[lb]>999?lb:-1,a._pf._overflowDayOfYear&&(fb>b||b>hb)&&(b=hb),a._pf.overflow=b)}function v(a){a._pf={empty:!1,unusedTokens:[],unusedInput:[],overflow:-2,charsLeftOver:0,nullInput:!1,invalidMonth:null,invalidFormat:!1,userInvalidated:!1,iso:!1}}function w(a){return null==a._isValid&&(a._isValid=!isNaN(a._d.getTime())&&a._pf.overflow<0&&!a._pf.empty&&!a._pf.invalidMonth&&!a._pf.nullInput&&!a._pf.invalidFormat&&!a._pf.userInvalidated,a._strict&&(a._isValid=a._isValid&&0===a._pf.charsLeftOver&&0===a._pf.unusedTokens.length)),a._isValid}function x(a){return a?a.toLowerCase().replace("_","-"):a}function y(a,b){return b.abbr=a,mb[a]||(mb[a]=new d),mb[a].set(b),mb[a]}function z(a){delete mb[a]}function A(a){var b,c,d,e,f=0,g=function(a){if(!mb[a]&&nb)try{require("./lang/"+a)}catch(b){}return mb[a]};if(!a)return bb.fn._lang;if(!k(a)){if(c=g(a))return c;a=[a]}for(;f0;){if(c=g(e.slice(0,b).join("-")))return c;if(d&&d.length>=b&&m(e,d,!0)>=b-1)break;b--}f++}return bb.fn._lang}function B(a){return a.match(/\[[\s\S]/)?a.replace(/^\[|\]$/g,""):a.replace(/\\/g,"")}function C(a){var b,c,d=a.match(rb);for(b=0,c=d.length;c>b;b++)d[b]=Pb[d[b]]?Pb[d[b]]:B(d[b]);return function(e){var f="";for(b=0;c>b;b++)f+=d[b]instanceof Function?d[b].call(e,a):d[b];return f}}function D(a,b){return a.isValid()?(b=E(b,a.lang()),Mb[b]||(Mb[b]=C(b)),Mb[b](a)):a.lang().invalidDate()}function E(a,b){function c(a){return b.longDateFormat(a)||a}var d=5;for(sb.lastIndex=0;d>=0&&sb.test(a);)a=a.replace(sb,c),sb.lastIndex=0,d-=1;return a}function F(a,b){var c;switch(a){case"DDDD":return vb;case"YYYY":case"GGGG":case"gggg":return wb;case"YYYYY":case"GGGGG":case"ggggg":return xb;case"S":case"SS":case"SSS":case"DDD":return ub;case"MMM":case"MMMM":case"dd":case"ddd":case"dddd":return zb;case"a":case"A":return A(b._l)._meridiemParse;case"X":return Cb;case"Z":case"ZZ":return Ab;case"T":return Bb;case"SSSS":return yb;case"MM":case"DD":case"YY":case"GG":case"gg":case"HH":case"hh":case"mm":case"ss":case"M":case"D":case"d":case"H":case"h":case"m":case"s":case"w":case"ww":case"W":case"WW":case"e":case"E":return tb;default:return c=new RegExp(N(M(a.replace("\\","")),"i"))}}function G(a){var b=(Ab.exec(a)||[])[0],c=(b+"").match(Hb)||["-",0,0],d=+(60*c[1])+q(c[2]);return"+"===c[0]?-d:d}function H(a,b,c){var d,e=c._a;switch(a){case"M":case"MM":null!=b&&(e[gb]=q(b)-1);break;case"MMM":case"MMMM":d=A(c._l).monthsParse(b),null!=d?e[gb]=d:c._pf.invalidMonth=b;break;case"D":case"DD":null!=b&&(e[hb]=q(b));break;case"DDD":case"DDDD":null!=b&&(c._dayOfYear=q(b));break;case"YY":e[fb]=q(b)+(q(b)>68?1900:2e3);break;case"YYYY":case"YYYYY":e[fb]=q(b);break;case"a":case"A":c._isPm=A(c._l).isPM(b);break;case"H":case"HH":case"h":case"hh":e[ib]=q(b);break;case"m":case"mm":e[jb]=q(b);break;case"s":case"ss":e[kb]=q(b);break;case"S":case"SS":case"SSS":case"SSSS":e[lb]=q(1e3*("0."+b));break;case"X":c._d=new Date(1e3*parseFloat(b));break;case"Z":case"ZZ":c._useUTC=!0,c._tzm=G(b);break;case"w":case"ww":case"W":case"WW":case"d":case"dd":case"ddd":case"dddd":case"e":case"E":a=a.substr(0,1);case"gg":case"gggg":case"GG":case"GGGG":case"GGGGG":a=a.substr(0,2),b&&(c._w=c._w||{},c._w[a]=b)}}function I(a){var b,c,d,e,f,g,h,i,j,k,l=[];if(!a._d){for(d=K(a),a._w&&null==a._a[hb]&&null==a._a[gb]&&(f=function(b){return b?b.length<3?parseInt(b,10)>68?"19"+b:"20"+b:b:null==a._a[fb]?bb().weekYear():a._a[fb]},g=a._w,null!=g.GG||null!=g.W||null!=g.E?h=X(f(g.GG),g.W||1,g.E,4,1):(i=A(a._l),j=null!=g.d?T(g.d,i):null!=g.e?parseInt(g.e,10)+i._week.dow:0,k=parseInt(g.w,10)||1,null!=g.d&&js(e)&&(a._pf._overflowDayOfYear=!0),c=S(e,0,a._dayOfYear),a._a[gb]=c.getUTCMonth(),a._a[hb]=c.getUTCDate()),b=0;3>b&&null==a._a[b];++b)a._a[b]=l[b]=d[b];for(;7>b;b++)a._a[b]=l[b]=null==a._a[b]?2===b?1:0:a._a[b];l[ib]+=q((a._tzm||0)/60),l[jb]+=q((a._tzm||0)%60),a._d=(a._useUTC?S:R).apply(null,l)}}function J(a){var b;a._d||(b=o(a._i),a._a=[b.year,b.month,b.day,b.hour,b.minute,b.second,b.millisecond],I(a))}function K(a){var b=new Date;return a._useUTC?[b.getUTCFullYear(),b.getUTCMonth(),b.getUTCDate()]:[b.getFullYear(),b.getMonth(),b.getDate()]}function L(a){a._a=[],a._pf.empty=!0;var b,c,d,e,f,g=A(a._l),h=""+a._i,i=h.length,j=0;for(d=E(a._f,g).match(rb)||[],b=0;b0&&a._pf.unusedInput.push(f),h=h.slice(h.indexOf(c)+c.length),j+=c.length),Pb[e]?(c?a._pf.empty=!1:a._pf.unusedTokens.push(e),H(e,c,a)):a._strict&&!c&&a._pf.unusedTokens.push(e);a._pf.charsLeftOver=i-j,h.length>0&&a._pf.unusedInput.push(h),a._isPm&&a._a[ib]<12&&(a._a[ib]+=12),a._isPm===!1&&12===a._a[ib]&&(a._a[ib]=0),I(a),u(a)}function M(a){return a.replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(a,b,c,d,e){return b||c||d||e})}function N(a){return a.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function O(a){var b,c,d,e,f;if(0===a._f.length)return a._pf.invalidFormat=!0,a._d=new Date(0/0),void 0;for(e=0;ef)&&(d=f,c=b));g(a,c||b)}function P(a){var b,c=a._i,d=Db.exec(c);if(d){for(a._pf.iso=!0,b=4;b>0;b--)if(d[b]){a._f=Fb[b-1]+(d[6]||" ");break}for(b=0;4>b;b++)if(Gb[b][1].exec(c)){a._f+=Gb[b][0];break}Ab.exec(c)&&(a._f+="Z"),L(a)}else a._d=new Date(c)}function Q(b){var c=b._i,d=ob.exec(c);c===a?b._d=new Date:d?b._d=new Date(+d[1]):"string"==typeof c?P(b):k(c)?(b._a=c.slice(0),I(b)):l(c)?b._d=new Date(+c):"object"==typeof c?J(b):b._d=new Date(c)}function R(a,b,c,d,e,f,g){var h=new Date(a,b,c,d,e,f,g);return 1970>a&&h.setFullYear(a),h}function S(a){var b=new Date(Date.UTC.apply(null,arguments));return 1970>a&&b.setUTCFullYear(a),b}function T(a,b){if("string"==typeof a)if(isNaN(a)){if(a=b.weekdaysParse(a),"number"!=typeof a)return null}else a=parseInt(a,10);return a}function U(a,b,c,d,e){return e.relativeTime(b||1,!!c,a,d)}function V(a,b,c){var d=eb(Math.abs(a)/1e3),e=eb(d/60),f=eb(e/60),g=eb(f/24),h=eb(g/365),i=45>d&&["s",d]||1===e&&["m"]||45>e&&["mm",e]||1===f&&["h"]||22>f&&["hh",f]||1===g&&["d"]||25>=g&&["dd",g]||45>=g&&["M"]||345>g&&["MM",eb(g/30)]||1===h&&["y"]||["yy",h];return i[2]=b,i[3]=a>0,i[4]=c,U.apply({},i)}function W(a,b,c){var d,e=c-b,f=c-a.day();return f>e&&(f-=7),e-7>f&&(f+=7),d=bb(a).add("d",f),{week:Math.ceil(d.dayOfYear()/7),year:d.year()}}function X(a,b,c,d,e){var f,g,h=new Date(Date.UTC(a,0)).getUTCDay();return c=null!=c?c:e,f=e-h+(h>d?7:0),g=7*(b-1)+(c-e)+f+1,{year:g>0?a:a-1,dayOfYear:g>0?g:s(a-1)+g}}function Y(a){var b=a._i,c=a._f;return"undefined"==typeof a._pf&&v(a),null===b?bb.invalid({nullInput:!0}):("string"==typeof b&&(a._i=b=A().preparse(b)),bb.isMoment(b)?(a=g({},b),a._d=new Date(+b._d)):c?k(c)?O(a):L(a):Q(a),new e(a))}function Z(a,b){bb.fn[a]=bb.fn[a+"s"]=function(a){var c=this._isUTC?"UTC":"";return null!=a?(this._d["set"+c+b](a),bb.updateOffset(this),this):this._d["get"+c+b]()}}function $(a){bb.duration.fn[a]=function(){return this._data[a]}}function _(a,b){bb.duration.fn["as"+a]=function(){return+this/b}}function ab(a){var b=!1,c=bb;"undefined"==typeof ender&&(this.moment=a?function(){return!b&&console&&console.warn&&(b=!0,console.warn("Accessing Moment through the global scope is deprecated, and will be removed in an upcoming release.")),c.apply(null,arguments)}:bb)}for(var bb,cb,db="2.4.0",eb=Math.round,fb=0,gb=1,hb=2,ib=3,jb=4,kb=5,lb=6,mb={},nb="undefined"!=typeof module&&module.exports,ob=/^\/?Date\((\-?\d+)/i,pb=/(\-)?(?:(\d*)\.)?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/,qb=/^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,rb=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|X|zz?|ZZ?|.)/g,sb=/(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,tb=/\d\d?/,ub=/\d{1,3}/,vb=/\d{3}/,wb=/\d{1,4}/,xb=/[+\-]?\d{1,6}/,yb=/\d+/,zb=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,Ab=/Z|[\+\-]\d\d:?\d\d/i,Bb=/T/i,Cb=/[\+\-]?\d+(\.\d{1,3})?/,Db=/^\s*\d{4}-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d:?\d\d|Z)?)?$/,Eb="YYYY-MM-DDTHH:mm:ssZ",Fb=["YYYY-MM-DD","GGGG-[W]WW","GGGG-[W]WW-E","YYYY-DDD"],Gb=[["HH:mm:ss.SSSS",/(T| )\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/(T| )\d\d:\d\d:\d\d/],["HH:mm",/(T| )\d\d:\d\d/],["HH",/(T| )\d\d/]],Hb=/([\+\-]|\d\d)/gi,Ib="Date|Hours|Minutes|Seconds|Milliseconds".split("|"),Jb={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6},Kb={ms:"millisecond",s:"second",m:"minute",h:"hour",d:"day",D:"date",w:"week",W:"isoWeek",M:"month",y:"year",DDD:"dayOfYear",e:"weekday",E:"isoWeekday",gg:"weekYear",GG:"isoWeekYear"},Lb={dayofyear:"dayOfYear",isoweekday:"isoWeekday",isoweek:"isoWeek",weekyear:"weekYear",isoweekyear:"isoWeekYear"},Mb={},Nb="DDD w W M D d".split(" "),Ob="M D H h m s w W".split(" "),Pb={M:function(){return this.month()+1},MMM:function(a){return this.lang().monthsShort(this,a)},MMMM:function(a){return this.lang().months(this,a)},D:function(){return this.date()},DDD:function(){return this.dayOfYear()},d:function(){return this.day()},dd:function(a){return this.lang().weekdaysMin(this,a)},ddd:function(a){return this.lang().weekdaysShort(this,a)},dddd:function(a){return this.lang().weekdays(this,a)},w:function(){return this.week()},W:function(){return this.isoWeek()},YY:function(){return i(this.year()%100,2)},YYYY:function(){return i(this.year(),4)},YYYYY:function(){return i(this.year(),5)},gg:function(){return i(this.weekYear()%100,2)},gggg:function(){return this.weekYear()},ggggg:function(){return i(this.weekYear(),5)},GG:function(){return i(this.isoWeekYear()%100,2)},GGGG:function(){return this.isoWeekYear()},GGGGG:function(){return i(this.isoWeekYear(),5)},e:function(){return this.weekday()},E:function(){return this.isoWeekday()},a:function(){return this.lang().meridiem(this.hours(),this.minutes(),!0)},A:function(){return this.lang().meridiem(this.hours(),this.minutes(),!1)},H:function(){return this.hours()},h:function(){return this.hours()%12||12},m:function(){return this.minutes()},s:function(){return this.seconds()},S:function(){return q(this.milliseconds()/100)},SS:function(){return i(q(this.milliseconds()/10),2)},SSS:function(){return i(this.milliseconds(),3)},SSSS:function(){return i(this.milliseconds(),3)},Z:function(){var a=-this.zone(),b="+";return 0>a&&(a=-a,b="-"),b+i(q(a/60),2)+":"+i(q(a)%60,2)},ZZ:function(){var a=-this.zone(),b="+";return 0>a&&(a=-a,b="-"),b+i(q(10*a/6),4)},z:function(){return this.zoneAbbr()},zz:function(){return this.zoneName()},X:function(){return this.unix()}},Qb=["months","monthsShort","weekdays","weekdaysShort","weekdaysMin"];Nb.length;)cb=Nb.pop(),Pb[cb+"o"]=c(Pb[cb],cb);for(;Ob.length;)cb=Ob.pop(),Pb[cb+cb]=b(Pb[cb],2);for(Pb.DDDD=b(Pb.DDD,3),g(d.prototype,{set:function(a){var b,c;for(c in a)b=a[c],"function"==typeof b?this[c]=b:this["_"+c]=b},_months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),months:function(a){return this._months[a.month()]},_monthsShort:"Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),monthsShort:function(a){return this._monthsShort[a.month()]},monthsParse:function(a){var b,c,d;for(this._monthsParse||(this._monthsParse=[]),b=0;12>b;b++)if(this._monthsParse[b]||(c=bb.utc([2e3,b]),d="^"+this.months(c,"")+"|^"+this.monthsShort(c,""),this._monthsParse[b]=new RegExp(d.replace(".",""),"i")),this._monthsParse[b].test(a))return b},_weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),weekdays:function(a){return this._weekdays[a.day()]},_weekdaysShort:"Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),weekdaysShort:function(a){return this._weekdaysShort[a.day()]},_weekdaysMin:"Su_Mo_Tu_We_Th_Fr_Sa".split("_"),weekdaysMin:function(a){return this._weekdaysMin[a.day()]},weekdaysParse:function(a){var b,c,d;for(this._weekdaysParse||(this._weekdaysParse=[]),b=0;7>b;b++)if(this._weekdaysParse[b]||(c=bb([2e3,1]).day(b),d="^"+this.weekdays(c,"")+"|^"+this.weekdaysShort(c,"")+"|^"+this.weekdaysMin(c,""),this._weekdaysParse[b]=new RegExp(d.replace(".",""),"i")),this._weekdaysParse[b].test(a))return b},_longDateFormat:{LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D YYYY",LLL:"MMMM D YYYY LT",LLLL:"dddd, MMMM D YYYY LT"},longDateFormat:function(a){var b=this._longDateFormat[a];return!b&&this._longDateFormat[a.toUpperCase()]&&(b=this._longDateFormat[a.toUpperCase()].replace(/MMMM|MM|DD|dddd/g,function(a){return a.slice(1)}),this._longDateFormat[a]=b),b},isPM:function(a){return"p"===(a+"").toLowerCase().charAt(0)},_meridiemParse:/[ap]\.?m?\.?/i,meridiem:function(a,b,c){return a>11?c?"pm":"PM":c?"am":"AM"},_calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},calendar:function(a,b){var c=this._calendar[a];return"function"==typeof c?c.apply(b):c},_relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},relativeTime:function(a,b,c,d){var e=this._relativeTime[c];return"function"==typeof e?e(a,b,c,d):e.replace(/%d/i,a)},pastFuture:function(a,b){var c=this._relativeTime[a>0?"future":"past"];return"function"==typeof c?c(b):c.replace(/%s/i,b)},ordinal:function(a){return this._ordinal.replace("%d",a)},_ordinal:"%d",preparse:function(a){return a},postformat:function(a){return a},week:function(a){return W(a,this._week.dow,this._week.doy).week},_week:{dow:0,doy:6},_invalidDate:"Invalid date",invalidDate:function(){return this._invalidDate}}),bb=function(b,c,d,e){return"boolean"==typeof d&&(e=d,d=a),Y({_i:b,_f:c,_l:d,_strict:e,_isUTC:!1})},bb.utc=function(b,c,d,e){var f;return"boolean"==typeof d&&(e=d,d=a),f=Y({_useUTC:!0,_isUTC:!0,_l:d,_i:b,_f:c,_strict:e}).utc()},bb.unix=function(a){return bb(1e3*a)},bb.duration=function(a,b){var c,d,e,g=bb.isDuration(a),h="number"==typeof a,i=g?a._input:h?{}:a,j=null;return h?b?i[b]=a:i.milliseconds=a:(j=pb.exec(a))?(c="-"===j[1]?-1:1,i={y:0,d:q(j[hb])*c,h:q(j[ib])*c,m:q(j[jb])*c,s:q(j[kb])*c,ms:q(j[lb])*c}):(j=qb.exec(a))&&(c="-"===j[1]?-1:1,e=function(a){var b=a&&parseFloat(a.replace(",","."));return(isNaN(b)?0:b)*c},i={y:e(j[2]),M:e(j[3]),d:e(j[4]),h:e(j[5]),m:e(j[6]),s:e(j[7]),w:e(j[8])}),d=new f(i),g&&a.hasOwnProperty("_lang")&&(d._lang=a._lang),d},bb.version=db,bb.defaultFormat=Eb,bb.updateOffset=function(){},bb.lang=function(a,b){var c;return a?(b?y(x(a),b):null===b?(z(a),a="en"):mb[a]||A(a),c=bb.duration.fn._lang=bb.fn._lang=A(a),c._abbr):bb.fn._lang._abbr},bb.langData=function(a){return a&&a._lang&&a._lang._abbr&&(a=a._lang._abbr),A(a)},bb.isMoment=function(a){return a instanceof e},bb.isDuration=function(a){return a instanceof f},cb=Qb.length-1;cb>=0;--cb)p(Qb[cb]);for(bb.normalizeUnits=function(a){return n(a)},bb.invalid=function(a){var b=bb.utc(0/0);return null!=a?g(b._pf,a):b._pf.userInvalidated=!0,b},bb.parseZone=function(a){return bb(a).parseZone()},g(bb.fn=e.prototype,{clone:function(){return bb(this)},valueOf:function(){return+this._d+6e4*(this._offset||0)},unix:function(){return Math.floor(+this/1e3)},toString:function(){return this.clone().lang("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},toDate:function(){return this._offset?new Date(+this):this._d},toISOString:function(){return D(bb(this).utc(),"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]")},toArray:function(){var a=this;return[a.year(),a.month(),a.date(),a.hours(),a.minutes(),a.seconds(),a.milliseconds()]},isValid:function(){return w(this)},isDSTShifted:function(){return this._a?this.isValid()&&m(this._a,(this._isUTC?bb.utc(this._a):bb(this._a)).toArray())>0:!1},parsingFlags:function(){return g({},this._pf)},invalidAt:function(){return this._pf.overflow},utc:function(){return this.zone(0)},local:function(){return this.zone(0),this._isUTC=!1,this},format:function(a){var b=D(this,a||bb.defaultFormat);return this.lang().postformat(b)},add:function(a,b){var c;return c="string"==typeof a?bb.duration(+b,a):bb.duration(a,b),j(this,c,1),this},subtract:function(a,b){var c;return c="string"==typeof a?bb.duration(+b,a):bb.duration(a,b),j(this,c,-1),this},diff:function(a,b,c){var d,e,f=this._isUTC?bb(a).zone(this._offset||0):bb(a).local(),g=6e4*(this.zone()-f.zone());return b=n(b),"year"===b||"month"===b?(d=432e5*(this.daysInMonth()+f.daysInMonth()),e=12*(this.year()-f.year())+(this.month()-f.month()),e+=(this-bb(this).startOf("month")-(f-bb(f).startOf("month")))/d,e-=6e4*(this.zone()-bb(this).startOf("month").zone()-(f.zone()-bb(f).startOf("month").zone()))/d,"year"===b&&(e/=12)):(d=this-f,e="second"===b?d/1e3:"minute"===b?d/6e4:"hour"===b?d/36e5:"day"===b?(d-g)/864e5:"week"===b?(d-g)/6048e5:d),c?e:h(e)},from:function(a,b){return bb.duration(this.diff(a)).lang(this.lang()._abbr).humanize(!b)},fromNow:function(a){return this.from(bb(),a)},calendar:function(){var a=this.diff(bb().zone(this.zone()).startOf("day"),"days",!0),b=-6>a?"sameElse":-1>a?"lastWeek":0>a?"lastDay":1>a?"sameDay":2>a?"nextDay":7>a?"nextWeek":"sameElse";return this.format(this.lang().calendar(b,this))},isLeapYear:function(){return t(this.year())},isDST:function(){return this.zone()+bb(a).startOf(b)},isBefore:function(a,b){return b="undefined"!=typeof b?b:"millisecond",+this.clone().startOf(b)<+bb(a).startOf(b)},isSame:function(a,b){return b="undefined"!=typeof b?b:"millisecond",+this.clone().startOf(b)===+bb(a).startOf(b)},min:function(a){return a=bb.apply(null,arguments),this>a?this:a},max:function(a){return a=bb.apply(null,arguments),a>this?this:a},zone:function(a){var b=this._offset||0;return null==a?this._isUTC?b:this._d.getTimezoneOffset():("string"==typeof a&&(a=G(a)),Math.abs(a)<16&&(a=60*a),this._offset=a,this._isUTC=!0,b!==a&&j(this,bb.duration(b-a,"m"),1,!0),this)},zoneAbbr:function(){return this._isUTC?"UTC":""},zoneName:function(){return this._isUTC?"Coordinated Universal Time":""},parseZone:function(){return"string"==typeof this._i&&this.zone(this._i),this},hasAlignedHourOffset:function(a){return a=a?bb(a).zone():0,0===(this.zone()-a)%60},daysInMonth:function(){return r(this.year(),this.month())},dayOfYear:function(a){var b=eb((bb(this).startOf("day")-bb(this).startOf("year"))/864e5)+1;return null==a?b:this.add("d",a-b)},weekYear:function(a){var b=W(this,this.lang()._week.dow,this.lang()._week.doy).year;return null==a?b:this.add("y",a-b)},isoWeekYear:function(a){var b=W(this,1,4).year;return null==a?b:this.add("y",a-b)},week:function(a){var b=this.lang().week(this);return null==a?b:this.add("d",7*(a-b))},isoWeek:function(a){var b=W(this,1,4).week;return null==a?b:this.add("d",7*(a-b))},weekday:function(a){var b=(this.day()+7-this.lang()._week.dow)%7;return null==a?b:this.add("d",a-b)},isoWeekday:function(a){return null==a?this.day()||7:this.day(this.day()%7?a:a-7)},get:function(a){return a=n(a),this[a]()},set:function(a,b){return a=n(a),"function"==typeof this[a]&&this[a](b),this},lang:function(b){return b===a?this._lang:(this._lang=A(b),this)}}),cb=0;cb Date: Fri, 7 Mar 2014 12:00:31 +0000 Subject: [PATCH 08/10] Show consistent colors for different users --- services/web/app/views/templates.jade | 4 +++- services/web/public/coffee/models/User.coffee | 23 +++++++++++++++++++ .../track-changes/ChangeListView.coffee | 1 + .../coffee/track-changes/DiffView.coffee | 6 ++--- .../coffee/track-changes/models/Diff.coffee | 9 +++++++- .../public/stylesheets/less/trackchanges.less | 7 ++++++ 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index 980872b1a0..9f56e61108 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -436,7 +436,9 @@ div(class='change-description') div(class='change-date') {{date}} - div(class='change-name') {{name}} + div(class='change-name') + div.color-square(style="background-color: hsl({{hue}}, 100%, 70%);") + span {{name}} script(type='text/template')#changeListTemplate ul.change-list.nav.nav-pills.nav-stacked diff --git a/services/web/public/coffee/models/User.coffee b/services/web/public/coffee/models/User.coffee index 5c90b81d34..ad52b08fed 100644 --- a/services/web/public/coffee/models/User.coffee +++ b/services/web/public/coffee/models/User.coffee @@ -7,6 +7,29 @@ define [ email = @get("email").trim().toLowerCase() hash = CryptoJS.MD5(email) return "//www.gravatar.com/avatar/#{hash}.jpg?size=#{size}&d=mm" + + OWNER_HUE: 200 + hue: () -> + if window.user.id == @get("id") + hue = @OWNER_HUE + else + hash = CryptoJS.MD5(@get("id")) + hue = parseInt(hash.toString().slice(0,8), 16) % 320 + # Avoid 20 degrees either side of the owner + if hue > @OWNER_HUE - 20 + hue = hue + 40 + return hue + + name: () -> + parts = [] + first_name = @get("first_name") + if first_name? and first_name.length > 0 + parts.push first_name + last_name = @get("last_name") + if last_name? and last_name.length > 0 + parts.push last_name + return parts.join(" ") + }, { findOrBuild : (id, attributes) -> model = @find id diff --git a/services/web/public/coffee/track-changes/ChangeListView.coffee b/services/web/public/coffee/track-changes/ChangeListView.coffee index 296a6d0628..5b8a392bdb 100644 --- a/services/web/public/coffee/track-changes/ChangeListView.coffee +++ b/services/web/public/coffee/track-changes/ChangeListView.coffee @@ -126,6 +126,7 @@ define [ modelView: -> modelView = { + hue: @model.get("user").hue() date: moment(parseInt(@model.get("end_ts"), 10)).calendar() name: @model.get("user").get("first_name") + " " + @model.get("user").get("last_name") } diff --git a/services/web/public/coffee/track-changes/DiffView.coffee b/services/web/public/coffee/track-changes/DiffView.coffee index 4c67dde80f..48f424bb9f 100644 --- a/services/web/public/coffee/track-changes/DiffView.coffee +++ b/services/web/public/coffee/track-changes/DiffView.coffee @@ -69,12 +69,12 @@ define [ markerFrontLayer = @aceEditor.renderer.$markerFront lineHeight = @aceEditor.renderer.lineHeight if entry.i? or entry.d? - hue = 200 + hue = entry.meta.user.hue() if entry.i? @_addMarkerWithCustomStyle session, markerBackLayer, range, "deleted-change-background", false, """ background-color : hsl(#{hue}, 70%, 85%); """ - tag = "Added by #{entry.meta.user.email}" + tag = "Added by #{entry.meta.user.name()}" if entry.d? @_addMarkerWithCustomStyle session, markerBackLayer, range, "deleted-change-background", false, """ background-color : hsl(#{hue}, 70%, 95%); @@ -83,7 +83,7 @@ define [ height: #{Math.round(lineHeight/2) - 1}px; border-bottom: 2px solid hsl(#{hue}, 70%, 40%); """ - tag = "Deleted by #{entry.meta.user.email}" + tag = "Deleted by #{entry.meta.user.name()}" tag += " on #{entry.meta.end_ts}" @_addNameTag session, id, range, tag, """ diff --git a/services/web/public/coffee/track-changes/models/Diff.coffee b/services/web/public/coffee/track-changes/models/Diff.coffee index 13f3b79c10..7d301273e2 100644 --- a/services/web/public/coffee/track-changes/models/Diff.coffee +++ b/services/web/public/coffee/track-changes/models/Diff.coffee @@ -1,6 +1,13 @@ define [ + "models/User" "libs/backbone" -], ()-> +], (User) -> Diff = Backbone.Model.extend url: () -> "/project/#{@get("project_id")}/doc/#{@get("doc_id")}/diff?from=#{@get("from")}&to=#{@get("to")}" + + parse: (diff) -> + for entry in diff.diff + if entry.meta? and entry.meta.user? + entry.meta.user = User.findOrBuild(entry.meta.user.id, entry.meta.user) + return diff diff --git a/services/web/public/stylesheets/less/trackchanges.less b/services/web/public/stylesheets/less/trackchanges.less index 1d92541d09..73fb47fe04 100644 --- a/services/web/public/stylesheets/less/trackchanges.less +++ b/services/web/public/stylesheets/less/trackchanges.less @@ -80,6 +80,13 @@ font-size: 0.9em; color: #666; } + .color-square { + display: inline-block; + height: 10px; + width: 10px; + margin-right: 4px; + margin-bottom: -1px; + } &:hover { background-color: #eaeaea; } From e0cd9ba1637af9f593d4baa14d7a9284d789ae4a Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 7 Mar 2014 12:54:08 +0000 Subject: [PATCH 09/10] Improve the description above each change --- services/web/public/coffee/models/User.coffee | 2 ++ .../public/coffee/track-changes/ChangeListView.coffee | 2 +- services/web/public/coffee/track-changes/DiffView.coffee | 9 +++++---- services/web/public/stylesheets/less/trackchanges.less | 2 ++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/services/web/public/coffee/models/User.coffee b/services/web/public/coffee/models/User.coffee index ad52b08fed..1e101bee34 100644 --- a/services/web/public/coffee/models/User.coffee +++ b/services/web/public/coffee/models/User.coffee @@ -21,6 +21,8 @@ define [ return hue name: () -> + if window.user.id == @get("id") + return "you" parts = [] first_name = @get("first_name") if first_name? and first_name.length > 0 diff --git a/services/web/public/coffee/track-changes/ChangeListView.coffee b/services/web/public/coffee/track-changes/ChangeListView.coffee index 5b8a392bdb..b4cebd15bd 100644 --- a/services/web/public/coffee/track-changes/ChangeListView.coffee +++ b/services/web/public/coffee/track-changes/ChangeListView.coffee @@ -128,7 +128,7 @@ define [ modelView = { hue: @model.get("user").hue() date: moment(parseInt(@model.get("end_ts"), 10)).calendar() - name: @model.get("user").get("first_name") + " " + @model.get("user").get("last_name") + name: @model.get("user").name() } # modelView.start_ts = util.formatDate(modelView.start_ts) # modelView.end_ts = util.formatDate(modelView.end_ts) diff --git a/services/web/public/coffee/track-changes/DiffView.coffee b/services/web/public/coffee/track-changes/DiffView.coffee index 48f424bb9f..70a67dd2e6 100644 --- a/services/web/public/coffee/track-changes/DiffView.coffee +++ b/services/web/public/coffee/track-changes/DiffView.coffee @@ -85,9 +85,10 @@ define [ """ tag = "Deleted by #{entry.meta.user.name()}" - tag += " on #{entry.meta.end_ts}" + date = moment(parseInt(entry.meta.end_ts, 10)).format("Do MMM YYYY, h:mm:ss a") + tag += " on #{date}" @_addNameTag session, id, range, tag, """ - background-color : hsl(#{hue}, 70%, 85%); + background-color : hsl(#{hue}, 70%, 95%); """ _addMarkerWithCustomStyle: (session, markerLayer, range, klass, foreground, style) -> @@ -105,7 +106,7 @@ define [ id: id startRange = new Range.Range( range.start.row, range.start.column - range.start.row, session.getScreenLastRowColumn(range.start.row) + range.start.row, range.start.column + 1 ) session.addMarker startRange, "change-name-marker", (html, range, left, top, config) -> html.push """ @@ -121,7 +122,7 @@ define [
#{content}
diff --git a/services/web/public/stylesheets/less/trackchanges.less b/services/web/public/stylesheets/less/trackchanges.less index 73fb47fe04..c96e69a646 100644 --- a/services/web/public/stylesheets/less/trackchanges.less +++ b/services/web/public/stylesheets/less/trackchanges.less @@ -48,6 +48,7 @@ padding: 2px 6px; .border-radius(3px 3px 3px 3px); position: absolute; + border: 1px solid #999; left: 0; } } @@ -79,6 +80,7 @@ .change-name { font-size: 0.9em; color: #666; + text-transform: capitalize; } .color-square { display: inline-block; From 548d7d98a4cacae8a14bf1fbbce01031782243a9 Mon Sep 17 00:00:00 2001 From: James Allen Date: Fri, 7 Mar 2014 13:05:59 +0000 Subject: [PATCH 10/10] Allow history view to be closed --- services/web/app/views/templates.jade | 4 +++ .../track-changes/TrackChangesManager.coffee | 7 ++++ .../public/stylesheets/less/trackchanges.less | 32 ++++++++++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/services/web/app/views/templates.jade b/services/web/app/views/templates.jade index 9f56e61108..5f4e7574ef 100644 --- a/services/web/app/views/templates.jade +++ b/services/web/app/views/templates.jade @@ -426,6 +426,10 @@ script(type='text/template')#trackChangesPanelTemplate #trackChangesPanel .track-changes-side-bar + .track-changes-header + h3 Recent changes + a(href="#").track-changes-close + i.icon-remove .change-list-area .track-changes-diff diff --git a/services/web/public/coffee/track-changes/TrackChangesManager.coffee b/services/web/public/coffee/track-changes/TrackChangesManager.coffee index a385f56fed..58d470b51b 100644 --- a/services/web/public/coffee/track-changes/TrackChangesManager.coffee +++ b/services/web/public/coffee/track-changes/TrackChangesManager.coffee @@ -12,6 +12,13 @@ define [ $("#editorWrapper").append(@$el) @hideEl() + @ide.editor.on "change:doc", () => + @hideEl() + + @$el.find(".track-changes-close").on "click", (e) => + e.preventDefault + @hideEl() + show: () -> @project_id = window.userSettings.project_id @doc_id = @ide.editor.current_doc_id diff --git a/services/web/public/stylesheets/less/trackchanges.less b/services/web/public/stylesheets/less/trackchanges.less index c96e69a646..c43bb55ab9 100644 --- a/services/web/public/stylesheets/less/trackchanges.less +++ b/services/web/public/stylesheets/less/trackchanges.less @@ -26,15 +26,31 @@ position: absolute; right: 0; background-color: white; - } - .change-list-area { - overflow: scroll; - position: absolute; - left: 0px; - right: 0px; - top: 0px; - bottom: 0px; + .track-changes-header { + background-color: black; + h3 { + color: white; + padding-left: 8px; + font-size: 1.2em; + } + a { + color: white; + position: absolute; + top: 6px; + right: 8px; + } + height: 30px; + } + + .change-list-area { + overflow: scroll; + position: absolute; + left: 0px; + right: 0px; + top: 30px; + bottom: 0px; + } } .deleted-change-background, .deleted-change-foreground, .inserted-change, .change-name-marker {