2014-07-08 07:02:26 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
"libs/jquery-layout"
|
|
|
|
], (App) ->
|
2018-03-20 11:08:34 -04:00
|
|
|
App.directive "layout", ["$parse", "$compile", "ide", ($parse, $compile, ide) ->
|
2014-07-08 07:02:26 -04:00
|
|
|
return {
|
|
|
|
compile: () ->
|
|
|
|
pre: (scope, element, attrs) ->
|
|
|
|
name = attrs.layout
|
|
|
|
|
2018-03-20 11:08:34 -04:00
|
|
|
customTogglerPane = scope.$eval(attrs.customTogglerPane)
|
2018-03-20 12:06:44 -04:00
|
|
|
customTogglerMsgWhenOpen = scope.$eval(attrs.customTogglerMsgWhenOpen)
|
|
|
|
customTogglerMsgWhenClosed = scope.$eval(attrs.customTogglerMsgWhenClosed)
|
|
|
|
hasCustomToggler = customTogglerPane? and customTogglerMsgWhenOpen? and customTogglerMsgWhenClosed?
|
2018-03-20 11:08:34 -04:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
if attrs.spacingOpen?
|
|
|
|
spacingOpen = parseInt(attrs.spacingOpen, 10)
|
|
|
|
else
|
2017-11-30 10:24:39 -05:00
|
|
|
spacingOpen = window.uiConfig.defaultResizerSizeOpen
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
if attrs.spacingClosed?
|
|
|
|
spacingClosed = parseInt(attrs.spacingClosed, 10)
|
|
|
|
else
|
2017-11-30 10:24:39 -05:00
|
|
|
spacingClosed = window.uiConfig.defaultResizerSizeClosed
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
options =
|
|
|
|
spacing_open: spacingOpen
|
|
|
|
spacing_closed: spacingClosed
|
|
|
|
slidable: false
|
2014-10-27 10:47:06 -04:00
|
|
|
enableCursorHotkey: false
|
2018-03-20 12:02:01 -04:00
|
|
|
onopen: (pane) =>
|
|
|
|
onPaneOpen(pane)
|
|
|
|
onclose: (pane) =>
|
|
|
|
onPaneClose(pane)
|
2014-07-08 07:02:26 -04:00
|
|
|
onresize: () =>
|
|
|
|
onInternalResize()
|
|
|
|
maskIframesOnResize: scope.$eval(
|
|
|
|
attrs.maskIframesOnResize or "false"
|
|
|
|
)
|
|
|
|
east:
|
|
|
|
size: scope.$eval(attrs.initialSizeEast)
|
|
|
|
initClosed: scope.$eval(attrs.initClosedEast)
|
|
|
|
west:
|
|
|
|
size: scope.$eval(attrs.initialSizeEast)
|
|
|
|
initClosed: scope.$eval(attrs.initClosedWest)
|
|
|
|
|
|
|
|
# Restore previously recorded state
|
2015-02-12 06:32:27 -05:00
|
|
|
if (state = ide.localStorage("layout.#{name}"))?
|
2016-02-23 10:21:22 -05:00
|
|
|
if state.east?
|
|
|
|
if !attrs.minimumRestoreSizeEast? or (state.east.size >= attrs.minimumRestoreSizeEast and !state.east.initClosed)
|
|
|
|
options.east = state.east
|
|
|
|
if state.west?
|
|
|
|
if !attrs.minimumRestoreSizeWest? or (state.west.size >= attrs.minimumRestoreSizeWest and !state.west.initClosed)
|
|
|
|
options.west = state.west
|
2014-07-08 07:02:26 -04:00
|
|
|
|
2017-12-11 10:33:00 -05:00
|
|
|
if window.uiConfig.eastResizerCursor?
|
|
|
|
options.east.resizerCursor = window.uiConfig.eastResizerCursor
|
|
|
|
|
|
|
|
if window.uiConfig.westResizerCursor?
|
|
|
|
options.west.resizerCursor = window.uiConfig.westResizerCursor
|
|
|
|
|
2015-01-29 14:23:04 -05:00
|
|
|
repositionControls = () ->
|
|
|
|
state = element.layout().readState()
|
|
|
|
if state.east?
|
|
|
|
controls = element.find("> .ui-layout-resizer-controls")
|
|
|
|
if state.east.initClosed
|
|
|
|
controls.hide()
|
|
|
|
else
|
|
|
|
controls.show()
|
|
|
|
controls.css({
|
|
|
|
right: state.east.size
|
|
|
|
})
|
|
|
|
|
2018-03-20 11:08:34 -04:00
|
|
|
repositionCustomToggler = () ->
|
|
|
|
if !customTogglerEl?
|
|
|
|
return
|
|
|
|
state = element.layout().readState()
|
2018-03-20 12:02:01 -04:00
|
|
|
positionAnchor = if customTogglerPane == "east" then "right" else "left"
|
|
|
|
paneState = state[customTogglerPane]
|
|
|
|
if paneState?
|
|
|
|
customTogglerEl.css(positionAnchor, if paneState.initClosed then 0 else paneState.size)
|
|
|
|
|
2015-01-29 14:23:04 -05:00
|
|
|
resetOpenStates = () ->
|
|
|
|
state = element.layout().readState()
|
|
|
|
if attrs.openEast? and state.east?
|
|
|
|
openEast = $parse(attrs.openEast)
|
|
|
|
openEast.assign(scope, !state.east.initClosed)
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
# Someone moved the resizer
|
|
|
|
onInternalResize = () ->
|
|
|
|
state = element.layout().readState()
|
|
|
|
scope.$broadcast "layout:#{name}:resize", state
|
|
|
|
repositionControls()
|
2018-03-20 11:08:34 -04:00
|
|
|
if hasCustomToggler
|
|
|
|
repositionCustomToggler()
|
2014-07-08 07:02:26 -04:00
|
|
|
resetOpenStates()
|
2015-01-29 14:23:04 -05:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
oldWidth = element.width()
|
|
|
|
# Something resized our parent element
|
|
|
|
onExternalResize = () ->
|
|
|
|
if attrs.resizeProportionally? and scope.$eval(attrs.resizeProportionally)
|
|
|
|
eastState = element.layout().readState().east
|
|
|
|
if eastState?
|
|
|
|
newInternalWidth = eastState.size / oldWidth * element.width()
|
|
|
|
oldWidth = element.width()
|
|
|
|
element.layout().sizePane("east", newInternalWidth)
|
|
|
|
return
|
|
|
|
|
|
|
|
element.layout().resizeAll()
|
|
|
|
|
|
|
|
element.layout options
|
|
|
|
element.layout().resizeAll()
|
|
|
|
|
|
|
|
if attrs.resizeOn?
|
|
|
|
scope.$on attrs.resizeOn, () -> onExternalResize()
|
|
|
|
|
2018-03-20 11:08:34 -04:00
|
|
|
if hasCustomToggler
|
|
|
|
state = element.layout().readState()
|
|
|
|
customTogglerScope = scope.$new()
|
2018-03-20 12:02:01 -04:00
|
|
|
|
|
|
|
customTogglerScope.isOpen = true
|
|
|
|
|
|
|
|
if state[customTogglerPane]?.initClosed == true
|
|
|
|
customTogglerScope.isOpen = false
|
|
|
|
|
|
|
|
console.log customTogglerScope.isOpen
|
2018-03-20 12:06:44 -04:00
|
|
|
customTogglerScope.tooltipMsgWhenOpen = customTogglerMsgWhenOpen
|
|
|
|
customTogglerScope.tooltipMsgWhenClosed = customTogglerMsgWhenClosed
|
2018-03-20 12:02:01 -04:00
|
|
|
|
|
|
|
customTogglerScope.tooltipPlacement = if customTogglerPane == "east" then "left" else "right"
|
|
|
|
customTogglerScope.handleClick = () ->
|
|
|
|
element.layout().toggle(customTogglerPane)
|
|
|
|
repositionCustomToggler()
|
2018-03-20 11:08:34 -04:00
|
|
|
customTogglerEl = $compile("
|
|
|
|
<a href
|
2018-03-20 12:02:01 -04:00
|
|
|
class=\"custom-toggler #{ 'custom-toggler-' + customTogglerPane }\"
|
|
|
|
ng-class=\"isOpen ? 'custom-toggler-open' : 'custom-toggler-closed'\"
|
2018-03-20 12:06:44 -04:00
|
|
|
tooltip=\"{{ isOpen ? tooltipMsgWhenOpen : tooltipMsgWhenClosed }}\"
|
2018-03-20 12:02:01 -04:00
|
|
|
tooltip-placement=\"{{ tooltipPlacement }}\"
|
|
|
|
ng-click=\"handleClick()\">
|
2018-03-20 11:08:34 -04:00
|
|
|
")(customTogglerScope)
|
|
|
|
element.append(customTogglerEl)
|
2018-03-20 12:02:01 -04:00
|
|
|
|
|
|
|
onPaneOpen = (pane) ->
|
|
|
|
if !hasCustomToggler and pane != customTogglerPane
|
|
|
|
return
|
|
|
|
customTogglerEl.scope().$applyAsync () ->
|
|
|
|
customTogglerEl.scope().isOpen = true
|
|
|
|
|
|
|
|
onPaneClose = (pane) ->
|
|
|
|
if !hasCustomToggler and pane != customTogglerPane
|
|
|
|
return
|
|
|
|
customTogglerEl.scope().$applyAsync () ->
|
|
|
|
customTogglerEl.scope().isOpen = false
|
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
# Save state when exiting
|
|
|
|
$(window).unload () ->
|
2015-02-12 06:32:27 -05:00
|
|
|
ide.localStorage("layout.#{name}", element.layout().readState())
|
2014-07-08 07:02:26 -04:00
|
|
|
|
|
|
|
if attrs.openEast?
|
|
|
|
scope.$watch attrs.openEast, (value, oldValue) ->
|
|
|
|
if value? and value != oldValue
|
|
|
|
if value
|
|
|
|
element.layout().open("east")
|
|
|
|
else
|
|
|
|
element.layout().close("east")
|
|
|
|
setTimeout () ->
|
|
|
|
scope.$digest()
|
|
|
|
, 0
|
|
|
|
|
2016-11-15 05:34:19 -05:00
|
|
|
if attrs.allowOverflowOn?
|
2017-02-24 09:38:46 -05:00
|
|
|
layoutObj = element.layout()
|
|
|
|
overflowPane = scope.$eval(attrs.allowOverflowOn)
|
|
|
|
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.
|
2017-12-04 07:25:40 -05:00
|
|
|
overflowPaneZVal = overflowPaneEl.zIndex()
|
2017-02-24 09:38:46 -05:00
|
|
|
overflowPaneEl.css "z-index", overflowPaneZVal + 1
|
2016-11-15 05:34:19 -05:00
|
|
|
|
2014-07-08 07:02:26 -04:00
|
|
|
resetOpenStates()
|
2014-07-10 09:36:04 -04:00
|
|
|
onInternalResize()
|
2015-01-23 15:37:02 -05:00
|
|
|
|
|
|
|
if attrs.layoutDisabled?
|
|
|
|
scope.$watch attrs.layoutDisabled, (value) ->
|
|
|
|
if value
|
|
|
|
element.layout().hide("east")
|
|
|
|
else
|
|
|
|
element.layout().show("east")
|
2017-01-12 11:49:29 -05:00
|
|
|
|
|
|
|
post: (scope, element, attrs) ->
|
|
|
|
name = attrs.layout
|
|
|
|
state = element.layout().readState()
|
|
|
|
scope.$broadcast "layout:#{name}:linked", state
|
2014-07-08 07:02:26 -04:00
|
|
|
}
|
2015-01-23 15:37:02 -05:00
|
|
|
]
|