Skip to content

Commit 6ef8ed9

Browse files
authored
Merge pull request #45 from typecode/issue-26
#26 - Code cleanup
2 parents cad7da2 + 0047248 commit 6ef8ed9

File tree

10 files changed

+13
-634
lines changed

10 files changed

+13
-634
lines changed

src/scripts/modules/BaseFormatter.js

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,6 @@ const BaseFormatter = Module({
132132
this.removeEmptyNodes(rootElem, { recursive: true });
133133
this.removeZeroWidthSpaces(rootElem);
134134
DOM.trimNodeText(rootElem);
135-
136-
// -----
137-
138-
// this.removeBrNodes(rootElem);
139-
// // this.removeEmptyNodes(rootElem);
140-
// this.removeFontTags(rootElem);
141-
// this.removeStyledSpans(rootElem);
142-
// this.clearEntities(rootElem);
143-
// this.removeZeroWidthSpaces(rootElem);
144-
// this.defaultOrphanedTextNodes(rootElem);
145-
// this.removeEmptyNodes(rootElem, { recursive: true });
146135
},
147136

148137
/**
@@ -234,7 +223,7 @@ const BaseFormatter = Module({
234223
return;
235224
}
236225

237-
const isLastChild = brNode === brNode.parentNode.lastChild;
226+
const isLastChild = DOM.isLastChild(brNode);
238227
const isDoubleBreak = brNode.nextSibling && brNode.nextSibling.nodeName === 'BR';
239228
const isInBlock = DOM.isIn(brNode, blockTags, rootElem);
240229
const isOrphan = brNode.parentNode === rootElem;
@@ -329,28 +318,6 @@ const BaseFormatter = Module({
329318
}
330319
},
331320

332-
clearEntities (rootElem) {
333-
const rootDoc = rootElem.ownerDocument;
334-
const walker = rootDoc.createTreeWalker(
335-
rootElem,
336-
NodeFilter.SHOW_TEXT,
337-
null,
338-
false
339-
);
340-
341-
let textNodes = [];
342-
while(walker.nextNode()) {
343-
textNodes.push(walker.currentNode);
344-
}
345-
346-
textNodes.forEach((textNode) => {
347-
if (/\w+/.test(textNode.textContent)) {
348-
textNode.nodeValue = textNode.nodeValue.replace(/^\u00a0/, '');
349-
textNode.nodeValue = textNode.nodeValue.replace(/\u00a0$/, '');
350-
}
351-
});
352-
},
353-
354321
ensureRootElems (rootElem) {
355322
const rootNodeTags = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'OL', 'UL', 'BLOCKQUOTE', 'P'];
356323
const nestableTags = [
@@ -456,17 +423,6 @@ const BaseFormatter = Module({
456423
}
457424
DOM.removeNode(styledSpan);
458425
}
459-
},
460-
461-
removeFontNodes (rootElem) {
462-
const fontTags = rootElem.querySelectorAll('font');
463-
for (let i = fontTags.length - 1; i >= 0; i--) {
464-
let fontTag = fontTags[i];
465-
while (fontTag.firstChild) {
466-
DOM.insertBefore(fontTag.firstChild, fontTag);
467-
}
468-
DOM.removeNode(fontTag);
469-
}
470426
}
471427
}
472428
});

src/scripts/modules/Canvas.js

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,12 @@
1414
* 'canvas:document' : 'getCanvasDocument',
1515
* 'canvas:window' : 'getCanvasWindow',
1616
* 'canvas:body' : 'getCanvasBody',
17-
* 'canvas:formatted:block': 'getFormattedBlock',
1817
* 'canvas:selection:coordinates' : 'getSelectionCoordinates',
1918
* 'canvas:selection': 'getSelection',
20-
* 'canvas:selection:in:or:contains': 'selectionInOrContains'
2119
* },
2220
* commands: {
2321
* 'canvas:content' : 'setContent',
24-
* 'canvas:insert:range' : 'insertRange',
25-
* 'canvas:insert:node' : 'insertNode',
26-
* 'canvas:select:all' : 'selectAll',
2722
* 'canvas:select:by:coordinates' : 'selectByCoordinates',
28-
* 'canvas:import:selection' : 'importSelection',
29-
* 'canvas:export:prep': 'exportPrep',
3023
* 'canvas:export:all': 'exportAll',
3124
* 'canvas:cache:selection': 'cacheSelection',
3225
* 'canvas:select:cachedSelection': 'selectCachedSelection',
@@ -55,19 +48,12 @@ const Canvas = Module({
5548
'canvas:document' : 'getCanvasDocument',
5649
'canvas:window' : 'getCanvasWindow',
5750
'canvas:body' : 'getCanvasBody',
58-
'canvas:formatted:block': 'getFormattedBlock',
5951
'canvas:selection:coordinates' : 'getSelectionCoordinates',
60-
'canvas:selection': 'getSelection',
61-
'canvas:selection:in:or:contains': 'selectionInOrContains'
52+
'canvas:selection': 'getSelection'
6253
},
6354
commands: {
6455
'canvas:content' : 'setContent',
65-
'canvas:insert:range' : 'insertRange',
66-
'canvas:insert:node' : 'insertNode',
67-
'canvas:select:all' : 'selectAll',
6856
'canvas:select:by:coordinates' : 'selectByCoordinates',
69-
'canvas:import:selection' : 'importSelection',
70-
'canvas:export:prep': 'exportPrep',
7157
'canvas:export:all': 'exportAll',
7258
'canvas:cache:selection': 'cacheSelection',
7359
'canvas:select:cachedSelection': 'selectCachedSelection',
@@ -257,13 +243,6 @@ const Canvas = Module({
257243
canvasBody.appendChild(rangeDocFrag);
258244
},
259245

260-
insertNode (node) {
261-
const nodeClone = node.cloneNode(true);
262-
const canvasBody = this.getCanvasBody();
263-
this.reset();
264-
canvasBody.appendChild(nodeClone);
265-
},
266-
267246
selectAll (opts={}) {
268247
const { mediator } = this;
269248
mediator.exec('selection:select:all', opts);
@@ -277,31 +256,6 @@ const Canvas = Module({
277256
mediator.exec('selection:select:coordinates', rangeCoordinates);
278257
},
279258

280-
importSelection (opts={}) {
281-
const { mediator } = this;
282-
let rangeCoordinates;
283-
284-
if (opts.toRoot) {
285-
rangeCoordinates = mediator.get('selection:range:relative:toroot');
286-
mediator.exec('selection:expand:toroot');
287-
}
288-
289-
const selectionRange = mediator.get('selection:range');
290-
291-
this.insertRange(selectionRange);
292-
if (opts.toRoot) {
293-
this.selectByCoordinates(rangeCoordinates);
294-
} else {
295-
this.selectAll();
296-
}
297-
this.setCanvasBodyEditable();
298-
299-
},
300-
301-
exportPrep () {
302-
this.cleanHtml();
303-
},
304-
305259
exportAll () {
306260
const { mediator } = this;
307261
const canvasBody = this.getCanvasBody();
@@ -311,13 +265,6 @@ const Canvas = Module({
311265
mediator.exec('contenteditable:inserthtml', exportHTMLString);
312266
},
313267

314-
getFormattedBlock () {
315-
const { mediator } = this;
316-
mediator.exec('selection:expand:toroot');
317-
const blockRange = mediator.get('selection:range');
318-
return blockRange.cloneContents();
319-
},
320-
321268
cleanHtml () {
322269
const canvasDoc = this.getCanvasDocument();
323270
const canvasBody = this.getCanvasBody();
@@ -367,11 +314,6 @@ const Canvas = Module({
367314
return mediator.get('selection:range:coordinates');
368315
},
369316

370-
selectionInOrContains (selectors) {
371-
const { mediator } = this;
372-
return mediator.get('selection:in:or:contains', selectors);
373-
},
374-
375317
destroy () {
376318
const { props } = this;
377319
const { iframe } = props;

src/scripts/modules/ContentEditable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ const ContentEditable = Module({
5656
},
5757
commands: {
5858
'contenteditable:inserthtml' : 'insertHTML',
59-
'contenteditable:refocus' : 'reFocus',
60-
'contenteditable:cleanup' : 'cleanup'
59+
'contenteditable:refocus' : 'reFocus'
6160
},
6261
events: {
6362
'app:destroy': 'destroy'

src/scripts/modules/LinkFormatter.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,6 @@ const LinkFormatter = Module({
185185

186186
if (targetEl) {
187187
targetBounds = targetEl.getBoundingClientRect();
188-
189-
// See reason below - Fred
190-
// elStyles = window.getComputedStyle(targetEl);
191-
// elLineHeight = elStyles.getPropertyValue('line-height');
192-
// elLineHeight = elLineHeight === 'normal' ? elStyles.getPropertyValue('font-size') : elStyles.getPropertyValue('line-height');
193-
// elLineHeight = parseInt(elLineHeight, 10);
194-
// lineCount = Math.ceil(targetBounds.height / elLineHeight);
195-
// lineStepHeight = targetBounds.height / lineCount;
196188
} else {
197189
targetBounds = mediator.get('selection:bounds');
198190
}
@@ -201,31 +193,9 @@ const LinkFormatter = Module({
201193
const scrollOffset = DOM.getScrollOffset();
202194
let docRelTop, docRelCenter;
203195

204-
// Commenting this out because it is trying to do something smart (position
205-
// the flyout close to the user's cursor when they hover over a link)
206-
// but isn't particularly stable. And the alternative of positioning it underneath
207-
// is acceptable and stable. Leaving this here in case the alternative
208-
// proves to be a pain.
209-
// - Fred
210-
//
211-
// const { initialEvent } = props;
212-
// if (false && initialEvent) {
213-
// const topDiff = initialEvent.clientY - targetBounds.top;
214-
//
215-
// docRelTop = initialEvent.clientY;
216-
// docRelCenter = initialEvent.clientX;
217-
//
218-
// if (opts.flyoutPlacement === 'below') {
219-
// docRelTop = targetBounds.top + (lineStepHeight * Math.ceil(topDiff / lineStepHeight));
220-
// } else {
221-
// docRelTop = targetBounds.top + (lineStepHeight * Math.floor(topDiff / lineStepHeight));
222-
// }
223-
// } else {
224196
docRelTop = (opts.flyoutPlacement === 'below' ? targetBounds.bottom : targetBounds.top);
225-
docRelCenter = targetBounds.width / 2 + targetBounds.left + scrollOffset.x;
226-
// }
227-
228197
docRelTop += scrollOffset.y;
198+
docRelCenter = targetBounds.width / 2 + targetBounds.left + scrollOffset.x;
229199

230200
props.flyout.position({
231201
left: docRelCenter + 'px',

src/scripts/modules/Mouse.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ const Mouse = Module({
3838
this.unsetMousedown();
3939
mediator.emit('mouse:up');
4040
};
41-
// document.body.onmouseout = () => {
42-
// props.mousedown = 0;
43-
// };
4441
},
4542

4643
setMousedown () {

0 commit comments

Comments
 (0)