2014-02-12 05:23:40 -05:00
|
|
|
define [
|
2014-07-08 07:01:32 -04:00
|
|
|
"base"
|
|
|
|
"ide/file-tree/FileTreeManager"
|
|
|
|
"ide/connection/ConnectionManager"
|
|
|
|
"ide/editor/EditorManager"
|
|
|
|
"ide/online-users/OnlineUsersManager"
|
2016-10-05 06:04:39 -04:00
|
|
|
"ide/history/HistoryManager"
|
2017-12-13 11:11:12 -05:00
|
|
|
"ide/history/HistoryV2Manager"
|
2014-07-08 07:01:32 -04:00
|
|
|
"ide/permissions/PermissionsManager"
|
2014-12-01 09:35:12 -05:00
|
|
|
"ide/pdf/PdfManager"
|
2014-07-08 07:01:32 -04:00
|
|
|
"ide/binary-files/BinaryFilesManager"
|
2016-02-08 12:04:27 -05:00
|
|
|
"ide/references/ReferencesManager"
|
2017-10-12 10:33:14 -04:00
|
|
|
"ide/metadata/MetadataManager"
|
2016-10-12 12:27:20 -04:00
|
|
|
"ide/review-panel/ReviewPanelManager"
|
2016-07-29 12:24:55 -04:00
|
|
|
"ide/SafariScrollPatcher"
|
2014-07-08 07:01:32 -04:00
|
|
|
"ide/settings/index"
|
|
|
|
"ide/share/index"
|
|
|
|
"ide/chat/index"
|
2014-07-17 09:04:21 -04:00
|
|
|
"ide/clone/index"
|
2014-07-22 09:38:32 -04:00
|
|
|
"ide/hotkeys/index"
|
2018-05-23 07:37:42 -04:00
|
|
|
"ide/test-controls/index"
|
2015-09-14 10:28:19 -04:00
|
|
|
"ide/wordcount/index"
|
2014-07-08 07:01:32 -04:00
|
|
|
"ide/directives/layout"
|
2018-02-05 11:56:52 -05:00
|
|
|
"ide/directives/validFile"
|
2014-07-08 07:01:32 -04:00
|
|
|
"ide/services/ide"
|
2014-09-08 12:33:30 -04:00
|
|
|
"__IDE_CLIENTSIDE_INCLUDES__"
|
2014-09-02 08:19:59 -04:00
|
|
|
"analytics/AbTestingManager"
|
2014-07-08 07:01:32 -04:00
|
|
|
"directives/focus"
|
|
|
|
"directives/fineUpload"
|
2014-07-08 07:32:50 -04:00
|
|
|
"directives/scroll"
|
2014-07-08 07:01:32 -04:00
|
|
|
"directives/onEnter"
|
2014-07-31 09:20:56 -04:00
|
|
|
"directives/stopPropagation"
|
|
|
|
"directives/rightClick"
|
2017-01-25 08:51:33 -05:00
|
|
|
"directives/expandableTextArea"
|
2017-02-09 10:44:15 -05:00
|
|
|
"directives/videoPlayState"
|
2016-02-09 10:13:58 -05:00
|
|
|
"services/queued-http"
|
2017-12-11 07:32:43 -05:00
|
|
|
"services/validateCaptcha"
|
2018-05-25 08:02:58 -04:00
|
|
|
"services/wait-for"
|
2014-07-08 07:01:32 -04:00
|
|
|
"filters/formatDate"
|
2015-03-17 15:14:55 -04:00
|
|
|
"main/event"
|
2014-11-24 18:59:55 -05:00
|
|
|
"main/account-upgrade"
|
2014-02-12 05:23:40 -05:00
|
|
|
], (
|
2014-07-08 07:01:32 -04:00
|
|
|
App
|
|
|
|
FileTreeManager
|
|
|
|
ConnectionManager
|
|
|
|
EditorManager
|
|
|
|
OnlineUsersManager
|
2016-10-05 06:04:39 -04:00
|
|
|
HistoryManager
|
2017-12-13 11:11:12 -05:00
|
|
|
HistoryV2Manager
|
2014-07-08 07:01:32 -04:00
|
|
|
PermissionsManager
|
|
|
|
PdfManager
|
|
|
|
BinaryFilesManager
|
2016-02-08 12:04:27 -05:00
|
|
|
ReferencesManager
|
2017-10-12 10:33:14 -04:00
|
|
|
MetadataManager
|
2016-10-12 12:27:20 -04:00
|
|
|
ReviewPanelManager
|
2016-07-29 12:24:55 -04:00
|
|
|
SafariScrollPatcher
|
2014-02-12 05:23:40 -05:00
|
|
|
) ->
|
2014-11-24 18:59:55 -05:00
|
|
|
|
2018-05-25 06:42:13 -04:00
|
|
|
App.controller "IdeController", ($scope, $timeout, ide, localStorage, sixpack, event_tracking, metadata, $q) ->
|
2014-07-08 07:01:32 -04:00
|
|
|
# Don't freak out if we're already in an apply callback
|
|
|
|
$scope.$originalApply = $scope.$apply
|
|
|
|
$scope.$apply = (fn = () ->) ->
|
|
|
|
phase = @$root.$$phase
|
|
|
|
if (phase == '$apply' || phase == '$digest')
|
|
|
|
fn()
|
2014-03-31 04:47:36 -04:00
|
|
|
else
|
2014-07-08 07:01:32 -04:00
|
|
|
this.$originalApply(fn);
|
|
|
|
|
|
|
|
$scope.state = {
|
|
|
|
loading: true
|
|
|
|
load_progress: 40
|
2015-03-09 09:57:13 -04:00
|
|
|
error: null
|
2014-07-08 07:01:32 -04:00
|
|
|
}
|
|
|
|
$scope.ui = {
|
|
|
|
leftMenuShown: false
|
|
|
|
view: "editor"
|
|
|
|
chatOpen: false
|
2014-07-22 08:33:01 -04:00
|
|
|
pdfLayout: 'sideBySide'
|
2017-10-12 10:33:14 -04:00
|
|
|
pdfHidden: false
|
|
|
|
pdfWidth: 0
|
|
|
|
reviewPanelOpen: localStorage("ui.reviewPanelOpen.#{window.project_id}")
|
|
|
|
miniReviewPanelVisible: false
|
2017-11-30 10:24:48 -05:00
|
|
|
chatResizerSizeOpen: window.uiConfig.chatResizerSizeOpen
|
|
|
|
chatResizerSizeClosed: window.uiConfig.chatResizerSizeClosed
|
2018-05-10 13:03:54 -04:00
|
|
|
defaultFontFamily: window.uiConfig.defaultFontFamily
|
|
|
|
defaultLineHeight: window.uiConfig.defaultLineHeight
|
2014-07-08 07:01:32 -04:00
|
|
|
}
|
|
|
|
$scope.user = window.user
|
2017-09-25 10:46:29 -04:00
|
|
|
|
2014-07-08 07:01:32 -04:00
|
|
|
$scope.settings = window.userSettings
|
2014-07-21 06:56:49 -04:00
|
|
|
$scope.anonymous = window.anonymous
|
2017-10-25 05:34:18 -04:00
|
|
|
$scope.isTokenMember = window.isTokenMember
|
2014-07-08 07:01:32 -04:00
|
|
|
|
|
|
|
$scope.chat = {}
|
2014-09-01 12:48:09 -04:00
|
|
|
|
2016-11-08 11:43:01 -05:00
|
|
|
ide.toggleReviewPanel = $scope.toggleReviewPanel = () ->
|
2017-08-03 10:17:28 -04:00
|
|
|
if !$scope.project.features.trackChangesVisible
|
|
|
|
return
|
2016-10-11 09:24:01 -04:00
|
|
|
$scope.ui.reviewPanelOpen = !$scope.ui.reviewPanelOpen
|
2017-01-17 09:39:31 -05:00
|
|
|
event_tracking.sendMB "rp-toggle-panel", { value : $scope.ui.reviewPanelOpen }
|
2016-11-08 11:43:01 -05:00
|
|
|
|
|
|
|
$scope.$watch "ui.reviewPanelOpen", (value) ->
|
|
|
|
if value?
|
|
|
|
localStorage "ui.reviewPanelOpen.#{window.project_id}", value
|
2016-09-27 06:50:34 -04:00
|
|
|
|
2017-09-25 10:46:29 -04:00
|
|
|
$scope.$on "layout:pdf:resize", (_, layoutState) ->
|
|
|
|
$scope.ui.pdfHidden = layoutState.east.initClosed
|
2017-09-28 06:31:55 -04:00
|
|
|
$scope.ui.pdfWidth = layoutState.east.size
|
2017-09-25 10:46:29 -04:00
|
|
|
|
2016-07-05 10:07:16 -04:00
|
|
|
# Tracking code.
|
|
|
|
$scope.$watch "ui.view", (newView, oldView) ->
|
2016-07-26 12:04:06 -04:00
|
|
|
if newView? and newView != "editor" and newView != "pdf"
|
2016-10-13 08:47:05 -04:00
|
|
|
event_tracking.sendMBOnce "ide-open-view-#{ newView }-once"
|
2016-07-05 10:07:16 -04:00
|
|
|
|
|
|
|
$scope.$watch "ui.chatOpen", (isOpen) ->
|
2016-08-10 12:29:43 -04:00
|
|
|
event_tracking.sendMBOnce "ide-open-chat-once" if isOpen
|
2016-07-05 10:07:16 -04:00
|
|
|
|
|
|
|
$scope.$watch "ui.leftMenuShown", (isOpen) ->
|
2016-08-10 12:29:43 -04:00
|
|
|
event_tracking.sendMBOnce "ide-open-left-menu-once" if isOpen
|
2016-08-03 07:17:19 -04:00
|
|
|
|
|
|
|
$scope.trackHover = (feature) ->
|
2016-08-10 12:29:43 -04:00
|
|
|
event_tracking.sendMBOnce "ide-hover-#{feature}-once"
|
2016-07-05 10:07:16 -04:00
|
|
|
# End of tracking code.
|
2016-01-18 05:29:13 -05:00
|
|
|
|
2014-07-08 07:01:32 -04:00
|
|
|
window._ide = ide
|
2016-10-13 08:47:05 -04:00
|
|
|
|
2016-09-21 11:31:02 -04:00
|
|
|
ide.validFileRegex = '^[^\*\/]*$' # Don't allow * and /
|
2014-07-08 07:01:32 -04:00
|
|
|
|
|
|
|
ide.project_id = $scope.project_id = window.project_id
|
|
|
|
ide.$scope = $scope
|
|
|
|
|
2016-02-08 12:04:27 -05:00
|
|
|
ide.referencesSearchManager = new ReferencesManager(ide, $scope)
|
2014-07-08 07:01:32 -04:00
|
|
|
ide.connectionManager = new ConnectionManager(ide, $scope)
|
|
|
|
ide.fileTreeManager = new FileTreeManager(ide, $scope)
|
2018-07-10 10:37:52 -04:00
|
|
|
ide.editorManager = new EditorManager(ide, $scope, localStorage)
|
2014-07-08 07:01:32 -04:00
|
|
|
ide.onlineUsersManager = new OnlineUsersManager(ide, $scope)
|
2017-12-13 11:11:12 -05:00
|
|
|
if window.data.useV2History
|
|
|
|
ide.historyManager = new HistoryV2Manager(ide, $scope)
|
|
|
|
else
|
|
|
|
ide.historyManager = new HistoryManager(ide, $scope)
|
2014-07-08 07:01:32 -04:00
|
|
|
ide.pdfManager = new PdfManager(ide, $scope)
|
|
|
|
ide.permissionsManager = new PermissionsManager(ide, $scope)
|
|
|
|
ide.binaryFilesManager = new BinaryFilesManager(ide, $scope)
|
2017-10-12 10:33:14 -04:00
|
|
|
ide.metadataManager = new MetadataManager(ide, $scope, metadata)
|
2015-12-17 10:13:02 -05:00
|
|
|
|
2014-07-24 11:39:32 -04:00
|
|
|
inited = false
|
|
|
|
$scope.$on "project:joined", () ->
|
|
|
|
return if inited
|
|
|
|
inited = true
|
2015-02-23 12:33:05 -05:00
|
|
|
if $scope?.project?.deletedByExternalDataSource
|
2014-07-24 11:39:32 -04:00
|
|
|
ide.showGenericMessageModal("Project Renamed or Deleted", """
|
|
|
|
This project has either been renamed or deleted by an external data source such as Dropbox.
|
|
|
|
We don't want to delete your data on ShareLaTeX, so this project still contains your history and collaborators.
|
|
|
|
If the project has been renamed please look in your project list for a new project under the new name.
|
|
|
|
""")
|
2017-06-14 08:26:02 -04:00
|
|
|
$timeout(
|
|
|
|
() ->
|
|
|
|
if $scope.permissions.write
|
2017-10-12 10:33:14 -04:00
|
|
|
ide.metadataManager.loadProjectMetaFromServer()
|
2017-06-14 08:26:02 -04:00
|
|
|
_labelsInitialLoadDone = true
|
|
|
|
, 200
|
|
|
|
)
|
2016-02-08 12:04:27 -05:00
|
|
|
|
2017-11-09 10:12:55 -05:00
|
|
|
# Count the first 'doc:opened' as a sign that the ide is loaded
|
|
|
|
# and broadcast a message. This is a good event to listen for
|
|
|
|
# if you want to wait until the ide is fully loaded and initialized
|
|
|
|
_loaded = false
|
|
|
|
$scope.$on 'doc:opened', () ->
|
|
|
|
if _loaded
|
|
|
|
return
|
|
|
|
$scope.$broadcast('ide:loaded')
|
|
|
|
_loaded = true
|
|
|
|
|
2018-01-24 12:20:30 -05:00
|
|
|
$scope.$on 'cursor:editor:update', event_tracking.editingSessionHeartbeat
|
|
|
|
|
2014-07-28 10:06:26 -04:00
|
|
|
DARK_THEMES = [
|
|
|
|
"ambiance", "chaos", "clouds_midnight", "cobalt", "idle_fingers",
|
|
|
|
"merbivore", "merbivore_soft", "mono_industrial", "monokai",
|
|
|
|
"pastel_on_dark", "solarized_dark", "terminal", "tomorrow_night",
|
|
|
|
"tomorrow_night_blue", "tomorrow_night_bright", "tomorrow_night_eighties",
|
|
|
|
"twilight", "vibrant_ink"
|
|
|
|
]
|
|
|
|
$scope.darkTheme = false
|
2018-08-27 10:25:00 -04:00
|
|
|
$scope.$watch "settings.editorTheme", (theme) ->
|
2014-07-28 10:06:26 -04:00
|
|
|
if theme in DARK_THEMES
|
|
|
|
$scope.darkTheme = true
|
|
|
|
else
|
|
|
|
$scope.darkTheme = false
|
2014-07-08 07:01:32 -04:00
|
|
|
|
2015-02-12 06:32:27 -05:00
|
|
|
ide.localStorage = localStorage
|
|
|
|
|
2016-04-11 09:35:59 -04:00
|
|
|
ide.browserIsSafari = false
|
|
|
|
try
|
|
|
|
userAgent = navigator.userAgent
|
|
|
|
ide.browserIsSafari = (
|
|
|
|
userAgent &&
|
2018-08-27 14:25:01 -04:00
|
|
|
/.*Safari\/.*/.test(userAgent) &&
|
|
|
|
!/.*Chrome\/.*/.test(userAgent) &&
|
2018-08-27 16:48:44 -04:00
|
|
|
!/.*Chromium\/.*/.test(userAgent)
|
2016-04-11 09:35:59 -04:00
|
|
|
)
|
|
|
|
catch err
|
|
|
|
console.error err
|
|
|
|
|
2016-07-29 12:24:55 -04:00
|
|
|
if ide.browserIsSafari
|
2016-08-01 06:12:50 -04:00
|
|
|
ide.safariScrollPatcher = new SafariScrollPatcher($scope)
|
2016-07-29 12:24:55 -04:00
|
|
|
|
2017-09-28 09:01:03 -04:00
|
|
|
# Fix Chrome 61 and 62 text-shadow rendering
|
|
|
|
browserIsChrome61or62 = false
|
|
|
|
try
|
|
|
|
chromeVersion = parseFloat(navigator.userAgent.split(" Chrome/")[1]) || null;
|
|
|
|
browserIsChrome61or62 = (
|
2018-06-06 12:19:12 -04:00
|
|
|
chromeVersion?
|
2017-09-28 09:01:03 -04:00
|
|
|
)
|
|
|
|
if browserIsChrome61or62
|
2018-06-06 12:19:12 -04:00
|
|
|
document.styleSheets[0].insertRule(".ace_editor.ace_autocomplete .ace_completion-highlight { text-shadow: none !important; font-weight: bold; }", 1)
|
2017-09-28 09:01:03 -04:00
|
|
|
catch err
|
|
|
|
console.error err
|
|
|
|
|
|
|
|
|
2016-04-19 06:53:27 -04:00
|
|
|
# User can append ?ft=somefeature to url to activate a feature toggle
|
|
|
|
ide.featureToggle = location?.search?.match(/^\?ft=(\w+)$/)?[1]
|
|
|
|
|
2017-10-26 06:04:00 -04:00
|
|
|
ide.socket.on 'project:publicAccessLevel:changed', (data) =>
|
|
|
|
if data.newAccessLevel?
|
|
|
|
ide.$scope.project.publicAccesLevel = data.newAccessLevel
|
|
|
|
$scope.$digest()
|
|
|
|
|
2014-12-01 09:35:12 -05:00
|
|
|
angular.bootstrap(document.body, ["SharelatexApp"])
|