UNPKG

pip-webui

Version:

HTML5 UI for LOB applications

81 lines (60 loc) 2.77 kB
/** * @file Dialog layout * @copyright Digital Living Software Corp. 2014-2015 */ /* global angular */ (function () { 'use strict'; var thisModule = angular.module('pipLayout.Dialog', []); thisModule.directive('pipDialog', function() { return { restrict: 'EA', controller: 'pipDialogController' }; }); thisModule.controller('pipDialogController', function($scope, $element, $attrs) { var $window = $(window); // Add class to the element $element.addClass('pip-dialog'); // Resize every time window is resized $scope.$on('pipWindowResized', resize); $scope.$on('pipResizeLayout', resize); // Resize right away to avoid flicking resize(); // Resize the element right away //setTimeout(resize, 0); $window.trigger('resize'); return; //----------------------- function resize() { var maxWidth = $window.width(), maxHeight = $window.height(), minWidth = $attrs.minWidth ? Math.floor($attrs.minWidth) : null, minHeight = $attrs.minHeight ? Math.floor($attrs.minHeight) : null, width = $attrs.width ? Math.floor($attrs.width) : null, height = $attrs.height ? Math.floor($attrs.height) : null; // Set margin and maximum dimensions var space = maxWidth > 1200 ? 24 : 16; maxWidth -= space * 2; maxHeight -= space * 2; // Set minimum dimensions minWidth = minWidth && minWidth < maxWidth ? minWidth : null; minHeight = minHeight && minHeight < maxHeight ? minHeight : null; // Set regular dimensions width = width ? Math.min(width, maxWidth) : null; height = height ? Math.min(height, maxHeight) : null; // Set dimensions $element.css('max-width', maxWidth ? maxWidth + 'px' : ''); $element.css('max-height', maxHeight ? maxHeight + 'px' : ''); $element.css('min-width', minWidth ? minWidth + 'px' : ''); $element.css('min-height', minHeight ? minHeight + 'px' : ''); $element.css('width', width ? width + 'px' : ''); $element.css('height', height ? height + 'px' : ''); // Notify child controls that layout was resized $scope.$broadcast('pipLayoutResized'); }; } ); })();