~dvko/wp-social-sharing

625e24949e4e0c28b3a0d3af1b739715c4396b97 — Danny van Kooten 1 year, 5 months ago dea6d3c
refactor JS & setup development tooling to build minified versions
A Makefile => Makefile +14 -0
@@ 0,0 1,14 @@
.PHONY: all
all: assets/js/admin-script.min.js assets/js/script.min.js assets/css/styles.min.css assets/css/admin-styles.min.css

assets/css/admin-styles.min.css: assets/css/admin-styles.css
	lightningcss --minify $^  -o $@

assets/css/styles.min.css: assets/css/styles.css
	lightningcss --minify $^  -o $@

assets/js/admin-script.min.js: assets/js/admin-script.js
	uglifyjs $^  -o $@

assets/js/script.min.js: assets/js/script.js
	uglifyjs $^  -o $@

M assets/css/styles.css => assets/css/styles.css +2 -3
@@ 1,9 1,8 @@

.dvk-social-sharing {
	line-height: 16px; 
	line-height: 16px;
}

.dvk-social-sharing > a{ 
.dvk-social-sharing > a{
	margin-left:12px;
	display: inline-block;
	text-decoration: none;

M assets/css/styles.min.css => assets/css/styles.min.css +1 -1
@@ 1,1 1,1 @@
.dvk-social-sharing{line-height:16px}.dvk-social-sharing>a{margin-left:12px;display:inline-block;text-decoration:none;border-bottom:0}.dvk-social-sharing>a:focus .ss-icon,.dvk-social-sharing>a:hover .ss-icon{opacity:1}.dvk-social-sharing>span:first-of-type{font-weight:700}.ss-icon{width:16px;height:16px;display:inline-block;background-repeat:no-repeat;margin-right:6px;vertical-align:middle;background-size:cover;opacity:.6}.ss-icon-twitter{background-image:url(../img/twitter.svg)}.ss-icon-facebook{background-image:url(../img/facebook.svg)}.ss-icon-googleplus{background-image:url(../img/google-plus.svg)}.ss-icon-linkedin{background-image:url(../img/linkedin.svg)}.ss-icon-size-32{line-height:32px}.ss-icon-size-32 .ss-icon{width:32px;height:32px}.ss-icon-size-48{line-height:48px}.ss-icon-size-48 .ss-icon{width:48px;height:48px}
\ No newline at end of file
.dvk-social-sharing{line-height:16px}.dvk-social-sharing>a{border-bottom:0;margin-left:12px;text-decoration:none;display:inline-block}.dvk-social-sharing>a:hover .ss-icon,.dvk-social-sharing>a:focus .ss-icon{opacity:1}.dvk-social-sharing>span:first-of-type{font-weight:700}.ss-icon{width:16px;height:16px;vertical-align:middle;opacity:.6;background-repeat:no-repeat;background-size:cover;margin-right:6px;display:inline-block}.ss-icon-twitter{background-image:url(../img/twitter.svg)}.ss-icon-facebook{background-image:url(../img/facebook.svg)}.ss-icon-googleplus{background-image:url(../img/google-plus.svg)}.ss-icon-linkedin{background-image:url(../img/linkedin.svg)}.ss-icon-size-32{line-height:32px}.ss-icon-size-32 .ss-icon{width:32px;height:32px}.ss-icon-size-48{line-height:48px}.ss-icon-size-48 .ss-icon{width:48px;height:48px}
\ No newline at end of file

A assets/js/admin-script.min.js => assets/js/admin-script.min.js +1 -0
@@ 0,0 1,1 @@
const form=document.getElementById("dvkss_settings");function toggleIconSizeRow(){const value=form.elements.namedItem("dvk_social_sharing[load_icon_css]").value;form.querySelector(".row-icon-size").style.display=value==="1"?"":"none"}form.addEventListener("change",toggleIconSizeRow);toggleIconSizeRow();
\ No newline at end of file

M assets/js/script.js => assets/js/script.js +29 -58
@@ 1,61 1,32 @@
(function() {
	'use strict';

	/**
	 * Initialises the Social Sharing plugin
	 */
	function initSocialSharing() {

		var links;

		links = document.querySelectorAll('.dvk-social-sharing a');
		for (var i = 0; i < links.length; i++) {
			addEvent(links[i], 'click', openPopup);
		}

	}

	/**
	 * Open a popup
	 *
	 * @param e
	 * @returns {boolean}
	 */
	function openPopup(e) {

		var top = (screen.availHeight - 500) / 2;
		var left = (screen.availWidth - 500) / 2;

		var popup = window.open(
			this.href,
			'social',
			'width=550,height=420,left='+ left +',top='+ top +',location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1'
		);

		if(popup) {
			popup.focus();
			e.preventDefault();
			return false;
		}

		return true;
/**
 * Open a popup
 *
 * @param {MouseEvent} evt
 * @returns {boolean}
 */
function openSocialSharingPopup(evt) {
	const top = (screen.availHeight - 500) / 2;
	const left = (screen.availWidth - 500) / 2;
	const popup = window.open(
		this.href,
		'social',
		'width=550,height=420,left='+ left +',top='+ top +',location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1'
	);

	if(popup) {
		popup.focus();
		evt.preventDefault();
	}

	/**
	 * Add event, compatible with IE.
	 *
	 * @param element
	 * @param eventName
	 * @param callback
	 */
	function addEvent(element, eventName, callback) {
		if (element.addEventListener) {
			element.addEventListener(eventName, callback, false);
		} else {
			element.attachEvent("on" + eventName, callback);
		}
}

/**
 * Adds the click event handler to all links inside the .dvk-social-sharing wrapper element
 */
function initSocialSharing() {
	const links = document.querySelectorAll('.dvk-social-sharing a');
	for (let i = 0; i < links.length; i++) {
		links[i].addEventListener('click', openSocialSharingPopup);
	}
}

	addEvent(window, 'load', initSocialSharing);

})();
\ No newline at end of file
window.addEventListener('load', initSocialSharing)

M assets/js/script.min.js => assets/js/script.min.js +1 -1
@@ 1,1 1,1 @@
!function(){"use strict";function a(){var a;a=document.querySelectorAll(".dvk-social-sharing a");for(var d=0;d<a.length;d++)c(a[d],"click",b)}function b(a){var b=(screen.availHeight-500)/2,c=(screen.availWidth-500)/2,d=window.open(this.href,"social","width=550,height=420,left="+c+",top="+b+",location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1");return d?(d.focus(),a.preventDefault(),!1):!0}function c(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)}c(window,"load",a)}();
\ No newline at end of file
function openSocialSharingPopup(evt){const top=(screen.availHeight-500)/2;const left=(screen.availWidth-500)/2;const popup=window.open(this.href,"social","width=550,height=420,left="+left+",top="+top+",location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1");if(popup){popup.focus();evt.preventDefault()}}function initSocialSharing(){const links=document.querySelectorAll(".dvk-social-sharing a");for(let i=0;i<links.length;i++){links[i].addEventListener("click",openSocialSharingPopup)}}window.addEventListener("load",initSocialSharing);
\ No newline at end of file