simple_form_markdown_editor 0.0.10 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +70 -58
- data/app/controllers/simple_form_markdown_editor/previews_controller.rb +19 -7
- data/lib/assets/javascripts/simple_form_markdown_editor.js +1 -3
- data/lib/assets/javascripts/simple_form_markdown_editor/__buttons.coffee.erb +48 -0
- data/lib/assets/javascripts/simple_form_markdown_editor/__editor.coffee.erb +81 -0
- data/lib/assets/javascripts/simple_form_markdown_editor/__help.coffee.erb +86 -0
- data/lib/assets/javascripts/simple_form_markdown_editor/__preview.coffee.erb +42 -0
- data/lib/assets/javascripts/simple_form_markdown_editor/__tabs.coffee.erb +59 -0
- data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor.coffee.erb +98 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor.css +2 -2
- data/lib/assets/stylesheets/simple_form_markdown_editor/_partials.scss +5 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button.scss.erb +4 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button_group.scss.erb +5 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button_wrapper.scss.erb +5 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/buttons/__buttons.scss.erb +9 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/editor/__editor.scss.erb +4 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/header/__header.scss.erb +4 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help.scss.erb +12 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__section.scss.erb +3 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sections.scss.erb +5 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section.scss.erb +9 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section__item.scss.erb +7 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section__items.scss.erb +5 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_sections.scss.erb +5 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__text.scss.erb +9 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/help/__help__texts.scss.erb +5 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/preview/__preview.scss.erb +4 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/simple_form_markdown_editor.scss.erb +23 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/tabs/__tab.scss.erb +8 -0
- data/lib/assets/stylesheets/simple_form_markdown_editor/tabs/__tabs.scss.erb +9 -0
- data/lib/simple_form_markdown_editor.rb +11 -3
- data/lib/simple_form_markdown_editor/markdown_editor_input.rb +41 -53
- data/lib/simple_form_markdown_editor/version.rb +1 -1
- data/simple_form_markdown_editor.gemspec +4 -1
- metadata +72 -7
- data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_buttons.coffee.erb +0 -114
- data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_help.coffee +0 -92
- data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_tabs.coffee +0 -82
- data/lib/assets/stylesheets/simple_form_markdown_editor/simple_form_markdown_editor.css.scss +0 -274
@@ -20,9 +20,12 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'rails', '>= 4.2'
|
22
22
|
spec.add_dependency 'simple_form', '>= 3.0.2'
|
23
|
+
spec.add_dependency 'slim'
|
23
24
|
spec.add_dependency 'redcarpet'
|
24
25
|
spec.add_dependency 'responders'
|
25
26
|
|
26
27
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
27
|
-
spec.add_development_dependency '
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
29
|
+
spec.add_development_dependency 'minitest-rails'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_markdown_editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-06-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 3.0.2
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: slim
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: redcarpet
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +96,21 @@ dependencies:
|
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '1.6'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
99
|
+
name: minitest
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '5.0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '5.0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: minitest-rails
|
86
114
|
requirement: !ruby/object:Gem::Requirement
|
87
115
|
requirements:
|
88
116
|
- - ">="
|
@@ -95,6 +123,20 @@ dependencies:
|
|
95
123
|
- - ">="
|
96
124
|
- !ruby/object:Gem::Version
|
97
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rake
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '10.0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '10.0'
|
98
140
|
description: Simple Markdown editor (inspired by GitHub editor).
|
99
141
|
email:
|
100
142
|
- mail@tomascelizna.com
|
@@ -104,6 +146,7 @@ extensions: []
|
|
104
146
|
extra_rdoc_files: []
|
105
147
|
files:
|
106
148
|
- ".gitignore"
|
149
|
+
- CHANGELOG.md
|
107
150
|
- Gemfile
|
108
151
|
- Gemfile.lock
|
109
152
|
- README.md
|
@@ -111,11 +154,33 @@ files:
|
|
111
154
|
- app/controllers/simple_form_markdown_editor/previews_controller.rb
|
112
155
|
- config/routes.rb
|
113
156
|
- lib/assets/javascripts/simple_form_markdown_editor.js
|
114
|
-
- lib/assets/javascripts/simple_form_markdown_editor/
|
115
|
-
- lib/assets/javascripts/simple_form_markdown_editor/
|
116
|
-
- lib/assets/javascripts/simple_form_markdown_editor/
|
157
|
+
- lib/assets/javascripts/simple_form_markdown_editor/__buttons.coffee.erb
|
158
|
+
- lib/assets/javascripts/simple_form_markdown_editor/__editor.coffee.erb
|
159
|
+
- lib/assets/javascripts/simple_form_markdown_editor/__help.coffee.erb
|
160
|
+
- lib/assets/javascripts/simple_form_markdown_editor/__preview.coffee.erb
|
161
|
+
- lib/assets/javascripts/simple_form_markdown_editor/__tabs.coffee.erb
|
162
|
+
- lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor.coffee.erb
|
117
163
|
- lib/assets/stylesheets/simple_form_markdown_editor.css
|
118
|
-
- lib/assets/stylesheets/simple_form_markdown_editor/
|
164
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/_partials.scss
|
165
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button.scss.erb
|
166
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button_group.scss.erb
|
167
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/buttons/__button_wrapper.scss.erb
|
168
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/buttons/__buttons.scss.erb
|
169
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/editor/__editor.scss.erb
|
170
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/header/__header.scss.erb
|
171
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help.scss.erb
|
172
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help__section.scss.erb
|
173
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sections.scss.erb
|
174
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section.scss.erb
|
175
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section__item.scss.erb
|
176
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_section__items.scss.erb
|
177
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help__sub_sections.scss.erb
|
178
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help__text.scss.erb
|
179
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/help/__help__texts.scss.erb
|
180
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/preview/__preview.scss.erb
|
181
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/simple_form_markdown_editor.scss.erb
|
182
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/tabs/__tab.scss.erb
|
183
|
+
- lib/assets/stylesheets/simple_form_markdown_editor/tabs/__tabs.scss.erb
|
119
184
|
- lib/config/locales/simple_form_markdown_editor.en.yml
|
120
185
|
- lib/simple_form_markdown_editor.rb
|
121
186
|
- lib/simple_form_markdown_editor/configuration.rb
|
@@ -1,114 +0,0 @@
|
|
1
|
-
# https://github.com/jquery-boilerplate/jquery-boilerplate/
|
2
|
-
do ($ = jQuery, window, document) ->
|
3
|
-
|
4
|
-
pluginName = 'simple_form_markdown_editor_buttons'
|
5
|
-
defaults =
|
6
|
-
debug: false
|
7
|
-
definitions: JSON.parse('<%= SimpleFormMarkdownEditor::MarkdownEditorInput.configuration.button_definitions.to_json %>')
|
8
|
-
|
9
|
-
# ---------------------------------------------------------------------
|
10
|
-
|
11
|
-
class Plugin
|
12
|
-
constructor: (@element, options) ->
|
13
|
-
@settings = $.extend {}, defaults, options
|
14
|
-
|
15
|
-
@$element = $(@element)
|
16
|
-
|
17
|
-
@_defaults = defaults
|
18
|
-
@_name = pluginName
|
19
|
-
|
20
|
-
@init()
|
21
|
-
|
22
|
-
init: ->
|
23
|
-
console.log 'init' if @settings.debug
|
24
|
-
|
25
|
-
@get_help_button().addClass('active') if @help_is_visible()
|
26
|
-
|
27
|
-
@get_help_button().on 'click', (e) =>
|
28
|
-
$(e.currentTarget).toggleClass('active')
|
29
|
-
@toggle_help_visibility()
|
30
|
-
|
31
|
-
@get_command_buttons().on 'click', (e) =>
|
32
|
-
$btn = $(e.currentTarget)
|
33
|
-
cmd = $btn.attr('value')
|
34
|
-
@execute_command(cmd)
|
35
|
-
|
36
|
-
# ---------------------------------------------------------------------
|
37
|
-
|
38
|
-
get_textarea: -> @get_editor_div().children('textarea')
|
39
|
-
get_editor_div: -> @$element.children('div.editor')
|
40
|
-
get_header_div: -> @$element.children('div.header:first')
|
41
|
-
get_help_div: -> @$element.children('div.help')
|
42
|
-
get_button_groups_ul: -> @get_header_div().find('ul.button_groups')
|
43
|
-
get_button_group_lis: -> @get_button_groups_ul().children('li.button_group')
|
44
|
-
get_buttons_uls: -> @get_button_group_lis().children('ul.buttons')
|
45
|
-
get_button_lis: -> @get_buttons_uls().children('li.button')
|
46
|
-
get_buttons: -> @get_button_lis().children('button')
|
47
|
-
get_command_buttons: -> @get_buttons().not(@get_help_button())
|
48
|
-
get_help_button: -> @get_buttons().filter('.help')
|
49
|
-
|
50
|
-
help_is_visible: -> @get_help_div().attr('data-visible') == 'true'
|
51
|
-
|
52
|
-
execute_command: (cmd) ->
|
53
|
-
$textarea = @get_textarea()
|
54
|
-
selection = @get_selection($textarea)
|
55
|
-
definition = @settings.definitions[cmd]
|
56
|
-
replacement = definition.replace('%{str}', selection.text)
|
57
|
-
caret_pos = replacement.indexOf('|')
|
58
|
-
start = selection.start
|
59
|
-
end = selection.start + replacement.length
|
60
|
-
if caret_pos > -1
|
61
|
-
replacement = replacement.replace(/\|/g, '')
|
62
|
-
start = selection.start + caret_pos
|
63
|
-
end = selection.start + caret_pos
|
64
|
-
@replace_selection($textarea, replacement)
|
65
|
-
@set_selection($textarea, start, end)
|
66
|
-
|
67
|
-
get_selection: ($e) ->
|
68
|
-
{
|
69
|
-
start: $e[0].selectionStart
|
70
|
-
end: $e[0].selectionEnd
|
71
|
-
length: $e[0].selectionEnd - $e[0].selectionStart
|
72
|
-
text: $e.val().substring($e[0].selectionStart, $e[0].selectionEnd)
|
73
|
-
}
|
74
|
-
|
75
|
-
set_selection: ($e, start, end) ->
|
76
|
-
$e.focus()
|
77
|
-
$e[0].selectionStart = start
|
78
|
-
$e[0].selectionEnd = end
|
79
|
-
|
80
|
-
replace_selection: ($e, string) ->
|
81
|
-
start = $e[0].selectionStart
|
82
|
-
end = $e[0].selectionEnd
|
83
|
-
val = $e.val()
|
84
|
-
$e.val(val.substring(0, start) + string + val.substring(end, val.length))
|
85
|
-
|
86
|
-
toggle_help_visibility: ->
|
87
|
-
@get_help_div().attr('data-visible', String(!@help_is_visible()))
|
88
|
-
|
89
|
-
# ---------------------------------------------------------------------
|
90
|
-
|
91
|
-
# A really lightweight plugin wrapper around the constructor,
|
92
|
-
# preventing against multiple instantiations and allowing any
|
93
|
-
# public function (ie. a function whose name doesn't start
|
94
|
-
# with an underscore) to be called via the jQuery plugin,
|
95
|
-
# e.g. $(element).defaultPluginName('functionName', arg1, arg2)
|
96
|
-
|
97
|
-
$.fn[pluginName] = (options) ->
|
98
|
-
args = arguments
|
99
|
-
if options is `undefined` or typeof options is "object"
|
100
|
-
@each ->
|
101
|
-
$.data this, "plugin_" + pluginName, new Plugin(this, options) unless $.data(this, "plugin_" + pluginName)
|
102
|
-
|
103
|
-
else if typeof options is "string" and options[0] isnt "_" and options isnt "init"
|
104
|
-
returns = undefined
|
105
|
-
@each ->
|
106
|
-
instance = $.data(this, "plugin_" + pluginName)
|
107
|
-
returns = instance[options].apply(instance, Array::slice.call(args, 1)) if instance instanceof Plugin and typeof instance[options] is "function"
|
108
|
-
$.data this, "plugin_" + pluginName, null if options is "destroy"
|
109
|
-
|
110
|
-
(if returns isnt `undefined` then returns else this)
|
111
|
-
|
112
|
-
# =====================================================================
|
113
|
-
|
114
|
-
$ -> $('div.simple_form_markdown_editor').simple_form_markdown_editor_buttons()
|
data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_help.coffee
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# https://github.com/jquery-boilerplate/jquery-boilerplate/
|
2
|
-
do ($ = jQuery, window, document) ->
|
3
|
-
|
4
|
-
pluginName = 'simple_form_markdown_editor_help'
|
5
|
-
defaults =
|
6
|
-
debug: false
|
7
|
-
|
8
|
-
# ---------------------------------------------------------------------
|
9
|
-
|
10
|
-
class Plugin
|
11
|
-
constructor: (@element, options) ->
|
12
|
-
@settings = $.extend {}, defaults, options
|
13
|
-
|
14
|
-
@$element = $(@element)
|
15
|
-
|
16
|
-
@_defaults = defaults
|
17
|
-
@_name = pluginName
|
18
|
-
|
19
|
-
@init()
|
20
|
-
|
21
|
-
init: ->
|
22
|
-
console.log 'init' if @settings.debug
|
23
|
-
|
24
|
-
@set_section_li @get_section_lis().first()
|
25
|
-
|
26
|
-
@get_section_lis().on 'click', (e) =>
|
27
|
-
$li = $(e.currentTarget)
|
28
|
-
@set_section_li($li)
|
29
|
-
|
30
|
-
@get_sub_section_lis().on 'click', (e) =>
|
31
|
-
$li = $(e.currentTarget)
|
32
|
-
@set_sub_section_li($li)
|
33
|
-
|
34
|
-
# ---------------------------------------------------------------------
|
35
|
-
|
36
|
-
get_help_div: -> @$element.find('div.help')
|
37
|
-
get_sections_ul: -> @get_help_div().find('ul.sections')
|
38
|
-
get_section_lis: -> @get_sections_ul().children('li')
|
39
|
-
get_sub_section_ul: (section) -> @get_sub_sections_uls().filter(".#{section}")
|
40
|
-
get_sub_sections_uls: -> @get_help_div().find('ul.sub_sections')
|
41
|
-
get_sub_section_lis: -> @get_sub_sections_uls().children('li.sub_section')
|
42
|
-
get_help_text_divs: -> @get_help_div().find('div.help_text')
|
43
|
-
|
44
|
-
set_section_li: ($li) ->
|
45
|
-
$li.siblings('li').removeClass('active')
|
46
|
-
$li.addClass('active')
|
47
|
-
section = $li.data('toggle')
|
48
|
-
$sub_section_ul = @get_sub_section_ul(section)
|
49
|
-
@set_sub_section_ul($sub_section_ul)
|
50
|
-
|
51
|
-
set_sub_section_ul: ($ul) ->
|
52
|
-
$ul.siblings('ul').removeClass('active')
|
53
|
-
$ul.addClass('active')
|
54
|
-
$li = $ul.children('li:first')
|
55
|
-
@set_sub_section_li($li)
|
56
|
-
|
57
|
-
set_sub_section_li: ($li) ->
|
58
|
-
$li.siblings('li').removeClass('active')
|
59
|
-
$li.addClass('active')
|
60
|
-
$help_text_div = @get_help_text_divs().filter(".#{$li.data('toggle')}")
|
61
|
-
@set_help_text_div($help_text_div)
|
62
|
-
|
63
|
-
set_help_text_div: ($div) ->
|
64
|
-
$div.siblings('div').removeClass('active')
|
65
|
-
$div.addClass('active')
|
66
|
-
|
67
|
-
# ---------------------------------------------------------------------
|
68
|
-
|
69
|
-
# A really lightweight plugin wrapper around the constructor,
|
70
|
-
# preventing against multiple instantiations and allowing any
|
71
|
-
# public function (ie. a function whose name doesn't start
|
72
|
-
# with an underscore) to be called via the jQuery plugin,
|
73
|
-
# e.g. $(element).defaultPluginName('functionName', arg1, arg2)
|
74
|
-
|
75
|
-
$.fn[pluginName] = (options) ->
|
76
|
-
args = arguments
|
77
|
-
if options is `undefined` or typeof options is "object"
|
78
|
-
@each ->
|
79
|
-
$.data this, "plugin_" + pluginName, new Plugin(this, options) unless $.data(this, "plugin_" + pluginName)
|
80
|
-
|
81
|
-
else if typeof options is "string" and options[0] isnt "_" and options isnt "init"
|
82
|
-
returns = undefined
|
83
|
-
@each ->
|
84
|
-
instance = $.data(this, "plugin_" + pluginName)
|
85
|
-
returns = instance[options].apply(instance, Array::slice.call(args, 1)) if instance instanceof Plugin and typeof instance[options] is "function"
|
86
|
-
$.data this, "plugin_" + pluginName, null if options is "destroy"
|
87
|
-
|
88
|
-
(if returns isnt `undefined` then returns else this)
|
89
|
-
|
90
|
-
# =====================================================================
|
91
|
-
|
92
|
-
$ -> $('div.simple_form_markdown_editor').simple_form_markdown_editor_help()
|
data/lib/assets/javascripts/simple_form_markdown_editor/simple_form_markdown_editor_tabs.coffee
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# https://github.com/jquery-boilerplate/jquery-boilerplate/
|
2
|
-
do ($ = jQuery, window, document) ->
|
3
|
-
|
4
|
-
pluginName = 'simple_form_markdown_editor_tabs'
|
5
|
-
defaults =
|
6
|
-
debug: false
|
7
|
-
|
8
|
-
# ---------------------------------------------------------------------
|
9
|
-
|
10
|
-
class Plugin
|
11
|
-
constructor: (@element, options) ->
|
12
|
-
@settings = $.extend {}, defaults, options
|
13
|
-
|
14
|
-
@$element = $(@element)
|
15
|
-
|
16
|
-
@_defaults = defaults
|
17
|
-
@_name = pluginName
|
18
|
-
|
19
|
-
@init()
|
20
|
-
|
21
|
-
init: ->
|
22
|
-
console.log 'init' if @settings.debug
|
23
|
-
|
24
|
-
@get_edit_tab().addClass('active')
|
25
|
-
|
26
|
-
@get_tab_lis().on 'click', (e) =>
|
27
|
-
@get_tab_lis().removeClass('active')
|
28
|
-
$(e.currentTarget).addClass('active')
|
29
|
-
@$element.attr('data-show', $(e.currentTarget).data('command'))
|
30
|
-
|
31
|
-
@get_preview_tab().on 'click', (e) =>
|
32
|
-
$.ajax(
|
33
|
-
context: @element
|
34
|
-
type: 'POST'
|
35
|
-
url: @$element.attr('data-preview-path')
|
36
|
-
data:
|
37
|
-
_method: 'PUT'
|
38
|
-
text: @get_textarea().val() || ''
|
39
|
-
options: @get_textarea_options()
|
40
|
-
success: (html) =>
|
41
|
-
@get_preview_div().html(html) or "<p>#{@get_nothing_to_preview_text()}</p>"
|
42
|
-
)
|
43
|
-
|
44
|
-
# ---------------------------------------------------------------------
|
45
|
-
|
46
|
-
get_textarea: -> @get_editor_div().find('textarea')
|
47
|
-
get_preview_div: -> @$element.find('div.preview')
|
48
|
-
get_editor_div: -> @$element.find('div.editor')
|
49
|
-
get_header: -> @$element.find('div.header:first')
|
50
|
-
get_tabs_ul: -> @get_header().find('ul.tabs')
|
51
|
-
get_tab_lis: -> @get_tabs_ul().children('li')
|
52
|
-
get_preview_tab: -> @get_tab_lis().filter('.preview')
|
53
|
-
get_edit_tab: -> @get_tab_lis().filter('.edit')
|
54
|
-
get_nothing_to_preview_text: -> @get_preview_div().data('nothing-to-preview-text') or "Nothing to preview."
|
55
|
-
get_textarea_options: -> @$element.data('options')
|
56
|
-
|
57
|
-
# ---------------------------------------------------------------------
|
58
|
-
|
59
|
-
# A really lightweight plugin wrapper around the constructor,
|
60
|
-
# preventing against multiple instantiations and allowing any
|
61
|
-
# public function (ie. a function whose name doesn't start
|
62
|
-
# with an underscore) to be called via the jQuery plugin,
|
63
|
-
# e.g. $(element).defaultPluginName('functionName', arg1, arg2)
|
64
|
-
|
65
|
-
$.fn[pluginName] = (options) ->
|
66
|
-
args = arguments
|
67
|
-
if options is `undefined` or typeof options is "object"
|
68
|
-
@each ->
|
69
|
-
$.data this, "plugin_" + pluginName, new Plugin(this, options) unless $.data(this, "plugin_" + pluginName)
|
70
|
-
|
71
|
-
else if typeof options is "string" and options[0] isnt "_" and options isnt "init"
|
72
|
-
returns = undefined
|
73
|
-
@each ->
|
74
|
-
instance = $.data(this, "plugin_" + pluginName)
|
75
|
-
returns = instance[options].apply(instance, Array::slice.call(args, 1)) if instance instanceof Plugin and typeof instance[options] is "function"
|
76
|
-
$.data this, "plugin_" + pluginName, null if options is "destroy"
|
77
|
-
|
78
|
-
(if returns isnt `undefined` then returns else this)
|
79
|
-
|
80
|
-
# =====================================================================
|
81
|
-
|
82
|
-
$ -> $('div.simple_form_markdown_editor').simple_form_markdown_editor_tabs()
|
data/lib/assets/stylesheets/simple_form_markdown_editor/simple_form_markdown_editor.css.scss
DELETED
@@ -1,274 +0,0 @@
|
|
1
|
-
@mixin clearfix {
|
2
|
-
&:after {
|
3
|
-
content: "";
|
4
|
-
display: table;
|
5
|
-
clear: both;
|
6
|
-
}
|
7
|
-
}
|
8
|
-
|
9
|
-
@mixin reset-list {
|
10
|
-
margin: 0;
|
11
|
-
padding: 0;
|
12
|
-
list-style: none;
|
13
|
-
}
|
14
|
-
|
15
|
-
@mixin default-font {
|
16
|
-
font-family: helvetica, arial, sans-serif;
|
17
|
-
font-size: 14px;
|
18
|
-
line-height: 16px;
|
19
|
-
font-weight: normal;
|
20
|
-
font-style: normal;
|
21
|
-
letter-spacing: 0;
|
22
|
-
color: $black;
|
23
|
-
}
|
24
|
-
|
25
|
-
$grey-light: rgb(240, 240, 240);
|
26
|
-
$grey: rgb(220, 220, 220);
|
27
|
-
$grey-dark: rgb(180, 180, 180);
|
28
|
-
$white: rgb(255, 255, 255);
|
29
|
-
$black: rgb(10, 10, 10);
|
30
|
-
|
31
|
-
// ====================================================================
|
32
|
-
|
33
|
-
div.simple_form_markdown_editor {
|
34
|
-
|
35
|
-
label {
|
36
|
-
display: block;
|
37
|
-
margin-bottom: 7px;
|
38
|
-
}
|
39
|
-
|
40
|
-
// --------------------------------------------------------------------
|
41
|
-
|
42
|
-
&[data-show="preview"] {
|
43
|
-
|
44
|
-
div.buttons,
|
45
|
-
div.help,
|
46
|
-
div.editor {
|
47
|
-
display: none;
|
48
|
-
}
|
49
|
-
|
50
|
-
div.preview {
|
51
|
-
display: block;
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
div.preview {
|
56
|
-
display: none;
|
57
|
-
}
|
58
|
-
|
59
|
-
div.editor {
|
60
|
-
textarea {
|
61
|
-
@include default-font;
|
62
|
-
border: 1px solid $grey;
|
63
|
-
border-radius: 2px;
|
64
|
-
width: 100%;
|
65
|
-
margin: 0;
|
66
|
-
box-sizing: border-box;
|
67
|
-
padding: 7px;
|
68
|
-
box-shadow: inset 0 1px 2px $grey-light;
|
69
|
-
resize: vertical;
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
// --------------------------------------------------------------------
|
74
|
-
|
75
|
-
div.header {
|
76
|
-
div.editor_tabs {
|
77
|
-
background-color: $grey-light;
|
78
|
-
border: 1px solid $grey;
|
79
|
-
border-radius: 2px 2px 0 0;
|
80
|
-
margin-bottom: 16px;
|
81
|
-
|
82
|
-
ul.tabs {
|
83
|
-
@include reset-list;
|
84
|
-
padding: 8px 8px 0 8px;
|
85
|
-
margin-bottom: -1px;
|
86
|
-
|
87
|
-
li.tab {
|
88
|
-
display: inline-block;
|
89
|
-
&.active {
|
90
|
-
span {
|
91
|
-
background-color: white;
|
92
|
-
border-color: $grey;
|
93
|
-
color: $black;
|
94
|
-
}
|
95
|
-
}
|
96
|
-
span {
|
97
|
-
@include default-font;
|
98
|
-
color: $grey-dark;
|
99
|
-
display: inline-block;
|
100
|
-
border-top: 1px solid transparent;
|
101
|
-
border-left: 1px solid transparent;
|
102
|
-
border-right: 1px solid transparent;
|
103
|
-
border-radius: 2px 2px 0 0;
|
104
|
-
padding: 8px 14px;
|
105
|
-
cursor: pointer;
|
106
|
-
}
|
107
|
-
}
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
div.buttons {
|
113
|
-
ul.button_groups {
|
114
|
-
@include clearfix;
|
115
|
-
@include reset-list;
|
116
|
-
margin-bottom: 16px;
|
117
|
-
|
118
|
-
li.button_group {
|
119
|
-
color: red;
|
120
|
-
float: left;
|
121
|
-
margin-right: 8px;
|
122
|
-
|
123
|
-
&[data-buttons*='help'] {
|
124
|
-
float: right;
|
125
|
-
margin: 0;
|
126
|
-
}
|
127
|
-
|
128
|
-
ul.buttons {
|
129
|
-
@include clearfix;
|
130
|
-
@include reset-list;
|
131
|
-
|
132
|
-
li.button {
|
133
|
-
float: left;
|
134
|
-
|
135
|
-
&:first-child {
|
136
|
-
button {
|
137
|
-
border-radius: 2px 0 0 2px;
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
&:last-child {
|
142
|
-
button {
|
143
|
-
border-radius: 0 2px 2px 0;
|
144
|
-
border-right: 1px solid $grey;
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
&:first-child:last-child {
|
149
|
-
button {
|
150
|
-
border-radius: 2px;
|
151
|
-
border-right: 1px solid $grey;
|
152
|
-
}
|
153
|
-
}
|
154
|
-
|
155
|
-
button {
|
156
|
-
@include default-font;
|
157
|
-
display: inline-block;
|
158
|
-
background-color: white;
|
159
|
-
margin: 0;
|
160
|
-
padding: 0;
|
161
|
-
|
162
|
-
border: 0;
|
163
|
-
border-left: 1px solid $grey;
|
164
|
-
border-top: 1px solid $grey;
|
165
|
-
border-bottom: 1px solid $grey-dark;
|
166
|
-
|
167
|
-
padding: 4px 6px;
|
168
|
-
cursor: pointer;
|
169
|
-
|
170
|
-
&:active,
|
171
|
-
&.active {
|
172
|
-
border-color: $grey;
|
173
|
-
border-top-color: $grey-dark;
|
174
|
-
background-color: $grey-light;
|
175
|
-
}
|
176
|
-
}
|
177
|
-
}
|
178
|
-
}
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
div.help {
|
185
|
-
@include clearfix;
|
186
|
-
@include default-font;
|
187
|
-
transition: height .2s ease-in-out;
|
188
|
-
overflow: hidden;
|
189
|
-
height: 0;
|
190
|
-
box-sizing: border-box;
|
191
|
-
|
192
|
-
&[data-visible="true"] {
|
193
|
-
height: 210px;
|
194
|
-
margin-bottom: 16px;
|
195
|
-
}
|
196
|
-
|
197
|
-
div.help_wrapper {
|
198
|
-
height: 210px;
|
199
|
-
border: 1px solid $grey;
|
200
|
-
box-sizing: border-box;
|
201
|
-
> ul {
|
202
|
-
@include reset-list;
|
203
|
-
float: left;
|
204
|
-
width: 200px;
|
205
|
-
height: 100%;
|
206
|
-
border-right: 1px solid;
|
207
|
-
background-color: $grey-light;
|
208
|
-
|
209
|
-
> li {
|
210
|
-
padding: 8px 16px;
|
211
|
-
border-bottom: 1px solid $grey;
|
212
|
-
color: $grey-dark;
|
213
|
-
cursor: pointer;
|
214
|
-
|
215
|
-
&:hover {
|
216
|
-
color: $black;
|
217
|
-
}
|
218
|
-
}
|
219
|
-
}
|
220
|
-
|
221
|
-
ul.sections {
|
222
|
-
border-right-color: $grey-dark;
|
223
|
-
overflow-y: auto;
|
224
|
-
li.section {
|
225
|
-
&.active {
|
226
|
-
color: $black;
|
227
|
-
border-bottom: 1px solid $grey-dark;
|
228
|
-
background-color: $white;
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
ul.sub_sections {
|
234
|
-
border-right-color: $grey;
|
235
|
-
display: none;
|
236
|
-
overflow-y: auto;
|
237
|
-
&.active {
|
238
|
-
display: block;
|
239
|
-
}
|
240
|
-
li.sub_section {
|
241
|
-
background-color: $white;
|
242
|
-
&.active {
|
243
|
-
color: $black;
|
244
|
-
}
|
245
|
-
}
|
246
|
-
}
|
247
|
-
|
248
|
-
div.help_text {
|
249
|
-
padding: 8px 16px;
|
250
|
-
height: 100%;
|
251
|
-
box-sizing: border-box;
|
252
|
-
overflow-y: auto;
|
253
|
-
display: none;
|
254
|
-
|
255
|
-
p {
|
256
|
-
margin-top: 0;
|
257
|
-
}
|
258
|
-
|
259
|
-
code {
|
260
|
-
padding: 2px 3px;
|
261
|
-
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
262
|
-
font-size: 13px;
|
263
|
-
background-color: $grey-light;
|
264
|
-
border-radius: 2px;
|
265
|
-
white-space: nowrap
|
266
|
-
}
|
267
|
-
|
268
|
-
&.active {
|
269
|
-
display: block;
|
270
|
-
}
|
271
|
-
}
|
272
|
-
}
|
273
|
-
}
|
274
|
-
}
|