2014-06-21 17:20:37 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.directive "layout", () ->
|
|
|
|
return {
|
|
|
|
link: (scope, element, attrs) ->
|
|
|
|
name = attrs.layout
|
|
|
|
|
|
|
|
options =
|
|
|
|
spacing_open: 24
|
|
|
|
spacing_closed: 24
|
|
|
|
onresize: () =>
|
2014-06-28 07:07:18 -04:00
|
|
|
console.log "Triggering", "layout:#{name}:resize", name
|
|
|
|
scope.$broadcast "layout:#{name}:resize"
|
2014-06-30 13:35:01 -04:00
|
|
|
repositionControls()
|
2014-06-28 07:07:18 -04:00
|
|
|
#maskIframesOnResize: true
|
2014-06-21 17:20:37 -04:00
|
|
|
|
|
|
|
# Restore previously recorded state
|
2014-06-28 07:07:18 -04:00
|
|
|
if (state = $.localStorage("layout.#{name}"))?
|
2014-06-21 17:20:37 -04:00
|
|
|
options.west = state.west
|
|
|
|
options.east = state.east
|
|
|
|
|
2014-06-28 07:07:18 -04:00
|
|
|
element.layout options
|
|
|
|
element.layout().resizeAll()
|
|
|
|
|
|
|
|
if attrs.resizeOn?
|
|
|
|
scope.$on attrs.resizeOn, () -> element.layout().resizeAll()
|
2014-06-21 17:20:37 -04:00
|
|
|
|
|
|
|
# Save state when exiting
|
|
|
|
$(window).unload () ->
|
|
|
|
$.localStorage("layout.#{name}", element.layout().readState())
|
2014-06-30 13:35:01 -04:00
|
|
|
|
|
|
|
repositionControls = () ->
|
|
|
|
state = element.layout().readState()
|
|
|
|
if state.east?
|
|
|
|
element.find(".ui-layout-resizer-controls").css({
|
|
|
|
position: "absolute"
|
|
|
|
right: state.east.size
|
|
|
|
"z-index": 10
|
|
|
|
})
|
2014-06-21 17:20:37 -04:00
|
|
|
}
|