Sha256: d6e30220a70c437a28ae0ab2ef3be96e5a6ce8ab22fbdf378dcf7455d264a290

Contents?: true

Size: 1.57 KB

Versions: 27

Compression:

Stored size: 1.57 KB

Contents

/*
 image_ex.js: javascript for image_ex.rb plugin of tDiary

 Copyright (C) 2012 by Shugo Maeda
 You can redistribute it and/or modify it under GPL2.
 */

$(function() {
	function getWindowSize() {
		if (window.innerWidth) {
			return {
				width: window.innerWidth,
				height: window.innerHeight
			};
		}
		else if (document.documentElement &&
				  	document.documentElement.clientWidth != 0 ) {
			return {
				width: document.documentElement.clientWidth,
				height: document.documentElement.clientHeight
			};
		}
		else if ( document.body ) {
			return {
				width: document.body.clientWidth,
				height: document.body.clientHeight
			}
		}
		return false;
	}

	var maxSize = null;

	function getMaxSize() {
		if (maxSize != null) {
			return maxSize;
		}

		var windowSize = getWindowSize();
		if (windowSize == false) {
			maxSize = false;
		}
		else {
			maxSize = {
				width: windowSize.width * 0.8,
				height: windowSize.height * 0.8
			};
		}
		return maxSize;
	}

	function resizeImage(img) {
		var maxSize = getMaxSize();

		if (img.width > maxSize.width || img.height > maxSize.height) {
			if (img.width / maxSize.width > img.height / maxSize.height) {
				img.width = maxSize.width;
			}
			else {
				img.height = maxSize.height;
			}
		}
	}

	if ($(window).width() <= 360) {
		$(document).ready(function() {
			$("img.image-ex").on("load", function() {
				resizeImage(this);
			});
		});

		// for when images have been cached
		$(window).on("load", function() {
			$("img.image-ex").each(function() {
				resizeImage(this);
			});
		});
	}
});

// vim: set ts=3 sw=3 noexpandtab :

Version data entries

27 entries across 26 versions & 2 rubygems

Version Path
tdiary-contrib-5.3.0 js/image_ex.js
tdiary-contrib-5.2.4 js/image_ex.js
tdiary-contrib-5.2.3 js/image_ex.js
tdiary-contrib-5.2.2 js/image_ex.js
tdiary-contrib-5.2.1 js/image_ex.js
tdiary-contrib-5.2.0 js/image_ex.js
tdiary-contrib-5.1.7 js/image_ex.js
tdiary-contrib-5.1.6 js/image_ex.js
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/js/image_ex.js
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/bundler/gems/tdiary-contrib-d1e41204db13/js/image_ex.js
tdiary-contrib-5.1.5 js/image_ex.js
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/js/image_ex.js
tdiary-contrib-5.1.4 js/image_ex.js
tdiary-contrib-5.1.3 js/image_ex.js
tdiary-contrib-5.1.2 js/image_ex.js
tdiary-contrib-5.1.1 js/image_ex.js
tdiary-contrib-5.1.0 js/image_ex.js
tdiary-contrib-5.0.13 js/image_ex.js
tdiary-contrib-5.0.12 js/image_ex.js
tdiary-contrib-5.0.11 js/image_ex.js