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

Commit

Permalink
Merge branch 'swift-2.0'
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
  • Loading branch information
cjwirth committed Sep 17, 2015
2 parents 66618c0 + 7d96ced commit ed5f9c1
Show file tree
Hide file tree
Showing 37 changed files with 1,013 additions and 679 deletions.
15 changes: 3 additions & 12 deletions README.md
Expand Up @@ -6,12 +6,9 @@ RichEditorView

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

Written in Swift 1.2 (Xcode 6.3)
Written in Swift 2.0 (Xcode 7.0)

**[Swift 2.0 Support](https://github.com/cjwirth/RichEditorView/tree/swift-2.0)** is available in the `swift-2.0` branch.
This will become the main branch when Xcode 7 official is released

Supports iOS 8 and 9 through Cocoapods, or iOS 7 by including the source in your project.
Supports iOS 8 and 9 through Cocoapods or Carthage.

- _Looking for Android? Check out_ [wasabeef/richeditor-android](https://github.com/wasabeef/richeditor-android)

Expand Down Expand Up @@ -55,8 +52,6 @@ Features
Installation
------------

### iOS 8+

#### Cocoapods

If you have Cocoapods 0.36+ installed, you can use Cocoapods to include `RichEditorView` into your project.
Expand All @@ -74,13 +69,9 @@ Note: the `use_frameworks!` is required for pods made in Swift.
Add the following to your `Cartfile`:

```
github 'cjwirth/RichEditorView' >= 1.2.0
github 'cjwirth/RichEditorView'
```

### iOS 7

Just add everything in the `RichEditorView/Assets` and `RichEditorView/Classes` directories to your project.

Using RichEditorView
--------------------

Expand Down
4 changes: 2 additions & 2 deletions RichEditorView.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "RichEditorView"
s.version = "1.2.0"
s.summary = "A beautiful Rich Text Editor for iOS written in Swift"
s.version = "2.0.0"
s.summary = "Rich Text Editor for iOS written in Swift"
s.homepage = "https://github.com/cjwirth/RichEditorView"
s.license = 'BSD 3-clause'
s.author = { "Caesar Wirth" => "cjwirth@gmail.com" }
Expand Down
24 changes: 23 additions & 1 deletion RichEditorView/Assets/editor/rich_editor.js
Expand Up @@ -42,8 +42,30 @@ RE.editor.addEventListener("blur", function() {
RE.callback("blur");
});

RE.customAction = function(action) {
RE.callback("action/" + action);
}

RE.callbackQueue = [];
RE.runCallbackQueue = function() {
if (RE.callbackQueue.length == 0) {
return;
}

setTimeout(function() {
window.location.href = "re-callback://";
}, 0);
}

RE.getCommandQueue = function() {
var commands = JSON.stringify(RE.callbackQueue);
RE.callbackQueue = [];
return commands;
}

RE.callback = function(method) {
window.location.href = "re-callback://" + method;
RE.callbackQueue.push(method);
RE.runCallbackQueue();
}

RE.setHtml = function(contents) {
Expand Down
11 changes: 7 additions & 4 deletions RichEditorView/Classes/CJWWebView+HackishAccessoryHiding.h
Expand Up @@ -7,11 +7,14 @@

#import <UIKit/UIKit.h>

// Credit to this extension goes to bjhomes
// https://gist.github.com/bjhomer/2048571
// Inspiration for this extension comes from:
// - bjhomes: https://gist.github.com/bjhomer/2048571
// - diegoreymendez: http://stackoverflow.com/a/25415378/1403046
// Bundled inside to add a vendored prefix so as to hopefully not cause naming conflicts
@interface UIWebView (CJWHackishAccessoryHiding)

// When set to YES, the UIWebView will no longer show an inputAccessoryView when they keyboard is shown.
@property (nonatomic, assign) BOOL cjw_hidesInputAccessoryView;
// Overrides the standard inputAccessoryView
// Set to a custom view to override. Setting to nil will remove it.
@property (nonatomic, strong, nullable) UIView *cjw_inputAccessoryView;

@end
62 changes: 37 additions & 25 deletions RichEditorView/Classes/CJWWebView+HackishAccessoryHiding.m
Expand Up @@ -13,6 +13,28 @@ @implementation UIWebView (HackishAccessoryHiding)
static const char * const hackishFixClassName = "UIWebBrowserViewMinusAccessoryView";
static Class hackishFixClass = Nil;

- (UIView *)cjw_inputAccessoryView {
return objc_getAssociatedObject(self, @selector(cjw_inputAccessoryView));
}

- (void)setCjw_inputAccessoryView:(UIView *)view {
objc_setAssociatedObject(self, @selector(cjw_inputAccessoryView), view, OBJC_ASSOCIATION_RETAIN);

UIView *browserView = [self hackishlyFoundBrowserView];
if (browserView == nil) {
return;
}
[self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]];

object_setClass(browserView, hackishFixClass);

// This is how we will return the accessory view if we want to
// Class normalClass = objc_getClass("UIWebBrowserView");
// object_setClass(browserView, normalClass);

[browserView reloadInputViews];
}

- (UIView *)hackishlyFoundBrowserView {
UIScrollView *scrollView = self.scrollView;

Expand All @@ -26,42 +48,32 @@ - (UIView *)hackishlyFoundBrowserView {
return browserView;
}

- (id)methodReturningNil {
return nil;
- (id)methodReturningCustomInputAccessoryView {
UIView *view = self;
UIView *customInputAccessoryView = nil;

while (view && ![view isKindOfClass:[UIWebView class]]) {
view = view.superview;
}

if ([view isKindOfClass:[UIWebView class]]) {
UIWebView *webView = (UIWebView*)view;
customInputAccessoryView = [webView cjw_inputAccessoryView];
}

return customInputAccessoryView;
}

- (void)ensureHackishSubclassExistsOfBrowserViewClass:(Class)browserViewClass {
if (!hackishFixClass) {
Class newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0);
newClass = objc_allocateClassPair(browserViewClass, hackishFixClassName, 0);
IMP nilImp = [self methodForSelector:@selector(methodReturningNil)];
IMP nilImp = [self methodForSelector:@selector(methodReturningCustomInputAccessoryView)];
class_addMethod(newClass, @selector(inputAccessoryView), nilImp, "@@:");
objc_registerClassPair(newClass);

hackishFixClass = newClass;
}
}

- (BOOL) cjw_hidesInputAccessoryView {
UIView *browserView = [self hackishlyFoundBrowserView];
return [browserView class] == hackishFixClass;
}

- (void) setCjw_hidesInputAccessoryView:(BOOL)value {
UIView *browserView = [self hackishlyFoundBrowserView];
if (browserView == nil) {
return;
}
[self ensureHackishSubclassExistsOfBrowserViewClass:[browserView class]];

if (value) {
object_setClass(browserView, hackishFixClass);
}
else {
Class normalClass = objc_getClass("UIWebBrowserView");
object_setClass(browserView, normalClass);
}
[browserView reloadInputViews];
}

@end
2 changes: 1 addition & 1 deletion RichEditorView/Classes/RichEditorOptionItem.swift
Expand Up @@ -27,7 +27,7 @@ public protocol RichEditorOption {
/**
The action to be evoked when the action is tapped
:param: editor The RichEditorToolbar that the RichEditorOption was being displayed in when tapped.
- parameter editor: The RichEditorToolbar that the RichEditorOption was being displayed in when tapped.
Contains a reference to the `editor` RichEditorView to perform actions on
*/
func action(editor: RichEditorToolbar?)
Expand Down
15 changes: 8 additions & 7 deletions RichEditorView/Classes/RichEditorToolbar.swift
Expand Up @@ -11,7 +11,7 @@ import UIKit
RichEditorToolbarDelegate is a protocol for the RichEditorToolbar.
Used to receive actions that need extra work to perform (eg. display some UI)
*/
public protocol RichEditorToolbarDelegate: class {
@objc public protocol RichEditorToolbarDelegate: class {

/**
Called when the Text Color toolbar item is pressed.
Expand Down Expand Up @@ -96,7 +96,7 @@ public class RichEditorToolbar: UIView {
setup()
}

public required init(coder aDecoder: NSCoder) {
public required init?(coder aDecoder: NSCoder) {
toolbarScroll = UIScrollView()
toolbar = UIToolbar()
backgroundToolbar = UIToolbar()
Expand All @@ -108,22 +108,23 @@ public class RichEditorToolbar: UIView {
self.autoresizingMask = .FlexibleWidth

backgroundToolbar.frame = self.bounds
backgroundToolbar.autoresizingMask = .FlexibleHeight | .FlexibleWidth
backgroundToolbar.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]

toolbar.autoresizingMask = .FlexibleWidth
toolbar.setBackgroundImage(UIImage(), forToolbarPosition: .Any, barMetrics: .Default)
toolbar.setShadowImage(UIImage(), forToolbarPosition: .Any)

toolbarScroll.frame = self.bounds
toolbarScroll.autoresizingMask = .FlexibleHeight | .FlexibleWidth
toolbarScroll.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]
toolbarScroll.showsHorizontalScrollIndicator = false
toolbarScroll.showsVerticalScrollIndicator = false
toolbarScroll.backgroundColor = UIColor.clearColor()

toolbarScroll.addSubview(toolbar)

self.addSubview(backgroundToolbar)
self.addSubview(toolbarScroll)
addSubview(backgroundToolbar)
addSubview(toolbarScroll)
updateToolbar()
}

private func updateToolbar() {
Expand All @@ -143,7 +144,7 @@ public class RichEditorToolbar: UIView {

let defaultIconWidth: CGFloat = 22
let barButtonItemMargin: CGFloat = 11
var width: CGFloat = buttons.reduce(0) {sofar, new in
let width: CGFloat = buttons.reduce(0) {sofar, new in
if let view = new.valueForKey("view") as? UIView {
return sofar + view.frame.size.width + barButtonItemMargin
} else {
Expand Down

0 comments on commit ed5f9c1

Please sign in to comment.