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

ep_align

Package Overview
Dependencies
Maintainers
4
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ep_align - npm Package Compare versions

Comparing version 0.0.24 to 0.1.24

9

ep.json

@@ -6,4 +6,5 @@ {

"client_hooks": {
"postToolbarInit": "ep_align/static/js/index",
"aceDomLinePreProcessLineAttributes": "ep_align/static/js/index",
"aceEditEvent": "ep_align/static/js/index",
"aceDomLineProcessLineAttributes": "ep_align/static/js/index",
"postAceInit": "ep_align/static/js/index",
"aceInitialized": "ep_align/static/js/index",

@@ -18,5 +19,3 @@ "aceAttribsToClasses": "ep_align/static/js/index",

"collectContentPost": "ep_align/static/js/shared",
"padInitToolbar": "ep_align/index",
"getLineHTMLForExport": "ep_align/index",
"eejsBlock_dd_format":"ep_align/index"
"getLineHTMLForExport": "ep_align/index"
}

@@ -23,0 +22,0 @@ }

var eejs = require('ep_etherpad-lite/node/eejs/');
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
var Security = require('ep_etherpad-lite/static/js/security');
exports.eejsBlock_editbarMenuLeft = function (hook_name, args, cb) {

@@ -8,47 +10,13 @@ args.content = args.content + eejs.require("ep_align/templates/editbarButtons.ejs");

exports.eejsBlock_dd_format = function (hook_name, args, cb) {
args.content = args.content + eejs.require("ep_align/templates/fileMenu.ejs");
return cb();
}
function getInlineStyle(header) {
// TODO!
switch (header) {
case "h1":
return "font-size: 2.0em;line-height: 120%;";
break;
case "h2":
return "font-size: 1.5em;line-height: 120%;";
break;
case "h3":
return "font-size: 1.17em;line-height: 120%;";
break;
case "h4":
return "line-height: 120%;";
break;
case "h5":
return "font-size: 0.83em;line-height: 120%;";
break;
case "h6":
return "font-size: 0.75em;line-height: 120%;";
break;
case "code":
return "font-family: monospace";
}
return "";
}
// line, apool,attribLine,text
exports.getLineHTMLForExport = function (hook, context) {
var header = _analyzeLine(context.attribLine, context.apool);
var lineContent = context.lineContent;
if (header) {
var inlineStyle = getInlineStyle(header);
context.lineContent = "<" + header + " style=\"" + inlineStyle + "\">" + lineContent + "</" + header + ">";
var alignment = _analyzeLine(context.attribLine, context.apool);
if (alignment) {
context.lineContent = "<p style='text-align:" + alignment + "'>" + Security.escapeHTML(context.text.substring(1)) + "</p>";
return "<p style='text-align:" + alignment + "'>" + Security.escapeHTML(context.text.substring(1)) + "</p>";
}
}
function _analyzeLine(alineAttrs, apool) {
var header = null;
var alignment = null;
if (alineAttrs) {

@@ -58,36 +26,6 @@ var opIter = Changeset.opIterator(alineAttrs);

var op = opIter.next();
header = Changeset.opAttributeValue(op, 'align', apool);
alignment = Changeset.opAttributeValue(op, 'align', apool);
}
}
return header;
return alignment;
}
exports.padInitToolbar = function (hook_name, args) {
var toolbar = args.toolbar;
var alignLeftButton = toolbar.button({
command: 'alignLeft',
class: "buttonicon grouped-left ep_align ep_align_left"
});
var alignCenterButton = toolbar.button({
command: 'alignCenter',
class: "buttonicon grouped-middle ep_align ep_align_center"
});
var alignJustifyButton = toolbar.button({
command: 'alignJustify',
class: "buttonicon grouped-middle ep_align ep_align_justify"
});
var alignRightButton = toolbar.button({
command: 'alignRight',
class: "buttonicon grouped-right ep_align ep_align_right"
});
toolbar.registerButton('alignLeft', alignLeftButton);
toolbar.registerButton('alignCenter', alignCenterButton);
toolbar.registerButton('alignJustify', alignJustifyButton);
toolbar.registerButton('alignRight', alignRightButton);
};
{
"description": "Add Left/Center/Right/Justify to lines of text in a pad",
"name": "ep_align",
"version": "0.0.24",
"_from": "ep_align",
"_id": "ep_align@0.1.0",
"_inBundle": false,
"_integrity": "sha512-hQwIerjWtcY3qWfqCsm+MIk/eo/hfpOl7mkGS+YZFJvljv4xuDk8QK8gnYY7RLtiKGo8jN8fKlht2w6DCLosjg==",
"_location": "/ep_align",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "ep_align",
"name": "ep_align",
"escapedName": "ep_align",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/ep_align/-/ep_align-0.0.24.tgz",
"_shasum": "20c4e8062cb212759b6ea2dcf7da46cd6d41f7a0",
"_spec": "ep_align",
"_where": "/home/jose/etherpad-lite",
"author": {

@@ -9,8 +30,19 @@ "name": "John McLear",

},
"bugs": {
"url": "https://github.com/johnmclear/ep_align/issues"
},
"bundleDependencies": false,
"contributors": [],
"dependencies": {},
"deprecated": false,
"description": "Add Left/Center/Right/Justify to lines of text in a pad",
"devDependencies": {},
"dist": {
"shasum": "9c71c10ccc09df9154763b8d1ebfcf12297f9cc3"
},
"engines": {
"node": "*"
},
"devDependencies": {},
"homepage": "https://github.com/johnmclear/ep_align#readme",
"name": "ep_align",
"repository": {

@@ -20,13 +52,3 @@ "type": "git",

},
"readme": "# ep_align\n\n## Function\nAdds options in the editbar to add justification to text IE Left, middle(center), right and justify.\n\n## Settings\nNone\n\n## Todo\nExport support\n\nWant further functionality?\nhttp://mclear.co.uk/experience\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/johnmclear/ep_align/issues"
},
"_id": "ep_align@0.0.3",
"dist": {
"shasum": "9c71c10ccc09df9154763b8d1ebfcf12297f9cc3"
},
"_from": "ep_align@",
"_resolved": "https://registry.npmjs.org/ep_align/-/ep_align-0.0.3.tgz"
"version": "0.1.24"
}

@@ -1,13 +0,19 @@

# ep_align
# What is this?
An Etherpad Plugin to apply Text Alignment in a pad. Currently supports:
## Function
Adds options in the editbar to add justification to text IE Left, middle(center), right and justify.
* Left
* Center
* Justify
* Right
## Settings
None
# Export support
Experimental. As attributes are line by line on Etherpad some weirdness may be experienced.
## Todo
Export support
# History
I decided to copy/pasta the ep_headings2 plugin over ep_align to fix a load of issues.
Want further functionality?
http://mclear.co.uk/experience
# License
Apache 2
# Development
Development done for free to help support continued learning due to distruption by the corona virus. 26LLC supported.

@@ -5,45 +5,70 @@ var _, $, jQuery;

var _ = require('ep_etherpad-lite/static/js/underscore');
var alignClass = 'align';
var cssFiles = ['ep_align/static/css/editor.css'];
// All our tags are block elements, so we just return them.
var tags = ['left', 'center', 'right', 'justify'];
var aceRegisterBlockElements = function(){
var tags = ['left', 'center', 'justify', 'right'];
exports.aceRegisterBlockElements = function(){
return tags;
}
function postToolbarInit (hook_name, context) {
var editbar = context.toolbar; // toolbar is actually editbar - http://etherpad.org/doc/v1.5.7/#index_editbar
// Bind the event handler to the toolbar buttons
exports.postAceInit = function(hook, context){
$('body').on('click', '.ep_align', function(){
var value = $(this).data("align");
var intValue = parseInt(value,10);
if(!_.isNaN(intValue)){
context.ace.callWithAce(function(ace){
ace.ace_doInsertAlign(intValue);
},'insertalign' , true);
}
})
};
editbar.registerCommand('alignLeft', function () {
align(context, 0);
});
// On caret position change show the current align
exports.aceEditEvent = function(hook, call, cb){
editbar.registerCommand('alignCenter', function () {
align(context, 1);
});
// If it's not a click or a key event and the text hasn't changed then do nothing
var cs = call.callstack;
if(!(cs.type == "handleClick") && !(cs.type == "handleKeyEvent") && !(cs.docTextChanged)){
return false;
}
// If it's an initial setup event then do nothing..
if(cs.type == "setBaseText" || cs.type == "setup") return false;
editbar.registerCommand('alignJustify', function () {
align(context, 3);
// It looks like we should check to see if this section has this attribute
setTimeout(function(){ // avoid race condition..
var attributeManager = call.documentAttributeManager;
var rep = call.rep;
var firstLine, lastLine;
var activeAttributes = {};
// $("#align-selection").val(-2); // TODO commented this out
firstLine = rep.selStart[0];
lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0));
var totalNumberOfLines = 0;
_(_.range(firstLine, lastLine + 1)).each(function(line){
totalNumberOfLines++;
var attr = attributeManager.getAttributeOnLine(line, "align");
if(!activeAttributes[attr]){
activeAttributes[attr] = {};
activeAttributes[attr].count = 1;
}else{
activeAttributes[attr].count++;
}
});
editbar.registerCommand('alignRight', function () {
align(context, 2);
$.each(activeAttributes, function(k, attr){
if(attr.count === totalNumberOfLines){
// show as active class
var ind = tags.indexOf(k);
// $("#align-selection").val(ind); // TODO commnented this out
}
});
};
function align(context, alignment){
context.ace.callWithAce(function(ace){
ace.ace_doInsertalign(alignment);
ace.ace_focus();
},'insertalign' , true);
},250);
}
// Our align attribute will result in an align:left...right class
function aceAttribsToClasses(hook, context){
if(context.key.indexOf("align:") !== -1){
var align = /(?:^| )align:([A-Za-z0-9]*)/.exec(context.key);
return ['align:' + align[1] ];
}
// Our align attribute will result in a heaading:left.... :left class
exports.aceAttribsToClasses = function(hook, context){
if(context.key == 'align'){

@@ -54,4 +79,4 @@ return ['align:' + context.value ];

// Here we convert the class align:h1 into a tag
var aceDomLinePreProcessLineAttributes = function(name, context){
// Here we convert the class align:left into a tag
exports.aceDomLineProcessLineAttributes = function(name, context){
var cls = context.cls;

@@ -64,4 +89,2 @@ var domline = context.domline;

var tag = tags[tagIndex];
// we have to have the tags here for the registered block elements else
// when you type in aligned content it goes back to left alignment..
var modifier = {

@@ -78,5 +101,5 @@ preHtml: '<'+tag+' style="width:100%;margin:0 auto;list-style-position:inside;display:block;text-align:' + tag + '">',

// Find out which lines are selected and assign them the align attribute.
// Passing a level >= 0 will set a align on the selected lines, level < 0
// Passing a level >= 0 will set a alignment on the selected lines, level < 0
// will remove it
function doInsertalign(level){
function doInsertAlign(level){
var rep = this.rep,

@@ -88,5 +111,5 @@ documentAttributeManager = this.documentAttributeManager;

}
var firstLine, lastLine;
firstLine = rep.selStart[0];

@@ -104,18 +127,8 @@ lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0));

// Once ace is initialized, we set ace_doInsertalign and bind it to the context
function aceInitialized(hook, context){
// Once ace is initialized, we set ace_doInsertAlign and bind it to the context
exports.aceInitialized = function(hook, context){
var editorInfo = context.editorInfo;
editorInfo.ace_doInsertalign = _(doInsertalign).bind(context);
editorInfo.ace_doInsertAlign = _(doInsertAlign).bind(context);
}
function aceEditorCSS(){
return cssFiles;
};
// Export all hooks
exports.postToolbarInit = postToolbarInit;
exports.aceRegisterBlockElements = aceRegisterBlockElements;
exports.aceInitialized = aceInitialized;
exports.aceDomLinePreProcessLineAttributes = aceDomLinePreProcessLineAttributes;
exports.aceAttribsToClasses = aceAttribsToClasses;
exports.aceEditorCSS = aceEditorCSS;
var _ = require('ep_etherpad-lite/static/js/underscore');
var tags = ['left', 'center', 'right', 'justify'];
var tags = ['left', 'center', 'justify', 'right'];

@@ -10,2 +10,5 @@ var collectContentPre = function(hook, context){

var tagIndex = _.indexOf(tags, tname);
if(tname === "div" || tname === "p"){
delete lineAttributes['align'];
}
if(tagIndex >= 0){

@@ -16,2 +19,3 @@ lineAttributes['align'] = tags[tagIndex];

// I don't even know when this is run..
var collectContentPost = function(hook, context){

@@ -22,3 +26,2 @@ var tname = context.tname;

var tagIndex = _.indexOf(tags, tname);
if(tagIndex >= 0){

@@ -25,0 +28,0 @@ delete lineAttributes['align'];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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