foundation-wysihtml5-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/CONTRIBUTING.md +5 -0
- data/Gemfile +4 -0
- data/README.md +82 -0
- data/Rakefile +78 -0
- data/foundation-wysihtml5-rails.gemspec +20 -0
- data/lib/foundation-wysihtml5-rails.rb +12 -0
- data/lib/foundation-wysihtml5-rails/engine.rb +9 -0
- data/lib/foundation-wysihtml5-rails/railtie.rb +5 -0
- data/lib/foundation-wysihtml5-rails/version.rb +5 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/core.js.erb +514 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/index.js +2 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/ar-AR.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/bg-BG.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/ca-CT.js +47 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/cs-CZ.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/da-DK.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/de-DE.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/el-GR.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/es-AR.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/es-ES.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/fr-FR.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/fr-NL.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/hr-HR.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/index.js +1 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/it-IT.js +47 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/ja-JP.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/ko-KR.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/lt-LT.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/mo-MD.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/nb-NB.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/nl-NL.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/pl-PL.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/pt-BR.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/ru-RU.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/sk-SK.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/sv-SE.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/tr-TR.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/ua-UA.js +49 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/zh-CN.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/locales/zh-TW.js +48 -0
- data/vendor/assets/javascripts/foundation-wysihtml5/wysihtml5.js +9523 -0
- data/vendor/assets/stylesheets/foundation-wysihtml5/core.css +106 -0
- data/vendor/assets/stylesheets/foundation-wysihtml5/index.css +3 -0
- data/vendor/assets/stylesheets/foundation-wysihtml5/wysiwyg-color.css +67 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 05dedd938d62111f0cf23039e68b385305eb8457
|
4
|
+
data.tar.gz: feb3e56a59e686951e863076be6883eed7d6ba70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 711796e64d6ddb7f83be73afc06559106d92f53cfcedec762867af7b8e00f3731637b05ef645cc90c463dfd801fb1bde196780a2686832e88d4073a4e54b378b
|
7
|
+
data.tar.gz: 89a0598d23f544345a1793d99c76b935f883aa7fd7800ba4c1eccd23eb91aca6fc1b864c97607762e1ccc220bbe2bdc1ed29b3b9674f580e2c90fa04640d5b7e
|
data/.gitignore
ADDED
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Foundation Wysihtml5 for Rails
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/foundation-wysihtml5-rails.png)](http://badge.fury.io/rb/foundation-wysihtml5-rails)
|
4
|
+
|
5
|
+
|
6
|
+
This is a port of Bootstrap Wysihtml5 to Zurb Foundation.
|
7
|
+
|
8
|
+
[Bootstrap Wysihtml5](https://github.com/jhollingworth/bootstrap-wysihtml5) is a plugin for Bootstrap designed by James Hollingworth. It provides a stylish wysiwyg editor for Bootstrap.
|
9
|
+
|
10
|
+
This project is a fork from [Nerian's `bootstrap-wysihtml5-rails`](https://github.com/Nerian/bootstrap-wysihtml5-rails) and it was modified to work with Zurb Foundation.
|
11
|
+
|
12
|
+
## Compatible with Foundation 4 and 5
|
13
|
+
|
14
|
+
Tested on Foundation 4 and 5.
|
15
|
+
|
16
|
+
## Rails > 3.1
|
17
|
+
Include foundation-wysihtml5-rails in Gemfile;
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
gem 'foundation-wysihtml5-rails'
|
21
|
+
```
|
22
|
+
|
23
|
+
and run bundle install.
|
24
|
+
|
25
|
+
This gem doesn't include Foundation. You can get Foundation here: https://github.com/zurb/foundation-rails.
|
26
|
+
|
27
|
+
It also has as dependency [`font-awesome`](http://fortawesome.github.io/Font-Awesome/) for the icons. Please add it to your project.
|
28
|
+
|
29
|
+
## Configuration
|
30
|
+
|
31
|
+
Foundation-wysihtml5 depends on jquery, foundation and font-awesome.
|
32
|
+
|
33
|
+
app/assets/stylesheets/application.css
|
34
|
+
``` css
|
35
|
+
*= require foundation-wysihtml5
|
36
|
+
```
|
37
|
+
|
38
|
+
app/assets/javascripts/application.js
|
39
|
+
```javascript
|
40
|
+
//= require foundation-wysihtml5
|
41
|
+
|
42
|
+
You may include all locales like this:
|
43
|
+
|
44
|
+
//= require foundation-wysihtml5/locales
|
45
|
+
|
46
|
+
Or just add the ones that you want
|
47
|
+
|
48
|
+
//= require foundation-wysihtml5/locales/de-DE
|
49
|
+
//= require foundation-wysihtml5/locales/es-ES
|
50
|
+
```
|
51
|
+
|
52
|
+
You may need to restart your rails server.
|
53
|
+
|
54
|
+
## Using foundation-wysihtml5-rails
|
55
|
+
|
56
|
+
Just call wysihtml5() with any selector.
|
57
|
+
|
58
|
+
```html
|
59
|
+
<textarea id="some-textarea" class='wysihtml5' placeholder="Enter text ..."></textarea>
|
60
|
+
|
61
|
+
<script type="text/javascript">
|
62
|
+
$(document).ready(function(){
|
63
|
+
$('.wysihtml5').wysihtml5();
|
64
|
+
})
|
65
|
+
</script>
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
## If using Turbolinks
|
70
|
+
|
71
|
+
```
|
72
|
+
$(document).on('page:load', function(){
|
73
|
+
window['rangy'].initialized = false
|
74
|
+
})
|
75
|
+
```
|
76
|
+
|
77
|
+
## License
|
78
|
+
Copyright (c) 2014 Josemar Luedke
|
79
|
+
|
80
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
81
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
82
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require File.expand_path('../lib/foundation-wysihtml5-rails/version', __FILE__)
|
3
|
+
|
4
|
+
ORIGIN_LIB_PATH = "foundation-wysihtml5/lib"
|
5
|
+
ORIGIN_SRC_PATH = "foundation-wysihtml5/src"
|
6
|
+
DEST_JAVASCRIPT_PATH = "vendor/assets/javascripts/foundation-wysihtml5"
|
7
|
+
DEST_CSS_PATH = "vendor/assets/stylesheets/foundation-wysihtml5"
|
8
|
+
|
9
|
+
def b2
|
10
|
+
system("cd foundation-wysihtml5 && git checkout master")
|
11
|
+
|
12
|
+
system("cp #{ORIGIN_SRC_PATH}/foundation-wysihtml5.css #{DEST_CSS_PATH}/core.css")
|
13
|
+
|
14
|
+
core_file = File.read("#{ORIGIN_SRC_PATH}/foundation-wysihtml5.js")
|
15
|
+
original_string = /stylesheets: \[".\/lib\/css\/wysiwyg-color.css"\]/
|
16
|
+
objective_string = "stylesheets: [\"<%= stylesheet_path('foundation-wysihtml5/wysiwyg-color.css') %>\"]"
|
17
|
+
|
18
|
+
replaced = core_file.gsub(original_string, objective_string)
|
19
|
+
|
20
|
+
File.open("#{DEST_JAVASCRIPT_PATH}/core.js.erb", "w") { |file| file.puts replaced }
|
21
|
+
end
|
22
|
+
|
23
|
+
def b3
|
24
|
+
system("cd foundation-wysihtml5 && git checkout tb3")
|
25
|
+
|
26
|
+
system("cp #{ORIGIN_SRC_PATH}/foundation-wysihtml5.css #{DEST_CSS_PATH}/core-b3.css")
|
27
|
+
|
28
|
+
core_file = File.read("#{ORIGIN_SRC_PATH}/foundation-wysihtml5.js")
|
29
|
+
original_string = /stylesheets: \[".\/lib\/css\/wysiwyg-color.css"\]/
|
30
|
+
objective_string = "stylesheets: [\"<%= stylesheet_path('foundation-wysihtml5/wysiwyg-color.css') %>\"]"
|
31
|
+
|
32
|
+
replaced = core_file.gsub(original_string, objective_string)
|
33
|
+
|
34
|
+
File.open("#{DEST_JAVASCRIPT_PATH}/core-b3.js.erb", "w") { |file| file.puts replaced }
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
desc "Update assets"
|
40
|
+
task 'update' do
|
41
|
+
if Dir.exist?('foundation-wysihtml5')
|
42
|
+
system("cd foundation-wysihtml5 && git pull && cd ..")
|
43
|
+
else
|
44
|
+
system("git clone git://github.com/jhollingworth/foundation-wysihtml5.git foundation-wysihtml5")
|
45
|
+
system("cd foundation-wysihtml5 && git remote add b3 git@github.com:artillery/foundation-wysihtml5.git")
|
46
|
+
system("cd foundation-wysihtml5 && git fetch b3")
|
47
|
+
system("cd foundation-wysihtml5 && git checkout -b tb3 b3/master")
|
48
|
+
end
|
49
|
+
|
50
|
+
Dir.foreach("foundation-wysihtml5/src/locales") do |file|
|
51
|
+
unless file == '.' || file == '..'
|
52
|
+
abbreviated_file_name = file.gsub('foundation-wysihtml5.', '')
|
53
|
+
system("cp #{ORIGIN_SRC_PATH}/locales/#{file} #{DEST_JAVASCRIPT_PATH}/locales/#{abbreviated_file_name}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
system("cp #{ORIGIN_LIB_PATH}/js/wysihtml5-0.3.0.js #{DEST_JAVASCRIPT_PATH}/wysihtml5.js")
|
58
|
+
system("cp #{ORIGIN_LIB_PATH}/css/wysiwyg-color.css #{DEST_CSS_PATH}/wysiwyg-color.css")
|
59
|
+
|
60
|
+
b2
|
61
|
+
b3
|
62
|
+
|
63
|
+
system("git status")
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Build"
|
67
|
+
task "build" do
|
68
|
+
system("gem build foundation-wysihtml5-rails.gemspec")
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Publish a new version"
|
72
|
+
task :publish => :build do
|
73
|
+
tags = `git tag`.split
|
74
|
+
version = FoundationWysihtml5Rails::Rails::VERSION
|
75
|
+
system("git tag -a #{version} -m 'Release #{version}' ") unless tags.include?(version)
|
76
|
+
system("gem push foundation-wysihtml5-rails-#{version}.gem")
|
77
|
+
system("git push --follow-tags")
|
78
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/foundation-wysihtml5-rails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Josemar Luedke', 'Gonzalo Rodríguez-Baltanás Díaz']
|
6
|
+
gem.email = ['josemarluedke@gmail.com', 'siotopo@gmail.com']
|
7
|
+
gem.description = %q{A wysiwyg text editor for Zurb Foundation}
|
8
|
+
gem.homepage = 'https://github.com/josemarluedke/foundation-wysihtml5-rails'
|
9
|
+
gem.summary = gem.description
|
10
|
+
gem.license = 'MIT'
|
11
|
+
|
12
|
+
gem.name = 'foundation-wysihtml5-rails'
|
13
|
+
gem.require_paths = ['lib']
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.version = FoundationWysihtml5Rails::Rails::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency 'railties', '>= 3.0'
|
18
|
+
gem.add_development_dependency 'bundler', '>= 1.0'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "rails"
|
2
|
+
require "foundation-wysihtml5-rails/version"
|
3
|
+
|
4
|
+
module FoundationWysihtml5Rails
|
5
|
+
module Rails
|
6
|
+
if ::Rails.version.to_s < "3.1"
|
7
|
+
require "foundation-wysihtml5-rails/railtie"
|
8
|
+
else
|
9
|
+
require "foundation-wysihtml5-rails/engine"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module FoundationWysihtml5Rails
|
2
|
+
module Rails
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
initializer "FoundationWysihtml5Rails precompile hook", :group => :all do |app|
|
5
|
+
app.config.assets.precompile += %w(foundation-wysihtml5.css foundation-wysihtml5.js foundation-wysihtml5/wysiwyg-color.css)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,514 @@
|
|
1
|
+
!function($, wysi) {
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
var tpl = {
|
5
|
+
"font-styles": function(locale, options) {
|
6
|
+
var size = (options && options.size) ? ' '+options.size : '';
|
7
|
+
return "<li class='dropdown'>" +
|
8
|
+
"<a class='button secondary dropdown" + size + "' data-dropdown='drop' href='#'>" +
|
9
|
+
"<i class='fa fa-font'></i> <span class='current-font'>" + locale.font_styles.normal + "</span> <b class='caret'></b>" +
|
10
|
+
"</a>" +
|
11
|
+
"<ul id='drop' data-dropdown-content class='f-dropdown'>" +
|
12
|
+
"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='div' tabindex='-1'>" + locale.font_styles.normal + "</a></li>" +
|
13
|
+
"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h1' tabindex='-1'>" + locale.font_styles.h1 + "</a></li>" +
|
14
|
+
"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h2' tabindex='-1'>" + locale.font_styles.h2 + "</a></li>" +
|
15
|
+
"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h3' tabindex='-1'>" + locale.font_styles.h3 + "</a></li>" +
|
16
|
+
"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h4'>" + locale.font_styles.h4 + "</a></li>" +
|
17
|
+
"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h5'>" + locale.font_styles.h5 + "</a></li>" +
|
18
|
+
"<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h6'>" + locale.font_styles.h6 + "</a></li>" +
|
19
|
+
"</ul>" +
|
20
|
+
"</li>";
|
21
|
+
},
|
22
|
+
|
23
|
+
"emphasis": function(locale, options) {
|
24
|
+
var size = (options && options.size) ? ' '+options.size : '';
|
25
|
+
return "<li>" +
|
26
|
+
"<div class='button-group'>" +
|
27
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='bold' title='CTRL+B' tabindex='-1'>" + locale.emphasis.bold + "</a>" +
|
28
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='italic' title='CTRL+I' tabindex='-1'>" + locale.emphasis.italic + "</a>" +
|
29
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='underline' title='CTRL+U' tabindex='-1'>" + locale.emphasis.underline + "</a>" +
|
30
|
+
"</div>" +
|
31
|
+
"</li>";
|
32
|
+
},
|
33
|
+
|
34
|
+
"lists": function(locale, options) {
|
35
|
+
var size = (options && options.size) ? ' '+options.size : '';
|
36
|
+
return "<li>" +
|
37
|
+
"<div class='button-group'>" +
|
38
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='insertUnorderedList' title='" + locale.lists.unordered + "' tabindex='-1'><i class='fa fa-list'></i></a>" +
|
39
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='insertOrderedList' title='" + locale.lists.ordered + "' tabindex='-1'><i class='fa fa-th-list'></i></a>" +
|
40
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='Outdent' title='" + locale.lists.outdent + "' tabindex='-1'><i class='fa fa-dedent'></i></a>" +
|
41
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='Indent' title='" + locale.lists.indent + "' tabindex='-1'><i class='fa fa-indent'></i></a>" +
|
42
|
+
"</div>" +
|
43
|
+
"</li>";
|
44
|
+
},
|
45
|
+
|
46
|
+
"link": function(locale, options) {
|
47
|
+
var size = (options && options.size) ? ' '+options.size : '';
|
48
|
+
return "<li>" +
|
49
|
+
"<div class='foundation-wysihtml5-insert-link-modal reveal-modal small' data-reveal>" +
|
50
|
+
"<div class='modal-header'>" +
|
51
|
+
"<a class='close-reveal-modal'>×</a>" +
|
52
|
+
"<h3>" + locale.link.insert + "</h3>" +
|
53
|
+
"</div>" +
|
54
|
+
"<div class='modal-body'>" +
|
55
|
+
"<input value='http://' class='foundation-wysihtml5-insert-link-url input-xlarge' type='text'>" +
|
56
|
+
"</div>" +
|
57
|
+
"<div class='modal-footer'>" +
|
58
|
+
"<a href='#' class='button secondary close'>" + locale.link.cancel + "</a> " +
|
59
|
+
"<a href='#' class='button insert close'>" + locale.link.insert + "</a>" +
|
60
|
+
"</div>" +
|
61
|
+
"</div>" +
|
62
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='createLink' title='" + locale.link.insert + "' tabindex='-1'><i class='fa fa-link'></i></a>" +
|
63
|
+
"</li>";
|
64
|
+
},
|
65
|
+
|
66
|
+
"image": function(locale, options) {
|
67
|
+
var size = (options && options.size) ? ' '+options.size : '';
|
68
|
+
return "<li>" +
|
69
|
+
"<div class='foundation-wysihtml5-insert-image-modal reveal-modal small' data-reveal>" +
|
70
|
+
"<div class='modal-header'>" +
|
71
|
+
"<a class='close-reveal-modal'>×</a>" +
|
72
|
+
"<h3>" + locale.image.insert + "</h3>" +
|
73
|
+
"</div>" +
|
74
|
+
"<div class='modal-body'>" +
|
75
|
+
"<input value='http://' class='foundation-wysihtml5-insert-image-url input-xlarge' type='text'>" +
|
76
|
+
"</div>" +
|
77
|
+
"<div class='modal-footer'>" +
|
78
|
+
"<a href='#' class='button secondary close'>" + locale.image.cancel + "</a> " +
|
79
|
+
"<a href='#' class='button insert close'>" + locale.image.insert + "</a>" +
|
80
|
+
"</div>" +
|
81
|
+
"</div>" +
|
82
|
+
"<a class='button secondary" + size + "' data-wysihtml5-command='insertImage' title='" + locale.image.insert + "' tabindex='-1'><i class='fa fa-picture-o'></i></a>" +
|
83
|
+
"</li>";
|
84
|
+
},
|
85
|
+
|
86
|
+
"html": function(locale, options) {
|
87
|
+
var size = (options && options.size) ? ' '+options.size : '';
|
88
|
+
return "<li>" +
|
89
|
+
"<div class='button-group'>" +
|
90
|
+
"<a class='button secondary" + size + "' data-wysihtml5-action='change_view' title='" + locale.html.edit + "' tabindex='-1'><i class='fa fa-pencil'></i></a>" +
|
91
|
+
"</div>" +
|
92
|
+
"</li>";
|
93
|
+
},
|
94
|
+
|
95
|
+
"color": function(locale, options) {
|
96
|
+
var size = (options && options.size) ? ' '+options.size : '';
|
97
|
+
return "<li class='dropdown'>" +
|
98
|
+
"<a class='button secondary dropdown" + size + "' data-dropdown='drop_2' href='#' tabindex='-1'>" +
|
99
|
+
"<span class='current-color'>" + locale.colours.black + "</span> <b class='caret'></b>" +
|
100
|
+
"</a>" +
|
101
|
+
"<ul id='drop_2' data-dropdown-content class='f-dropdown'>" +
|
102
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='black'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='black'>" + locale.colours.black + "</a></li>" +
|
103
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='silver'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='silver'>" + locale.colours.silver + "</a></li>" +
|
104
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='gray'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='gray'>" + locale.colours.gray + "</a></li>" +
|
105
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='maroon'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='maroon'>" + locale.colours.maroon + "</a></li>" +
|
106
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='red'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='red'>" + locale.colours.red + "</a></li>" +
|
107
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='purple'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='purple'>" + locale.colours.purple + "</a></li>" +
|
108
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='green'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='green'>" + locale.colours.green + "</a></li>" +
|
109
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='olive'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='olive'>" + locale.colours.olive + "</a></li>" +
|
110
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='navy'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='navy'>" + locale.colours.navy + "</a></li>" +
|
111
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='blue'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='blue'>" + locale.colours.blue + "</a></li>" +
|
112
|
+
"<li><div class='wysihtml5-colors' data-wysihtml5-command-value='orange'></div><a class='wysihtml5-colors-title' data-wysihtml5-command='foreColor' data-wysihtml5-command-value='orange'>" + locale.colours.orange + "</a></li>" +
|
113
|
+
"</ul>" +
|
114
|
+
"</li>";
|
115
|
+
}
|
116
|
+
};
|
117
|
+
|
118
|
+
var templates = function(key, locale, options) {
|
119
|
+
return tpl[key](locale, options);
|
120
|
+
};
|
121
|
+
|
122
|
+
|
123
|
+
var Wysihtml5 = function(el, options) {
|
124
|
+
this.el = el;
|
125
|
+
var toolbarOpts = options || defaultOptions;
|
126
|
+
for(var t in toolbarOpts.customTemplates) {
|
127
|
+
tpl[t] = toolbarOpts.customTemplates[t];
|
128
|
+
}
|
129
|
+
this.toolbar = this.createToolbar(el, toolbarOpts);
|
130
|
+
this.editor = this.createEditor(options);
|
131
|
+
|
132
|
+
window.editor = this.editor;
|
133
|
+
|
134
|
+
$('iframe.wysihtml5-sandbox').each(function(i, el){
|
135
|
+
$(el.contentWindow).off('focus.wysihtml5').on({
|
136
|
+
'focus.wysihtml5' : function(){
|
137
|
+
$('li.dropdown ul[data-dropdown-content]').removeClass('open');
|
138
|
+
}
|
139
|
+
});
|
140
|
+
});
|
141
|
+
};
|
142
|
+
|
143
|
+
Wysihtml5.prototype = {
|
144
|
+
|
145
|
+
constructor: Wysihtml5,
|
146
|
+
|
147
|
+
createEditor: function(options) {
|
148
|
+
options = options || {};
|
149
|
+
|
150
|
+
// Add the toolbar to a clone of the options object so multiple instances
|
151
|
+
// of the WYISYWG don't break because "toolbar" is already defined
|
152
|
+
options = $.extend(true, {}, options);
|
153
|
+
options.toolbar = this.toolbar[0];
|
154
|
+
|
155
|
+
var editor = new wysi.Editor(this.el[0], options);
|
156
|
+
|
157
|
+
if(options && options.events) {
|
158
|
+
for(var eventName in options.events) {
|
159
|
+
editor.on(eventName, options.events[eventName]);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
return editor;
|
163
|
+
},
|
164
|
+
|
165
|
+
createToolbar: function(el, options) {
|
166
|
+
var self = this;
|
167
|
+
var toolbar = $("<ul/>", {
|
168
|
+
'class' : "wysihtml5-toolbar",
|
169
|
+
'style': "display:none"
|
170
|
+
});
|
171
|
+
var culture = options.locale || defaultOptions.locale || "en";
|
172
|
+
for(var key in defaultOptions) {
|
173
|
+
var value = false;
|
174
|
+
|
175
|
+
if(options[key] !== undefined) {
|
176
|
+
if(options[key] === true) {
|
177
|
+
value = true;
|
178
|
+
}
|
179
|
+
} else {
|
180
|
+
value = defaultOptions[key];
|
181
|
+
}
|
182
|
+
|
183
|
+
if(value === true) {
|
184
|
+
toolbar.append(templates(key, locale[culture], options));
|
185
|
+
|
186
|
+
if(key === "html") {
|
187
|
+
this.initHtml(toolbar);
|
188
|
+
}
|
189
|
+
|
190
|
+
if(key === "link") {
|
191
|
+
this.initInsertLink(toolbar);
|
192
|
+
}
|
193
|
+
|
194
|
+
if(key === "image") {
|
195
|
+
this.initInsertImage(toolbar);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
if(options.toolbar) {
|
201
|
+
for(key in options.toolbar) {
|
202
|
+
toolbar.append(options.toolbar[key]);
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
toolbar.find("a[data-wysihtml5-command='formatBlock']").click(function(e) {
|
207
|
+
var target = e.target || e.srcElement;
|
208
|
+
var el = $(target);
|
209
|
+
self.toolbar.find('.current-font').text(el.html());
|
210
|
+
el.parents('[data-dropdown-content]').foundation('dropdown', 'close', el.parents('[data-dropdown-content]'));
|
211
|
+
});
|
212
|
+
|
213
|
+
toolbar.find("a[data-wysihtml5-command='foreColor']").click(function(e) {
|
214
|
+
var target = e.target || e.srcElement;
|
215
|
+
var el = $(target);
|
216
|
+
self.toolbar.find('.current-color').text(el.html());
|
217
|
+
el.parents('[data-dropdown-content]').foundation('dropdown', 'close', el.parents('[data-dropdown-content]'));
|
218
|
+
});
|
219
|
+
|
220
|
+
this.el.before(toolbar);
|
221
|
+
|
222
|
+
return toolbar;
|
223
|
+
},
|
224
|
+
|
225
|
+
initHtml: function(toolbar) {
|
226
|
+
var changeViewSelector = "a[data-wysihtml5-action='change_view']";
|
227
|
+
toolbar.find(changeViewSelector).click(function(e) {
|
228
|
+
toolbar.find('a.button').not(changeViewSelector).toggleClass('disabled');
|
229
|
+
});
|
230
|
+
},
|
231
|
+
|
232
|
+
initInsertImage: function(toolbar) {
|
233
|
+
var self = this;
|
234
|
+
var insertImageModal = toolbar.find('.foundation-wysihtml5-insert-image-modal');
|
235
|
+
var urlInput = insertImageModal.find('.foundation-wysihtml5-insert-image-url');
|
236
|
+
var insertButton = insertImageModal.find('a.button.insert');
|
237
|
+
var initialValue = urlInput.val();
|
238
|
+
var caretBookmark;
|
239
|
+
|
240
|
+
var insertImage = function() {
|
241
|
+
var url = urlInput.val();
|
242
|
+
urlInput.val(initialValue);
|
243
|
+
self.editor.currentView.element.focus();
|
244
|
+
if (caretBookmark) {
|
245
|
+
self.editor.composer.selection.setBookmark(caretBookmark);
|
246
|
+
caretBookmark = null;
|
247
|
+
}
|
248
|
+
self.editor.composer.commands.exec("insertImage", url);
|
249
|
+
};
|
250
|
+
|
251
|
+
urlInput.keypress(function(e) {
|
252
|
+
if(e.which == 13) {
|
253
|
+
insertImage();
|
254
|
+
insertImageModal.foundation('reveal', 'close');
|
255
|
+
}
|
256
|
+
});
|
257
|
+
|
258
|
+
insertButton.click(insertImage);
|
259
|
+
|
260
|
+
insertImageModal.on('shown', function() {
|
261
|
+
urlInput.focus();
|
262
|
+
});
|
263
|
+
|
264
|
+
insertImageModal.on('hide', function() {
|
265
|
+
self.editor.currentView.element.focus();
|
266
|
+
});
|
267
|
+
|
268
|
+
toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() {
|
269
|
+
var activeButton = $(this).hasClass("wysihtml5-command-active");
|
270
|
+
|
271
|
+
if (!activeButton) {
|
272
|
+
self.editor.currentView.element.focus(false);
|
273
|
+
caretBookmark = self.editor.composer.selection.getBookmark();
|
274
|
+
insertImageModal.foundation('reveal', 'open');
|
275
|
+
insertImageModal.on('click', '.close', function(e) {
|
276
|
+
insertImageModal.foundation('reveal', 'close');
|
277
|
+
e.preventDefault();
|
278
|
+
});
|
279
|
+
return false;
|
280
|
+
}
|
281
|
+
else {
|
282
|
+
return true;
|
283
|
+
}
|
284
|
+
});
|
285
|
+
},
|
286
|
+
|
287
|
+
initInsertLink: function(toolbar) {
|
288
|
+
var self = this;
|
289
|
+
var insertLinkModal = toolbar.find('.foundation-wysihtml5-insert-link-modal');
|
290
|
+
var urlInput = insertLinkModal.find('.foundation-wysihtml5-insert-link-url');
|
291
|
+
var targetInput = insertLinkModal.find('.foundation-wysihtml5-insert-link-target');
|
292
|
+
var insertButton = insertLinkModal.find('a.button.insert');
|
293
|
+
var initialValue = urlInput.val();
|
294
|
+
var caretBookmark;
|
295
|
+
|
296
|
+
var insertLink = function() {
|
297
|
+
var url = urlInput.val();
|
298
|
+
urlInput.val(initialValue);
|
299
|
+
self.editor.currentView.element.focus();
|
300
|
+
if (caretBookmark) {
|
301
|
+
self.editor.composer.selection.setBookmark(caretBookmark);
|
302
|
+
caretBookmark = null;
|
303
|
+
}
|
304
|
+
|
305
|
+
var newWindow = targetInput.prop("checked");
|
306
|
+
self.editor.composer.commands.exec("createLink", {
|
307
|
+
'href' : url,
|
308
|
+
'target' : (newWindow ? '_blank' : '_self'),
|
309
|
+
'rel' : (newWindow ? 'nofollow' : '')
|
310
|
+
});
|
311
|
+
};
|
312
|
+
var pressedEnter = false;
|
313
|
+
|
314
|
+
urlInput.keypress(function(e) {
|
315
|
+
if(e.which == 13) {
|
316
|
+
insertLink();
|
317
|
+
insertLinkModal.foundation('reveal', 'close');
|
318
|
+
}
|
319
|
+
});
|
320
|
+
|
321
|
+
insertButton.click(insertLink);
|
322
|
+
|
323
|
+
insertLinkModal.on('shown', function() {
|
324
|
+
urlInput.focus();
|
325
|
+
});
|
326
|
+
|
327
|
+
insertLinkModal.on('hide', function() {
|
328
|
+
self.editor.currentView.element.focus();
|
329
|
+
});
|
330
|
+
|
331
|
+
toolbar.find('a[data-wysihtml5-command=createLink]').click(function() {
|
332
|
+
var activeButton = $(this).hasClass("wysihtml5-command-active");
|
333
|
+
|
334
|
+
if (!activeButton) {
|
335
|
+
self.editor.currentView.element.focus(false);
|
336
|
+
caretBookmark = self.editor.composer.selection.getBookmark();
|
337
|
+
insertLinkModal.foundation('reveal', 'open');
|
338
|
+
insertLinkModal.on('click', '.close', function(e) {
|
339
|
+
insertLinkModal.foundation('reveal', 'close')
|
340
|
+
e.preventDefault();
|
341
|
+
});
|
342
|
+
return false;
|
343
|
+
}
|
344
|
+
else {
|
345
|
+
return true;
|
346
|
+
}
|
347
|
+
});
|
348
|
+
}
|
349
|
+
};
|
350
|
+
|
351
|
+
// these define our public api
|
352
|
+
var methods = {
|
353
|
+
resetDefaults: function() {
|
354
|
+
$.fn.wysihtml5.defaultOptions = $.extend(true, {}, $.fn.wysihtml5.defaultOptionsCache);
|
355
|
+
},
|
356
|
+
bypassDefaults: function(options) {
|
357
|
+
return this.each(function () {
|
358
|
+
var $this = $(this);
|
359
|
+
$this.data('wysihtml5', new Wysihtml5($this, options));
|
360
|
+
});
|
361
|
+
},
|
362
|
+
shallowExtend: function (options) {
|
363
|
+
var settings = $.extend({}, $.fn.wysihtml5.defaultOptions, options || {}, $(this).data());
|
364
|
+
var that = this;
|
365
|
+
return methods.bypassDefaults.apply(that, [settings]);
|
366
|
+
},
|
367
|
+
deepExtend: function(options) {
|
368
|
+
var settings = $.extend(true, {}, $.fn.wysihtml5.defaultOptions, options || {});
|
369
|
+
var that = this;
|
370
|
+
return methods.bypassDefaults.apply(that, [settings]);
|
371
|
+
},
|
372
|
+
init: function(options) {
|
373
|
+
var that = this;
|
374
|
+
return methods.shallowExtend.apply(that, [options]);
|
375
|
+
}
|
376
|
+
};
|
377
|
+
|
378
|
+
$.fn.wysihtml5 = function ( method ) {
|
379
|
+
if ( methods[method] ) {
|
380
|
+
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
381
|
+
} else if ( typeof method === 'object' || ! method ) {
|
382
|
+
return methods.init.apply( this, arguments );
|
383
|
+
} else {
|
384
|
+
$.error( 'Method ' + method + ' does not exist on jQuery.wysihtml5' );
|
385
|
+
}
|
386
|
+
};
|
387
|
+
|
388
|
+
$.fn.wysihtml5.Constructor = Wysihtml5;
|
389
|
+
|
390
|
+
var defaultOptions = $.fn.wysihtml5.defaultOptions = {
|
391
|
+
"font-styles": true,
|
392
|
+
"color": false,
|
393
|
+
"emphasis": true,
|
394
|
+
"lists": true,
|
395
|
+
"html": false,
|
396
|
+
"link": true,
|
397
|
+
"image": true,
|
398
|
+
events: {},
|
399
|
+
parserRules: {
|
400
|
+
classes: {
|
401
|
+
// (path_to_project/lib/css/wysiwyg-color.css)
|
402
|
+
"wysiwyg-color-silver" : 1,
|
403
|
+
"wysiwyg-color-gray" : 1,
|
404
|
+
"wysiwyg-color-white" : 1,
|
405
|
+
"wysiwyg-color-maroon" : 1,
|
406
|
+
"wysiwyg-color-red" : 1,
|
407
|
+
"wysiwyg-color-purple" : 1,
|
408
|
+
"wysiwyg-color-fuchsia" : 1,
|
409
|
+
"wysiwyg-color-green" : 1,
|
410
|
+
"wysiwyg-color-lime" : 1,
|
411
|
+
"wysiwyg-color-olive" : 1,
|
412
|
+
"wysiwyg-color-yellow" : 1,
|
413
|
+
"wysiwyg-color-navy" : 1,
|
414
|
+
"wysiwyg-color-blue" : 1,
|
415
|
+
"wysiwyg-color-teal" : 1,
|
416
|
+
"wysiwyg-color-aqua" : 1,
|
417
|
+
"wysiwyg-color-orange" : 1
|
418
|
+
},
|
419
|
+
tags: {
|
420
|
+
"b": {},
|
421
|
+
"i": {},
|
422
|
+
"br": {},
|
423
|
+
"ol": {},
|
424
|
+
"ul": {},
|
425
|
+
"li": {},
|
426
|
+
"h1": {},
|
427
|
+
"h2": {},
|
428
|
+
"h3": {},
|
429
|
+
"h4": {},
|
430
|
+
"h5": {},
|
431
|
+
"h6": {},
|
432
|
+
"blockquote": {},
|
433
|
+
"u": 1,
|
434
|
+
"img": {
|
435
|
+
"check_attributes": {
|
436
|
+
"width": "numbers",
|
437
|
+
"alt": "alt",
|
438
|
+
"src": "url",
|
439
|
+
"height": "numbers"
|
440
|
+
}
|
441
|
+
},
|
442
|
+
"a": {
|
443
|
+
check_attributes: {
|
444
|
+
'href': "url", // important to avoid XSS
|
445
|
+
'target': 'alt',
|
446
|
+
'rel': 'alt'
|
447
|
+
}
|
448
|
+
},
|
449
|
+
"span": 1,
|
450
|
+
"div": 1,
|
451
|
+
// to allow save and edit files with code tag hacks
|
452
|
+
"code": 1,
|
453
|
+
"pre": 1
|
454
|
+
}
|
455
|
+
},
|
456
|
+
stylesheets: ["<%= stylesheet_path('foundation-wysihtml5/wysiwyg-color.css') %>"], // (path_to_project/lib/css/wysiwyg-color.css)
|
457
|
+
locale: "en"
|
458
|
+
};
|
459
|
+
|
460
|
+
if (typeof $.fn.wysihtml5.defaultOptionsCache === 'undefined') {
|
461
|
+
$.fn.wysihtml5.defaultOptionsCache = $.extend(true, {}, $.fn.wysihtml5.defaultOptions);
|
462
|
+
}
|
463
|
+
|
464
|
+
var locale = $.fn.wysihtml5.locale = {
|
465
|
+
en: {
|
466
|
+
font_styles: {
|
467
|
+
normal: "Normal text",
|
468
|
+
h1: "Heading 1",
|
469
|
+
h2: "Heading 2",
|
470
|
+
h3: "Heading 3",
|
471
|
+
h4: "Heading 4",
|
472
|
+
h5: "Heading 5",
|
473
|
+
h6: "Heading 6"
|
474
|
+
},
|
475
|
+
emphasis: {
|
476
|
+
bold: "Bold",
|
477
|
+
italic: "Italic",
|
478
|
+
underline: "Underline"
|
479
|
+
},
|
480
|
+
lists: {
|
481
|
+
unordered: "Unordered list",
|
482
|
+
ordered: "Ordered list",
|
483
|
+
outdent: "Outdent",
|
484
|
+
indent: "Indent"
|
485
|
+
},
|
486
|
+
link: {
|
487
|
+
insert: "Insert link",
|
488
|
+
cancel: "Cancel",
|
489
|
+
target: "Open link in new window"
|
490
|
+
},
|
491
|
+
image: {
|
492
|
+
insert: "Insert image",
|
493
|
+
cancel: "Cancel"
|
494
|
+
},
|
495
|
+
html: {
|
496
|
+
edit: "Edit HTML"
|
497
|
+
},
|
498
|
+
colours: {
|
499
|
+
black: "Black",
|
500
|
+
silver: "Silver",
|
501
|
+
gray: "Grey",
|
502
|
+
maroon: "Maroon",
|
503
|
+
red: "Red",
|
504
|
+
purple: "Purple",
|
505
|
+
green: "Green",
|
506
|
+
olive: "Olive",
|
507
|
+
navy: "Navy",
|
508
|
+
blue: "Blue",
|
509
|
+
orange: "Orange"
|
510
|
+
}
|
511
|
+
}
|
512
|
+
};
|
513
|
+
|
514
|
+
}(window.jQuery, window.wysihtml5);
|