Skip to content

Commit 0daeb3b

Browse files
committed
Merge branch 'cjwirth-master'
2 parents 553e089 + 6565d99 commit 0daeb3b

File tree

20 files changed

+656
-347
lines changed

20 files changed

+656
-347
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RichEditorView
66

77
RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing.
88

9-
Written in Swift 4.0
9+
Written in Swift 4
1010

1111
Supports iOS 8+ through Cocoapods or Carthage.
1212

RichEditorView.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "RichEditorView"
3-
s.version = "4.0.0"
3+
s.version = "5.0.0"
44
s.summary = "Rich Text Editor for iOS written in Swift"
55
s.homepage = "https://github.com/cjwirth/RichEditorView"
66
s.license = 'BSD 3-clause'
@@ -9,6 +9,7 @@ Pod::Spec.new do |s|
99
s.social_media_url = 'https://twitter.com/cjwirth'
1010

1111
s.platform = :ios, '8.0'
12+
s.swift_version = '4.0'
1213
s.requires_arc = true
1314

1415
s.source_files = 'RichEditorView/Classes/*'

RichEditorView/Assets/editor/rich_editor.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,16 @@ RE.getText = function() {
113113
return RE.editor.innerText;
114114
};
115115

116+
RE.setBaseTextColor = function(color) {
117+
RE.editor.style.color = color;
118+
};
119+
116120
RE.setPlaceholderText = function(text) {
117121
RE.editor.setAttribute("placeholder", text);
118122
};
119123

120124
RE.updatePlaceholder = function() {
121-
if (RE.editor.textContent.length > 0) {
125+
if (RE.editor.innerHTML.indexOf('img') !== -1 || (RE.editor.textContent.length > 0 && RE.editor.innerHTML.length > 0)) {
122126
RE.editor.classList.remove("placeholder");
123127
} else {
124128
RE.editor.classList.add("placeholder");

RichEditorView/Classes/RichEditorToolbar.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import UIKit
2525
}
2626

2727
/// RichBarButtonItem is a subclass of UIBarButtonItem that takes a callback as opposed to the target-action pattern
28-
open class RichBarButtonItem: UIBarButtonItem {
28+
@objcMembers open class RichBarButtonItem: UIBarButtonItem {
2929
open var actionHandler: (() -> Void)?
3030

3131
public convenience init(image: UIImage? = nil, handler: (() -> Void)? = nil) {
@@ -48,7 +48,7 @@ open class RichBarButtonItem: UIBarButtonItem {
4848
}
4949

5050
/// RichEditorToolbar is UIView that contains the toolbar for actions that can be performed on a RichEditorView
51-
open class RichEditorToolbar: UIView {
51+
@objcMembers open class RichEditorToolbar: UIView {
5252

5353
/// The delegate to receive events that cannot be automatically completed
5454
open weak var delegate: RichEditorToolbarDelegate?
@@ -134,7 +134,7 @@ open class RichEditorToolbar: UIView {
134134
}
135135
toolbar.items = buttons
136136

137-
let defaultIconWidth: CGFloat = 22
137+
let defaultIconWidth: CGFloat = 28
138138
let barButtonItemMargin: CGFloat = 11
139139
let width: CGFloat = buttons.reduce(0) {sofar, new in
140140
if let view = new.value(forKey: "view") as? UIView {

RichEditorView/Classes/RichEditorView.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import UIKit
4040
}
4141

4242
/// RichEditorView is a UIView that displays richly styled text, and allows it to be edited in a WYSIWYG fashion.
43-
open class RichEditorView: UIView, UIScrollViewDelegate, UIWebViewDelegate, UIGestureRecognizerDelegate {
43+
@objcMembers open class RichEditorView: UIView, UIScrollViewDelegate, UIWebViewDelegate, UIGestureRecognizerDelegate {
4444

4545
// MARK: Public Properties
4646

@@ -278,6 +278,10 @@ open class RichEditorView: UIView, UIScrollViewDelegate, UIWebViewDelegate, UIGe
278278
runJS("RE.setTextColor('\(color.hex)');")
279279
}
280280

281+
public func setEditorFontColor(_ color: UIColor) {
282+
runJS("RE.setBaseTextColor('\(color.hex)');")
283+
}
284+
281285
public func setTextBackgroundColor(_ color: UIColor) {
282286
runJS("RE.prepareInsert();")
283287
runJS("RE.setTextBackgroundColor('\(color.hex)');")
@@ -528,6 +532,8 @@ open class RichEditorView: UIView, UIScrollViewDelegate, UIWebViewDelegate, UIGe
528532
}
529533
}
530534

535+
// MARK: - Responder Handling
536+
531537
/// Called by the UITapGestureRecognizer when the user taps the view.
532538
/// If we are not already the first responder, focus the editor.
533539
@objc private func viewWasTapped() {
@@ -537,5 +543,19 @@ open class RichEditorView: UIView, UIScrollViewDelegate, UIWebViewDelegate, UIGe
537543
focus(at: point)
538544
}
539545
}
540-
546+
547+
override open func becomeFirstResponder() -> Bool {
548+
if !webView.containsFirstResponder {
549+
focus()
550+
return true
551+
} else {
552+
return false
553+
}
554+
}
555+
556+
open override func resignFirstResponder() -> Bool {
557+
blur()
558+
return true
559+
}
560+
541561
}

RichEditorViewSample/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use_frameworks!
2+
platform :ios, '8.0'
23

34
target 'RichEditorViewSample' do
45
pod "RichEditorView", :path => "../"

RichEditorViewSample/Podfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
PODS:
2-
- RichEditorView (3.2.0)
2+
- RichEditorView (5.0.0)
33

44
DEPENDENCIES:
55
- RichEditorView (from `../`)
66

77
EXTERNAL SOURCES:
88
RichEditorView:
9-
:path: "../"
9+
:path: ../
1010

1111
SPEC CHECKSUMS:
12-
RichEditorView: b4ee60a4f5301cbe8f3fcb1f065cdd7de74ddd10
12+
RichEditorView: 2b536e648162702950a152786223f5a55794504f
1313

14-
PODFILE CHECKSUM: db274185d3928152699d5fb4a21714929f874dd8
14+
PODFILE CHECKSUM: 7a4df9933ce0390c2a1aa64e14fa39cd32734a0d
1515

16-
COCOAPODS: 1.2.0
16+
COCOAPODS: 1.4.0

RichEditorViewSample/Pods/Local Podspecs/RichEditorView.podspec.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RichEditorViewSample/Pods/Manifest.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)