overleaf/services/web/public/coffee/ide.coffee

172 lines
5.1 KiB
CoffeeScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
define [
"base"
"ide/file-tree/FileTreeManager"
"ide/connection/ConnectionManager"
"ide/editor/EditorManager"
"ide/online-users/OnlineUsersManager"
"ide/history/HistoryManager"
"ide/permissions/PermissionsManager"
"ide/pdf/PdfManager"
"ide/binary-files/BinaryFilesManager"
"ide/references/ReferencesManager"
"ide/review-panel/ReviewPanelManager"
2016-07-29 12:24:55 -04:00
"ide/SafariScrollPatcher"
2016-10-20 11:39:43 -04:00
"ide/FeatureOnboardingController"
"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"
2015-09-14 10:28:19 -04:00
"ide/wordcount/index"
"ide/directives/layout"
"ide/services/ide"
"__IDE_CLIENTSIDE_INCLUDES__"
2014-09-02 08:19:59 -04:00
"analytics/AbTestingManager"
"directives/focus"
"directives/fineUpload"
2014-07-08 07:32:50 -04:00
"directives/scroll"
"directives/onEnter"
"directives/stopPropagation"
"directives/rightClick"
"directives/expandableTextArea"
"directives/videoPlayState"
"services/queued-http"
"filters/formatDate"
2015-03-17 15:14:55 -04:00
"main/event"
"main/account-upgrade"
2014-02-12 05:23:40 -05:00
], (
App
FileTreeManager
ConnectionManager
EditorManager
OnlineUsersManager
HistoryManager
PermissionsManager
PdfManager
BinaryFilesManager
ReferencesManager
ReviewPanelManager
2016-07-29 12:24:55 -04:00
SafariScrollPatcher
2014-02-12 05:23:40 -05:00
) ->
2016-09-27 11:01:56 -04:00
App.controller "IdeController", ($scope, $timeout, ide, localStorage, sixpack, event_tracking) ->
# 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()
else
this.$originalApply(fn);
$scope.state = {
loading: true
load_progress: 40
error: null
}
$scope.ui = {
leftMenuShown: false
view: "editor"
chatOpen: false
2014-07-22 08:33:01 -04:00
pdfLayout: 'sideBySide'
reviewPanelOpen: localStorage("ui.reviewPanelOpen.#{window.project_id}")
}
$scope.user = window.user
$scope.shouldABTestPlans = false
2016-10-27 04:41:51 -04:00
if $scope.user.signUpDate >= '2016-10-27'
$scope.shouldABTestPlans = true
$scope.settings = window.userSettings
2014-07-21 06:56:49 -04:00
$scope.anonymous = window.anonymous
$scope.chat = {}
2014-09-01 12:48:09 -04:00
ide.toggleReviewPanel = $scope.toggleReviewPanel = () ->
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 }
$scope.$watch "ui.reviewPanelOpen", (value) ->
if value?
localStorage "ui.reviewPanelOpen.#{window.project_id}", value
2016-07-05 10:07:16 -04:00
# Tracking code.
$scope.$watch "ui.view", (newView, oldView) ->
if newView? and newView != "editor" and newView != "pdf"
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.
window._ide = ide
ide.validFileRegex = '^[^\*\/]*$' # Don't allow * and /
ide.project_id = $scope.project_id = window.project_id
ide.$scope = $scope
ide.referencesSearchManager = new ReferencesManager(ide, $scope)
ide.connectionManager = new ConnectionManager(ide, $scope)
ide.fileTreeManager = new FileTreeManager(ide, $scope)
ide.editorManager = new EditorManager(ide, $scope)
ide.onlineUsersManager = new OnlineUsersManager(ide, $scope)
ide.historyManager = new HistoryManager(ide, $scope)
ide.pdfManager = new PdfManager(ide, $scope)
ide.permissionsManager = new PermissionsManager(ide, $scope)
ide.binaryFilesManager = new BinaryFilesManager(ide, $scope)
2014-07-24 11:39:32 -04:00
inited = false
$scope.$on "project:joined", () ->
return if inited
inited = true
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.
""")
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
$scope.$watch "settings.theme", (theme) ->
if theme in DARK_THEMES
$scope.darkTheme = true
else
$scope.darkTheme = false
ide.localStorage = localStorage
ide.browserIsSafari = false
try
userAgent = navigator.userAgent
ide.browserIsSafari = (
userAgent &&
userAgent.match(/.*Safari\/.*/) &&
!userAgent.match(/.*Chrome\/.*/) &&
!userAgent.match(/.*Chromium\/.*/)
)
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
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]
angular.bootstrap(document.body, ["SharelatexApp"])