Comparing version 0.2.26 to 0.2.27
37
index.js
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const eejs = require('ep_etherpad-lite/node/eejs/'); | ||
@@ -6,7 +8,7 @@ const Changeset = require('ep_etherpad-lite/static/js/Changeset'); | ||
exports.eejsBlock_editbarMenuLeft = function (hook_name, args, cb) { | ||
exports.eejsBlock_editbarMenuLeft = (hookName, args, cb) => { | ||
if (args.renderContext.isReadOnly) return cb(); | ||
for (const button of ['alignLeft', 'alignJustify', 'alignCenter', 'alignRight']) { | ||
if (JSON.stringify(settings.toolbar).indexOf(button) > -1 ) { | ||
if (JSON.stringify(settings.toolbar).indexOf(button) > -1) { | ||
return cb(); | ||
@@ -20,12 +22,3 @@ } | ||
// line, apool,attribLine,text | ||
exports.getLineHTMLForExport = async (hookName, context) => { | ||
const 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) { | ||
const _analyzeLine = (alineAttrs, apool) => { | ||
let alignment = null; | ||
@@ -40,6 +33,14 @@ if (alineAttrs) { | ||
return alignment; | ||
} | ||
}; | ||
// line, apool,attribLine,text | ||
exports.getLineHTMLForExport = async (hookName, context) => { | ||
const align = _analyzeLine(context.attribLine, context.apool); | ||
if (align) { | ||
context.lineContent = `<p style='text-align:${align}'>${Security.escapeHTML(context.text.substring(1))}</p>`; | ||
return `<p style='text-align:${align}'>${Security.escapeHTML(context.text.substring(1))}</p>`; | ||
} | ||
}; | ||
exports.padInitToolbar = function (hook_name, args, cb) { | ||
exports.padInitToolbar = (hookName, args, cb) => { | ||
const toolbar = args.toolbar; | ||
@@ -50,3 +51,3 @@ | ||
localizationId: 'ep_align.toolbar.left.title', | ||
class: "buttonicon buttonicon-align-left ep_align ep_align_left" | ||
class: 'buttonicon buttonicon-align-left ep_align ep_align_left', | ||
}); | ||
@@ -57,3 +58,3 @@ | ||
localizationId: 'ep_align.toolbar.middle.title', | ||
class: "buttonicon buttonicon-align-center ep_align ep_align_center" | ||
class: 'buttonicon buttonicon-align-center ep_align ep_align_center', | ||
}); | ||
@@ -64,3 +65,3 @@ | ||
localizationId: 'ep_align.toolbar.justify.title', | ||
class: "buttonicon buttonicon-align-justify ep_align ep_align_justify" | ||
class: 'buttonicon buttonicon-align-justify ep_align ep_align_justify', | ||
}); | ||
@@ -71,3 +72,3 @@ | ||
localizationId: 'ep_align.toolbar.right.title', | ||
class: "buttonicon buttonicon-align-right ep_align ep_align_right" | ||
class: 'buttonicon buttonicon-align-right ep_align ep_align_right', | ||
}); | ||
@@ -74,0 +75,0 @@ |
@@ -21,3 +21,3 @@ { | ||
}, | ||
"version": "0.2.26", | ||
"version": "0.2.27", | ||
"funding": { | ||
@@ -24,0 +24,0 @@ "type": "individual", |
@@ -1,12 +0,12 @@ | ||
const $ = require('ep_etherpad-lite/static/js/rjquery').$; | ||
'use strict'; | ||
const _ = require('ep_etherpad-lite/static/js/underscore'); | ||
// All our tags are block elements, so we just return them. | ||
var tags = ['left', 'center', 'justify', 'right']; | ||
exports.aceRegisterBlockElements = function () { | ||
return tags; | ||
}; | ||
const tags = ['left', 'center', 'justify', 'right']; | ||
exports.aceRegisterBlockElements = () => tags; | ||
// Bind the event handler to the toolbar buttons | ||
exports.postAceInit = function (hook, context) { | ||
exports.postAceInit = (hookName, context) => { | ||
$('body').on('click', '.ep_align', function () { | ||
@@ -26,10 +26,10 @@ const value = $(this).data('align'); | ||
// On caret position change show the current align | ||
exports.aceEditEvent = function (hook, call) { | ||
exports.aceEditEvent = (hook, call) => { | ||
// If it's not a click or a key event and the text hasn't changed then do nothing | ||
const cs = call.callstack; | ||
if (!(cs.type == 'handleClick') && !(cs.type == 'handleKeyEvent') && !(cs.docTextChanged)) { | ||
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; | ||
if (cs.type === 'setBaseText' || cs.type === 'setup') return false; | ||
@@ -40,8 +40,7 @@ // It looks like we should check to see if this section has this attribute | ||
const rep = call.rep; | ||
let firstLine, lastLine; | ||
const 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)); | ||
const firstLine = rep.selStart[0]; | ||
const lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0)); | ||
let totalNumberOfLines = 0; | ||
@@ -63,3 +62,3 @@ | ||
// show as active class | ||
const ind = tags.indexOf(k); | ||
// const ind = tags.indexOf(k); | ||
// $("#align-selection").val(ind); // TODO commnented this out | ||
@@ -74,4 +73,4 @@ } | ||
// Our align attribute will result in a heaading:left.... :left class | ||
exports.aceAttribsToClasses = function (hook, context) { | ||
if (context.key == 'align') { | ||
exports.aceAttribsToClasses = (hook, context) => { | ||
if (context.key === 'align') { | ||
return [`align:${context.value}`]; | ||
@@ -82,5 +81,4 @@ } | ||
// Here we convert the class align:left into a tag | ||
exports.aceDomLineProcessLineAttributes = function (name, context) { | ||
exports.aceDomLineProcessLineAttributes = (name, context) => { | ||
const cls = context.cls; | ||
const domline = context.domline; | ||
const alignType = /(?:^| )align:([A-Za-z0-9]*)/.exec(cls); | ||
@@ -111,6 +109,4 @@ let tagIndex; | ||
let firstLine, lastLine; | ||
firstLine = rep.selStart[0]; | ||
lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0)); | ||
const firstLine = rep.selStart[0]; | ||
const lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0)); | ||
_(_.range(firstLine, lastLine + 1)).each((i) => { | ||
@@ -127,25 +123,30 @@ if (level >= 0) { | ||
// Once ace is initialized, we set ace_doInsertAlign and bind it to the context | ||
exports.aceInitialized = function (hook, context) { | ||
exports.aceInitialized = (hook, context) => { | ||
const editorInfo = context.editorInfo; | ||
editorInfo.ace_doInsertAlign = _(doInsertAlign).bind(context); | ||
return; | ||
} | ||
}; | ||
exports.postToolbarInit = function (hook_name, context) { | ||
const align = (context, alignment) => { | ||
context.ace.callWithAce((ace) => { | ||
ace.ace_doInsertAlign(alignment); | ||
ace.ace_focus(); | ||
}, 'insertalign', true); | ||
}; | ||
exports.postToolbarInit = (hookName, context) => { | ||
const editbar = context.toolbar; // toolbar is actually editbar - http://etherpad.org/doc/v1.5.7/#index_editbar | ||
editbar.registerCommand('alignLeft', function () { | ||
editbar.registerCommand('alignLeft', () => { | ||
align(context, 0); | ||
}); | ||
editbar.registerCommand('alignCenter', function () { | ||
editbar.registerCommand('alignCenter', () => { | ||
align(context, 1); | ||
}); | ||
editbar.registerCommand('alignJustify', function () { | ||
editbar.registerCommand('alignJustify', () => { | ||
align(context, 2); | ||
}); | ||
editbar.registerCommand('alignRight', function () { | ||
editbar.registerCommand('alignRight', () => { | ||
align(context, 3); | ||
@@ -156,9 +157,1 @@ }); | ||
}; | ||
function align(context, alignment){ | ||
context.ace.callWithAce(function(ace){ | ||
ace.ace_doInsertAlign(alignment); | ||
ace.ace_focus(); | ||
},'insertalign' , true); | ||
} | ||
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const _ = require('ep_etherpad-lite/static/js/underscore'); | ||
@@ -2,0 +4,0 @@ |
31962
754