Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Fix body button #186

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions RichEditorView/Assets/editor/rich_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,24 @@ RE.updatePlaceholder = function() {
};

RE.removeFormat = function() {
// https://stackoverflow.com/a/52137754/4514671
// https://stackoverflow.com/questions/14028773/javascript-execcommandremoveformat-doesnt-strip-h2-tag
// formatting to 'p' because removeFormat cannot deal with headers (h1, h2, ...)
document.execCommand('formatBlock', false, 'p');
document.execCommand('removeFormat', false, null);
};

RE.setFontSize = function(size) {
RE.editor.style.fontSize = size;
};

RE.setFontFamily = function(font) {
RE.restorerange();
document.execCommand("styleWithCSS", null, true);
document.execCommand('fontName', false, font);
document.execCommand("styleWithCSS", null, false);
};

RE.setBackgroundColor = function(color) {
RE.editor.style.backgroundColor = color;
};
Expand Down
1 change: 1 addition & 0 deletions RichEditorView/Assets/editor/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ html {
body {
min-height: 100%;
overflow: auto;
padding: 10px;
}

body, h1, p {
Expand Down
4 changes: 4 additions & 0 deletions RichEditorView/Classes/RichEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ import UIKit
runJS("RE.setFontSize('\(size)px');")
}

public func setFontFamily(_ font: String) {
runJS("RE.setFontFamily('\(font)');")
}

public func setEditorBackgroundColor(_ color: UIColor) {
runJS("RE.setBackgroundColor('\(color.hex)');")
}
Expand Down