changeset 13:8d32537e0ca7

icons again
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 07 Aug 2022 14:28:14 -0600
parents 933a459aa182
children 0cb206904499
files src/icons/famfamfam.js src/icons/material.js src/icons/monocons.js src/sceditor.js
diffstat 4 files changed, 92 insertions(+), 107 deletions(-) [+]
line wrap: on
line diff
--- a/src/icons/famfamfam.js	Sun Aug 07 13:58:27 2022 -0600
+++ b/src/icons/famfamfam.js	Sun Aug 07 14:28:14 2022 -0600
@@ -2,11 +2,8 @@
 	'use strict';
 
 	let baseUrl = document.currentScript.getAttribute('src').match(/.*\//)[0];
-
-	sceditor.icons.fn = function() {
-		let cssUrl = baseUrl + 'famfamfam/famfamfam.css';
-		let html = '<style>@import "' + cssUrl + '";</style>';
-		document.head.insertAdjacentHTML('beforeend',html);
-		return {};
-	};
+	let cssUrl = baseUrl + 'famfamfam/famfamfam.css';
+	let html = '<style>@import "' + cssUrl + '";</style>';
+	document.head.insertAdjacentHTML('beforeend',html);
+	sceditor.icons = {};
 })(document, sceditor);
--- a/src/icons/material.js	Sun Aug 07 13:58:27 2022 -0600
+++ b/src/icons/material.js	Sun Aug 07 14:28:14 2022 -0600
@@ -77,56 +77,53 @@
 		'youtube': '<path d="M10,16.5V7.5L16,12M20,4.4C19.4,4.2 15.7,4 12,4C8.3,4 4.6,4.19 4,4.38C2.44,4.9 2,8.4 2,12C2,15.59 2.44,19.1 4,19.61C4.6,19.81 8.3,20 12,20C15.7,20 19.4,19.81 20,19.61C21.56,19.1 22,15.59 22,12C22,8.4 21.56,4.91 20,4.4Z" />'
 	};
 
-	sceditor.icons.fn = function () {
-		var nodes = {};
+	var nodes = {};
 
-		var colorPath;
+	var colorPath;
 
-		return {
-			create: function (command) {
-				if (command in icons) {
-					// Using viewbox="1 1 22 22" to trim off the 1 unit border
-					// around the SVG icons.
-					// Default is viewbox="0 0 24 24"
-					nodes[command] = sceditor.dom.parseHTML(
-						'<svg xmlns="http://www.w3.org/2000/svg" ' +
-							'viewbox="1 1 22 22" unselectable="on">' +
-								icons[command] +
-						'</svg>'
-					).firstChild;
+	sceditor.icons = {
+		create: function (command) {
+			if (command in icons) {
+				// Using viewbox="1 1 22 22" to trim off the 1 unit border
+				// around the SVG icons.
+				// Default is viewbox="0 0 24 24"
+				nodes[command] = sceditor.dom.parseHTML(
+					'<svg xmlns="http://www.w3.org/2000/svg" ' +
+						'viewbox="1 1 22 22" unselectable="on">' +
+							icons[command] +
+					'</svg>'
+				).firstChild;
 
-					if (command === 'color') {
-						colorPath = nodes[command].querySelector('.sce-color');
-					}
+				if (command === 'color') {
+					colorPath = nodes[command].querySelector('.sce-color');
+				}
+			}
+
+			return nodes[command];
+		},
+		update: function (isSourceMode, currentNode) {
+			if (colorPath) {
+				var color = 'inherit';
+
+				if (!isSourceMode && currentNode) {
+					color = currentNode.ownerDocument
+						.queryCommandValue('forecolor');
 				}
 
-				return nodes[command];
-			},
-			update: function (isSourceMode, currentNode) {
-				if (colorPath) {
-					var color = 'inherit';
+				dom.css(colorPath, 'fill', color);
+			}
+		},
+		rtl: function (isRtl) {
+			var gripNode = nodes.grip;
 
-					if (!isSourceMode && currentNode) {
-						color = currentNode.ownerDocument
-							.queryCommandValue('forecolor');
-					}
+			if (gripNode) {
+				var transform = isRtl ? 'scaleX(-1)' : '';
 
-					dom.css(colorPath, 'fill', color);
-				}
-			},
-			rtl: function (isRtl) {
-				var gripNode = nodes.grip;
-
-				if (gripNode) {
-					var transform = isRtl ? 'scaleX(-1)' : '';
-
-					dom.css(gripNode, 'transform', transform);
-					dom.css(gripNode, 'msTransform', transform);
-					dom.css(gripNode, 'webkitTransform', transform);
-				}
+				dom.css(gripNode, 'transform', transform);
+				dom.css(gripNode, 'msTransform', transform);
+				dom.css(gripNode, 'webkitTransform', transform);
 			}
-		};
+		},
+		icons: icons
 	};
-
-	sceditor.icons.icons = icons;
 })(document, sceditor);
--- a/src/icons/monocons.js	Sun Aug 07 13:58:27 2022 -0600
+++ b/src/icons/monocons.js	Sun Aug 07 14:28:14 2022 -0600
@@ -61,52 +61,49 @@
 		'youtube': '<path d="M2 2C1 2 0 3 0 4v8c0 1 1 2 2 2h12c1 0 2-1 2-2V4c0-1-1-2-2-2H2zm4 3l6 3-6 3V5z"/>'
 	};
 
-	sceditor.icons.fn = function () {
-		var nodes = {};
-		var colorPath;
+	var nodes = {};
+	var colorPath;
+
+	sceditor.icons = {
+		create: function (command) {
+			if (command in icons) {
+				nodes[command] = sceditor.dom.parseHTML(
+					'<svg xmlns="http://www.w3.org/2000/svg" ' +
+						'viewbox="0 0 16 16" unselectable="on">' +
+							icons[command] +
+					'</svg>'
+				).firstChild;
 
-		return {
-			create: function (command) {
-				if (command in icons) {
-					nodes[command] = sceditor.dom.parseHTML(
-						'<svg xmlns="http://www.w3.org/2000/svg" ' +
-							'viewbox="0 0 16 16" unselectable="on">' +
-								icons[command] +
-						'</svg>'
-					).firstChild;
+				if (command === 'color') {
+					colorPath = nodes[command].querySelector('.sce-color');
+				}
+			}
 
-					if (command === 'color') {
-						colorPath = nodes[command].querySelector('.sce-color');
-					}
+			return nodes[command];
+		},
+		update: function (isSourceMode, currentNode) {
+			if (colorPath) {
+				var color = 'inherit';
+
+				if (!isSourceMode && currentNode) {
+					color = currentNode.ownerDocument
+						.queryCommandValue('forecolor');
 				}
 
-				return nodes[command];
-			},
-			update: function (isSourceMode, currentNode) {
-				if (colorPath) {
-					var color = 'inherit';
+				dom.css(colorPath, 'fill', color);
+			}
+		},
+		rtl: function (isRtl) {
+			var gripNode = nodes.grip;
 
-					if (!isSourceMode && currentNode) {
-						color = currentNode.ownerDocument
-							.queryCommandValue('forecolor');
-					}
+			if (gripNode) {
+				var transform = isRtl ? 'scaleX(-1)' : '';
 
-					dom.css(colorPath, 'fill', color);
-				}
-			},
-			rtl: function (isRtl) {
-				var gripNode = nodes.grip;
-
-				if (gripNode) {
-					var transform = isRtl ? 'scaleX(-1)' : '';
-
-					dom.css(gripNode, 'transform', transform);
-					dom.css(gripNode, 'msTransform', transform);
-					dom.css(gripNode, 'webkitTransform', transform);
-				}
+				dom.css(gripNode, 'transform', transform);
+				dom.css(gripNode, 'msTransform', transform);
+				dom.css(gripNode, 'webkitTransform', transform);
 			}
-		};
+		},
+		icons: icons
 	};
-
-	sceditor.icons.icons = icons;
 })(document, sceditor);
--- a/src/sceditor.js	Sun Aug 07 13:58:27 2022 -0600
+++ b/src/sceditor.js	Sun Aug 07 14:28:14 2022 -0600
@@ -5724,7 +5724,13 @@
 		 * @type {?Object}
 		 * @private
 		 */
-		var icons;
+		let icons = sceditor.icons;
+		if(!icons) {
+			let cssUrl = baseUrl + 'icons/famfamfam/famfamfam.css';
+			let html = '<style>@import "' + cssUrl + '";</style>';
+			document.head.insertAdjacentHTML('beforeend',html);
+			sceditor.icons = icons = {};
+		}
 
 		/**
 		 * Private functions
@@ -6138,8 +6144,6 @@
 				unselectable: 'on'
 			});
 
-			icons = SCEditor.icons.fn();
-
 			each(groups, function (_, menuItems) {
 				group = createElement('div', {
 					className: 'sceditor-group'
@@ -6161,7 +6165,7 @@
 								command.tooltip || commandName)
 					}, true).firstChild;
 
-					if (icons && icons.create) {
+					if (icons.create) {
 						var icon = icons.create(commandName);
 						if (icon) {
 							insertBefore(icons.create(commandName),
@@ -6316,7 +6320,7 @@
 				e.preventDefault();
 			};
 
-			if (icons && icons.create) {
+			if (icons.create) {
 				var icon = icons.create('grip');
 				if (icon) {
 					appendChild(grip, icon);
@@ -6510,7 +6514,7 @@
 			removeClass(editorContainer, 'ltr');
 			addClass(editorContainer, dir);
 
-			if (icons && icons.rtl) {
+			if (icons.rtl) {
 				icons.rtl(rtl);
 			}
 
@@ -7895,7 +7899,7 @@
 				toggleClass(btn, activeClass, state > 0);
 			}
 
-			if (icons && icons.update) {
+			if (icons.update) {
 				icons.update(isSource, parent, firstBlock);
 			}
 		};
@@ -8930,15 +8934,6 @@
 	SCEditor.locale = {};
 
 	SCEditor.formats = {};
-	SCEditor.icons = {};
-
-	// default icons
-	SCEditor.icons.fn = function() {
-		let cssUrl = baseUrl + 'icons/famfamfam/famfamfam.css';
-		let html = '<style>@import "' + cssUrl + '";</style>';
-		document.head.insertAdjacentHTML('beforeend',html);
-		return {};
-	};
 
 
 	/**
@@ -9072,7 +9067,6 @@
 			hasStyle: hasStyle
 		},
 		locale: SCEditor.locale,
-		icons: SCEditor.icons,
 		utils: {
 			each: each,
 			isEmptyObject: isEmptyObject,