mirror of https://github.com/akveo/blur-admin
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
/**
|
|
* @author v.lugovsky
|
|
* created on 15.01.2016
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
angular.module('BlurAdmin.theme')
|
|
.service('baPanelBlurHelper', baPanelBlurHelper);
|
|
|
|
/** @ngInject */
|
|
function baPanelBlurHelper($q) {
|
|
var res = $q.defer();
|
|
var computedStyle = getComputedStyle(document.body);
|
|
var image = new Image();
|
|
image.src = computedStyle.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2');
|
|
image.onerror = function() {
|
|
res.reject();
|
|
};
|
|
image.onload = function() {
|
|
res.resolve();
|
|
};
|
|
|
|
this.bodyBgLoad = function() {
|
|
return res.promise;
|
|
};
|
|
|
|
this.getBodyBgImageSizes = function() {
|
|
var elemW = document.documentElement.clientWidth;
|
|
var elemH = document.documentElement.clientHeight;
|
|
var imgRatio = (image.height / image.width); // original img ratio
|
|
var containerRatio = (elemH / elemW); // container ratio
|
|
|
|
var finalHeight, finalWidth;
|
|
if (containerRatio > imgRatio) {
|
|
finalHeight = elemH;
|
|
finalWidth = (elemH / imgRatio);
|
|
} else {
|
|
finalWidth = elemW;
|
|
finalHeight = (elemW * imgRatio);
|
|
}
|
|
return { width: finalWidth, height: finalHeight, positionX: (elemW - finalWidth)/2, positionY: (elemH - finalHeight)/2};
|
|
};
|
|
}
|
|
|
|
})();
|