2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-useless-escape,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../base'
|
|
|
|
import 'libs/jquery-layout'
|
|
|
|
import 'libs/jquery.ui.touch-punch'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
export default App.directive('layout', ($parse, $compile, ide) => ({
|
|
|
|
compile() {
|
|
|
|
return {
|
|
|
|
pre(scope, element, attrs) {
|
|
|
|
let customTogglerEl, spacingClosed, spacingOpen, state
|
|
|
|
const name = attrs.layout
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const { customTogglerPane } = attrs
|
|
|
|
const { customTogglerMsgWhenOpen } = attrs
|
|
|
|
const { customTogglerMsgWhenClosed } = attrs
|
|
|
|
const hasCustomToggler =
|
|
|
|
customTogglerPane != null &&
|
|
|
|
customTogglerMsgWhenOpen != null &&
|
|
|
|
customTogglerMsgWhenClosed != null
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.spacingOpen != null) {
|
|
|
|
spacingOpen = parseInt(attrs.spacingOpen, 10)
|
|
|
|
} else {
|
|
|
|
spacingOpen = window.uiConfig.defaultResizerSizeOpen
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.spacingClosed != null) {
|
|
|
|
spacingClosed = parseInt(attrs.spacingClosed, 10)
|
|
|
|
} else {
|
|
|
|
spacingClosed = window.uiConfig.defaultResizerSizeClosed
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
spacing_open: spacingOpen,
|
|
|
|
spacing_closed: spacingClosed,
|
|
|
|
slidable: false,
|
|
|
|
enableCursorHotkey: false,
|
|
|
|
onopen: pane => {
|
|
|
|
return onPaneOpen(pane)
|
|
|
|
},
|
|
|
|
onclose: pane => {
|
|
|
|
return onPaneClose(pane)
|
|
|
|
},
|
|
|
|
onresize: () => {
|
|
|
|
return onInternalResize()
|
|
|
|
},
|
|
|
|
maskIframesOnResize: scope.$eval(
|
|
|
|
attrs.maskIframesOnResize || 'false'
|
|
|
|
),
|
|
|
|
east: {
|
|
|
|
size: scope.$eval(attrs.initialSizeEast),
|
|
|
|
initClosed: scope.$eval(attrs.initClosedEast)
|
|
|
|
},
|
|
|
|
west: {
|
|
|
|
size: scope.$eval(attrs.initialSizeEast),
|
|
|
|
initClosed: scope.$eval(attrs.initClosedWest)
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Restore previously recorded state
|
|
|
|
if ((state = ide.localStorage(`layout.${name}`)) != null) {
|
|
|
|
if (state.east != null) {
|
|
|
|
if (
|
|
|
|
attrs.minimumRestoreSizeEast == null ||
|
|
|
|
(state.east.size >= attrs.minimumRestoreSizeEast &&
|
|
|
|
!state.east.initClosed)
|
|
|
|
) {
|
|
|
|
options.east = state.east
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
if (state.west != null) {
|
|
|
|
if (
|
|
|
|
attrs.minimumRestoreSizeWest == null ||
|
|
|
|
(state.west.size >= attrs.minimumRestoreSizeWest &&
|
|
|
|
!state.west.initClosed)
|
|
|
|
) {
|
|
|
|
options.west = state.west
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (window.uiConfig.eastResizerCursor != null) {
|
|
|
|
options.east.resizerCursor = window.uiConfig.eastResizerCursor
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (window.uiConfig.westResizerCursor != null) {
|
|
|
|
options.west.resizerCursor = window.uiConfig.westResizerCursor
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const repositionControls = function() {
|
|
|
|
state = element.layout().readState()
|
|
|
|
if (state.east != null) {
|
|
|
|
const controls = element.find('> .ui-layout-resizer-controls')
|
|
|
|
if (state.east.initClosed) {
|
|
|
|
return controls.hide()
|
|
|
|
} else {
|
|
|
|
controls.show()
|
|
|
|
return controls.css({
|
|
|
|
right: state.east.size
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const repositionCustomToggler = function() {
|
|
|
|
if (customTogglerEl == null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
state = element.layout().readState()
|
|
|
|
const positionAnchor = customTogglerPane === 'east' ? 'right' : 'left'
|
|
|
|
const paneState = state[customTogglerPane]
|
|
|
|
if (paneState != null) {
|
|
|
|
return customTogglerEl.css(
|
|
|
|
positionAnchor,
|
|
|
|
paneState.initClosed ? 0 : paneState.size
|
|
|
|
)
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const resetOpenStates = function() {
|
|
|
|
state = element.layout().readState()
|
|
|
|
if (attrs.openEast != null && state.east != null) {
|
|
|
|
const openEast = $parse(attrs.openEast)
|
|
|
|
return openEast.assign(scope, !state.east.initClosed)
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Someone moved the resizer
|
|
|
|
var onInternalResize = function() {
|
|
|
|
state = element.layout().readState()
|
|
|
|
scope.$broadcast(`layout:${name}:resize`, state)
|
|
|
|
repositionControls()
|
|
|
|
if (hasCustomToggler) {
|
|
|
|
repositionCustomToggler()
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return resetOpenStates()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
let oldWidth = element.width()
|
|
|
|
// Something resized our parent element
|
|
|
|
const onExternalResize = function() {
|
|
|
|
if (
|
|
|
|
attrs.resizeProportionally != null &&
|
|
|
|
scope.$eval(attrs.resizeProportionally)
|
|
|
|
) {
|
|
|
|
const eastState = element.layout().readState().east
|
|
|
|
if (eastState != null) {
|
|
|
|
const newInternalWidth =
|
|
|
|
(eastState.size / oldWidth) * element.width()
|
|
|
|
oldWidth = element.width()
|
|
|
|
element.layout().sizePane('east', newInternalWidth)
|
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return element.layout().resizeAll()
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
element.layout(options)
|
|
|
|
element.layout().resizeAll()
|
|
|
|
|
|
|
|
if (attrs.resizeOn != null) {
|
|
|
|
for (let event of Array.from(attrs.resizeOn.split(','))) {
|
|
|
|
scope.$on(event, () => onExternalResize())
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (hasCustomToggler) {
|
|
|
|
state = element.layout().readState()
|
|
|
|
const customTogglerScope = scope.$new()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
customTogglerScope.isOpen = true
|
|
|
|
customTogglerScope.isVisible = true
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (
|
|
|
|
(state[customTogglerPane] != null
|
|
|
|
? state[customTogglerPane].initClosed
|
|
|
|
: undefined) === true
|
|
|
|
) {
|
|
|
|
customTogglerScope.isOpen = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
customTogglerScope.tooltipMsgWhenOpen = customTogglerMsgWhenOpen
|
|
|
|
customTogglerScope.tooltipMsgWhenClosed = customTogglerMsgWhenClosed
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
customTogglerScope.tooltipPlacement =
|
|
|
|
customTogglerPane === 'east' ? 'left' : 'right'
|
|
|
|
customTogglerScope.handleClick = function() {
|
|
|
|
element.layout().toggle(customTogglerPane)
|
|
|
|
return repositionCustomToggler()
|
|
|
|
}
|
|
|
|
customTogglerEl = $compile(`\
|
2018-11-05 05:06:39 -05:00
|
|
|
<a href \
|
|
|
|
ng-show=\"isVisible\" \
|
|
|
|
class=\"custom-toggler ${`custom-toggler-${customTogglerPane}`}\" \
|
|
|
|
ng-class=\"isOpen ? 'custom-toggler-open' : 'custom-toggler-closed'\" \
|
|
|
|
tooltip=\"{{ isOpen ? tooltipMsgWhenOpen : tooltipMsgWhenClosed }}\" \
|
|
|
|
tooltip-placement=\"{{ tooltipPlacement }}\" \
|
|
|
|
ng-click=\"handleClick()\">\
|
|
|
|
`)(customTogglerScope)
|
2020-05-19 05:02:56 -04:00
|
|
|
element.append(customTogglerEl)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
var onPaneOpen = function(pane) {
|
|
|
|
if (!hasCustomToggler && pane !== customTogglerPane) {
|
|
|
|
return
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return customTogglerEl
|
|
|
|
.scope()
|
|
|
|
.$applyAsync(() => (customTogglerEl.scope().isOpen = true))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
var onPaneClose = function(pane) {
|
|
|
|
if (!hasCustomToggler && pane !== customTogglerPane) {
|
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return customTogglerEl
|
|
|
|
.scope()
|
|
|
|
.$applyAsync(() => (customTogglerEl.scope().isOpen = false))
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Save state when exiting
|
|
|
|
$(window).unload(() =>
|
|
|
|
ide.localStorage(`layout.${name}`, element.layout().readState())
|
|
|
|
)
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.openEast != null) {
|
|
|
|
scope.$watch(attrs.openEast, function(value, oldValue) {
|
|
|
|
if (value != null && value !== oldValue) {
|
2019-07-16 05:13:18 -04:00
|
|
|
if (value) {
|
2020-05-19 05:02:56 -04:00
|
|
|
element.layout().open('east')
|
2019-07-16 05:13:18 -04:00
|
|
|
} else {
|
2020-05-19 05:02:56 -04:00
|
|
|
element.layout().close('east')
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
return setTimeout(() => scope.$digest(), 0)
|
|
|
|
})
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.allowOverflowOn != null) {
|
|
|
|
const layoutObj = element.layout()
|
|
|
|
const overflowPane = scope.$eval(attrs.allowOverflowOn)
|
|
|
|
const overflowPaneEl = layoutObj.panes[overflowPane]
|
|
|
|
// Set the panel as overflowing (gives it higher z-index and sets overflow rules)
|
|
|
|
layoutObj.allowOverflow(overflowPane)
|
|
|
|
// Read the given z-index value and increment it, so that it's higher than synctex controls.
|
|
|
|
const overflowPaneZVal = overflowPaneEl.zIndex()
|
|
|
|
overflowPaneEl.css('z-index', overflowPaneZVal + 1)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
|
|
|
resetOpenStates()
|
|
|
|
onInternalResize()
|
|
|
|
|
|
|
|
if (attrs.layoutDisabled != null) {
|
|
|
|
return scope.$watch(attrs.layoutDisabled, function(value) {
|
|
|
|
if (value) {
|
|
|
|
element.layout().hide('east')
|
|
|
|
} else {
|
|
|
|
element.layout().show('east')
|
|
|
|
}
|
|
|
|
if (hasCustomToggler) {
|
|
|
|
return customTogglerEl.scope().$applyAsync(function() {
|
|
|
|
customTogglerEl.scope().isOpen = !value
|
|
|
|
return (customTogglerEl.scope().isVisible = !value)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
post(scope, element, attrs) {
|
|
|
|
const name = attrs.layout
|
|
|
|
const state = element.layout().readState()
|
|
|
|
return scope.$broadcast(`layout:${name}:linked`, state)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
}))
|