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

ep_font_family

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ep_font_family - npm Package Compare versions

Comparing version 0.0.4 to 0.1.1

static/css/iframe.css

15

ep.json

@@ -7,6 +7,9 @@ {

"postAceInit": "ep_font_family/static/js/index",
"aceInitialized": "ep_font_family/static/js/index",
"aceCreateDomLine": "ep_font_family/static/js/index",
"aceRegisterBlockElements": "ep_font_family/static/js/index",
"aceAttribsToClasses": "ep_font_family/static/js/index",
"collectContentPre": "ep_font_family/static/js/shared"
"aceAttribClasses":"ep_font_family/static/js/index",
"collectContentPre": "ep_font_family/static/js/shared",
"collectContentPost": "ep_font_family/static/js/shared",
"aceEditEvent": "ep_font_family/static/js/index",
"aceEditorCSS": "ep_font_family/static/js/index"
},

@@ -17,4 +20,6 @@ "hooks": {

"collectContentPost": "ep_font_family/static/js/shared",
"getLineHTMLForExport": "ep_font_family/index",
"eejsBlock_dd_format":"ep_font_family/index"
"eejsBlock_dd_format":"ep_font_family/index",
"aceAttribClasses":"ep_font_family/index",
"stylesForExport" : "ep_font_family/index",
"exportHtmlAdditionalTags" : "ep_font_family/index"
}

@@ -21,0 +26,0 @@ }

var eejs = require('ep_etherpad-lite/node/eejs/');
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
var fonts = ["arial", "times-new-roman", "calibri", "helvetica", "courier", "palatino", "garamond", "bookman", "avant-garde"];
var fs = require('fs');
/********************
* UI
*/
exports.eejsBlock_editbarMenuLeft = function (hook_name, args, cb) {

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

exports.eejsBlock_dd_format = function(hook_name, args, cb){
exports.eejsBlock_dd_format = function (hook_name, args, cb) {
args.content = args.content + eejs.require("ep_font_family/templates/fileMenu.ejs");

@@ -14,24 +19,30 @@ return cb();

function getInlineStyle(font) {
return "font-family: "+font+";";
/********************
* Editor
*/
// Allow <whatever> to be an attribute
exports.aceAttribClasses = function(hook_name, attr, cb){
for (var i in fonts){
var font = fonts[i];
attr[font] = 'tag:'+font;
};
cb(attr);
}
// line, apool,attribLine,text
exports.getLineHTMLForExport = function (hook, context) {
var header = _analyzeLine(context.attribLine, context.apool);
if (header) {
var inlineStyle = getInlineStyle(header);
return "<span style=\"" + inlineStyle + "\">" + context.text.substring(1) + "</span>";
}
}
function _analyzeLine(alineAttrs, apool) {
var header = null;
if (alineAttrs) {
var opIter = Changeset.opIterator(alineAttrs);
if (opIter.hasNext()) {
var op = opIter.next();
header = Changeset.opAttributeValue(op, 'fonts', apool);
}
}
return header;
}
/********************
* Export
*/
// Include CSS for HTML export
exports.stylesForExport = function(hook, padId, cb){
var cssPath = __dirname +'/static/css/iframe.css';
fs.readFile(cssPath, function(err, data){
cb(data);
});
};
// Add the props to be supported in export
exports.exportHtmlAdditionalTags = function(hook, pad, cb){
cb(fonts);
};
{
"ep_font_familt.font" : "Font"
"ep_font_size.size" : "Font Size"
}
{
"ep_font_familt.font" : "Fontes"
"ep_font_size.size" : "Taille"
}
{
"description": "Change the font of some text",
"description": "Add support for different Fonts",
"name": "ep_font_family",
"version": "0.0.4",
"version": "0.1.1",
"author": {

@@ -6,0 +6,0 @@ "name": "John McLear",

@@ -1,99 +0,110 @@

var _, $, jQuery;
var $, jQuery;
var $ = require('ep_etherpad-lite/static/js/rjquery').$;
var _ = require('ep_etherpad-lite/static/js/underscore');
var FontFamilyClass = 'FontFamily';
var cssFiles = ['ep_font_family/static/css/editor.css'];
// All our FontFamily are block elements, so we just return them.
var FontFamily = ['Arial', 'TimesNewRoman', 'Calibri', 'Helvetica', 'Courier', 'Palatino', 'Garamond', 'Bookman', 'Avant Guard'];
var fonts = ["arial", "times-new-roman", "calibri", "helvetica", "courier", "palatino", "garamond", "bookman", "avant-garde"];
/*****
* Basic setup
******/
// Bind the event handler to the toolbar buttons
var postAceInit = function(hook, context){
var hs = $('.font-selection');
hs.on('change', function(){
exports.postAceInit = function(hook, context){
var fontFamily = $('.family-selection');
$.each(fonts, function(k, font){
var fontString = capitaliseFirstLetter(font)
fontString = fontString.split("-").join(" ");
fontFamily.append("<option value='"+font+"'>"+fontString+"</option>");
});
fontFamily.on('change', function(){
var value = $(this).val();
var intValue = parseInt(value,10);
if(!_.isNaN(intValue)){
context.ace.callWithAce(function(ace){
ace.ace_doInsertFontFamily(intValue);
},'insertFontFamily' , true);
hs.val("dummy");
}
context.ace.callWithAce(function(ace){
// remove all other attrs
$.each(fonts, function(k, v){
ace.ace_setAttributeOnSelection(v, false);
});
ace.ace_setAttributeOnSelection(value, true);
},'insertfontFamily' , true);
})
$('.ep_font_family').click(function(){
var family = $(this).data("family");
});
$('.font_family').hover(function(){
$('.submenu > .font-selection').attr('size', 6);
$('.submenu > .family-selection').attr('family', 6);
});
$('.font-icon').click(function(){
$('#font').toggle();
$('.font-family-icon').click(function(){
$('#font-family').toggle();
});
};
// To do show what font family is active on current selection
exports.aceEditEvent = function(hook, call, cb){
var cs = call.callstack;
// Our FontFamily attribute will result in a heaading:h1... :h6 class
function aceAttribsToClasses(hook, context){
if(context.key.indexOf("FontFamily:") !== -1){
var fontFamily = /(?:^| )FontFamily:([A-Za-z0-9]*)/.exec(context.key);
return ['FontFamily:' + fontFamily[1] ];
if(!(cs.type == "handleClick") && !(cs.type == "handleKeyEvent") && !(cs.docTextChanged)){
return false;
}
if(context.key == 'FontFamily'){
return ['FontFamily:' + context.value ];
}
}
// If it's an initial setup event then do nothing..
if(cs.type == "setBaseText" || cs.type == "setup") return false;
// It looks like we should check to see if this section has this attribute
setTimeout(function(){ // avoid race condition..
// Here we convert the class FontFamily:h1 into a tag
exports.aceCreateDomLine = function(name, context){
var cls = context.cls;
var domline = context.domline;
var FontFamilyType = /(?:^| )FontFamily:([A-Za-z0-9]*)/.exec(cls);
$('.family-selection').val("dummy"); // reset value to the dummy value
var tagIndex;
if (FontFamilyType) tagIndex = _.indexOf(FontFamily, FontFamilyType[1]);
if (tagIndex !== undefined && tagIndex >= 0){
var tag = FontFamily[tagIndex];
var modifier = {
extraOpenTags: '<span style="font-family: ' + tag + '">',
extraCloseTags: '</span>',
cls: cls
};
return [modifier];
}
return [];
};
// Attribtes are never available on the first X caret position so we need to ignore that
if(call.rep.selStart[1] === 0){
// Attributes are never on the first line
return;
}
// The line has an attribute set, this means it wont get hte correct X caret position
if(call.rep.selStart[1] === 1){
if(call.rep.alltext[0] === "*"){
// Attributes are never on the "first" character of lines with attributes
return;
}
}
// the caret is in a new position.. Let's do some funky shit
$('.subscript > a').removeClass('activeButton');
$.each(fonts, function(k,v){
if ( call.editorInfo.ace_getAttributeOnSelection(v) ) {
// show the button as being depressed.. Not sad, but active..
$('.family-selection').val(v);
}
});
},250);
}
/*****
* Editor setup
******/
// Find out which lines are selected and assign them the FontFamily attribute.
// Passing a level >= 0 will set a FontFamily on the selected lines, level < 0
// will remove it
function doInsertFontFamily(level){
var rep = this.rep, documentAttributeManager = this.documentAttributeManager;
if (!(rep.selStart && rep.selEnd) || (level >= 0 && FontFamily[level] === undefined)){
return;
// Our fontFamily attribute will result in a class
// I'm not sure if this is actually required..
exports.aceAttribsToClasses = function(hook, context){
if(fonts.indexOf(context.key) !== -1){
return [context.key];
}
if(level >= 0){
documentAttributeManager.setAttributesOnRange(rep.selStart, rep.selEnd, [
['FontFamily', FontFamily[level]]
]);
}else{
documentAttributeManager.setAttributesOnRange(rep.selStart, rep.selEnd, [
['FontFamily', '']
]);
}
}
// Block elements
// I'm not sure if this is actually required..
exports.aceRegisterBlockElements = function(){
return fonts;
}
// Once ace is initialized, we set ace_doInsertFontFamily and bind it to the context
function aceInitialized(hook, context){
var editorInfo = context.editorInfo;
editorInfo.ace_doInsertFontFamily = _(doInsertFontFamily).bind(context);
// Register attributes that are html markup / blocks not just classes
// This should make export export properly IE <sub>helllo</sub>world
// will be the output and not <span class=sub>helllo</span>
exports.aceAttribClasses = function(hook, attr){
$.each(fonts, function(k, v){
attr[v] = 'tag:'+v;
});
return attr;
}
exports.aceEditorCSS = function(hook_name, cb){
return ["/ep_font_family/static/css/iframe.css"];
}
// Export all hooks
exports.aceInitialized = aceInitialized;
exports.postAceInit = postAceInit;
exports.aceAttribsToClasses = aceAttribsToClasses;
function capitaliseFirstLetter(string){
return string.charAt(0).toUpperCase() + string.slice(1);
}

@@ -1,24 +0,22 @@

var _ = require('ep_etherpad-lite/static/js/underscore');
var collectContentPre = function(hook, context){
var fontFamily = /(?:^| )FontFamily:([A-Za-z0-9]*)/.exec(context.cls);
if(fontFamily && fontFamily[1]){
context.cc.doAttrib(context.state, fontFamily[0]);
exports.collectContentPre = function(hook, context){
var tname = context.tname;
var state = context.state;
var lineAttributes = state.lineAttributes
var tagIndex = tname;
var fonts = ["arial", "times-new-roman", "calibri", "helvetica", "courier", "palatino", "garamond", "bookman", "avant-garde"];
if(fonts.indexOf(tname) !== -1){
context.cc.doAttrib(state, tname);
}
};
var collectContentPost = function(hook, context){
/*
// never seems to be run
exports.collectContentPost = function(hook, context){
var tname = context.tname;
var state = context.state;
var lineAttributes = state.lineAttributes
var tagIndex = _.indexOf(fonts, tname);
var tagIndex = tname;
if(tagIndex >= 0){
delete lineAttributes['font'];
delete lineAttributes['sub'];
}
*/
};
exports.collectContentPre = collectContentPre;
exports.collectContentPost = collectContentPost;

Sorry, the diff of this file is not supported yet

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