bootsy 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +37 -27
  4. data/Rakefile +1 -6
  5. data/app/assets/javascripts/bootsy.js +8 -7
  6. data/app/assets/javascripts/bootsy/area.js +91 -0
  7. data/app/assets/javascripts/bootsy/editor_options.js +8 -53
  8. data/app/assets/javascripts/bootsy/image_template.js.erb +45 -0
  9. data/app/assets/javascripts/bootsy/locales/en.js +59 -0
  10. data/app/assets/javascripts/bootsy/locales/pt-BR.js +59 -0
  11. data/app/assets/javascripts/bootsy/modal.js +167 -0
  12. data/app/assets/javascripts/bootsy/{bootstrap.file-input.js → vendor/bootstrap.file-input.js} +0 -0
  13. data/app/assets/javascripts/bootsy/vendor/bootstrap3-wysihtml5.all.js +14975 -0
  14. data/app/assets/javascripts/bootsy/{polyfill.js → vendor/polyfill.js} +0 -0
  15. data/app/assets/stylesheets/bootsy.css +14 -0
  16. data/app/helpers/bootsy/application_helper.rb +0 -6
  17. data/app/views/bootsy/images/_image.html.erb +3 -1
  18. data/config/locales/bootsy.en.yml +0 -2
  19. data/config/locales/bootsy.pt-BR.yml +0 -2
  20. data/lib/bootsy.rb +5 -4
  21. data/lib/bootsy/form_helper.rb +23 -17
  22. data/lib/bootsy/version.rb +1 -1
  23. data/lib/generators/bootsy/templates/bootsy.rb +5 -4
  24. metadata +14 -17
  25. data/app/assets/javascripts/bootsy/bootstrap-wysihtml5.js +0 -530
  26. data/app/assets/javascripts/bootsy/bootsy.js +0 -320
  27. data/app/assets/javascripts/bootsy/locales/bootstrap-wysihtml5.pt-BR.js +0 -50
  28. data/app/assets/javascripts/bootsy/locales/bootsy.pt-BR.js +0 -9
  29. data/app/assets/javascripts/bootsy/translations.js +0 -8
  30. data/app/assets/javascripts/bootsy/wysihtml5.js +0 -9565
  31. data/app/views/bootsy/images/_modal.html.erb +0 -30
  32. data/config/cucumber.yml +0 -8
  33. data/lib/tasks/cucumber.rake +0 -65
@@ -157,6 +157,20 @@ ul.wysihtml5-toolbar div[data-wysihtml5-command-value="orange"] {
157
157
  background: orange !important;
158
158
  }
159
159
 
160
+ .glyphicon-quote:before {
161
+ content: "\201C";
162
+ font-family: Georgia, serif;
163
+ font-size: 50px;
164
+ position: absolute;
165
+ top: -4px;
166
+ left: -3px;
167
+ max-height: 100%;
168
+ }
169
+
170
+ .glyphicon-quote:after {
171
+ content: "\0000a0";
172
+ }
173
+
160
174
  /*
161
175
  Bootsy
162
176
  */
@@ -1,11 +1,5 @@
1
1
  module Bootsy
2
2
  module ApplicationHelper
3
- def refresh_btn
4
- link_to t('bootsy.action.refresh'),
5
- '#refresh-gallery',
6
- class: 'btn btn-default btn-sm refresh-btn'
7
- end
8
-
9
3
  def resource_or_nil(resource)
10
4
  resource if resource.present? && resource.persisted?
11
5
  end
@@ -16,8 +16,10 @@
16
16
  <ul class="dropdown-menu" role="menu">
17
17
  <% [:left, :right, :inline].each do |position| %>
18
18
  <li role="presentation">
19
+ <% file = image.image_file %>
20
+ <% file = image.image_file.versions[size] if size != :original %>
19
21
  <%= link_to '#', class: 'insert', tabindex: '-1', role: 'menuitem',
20
- data: { image_size: size.to_s, position: position.to_s} do %>
22
+ data: { src: file.url, class_name: "wysiwyg-float-#{position}", wysihtml5_dialog_action: 'save' } do %>
21
23
  <%= t position, scope: 'bootsy.image.position' %>
22
24
  <% end %>
23
25
  </li>
@@ -1,7 +1,6 @@
1
1
  en:
2
2
  bootsy:
3
3
  action:
4
- refresh: Refresh
5
4
  destroy: Delete
6
5
  close: Close
7
6
  load: Load
@@ -25,6 +24,5 @@ en:
25
24
  left: Left
26
25
  right: Right
27
26
  inline: Inline
28
- no_images_uploaded: There are currently no uploaded images.
29
27
  js:
30
28
  alert_unsaved: You have unsaved changes.
@@ -1,7 +1,6 @@
1
1
  pt-BR:
2
2
  bootsy:
3
3
  action:
4
- refresh: Atualizar
5
4
  destroy: Apagar
6
5
  close: Fechar
7
6
  load: Carregar
@@ -25,6 +24,5 @@ pt-BR:
25
24
  left: Esquerda
26
25
  right: Direita
27
26
  inline: Mesma linha
28
- no_images_uploaded: Não existem imagens salvas.
29
27
  js:
30
28
  alert_unsaved: As suas modificações ainda não foram gravadas.
@@ -15,13 +15,14 @@ module Bootsy
15
15
  # Default editor options
16
16
  mattr_accessor :editor_options
17
17
  @@editor_options = {
18
- font_styles: true,
18
+ blockquote: true,
19
+ color: true,
19
20
  emphasis: true,
20
- lists: true,
21
+ font_styles: true,
21
22
  html: false,
22
- link: true,
23
23
  image: true,
24
- color: true
24
+ link: true,
25
+ lists: true
25
26
  }
26
27
 
27
28
  # Image versions available
@@ -28,23 +28,10 @@ module Bootsy
28
28
  def bootsy_area(object_name, method, options = {})
29
29
  container = options[:container] || options[:object]
30
30
 
31
- output = text_area(object_name, method, text_area_options(options))
31
+ set_gallery_id(container, options)
32
32
 
33
- if output.present? && enable_uploader?(options)
34
- container.bootsy_image_gallery_id ||= Bootsy::ImageGallery.create!.id
35
-
36
- output += render('bootsy/images/modal', container: container)
37
-
38
- if container.new_record?
39
- output += hidden_field(
40
- object_name,
41
- :bootsy_image_gallery_id,
42
- class: 'bootsy_image_gallery_id'
43
- )
44
- end
45
- end
46
-
47
- output
33
+ text_area(object_name, method, text_area_options(options)) +
34
+ gallery_id_param(object_name, container, options)
48
35
  end
49
36
 
50
37
  private
@@ -75,7 +62,7 @@ module Bootsy
75
62
  end
76
63
 
77
64
  def data_options(options)
78
- (options[:data] || {}).merge(
65
+ (options[:data] || {}).deep_merge(
79
66
  Hash[bootsy_options(options).map do |key, value|
80
67
  ["bootsy-#{key}", value]
81
68
  end]
@@ -98,5 +85,24 @@ module Bootsy
98
85
  class: tag_class(options)
99
86
  )
100
87
  end
88
+
89
+ def set_gallery_id(container, options)
90
+ return unless enable_uploader?(options)
91
+
92
+ container.bootsy_image_gallery_id ||= Bootsy::ImageGallery.create!.id
93
+ options.deep_merge!(
94
+ data: { gallery_id: container.bootsy_image_gallery_id }
95
+ )
96
+ end
97
+
98
+ def gallery_id_param(object_name, container, options)
99
+ return unless enable_uploader?(options) && container.new_record?
100
+
101
+ hidden_field(
102
+ object_name,
103
+ :bootsy_image_gallery_id,
104
+ class: 'bootsy_image_gallery_id'
105
+ )
106
+ end
101
107
  end
102
108
  end
@@ -1,4 +1,4 @@
1
1
  # Public: The gem version
2
2
  module Bootsy
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.0'
4
4
  end
@@ -4,13 +4,14 @@ Bootsy.setup do |config|
4
4
  # You can also override them locally by passing an
5
5
  # editor_options hash to bootsy_area
6
6
  # config.editor_options = {
7
- # font_styles: true,
7
+ # blockquote: true,
8
+ # color: true,
8
9
  # emphasis: true,
9
- # lists: true,
10
+ # font_styles: true,
10
11
  # html: false,
11
- # link: true,
12
12
  # image: true,
13
- # color: true
13
+ # link: true,
14
+ # lists: true
14
15
  # }
15
16
  #
16
17
  # Image versions available
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volmer Soares
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '4.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '4.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: carrierwave
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '1.2'
55
55
  description: A beautiful WYSIWYG editor with image uploads for Rails.
56
56
  email:
57
- - volmerius@gmail.com
57
+ - volmer@radicaos.com
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
@@ -65,25 +65,23 @@ files:
65
65
  - app/assets/images/bootsy/gallery-loader.gif
66
66
  - app/assets/images/bootsy/upload-loader.gif
67
67
  - app/assets/javascripts/bootsy.js
68
- - app/assets/javascripts/bootsy/bootstrap-wysihtml5.js
69
- - app/assets/javascripts/bootsy/bootstrap.file-input.js
70
- - app/assets/javascripts/bootsy/bootsy.js
68
+ - app/assets/javascripts/bootsy/area.js
71
69
  - app/assets/javascripts/bootsy/editor_options.js
70
+ - app/assets/javascripts/bootsy/image_template.js.erb
72
71
  - app/assets/javascripts/bootsy/init.js
73
- - app/assets/javascripts/bootsy/locales/bootstrap-wysihtml5.pt-BR.js
74
- - app/assets/javascripts/bootsy/locales/bootsy.pt-BR.js
75
- - app/assets/javascripts/bootsy/polyfill.js
76
- - app/assets/javascripts/bootsy/translations.js
77
- - app/assets/javascripts/bootsy/wysihtml5.js
72
+ - app/assets/javascripts/bootsy/locales/en.js
73
+ - app/assets/javascripts/bootsy/locales/pt-BR.js
74
+ - app/assets/javascripts/bootsy/modal.js
75
+ - app/assets/javascripts/bootsy/vendor/bootstrap.file-input.js
76
+ - app/assets/javascripts/bootsy/vendor/bootstrap3-wysihtml5.all.js
77
+ - app/assets/javascripts/bootsy/vendor/polyfill.js
78
78
  - app/assets/stylesheets/bootsy.css
79
79
  - app/controllers/bootsy/application_controller.rb
80
80
  - app/controllers/bootsy/images_controller.rb
81
81
  - app/helpers/bootsy/application_helper.rb
82
82
  - app/uploaders/bootsy/image_uploader.rb
83
83
  - app/views/bootsy/images/_image.html.erb
84
- - app/views/bootsy/images/_modal.html.erb
85
84
  - app/views/bootsy/images/_new.html.erb
86
- - config/cucumber.yml
87
85
  - config/locales/bootsy.en.yml
88
86
  - config/locales/bootsy.pt-BR.yml
89
87
  - config/routes.rb
@@ -103,7 +101,6 @@ files:
103
101
  - lib/generators/bootsy/install_generator.rb
104
102
  - lib/generators/bootsy/templates/bootsy.rb
105
103
  - lib/tasks/bootsy_tasks.rake
106
- - lib/tasks/cucumber.rake
107
104
  homepage: http://github.com/volmer/bootsy
108
105
  licenses:
109
106
  - MIT
@@ -124,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
121
  version: '0'
125
122
  requirements: []
126
123
  rubyforge_project:
127
- rubygems_version: 2.4.5
124
+ rubygems_version: 2.5.0
128
125
  signing_key:
129
126
  specification_version: 4
130
127
  summary: A beautiful WYSIWYG editor with image uploads for Rails.
@@ -1,530 +0,0 @@
1
- !function($, wysi) {
2
- "use strict";
3
-
4
- var tpl = {
5
- "font-styles": function(locale, options) {
6
- var size = (options && options.size) ? ' btn-'+options.size : '';
7
- return "<li class='dropdown'>" +
8
- "<a class='btn btn-default dropdown-toggle" + size + "' data-toggle='dropdown' href='#' title='" + locale.font_styles.title + "'>" +
9
- "<i class='glyphicon glyphicon-font'></i>&nbsp;<span class='current-font'>" + locale.font_styles.normal + "</span>&nbsp;<b class='caret'></b>" +
10
- "</a>" +
11
- "<ul class='dropdown-menu'>" +
12
- "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='div' tabindex='-1' role='menuitem'>" + locale.font_styles.normal + "</a></li>" +
13
- "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h1' tabindex='-1' role='menuitem'>" + locale.font_styles.h1 + "</a></li>" +
14
- "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h2' tabindex='-1' role='menuitem'>" + locale.font_styles.h2 + "</a></li>" +
15
- "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h3' tabindex='-1' role='menuitem'>" + locale.font_styles.h3 + "</a></li>" +
16
- "</ul>" +
17
- "</li>";
18
- },
19
-
20
- "emphasis": function(locale, options) {
21
- var size = (options && options.size) ? ' btn-'+options.size : '';
22
- return "<li>" +
23
- "<div class='btn-group'>" +
24
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='bold' title='CTRL+B' tabindex='-1'>" + locale.emphasis.bold + "</a>" +
25
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='italic' title='CTRL+I' tabindex='-1'>" + locale.emphasis.italic + "</a>" +
26
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='underline' title='CTRL+U' tabindex='-1'>" + locale.emphasis.underline + "</a>" +
27
- "</div>" +
28
- "</li>";
29
- },
30
-
31
- "lists": function(locale, options) {
32
- var size = (options && options.size) ? ' btn-'+options.size : '';
33
- return "<li>" +
34
- "<div class='btn-group'>" +
35
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='insertUnorderedList' title='" + locale.lists.unordered + "' tabindex='-1'><i class='glyphicon glyphicon-list'></i></a>" +
36
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='insertOrderedList' title='" + locale.lists.ordered + "' tabindex='-1'><i class='glyphicon glyphicon-th-list'></i></a>" +
37
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='Outdent' title='" + locale.lists.outdent + "' tabindex='-1'><i class='glyphicon glyphicon-indent-left'></i></a>" +
38
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='Indent' title='" + locale.lists.indent + "' tabindex='-1'><i class='glyphicon glyphicon-indent-right'></i></a>" +
39
- "</div>" +
40
- "</li>";
41
- },
42
-
43
- "link": function(locale, options) {
44
- var size = (options && options.size) ? ' btn-'+options.size : '';
45
- return "<li>" +
46
- "<div class='bootstrap-wysihtml5-insert-link-modal modal fade' tabindex='-1' role='dialog' aria-hidden='true'>" +
47
- "<div class='modal-dialog'>" +
48
- "<div class='modal-content'>" +
49
- "<div class='modal-header'>" +
50
- "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>" +
51
- "<h3 class='modal-title'>" + locale.link.insert + "</h3>" +
52
- "</div>" +
53
- "<div class='modal-body'>" +
54
- "<input value='http://' class='bootstrap-wysihtml5-insert-link-url form-control input-lg'>" +
55
- "</div>" +
56
- "<div class='modal-footer'>" +
57
- "<a href='#' class='btn btn-default' data-dismiss='modal'>" + locale.link.cancel + "</a>" +
58
- "<a href='#' class='btn btn-primary' data-dismiss='modal'>" + locale.link.insert + "</a>" +
59
- "</div>" +
60
- "</div>" +
61
- "</div>" +
62
- "</div>" +
63
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='createLink' title='" + locale.link.insert + "' tabindex='-1'><i class='glyphicon glyphicon-share'></i></a>" +
64
- "</li>";
65
- },
66
-
67
- "image": function(locale, options) {
68
- var size = (options && options.size) ? ' btn-'+options.size : '';
69
- return "<li>" +
70
- "<div class='bootstrap-wysihtml5-insert-image-modal modal fade' tabindex='-1' role='dialog' aria-hidden='true'>" +
71
- "<div class='modal-dialog'>" +
72
- "<div class='modal-content'>" +
73
- "<div class='modal-header'>" +
74
- "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>" +
75
- "<h3 class='modal-title'>" + locale.image.insert + "</h3>" +
76
- "</div>" +
77
- "<div class='modal-body'>" +
78
- "<input value='http://' class='bootstrap-wysihtml5-insert-image-url form-control input-lg'>" +
79
- "</div>" +
80
- "<div class='modal-footer'>" +
81
- "<a href='#' class='btn btn-default ' data-dismiss='modal'>" + locale.image.cancel + "</a>" +
82
- "<a href='#' class='btn btn-primary' data-dismiss='modal'>" + locale.image.insert + "</a>" +
83
- "</div>" +
84
- "</div>" +
85
- "</div>" +
86
- "</div>" +
87
- "<a class='btn btn-default " + size + "' data-wysihtml5-command='insertImage' title='" + locale.image.insert + "' tabindex='-1'><i class='glyphicon glyphicon-picture'></i></a>" +
88
- "</li>";
89
- },
90
-
91
- "html": function(locale, options) {
92
- var size = (options && options.size) ? ' btn-'+options.size : '';
93
- return "<li>" +
94
- "<div class='btn-group'>" +
95
- "<a class='btn btn-default " + size + "' data-wysihtml5-action='change_view' title='" + locale.html.edit + "' tabindex='-1'><i class='glyphicon glyphicon-pencil'></i></a>" +
96
- "</div>" +
97
- "</li>";
98
- },
99
-
100
- "color": function(locale, options) {
101
- var size = (options && options.size) ? ' btn-'+options.size : '';
102
- return "<li class='dropdown'>" +
103
- "<a class='btn btn-default dropdown-toggle" + size + "' data-toggle='dropdown' href='#' tabindex='-1' title='" + locale.colours.title + "'>" +
104
- "<span class='current-color'>" + locale.colours.black + "</span>&nbsp;<b class='caret'></b>" +
105
- "</a>" +
106
- "<ul class='dropdown-menu'>" +
107
- "<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' role='menuitem'>" + locale.colours.black + "</a></li>" +
108
- "<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' role='menuitem'>" + locale.colours.silver + "</a></li>" +
109
- "<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' role='menuitem'>" + locale.colours.gray + "</a></li>" +
110
- "<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' role='menuitem'>" + locale.colours.maroon + "</a></li>" +
111
- "<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' role='menuitem'>" + locale.colours.red + "</a></li>" +
112
- "<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' role='menuitem'>" + locale.colours.purple + "</a></li>" +
113
- "<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' role='menuitem'>" + locale.colours.green + "</a></li>" +
114
- "<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' role='menuitem'>" + locale.colours.olive + "</a></li>" +
115
- "<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' role='menuitem'>" + locale.colours.navy + "</a></li>" +
116
- "<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' role='menuitem'>" + locale.colours.blue + "</a></li>" +
117
- "<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' role='menuitem'>" + locale.colours.orange + "</a></li>" +
118
- "</ul>" +
119
- "</li>";
120
- }
121
- };
122
-
123
- var templates = function(key, locale, options) {
124
- return tpl[key](locale, options);
125
- };
126
-
127
-
128
- var Wysihtml5 = function(el, options) {
129
- this.el = el;
130
- var toolbarOpts = options || defaultOptions;
131
- for(var t in toolbarOpts.customTemplates) {
132
- tpl[t] = toolbarOpts.customTemplates[t];
133
- }
134
- this.toolbar = this.createToolbar(el, toolbarOpts);
135
- this.editor = this.createEditor(options);
136
-
137
- window.editor = this.editor;
138
-
139
- $('iframe.wysihtml5-sandbox').each(function(i, el){
140
- $(el.contentWindow).off('focus.wysihtml5').on({
141
- 'focus.wysihtml5' : function(){
142
- $('li.dropdown').removeClass('open');
143
- }
144
- });
145
- });
146
- };
147
-
148
- Wysihtml5.prototype = {
149
-
150
- constructor: Wysihtml5,
151
-
152
- createEditor: function(options) {
153
- options = options || {};
154
-
155
- // Add the toolbar to a clone of the options object so multiple instances
156
- // of the WYISYWG don't break because "toolbar" is already defined
157
- options = $.extend(true, {}, options);
158
- options.toolbar = this.toolbar[0];
159
-
160
- var editor = new wysi.Editor(this.el[0], options);
161
-
162
- if(options && options.events) {
163
- for(var eventName in options.events) {
164
- editor.on(eventName, options.events[eventName]);
165
- }
166
- }
167
- return editor;
168
- },
169
-
170
- createToolbar: function(el, options) {
171
- var self = this;
172
- var toolbar = $("<ul/>", {
173
- 'class' : "wysihtml5-toolbar",
174
- 'style': "display:none"
175
- });
176
- var culture = options.locale || defaultOptions.locale || "en";
177
- for(var key in defaultOptions) {
178
- var value = false;
179
-
180
- if(options[key] !== undefined) {
181
- if(options[key] === true) {
182
- value = true;
183
- }
184
- } else {
185
- value = defaultOptions[key];
186
- }
187
-
188
- if(value === true) {
189
- toolbar.append(templates(key, locale[culture], options));
190
-
191
- if(key === "html") {
192
- this.initHtml(toolbar);
193
- }
194
-
195
- if(key === "link") {
196
- this.initInsertLink(toolbar);
197
- }
198
-
199
- if(key === "image") {
200
- this.initInsertImage(toolbar);
201
- }
202
-
203
- if(key == "customCommand") {
204
- this.initCustomCommand(toolbar, options.customCommandCallback);
205
- }
206
- }
207
- }
208
-
209
- if(options.toolbar) {
210
- for(key in options.toolbar) {
211
- toolbar.append(options.toolbar[key]);
212
- }
213
- }
214
-
215
- toolbar.find("a[data-wysihtml5-command='formatBlock']").click(function(e) {
216
- var target = e.target || e.srcElement;
217
- var el = $(target);
218
- self.toolbar.find('.current-font').text(el.html());
219
- });
220
-
221
- toolbar.find("a[data-wysihtml5-command='foreColor']").click(function(e) {
222
- var target = e.target || e.srcElement;
223
- var el = $(target);
224
- self.toolbar.find('.current-color').text(el.html());
225
- });
226
-
227
- this.el.before(toolbar);
228
-
229
- return toolbar;
230
- },
231
-
232
- initHtml: function(toolbar) {
233
- var changeViewSelector = "a[data-wysihtml5-action='change_view']";
234
- toolbar.find(changeViewSelector).click(function(e) {
235
- toolbar.find('a.btn').not(changeViewSelector).toggleClass('disabled');
236
- });
237
- },
238
-
239
- initInsertImage: function(toolbar) {
240
- var self = this;
241
- var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal');
242
- var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url');
243
- var insertButton = insertImageModal.find('a.btn-primary');
244
- var initialValue = urlInput.val();
245
- var caretBookmark;
246
-
247
- var insertImage = function() {
248
- var url = urlInput.val();
249
- urlInput.val(initialValue);
250
- self.editor.currentView.element.focus();
251
- if (caretBookmark) {
252
- self.editor.composer.selection.setBookmark(caretBookmark);
253
- caretBookmark = null;
254
- }
255
- self.editor.composer.commands.exec("insertImage", url);
256
- };
257
-
258
- urlInput.keypress(function(e) {
259
- if(e.which == 13) {
260
- insertImage();
261
- insertImageModal.modal('hide');
262
- }
263
- });
264
-
265
- insertButton.click(insertImage);
266
-
267
- insertImageModal.on('shown', function() {
268
- urlInput.focus();
269
- });
270
-
271
- insertImageModal.on('hide', function() {
272
- self.editor.currentView.element.focus();
273
- });
274
-
275
- toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() {
276
- var activeButton = $(this).hasClass("wysihtml5-command-active");
277
-
278
- if (!activeButton) {
279
- self.editor.currentView.element.focus(false);
280
- caretBookmark = self.editor.composer.selection.getBookmark();
281
- insertImageModal.appendTo('body').modal('show');
282
- insertImageModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {
283
- e.stopPropagation();
284
- });
285
- return false;
286
- }
287
- else {
288
- return true;
289
- }
290
- });
291
- },
292
-
293
- initCustomCommand: function(toolbar, callback) {
294
- var self = this;
295
-
296
- toolbar.find('a[data-wysihtml5-command=customCommand]').click(function() {
297
- var activeButton = $(this).hasClass("wysihtml5-command-active");
298
-
299
- if (!activeButton) {
300
- callback(self.editor);
301
- return false;
302
- }
303
- else {
304
- return true;
305
- }
306
- });
307
- },
308
-
309
- initInsertLink: function(toolbar) {
310
- var self = this;
311
- var insertLinkModal = toolbar.find('.bootstrap-wysihtml5-insert-link-modal');
312
- var urlInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-url');
313
- var insertButton = insertLinkModal.find('a.btn-primary');
314
- var initialValue = urlInput.val();
315
- var caretBookmark;
316
-
317
- var insertLink = function() {
318
- var url = urlInput.val();
319
- urlInput.val(initialValue);
320
- self.editor.currentView.element.focus();
321
- if (caretBookmark) {
322
- self.editor.composer.selection.setBookmark(caretBookmark);
323
- caretBookmark = null;
324
- }
325
- self.editor.composer.commands.exec("createLink", {
326
- href: url,
327
- target: "_blank",
328
- rel: "nofollow"
329
- });
330
- };
331
- var pressedEnter = false;
332
-
333
- urlInput.keypress(function(e) {
334
- if(e.which == 13) {
335
- insertLink();
336
- insertLinkModal.modal('hide');
337
- }
338
- });
339
-
340
- insertButton.click(insertLink);
341
-
342
- insertLinkModal.on('shown', function() {
343
- urlInput.focus();
344
- });
345
-
346
- insertLinkModal.on('hide', function() {
347
- self.editor.currentView.element.focus();
348
- });
349
-
350
- toolbar.find('a[data-wysihtml5-command=createLink]').click(function() {
351
- var activeButton = $(this).hasClass("wysihtml5-command-active");
352
-
353
- if (!activeButton) {
354
- self.editor.currentView.element.focus(false);
355
- caretBookmark = self.editor.composer.selection.getBookmark();
356
- insertLinkModal.appendTo('body').modal('show');
357
- insertLinkModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {
358
- e.stopPropagation();
359
- });
360
- return false;
361
- }
362
- else {
363
- return true;
364
- }
365
- });
366
- }
367
- };
368
-
369
- // these define our public api
370
- var methods = {
371
- resetDefaults: function() {
372
- $.fn.wysihtml5.defaultOptions = $.extend(true, {}, $.fn.wysihtml5.defaultOptionsCache);
373
- },
374
- bypassDefaults: function(options) {
375
- return this.each(function () {
376
- var $this = $(this);
377
- $this.data('wysihtml5', new Wysihtml5($this, options));
378
- });
379
- },
380
- shallowExtend: function (options) {
381
- var settings = $.extend({}, $.fn.wysihtml5.defaultOptions, options || {});
382
- var that = this;
383
- return methods.bypassDefaults.apply(that, [settings]);
384
- },
385
- deepExtend: function(options) {
386
- var settings = $.extend(true, {}, $.fn.wysihtml5.defaultOptions, options || {});
387
- var that = this;
388
- return methods.bypassDefaults.apply(that, [settings]);
389
- },
390
- init: function(options) {
391
- var that = this;
392
- return methods.shallowExtend.apply(that, [options]);
393
- }
394
- };
395
-
396
- $.fn.wysihtml5 = function ( method ) {
397
- if ( methods[method] ) {
398
- return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
399
- } else if ( typeof method === 'object' || ! method ) {
400
- return methods.init.apply( this, arguments );
401
- } else {
402
- $.error( 'Method ' + method + ' does not exist on jQuery.wysihtml5' );
403
- }
404
- };
405
-
406
- $.fn.wysihtml5.Constructor = Wysihtml5;
407
-
408
- var defaultOptions = $.fn.wysihtml5.defaultOptions = {
409
- "font-styles": true,
410
- "color": false,
411
- "emphasis": true,
412
- "lists": true,
413
- "html": false,
414
- "link": true,
415
- "image": true,
416
- customCommand: false,
417
- events: {},
418
- parserRules: {
419
- classes: {
420
- // (path_to_project/lib/css/wysiwyg-color.css)
421
- "wysiwyg-color-silver" : 1,
422
- "wysiwyg-color-gray" : 1,
423
- "wysiwyg-color-white" : 1,
424
- "wysiwyg-color-maroon" : 1,
425
- "wysiwyg-color-red" : 1,
426
- "wysiwyg-color-purple" : 1,
427
- "wysiwyg-color-fuchsia" : 1,
428
- "wysiwyg-color-green" : 1,
429
- "wysiwyg-color-lime" : 1,
430
- "wysiwyg-color-olive" : 1,
431
- "wysiwyg-color-yellow" : 1,
432
- "wysiwyg-color-navy" : 1,
433
- "wysiwyg-color-blue" : 1,
434
- "wysiwyg-color-teal" : 1,
435
- "wysiwyg-color-aqua" : 1,
436
- "wysiwyg-color-orange" : 1
437
- },
438
- tags: {
439
- "b": {},
440
- "i": {},
441
- "br": {},
442
- "ol": {},
443
- "ul": {},
444
- "li": {},
445
- "h1": {},
446
- "h2": {},
447
- "h3": {},
448
- "blockquote": {},
449
- "u": 1,
450
- "img": {
451
- "check_attributes": {
452
- "width": "numbers",
453
- "alt": "alt",
454
- "src": "url",
455
- "height": "numbers"
456
- }
457
- },
458
- "a": {
459
- set_attributes: {
460
- target: "_blank",
461
- rel: "nofollow"
462
- },
463
- check_attributes: {
464
- href: "url" // important to avoid XSS
465
- }
466
- },
467
- "span": 1,
468
- "div": 1,
469
- // to allow save and edit files with code tag hacks
470
- "code": 1,
471
- "pre": 1
472
- }
473
- },
474
- stylesheets: ["./lib/css/wysiwyg-color.css"], // (path_to_project/lib/css/wysiwyg-color.css)
475
- locale: "en"
476
- };
477
-
478
- if (typeof $.fn.wysihtml5.defaultOptionsCache === 'undefined') {
479
- $.fn.wysihtml5.defaultOptionsCache = $.extend(true, {}, $.fn.wysihtml5.defaultOptions);
480
- }
481
-
482
- var locale = $.fn.wysihtml5.locale = {
483
- en: {
484
- font_styles: {
485
- title: "Font style",
486
- normal: "Normal text",
487
- h1: "Heading 1",
488
- h2: "Heading 2",
489
- h3: "Heading 3"
490
- },
491
- emphasis: {
492
- bold: "Bold",
493
- italic: "Italic",
494
- underline: "Underline"
495
- },
496
- lists: {
497
- unordered: "Unordered list",
498
- ordered: "Ordered list",
499
- outdent: "Outdent",
500
- indent: "Indent"
501
- },
502
- link: {
503
- insert: "Insert link",
504
- cancel: "Cancel"
505
- },
506
- image: {
507
- insert: "Insert image",
508
- cancel: "Cancel"
509
- },
510
- html: {
511
- edit: "Edit HTML"
512
- },
513
- colours: {
514
- title: "Text color",
515
- black: "Black",
516
- silver: "Silver",
517
- gray: "Grey",
518
- maroon: "Maroon",
519
- red: "Red",
520
- purple: "Purple",
521
- green: "Green",
522
- olive: "Olive",
523
- navy: "Navy",
524
- blue: "Blue",
525
- orange: "Orange"
526
- }
527
- }
528
- };
529
-
530
- }(window.jQuery, window.wysihtml5);