[go: nahoru, domu]

Skip to content

Commit

Permalink
[5-handle-editor-scroll] add .editorconfig and fix whitespace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kensnyder committed Apr 10, 2017
1 parent 23bfd24 commit 33c41aa
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 84 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
indent_style = tab
indent_size = 4
8 changes: 4 additions & 4 deletions src/DefaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
overlayStyles: {
position: 'absolute',
boxSizing: 'border-box',
border: '1px dashed #444',
border: '1px dashed #444',
},
handleStyles: {
position: 'absolute',
Expand Down Expand Up @@ -48,16 +48,16 @@ export default {
cursor: 'default',
},
toolbarButtonStyles: {
display: 'inline-block',
display: 'inline-block',
width: '24px',
height: '24px',
background: 'white',
border: '1px solid #999',
verticalAlign: 'middle',
},
toolbarButtonSvgStyles: {
fill: '#444',
stroke: '#444',
fill: '#444',
stroke: '#444',
strokeWidth: '2',
},
};
12 changes: 6 additions & 6 deletions src/ImageResize.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ImageResize {
}

// Remove the overlay
this.quill.root.parentNode.removeChild(this.overlay);
this.quill.root.parentNode.removeChild(this.overlay);
this.overlay = undefined;

// stop listening for image deletion or movement
Expand All @@ -155,7 +155,7 @@ class ImageResize {
}

// position the overlay over the image
const parent = this.quill.root.parentNode;
const parent = this.quill.root.parentNode;
const imgRect = this.img.getBoundingClientRect();
const containerRect = parent.getBoundingClientRect();

Expand Down Expand Up @@ -188,11 +188,11 @@ class ImageResize {

checkImage = (evt) => {
if (this.img) {
if (evt.keyCode == 46 || evt.keyCode == 8) {
Quill.find(this.img).deleteAt(0);
}
this.hide();
if (evt.keyCode == 46 || evt.keyCode == 8) {
Quill.find(this.img).deleteAt(0);
}
this.hide();
}
};
}

Expand Down
22 changes: 10 additions & 12 deletions src/modules/DisplaySize.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,23 @@ export default class DisplaySize extends BaseModule {
Object.assign(this.display.style, {
right: '4px',
bottom: '4px',
left: 'auto',
left: 'auto',
});
}
else if (this.img.style.float == 'right') {
} else if (this.img.style.float == 'right') {
// position off bottom left
const dispRect = this.display.getBoundingClientRect();
Object.assign(this.display.style, {
right: 'auto',
bottom: `-${dispRect.height + 4}px`,
left: `-${dispRect.width + 4}px`,
});
}
else {
const dispRect = this.display.getBoundingClientRect();
Object.assign(this.display.style, {
right: 'auto',
bottom: `-${dispRect.height + 4}px`,
left: `-${dispRect.width + 4}px`,
});
} else {
// position off bottom right
const dispRect = this.display.getBoundingClientRect();
Object.assign(this.display.style, {
right: `-${dispRect.width + 4}px`,
bottom: `-${dispRect.height + 4}px`,
left: 'auto',
left: 'auto',
});
}
};
Expand Down
123 changes: 61 additions & 62 deletions src/modules/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,86 +16,85 @@ export default class Toolbar extends BaseModule {
this.overlay.appendChild(this.toolbar);

// Setup Buttons
this._defineAlignments();
this._addToolbarButtons();
this._defineAlignments();
this._addToolbarButtons();
};

// The toolbar and its children will be destroyed when the overlay is removed
onDestroy = () => {};
onDestroy = () => {};

// Nothing to update on drag because we are are positioned relative to the overlay
onUpdate = () => {};
onUpdate = () => {};

_defineAlignments = () => {
this.alignments = [
{
icon: IconAlignLeft,
apply: () => {
DisplayStyle.add(this.img, 'inline');
FloatStyle.add(this.img, 'left');
MarginStyle.add(this.img, '0 1em 1em 0');
},
isApplied: () => FloatStyle.value(this.img) == 'left',
},
{
icon: IconAlignCenter,
apply: () => {
DisplayStyle.add(this.img, 'block');
FloatStyle.remove(this.img);
MarginStyle.add(this.img, 'auto');
},
isApplied: () => MarginStyle.value(this.img) == 'auto',
},
{
icon: IconAlignRight,
apply: () => {
DisplayStyle.add(this.img, 'inline');
FloatStyle.add(this.img, 'right');
MarginStyle.add(this.img, '0 0 1em 1em');
},
isApplied: () => FloatStyle.value(this.img) == 'right',
},
];
};
this.alignments = [
{
icon: IconAlignLeft,
apply: () => {
DisplayStyle.add(this.img, 'inline');
FloatStyle.add(this.img, 'left');
MarginStyle.add(this.img, '0 1em 1em 0');
},
isApplied: () => FloatStyle.value(this.img) == 'left',
},
{
icon: IconAlignCenter,
apply: () => {
DisplayStyle.add(this.img, 'block');
FloatStyle.remove(this.img);
MarginStyle.add(this.img, 'auto');
},
isApplied: () => MarginStyle.value(this.img) == 'auto',
},
{
icon: IconAlignRight,
apply: () => {
DisplayStyle.add(this.img, 'inline');
FloatStyle.add(this.img, 'right');
MarginStyle.add(this.img, '0 0 1em 1em');
},
isApplied: () => FloatStyle.value(this.img) == 'right',
},
];
};

_addToolbarButtons = () => {
const buttons = [];
this.alignments.forEach((alignment, idx) => {
const button = document.createElement('span');
buttons.push(button);
button.innerHTML = alignment.icon;
button.addEventListener('click', () => {
const button = document.createElement('span');
buttons.push(button);
button.innerHTML = alignment.icon;
button.addEventListener('click', () => {
// deselect all buttons
buttons.forEach(button => button.style.filter = '');
if (alignment.isApplied()) {
buttons.forEach(button => button.style.filter = '');
if (alignment.isApplied()) {
// If applied, unapply
FloatStyle.remove(this.img);
MarginStyle.remove(this.img);
DisplayStyle.remove(this.img);
}
else {
FloatStyle.remove(this.img);
MarginStyle.remove(this.img);
DisplayStyle.remove(this.img);
} else {
// otherwise, select button and apply
this._selectButton(button);
alignment.apply();
}
this._selectButton(button);
alignment.apply();
}
// image may change position; redraw drag handles
this.requestUpdate();
});
Object.assign(button.style, this.options.toolbarButtonStyles);
if (idx > 0) {
button.style.borderLeftWidth = '0';
}
Object.assign(button.children[0].style, this.options.toolbarButtonSvgStyles);
if (alignment.isApplied()) {
this.requestUpdate();
});
Object.assign(button.style, this.options.toolbarButtonStyles);
if (idx > 0) {
button.style.borderLeftWidth = '0';
}
Object.assign(button.children[0].style, this.options.toolbarButtonSvgStyles);
if (alignment.isApplied()) {
// select button if previously applied
this._selectButton(button);
}
this.toolbar.appendChild(button);
});
this._selectButton(button);
}
this.toolbar.appendChild(button);
});
};

_selectButton = (button) => {
button.style.filter = 'invert(20%)';
};
button.style.filter = 'invert(20%)';
};

}

0 comments on commit 33c41aa

Please sign in to comment.