ACC SHELL

Path : /srv/www/vhosts/agroing/web/views/agroing/www/
File Upload :
Current File : /srv/www/vhosts/agroing/web/views/agroing/www/responsive.js

//Config

var responsive = true;

//Config


var lastchange = $.now();

function var_dump(e) {
	console.log(e);
}

function memmorySize(els) {
	console.log(els);
	$.each(els, function () {
		var defWidth;
		var defHeight;

		if (!$(this).is('[data-defwidth][data-defheight]')) {
			if ($(this).is('[width]')) {
				defWidth = $(this).attr('width');
			} else {
				defWidth = $(this).width();
			}

			if ($(this).is('[height]')) {
				defHeight = $(this).attr('height');
			} else {
				defHeight = $(this).height();
			}

//			console.log(defWidth);
//			console.log(defHeight);
			$(this).attr('data-defwidth', defWidth);
			$(this).attr('data-defheight', defHeight);
//			console.log($(this));
//			console.log('w'+$(this).data('defwidth'));
//			console.log('h'+$(this).data('defheight'));
		}
	});
}

function checkObject(els) {
	console.log('Resize');

	$.each(els, function () {
		var defWidth = $(this).data('defwidth');
		var defHeight = $(this).data('defheight');
		var parent = $(this).parent();
		var coefWidth = 0;
		var coefHeight = 0;
		var coef = 1;
		
		if (parent.css('height')== 'auto') {
			$(this).addClass('noresh');
		}

		$(this).css({'width':'','height':''});

		if (!$(this).hasClass('noresw') && parent.width() < $(this).attr('width')) {
			coefWidth = parent.width() / $(this).attr('width');
		}

		if (!$(this).hasClass('noresh') && parent.height() < $(this).attr('height')) {
			coefHeight = parent.height() / $(this).attr('height');
		}
//		console.log($(this));
//		console.log(!$(this).hasClass('noresw'));
//		console.log(!$(this).hasClass('noresh'));
//		console.log(coefWidth);
//		console.log(coefHeight);

		if (coefWidth != 0 || coefHeight != 0) {
			if (coefWidth > coefHeight) {
				coef = coefWidth;
			} else {
				coef = coefHeight;
			}

			$(this).width(defWidth * coef);
			$(this).height(defHeight * coef);

//			console.log(defWidth*coef);
//			console.log(defHeight*coef);
//			console.log('Nevejde se');
		} else {
//			console.log('Vejde se');
		}
	});
}

function setDefaultStyles() {
	var remake = $('body').find('table, tr, td, th, tbody');
	remake.each(function () {
		if ((typeof $(this).attr('style')) != 'undefined') {
			$(this).attr('data-style-back', $(this).attr('style'));
		} else {
			$(this).attr('data-style-back', '');
		}
	});
}

function resizeTables() {
	var remake = $('body').find('table, tr, td, th, tbody');
	remake.each(function () {
		if ((typeof $(this).attr('data-style-back')) != 'undefined') {
			console.log('existuje old style');
			$(this).attr('style', $(this).attr('data-style-back'));
		} else {
			$(this).attr('style', '');
		}
	});

	$('table').each(function () {
		if ($(this).parent().width() != 0 && $(this).parent().width() < $(this).width()) {
			console.log('nevejde se');
			var remake = $(this).find('table, tr, td, th, tbody').andSelf();
			remake.css({'display': 'block', 'width': 'auto'});
			console.log('upravena sirka');

			resizeIframe($(this).find('iframe'));
		}
	});
}

function resizeIframe(els) {
	$(els).each(function () {
		$(this).css('width', 'auto');

//		alert ($(this).parent().width() + ' vs' +  $(this).width());

		if ($(this).parent().width() != 0 && $(this).parent().width() < $(this).width()) {
			$(this).css('width', $(this).parent().width());
		}
	});
}

function resize(now) {
	if (lastchange !== now) {
		return;
	}

	resizeTables();
	resizeIframe($('body').find('iframe'));
	checkObject($('object'));
}

function revalidateObjects() {
	memmorySize($('object'));
	checkObject($('object'));
}

$(document).ready(function () {

	if (responsive === true) {

		if (!$('head meta[name=viewport]').length > 0) {
			$('head').append('<meta name="viewport" content="width=device-width, initial-scale=1.0" />');
		}

		setDefaultStyles();
		memmorySize($('object'));

		$(window).resize(function () {
			var now = $.now();
			lastchange = now;
			setTimeout(resize, 500, now);
		});
		
		
		setTimeout(revalidateObjects, 2000);
		
		$(window).resize();
	}
});

ACC SHELL 2018