CoreFiles by mySites.guru
caption.js66 lines, 2,085 bytes, from Joomla_4.0.0-alpha3-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha2
md5
ea831cde0c7d38b01b460cf6a3d95cb0
sha1
21dec2c75bca6afc664db804dd648cf591db3d07
sha256
89421c52119ec3a7d507b314f58ce02dc24635879b2181672daf472e779b9400
/**
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

/**
 * JCaption javascript behavior
 *
 * Used for displaying image captions
 *
 * @package     Joomla
 * @since       1.5
 * @version  1.0
 */
Joomla = window.Joomla || {};

(function(Joomla) {
	Joomla.JCaption = function(selector) {
		var insertBefore = function(el, referenceNode) {
			    referenceNode.parentNode.insertBefore(el, referenceNode);
		    },

		    initialize = function(selector) {
			    var elements = document.querySelectorAll(selector);
			    for (var i = 0, count = elements.length; i < count; i++) {
				    createCaption(elements[i], selector);
			    }
		    },

		    createCaption = function(element, selector) {
			    var container, caption = element.getAttribute('title'),
			        width = element.getAttribute("width") || element.style.width,
			        align = element.getAttribute("align") || element.style.cssFloat || "none",
			        pEl = document.createElement('p'),
			        clearClass = selector.replace('.', '_').replace('#', '').replace(',', '').split(' ');
			    pEl.innerHTML = caption;
			    container = document.createElement('div');
			    clearClass.forEach(function(className) {
				    pEl.classList.add(className);
				    container.classList.add(className);
			    });
			    container.classList.add(align);
			    insertBefore(container, element);

			    if (caption !== "") {
				    container.appendChild(pEl);
			    }

			    container.style.cssFloat = align;
			    container.style.width = /px/.test(width) ? width : width + 'px';

			    container.appendChild(element);
		    };

		initialize(selector);
	};

	document.addEventListener('DOMContentLoaded',  function() {

		if (Joomla.getOptions && typeof Joomla.getOptions === 'function' && Joomla.getOptions('js-image-caption')) {
			if (Joomla.getOptions('js-image-caption').selector) {
				new Joomla.JCaption(Joomla.getOptions('js-image-caption').selector);
			}
		}
	});
})(Joomla);

No other release has this exact content. See every version of this file.