Skip to content

Commit

Permalink
Inital draft of working TinyMCE
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoppe committed Jun 5, 2015
1 parent 0510320 commit 9d103b2
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "tinymce"]
path = tinymce
path = app/assets/javascripts/tinymce
url = [email protected]:tinymce/tinymce-dist.git
15 changes: 15 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
source "https://rubygems.org"

gemspec

git "http://github.com/refinery/refinerycms", branch: "master" do
gem "refinerycms"
gem "refinerycms-testing"
end

gem 'sqlite3'
gem 'pry'

group :development, :test do
gem 'selenium-webdriver', '~> 2.43'
end
18 changes: 18 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

ENGINE_PATH = File.dirname(__FILE__)
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)

if File.exists?(APP_RAKEFILE)
load 'rails/tasks/engine.rake'
end

require "refinerycms-testing"
Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)

task :default => :spec
9 changes: 9 additions & 0 deletions app/assets/controllers/refinery/tinymce_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Refinery
class TinymceController < ActionController::Base

def tinymceiframe
render :template => "/refinery/tinymceiframe", :layout => false
end

end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Refinery::FastController.class_eval do
def tinymceiframe
render :template => "/refinery/tinymceiframe", :layout => false
end
end
49 changes: 49 additions & 0 deletions app/assets/javascripts/refinery/boot_tinymce.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
$(document).on('ready page:load', function(){

tinymce.init({
selector: "textarea.visual_editor",
menubar : false,
plugins: ["image", "link"],

file_browser_callback : function(field_name, url, type, win) {

if (type == 'image') {
var title_text = "Choose an Image"
var cmsURL = '/refinery/dialogs/image';
} else {
var title_text = "Choose Object to Link"
var cmsURL = '/refinery/dialogs/link';
}

tinymce.activeEditor.windowManager.open({
file : cmsURL,
title : title_text,
width : 600, // Your dimensions may differ - toy around with them!
height : 600,
resizable : "yes",
inline : "yes", // This parameter only has an effect if you use the inlinepopups plugin!
close_previous : "yes"
}, {
window : win,
input : field_name
});
}
});

$('#submit_button').on('click', function(event){
var args = top.tinymce.activeEditor.windowManager.getParams();
win = (args.window);
input = (args.input);
dialog_type = $('#visual_editor_dialog_type', window.parent.document).val();

if (dialog_type == 'link') {
selector = "#visual_editor_href";
} else {
selector = "#visual_editor_src";
}
win.document.getElementById(input).value = $(selector, window.parent.document).val();
// window.alert( JSON.stringify(args) );
top.tinymce.activeEditor.windowManager.close();
});

});
14 changes: 14 additions & 0 deletions app/assets/javascripts/refinery/tinymce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* TINYMCE
*/

/*
Namespace: TINYMCE
Global Tinymce namespace.
*/
/*
*= require tinymce/tinymce
*= require tinymce/tinymce.jquery
*= require refinery/boot_tinymce
*= require_self
*/
4 changes: 4 additions & 0 deletions app/assets/stylesheets/tinymce.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#dialog_container, .dialog_container {
margin-left: 20px;
}

16 changes: 16 additions & 0 deletions app/views/refinery/admin/dialogs/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<form id='visual_editor_dialog_form' class='visual_editor_dialog visual_editor_dialog_<%= @dialog_type %>'>
<input type='hidden' id='visual_editor_dialog_type' class='visual_editor_dialog_type' value='<%= @dialog_type %>' />
<iframe src='<%= @iframe_src %>' id='dialog_frame' frameborder='0' marginheight='0' marginwidth='0' border='0' height='570px' width='550px'></iframe>
<div class='wym_hideables'>
<% if @dialog_type == "image" %>
<input type='hidden' id='visual_editor_src' class='visual_editor_src' value='' />
<input type='hidden' id='visual_editor_alt' class='visual_editor_alt' value='' />
<input type='hidden' id='visual_editor_title' class='visual_editor_title' value='' />
<input type='hidden' id='visual_editor_size' class='visual_editor_size' value='' />
<% elsif @dialog_type == "link" %>
<input type='hidden' id='visual_editor_href' class='visual_editor_href' value='' />
<input type='hidden' id='visual_editor_title' class='visual_editor_title' value='' />
<input type='hidden' id='visual_editor_target' class='visual_editor_target' value='' />
<% end %>
</div>
</form>
13 changes: 13 additions & 0 deletions app/views/refinery/tinymceiframe.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>TinyMCE</title>
<meta charset='<%= ::Rails.application.config.encoding %>' />
<meta httpequiv="XUACompatible" content="IE=edge,chrome=1" />
<%#= stylesheet_link_tag "tinymce/skins/lightgray/skin.min", :media => "all" %>
<%= stylesheet_link_tag "formatting", :media => "all" if Rails.application.assets.find_asset('formatting.css') %>
<%= javascript_include_tag 'modernizr-min' %>
</head>
<body class="tinymce_iframe<%= " #{params[:id]}" if params[:id].present? %>">
</body>
</html>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Refinery::Core::Engine.routes.draw do
get 'tinymceiframe(/:id)', :to => 'fast#tinymceiframe', :as => :tinymceiframe
end
11 changes: 11 additions & 0 deletions lib/refinery/tinymce.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Refinery
module Tinymce
require 'refinery/tinymce/engine'

class << self
def root
@root ||= Pathname.new(File.expand_path('../../../', __FILE__))
end
end
end
end
44 changes: 44 additions & 0 deletions lib/refinery/tinymce/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Refinery
module Tinymce
class Engine < ::Rails::Engine
include Refinery::Engine

isolate_namespace Refinery
engine_name :refinery_tinymce

# set the manifests and assets to be precompiled
config.to_prepare do
Rails.application.config.assets.precompile += %w(
tinymce/themes/modern/theme.min.js
tinymce.css
tinymce/skins/lightgray/*
)
end

before_inclusion do
Refinery::Plugin.register do |plugin|
plugin.pathname = root
plugin.name = "refinerycms_tinymce"
plugin.hide_from_menu = true
plugin.menu_match = %r{refinery/tinymce}
end
end

config.after_initialize do
Refinery.register_engine Refinery::Tinymce
end

after_inclusion do
%w(tinymce/skins/lightgray/skin.min tinymce).each do |stylesheet|
Refinery::Core.config.register_visual_editor_stylesheet stylesheet
end

%W(refinery/tinymce tinymce/themes/modern/theme.min).each do |javascript|
Refinery::Core.config.register_visual_editor_javascript javascript
end

Refinery::Pages.config.friendly_id_reserved_words << 'tinymceiframe'
end
end
end
end
2 changes: 2 additions & 0 deletions lib/refinerycms-tinymce.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'refinerycms-core'
require 'refinery/tinymce'
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TinyMCE Visual Editing for RefineryCMS
18 changes: 18 additions & 0 deletions refinerycms-tinymce.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Encoding: UTF-8
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = %q{refinerycms-tinymce}
s.version = '1.0.0'
s.summary = %q{TinyMCE support for Refinery CMS}
s.description = %q{This extension adds TinyMCE editor to Refinery CMS for visual editing.}
s.email = %q{[email protected]}
s.homepage = %q{http://refinerycms.com}
s.authors = ['Glenn Hoppe']
s.license = %q{MIT}
s.require_paths = %w(lib)

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- spec/*`.split("\n")

s.add_dependency 'refinerycms-core', '~> 3.0', '>= 3.0.0'
end

0 comments on commit 9d103b2

Please sign in to comment.