first commit

This commit is contained in:
2026-06-24 09:48:54 +02:00
commit 41e62ddcad
33739 changed files with 4266226 additions and 0 deletions
+212
View File
@@ -0,0 +1,212 @@
var Delta, Document, Format, Line, LinkedList, Normalizer, dom, _;
_ = require('lodash');
Delta = require('rich-text').Delta;
dom = require('../lib/dom');
Format = require('./format');
Line = require('./line');
LinkedList = require('../lib/linked-list');
Normalizer = require('../lib/normalizer');
Document = (function() {
function Document(root, options) {
this.root = root;
if (options == null) {
options = {};
}
this.formats = {};
_.each(options.formats, _.bind(this.addFormat, this));
this.setHTML(this.root.innerHTML);
}
Document.prototype.addFormat = function(name, config) {
if (!_.isObject(config)) {
config = Format.FORMATS[name];
}
if (this.formats[name] != null) {
console.warn('Overwriting format', name, this.formats[name]);
}
return this.formats[name] = new Format(this.root.ownerDocument, config);
};
Document.prototype.appendLine = function(lineNode) {
return this.insertLineBefore(lineNode, null);
};
Document.prototype.findLeafAt = function(index, inclusive) {
var line, offset, _ref;
_ref = this.findLineAt(index), line = _ref[0], offset = _ref[1];
if (line != null) {
return line.findLeafAt(offset, inclusive);
} else {
return [null, offset];
}
};
Document.prototype.findLine = function(node) {
var line;
while ((node != null) && (dom.BLOCK_TAGS[node.tagName] == null)) {
node = node.parentNode;
}
line = node != null ? this.lineMap[node.id] : null;
if ((line != null ? line.node : void 0) === node) {
return line;
} else {
return null;
}
};
Document.prototype.findLineAt = function(index) {
var curLine, length;
if (!(this.lines.length > 0)) {
return [null, index];
}
length = this.toDelta().length();
if (index === length) {
return [this.lines.last, this.lines.last.length];
}
if (index > length) {
return [null, index - length];
}
curLine = this.lines.first;
while (curLine != null) {
if (index < curLine.length) {
return [curLine, index];
}
index -= curLine.length;
curLine = curLine.next;
}
return [null, index];
};
Document.prototype.insertLineBefore = function(newLineNode, refLine) {
var line;
line = new Line(this, newLineNode);
if (refLine != null) {
if (!dom(newLineNode.parentNode).isElement()) {
this.root.insertBefore(newLineNode, refLine.node);
}
this.lines.insertAfter(refLine.prev, line);
} else {
if (!dom(newLineNode.parentNode).isElement()) {
this.root.appendChild(newLineNode);
}
this.lines.append(line);
}
this.lineMap[line.id] = line;
return line;
};
Document.prototype.mergeLines = function(line, lineToMerge) {
if (lineToMerge.length > 1) {
if (line.length === 1) {
dom(line.leaves.last.node).remove();
}
_.each(dom(lineToMerge.node).childNodes(), function(child) {
if (child.tagName !== dom.DEFAULT_BREAK_TAG) {
return line.node.appendChild(child);
}
});
}
this.removeLine(lineToMerge);
return line.rebuild();
};
Document.prototype.optimizeLines = function() {
return _.each(this.lines.toArray(), function(line, i) {
line.optimize();
return true;
});
};
Document.prototype.rebuild = function() {
var lineNode, lines, _results;
lines = this.lines.toArray();
lineNode = this.root.firstChild;
if ((lineNode != null) && (dom.LIST_TAGS[lineNode.tagName] != null)) {
lineNode = lineNode.firstChild;
}
_.each(lines, (function(_this) {
return function(line, index) {
var newLine, _ref;
while (line.node !== lineNode) {
if (line.node.parentNode === _this.root || ((_ref = line.node.parentNode) != null ? _ref.parentNode : void 0) === _this.root) {
lineNode = Normalizer.normalizeLine(lineNode);
newLine = _this.insertLineBefore(lineNode, line);
lineNode = dom(lineNode).nextLineNode(_this.root);
} else {
return _this.removeLine(line);
}
}
if (line.outerHTML !== lineNode.outerHTML) {
line.node = Normalizer.normalizeLine(line.node);
line.rebuild();
}
return lineNode = dom(lineNode).nextLineNode(_this.root);
};
})(this));
_results = [];
while (lineNode != null) {
lineNode = Normalizer.normalizeLine(lineNode);
this.appendLine(lineNode);
_results.push(lineNode = dom(lineNode).nextLineNode(this.root));
}
return _results;
};
Document.prototype.removeLine = function(line) {
if (line.node.parentNode != null) {
if (dom.LIST_TAGS[line.node.parentNode.tagName] && line.node.parentNode.childNodes.length === 1) {
dom(line.node.parentNode).remove();
} else {
dom(line.node).remove();
}
}
delete this.lineMap[line.id];
return this.lines.remove(line);
};
Document.prototype.setHTML = function(html) {
html = Normalizer.stripComments(html);
html = Normalizer.stripWhitespace(html);
this.root.innerHTML = html;
this.lines = new LinkedList();
this.lineMap = {};
return this.rebuild();
};
Document.prototype.splitLine = function(line, offset) {
var lineNode1, lineNode2, newLine, _ref;
offset = Math.min(offset, line.length - 1);
_ref = dom(line.node).split(offset, true), lineNode1 = _ref[0], lineNode2 = _ref[1];
line.node = lineNode1;
line.rebuild();
newLine = this.insertLineBefore(lineNode2, line.next);
newLine.formats = _.clone(line.formats);
newLine.resetContent();
return newLine;
};
Document.prototype.toDelta = function() {
var delta, lines;
lines = this.lines.toArray();
delta = new Delta();
lines.forEach(function(line) {
return line.delta.ops.forEach(function(op) {
return delta.push(op);
});
});
return delta;
};
return Document;
})();
module.exports = Document;
+242
View File
@@ -0,0 +1,242 @@
var Document, Editor, Line, Renderer, Selection, dom, _;
_ = require('lodash');
dom = require('../lib/dom');
Document = require('./document');
Line = require('./line');
Renderer = require('./renderer');
Selection = require('./selection');
Editor = (function() {
Editor.sources = {
API: 'api',
SILENT: 'silent',
USER: 'user'
};
function Editor(iframeContainer, quill, options) {
this.iframeContainer = iframeContainer;
this.quill = quill;
this.options = options != null ? options : {};
this.renderer = new Renderer(this.iframeContainer, this.options);
dom(this.iframeContainer).on('focus', this.focus.bind(this));
this.root = this.renderer.root;
this.doc = new Document(this.root, this.options);
this.delta = this.doc.toDelta();
this.selection = new Selection(this.doc, this.renderer.iframe, this.quill);
this.timer = setInterval(_.bind(this.checkUpdate, this), this.options.pollInterval);
if (!this.options.readOnly) {
this.enable();
}
}
Editor.prototype.disable = function() {
return this.enable(false);
};
Editor.prototype.enable = function(enabled) {
if (enabled == null) {
enabled = true;
}
return this.root.setAttribute('contenteditable', enabled);
};
Editor.prototype.applyDelta = function(delta, source) {
var localDelta;
localDelta = this._update();
if (localDelta) {
delta = localDelta.transform(delta, true);
localDelta = delta.transform(localDelta, false);
}
if (delta.ops.length > 0) {
delta = this._trackDelta((function(_this) {
return function() {
var index;
index = 0;
_.each(delta.ops, function(op) {
if (_.isString(op.insert)) {
_this._insertAt(index, op.insert, op.attributes);
return index += op.insert.length;
} else if (_.isNumber(op.insert)) {
_this._insertAt(index, dom.EMBED_TEXT, op.attributes);
return index += 1;
} else if (_.isNumber(op["delete"])) {
return _this._deleteAt(index, op["delete"]);
} else if (_.isNumber(op.retain)) {
_.each(op.attributes, function(value, name) {
return _this._formatAt(index, op.retain, name, value);
});
return index += op.retain;
}
});
return _this.selection.shiftAfter(0, 0, _.bind(_this.doc.optimizeLines, _this.doc));
};
})(this));
this.delta = this.doc.toDelta();
this.innerHTML = this.root.innerHTML;
if (delta && source !== Editor.sources.SILENT) {
this.quill.emit(this.quill.constructor.events.TEXT_CHANGE, delta, source);
}
}
if (localDelta && localDelta.ops.length > 0 && source !== Editor.sources.SILENT) {
return this.quill.emit(this.quill.constructor.events.TEXT_CHANGE, localDelta, Editor.sources.USER);
}
};
Editor.prototype.checkUpdate = function(source) {
var delta;
if (source == null) {
source = 'user';
}
if ((this.renderer.iframe.parentNode == null) || (this.root.parentNode == null)) {
return clearInterval(this.timer);
}
delta = this._update();
if (delta) {
this.delta.compose(delta);
this.quill.emit(this.quill.constructor.events.TEXT_CHANGE, delta, source);
}
if (delta) {
source = Editor.sources.SILENT;
}
return this.selection.update(source);
};
Editor.prototype.focus = function() {
if (dom.isIE(11)) {
this.selection.setRange(this.selection.range);
}
if (dom.isIOS()) {
this.renderer.iframe.focus();
}
return this.root.focus();
};
Editor.prototype.getDelta = function() {
return this.delta;
};
Editor.prototype._deleteAt = function(index, length) {
if (length <= 0) {
return;
}
return this.selection.shiftAfter(index, -1 * length, (function(_this) {
return function() {
var curLine, deleteLength, firstLine, mergeFirstLine, nextLine, offset, _ref;
_ref = _this.doc.findLineAt(index), firstLine = _ref[0], offset = _ref[1];
curLine = firstLine;
mergeFirstLine = firstLine.length - offset <= length && offset > 0;
while ((curLine != null) && length > 0) {
nextLine = curLine.next;
deleteLength = Math.min(curLine.length - offset, length);
if (offset === 0 && length >= curLine.length) {
_this.doc.removeLine(curLine);
} else {
curLine.deleteText(offset, deleteLength);
}
length -= deleteLength;
curLine = nextLine;
offset = 0;
}
if (mergeFirstLine && firstLine.next) {
return _this.doc.mergeLines(firstLine, firstLine.next);
}
};
})(this));
};
Editor.prototype._formatAt = function(index, length, name, value) {
return this.selection.shiftAfter(index, 0, (function(_this) {
return function() {
var formatLength, line, offset, _ref, _results;
_ref = _this.doc.findLineAt(index), line = _ref[0], offset = _ref[1];
_results = [];
while ((line != null) && length > 0) {
formatLength = Math.min(length, line.length - offset - 1);
line.formatText(offset, formatLength, name, value);
length -= formatLength;
if (length > 0) {
line.format(name, value);
}
length -= 1;
offset = 0;
_results.push(line = line.next);
}
return _results;
};
})(this));
};
Editor.prototype._insertAt = function(index, text, formatting) {
if (formatting == null) {
formatting = {};
}
return this.selection.shiftAfter(index, text.length, (function(_this) {
return function() {
var line, lineTexts, offset, _ref;
text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
lineTexts = text.split('\n');
_ref = _this.doc.findLineAt(index), line = _ref[0], offset = _ref[1];
return _.each(lineTexts, function(lineText, i) {
var nextLine;
if ((line == null) || line.length <= offset) {
if (i < lineTexts.length - 1 || lineText.length > 0) {
line = _this.doc.appendLine(_this.root.ownerDocument.createElement(dom.DEFAULT_BLOCK_TAG));
offset = 0;
line.insertText(offset, lineText, formatting);
line.format(formatting);
nextLine = null;
}
} else {
line.insertText(offset, lineText, formatting);
if (i < lineTexts.length - 1) {
nextLine = _this.doc.splitLine(line, offset + lineText.length);
_.each(_.defaults({}, formatting, line.formats), function(value, format) {
return line.format(format, formatting[format]);
});
offset = 0;
}
}
return line = nextLine;
});
};
})(this));
};
Editor.prototype._trackDelta = function(fn) {
var delta, newDelta;
fn();
newDelta = this.doc.toDelta();
delta = this.delta.diff(newDelta);
return delta;
};
Editor.prototype._update = function() {
var delta;
if (this.innerHTML === this.root.innerHTML) {
return false;
}
delta = this._trackDelta((function(_this) {
return function() {
_this.selection.preserve(_.bind(_this.doc.rebuild, _this.doc));
return _this.selection.shiftAfter(0, 0, _.bind(_this.doc.optimizeLines, _this.doc));
};
})(this));
this.innerHTML = this.root.innerHTML;
if (delta.ops.length > 0) {
return delta;
} else {
return false;
}
};
return Editor;
})();
module.exports = Editor;
+261
View File
@@ -0,0 +1,261 @@
var Format, dom, _;
_ = require('lodash');
dom = require('../lib/dom');
Format = (function() {
Format.types = {
LINE: 'line'
};
Format.FORMATS = {
bold: {
tag: 'B',
prepare: 'bold'
},
italic: {
tag: 'I',
prepare: 'italic'
},
underline: {
tag: 'U',
prepare: 'underline'
},
strike: {
tag: 'S',
prepare: 'strikeThrough'
},
color: {
style: 'color',
"default": 'rgb(0, 0, 0)',
prepare: 'foreColor'
},
background: {
style: 'backgroundColor',
"default": 'rgb(255, 255, 255)',
prepare: 'backColor'
},
font: {
style: 'fontFamily',
"default": "'Helvetica', 'Arial', sans-serif",
prepare: 'fontName'
},
size: {
style: 'fontSize',
"default": '13px',
prepare: function(doc, value) {
return doc.execCommand('fontSize', false, dom.convertFontSize(value));
}
},
link: {
tag: 'A',
attribute: 'href'
},
image: {
tag: 'IMG',
attribute: 'src'
},
align: {
type: Format.types.LINE,
style: 'textAlign',
"default": 'left'
},
bullet: {
type: Format.types.LINE,
exclude: 'list',
parentTag: 'UL',
tag: 'LI'
},
list: {
type: Format.types.LINE,
exclude: 'bullet',
parentTag: 'OL',
tag: 'LI'
}
};
function Format(document, config) {
this.document = document;
this.config = config;
}
Format.prototype.add = function(node, value) {
var formatNode, inline, parentNode, _ref, _ref1;
if (!value) {
return this.remove(node);
}
if (this.value(node) === value) {
return node;
}
if (_.isString(this.config.parentTag)) {
parentNode = this.document.createElement(this.config.parentTag);
dom(node).wrap(parentNode);
if (node.parentNode.tagName === ((_ref = node.parentNode.previousSibling) != null ? _ref.tagName : void 0)) {
dom(node.parentNode.previousSibling).merge(node.parentNode);
}
if (node.parentNode.tagName === ((_ref1 = node.parentNode.nextSibling) != null ? _ref1.tagName : void 0)) {
dom(node.parentNode).merge(node.parentNode.nextSibling);
}
}
if (_.isString(this.config.tag)) {
formatNode = this.document.createElement(this.config.tag);
if (dom.VOID_TAGS[formatNode.tagName] != null) {
if (node.parentNode != null) {
dom(node).replace(formatNode);
}
node = formatNode;
} else if (this.isType(Format.types.LINE)) {
node = dom(node).switchTag(this.config.tag);
} else {
dom(node).wrap(formatNode);
node = formatNode;
}
}
if (_.isString(this.config.style) || _.isString(this.config.attribute) || _.isString(this.config["class"])) {
if (_.isString(this.config["class"])) {
node = this.remove(node);
}
if (dom(node).isTextNode()) {
inline = this.document.createElement(dom.DEFAULT_INLINE_TAG);
dom(node).wrap(inline);
node = inline;
}
if (_.isString(this.config.style)) {
if (value !== this.config["default"]) {
node.style[this.config.style] = value;
}
}
if (_.isString(this.config.attribute)) {
node.setAttribute(this.config.attribute, value);
}
if (_.isString(this.config["class"])) {
dom(node).addClass(this.config["class"] + value);
}
}
return node;
};
Format.prototype.isType = function(type) {
return type === this.config.type;
};
Format.prototype.match = function(node) {
var c, _i, _len, _ref, _ref1;
if (!dom(node).isElement()) {
return false;
}
if (_.isString(this.config.parentTag) && ((_ref = node.parentNode) != null ? _ref.tagName : void 0) !== this.config.parentTag) {
return false;
}
if (_.isString(this.config.tag) && node.tagName !== this.config.tag) {
return false;
}
if (_.isString(this.config.style) && (!node.style[this.config.style] || node.style[this.config.style] === this.config["default"])) {
return false;
}
if (_.isString(this.config.attribute) && !node.hasAttribute(this.config.attribute)) {
return false;
}
if (_.isString(this.config["class"])) {
_ref1 = dom(node).classes();
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
c = _ref1[_i];
if (c.indexOf(this.config["class"]) === 0) {
return true;
}
}
return false;
}
return true;
};
Format.prototype.prepare = function(value) {
if (_.isString(this.config.prepare)) {
return this.document.execCommand(this.config.prepare, false, value);
} else if (_.isFunction(this.config.prepare)) {
return this.config.prepare(this.document, value);
}
};
Format.prototype.remove = function(node) {
var c, _i, _len, _ref;
if (!this.match(node)) {
return node;
}
if (_.isString(this.config.style)) {
node.style[this.config.style] = '';
if (!node.getAttribute('style')) {
node.removeAttribute('style');
}
}
if (_.isString(this.config.attribute)) {
node.removeAttribute(this.config.attribute);
}
if (_.isString(this.config["class"])) {
_ref = dom(node).classes();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
c = _ref[_i];
if (c.indexOf(this.config["class"]) === 0) {
dom(node).removeClass(c);
}
}
if (!node.getAttribute('class')) {
node.removeAttribute('class');
}
}
if (_.isString(this.config.tag)) {
if (this.isType(Format.types.LINE)) {
if (_.isString(this.config.parentTag)) {
if (node.previousSibling != null) {
dom(node).splitAncestors(node.parentNode.parentNode);
}
if (node.nextSibling != null) {
dom(node.nextSibling).splitAncestors(node.parentNode.parentNode);
}
}
node = dom(node).switchTag(dom.DEFAULT_BLOCK_TAG);
} else {
node = dom(node).switchTag(dom.DEFAULT_INLINE_TAG);
if (dom.EMBED_TAGS[this.config.tag] != null) {
dom(node).text(dom.EMBED_TEXT);
}
}
}
if (_.isString(this.config.parentTag)) {
dom(node.parentNode).unwrap();
}
if (node.tagName === dom.DEFAULT_INLINE_TAG && !node.hasAttributes()) {
node = dom(node).unwrap();
}
return node;
};
Format.prototype.value = function(node) {
var c, _i, _len, _ref;
if (!this.match(node)) {
return void 0;
}
if (_.isString(this.config.attribute)) {
return node.getAttribute(this.config.attribute) || void 0;
} else if (_.isString(this.config.style)) {
return node.style[this.config.style] || void 0;
} else if (_.isString(this.config["class"])) {
_ref = dom(node).classes();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
c = _ref[_i];
if (c.indexOf(this.config["class"]) === 0) {
return c.slice(this.config["class"].length);
}
}
} else if (_.isString(this.config.tag)) {
return true;
}
return void 0;
};
return Format;
})();
module.exports = Format;
+66
View File
@@ -0,0 +1,66 @@
var Format, Leaf, LinkedList, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
_ = require('lodash');
dom = require('../lib/dom');
Format = require('./format');
LinkedList = require('../lib/linked-list');
Leaf = (function(_super) {
__extends(Leaf, _super);
Leaf.ID_PREFIX = 'leaf-';
Leaf.isLeafNode = function(node) {
return dom(node).isTextNode() || (node.firstChild == null);
};
function Leaf(node, formats) {
this.node = node;
this.formats = _.clone(formats);
this.id = _.uniqueId(Leaf.ID_PREFIX);
this.text = dom(this.node).text();
this.length = this.text.length;
}
Leaf.prototype.deleteText = function(offset, length) {
var textNode;
if (!(length > 0)) {
return;
}
this.text = this.text.slice(0, offset) + this.text.slice(offset + length);
this.length = this.text.length;
if (dom.EMBED_TAGS[this.node.tagName] != null) {
textNode = this.node.ownerDocument.createTextNode(this.text);
return this.node = dom(this.node).replace(textNode);
} else {
return dom(this.node).text(this.text);
}
};
Leaf.prototype.insertText = function(offset, text) {
var textNode;
this.text = this.text.slice(0, offset) + text + this.text.slice(offset);
if (dom(this.node).isTextNode()) {
dom(this.node).text(this.text);
} else {
textNode = this.node.ownerDocument.createTextNode(text);
if (this.node.tagName === dom.DEFAULT_BREAK_TAG) {
this.node = dom(this.node).replace(textNode);
} else {
this.node.appendChild(textNode);
this.node = textNode;
}
}
return this.length = this.text.length;
};
return Leaf;
})(LinkedList.Node);
module.exports = Leaf;
+260
View File
@@ -0,0 +1,260 @@
var Delta, Format, Leaf, Line, LinkedList, Normalizer, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
_ = require('lodash');
Delta = require('rich-text').Delta;
dom = require('../lib/dom');
Format = require('./format');
Leaf = require('./leaf');
Line = require('./line');
LinkedList = require('../lib/linked-list');
Normalizer = require('../lib/normalizer');
Line = (function(_super) {
__extends(Line, _super);
Line.CLASS_NAME = 'line';
Line.ID_PREFIX = 'line-';
function Line(doc, node) {
this.doc = doc;
this.node = node;
this.id = _.uniqueId(Line.ID_PREFIX);
this.formats = {};
dom(this.node).addClass(Line.CLASS_NAME);
this.rebuild();
Line.__super__.constructor.call(this, this.node);
}
Line.prototype.buildLeaves = function(node, formats) {
return _.each(dom(node).childNodes(), (function(_this) {
return function(node) {
var nodeFormats;
node = Normalizer.normalizeNode(node);
nodeFormats = _.clone(formats);
_.each(_this.doc.formats, function(format, name) {
if (!format.isType(Format.types.LINE) && format.match(node)) {
return nodeFormats[name] = format.value(node);
}
});
if (Leaf.isLeafNode(node)) {
return _this.leaves.append(new Leaf(node, nodeFormats));
} else {
return _this.buildLeaves(node, nodeFormats);
}
};
})(this));
};
Line.prototype.deleteText = function(offset, length) {
var deleteLength, leaf, _ref;
if (!(length > 0)) {
return;
}
_ref = this.findLeafAt(offset), leaf = _ref[0], offset = _ref[1];
while ((leaf != null) && length > 0) {
deleteLength = Math.min(length, leaf.length - offset);
leaf.deleteText(offset, deleteLength);
length -= deleteLength;
leaf = leaf.next;
offset = 0;
}
return this.rebuild();
};
Line.prototype.findLeaf = function(leafNode) {
var curLeaf;
curLeaf = this.leaves.first;
while (curLeaf != null) {
if (curLeaf.node === leafNode) {
return curLeaf;
}
curLeaf = curLeaf.next;
}
return null;
};
Line.prototype.findLeafAt = function(offset, inclusive) {
var leaf;
if (inclusive == null) {
inclusive = false;
}
if (offset >= this.length - 1) {
return [this.leaves.last, this.leaves.last.length];
}
leaf = this.leaves.first;
while (leaf != null) {
if (offset < leaf.length || (offset === leaf.length && inclusive)) {
return [leaf, offset];
}
offset -= leaf.length;
leaf = leaf.next;
}
return [this.leaves.last, offset - this.leaves.last.length];
};
Line.prototype.format = function(name, value) {
var formats;
if (_.isObject(name)) {
formats = name;
} else {
formats = {};
formats[name] = value;
}
_.each(formats, (function(_this) {
return function(value, name) {
var excludeFormat, format;
format = _this.doc.formats[name];
if (format.isType(Format.types.LINE)) {
if (format.config.exclude && _this.formats[format.config.exclude]) {
excludeFormat = _this.doc.formats[format.config.exclude];
if (excludeFormat != null) {
_this.node = excludeFormat.remove(_this.node);
delete _this.formats[format.config.exclude];
}
}
_this.node = format.add(_this.node, value);
}
if (value) {
return _this.formats[name] = value;
} else {
return delete _this.formats[name];
}
};
})(this));
return this.resetContent();
};
Line.prototype.formatText = function(offset, length, name, value) {
var format, leaf, leafOffset, leftNode, nextLeaf, rightNode, targetNode, _ref, _ref1, _ref2;
_ref = this.findLeafAt(offset), leaf = _ref[0], leafOffset = _ref[1];
format = this.doc.formats[name];
if (!((format != null) && format.config.type !== Format.types.LINE)) {
return;
}
while ((leaf != null) && length > 0) {
nextLeaf = leaf.next;
if ((value && leaf.formats[name] !== value) || (!value && (leaf.formats[name] != null))) {
targetNode = leaf.node;
if (leaf.formats[name] != null) {
dom(targetNode).splitAncestors(this.node);
while (!format.match(targetNode)) {
targetNode = targetNode.parentNode;
}
}
if (leafOffset > 0) {
_ref1 = dom(targetNode).split(leafOffset), leftNode = _ref1[0], targetNode = _ref1[1];
}
if (leaf.length > leafOffset + length) {
_ref2 = dom(targetNode).split(length), targetNode = _ref2[0], rightNode = _ref2[1];
}
format.add(targetNode, value);
}
length -= leaf.length - leafOffset;
leafOffset = 0;
leaf = nextLeaf;
}
return this.rebuild();
};
Line.prototype.insertText = function(offset, text, formats) {
var leaf, leafOffset, nextNode, node, prevNode, _ref, _ref1;
if (formats == null) {
formats = {};
}
if (!(text.length > 0)) {
return;
}
_ref = this.findLeafAt(offset), leaf = _ref[0], leafOffset = _ref[1];
if (_.isEqual(leaf.formats, formats)) {
leaf.insertText(leafOffset, text);
return this.resetContent();
} else {
node = _.reduce(formats, (function(_this) {
return function(node, value, name) {
return _this.doc.formats[name].add(node, value);
};
})(this), this.node.ownerDocument.createTextNode(text));
_ref1 = dom(leaf.node).split(leafOffset), prevNode = _ref1[0], nextNode = _ref1[1];
if (nextNode) {
nextNode = dom(nextNode).splitAncestors(this.node).get();
}
this.node.insertBefore(node, nextNode);
return this.rebuild();
}
};
Line.prototype.optimize = function() {
Normalizer.optimizeLine(this.node);
return this.rebuild();
};
Line.prototype.rebuild = function(force) {
if (force == null) {
force = false;
}
if (!force && (this.outerHTML != null) && this.outerHTML === this.node.outerHTML) {
if (_.all(this.leaves.toArray(), (function(_this) {
return function(leaf) {
return dom(leaf.node).isAncestor(_this.node);
};
})(this))) {
return false;
}
}
this.node = Normalizer.normalizeNode(this.node);
if (dom(this.node).length() === 0 && !this.node.querySelector(dom.DEFAULT_BREAK_TAG)) {
this.node.appendChild(this.node.ownerDocument.createElement(dom.DEFAULT_BREAK_TAG));
}
this.leaves = new LinkedList();
this.formats = _.reduce(this.doc.formats, (function(_this) {
return function(formats, format, name) {
if (format.isType(Format.types.LINE)) {
if (format.match(_this.node)) {
formats[name] = format.value(_this.node);
} else {
delete formats[name];
}
}
return formats;
};
})(this), this.formats);
this.buildLeaves(this.node, {});
this.resetContent();
return true;
};
Line.prototype.resetContent = function() {
if (this.node.id !== this.id) {
this.node.id = this.id;
}
this.outerHTML = this.node.outerHTML;
this.length = 1;
this.delta = new Delta();
this.leaves.toArray().forEach((function(_this) {
return function(leaf) {
_this.length += leaf.length;
if (dom.EMBED_TAGS[leaf.node.tagName] != null) {
return _this.delta.insert(1, leaf.formats);
} else {
return _this.delta.insert(leaf.text, leaf.formats);
}
};
})(this));
return this.delta.insert('\n', this.formats);
};
return Line;
})(LinkedList.Node);
module.exports = Line;
+177
View File
@@ -0,0 +1,177 @@
var DEFAULT_STYLES, LIST_STYLES, Normalizer, Renderer, dom, rule, _;
_ = require('lodash');
dom = require('../lib/dom');
Normalizer = require('../lib/normalizer');
DEFAULT_STYLES = {
'html': {
'height': '100%',
'width': '100%'
},
'body': {
'box-sizing': 'border-box',
'cursor': 'text',
'font-family': "'Helvetica', 'Arial', sans-serif",
'font-size': '13px',
'height': '100%',
'line-height': '1.42',
'margin': '0px',
'overflow-x': 'hidden',
'overflow-y': 'auto',
'padding': '12px 15px'
},
'.editor-container': {
'height': '100%',
'outline': 'none',
'position': 'relative',
'tab-size': '4',
'white-space': 'pre-wrap'
},
'.editor-container div': {
'margin': '0',
'padding': '0'
},
'.editor-container a': {
'text-decoration': 'underline'
},
'.editor-container b': {
'font-weight': 'bold'
},
'.editor-container i': {
'font-style': 'italic'
},
'.editor-container s': {
'text-decoration': 'line-through'
},
'.editor-container u': {
'text-decoration': 'underline'
},
'.editor-container img': {
'max-width': '100%'
},
'.editor-container blockquote': {
'margin': '0 0 0 2em',
'padding': '0'
},
'.editor-container ol': {
'margin': '0 0 0 2em',
'padding': '0',
'list-style-type': 'decimal'
},
'.editor-container ul': {
'margin': '0 0 0 2em',
'padding': '0',
'list-style-type': 'disc'
}
};
LIST_STYLES = ['decimal', 'lower-alpha', 'lower-roman'];
rule = '.editor-container ol > li';
_.each([1, 2, 3, 4, 5, 6, 7, 8, 9], function(i) {
rule += ' > ol';
DEFAULT_STYLES[rule] = {
'list-style-type': LIST_STYLES[i % 3]
};
return rule += ' > li';
});
if (dom.isIE(10)) {
DEFAULT_STYLES[dom.DEFAULT_BREAK_TAG] = {
'display': 'none'
};
}
Renderer = (function() {
Renderer.objToCss = function(obj) {
return _.map(obj, function(value, key) {
var innerStr;
innerStr = _.map(value, function(innerValue, innerKey) {
return "" + innerKey + ": " + innerValue + ";";
}).join(' ');
return "" + key + " { " + innerStr + " }";
}).join("\n");
};
Renderer.buildFrame = function(container) {
var iframe, iframeDoc, root;
iframe = container.ownerDocument.createElement('iframe');
dom(iframe).attributes({
frameBorder: '0',
height: '100%',
width: '100%',
title: 'Quill Rich Text Editor',
role: 'presentation'
});
container.appendChild(iframe);
iframeDoc = iframe.contentWindow.document;
iframeDoc.open();
iframeDoc.write('<!DOCTYPE html>');
iframeDoc.close();
root = iframeDoc.createElement('div');
iframeDoc.body.appendChild(root);
return [root, iframe];
};
function Renderer(container, options) {
var _ref;
this.container = container;
this.options = options != null ? options : {};
this.container.innerHTML = '';
_ref = Renderer.buildFrame(this.container), this.root = _ref[0], this.iframe = _ref[1];
this.root.setAttribute('id', this.options.id);
this.iframe.setAttribute('name', this.options.id);
dom(this.root).addClass('editor-container');
dom(this.container).addClass('ql-container');
if (dom.isIOS()) {
dom(this.container).styles({
'overflow': 'auto',
'-webkit-overflow-scrolling': 'touch'
});
}
this.addStyles(DEFAULT_STYLES);
if (this.options.styles != null) {
_.defer(_.bind(this.addStyles, this, this.options.styles));
}
}
Renderer.prototype.addContainer = function(className, before) {
var container, refNode;
if (before == null) {
before = false;
}
refNode = before ? this.root : null;
container = this.root.ownerDocument.createElement('div');
dom(container).addClass(className);
this.root.parentNode.insertBefore(container, refNode);
return container;
};
Renderer.prototype.addStyles = function(css) {
var link, style;
if (typeof css === 'object') {
style = this.root.ownerDocument.createElement('style');
style.type = 'text/css';
css = Renderer.objToCss(css);
style.appendChild(this.root.ownerDocument.createTextNode(css));
return this.root.ownerDocument.head.appendChild(style);
} else if (typeof css === 'string') {
link = this.root.ownerDocument.createElement('link');
dom(link).attributes({
type: 'text/css',
rel: 'stylesheet',
href: css
});
return this.root.ownerDocument.head.appendChild(link);
}
};
return Renderer;
})();
module.exports = Renderer;
+230
View File
@@ -0,0 +1,230 @@
var Leaf, Normalizer, Range, Selection, dom, _;
_ = require('lodash');
dom = require('../lib/dom');
Leaf = require('./leaf');
Normalizer = require('../lib/normalizer');
Range = require('../lib/range');
Selection = (function() {
function Selection(doc, iframe, emitter) {
this.doc = doc;
this.iframe = iframe;
this.emitter = emitter;
this.document = this.doc.root.ownerDocument;
this.focus = false;
this.range = new Range(0, 0);
this.nullDelay = false;
this.update('silent');
}
Selection.prototype.checkFocus = function() {
return this.document.activeElement === this.doc.root && document.activeElement === this.iframe;
};
Selection.prototype.getRange = function(ignoreFocus) {
var end, nativeRange, start;
if (ignoreFocus == null) {
ignoreFocus = false;
}
if (this.checkFocus()) {
nativeRange = this._getNativeRange();
if (nativeRange == null) {
return null;
}
start = this._positionToIndex(nativeRange.startContainer, nativeRange.startOffset);
if (nativeRange.startContainer === nativeRange.endContainer && nativeRange.startOffset === nativeRange.endOffset) {
end = start;
} else {
end = this._positionToIndex(nativeRange.endContainer, nativeRange.endOffset);
}
return new Range(Math.min(start, end), Math.max(start, end));
} else if (ignoreFocus) {
return this.range;
} else {
return null;
}
};
Selection.prototype.preserve = function(fn) {
var endNode, endOffset, nativeRange, startNode, startOffset, _ref, _ref1, _ref2, _ref3;
nativeRange = this._getNativeRange();
if ((nativeRange != null) && this.checkFocus()) {
_ref = this._encodePosition(nativeRange.startContainer, nativeRange.startOffset), startNode = _ref[0], startOffset = _ref[1];
_ref1 = this._encodePosition(nativeRange.endContainer, nativeRange.endOffset), endNode = _ref1[0], endOffset = _ref1[1];
fn();
_ref2 = this._decodePosition(startNode, startOffset), startNode = _ref2[0], startOffset = _ref2[1];
_ref3 = this._decodePosition(endNode, endOffset), endNode = _ref3[0], endOffset = _ref3[1];
return this._setNativeRange(startNode, startOffset, endNode, endOffset);
} else {
return fn();
}
};
Selection.prototype.setRange = function(range, source) {
var endNode, endOffset, startNode, startOffset, _ref, _ref1, _ref2;
if (range != null) {
_ref = this._indexToPosition(range.start), startNode = _ref[0], startOffset = _ref[1];
if (range.isCollapsed()) {
_ref1 = [startNode, startOffset], endNode = _ref1[0], endOffset = _ref1[1];
} else {
_ref2 = this._indexToPosition(range.end), endNode = _ref2[0], endOffset = _ref2[1];
}
this._setNativeRange(startNode, startOffset, endNode, endOffset);
} else {
this._setNativeRange(null);
}
return this.update(source);
};
Selection.prototype.shiftAfter = function(index, length, fn) {
var range;
range = this.getRange();
fn();
if (range != null) {
range.shift(index, length);
return this.setRange(range, 'silent');
}
};
Selection.prototype.update = function(source) {
var emit, focus, range, toEmit;
focus = this.checkFocus();
range = this.getRange(true);
emit = source !== 'silent' && (!Range.compare(range, this.range) || focus !== this.focus);
toEmit = focus ? range : null;
if (toEmit === null && source === 'user' && !this.nullDelay) {
return this.nullDelay = true;
} else {
this.nullDelay = false;
this.range = range;
this.focus = focus;
if (emit) {
return this.emitter.emit(this.emitter.constructor.events.SELECTION_CHANGE, toEmit, source);
}
}
};
Selection.prototype._decodePosition = function(node, offset) {
var childIndex;
if (dom(node).isElement()) {
childIndex = _.indexOf(dom(node.parentNode).childNodes(), node);
offset += childIndex;
node = node.parentNode;
}
return [node, offset];
};
Selection.prototype._encodePosition = function(node, offset) {
var text;
while (true) {
if (dom(node).isTextNode() || node.tagName === dom.DEFAULT_BREAK_TAG || (dom.EMBED_TAGS[node.tagName] != null)) {
return [node, offset];
} else if (offset < node.childNodes.length) {
node = node.childNodes[offset];
offset = 0;
} else if (node.childNodes.length === 0) {
if (Normalizer.TAGS[node.tagName] == null) {
text = node.ownerDocument.createTextNode('');
node.appendChild(text);
node = text;
}
return [node, 0];
} else {
node = node.lastChild;
if (dom(node).isElement()) {
if (node.tagName === dom.DEFAULT_BREAK_TAG || (dom.EMBED_TAGS[node.tagName] != null)) {
return [node, 1];
} else {
offset = node.childNodes.length;
}
} else {
return [node, dom(node).length()];
}
}
}
};
Selection.prototype._getNativeRange = function() {
var range, selection;
selection = this.document.getSelection();
if ((selection != null ? selection.rangeCount : void 0) > 0) {
range = selection.getRangeAt(0);
if (dom(range.startContainer).isAncestor(this.doc.root, true)) {
if (range.startContainer === range.endContainer || dom(range.endContainer).isAncestor(this.doc.root, true)) {
return range;
}
}
}
return null;
};
Selection.prototype._indexToPosition = function(index) {
var leaf, offset, _ref;
if (this.doc.lines.length === 0) {
return [this.doc.root, 0];
}
_ref = this.doc.findLeafAt(index, true), leaf = _ref[0], offset = _ref[1];
return this._decodePosition(leaf.node, offset);
};
Selection.prototype._positionToIndex = function(node, offset) {
var leaf, leafNode, leafOffset, line, lineOffset, _ref;
_ref = this._encodePosition(node, offset), leafNode = _ref[0], offset = _ref[1];
line = this.doc.findLine(leafNode);
if (line == null) {
return 0;
}
leaf = line.findLeaf(leafNode);
lineOffset = 0;
while (line.prev != null) {
line = line.prev;
lineOffset += line.length;
}
if (leaf == null) {
return lineOffset;
}
leafOffset = 0;
while (leaf.prev != null) {
leaf = leaf.prev;
leafOffset += leaf.length;
}
return lineOffset + leafOffset + offset;
};
Selection.prototype._setNativeRange = function(startNode, startOffset, endNode, endOffset) {
var nativeRange, selection;
selection = this.document.getSelection();
if (!selection) {
return;
}
if (startNode != null) {
if (!this.checkFocus()) {
this.doc.root.focus();
}
nativeRange = this._getNativeRange();
if ((nativeRange == null) || startNode !== nativeRange.startContainer || startOffset !== nativeRange.startOffset || endNode !== nativeRange.endContainer || endOffset !== nativeRange.endOffset) {
selection.removeAllRanges();
nativeRange = this.document.createRange();
nativeRange.setStart(startNode, startOffset);
nativeRange.setEnd(endNode, endOffset);
selection.addRange(nativeRange);
if (!this.checkFocus()) {
return this.doc.root.focus();
}
}
} else {
selection.removeAllRanges();
return this.doc.root.blur();
}
};
return Selection;
})();
module.exports = Selection;
+19
View File
@@ -0,0 +1,19 @@
require('./modules/authorship');
require('./modules/image-tooltip');
require('./modules/keyboard');
require('./modules/link-tooltip');
require('./modules/multi-cursor');
require('./modules/paste-manager');
require('./modules/toolbar');
require('./modules/tooltip');
require('./modules/undo-manager');
module.exports = require('./quill');
+28
View File
@@ -0,0 +1,28 @@
var ColorPicker, Picker, dom,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
dom = require('./dom');
Picker = require('./picker');
ColorPicker = (function(_super) {
__extends(ColorPicker, _super);
function ColorPicker() {
ColorPicker.__super__.constructor.apply(this, arguments);
dom(this.container).addClass('ql-color-picker');
}
ColorPicker.prototype.buildItem = function(picker, option, index) {
var item;
item = ColorPicker.__super__.buildItem.call(this, picker, option, index);
item.style.backgroundColor = option.value;
return item;
};
return ColorPicker;
})(Picker);
module.exports = ColorPicker;
+664
View File
@@ -0,0 +1,664 @@
var SelectWrapper, Wrapper, dom, lastKeyEvent, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
_ = require('lodash');
lastKeyEvent = null;
Wrapper = (function() {
function Wrapper(node) {
this.node = node;
this.trigger = __bind(this.trigger, this);
}
Wrapper.prototype.addClass = function(cssClass) {
if (this.hasClass(cssClass)) {
return;
}
if (this.node.classList != null) {
this.node.classList.add(cssClass);
} else if (this.node.className != null) {
this.node.className = (this.node.className + ' ' + cssClass).trim();
}
return this;
};
Wrapper.prototype.attributes = function(attributes) {
var attr, i, value, _i, _len, _ref;
if (attributes) {
_.each(attributes, (function(_this) {
return function(value, name) {
return _this.node.setAttribute(name, value);
};
})(this));
return this;
} else {
if (this.node.attributes == null) {
return {};
}
attributes = {};
_ref = this.node.attributes;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
value = _ref[i];
attr = this.node.attributes[i];
attributes[attr.name] = attr.value;
}
return attributes;
}
};
Wrapper.prototype.child = function(offset) {
var child, length;
child = this.node.firstChild;
length = dom(child).length();
while (child != null) {
if (offset < length) {
break;
}
offset -= length;
child = child.nextSibling;
length = dom(child).length();
}
if (child == null) {
child = this.node.lastChild;
offset = dom(child).length();
}
return [child, offset];
};
Wrapper.prototype.childNodes = function() {
return _.map(this.node.childNodes);
};
Wrapper.prototype.classes = function() {
return this.node.className.split(/\s+/);
};
Wrapper.prototype.descendants = function() {
return _.map(this.node.getElementsByTagName('*'));
};
Wrapper.prototype.get = function() {
return this.node;
};
Wrapper.prototype.hasClass = function(cssClass) {
if (this.node.classList != null) {
return this.node.classList.contains(cssClass);
} else if (this.node.className != null) {
return _.indexOf(this.classes(), cssClass) > -1;
}
return false;
};
Wrapper.prototype.isAncestor = function(ancestor, inclusive) {
var node;
if (inclusive == null) {
inclusive = false;
}
if (ancestor === this.node) {
return inclusive;
}
node = this.node;
while (node) {
if (node === ancestor) {
return true;
}
node = node.parentNode;
}
return false;
};
Wrapper.prototype.isElement = function() {
var _ref;
return ((_ref = this.node) != null ? _ref.nodeType : void 0) === dom.ELEMENT_NODE;
};
Wrapper.prototype.isTextNode = function() {
var _ref;
return ((_ref = this.node) != null ? _ref.nodeType : void 0) === dom.TEXT_NODE;
};
Wrapper.prototype.length = function() {
var length;
if (this.node == null) {
return 0;
}
length = this.text().length;
if (this.isElement()) {
length += this.node.querySelectorAll(_.keys(dom.EMBED_TAGS).join(',')).length;
}
return length;
};
Wrapper.prototype.merge = function(node) {
var $node;
$node = dom(node);
if (this.isElement()) {
$node.moveChildren(this.node);
this.normalize();
} else {
this.text(this.text() + $node.text());
}
$node.remove();
return this;
};
Wrapper.prototype.moveChildren = function(newParent) {
_.each(this.childNodes(), function(child) {
return newParent.appendChild(child);
});
return this;
};
Wrapper.prototype.nextLineNode = function(root) {
var nextNode;
nextNode = this.node.nextSibling;
if ((nextNode == null) && this.node.parentNode !== root) {
nextNode = this.node.parentNode.nextSibling;
}
if ((nextNode != null) && (dom.LIST_TAGS[nextNode.tagName] != null)) {
nextNode = nextNode.firstChild;
}
return nextNode;
};
Wrapper.prototype.normalize = function() {
var $node, curNode, followingNode, nextNode;
curNode = this.node.firstChild;
while (curNode != null) {
nextNode = curNode.nextSibling;
$node = dom(curNode);
if ((nextNode != null) && dom(nextNode).isTextNode()) {
if ($node.text().length === 0) {
$node.remove();
} else if ($node.isTextNode()) {
followingNode = nextNode.nextSibling;
$node.merge(nextNode);
nextNode = followingNode;
}
}
curNode = nextNode;
}
return this;
};
Wrapper.prototype.on = function(eventName, listener) {
this.node.addEventListener(eventName, (function(_this) {
return function(event) {
var arg, propagate;
arg = lastKeyEvent && (eventName === 'keydown' || eventName === 'keyup') ? lastKeyEvent : event;
propagate = listener.call(_this.node, arg);
if (!propagate) {
event.preventDefault();
event.stopPropagation();
}
return propagate;
};
})(this));
return this;
};
Wrapper.prototype.remove = function() {
var _ref;
if ((_ref = this.node.parentNode) != null) {
_ref.removeChild(this.node);
}
this.node = null;
return null;
};
Wrapper.prototype.removeClass = function(cssClass) {
var classArray;
if (!this.hasClass(cssClass)) {
return;
}
if (this.node.classList != null) {
return this.node.classList.remove(cssClass);
} else if (this.node.className != null) {
classArray = this.classes();
classArray.splice(_.indexOf(classArray, cssClass), 1);
this.node.className = classArray.join(' ');
}
return this;
};
Wrapper.prototype.replace = function(newNode) {
this.node.parentNode.replaceChild(newNode, this.node);
this.node = newNode;
return newNode;
};
Wrapper.prototype.splitAncestors = function(root, force) {
var nextNode, parentClone, parentNode, refNode;
if (force == null) {
force = false;
}
if (this.node === root || this.node.parentNode === root) {
return this;
}
if ((this.node.previousSibling != null) || force) {
parentNode = this.node.parentNode;
parentClone = parentNode.cloneNode(false);
parentNode.parentNode.insertBefore(parentClone, parentNode.nextSibling);
refNode = this.node;
while (refNode != null) {
nextNode = refNode.nextSibling;
parentClone.appendChild(refNode);
refNode = nextNode;
}
return dom(parentClone).splitAncestors(root);
} else {
return dom(this.node.parentNode).splitAncestors(root);
}
};
Wrapper.prototype.split = function(offset, force) {
var after, child, childLeft, childRight, left, nextRight, nodeLength, right, _ref, _ref1;
if (force == null) {
force = false;
}
nodeLength = this.length();
offset = Math.max(0, offset);
offset = Math.min(offset, nodeLength);
if (!(force || offset !== 0)) {
return [this.node.previousSibling, this.node, false];
}
if (!(force || offset !== nodeLength)) {
return [this.node, this.node.nextSibling, false];
}
if (this.node.nodeType === dom.TEXT_NODE) {
after = this.node.splitText(offset);
return [this.node, after, true];
} else {
left = this.node;
right = this.node.cloneNode(false);
this.node.parentNode.insertBefore(right, left.nextSibling);
_ref = this.child(offset), child = _ref[0], offset = _ref[1];
_ref1 = dom(child).split(offset), childLeft = _ref1[0], childRight = _ref1[1];
while (childRight !== null) {
nextRight = childRight.nextSibling;
right.appendChild(childRight);
childRight = nextRight;
}
return [left, right, true];
}
};
Wrapper.prototype.styles = function(styles, overwrite) {
var obj, styleString;
if (overwrite == null) {
overwrite = false;
}
if (styles) {
if (!overwrite) {
styles = _.defaults(styles, this.styles());
}
styleString = _.map(styles, function(style, name) {
return "" + name + ": " + style;
}).join('; ') + ';';
this.node.setAttribute('style', styleString);
return this;
} else {
styleString = this.node.getAttribute('style') || '';
obj = _.reduce(styleString.split(';'), function(styles, str) {
var name, value, _ref;
_ref = str.split(':'), name = _ref[0], value = _ref[1];
if (name && value) {
name = name.trim();
value = value.trim();
styles[name.toLowerCase()] = value;
}
return styles;
}, {});
return obj;
}
};
Wrapper.prototype.switchTag = function(newTag) {
var attributes, newNode;
newTag = newTag.toUpperCase();
if (this.node.tagName === newTag) {
return this;
}
newNode = this.node.ownerDocument.createElement(newTag);
attributes = this.attributes();
if (dom.VOID_TAGS[newTag] == null) {
this.moveChildren(newNode);
}
this.replace(newNode);
return this.attributes(attributes).get();
};
Wrapper.prototype.text = function(text) {
if (text != null) {
switch (this.node.nodeType) {
case dom.ELEMENT_NODE:
this.node.textContent = text;
break;
case dom.TEXT_NODE:
this.node.data = text;
}
return this;
} else {
switch (this.node.nodeType) {
case dom.ELEMENT_NODE:
if (this.node.tagName === dom.DEFAULT_BREAK_TAG) {
return "";
}
if (dom.EMBED_TAGS[this.node.tagName] != null) {
return dom.EMBED_TEXT;
}
if (this.node.textContent != null) {
return this.node.textContent;
}
return "";
case dom.TEXT_NODE:
return this.node.data || "";
default:
return "";
}
}
};
Wrapper.prototype.textNodes = function() {
var textNode, textNodes, walker;
walker = this.node.ownerDocument.createTreeWalker(this.node, NodeFilter.SHOW_TEXT, null, false);
textNodes = [];
while (textNode = walker.nextNode()) {
textNodes.push(textNode);
}
return textNodes;
};
Wrapper.prototype.toggleClass = function(className, state) {
if (state == null) {
state = !this.hasClass(className);
}
if (state) {
this.addClass(className);
} else {
this.removeClass(className);
}
return this;
};
Wrapper.prototype.trigger = function(eventName, options) {
var event, initFn, modifiers;
if (options == null) {
options = {};
}
if (_.indexOf(['keypress', 'keydown', 'keyup'], eventName) < 0) {
event = this.node.ownerDocument.createEvent('Event');
event.initEvent(eventName, options.bubbles, options.cancelable);
} else {
event = this.node.ownerDocument.createEvent('KeyboardEvent');
lastKeyEvent = _.clone(options);
if (_.isNumber(options.key)) {
lastKeyEvent.which = options.key;
} else if (_.isString(options.key)) {
lastKeyEvent.which = options.key.toUpperCase().charCodeAt(0);
} else {
lastKeyEvent.which = 0;
}
if (dom.isIE(10)) {
modifiers = [];
if (options.altKey) {
modifiers.push('Alt');
}
if (options.ctrlKey) {
modifiers.push('Control');
}
if (options.metaKey) {
modifiers.push('Meta');
}
if (options.shiftKey) {
modifiers.push('Shift');
}
event.initKeyboardEvent(eventName, options.bubbles, options.cancelable, this.window(), 0, 0, modifiers.join(' '), null, null);
} else {
initFn = _.isFunction(event.initKeyboardEvent) ? 'initKeyboardEvent' : 'initKeyEvent';
event[initFn](eventName, options.bubbles, options.cancelable, this.window(), options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 0, 0);
}
}
this.node.dispatchEvent(event);
lastKeyEvent = null;
return this;
};
Wrapper.prototype.unwrap = function() {
var next, ret;
ret = this.node.firstChild;
next = this.node.nextSibling;
_.each(this.childNodes(), (function(_this) {
return function(child) {
return _this.node.parentNode.insertBefore(child, next);
};
})(this));
this.remove();
return ret;
};
Wrapper.prototype.window = function() {
return this.node.ownerDocument.defaultView || this.node.ownerDocument.parentWindow;
};
Wrapper.prototype.wrap = function(wrapper) {
var parent;
if (this.node.parentNode != null) {
this.node.parentNode.insertBefore(wrapper, this.node);
}
parent = wrapper;
while (parent.firstChild != null) {
parent = wrapper.firstChild;
}
parent.appendChild(this.node);
return this;
};
return Wrapper;
})();
SelectWrapper = (function(_super) {
__extends(SelectWrapper, _super);
function SelectWrapper() {
return SelectWrapper.__super__.constructor.apply(this, arguments);
}
SelectWrapper.prototype["default"] = function() {
return this.node.querySelector('option[selected]');
};
SelectWrapper.prototype.option = function(option, trigger) {
var child, i, value, _i, _len, _ref;
if (trigger == null) {
trigger = true;
}
value = _.isElement(option) ? option.value : option;
if (value) {
value = value.replace(/[^\w]+/g, '');
_ref = this.node.children;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
child = _ref[i];
if (child.value.replace(/[^\w]+/g, '') === value) {
this.node.selectedIndex = i;
break;
}
}
} else {
this.node.selectedIndex = -1;
}
if (trigger) {
this.trigger('change');
}
return this;
};
SelectWrapper.prototype.reset = function(trigger) {
var option;
if (trigger == null) {
trigger = true;
}
option = this["default"]();
if (option != null) {
option.selected = true;
} else {
this.node.selectedIndex = 0;
}
if (trigger) {
this.trigger('change');
}
return this;
};
SelectWrapper.prototype.value = function() {
if (this.node.selectedIndex > -1) {
return this.node.options[this.node.selectedIndex].value;
} else {
return '';
}
};
return SelectWrapper;
})(Wrapper);
dom = function(node) {
if ((node != null ? node.tagName : void 0) === 'SELECT') {
return new SelectWrapper(node);
} else {
return new Wrapper(node);
}
};
dom = _.extend(dom, {
ELEMENT_NODE: 1,
NOBREAK_SPACE: "&nbsp;",
TEXT_NODE: 3,
ZERO_WIDTH_NOBREAK_SPACE: "\uFEFF",
DEFAULT_BLOCK_TAG: 'DIV',
DEFAULT_BREAK_TAG: 'BR',
DEFAULT_INLINE_TAG: 'SPAN',
EMBED_TEXT: '!',
FONT_SIZES: {
'10px': 1,
'13px': 2,
'16px': 3,
'18px': 4,
'24px': 5,
'32px': 6,
'48px': 7
},
KEYS: {
BACKSPACE: 8,
TAB: 9,
ENTER: 13,
ESCAPE: 27,
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40,
DELETE: 46
},
BLOCK_TAGS: {
'ADDRESS': 'ADDRESS',
'ARTICLE': 'ARTICLE',
'ASIDE': 'ASIDE',
'AUDIO': 'AUDIO',
'BLOCKQUOTE': 'BLOCKQUOTE',
'CANVAS': 'CANVAS',
'DD': 'DD',
'DIV': 'DIV',
'DL': 'DL',
'FIGCAPTION': 'FIGCAPTION',
'FIGURE': 'FIGURE',
'FOOTER': 'FOOTER',
'FORM': 'FORM',
'H1': 'H1',
'H2': 'H2',
'H3': 'H3',
'H4': 'H4',
'H5': 'H5',
'H6': 'H6',
'HEADER': 'HEADER',
'HGROUP': 'HGROUP',
'LI': 'LI',
'OL': 'OL',
'OUTPUT': 'OUTPUT',
'P': 'P',
'PRE': 'PRE',
'SECTION': 'SECTION',
'TABLE': 'TABLE',
'TBODY': 'TBODY',
'TD': 'TD',
'TFOOT': 'TFOOT',
'TH': 'TH',
'THEAD': 'THEAD',
'TR': 'TR',
'UL': 'UL',
'VIDEO': 'VIDEO'
},
EMBED_TAGS: {
'IMG': 'IMG'
},
LINE_TAGS: {
'DIV': 'DIV',
'LI': 'LI'
},
LIST_TAGS: {
'OL': 'OL',
'UL': 'UL'
},
VOID_TAGS: {
'AREA': 'AREA',
'BASE': 'BASE',
'BR': 'BR',
'COL': 'COL',
'COMMAND': 'COMMAND',
'EMBED': 'EMBED',
'HR': 'HR',
'IMG': 'IMG',
'INPUT': 'INPUT',
'KEYGEN': 'KEYGEN',
'LINK': 'LINK',
'META': 'META',
'PARAM': 'PARAM',
'SOURCE': 'SOURCE',
'TRACK': 'TRACK',
'WBR': 'WBR'
},
convertFontSize: function(size) {
var i, s, sources, targets;
if (_.isString(size) && size.indexOf('px') > -1) {
sources = _.keys(dom.FONT_SIZES);
targets = _.values(dom.FONT_SIZES);
} else {
targets = _.keys(dom.FONT_SIZES);
sources = _.values(dom.FONT_SIZES);
}
for (i in sources) {
s = sources[i];
if (parseInt(size) <= parseInt(s)) {
return targets[i];
}
}
return _.last(targets);
},
isIE: function(maxVersion) {
var version;
version = document.documentMode;
return version && maxVersion >= version;
},
isIOS: function() {
return /iPhone|iPad/i.test(navigator.userAgent);
},
isMac: function() {
return /Mac/i.test(navigator.platform);
}
});
module.exports = dom;
+88
View File
@@ -0,0 +1,88 @@
var LinkedList, Node;
Node = (function() {
function Node(data) {
this.data = data;
this.prev = this.next = null;
}
return Node;
})();
LinkedList = (function() {
LinkedList.Node = Node;
function LinkedList() {
this.length = 0;
this.first = this.last = null;
}
LinkedList.prototype.append = function(node) {
if (this.first != null) {
node.next = null;
this.last.next = node;
} else {
this.first = node;
}
node.prev = this.last;
this.last = node;
return this.length += 1;
};
LinkedList.prototype.insertAfter = function(refNode, newNode) {
newNode.prev = refNode;
if (refNode != null) {
newNode.next = refNode.next;
if (refNode.next != null) {
refNode.next.prev = newNode;
}
refNode.next = newNode;
if (refNode === this.last) {
this.last = newNode;
}
} else {
newNode.next = this.first;
this.first.prev = newNode;
this.first = newNode;
}
return this.length += 1;
};
LinkedList.prototype.remove = function(node) {
if (this.length > 1) {
if (node.prev != null) {
node.prev.next = node.next;
}
if (node.next != null) {
node.next.prev = node.prev;
}
if (node === this.first) {
this.first = node.next;
}
if (node === this.last) {
this.last = node.prev;
}
} else {
this.first = this.last = null;
}
node.prev = node.next = null;
return this.length -= 1;
};
LinkedList.prototype.toArray = function() {
var arr, cur;
arr = [];
cur = this.first;
while (cur != null) {
arr.push(cur);
cur = cur.next;
}
return arr;
};
return LinkedList;
})();
module.exports = LinkedList;
+208
View File
@@ -0,0 +1,208 @@
var Normalizer, dom, _;
_ = require('lodash');
dom = require('./dom');
Normalizer = {
ALIASES: {
'STRONG': 'B',
'EM': 'I',
'DEL': 'S',
'STRIKE': 'S'
},
ATTRIBUTES: {
'color': 'color',
'face': 'fontFamily',
'size': 'fontSize'
},
STYLES: {
'background-color': 'background-color',
'color': 'color',
'font-family': 'font-family',
'font-size': 'font-size',
'text-align': 'text-align'
},
TAGS: {
'DIV': 'DIV',
'BR': 'BR',
'SPAN': 'SPAN',
'B': 'B',
'I': 'I',
'S': 'S',
'U': 'U',
'A': 'A',
'IMG': 'IMG',
'OL': 'OL',
'UL': 'UL',
'LI': 'LI'
},
handleBreaks: function(lineNode) {
var breaks;
breaks = _.map(lineNode.querySelectorAll(dom.DEFAULT_BREAK_TAG));
_.each(breaks, (function(_this) {
return function(br) {
if ((br.nextSibling != null) && (!dom.isIE(10) || (br.previousSibling != null))) {
return dom(br.nextSibling).splitAncestors(lineNode.parentNode);
}
};
})(this));
return lineNode;
},
normalizeLine: function(lineNode) {
lineNode = Normalizer.wrapInline(lineNode);
lineNode = Normalizer.handleBreaks(lineNode);
lineNode = Normalizer.pullBlocks(lineNode);
lineNode = Normalizer.normalizeNode(lineNode);
Normalizer.unwrapText(lineNode);
if ((lineNode != null) && (dom.LIST_TAGS[lineNode.tagName] != null)) {
lineNode = lineNode.firstChild;
}
return lineNode;
},
normalizeNode: function(node) {
if (dom(node).isTextNode()) {
return node;
}
_.each(Normalizer.ATTRIBUTES, function(style, attribute) {
var value;
if (node.hasAttribute(attribute)) {
value = node.getAttribute(attribute);
if (attribute === 'size') {
value = dom.convertFontSize(value);
}
node.style[style] = value;
return node.removeAttribute(attribute);
}
});
Normalizer.whitelistStyles(node);
return Normalizer.whitelistTags(node);
},
optimizeLine: function(lineNode) {
var lineNodeLength, node, nodes, _results;
lineNodeLength = dom(lineNode).length();
nodes = dom(lineNode).descendants();
_results = [];
while (nodes.length > 0) {
node = nodes.pop();
if ((node != null ? node.parentNode : void 0) == null) {
continue;
}
if (dom.EMBED_TAGS[node.tagName] != null) {
continue;
}
if (node.tagName === dom.DEFAULT_BREAK_TAG) {
if (lineNodeLength !== 0) {
_results.push(dom(node).remove());
} else {
_results.push(void 0);
}
} else if (dom(node).length() === 0) {
nodes.push(node.nextSibling);
_results.push(dom(node).unwrap());
} else if ((node.previousSibling != null) && node.tagName === node.previousSibling.tagName) {
if (_.isEqual(dom(node).attributes(), dom(node.previousSibling).attributes())) {
nodes.push(node.firstChild);
_results.push(dom(node.previousSibling).merge(node));
} else {
_results.push(void 0);
}
} else {
_results.push(void 0);
}
}
return _results;
},
pullBlocks: function(lineNode) {
var curNode;
curNode = lineNode.firstChild;
while (curNode != null) {
if ((dom.BLOCK_TAGS[curNode.tagName] != null) && curNode.tagName !== 'LI') {
if (curNode.previousSibling != null) {
dom(curNode).splitAncestors(lineNode.parentNode);
}
if (curNode.nextSibling != null) {
dom(curNode.nextSibling).splitAncestors(lineNode.parentNode);
}
if ((dom.LIST_TAGS[curNode.tagName] == null) || !curNode.firstChild) {
dom(curNode).unwrap();
Normalizer.pullBlocks(lineNode);
} else {
dom(curNode.parentNode).unwrap();
if (lineNode.parentNode == null) {
lineNode = curNode;
}
}
break;
}
curNode = curNode.nextSibling;
}
return lineNode;
},
stripComments: function(html) {
return html.replace(/<!--[\s\S]*?-->/g, '');
},
stripWhitespace: function(html) {
html = html.replace(/^\s+/, '').replace(/\s+$/, '');
html = html.replace(/^\s+/, '').replace(/\s+$/, '');
html = html.replace(/(\r?\n|\r)+/g, ' ');
html = html.replace(/\>\s+\</g, '><');
return html;
},
whitelistStyles: function(node) {
var original, styles;
original = dom(node).styles();
styles = _.omit(original, function(value, key) {
return Normalizer.STYLES[key] == null;
});
if (_.keys(styles).length < _.keys(original).length) {
if (_.keys(styles).length > 0) {
return dom(node).styles(styles, true);
} else {
return node.removeAttribute('style');
}
}
},
whitelistTags: function(node) {
if (!dom(node).isElement()) {
return node;
}
if (Normalizer.ALIASES[node.tagName] != null) {
node = dom(node).switchTag(Normalizer.ALIASES[node.tagName]);
} else if (Normalizer.TAGS[node.tagName] == null) {
if (dom.BLOCK_TAGS[node.tagName] != null) {
node = dom(node).switchTag(dom.DEFAULT_BLOCK_TAG);
} else if (!node.hasAttributes() && (node.firstChild != null)) {
node = dom(node).unwrap();
} else {
node = dom(node).switchTag(dom.DEFAULT_INLINE_TAG);
}
}
return node;
},
wrapInline: function(lineNode) {
var blockNode, nextNode;
if (dom.BLOCK_TAGS[lineNode.tagName] != null) {
return lineNode;
}
blockNode = lineNode.ownerDocument.createElement(dom.DEFAULT_BLOCK_TAG);
lineNode.parentNode.insertBefore(blockNode, lineNode);
while ((lineNode != null) && (dom.BLOCK_TAGS[lineNode.tagName] == null)) {
nextNode = lineNode.nextSibling;
blockNode.appendChild(lineNode);
lineNode = nextNode;
}
return blockNode;
},
unwrapText: function(lineNode) {
var spans;
spans = _.map(lineNode.querySelectorAll(dom.DEFAULT_INLINE_TAG));
return _.each(spans, function(span) {
if (!span.hasAttributes()) {
return dom(span).unwrap();
}
});
}
};
module.exports = Normalizer;
+107
View File
@@ -0,0 +1,107 @@
var Normalizer, Picker, dom, _;
_ = require('lodash');
dom = require('./dom');
Normalizer = require('./normalizer');
Picker = (function() {
Picker.TEMPLATE = '<span class="ql-picker-label"></span><span class="ql-picker-options"></span>';
function Picker(select) {
this.select = select;
this.container = this.select.ownerDocument.createElement('span');
this.buildPicker();
dom(this.container).addClass('ql-picker');
this.select.style.display = 'none';
this.select.parentNode.insertBefore(this.container, this.select);
dom(this.select.ownerDocument).on('click', (function(_this) {
return function() {
_this.close();
return true;
};
})(this));
dom(this.label).on('click', (function(_this) {
return function() {
_.defer(function() {
return dom(_this.container).toggleClass('ql-expanded');
});
return false;
};
})(this));
dom(this.select).on('change', (function(_this) {
return function() {
var item, option;
if (_this.select.selectedIndex > -1) {
item = _this.container.querySelectorAll('.ql-picker-item')[_this.select.selectedIndex];
option = _this.select.options[_this.select.selectedIndex];
}
_this.selectItem(item, false);
return dom(_this.label).toggleClass('ql-active', option !== dom(_this.select)["default"]());
};
})(this));
}
Picker.prototype.buildItem = function(picker, option, index) {
var item;
item = this.select.ownerDocument.createElement('span');
item.setAttribute('data-value', option.getAttribute('value'));
dom(item).addClass('ql-picker-item').text(dom(option).text()).on('click', (function(_this) {
return function() {
_this.selectItem(item, true);
return _this.close();
};
})(this));
if (this.select.selectedIndex === index) {
this.selectItem(item, false);
}
return item;
};
Picker.prototype.buildPicker = function() {
var picker;
_.each(dom(this.select).attributes(), (function(_this) {
return function(value, name) {
return _this.container.setAttribute(name, value);
};
})(this));
this.container.innerHTML = Normalizer.stripWhitespace(Picker.TEMPLATE);
this.label = this.container.querySelector('.ql-picker-label');
picker = this.container.querySelector('.ql-picker-options');
return _.each(this.select.options, (function(_this) {
return function(option, i) {
var item;
item = _this.buildItem(picker, option, i);
return picker.appendChild(item);
};
})(this));
};
Picker.prototype.close = function() {
return dom(this.container).removeClass('ql-expanded');
};
Picker.prototype.selectItem = function(item, trigger) {
var selected, value;
selected = this.container.querySelector('.ql-selected');
if (selected != null) {
dom(selected).removeClass('ql-selected');
}
if (item != null) {
value = item.getAttribute('data-value');
dom(item).addClass('ql-selected');
dom(this.label).text(dom(item).text());
dom(this.select).option(value, trigger);
return this.label.setAttribute('data-value', value);
} else {
this.label.innerHTML = '&nbsp;';
return this.label.removeAttribute('data-value');
}
};
return Picker;
})();
module.exports = Picker;
+50
View File
@@ -0,0 +1,50 @@
var Range, _;
_ = require('lodash');
Range = (function() {
Range.compare = function(r1, r2) {
if (r1 === r2) {
return true;
}
if (!((r1 != null) && (r2 != null))) {
return false;
}
return r1.equals(r2);
};
function Range(start, end) {
this.start = start;
this.end = end;
}
Range.prototype.equals = function(range) {
if (range == null) {
return false;
}
return this.start === range.start && this.end === range.end;
};
Range.prototype.shift = function(index, length) {
var _ref;
return _ref = _.map([this.start, this.end], function(pos) {
if (index > pos) {
return pos;
}
if (length >= 0) {
return pos + length;
} else {
return Math.max(index, pos + length);
}
}), this.start = _ref[0], this.end = _ref[1], _ref;
};
Range.prototype.isCollapsed = function() {
return this.start === this.end;
};
return Range;
})();
module.exports = Range;
+97
View File
@@ -0,0 +1,97 @@
var Authorship, Delta, Quill, dom, _;
Quill = require('../quill');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Delta = Quill.require('delta');
Authorship = (function() {
Authorship.DEFAULTS = {
authorId: null,
color: 'transparent',
enabled: false
};
function Authorship(quill, options) {
this.quill = quill;
this.options = options;
if (this.options.button != null) {
this.attachButton(this.options.button);
}
if (this.options.enabled) {
this.enable();
}
this.quill.addFormat('author', {
"class": 'author-'
});
if (this.options.authorId == null) {
return;
}
this.quill.on(this.quill.constructor.events.PRE_EVENT, (function(_this) {
return function(eventName, delta, origin) {
var authorDelta, authorFormat;
if (eventName === _this.quill.constructor.events.TEXT_CHANGE && origin === 'user') {
authorDelta = new Delta();
authorFormat = {
author: _this.options.authorId
};
_.each(delta.ops, function(op) {
if (op["delete"] != null) {
return;
}
if ((op.insert != null) || ((op.retain != null) && (op.attributes != null))) {
op.attributes || (op.attributes = {});
op.attributes.author = _this.options.authorId;
return authorDelta.retain(op.retain || op.insert.length || 1, authorFormat);
} else {
return authorDelta.retain(op.retain);
}
});
return _this.quill.updateContents(authorDelta, Quill.sources.SILENT);
}
};
})(this));
this.addAuthor(this.options.authorId, this.options.color);
}
Authorship.prototype.addAuthor = function(id, color) {
var styles;
styles = {};
styles[".authorship .author-" + id] = {
"background-color": "" + color
};
return this.quill.addStyles(styles);
};
Authorship.prototype.attachButton = function(button) {
var $button;
$button = dom(button);
return $button.on('click', (function(_this) {
return function() {
$button.toggleClass('ql-on');
return _this.enable($dom.hasClass('ql-on'));
};
})(this));
};
Authorship.prototype.enable = function(enabled) {
if (enabled == null) {
enabled = true;
}
return dom(this.quill.root).toggleClass('authorship', enabled);
};
Authorship.prototype.disable = function() {
return this.enable(false);
};
return Authorship;
})();
Quill.registerModule('authorship', Authorship);
module.exports = Authorship;
+158
View File
@@ -0,0 +1,158 @@
var Delta, ImageTooltip, Quill, Tooltip, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Quill = require('../quill');
Tooltip = require('./tooltip');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Delta = Quill.require('delta');
ImageTooltip = (function(_super) {
__extends(ImageTooltip, _super);
ImageTooltip.DEFAULTS = {
styles: {
'.image-tooltip-container': {
'margin': '25px',
'padding': '10px',
'width': '300px'
},
'.image-tooltip-container:after': {
'clear': 'both',
'content': '""',
'display': 'table'
},
'.image-tooltip-container .preview': {
'margin': '10px 0px',
'position': 'relative',
'border': '1px dashed #000',
'height': '200px'
},
'.image-tooltip-container .preview span': {
'display': 'inline-block',
'position': 'absolute',
'text-align': 'center',
'top': '40%',
'width': '100%'
},
'.image-tooltip-container img': {
'bottom': '0',
'left': '0',
'margin': 'auto',
'max-height': '100%',
'max-width': '100%',
'position': 'absolute',
'right': '0',
'top': '0'
},
'.image-tooltip-container .input': {
'box-sizing': 'border-box',
'width': '100%'
},
'.image-tooltip-container a': {
'border': '1px solid black',
'box-sizing': 'border-box',
'display': 'inline-block',
'float': 'left',
'padding': '5px',
'text-align': 'center',
'width': '50%'
}
},
template: '<input class="input" type="textbox"> <div class="preview"> <span>Preview</span> </div> <a href="javascript:;" class="cancel">Cancel</a> <a href="javascript:;" class="insert">Insert</a>'
};
function ImageTooltip(quill, options) {
this.quill = quill;
this.options = options;
this.options.styles = _.defaults(this.options.styles, Tooltip.DEFAULTS.styles);
this.options = _.defaults(this.options, Tooltip.DEFAULTS);
ImageTooltip.__super__.constructor.call(this, this.quill, this.options);
this.preview = this.container.querySelector('.preview');
this.textbox = this.container.querySelector('.input');
dom(this.container).addClass('image-tooltip-container');
this.initListeners();
}
ImageTooltip.prototype.initListeners = function() {
dom(this.container.querySelector('.insert')).on('click', _.bind(this.insertImage, this));
dom(this.container.querySelector('.cancel')).on('click', _.bind(this.hide, this));
dom(this.textbox).on('input', _.bind(this._preview, this));
this.initTextbox(this.textbox, this.insertImage, this.hide);
return this.quill.onModuleLoad('toolbar', (function(_this) {
return function(toolbar) {
return toolbar.initFormat('image', _.bind(_this._onToolbar, _this));
};
})(this));
};
ImageTooltip.prototype.insertImage = function() {
var index, url;
url = this._normalizeURL(this.textbox.value);
if (this.range == null) {
this.range = new Range(0, 0);
}
if (this.range) {
this.preview.innerHTML = '<span>Preview</span>';
this.textbox.value = '';
index = this.range.end;
this.quill.insertEmbed(index, 'image', url, 'user');
this.quill.setSelection(index + 1, index + 1);
}
return this.hide();
};
ImageTooltip.prototype._onToolbar = function(range, value) {
if (value) {
if (!this.textbox.value) {
this.textbox.value = 'http://';
}
this.show();
this.textbox.focus();
return _.defer((function(_this) {
return function() {
return _this.textbox.setSelectionRange(_this.textbox.value.length, _this.textbox.value.length);
};
})(this));
} else {
return this.quill.deleteText(range, 'user');
}
};
ImageTooltip.prototype._preview = function() {
var img;
if (!this._matchImageURL(this.textbox.value)) {
return;
}
if (this.preview.firstChild.tagName === 'IMG') {
return this.preview.firstChild.setAttribute('src', this.textbox.value);
} else {
img = this.preview.ownerDocument.createElement('img');
img.setAttribute('src', this.textbox.value);
return this.preview.replaceChild(img, this.preview.firstChild);
}
};
ImageTooltip.prototype._matchImageURL = function(url) {
return /^https?:\/\/.+\.(jp?g|gif|png)$/.test(url);
};
ImageTooltip.prototype._normalizeURL = function(url) {
if (!/^https?:\/\//.test(url)) {
url = 'http://' + url;
}
return url;
};
return ImageTooltip;
})(Tooltip);
Quill.registerModule('image-tooltip', ImageTooltip);
module.exports = ImageTooltip;
+155
View File
@@ -0,0 +1,155 @@
var Delta, Keyboard, Quill, dom, _;
Quill = require('../quill');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Delta = Quill.require('delta');
Keyboard = (function() {
Keyboard.hotkeys = {
BOLD: {
key: 'B',
metaKey: true
},
INDENT: {
key: dom.KEYS.TAB
},
ITALIC: {
key: 'I',
metaKey: true
},
OUTDENT: {
key: dom.KEYS.TAB,
shiftKey: true
},
UNDERLINE: {
key: 'U',
metaKey: true
}
};
function Keyboard(quill, options) {
this.quill = quill;
this.hotkeys = {};
this._initListeners();
this._initHotkeys();
this._initDeletes();
}
Keyboard.prototype.addHotkey = function(hotkeys, callback) {
if (!_.isArray(hotkeys)) {
hotkeys = [hotkeys];
}
return _.each(hotkeys, (function(_this) {
return function(hotkey) {
var which, _base;
hotkey = _.isObject(hotkey) ? _.clone(hotkey) : {
key: hotkey
};
hotkey.callback = callback;
which = _.isNumber(hotkey.key) ? hotkey.key : hotkey.key.toUpperCase().charCodeAt(0);
if ((_base = _this.hotkeys)[which] == null) {
_base[which] = [];
}
return _this.hotkeys[which].push(hotkey);
};
})(this));
};
Keyboard.prototype.toggleFormat = function(range, format) {
var delta, toolbar, value;
if (range.isCollapsed()) {
delta = this.quill.getContents(Math.max(0, range.start - 1), range.end);
} else {
delta = this.quill.getContents(range);
}
value = delta.ops.length === 0 || !_.all(delta.ops, function(op) {
var _ref;
return (_ref = op.attributes) != null ? _ref[format] : void 0;
});
if (range.isCollapsed()) {
this.quill.prepareFormat(format, value);
} else {
this.quill.formatText(range, format, value, 'user');
}
toolbar = this.quill.getModule('toolbar');
if (toolbar != null) {
return toolbar.setActive(format, value);
}
};
Keyboard.prototype._initDeletes = function() {
return this.addHotkey([dom.KEYS.DELETE, dom.KEYS.BACKSPACE], (function(_this) {
return function() {
return _this.quill.getLength() > 1;
};
})(this));
};
Keyboard.prototype._initHotkeys = function() {
this.addHotkey(Keyboard.hotkeys.INDENT, (function(_this) {
return function(range) {
_this._onTab(range, false);
return false;
};
})(this));
this.addHotkey(Keyboard.hotkeys.OUTDENT, (function(_this) {
return function(range) {
return false;
};
})(this));
return _.each(['bold', 'italic', 'underline'], (function(_this) {
return function(format) {
return _this.addHotkey(Keyboard.hotkeys[format.toUpperCase()], function(range) {
_this.toggleFormat(range, format);
return false;
});
};
})(this));
};
Keyboard.prototype._initListeners = function() {
return dom(this.quill.root).on('keydown', (function(_this) {
return function(event) {
var prevent;
prevent = false;
_.each(_this.hotkeys[event.which], function(hotkey) {
var metaKey;
metaKey = dom.isMac() ? event.metaKey : event.metaKey || event.ctrlKey;
if (!!hotkey.metaKey !== !!metaKey) {
return;
}
if (!!hotkey.shiftKey !== !!event.shiftKey) {
return;
}
if (!!hotkey.altKey !== !!event.altKey) {
return;
}
prevent = hotkey.callback(_this.quill.getSelection()) === false || prevent;
return true;
});
return !prevent;
};
})(this));
};
Keyboard.prototype._onTab = function(range, shift) {
var delta;
if (shift == null) {
shift = false;
}
delta = new Delta().retain(range.start).insert("\t")["delete"](range.end - range.start).retain(this.quill.getLength() - range.end);
this.quill.updateContents(delta);
return this.quill.setSelection(range.start + 1, range.start + 1);
};
return Keyboard;
})();
Quill.registerModule('keyboard', Keyboard);
module.exports = Keyboard;
+163
View File
@@ -0,0 +1,163 @@
var LinkTooltip, Quill, Tooltip, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Quill = require('../quill');
Tooltip = require('./tooltip');
_ = Quill.require('lodash');
dom = Quill.require('dom');
LinkTooltip = (function(_super) {
__extends(LinkTooltip, _super);
LinkTooltip.DEFAULTS = {
maxLength: 50,
styles: {
'.link-tooltip-container': {
'padding': '5px 10px'
},
'.link-tooltip-container input.input': {
'width': '170px'
},
'.link-tooltip-container input.input, .link-tooltip-container a.done, .link-tooltip-container.editing a.url, .link-tooltip-container.editing a.change': {
'display': 'none'
},
'.link-tooltip-container.editing input.input, .link-tooltip-container.editing a.done': {
'display': 'inline-block'
}
},
template: '<span class="title">Visit URL:&nbsp;</span> <a href="#" class="url" target="_blank" href="about:blank"></a> <input class="input" type="text"> <span>&nbsp;&#45;&nbsp;</span> <a href="javascript:;" class="change">Change</a> <a href="javascript:;" class="done">Done</a>'
};
function LinkTooltip(quill, options) {
this.quill = quill;
this.options = options;
this.options.styles = _.defaults(this.options.styles, Tooltip.DEFAULTS.styles);
this.options = _.defaults(this.options, Tooltip.DEFAULTS);
LinkTooltip.__super__.constructor.call(this, this.quill, this.options);
dom(this.container).addClass('link-tooltip-container');
this.textbox = this.container.querySelector('.input');
this.link = this.container.querySelector('.url');
this.initListeners();
}
LinkTooltip.prototype.initListeners = function() {
this.quill.on(this.quill.constructor.events.SELECTION_CHANGE, (function(_this) {
return function(range) {
var anchor;
if (!((range != null) && range.isCollapsed())) {
return;
}
anchor = _this._findAnchor(range);
if (anchor) {
_this.setMode(anchor.href, false);
return _this.show(anchor);
} else {
_this.range = null;
return _this.hide();
}
};
})(this));
dom(this.container.querySelector('.done')).on('click', _.bind(this.saveLink, this));
dom(this.container.querySelector('.change')).on('click', (function(_this) {
return function() {
return _this.setMode(_this.link.href, true);
};
})(this));
this.initTextbox(this.textbox, this.saveLink, this.hide);
return this.quill.onModuleLoad('toolbar', (function(_this) {
return function(toolbar) {
return toolbar.initFormat('link', _.bind(_this._onToolbar, _this));
};
})(this));
};
LinkTooltip.prototype.saveLink = function() {
var anchor, url;
url = this._normalizeURL(this.textbox.value);
if (this.range != null) {
if (this.range.isCollapsed()) {
anchor = this._findAnchor(this.range);
if (anchor != null) {
anchor.href = url;
}
} else {
this.quill.formatText(this.range, 'link', url, 'user');
}
}
return this.setMode(url, false);
};
LinkTooltip.prototype.setMode = function(url, edit) {
var text;
if (edit == null) {
edit = false;
}
if (edit) {
this.textbox.value = url;
_.defer((function(_this) {
return function() {
_this.textbox.focus();
return _this.textbox.setSelectionRange(url.length, url.length);
};
})(this));
} else {
this.link.href = url;
text = url.length > this.options.maxLength ? url.slice(0, this.options.maxLength) + '...' : url;
dom(this.link).text(text);
}
return dom(this.container).toggleClass('editing', edit);
};
LinkTooltip.prototype._findAnchor = function(range) {
var leaf, node, offset, _ref;
_ref = this.quill.editor.doc.findLeafAt(range.start, true), leaf = _ref[0], offset = _ref[1];
if (leaf != null) {
node = leaf.node;
}
while (node != null) {
if (node.tagName === 'A') {
return node;
}
node = node.parentNode;
}
return null;
};
LinkTooltip.prototype._onToolbar = function(range, value) {
var nativeRange;
if (!(range && !range.isCollapsed())) {
return;
}
if (value) {
this.setMode(this._suggestURL(range), true);
nativeRange = this.quill.editor.selection._getNativeRange();
return this.show(nativeRange);
} else {
return this.quill.formatText(range, 'link', false, 'user');
}
};
LinkTooltip.prototype._normalizeURL = function(url) {
if (!/^(https?:\/\/|mailto:)/.test(url)) {
url = 'http://' + url;
}
return url;
};
LinkTooltip.prototype._suggestURL = function(range) {
var text;
text = this.quill.getText(range);
return this._normalizeURL(text);
};
return LinkTooltip;
})(Tooltip);
Quill.registerModule('link-tooltip', LinkTooltip);
module.exports = LinkTooltip;
+226
View File
@@ -0,0 +1,226 @@
var EventEmitter2, MultiCursor, Quill, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Quill = require('../quill');
EventEmitter2 = require('eventemitter2').EventEmitter2;
_ = Quill.require('lodash');
dom = Quill.require('dom');
MultiCursor = (function(_super) {
__extends(MultiCursor, _super);
MultiCursor.DEFAULTS = {
template: '<span class="cursor-flag"> <span class="cursor-name"></span> </span> <span class="cursor-caret"></span>',
timeout: 2500
};
MultiCursor.events = {
CURSOR_ADDED: 'cursor-addded',
CURSOR_MOVED: 'cursor-moved',
CURSOR_REMOVED: 'cursor-removed'
};
function MultiCursor(quill, options) {
this.quill = quill;
this.options = options;
this.cursors = {};
this.container = this.quill.addContainer('cursor-container', true);
this.quill.addStyles({
'.cursor-container': {
'position': 'absolute',
'left': '0',
'top': '0',
'z-index': '1000'
},
'.cursor': {
'margin-left': '-1px',
'position': 'absolute'
},
'.cursor-flag': {
'bottom': '100%',
'position': 'absolute',
'white-space': 'nowrap'
},
'.cursor-name': {
'display': 'inline-block',
'color': 'white',
'padding': '2px 8px'
},
'.cursor-caret': {
'height': '100%',
'position': 'absolute',
'width': '2px'
},
'.cursor.hidden .cursor-flag': {
'display': 'none'
},
'.cursor.top > .cursor-flag': {
'bottom': 'auto',
'top': '100%'
},
'.cursor.right > .cursor-flag': {
'right': '-2px'
}
});
this.quill.on(this.quill.constructor.events.TEXT_CHANGE, _.bind(this._applyDelta, this));
}
MultiCursor.prototype.clearCursors = function() {
_.each(_.keys(this.cursors), _.bind(this.removeCursor, this));
return this.cursors = {};
};
MultiCursor.prototype.moveCursor = function(userId, index) {
var cursor;
cursor = this.cursors[userId];
cursor.index = index;
dom(cursor.elem).removeClass('hidden');
clearTimeout(cursor.timer);
cursor.timer = setTimeout((function(_this) {
return function() {
dom(cursor.elem).addClass('hidden');
return cursor.timer = null;
};
})(this), this.options.timeout);
this._updateCursor(cursor);
return cursor;
};
MultiCursor.prototype.removeCursor = function(userId) {
var cursor;
cursor = this.cursors[userId];
this.emit(MultiCursor.events.CURSOR_REMOVED, cursor);
if (cursor != null) {
cursor.elem.parentNode.removeChild(cursor.elem);
}
return delete this.cursors[userId];
};
MultiCursor.prototype.setCursor = function(userId, index, name, color) {
var cursor;
if (this.cursors[userId] == null) {
this.cursors[userId] = cursor = {
userId: userId,
index: index,
color: color,
elem: this._buildCursor(name, color)
};
this.emit(MultiCursor.events.CURSOR_ADDED, cursor);
}
_.defer((function(_this) {
return function() {
return _this.moveCursor(userId, index);
};
})(this));
return this.cursors[userId];
};
MultiCursor.prototype.shiftCursors = function(index, length, authorId) {
if (authorId == null) {
authorId = null;
}
return _.each(this.cursors, (function(_this) {
return function(cursor, id) {
if (!(cursor && (cursor.index > index || cursor.userId === authorId))) {
return;
}
return cursor.index += Math.max(length, index - cursor.index);
};
})(this));
};
MultiCursor.prototype.update = function() {
return _.each(this.cursors, (function(_this) {
return function(cursor, id) {
if (cursor == null) {
return;
}
_this._updateCursor(cursor);
return true;
};
})(this));
};
MultiCursor.prototype._applyDelta = function(delta) {
var index;
index = 0;
_.each(delta.ops, (function(_this) {
return function(op) {
var length, _ref;
length = 0;
if (op.insert != null) {
length = op.insert.length || 1;
_this.shiftCursors(index, length, (_ref = op.attributes) != null ? _ref['author'] : void 0);
} else if (op["delete"] != null) {
_this.shiftCursors(index, -1 * op["delete"], null);
} else if (op.retain != null) {
_this.shiftCursors(index, 0, null);
length = op.retain;
}
return index += length;
};
})(this));
return this.update();
};
MultiCursor.prototype._buildCursor = function(name, color) {
var cursor, cursorCaret, cursorFlag, cursorName;
cursor = this.container.ownerDocument.createElement('span');
dom(cursor).addClass('cursor');
cursor.innerHTML = this.options.template;
cursorFlag = cursor.querySelector('.cursor-flag');
cursorName = cursor.querySelector('.cursor-name');
dom(cursorName).text(name);
cursorCaret = cursor.querySelector('.cursor-caret');
cursorCaret.style.backgroundColor = cursorName.style.backgroundColor = color;
this.container.appendChild(cursor);
return cursor;
};
MultiCursor.prototype._moveCursor = function(cursor, reference, side) {
var bounds, flag, win;
if (side == null) {
side = 'left';
}
win = dom(reference).window();
bounds = reference.getBoundingClientRect();
cursor.elem.style.top = bounds.top + win.pageYOffset + 'px';
cursor.elem.style.left = bounds[side] + 'px';
cursor.elem.style.height = bounds.height + 'px';
flag = cursor.elem.querySelector('.cursor-flag');
dom(cursor.elem).toggleClass('top', parseInt(cursor.elem.style.top) <= flag.offsetHeight).toggleClass('left', parseInt(cursor.elem.style.left) <= flag.offsetWidth).toggleClass('right', this.quill.root.offsetWidth - parseInt(cursor.elem.style.left) <= flag.offsetWidth);
return this.emit(MultiCursor.events.CURSOR_MOVED, cursor);
};
MultiCursor.prototype._updateCursor = function(cursor) {
var didSplit, guide, leaf, leftNode, offset, rightNode, _ref, _ref1;
this.quill.editor.checkUpdate();
_ref = this.quill.editor.doc.findLeafAt(cursor.index, true), leaf = _ref[0], offset = _ref[1];
guide = this.container.ownerDocument.createElement('span');
if (leaf != null) {
_ref1 = dom(leaf.node).split(offset), leftNode = _ref1[0], rightNode = _ref1[1], didSplit = _ref1[2];
dom(guide).text(dom.ZERO_WIDTH_NOBREAK_SPACE);
leaf.node.parentNode.insertBefore(guide, rightNode);
} else {
dom(guide).text(dom.NOBREAK_SPACE);
this.quill.root.appendChild(guide);
}
this._moveCursor(cursor, guide);
dom(guide).remove();
if (didSplit) {
dom(leaf.node.parentNode).normalize();
}
return this.quill.editor.selection.update(Quill.sources.SILENT);
};
return MultiCursor;
})(EventEmitter2);
Quill.registerModule('multi-cursor', MultiCursor);
module.exports = MultiCursor;
+74
View File
@@ -0,0 +1,74 @@
var Delta, Document, PasteManager, Quill, dom, _;
Quill = require('../quill');
Document = require('../core/document');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Delta = Quill.require('delta');
PasteManager = (function() {
function PasteManager(quill, options) {
this.quill = quill;
this.options = options;
this.container = this.quill.addContainer('paste-container');
this.container.setAttribute('contenteditable', true);
this.quill.addStyles({
'.paste-container': {
'left': '-10000px',
'position': 'absolute',
'top': '50%'
}
});
dom(this.quill.root).on('paste', _.bind(this._paste, this));
}
PasteManager.prototype._paste = function() {
var iframe, iframeScrollY, oldDocLength, range, windowScrollX, windowScrollY;
oldDocLength = this.quill.getLength();
range = this.quill.getSelection();
if (range == null) {
return;
}
this.container.innerHTML = "";
iframe = dom(this.quill.root).window();
iframeScrollY = iframe.scrollY;
windowScrollX = window.scrollX;
windowScrollY = window.scrollY;
this.container.focus();
return _.defer((function(_this) {
return function() {
var delta, doc, lengthAdded, line, lineBottom, offset, _ref;
doc = new Document(_this.container, _this.quill.options);
delta = doc.toDelta();
lengthAdded = delta.length() - 1;
delta.compose(new Delta().retain(lengthAdded)["delete"](1));
if (range.start > 0) {
delta.ops.unshift({
retain: range.start
});
}
delta["delete"](range.end - range.start);
_this.quill.updateContents(delta, 'user');
_this.quill.setSelection(range.start + lengthAdded, range.start + lengthAdded);
_ref = _this.quill.editor.doc.findLineAt(range.start + lengthAdded), line = _ref[0], offset = _ref[1];
lineBottom = line.node.offsetTop + line.node.offsetHeight;
if (lineBottom > iframeScrollY + _this.quill.root.offsetHeight) {
iframeScrollY = line.node.offsetTop - _this.quill.root.offsetHeight / 2;
}
iframe.scrollTo(0, iframeScrollY);
return window.scrollTo(windowScrollX, windowScrollY);
};
})(this));
};
return PasteManager;
})();
Quill.registerModule('paste-manager', PasteManager);
module.exports = PasteManager;
+261
View File
@@ -0,0 +1,261 @@
var Quill, Toolbar, dom, _;
Quill = require('../quill');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Toolbar = (function() {
Toolbar.DEFAULTS = {
container: null
};
Toolbar.formats = {
LINE: {
'align': 'align',
'bullet': 'bullet',
'list': 'list'
},
SELECT: {
'align': 'align',
'background': 'background',
'color': 'color',
'font': 'font',
'size': 'size'
},
TOGGLE: {
'bold': 'bold',
'bullet': 'bullet',
'image': 'image',
'italic': 'italic',
'link': 'link',
'list': 'list',
'strike': 'strike',
'underline': 'underline'
},
TOOLTIP: {
'image': 'image',
'link': 'link'
}
};
function Toolbar(quill, options) {
this.quill = quill;
this.options = options;
if (this.options.container == null) {
throw new Error('container required for toolbar', this.options);
}
this.container = _.isString(this.options.container) ? document.querySelector(this.options.container) : this.options.container;
this.inputs = {};
this.preventUpdate = false;
this.triggering = false;
_.each(this.quill.options.formats, (function(_this) {
return function(format) {
if (Toolbar.formats.TOOLTIP[format] != null) {
return;
}
return _this.initFormat(format, function(range, value) {
if (_this.triggering) {
return;
}
if (range.isCollapsed()) {
_this.quill.prepareFormat(format, value);
} else if (Toolbar.formats.LINE[format] != null) {
_this.quill.formatLine(range, format, value, 'user');
} else {
_this.quill.formatText(range, format, value, 'user');
}
return _.defer(function() {
_this.updateActive(range, ['bullet', 'list']);
return _this.setActive(format, value);
});
});
};
})(this));
this.quill.on(this.quill.constructor.events.SELECTION_CHANGE, (function(_this) {
return function(range) {
if (range != null) {
return _this.updateActive(range);
}
};
})(this));
this.quill.onModuleLoad('keyboard', (function(_this) {
return function(keyboard) {
return keyboard.addHotkey([dom.KEYS.BACKSPACE, dom.KEYS.DELETE, dom.KEYS.ENTER], function() {
return _.defer(_.bind(_this.updateActive, _this));
});
};
})(this));
dom(this.container).addClass('ql-toolbar-container');
if (dom.isIOS()) {
dom(this.container).addClass('ios');
}
if (dom.isIE(11)) {
dom(this.container).on('mousedown', (function(_this) {
return function() {
return false;
};
})(this));
}
}
Toolbar.prototype.initFormat = function(format, callback) {
var eventName, input, selector;
selector = ".ql-" + format;
if (Toolbar.formats.SELECT[format] != null) {
selector = "select" + selector;
eventName = 'change';
} else {
eventName = 'click';
}
input = this.container.querySelector(selector);
if (input == null) {
return;
}
this.inputs[format] = input;
return dom(input).on(eventName, (function(_this) {
return function() {
var range, value;
value = eventName === 'change' ? dom(input).value() : !dom(input).hasClass('ql-active');
_this.preventUpdate = true;
_this.quill.focus();
range = _this.quill.getSelection();
if (range != null) {
callback(range, value);
}
_this.preventUpdate = false;
return true;
};
})(this));
};
Toolbar.prototype.setActive = function(format, value) {
var $input, input, selectValue, _ref;
input = this.inputs[format];
if (input == null) {
return;
}
$input = dom(input);
if (input.tagName === 'SELECT') {
this.triggering = true;
selectValue = $input.value(input);
if (value == null) {
value = (_ref = $input["default"]()) != null ? _ref.value : void 0;
}
if (_.isArray(value)) {
value = '';
}
if (value !== selectValue) {
if (value != null) {
$input.option(value, false);
} else {
$input.reset(false);
}
}
return this.triggering = false;
} else {
return $input.toggleClass('ql-active', value || false);
}
};
Toolbar.prototype.updateActive = function(range, formats) {
var activeFormats;
if (formats == null) {
formats = null;
}
range || (range = this.quill.getSelection());
if (!((range != null) && !this.preventUpdate)) {
return;
}
activeFormats = this._getActive(range);
return _.each(this.inputs, (function(_this) {
return function(input, format) {
if (!_.isArray(formats) || formats.indexOf(format) > -1) {
_this.setActive(format, activeFormats[format]);
}
return true;
};
})(this));
};
Toolbar.prototype._getActive = function(range) {
var leafFormats, lineFormats;
leafFormats = this._getLeafActive(range);
lineFormats = this._getLineActive(range);
return _.defaults({}, leafFormats, lineFormats);
};
Toolbar.prototype._getLeafActive = function(range) {
var contents, formatsArr, line, offset, _ref;
if (range.isCollapsed()) {
_ref = this.quill.editor.doc.findLineAt(range.start), line = _ref[0], offset = _ref[1];
if (offset === 0) {
contents = this.quill.getContents(range.start, range.end + 1);
} else {
contents = this.quill.getContents(range.start - 1, range.end);
}
} else {
contents = this.quill.getContents(range);
}
formatsArr = _.map(contents.ops, 'attributes');
return this._intersectFormats(formatsArr);
};
Toolbar.prototype._getLineActive = function(range) {
var firstLine, formatsArr, lastLine, offset, _ref, _ref1;
formatsArr = [];
_ref = this.quill.editor.doc.findLineAt(range.start), firstLine = _ref[0], offset = _ref[1];
_ref1 = this.quill.editor.doc.findLineAt(range.end), lastLine = _ref1[0], offset = _ref1[1];
if ((lastLine != null) && lastLine === firstLine) {
lastLine = lastLine.next;
}
while ((firstLine != null) && firstLine !== lastLine) {
formatsArr.push(_.clone(firstLine.formats));
firstLine = firstLine.next;
}
return this._intersectFormats(formatsArr);
};
Toolbar.prototype._intersectFormats = function(formatsArr) {
return _.reduce(formatsArr.slice(1), function(activeFormats, formats) {
var activeKeys, added, formatKeys, intersection, missing;
activeKeys = _.keys(activeFormats);
formatKeys = _.keys(formats);
intersection = _.intersection(activeKeys, formatKeys);
missing = _.difference(activeKeys, formatKeys);
added = _.difference(formatKeys, activeKeys);
_.each(intersection, function(name) {
if (Toolbar.formats.SELECT[name] != null) {
if (_.isArray(activeFormats[name])) {
if (_.indexOf(activeFormats[name], formats[name]) < 0) {
return activeFormats[name].push(formats[name]);
}
} else if (activeFormats[name] !== formats[name]) {
return activeFormats[name] = [activeFormats[name], formats[name]];
}
}
});
_.each(missing, function(name) {
if (Toolbar.formats.TOGGLE[name] != null) {
return delete activeFormats[name];
} else if ((Toolbar.formats.SELECT[name] != null) && !_.isArray(activeFormats[name])) {
return activeFormats[name] = [activeFormats[name]];
}
});
_.each(added, function(name) {
if (Toolbar.formats.SELECT[name] != null) {
return activeFormats[name] = [formats[name]];
}
});
return activeFormats;
}, formatsArr[0] || {});
};
return Toolbar;
})();
Quill.registerModule('toolbar', Toolbar);
module.exports = Toolbar;
+138
View File
@@ -0,0 +1,138 @@
var Normalizer, Quill, Tooltip, dom, _;
Quill = require('../quill');
Normalizer = require('../lib/normalizer');
_ = Quill.require('lodash');
dom = Quill.require('dom');
Tooltip = (function() {
Tooltip.DEFAULTS = {
offset: 10,
styles: {
'.tooltip': {
'background-color': '#fff',
'border': '1px solid #000',
'top': '0px',
'white-space': 'nowrap',
'z-index': '2000'
},
'.tooltip a': {
'cursor': 'pointer',
'text-decoration': 'none'
}
},
template: ''
};
Tooltip.HIDE_MARGIN = '-10000px';
function Tooltip(quill, options) {
this.quill = quill;
this.options = options;
this.quill.addStyles(this.options.styles);
this.container = this.quill.addContainer('tooltip');
this.container.innerHTML = Normalizer.stripWhitespace(this.options.template);
this.container.style.position = 'absolute';
dom(this.quill.root).on('focus', _.bind(this.hide, this));
this.hide();
this.quill.on(this.quill.constructor.events.TEXT_CHANGE, (function(_this) {
return function(delta, source) {
if (source === 'user' && _this.container.style.left !== Tooltip.HIDE_MARGIN) {
_this.range = null;
return _this.hide();
}
};
})(this));
}
Tooltip.prototype.initTextbox = function(textbox, enterCallback, escapeCallback) {
return dom(textbox).on('keyup', (function(_this) {
return function(event) {
switch (event.which) {
case dom.KEYS.ENTER:
return enterCallback.call(_this);
case dom.KEYS.ESCAPE:
return escapeCallback.call(_this);
default:
return true;
}
};
})(this));
};
Tooltip.prototype.hide = function() {
this.container.style.left = Tooltip.HIDE_MARGIN;
if (this.range) {
this.quill.setSelection(this.range);
}
return this.range = null;
};
Tooltip.prototype.show = function(reference) {
var left, top, win, _ref, _ref1;
this.range = this.quill.getSelection();
_ref = this._position(reference), left = _ref[0], top = _ref[1];
_ref1 = this._limit(left, top), left = _ref1[0], top = _ref1[1];
win = dom(this.quill.root).window();
left += win.pageXOffset;
top += win.pageYOffset;
this.container.style.left = "" + left + "px";
this.container.style.top = "" + top + "px";
return this.container.focus();
};
Tooltip.prototype._getBounds = function() {
var bounds, scrollX, scrollY, win;
bounds = this.quill.root.getBoundingClientRect();
win = dom(this.quill.root).window();
scrollX = win.pageXOffset;
scrollY = win.pageYOffset;
return {
left: bounds.left + scrollX,
right: bounds.right + scrollX,
top: bounds.top + scrollY,
bottom: bounds.bottom + scrollY,
width: bounds.width,
height: bounds.height
};
};
Tooltip.prototype._limit = function(left, top) {
var editorRect, toolbarRect;
editorRect = this._getBounds();
toolbarRect = this.container.getBoundingClientRect();
left = Math.min(editorRect.right - toolbarRect.width, left);
left = Math.max(editorRect.left, left);
top = Math.min(editorRect.bottom - toolbarRect.height, top);
top = Math.max(editorRect.top, top);
return [left, top];
};
Tooltip.prototype._position = function(reference) {
var editorRect, left, referenceBounds, toolbarRect, top;
toolbarRect = this.container.getBoundingClientRect();
editorRect = this._getBounds();
if (reference != null) {
referenceBounds = reference.getBoundingClientRect();
left = referenceBounds.left + referenceBounds.width / 2 - toolbarRect.width / 2;
top = referenceBounds.top + referenceBounds.height + this.options.offset;
if (top + toolbarRect.height > editorRect.bottom) {
top = referenceBounds.top - toolbarRect.height - this.options.offset;
}
} else {
left = editorRect.left + editorRect.width / 2 - toolbarRect.width / 2;
top = editorRect.top + editorRect.height / 2 - toolbarRect.height / 2;
}
return [left, top];
};
return Tooltip;
})();
Quill.registerModule('tooltip', Tooltip);
module.exports = Tooltip;
+145
View File
@@ -0,0 +1,145 @@
var Delta, Quill, UndoManager, _;
Quill = require('../quill');
_ = Quill.require('lodash');
Delta = Quill.require('delta');
UndoManager = (function() {
UndoManager.DEFAULTS = {
delay: 1000,
maxStack: 100
};
UndoManager.hotkeys = {
UNDO: {
key: 'Z',
metaKey: true
},
REDO: {
key: 'Z',
metaKey: true,
shiftKey: true
}
};
function UndoManager(quill, options) {
this.quill = quill;
this.options = options != null ? options : {};
this.lastRecorded = 0;
this.emittedDelta = null;
this.clear();
this.initListeners();
}
UndoManager.prototype.initListeners = function() {
this.quill.onModuleLoad('keyboard', (function(_this) {
return function(keyboard) {
keyboard.addHotkey(UndoManager.hotkeys.UNDO, function() {
_this.undo();
return false;
});
return keyboard.addHotkey(UndoManager.hotkeys.REDO, function() {
_this.redo();
return false;
});
};
})(this));
return this.quill.on(this.quill.constructor.events.TEXT_CHANGE, (function(_this) {
return function(delta, origin) {
if (_.isEqual(delta, _this.emittedDelta)) {
return;
}
_this.record(delta, _this.oldDelta);
return _this.oldDelta = _this.quill.getContents();
};
})(this));
};
UndoManager.prototype.clear = function() {
this.stack = {
undo: [],
redo: []
};
return this.oldDelta = this.quill.getContents();
};
UndoManager.prototype.record = function(changeDelta, oldDelta) {
var change, ignored, timestamp, undoDelta;
if (!(changeDelta.ops.length > 0)) {
return;
}
this.stack.redo = [];
try {
undoDelta = this.quill.getContents().diff(this.oldDelta);
timestamp = new Date().getTime();
if (this.lastRecorded + this.options.delay > timestamp && this.stack.undo.length > 0) {
change = this.stack.undo.pop();
undoDelta = undoDelta.compose(change.undo);
changeDelta = change.redo.compose(changeDelta);
} else {
this.lastRecorded = timestamp;
}
this.stack.undo.push({
redo: changeDelta,
undo: undoDelta
});
if (this.stack.undo.length > this.options.maxStack) {
return this.stack.undo.unshift();
}
} catch (_error) {
ignored = _error;
return this.clear();
}
};
UndoManager.prototype.redo = function() {
return this._change('redo', 'undo');
};
UndoManager.prototype.undo = function() {
return this._change('undo', 'redo');
};
UndoManager.prototype._getLastChangeIndex = function(delta) {
var index, lastIndex;
lastIndex = 0;
index = 0;
delta.ops.forEach(function(op) {
if (op.insert != null) {
return lastIndex = Math.max(index + (op.insert.length || 1), lastIndex);
} else if (op["delete"] != null) {
return lastIndex = Math.max(index, lastIndex);
} else if (op.retain != null) {
if (op.attributes != null) {
lastIndex = Math.max(index + op.retain, lastIndex);
}
return index += op.retain;
}
});
return lastIndex;
};
UndoManager.prototype._change = function(source, dest) {
var change, index;
if (this.stack[source].length > 0) {
change = this.stack[source].pop();
this.lastRecorded = 0;
this.emittedDelta = change[source];
this.quill.updateContents(change[source], 'user');
this.emittedDelta = null;
index = this._getLastChangeIndex(change[source]);
this.quill.setSelection(index, index);
this.oldDelta = this.quill.getContents();
return this.stack[dest].push(change);
}
};
return UndoManager;
})();
Quill.registerModule('undo-manager', UndoManager);
module.exports = UndoManager;
+359
View File
@@ -0,0 +1,359 @@
var Delta, Editor, EventEmitter2, Format, Quill, Range, dom, pkg, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__slice = [].slice;
_ = require('lodash');
pkg = require('../package.json');
Delta = require('rich-text').Delta;
EventEmitter2 = require('eventemitter2').EventEmitter2;
dom = require('./lib/dom');
Editor = require('./core/editor');
Format = require('./core/format');
Range = require('./lib/range');
Quill = (function(_super) {
__extends(Quill, _super);
Quill.version = pkg.version;
Quill.editors = [];
Quill.modules = [];
Quill.themes = [];
Quill.DEFAULTS = {
formats: ['align', 'bold', 'italic', 'strike', 'underline', 'color', 'background', 'font', 'size', 'link', 'image', 'bullet', 'list'],
modules: {
'keyboard': true,
'paste-manager': true,
'undo-manager': true
},
pollInterval: 100,
readOnly: false,
theme: 'default'
};
Quill.events = {
MODULE_INIT: 'module-init',
POST_EVENT: 'post-event',
PRE_EVENT: 'pre-event',
SELECTION_CHANGE: 'selection-change',
TEXT_CHANGE: 'text-change'
};
Quill.sources = Editor.sources;
Quill.registerModule = function(name, module) {
if (Quill.modules[name] != null) {
console.warn("Overwriting " + name + " module");
}
return Quill.modules[name] = module;
};
Quill.registerTheme = function(name, theme) {
if (Quill.themes[name] != null) {
console.warn("Overwriting " + name + " theme");
}
return Quill.themes[name] = theme;
};
Quill.require = function(name) {
switch (name) {
case 'lodash':
return _;
case 'delta':
return Delta;
case 'dom':
return dom;
default:
return null;
}
};
function Quill(container, options) {
var html, moduleOptions, themeClass;
if (options == null) {
options = {};
}
if (_.isString(container)) {
container = document.querySelector(container);
}
if (container == null) {
throw new Error('Invalid Quill container');
}
moduleOptions = _.defaults(options.modules || {}, Quill.DEFAULTS.modules);
html = container.innerHTML;
this.options = _.defaults(options, Quill.DEFAULTS);
this.options.modules = moduleOptions;
this.options.id = this.id = "quill-" + (Quill.editors.length + 1);
this.options.emitter = this;
this.modules = {};
this.editor = new Editor(container, this, this.options);
this.root = this.editor.doc.root;
Quill.editors.push(this);
this.setHTML(html, Quill.sources.SILENT);
themeClass = Quill.themes[this.options.theme];
if (themeClass == null) {
throw new Error("Cannot load " + this.options.theme + " theme. Are you sure you registered it?");
}
this.theme = new themeClass(this, this.options);
_.each(this.options.modules, (function(_this) {
return function(option, name) {
return _this.addModule(name, option);
};
})(this));
}
Quill.prototype.addContainer = function(className, before) {
if (before == null) {
before = false;
}
return this.editor.renderer.addContainer(className, before);
};
Quill.prototype.addFormat = function(name, format) {
return this.editor.doc.addFormat(name, format);
};
Quill.prototype.addModule = function(name, options) {
var moduleClass;
moduleClass = Quill.modules[name];
if (moduleClass == null) {
throw new Error("Cannot load " + name + " module. Are you sure you registered it?");
}
if (!_.isObject(options)) {
options = {};
}
options = _.defaults(options, this.theme.constructor.OPTIONS[name] || {}, moduleClass.DEFAULTS || {});
this.modules[name] = new moduleClass(this, options);
this.emit(Quill.events.MODULE_INIT, name, this.modules[name]);
return this.modules[name];
};
Quill.prototype.addStyles = function(styles) {
return this.editor.renderer.addStyles(styles);
};
Quill.prototype.deleteText = function(start, end, source) {
var delta, formats, _ref;
if (source == null) {
source = Quill.sources.API;
}
_ref = this._buildParams(start, end, {}, source), start = _ref[0], end = _ref[1], formats = _ref[2], source = _ref[3];
if (!(end > start)) {
return;
}
delta = new Delta().retain(start)["delete"](end - start);
return this.editor.applyDelta(delta, source);
};
Quill.prototype.emit = function() {
var args, eventName;
eventName = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
Quill.__super__.emit.apply(this, [Quill.events.PRE_EVENT, eventName].concat(__slice.call(args)));
Quill.__super__.emit.apply(this, [eventName].concat(__slice.call(args)));
return Quill.__super__.emit.apply(this, [Quill.events.POST_EVENT, eventName].concat(__slice.call(args)));
};
Quill.prototype.focus = function() {
return this.editor.focus();
};
Quill.prototype.formatLine = function(start, end, name, value, source) {
var formats, line, offset, _ref, _ref1;
_ref = this._buildParams(start, end, name, value, source), start = _ref[0], end = _ref[1], formats = _ref[2], source = _ref[3];
_ref1 = this.editor.doc.findLineAt(end), line = _ref1[0], offset = _ref1[1];
if (line != null) {
end += line.length - offset;
}
return this.formatText(start, end, formats, source);
};
Quill.prototype.formatText = function(start, end, name, value, source) {
var delta, formats, _ref;
_ref = this._buildParams(start, end, name, value, source), start = _ref[0], end = _ref[1], formats = _ref[2], source = _ref[3];
formats = _.reduce(formats, (function(_this) {
return function(formats, value, name) {
var format;
format = _this.editor.doc.formats[name];
if (!(value && value !== format.config["default"])) {
formats[name] = null;
}
return formats;
};
})(this), formats);
delta = new Delta().retain(start).retain(end - start, formats);
return this.editor.applyDelta(delta, source);
};
Quill.prototype.getContents = function(start, end) {
if (start == null) {
start = 0;
}
if (end == null) {
end = null;
}
if (_.isObject(start)) {
end = start.end;
start = start.start;
}
return this.editor.getDelta().slice(start, end);
};
Quill.prototype.getHTML = function() {
return this.root.innerHTML;
};
Quill.prototype.getLength = function() {
return this.editor.getDelta().length();
};
Quill.prototype.getModule = function(name) {
return this.modules[name];
};
Quill.prototype.getSelection = function() {
this.editor.checkUpdate();
return this.editor.selection.getRange();
};
Quill.prototype.getText = function(start, end) {
if (start == null) {
start = 0;
}
if (end == null) {
end = null;
}
return _.map(this.getContents(start, end).ops, function(op) {
if (_.isString(op.insert)) {
return op.insert;
} else {
return '';
}
}).join('');
};
Quill.prototype.insertEmbed = function(index, type, url, source) {
return this.insertText(index, dom.EMBED_TEXT, type, url, source);
};
Quill.prototype.insertText = function(index, text, name, value, source) {
var delta, end, formats, _ref;
_ref = this._buildParams(index, 0, name, value, source), index = _ref[0], end = _ref[1], formats = _ref[2], source = _ref[3];
if (!(text.length > 0)) {
return;
}
delta = new Delta().retain(index).insert(text, formats);
return this.editor.applyDelta(delta, source);
};
Quill.prototype.onModuleLoad = function(name, callback) {
if (this.modules[name]) {
return callback(this.modules[name]);
}
return this.on(Quill.events.MODULE_INIT, function(moduleName, module) {
if (moduleName === name) {
return callback(module);
}
});
};
Quill.prototype.prepareFormat = function(name, value) {
var format, range;
format = this.editor.doc.formats[name];
if (format == null) {
return;
}
range = this.getSelection();
if (!(range != null ? range.isCollapsed() : void 0)) {
return;
}
if (format.isType(Format.types.LINE)) {
return this.formatLine(range, name, value, Quill.sources.USER);
} else {
return format.prepare(value);
}
};
Quill.prototype.setContents = function(delta, source) {
if (source == null) {
source = Quill.sources.API;
}
if (_.isArray(delta)) {
delta = {
ops: delta
};
}
delta.ops.unshift({
"delete": this.getLength()
});
return this.updateContents(delta, source);
};
Quill.prototype.setHTML = function(html, source) {
if (source == null) {
source = Quill.sources.API;
}
if (!html) {
html = "<" + dom.DEFAULT_BLOCK_TAG + "><" + dom.DEFAULT_BREAK_TAG + "></" + dom.DEFAULT_BLOCK_TAG + ">";
}
this.editor.doc.setHTML(html);
return this.editor.checkUpdate(source);
};
Quill.prototype.setSelection = function(start, end, source) {
var range;
if (source == null) {
source = Quill.sources.API;
}
if (_.isNumber(start) && _.isNumber(end)) {
range = new Range(start, end);
} else {
range = start;
source = end || source;
}
return this.editor.selection.setRange(range, source);
};
Quill.prototype.updateContents = function(delta, source) {
if (source == null) {
source = Quill.sources.API;
}
return this.editor.applyDelta(delta, source);
};
Quill.prototype._buildParams = function() {
var formats, params;
params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (_.isObject(params[0])) {
params.splice(0, 1, params[0].start, params[0].end);
}
if (_.isString(params[2])) {
formats = {};
formats[params[2]] = params[3];
params.splice(2, 2, formats);
}
if (params[3] == null) {
params[3] = Quill.sources.API;
}
return params;
};
return Quill;
})(EventEmitter2);
Quill.registerTheme('default', require('./themes/default'));
Quill.registerTheme('snow', require('./themes/snow'));
module.exports = Quill;
+16
View File
@@ -0,0 +1,16 @@
var DefaultTheme;
DefaultTheme = (function() {
DefaultTheme.OPTIONS = {};
function DefaultTheme(quill) {
this.quill = quill;
this.editor = this.quill.editor;
this.editorContainer = this.editor.root;
}
return DefaultTheme;
})();
module.exports = DefaultTheme;
+165
View File
@@ -0,0 +1,165 @@
var ColorPicker, DefaultTheme, Picker, SnowTheme, dom, _,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
_ = require('lodash');
ColorPicker = require('../../lib/color-picker');
DefaultTheme = require('../default');
dom = require('../../lib/dom');
Picker = require('../../lib/picker');
SnowTheme = (function(_super) {
__extends(SnowTheme, _super);
SnowTheme.COLORS = ["#000000", "#e60000", "#ff9900", "#ffff00", "#008A00", "#0066cc", "#9933ff", "#ffffff", "#facccc", "#ffebcc", "#ffffcc", "#cce8cc", "#cce0f5", "#ebd6ff", "#bbbbbb", "#f06666", "#ffc266", "#ffff66", "#66b966", "#66a3e0", "#c285ff", "#888888", "#a10000", "#b26b00", "#b2b200", "#006100", "#0047b2", "#6b24b2", "#444444", "#5c0000", "#663d00", "#666600", "#003700", "#002966", "#3d1466"];
SnowTheme.OPTIONS = {
'multi-cursor': {
template: '<span class="cursor-flag"> <span class="cursor-triangle top"></span> <span class="cursor-name"></span> <span class="cursor-triangle bottom"></span> </span> <span class="cursor-caret"></span>'
}
};
SnowTheme.STYLES = {
'.snow .image-tooltip-container a': {
'border': '1px solid #06c'
},
'.snow .image-tooltip-container a.insert': {
'background-color': '#06c',
'color': '#fff'
},
'.snow .cursor-name': {
'border-radius': '4px',
'font-size': '11px',
'font-family': 'Arial',
'margin-left': '-50%',
'padding': '4px 10px'
},
'.snow .cursor-triangle': {
'border-left': '4px solid transparent',
'border-right': '4px solid transparent',
'height': '0px',
'margin-left': '-3px',
'width': '0px'
},
'.snow .cursor.left .cursor-name': {
'margin-left': '-8px'
},
'.snow .cursor.right .cursor-flag': {
'right': 'auto'
},
'.snow .cursor.right .cursor-name': {
'margin-left': '-100%',
'margin-right': '-8px'
},
'.snow .cursor-triangle.bottom': {
'border-top': '4px solid transparent',
'display': 'block',
'margin-bottom': '-1px'
},
'.snow .cursor-triangle.top': {
'border-bottom': '4px solid transparent',
'display': 'none',
'margin-top': '-1px'
},
'.snow .cursor.top .cursor-triangle.bottom': {
'display': 'none'
},
'.snow .cursor.top .cursor-triangle.top': {
'display': 'block'
},
'.snow a': {
'color': '#06c'
},
'.snow .tooltip': {
'border': '1px solid #ccc',
'box-shadow': '0px 0px 5px #ddd',
'color': '#222'
},
'.snow .tooltip a': {
'color': '#06c'
},
'.snow .tooltip .input': {
'border': '1px solid #ccc',
'margin': '0px',
'padding': '5px'
},
'.snow .image-tooltip-container .preview': {
'border-color': '#ccc',
'color': '#ccc'
},
'.snow .link-tooltip-container a, .snow .link-tooltip-container span': {
'display': 'inline-block',
'line-height': '25px'
}
};
function SnowTheme(quill) {
this.quill = quill;
SnowTheme.__super__.constructor.apply(this, arguments);
this.quill.addStyles(SnowTheme.STYLES);
this.pickers = [];
this.quill.on(this.quill.constructor.events.SELECTION_CHANGE, (function(_this) {
return function(range) {
if (range != null) {
return _.invoke(_this.pickers, 'close');
}
};
})(this));
dom(this.quill.root.ownerDocument.body).addClass('snow');
this.quill.onModuleLoad('multi-cursor', _.bind(this.extendMultiCursor, this));
this.quill.onModuleLoad('toolbar', _.bind(this.extendToolbar, this));
}
SnowTheme.prototype.extendMultiCursor = function(module) {
return module.on(module.constructor.events.CURSOR_ADDED, function(cursor) {
var bottomTriangle, topTriangle;
bottomTriangle = cursor.elem.querySelector('.cursor-triangle.bottom');
topTriangle = cursor.elem.querySelector('.cursor-triangle.top');
return bottomTriangle.style.borderTopColor = topTriangle.style.borderBottomColor = cursor.color;
});
};
SnowTheme.prototype.extendToolbar = function(module) {
_.each(['color', 'background', 'font', 'size', 'align'], (function(_this) {
return function(format) {
var picker, select;
select = module.container.querySelector(".ql-" + format);
if (select == null) {
return;
}
switch (format) {
case 'font':
case 'size':
case 'align':
picker = new Picker(select);
break;
case 'color':
case 'background':
picker = new ColorPicker(select);
_.each(picker.container.querySelectorAll('.ql-picker-item'), function(item, i) {
if (i < 7) {
return dom(item).addClass('ql-primary-color');
}
});
}
if (picker != null) {
return _this.pickers.push(picker);
}
};
})(this));
return _.each(dom(module.container).textNodes(), function(node) {
if (dom(node).text().trim().length === 0) {
return dom(node).remove();
}
});
};
return SnowTheme;
})(DefaultTheme);
module.exports = SnowTheme;