Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scribe-plugin-span-style

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scribe-plugin-span-style - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

package.json
{
"name": "scribe-plugin-span-style",
"version": "0.1.1",
"version": "0.1.2",
"description": "A Scribe Plugin for adding inline styles through <span> elements",

@@ -5,0 +5,0 @@ "main": "src/scribe-plugin-span-style.js",

@@ -1,72 +0,76 @@

module.exports = function(styleName) {
return function(scribe) {
let spanStyleCommand = new scribe.api.SimpleCommand(styleName);
spanStyleCommand.nodeName = 'SPAN';
define(function () {
'use strict';
let clearChildStyles = (root) => {
if (typeof root === 'undefined' || typeof root.childNodes === 'undefined') return;
return function (styleName) {
return function(scribe) {
let spanStyleCommand = new scribe.api.SimpleCommand(styleName);
spanStyleCommand.nodeName = 'SPAN';
for (let i in root.childNodes) {
let child = root.childNodes[i];
let clearChildStyles = (root) => {
if (typeof root === 'undefined' || typeof root.childNodes === 'undefined') return;
clearChildStyles(child.childNodes);
for (let i in root.childNodes) {
let child = root.childNodes[i];
if (child.nodeName === 'SPAN') {
child.style[styleName] = '';
if (!child.getAttribute('style')) {
scribe.node.unwrap(root, child);
clearChildStyles(child.childNodes);
if (child.nodeName === 'SPAN') {
child.style[styleName] = '';
if (!child.getAttribute('style')) {
scribe.node.unwrap(root, child);
}
}
}
}
};
};
spanStyleCommand.execute = function(value) {
scribe.transactionManager.run(() => {
let selection = new scribe.api.Selection();
let range = selection.range;
spanStyleCommand.execute = function(value) {
scribe.transactionManager.run(() => {
let selection = new scribe.api.Selection();
let range = selection.range;
// Get Range Text & Current Node Text
let selectedHtmlDocumentFragment = range.extractContents();
let tDiv = document.createElement('div');
tDiv.appendChild(selectedHtmlDocumentFragment.cloneNode(true));
let rangeText = tDiv.innerText;
let nodeText = selection.selection.focusNode.textContent;
// Get Range Text & Current Node Text
let selectedHtmlDocumentFragment = range.extractContents();
let tDiv = document.createElement('div');
tDiv.appendChild(selectedHtmlDocumentFragment.cloneNode(true));
let rangeText = tDiv.innerText;
let nodeText = selection.selection.focusNode.textContent;
// Determine if we need a new node
let isNewNode = true;
if (nodeText === rangeText) {
isNewNode = (selection.selection.focusNode.parentElement.nodeName === 'SPAN') ? false : true;
}
// Determine if we need a new node
let isNewNode = true;
if (nodeText === rangeText) {
isNewNode = (selection.selection.focusNode.parentElement.nodeName === 'SPAN') ? false : true;
}
// Create / Get SPAN
let span = (!isNewNode) ? selection.selection.focusNode.parentElement : document.createElement('span');
span.appendChild(selectedHtmlDocumentFragment);
if (isNewNode) {
range.insertNode(span);
range.selectNode(span);
}
// Clear Setting for children
clearChildStyles(span);
// Create / Get SPAN
let span = (!isNewNode) ? selection.selection.focusNode.parentElement : document.createElement('span');
span.appendChild(selectedHtmlDocumentFragment);
if (isNewNode) {
range.insertNode(span);
range.selectNode(span);
}
// Clear Setting for children
clearChildStyles(span);
// Apply new Font-Size
span.style[styleName] = value;
// Apply new Font-Size
span.style[styleName] = value;
// Re-apply the range
selection.selection.removeAllRanges();
selection.selection.addRange(range);
});
};
// Re-apply the range
selection.selection.removeAllRanges();
selection.selection.addRange(range);
});
};
spanStyleCommand.queryState = function() {
var selection = new scribe.api.Selection();
return !!selection.getContaining(node => {
if (node.style) {
return (node.nodeName === this.nodeName && node.style[styleName] !== '');
}
return false;
});
spanStyleCommand.queryState = function() {
var selection = new scribe.api.Selection();
return !!selection.getContaining(node => {
if (node.style) {
return (node.nodeName === this.nodeName && node.style[styleName] !== '');
}
return false;
});
};
scribe.commands[styleName] = spanStyleCommand;
};
scribe.commands[styleName] = spanStyleCommand;
};
};
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc