caseadilla 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.svg +228 -228
- data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/images/caseadilla/caseadilla.png +0 -0
- data/app/assets/javascripts/caseadilla/bootstrap.js +2114 -2114
- data/app/assets/javascripts/caseadilla/bootstrap3-wysihtml5.js +520 -520
- data/app/assets/javascripts/caseadilla/caseadilla.js +50 -50
- data/app/assets/javascripts/caseadilla/html5shiv.js +8 -8
- data/app/assets/javascripts/caseadilla/wysihtml5-0.3.0.min.js +260 -260
- data/app/assets/stylesheets/caseadilla/bootstrap-glyphicons.css.scss +2 -2
- data/app/assets/stylesheets/caseadilla/bootstrap-theme.css +442 -442
- data/app/assets/stylesheets/caseadilla/bootstrap-wysihtml5.css +101 -101
- data/app/assets/stylesheets/caseadilla/bootstrap.css +6203 -6203
- data/app/assets/stylesheets/caseadilla/caseadilla-bootstrap-overrides.css.scss +79 -79
- data/app/assets/stylesheets/caseadilla/caseadilla.scss +269 -269
- data/app/assets/stylesheets/caseadilla/login.css.scss +80 -80
- data/app/controllers/caseadilla/caseadilla_controller.rb +56 -56
- data/app/controllers/caseadilla/caseadilla_user_sessions_controller.rb +35 -35
- data/app/controllers/caseadilla/password_resets_controller.rb +63 -63
- data/app/controllers/caseadilla/roles_controller.rb +64 -64
- data/app/controllers/caseadilla/users_controller.rb +117 -117
- data/app/helpers/caseadilla/caseadilla_helper.rb +261 -261
- data/app/mailers/caseadilla/caseadilla_notification.rb +38 -38
- data/app/views/caseadilla/caseadilla/blank.html.erb +11 -11
- data/app/views/caseadilla/caseadilla_notification/generate_new_password.erb +11 -11
- data/app/views/caseadilla/caseadilla_notification/new_user_information.erb +11 -11
- data/app/views/caseadilla/caseadilla_notification/password_reset_instructions.erb +10 -10
- data/app/views/caseadilla/caseadilla_user_sessions/new.html.erb +38 -38
- data/app/views/caseadilla/roles/_form.html.erb +11 -11
- data/app/views/caseadilla/roles/_table.html.erb +27 -27
- data/app/views/caseadilla/roles/index.html.erb +14 -14
- data/app/views/caseadilla/roles/new.html.erb +17 -17
- data/app/views/caseadilla/roles/show.html.erb +17 -17
- data/app/views/caseadilla/users/index.html.erb +36 -36
- data/app/views/caseadilla/users/new.html.erb +49 -49
- data/app/views/caseadilla/users/show.html.erb +38 -38
- data/app/views/layouts/caseadilla_auth.html.erb +36 -36
- data/app/views/layouts/caseadilla_main.html.erb +110 -118
- data/caseadilla.gemspec +48 -48
- data/config/initializers/will_paginate.rb +39 -39
- data/config/routes.rb +22 -22
- data/lib/caseadilla.rb +13 -13
- data/lib/caseadilla/engine.rb +34 -34
- data/lib/caseadilla/version.rb +1 -1
- data/lib/generators/caseadilla/install/install_generator.rb +153 -153
- data/lib/generators/caseadilla/install/templates/app/assets/javascripts/caseadilla/custom.js +1 -1
- data/lib/generators/caseadilla/install/templates/app/assets/stylesheets/caseadilla/custom.css.scss +2 -2
- data/lib/generators/caseadilla/install/templates/app/helpers/caseadilla/config_helper.rb +44 -44
- data/lib/generators/caseadilla/install/templates/app/models/user.rb +23 -23
- data/lib/generators/caseadilla/install/templates/app/views/caseadilla/layouts/_tab_navigation.html.erb +1 -1
- data/lib/generators/caseadilla/install/templates/app/views/caseadilla/layouts/_top_navigation.html.erb +3 -3
- data/lib/generators/caseadilla/install/templates/public/robots.txt +4 -4
- data/lib/generators/caseadilla/install/templates/steak/config/initializers/caseadilla.rb +7 -7
- data/lib/generators/caseadilla/install/templates/steak/db/migrate/add_name_to_users.rb +8 -8
- data/lib/generators/caseadilla/install/templates/veggie/config/initializers/caseadilla.rb +7 -7
- data/lib/generators/caseadilla/scaffold/scaffold_generator.rb +110 -110
- data/lib/generators/caseadilla/scaffold/templates/controller.rb +71 -71
- data/lib/generators/caseadilla/scaffold/templates/migration.rb +12 -12
- data/lib/generators/caseadilla/scaffold/templates/model.rb +2 -2
- data/lib/generators/caseadilla/scaffold/templates/views/_form.html.erb +11 -11
- data/lib/generators/caseadilla/scaffold/templates/views/_table.html.erb +18 -18
- data/lib/generators/caseadilla/scaffold/templates/views/index.html.erb +14 -14
- data/lib/generators/caseadilla/scaffold/templates/views/new.html.erb +17 -17
- data/lib/generators/caseadilla/scaffold/templates/views/show.html.erb +17 -17
- data/lib/railties/tasks.rake +31 -31
- metadata +2 -2
@@ -1,521 +1,521 @@
|
|
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 dropdown-toggle " + size + " btn-default' data-toggle='dropdown' href='#'>" +
|
9
|
-
"<i class='glyphicon glyphicon-font'></i> <span class='current-font'>" + locale.font_styles.normal + "</span> <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'>" + 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) ? ' btn-'+options.size : '';
|
25
|
-
return "<li>" +
|
26
|
-
"<div class='btn-group'>" +
|
27
|
-
"<a class='btn " + size + " btn-default' data-wysihtml5-command='bold' title='CTRL+B' tabindex='-1'>" + locale.emphasis.bold + "</a>" +
|
28
|
-
"<a class='btn " + size + " btn-default' data-wysihtml5-command='italic' title='CTRL+I' tabindex='-1'>" + locale.emphasis.italic + "</a>" +
|
29
|
-
"<a class='btn " + size + " btn-default' 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) ? ' btn-'+options.size : '';
|
36
|
-
return "<li>" +
|
37
|
-
"<div class='btn-group'>" +
|
38
|
-
"<a class='btn " + size + " btn-default' data-wysihtml5-command='insertUnorderedList' title='" + locale.lists.unordered + "' tabindex='-1'><i class='glyphicon glyphicon-list'></i></a>" +
|
39
|
-
"<a class='btn " + size + " btn-default' data-wysihtml5-command='insertOrderedList' title='" + locale.lists.ordered + "' tabindex='-1'><i class='glyphicon glyphicon-th-list'></i></a>" +
|
40
|
-
"<a class='btn " + size + " btn-default' data-wysihtml5-command='Outdent' title='" + locale.lists.outdent + "' tabindex='-1'><i class='glyphicon glyphicon-indent-right'></i></a>" +
|
41
|
-
"<a class='btn -" + size + " btn-default' data-wysihtml5-command='Indent' title='" + locale.lists.indent + "' tabindex='-1'><i class='glyphicon glyphicon-indent-left'></i></a>" +
|
42
|
-
"</div>" +
|
43
|
-
"</li>";
|
44
|
-
},
|
45
|
-
|
46
|
-
"link": function(locale, options) {
|
47
|
-
var size = (options && options.size) ? ' btn-'+options.size : '';
|
48
|
-
return "<li>" +
|
49
|
-
""+
|
50
|
-
"<div class='bootstrap-wysihtml5-insert-link-modal modal fade'>" +
|
51
|
-
"<div class='modal-dialog'>"+
|
52
|
-
"<div class='modal-content'>"+
|
53
|
-
"<div class='modal-header'>" +
|
54
|
-
"<a class='close' data-dismiss='modal'>×</a>" +
|
55
|
-
"<h4>" + locale.link.insert + "</h4>" +
|
56
|
-
"</div>" +
|
57
|
-
"<div class='modal-body'>" +
|
58
|
-
"<input value='http://' class='bootstrap-wysihtml5-insert-link-url form-control'>" +
|
59
|
-
"<label class='checkbox'> <input type='checkbox' class='bootstrap-wysihtml5-insert-link-target' checked>" + locale.link.target + "</label>" +
|
60
|
-
"</div>" +
|
61
|
-
"<div class='modal-footer'>" +
|
62
|
-
"<button class='btn btn-default' data-dismiss='modal'>" + locale.link.cancel + "</button>" +
|
63
|
-
"<button href='#' class='btn btn-primary' data-dismiss='modal'>" + locale.link.insert + "</button>" +
|
64
|
-
"</div>" +
|
65
|
-
"</div>" +
|
66
|
-
"</div>" +
|
67
|
-
"</div>" +
|
68
|
-
"<a class='btn " + size + " btn-default' data-wysihtml5-command='createLink' title='" + locale.link.insert + "' tabindex='-1'><i class='glyphicon glyphicon-share'></i></a>" +
|
69
|
-
"</li>";
|
70
|
-
},
|
71
|
-
|
72
|
-
"image": function(locale, options) {
|
73
|
-
var size = (options && options.size) ? ' btn-'+options.size : '';
|
74
|
-
return "<li>" +
|
75
|
-
"<div class='bootstrap-wysihtml5-insert-image-modal modal fade'>" +
|
76
|
-
"<div class='modal-dialog'>"+
|
77
|
-
"<div class='modal-content'>"+
|
78
|
-
"<div class='modal-header'>" +
|
79
|
-
"<a class='close' data-dismiss='modal'>×</a>" +
|
80
|
-
"<h4>" + locale.image.insert + "</h4>" +
|
81
|
-
"</div>" +
|
82
|
-
"<div class='modal-body'>" +
|
83
|
-
"<input value='http://' class='bootstrap-wysihtml5-insert-image-url form-control'>" +
|
84
|
-
"</div>" +
|
85
|
-
"<div class='modal-footer'>" +
|
86
|
-
"<button class='btn btn-default' data-dismiss='modal'>" + locale.image.cancel + "</button>" +
|
87
|
-
"<button class='btn btn-primary' data-dismiss='modal'>" + locale.image.insert + "</button>" +
|
88
|
-
"</div>" +
|
89
|
-
"</div>" +
|
90
|
-
"</div>" +
|
91
|
-
"</div>" +
|
92
|
-
"<a class='btn " + size + " btn-default' data-wysihtml5-command='insertImage' title='" + locale.image.insert + "' tabindex='-1'><i class='glyphicon glyphicon-picture'></i></a>" +
|
93
|
-
"</li>";
|
94
|
-
},
|
95
|
-
|
96
|
-
"html": function(locale, options) {
|
97
|
-
var size = (options && options.size) ? ' btn-'+options.size : '';
|
98
|
-
return "<li>" +
|
99
|
-
"<div class='btn-group'>" +
|
100
|
-
"<a class='btn " + size + " btn-default' data-wysihtml5-action='change_view' title='" + locale.html.edit + "' tabindex='-1'><i class='glyphicon glyphicon-pencil'></i></a>" +
|
101
|
-
"</div>" +
|
102
|
-
"</li>";
|
103
|
-
},
|
104
|
-
|
105
|
-
"color": function(locale, options) {
|
106
|
-
var size = (options && options.size) ? ' btn-'+options.size : '';
|
107
|
-
return "<li class='dropdown'>" +
|
108
|
-
"<a class='btn dropdown-toggle " + size + " btn-default' data-toggle='dropdown' href='#' tabindex='-1'>" +
|
109
|
-
"<span class='current-color'>" + locale.colours.black + "</span> <b class='caret'></b>" +
|
110
|
-
"</a>" +
|
111
|
-
"<ul class='dropdown-menu'>" +
|
112
|
-
"<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>" +
|
113
|
-
"<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>" +
|
114
|
-
"<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>" +
|
115
|
-
"<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>" +
|
116
|
-
"<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>" +
|
117
|
-
"<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>" +
|
118
|
-
"<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>" +
|
119
|
-
"<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>" +
|
120
|
-
"<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>" +
|
121
|
-
"<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>" +
|
122
|
-
"<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>" +
|
123
|
-
"</ul>" +
|
124
|
-
"</li>";
|
125
|
-
}
|
126
|
-
};
|
127
|
-
|
128
|
-
var templates = function(key, locale, options) {
|
129
|
-
return tpl[key](locale, options);
|
130
|
-
};
|
131
|
-
|
132
|
-
|
133
|
-
var Wysihtml5 = function(el, options) {
|
134
|
-
this.el = el;
|
135
|
-
var toolbarOpts = options || defaultOptions;
|
136
|
-
for(var t in toolbarOpts.customTemplates) {
|
137
|
-
tpl[t] = toolbarOpts.customTemplates[t];
|
138
|
-
}
|
139
|
-
this.toolbar = this.createToolbar(el, toolbarOpts);
|
140
|
-
this.editor = this.createEditor(options);
|
141
|
-
|
142
|
-
window.editor = this.editor;
|
143
|
-
|
144
|
-
$('iframe.wysihtml5-sandbox').each(function(i, el){
|
145
|
-
$(el.contentWindow).off('focus.wysihtml5').on({
|
146
|
-
'focus.wysihtml5' : function(){
|
147
|
-
$('li.dropdown').removeClass('open');
|
148
|
-
}
|
149
|
-
});
|
150
|
-
});
|
151
|
-
};
|
152
|
-
|
153
|
-
Wysihtml5.prototype = {
|
154
|
-
|
155
|
-
constructor: Wysihtml5,
|
156
|
-
|
157
|
-
createEditor: function(options) {
|
158
|
-
options = options || {};
|
159
|
-
|
160
|
-
// Add the toolbar to a clone of the options object so multiple instances
|
161
|
-
// of the WYISYWG don't break because "toolbar" is already defined
|
162
|
-
options = $.extend(true, {}, options);
|
163
|
-
options.toolbar = this.toolbar[0];
|
164
|
-
|
165
|
-
var editor = new wysi.Editor(this.el[0], options);
|
166
|
-
|
167
|
-
if(options && options.events) {
|
168
|
-
for(var eventName in options.events) {
|
169
|
-
editor.on(eventName, options.events[eventName]);
|
170
|
-
}
|
171
|
-
}
|
172
|
-
return editor;
|
173
|
-
},
|
174
|
-
|
175
|
-
createToolbar: function(el, options) {
|
176
|
-
var self = this;
|
177
|
-
var toolbar = $("<ul/>", {
|
178
|
-
'class' : "wysihtml5-toolbar",
|
179
|
-
'style': "display:none"
|
180
|
-
});
|
181
|
-
var culture = options.locale || defaultOptions.locale || "en";
|
182
|
-
for(var key in defaultOptions) {
|
183
|
-
var value = false;
|
184
|
-
|
185
|
-
if(options[key] !== undefined) {
|
186
|
-
if(options[key] === true) {
|
187
|
-
value = true;
|
188
|
-
}
|
189
|
-
} else {
|
190
|
-
value = defaultOptions[key];
|
191
|
-
}
|
192
|
-
|
193
|
-
if(value === true) {
|
194
|
-
toolbar.append(templates(key, locale[culture], options));
|
195
|
-
|
196
|
-
if(key === "html") {
|
197
|
-
this.initHtml(toolbar);
|
198
|
-
}
|
199
|
-
|
200
|
-
if(key === "link") {
|
201
|
-
this.initInsertLink(toolbar);
|
202
|
-
}
|
203
|
-
|
204
|
-
if(key === "image") {
|
205
|
-
this.initInsertImage(toolbar);
|
206
|
-
}
|
207
|
-
}
|
208
|
-
}
|
209
|
-
|
210
|
-
if(options.toolbar) {
|
211
|
-
for(key in options.toolbar) {
|
212
|
-
toolbar.append(options.toolbar[key]);
|
213
|
-
}
|
214
|
-
}
|
215
|
-
|
216
|
-
toolbar.find("a[data-wysihtml5-command='formatBlock']").click(function(e) {
|
217
|
-
var target = e.target || e.srcElement;
|
218
|
-
var el = $(target);
|
219
|
-
self.toolbar.find('.current-font').text(el.html());
|
220
|
-
});
|
221
|
-
|
222
|
-
toolbar.find("a[data-wysihtml5-command='foreColor']").click(function(e) {
|
223
|
-
var target = e.target || e.srcElement;
|
224
|
-
var el = $(target);
|
225
|
-
self.toolbar.find('.current-color').text(el.html());
|
226
|
-
});
|
227
|
-
|
228
|
-
this.el.before(toolbar);
|
229
|
-
|
230
|
-
return toolbar;
|
231
|
-
},
|
232
|
-
|
233
|
-
initHtml: function(toolbar) {
|
234
|
-
var changeViewSelector = "a[data-wysihtml5-action='change_view']";
|
235
|
-
toolbar.find(changeViewSelector).click(function(e) {
|
236
|
-
toolbar.find('a.btn').not(changeViewSelector).toggleClass('disabled');
|
237
|
-
});
|
238
|
-
},
|
239
|
-
|
240
|
-
initInsertImage: function(toolbar) {
|
241
|
-
var self = this;
|
242
|
-
var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal');
|
243
|
-
var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url');
|
244
|
-
var insertButton = insertImageModal.find('.btn-primary');
|
245
|
-
var initialValue = urlInput.val();
|
246
|
-
var caretBookmark;
|
247
|
-
|
248
|
-
var insertImage = function() {
|
249
|
-
var url = urlInput.val();
|
250
|
-
urlInput.val(initialValue);
|
251
|
-
self.editor.currentView.element.focus();
|
252
|
-
if (caretBookmark) {
|
253
|
-
self.editor.composer.selection.setBookmark(caretBookmark);
|
254
|
-
caretBookmark = null;
|
255
|
-
}
|
256
|
-
self.editor.composer.commands.exec("insertImage", url);
|
257
|
-
};
|
258
|
-
|
259
|
-
urlInput.keypress(function(e) {
|
260
|
-
if(e.which == 13) {
|
261
|
-
insertImage();
|
262
|
-
insertImageModal.modal('hide');
|
263
|
-
}
|
264
|
-
});
|
265
|
-
|
266
|
-
insertButton.click(insertImage);
|
267
|
-
|
268
|
-
insertImageModal.on('shown', function() {
|
269
|
-
urlInput.focus();
|
270
|
-
});
|
271
|
-
|
272
|
-
insertImageModal.on('hide', function() {
|
273
|
-
self.editor.currentView.element.focus();
|
274
|
-
});
|
275
|
-
|
276
|
-
toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() {
|
277
|
-
var activeButton = $(this).hasClass("wysihtml5-command-active");
|
278
|
-
|
279
|
-
if (!activeButton) {
|
280
|
-
self.editor.currentView.element.focus(false);
|
281
|
-
caretBookmark = self.editor.composer.selection.getBookmark();
|
282
|
-
insertImageModal.appendTo('body').modal('show');
|
283
|
-
insertImageModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {
|
284
|
-
e.stopPropagation();
|
285
|
-
});
|
286
|
-
return false;
|
287
|
-
}
|
288
|
-
else {
|
289
|
-
return true;
|
290
|
-
}
|
291
|
-
});
|
292
|
-
},
|
293
|
-
|
294
|
-
initInsertLink: function(toolbar) {
|
295
|
-
var self = this;
|
296
|
-
var insertLinkModal = toolbar.find('.bootstrap-wysihtml5-insert-link-modal');
|
297
|
-
var urlInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-url');
|
298
|
-
var targetInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-target');
|
299
|
-
var insertButton = insertLinkModal.find('.btn-primary');
|
300
|
-
var initialValue = urlInput.val();
|
301
|
-
var caretBookmark;
|
302
|
-
|
303
|
-
var insertLink = function() {
|
304
|
-
var url = urlInput.val();
|
305
|
-
urlInput.val(initialValue);
|
306
|
-
self.editor.currentView.element.focus();
|
307
|
-
if (caretBookmark) {
|
308
|
-
self.editor.composer.selection.setBookmark(caretBookmark);
|
309
|
-
caretBookmark = null;
|
310
|
-
}
|
311
|
-
|
312
|
-
var newWindow = targetInput.prop("checked");
|
313
|
-
self.editor.composer.commands.exec("createLink", {
|
314
|
-
'href' : url,
|
315
|
-
'target' : (newWindow ? '_blank' : '_self'),
|
316
|
-
'rel' : (newWindow ? 'nofollow' : '')
|
317
|
-
});
|
318
|
-
};
|
319
|
-
var pressedEnter = false;
|
320
|
-
|
321
|
-
urlInput.keypress(function(e) {
|
322
|
-
if(e.which == 13) {
|
323
|
-
insertLink();
|
324
|
-
insertLinkModal.modal('hide');
|
325
|
-
}
|
326
|
-
});
|
327
|
-
|
328
|
-
insertButton.click(insertLink);
|
329
|
-
|
330
|
-
insertLinkModal.on('shown', function() {
|
331
|
-
urlInput.focus();
|
332
|
-
});
|
333
|
-
|
334
|
-
insertLinkModal.on('hide', function() {
|
335
|
-
self.editor.currentView.element.focus();
|
336
|
-
});
|
337
|
-
|
338
|
-
toolbar.find('a[data-wysihtml5-command=createLink]').click(function() {
|
339
|
-
var activeButton = $(this).hasClass("wysihtml5-command-active");
|
340
|
-
|
341
|
-
if (!activeButton) {
|
342
|
-
self.editor.currentView.element.focus(false);
|
343
|
-
caretBookmark = self.editor.composer.selection.getBookmark();
|
344
|
-
insertLinkModal.appendTo('body').modal('show');
|
345
|
-
insertLinkModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {
|
346
|
-
e.stopPropagation();
|
347
|
-
});
|
348
|
-
return false;
|
349
|
-
}
|
350
|
-
else {
|
351
|
-
return true;
|
352
|
-
}
|
353
|
-
});
|
354
|
-
}
|
355
|
-
};
|
356
|
-
|
357
|
-
// these define our public api
|
358
|
-
var methods = {
|
359
|
-
resetDefaults: function() {
|
360
|
-
$.fn.wysihtml5.defaultOptions = $.extend(true, {}, $.fn.wysihtml5.defaultOptionsCache);
|
361
|
-
},
|
362
|
-
bypassDefaults: function(options) {
|
363
|
-
return this.each(function () {
|
364
|
-
var $this = $(this);
|
365
|
-
$this.data('wysihtml5', new Wysihtml5($this, options));
|
366
|
-
});
|
367
|
-
},
|
368
|
-
shallowExtend: function (options) {
|
369
|
-
var settings = $.extend({}, $.fn.wysihtml5.defaultOptions, options || {}, $(this).data());
|
370
|
-
var that = this;
|
371
|
-
return methods.bypassDefaults.apply(that, [settings]);
|
372
|
-
},
|
373
|
-
deepExtend: function(options) {
|
374
|
-
var settings = $.extend(true, {}, $.fn.wysihtml5.defaultOptions, options || {});
|
375
|
-
var that = this;
|
376
|
-
return methods.bypassDefaults.apply(that, [settings]);
|
377
|
-
},
|
378
|
-
init: function(options) {
|
379
|
-
var that = this;
|
380
|
-
return methods.shallowExtend.apply(that, [options]);
|
381
|
-
}
|
382
|
-
};
|
383
|
-
|
384
|
-
$.fn.wysihtml5 = function ( method ) {
|
385
|
-
if ( methods[method] ) {
|
386
|
-
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
387
|
-
} else if ( typeof method === 'object' || ! method ) {
|
388
|
-
return methods.init.apply( this, arguments );
|
389
|
-
} else {
|
390
|
-
$.error( 'Method ' + method + ' does not exist on jQuery.wysihtml5' );
|
391
|
-
}
|
392
|
-
};
|
393
|
-
|
394
|
-
$.fn.wysihtml5.Constructor = Wysihtml5;
|
395
|
-
|
396
|
-
var defaultOptions = $.fn.wysihtml5.defaultOptions = {
|
397
|
-
"font-styles": true,
|
398
|
-
"color": false,
|
399
|
-
"emphasis": true,
|
400
|
-
"lists": true,
|
401
|
-
"html": false,
|
402
|
-
"link": true,
|
403
|
-
"image": true,
|
404
|
-
"size": 'sm',
|
405
|
-
events: {},
|
406
|
-
parserRules: {
|
407
|
-
classes: {
|
408
|
-
// (path_to_project/lib/css/bootstrap3-wysiwyg5-color.css)
|
409
|
-
"wysiwyg-color-silver" : 1,
|
410
|
-
"wysiwyg-color-gray" : 1,
|
411
|
-
"wysiwyg-color-white" : 1,
|
412
|
-
"wysiwyg-color-maroon" : 1,
|
413
|
-
"wysiwyg-color-red" : 1,
|
414
|
-
"wysiwyg-color-purple" : 1,
|
415
|
-
"wysiwyg-color-fuchsia" : 1,
|
416
|
-
"wysiwyg-color-green" : 1,
|
417
|
-
"wysiwyg-color-lime" : 1,
|
418
|
-
"wysiwyg-color-olive" : 1,
|
419
|
-
"wysiwyg-color-yellow" : 1,
|
420
|
-
"wysiwyg-color-navy" : 1,
|
421
|
-
"wysiwyg-color-blue" : 1,
|
422
|
-
"wysiwyg-color-teal" : 1,
|
423
|
-
"wysiwyg-color-aqua" : 1,
|
424
|
-
"wysiwyg-color-orange" : 1
|
425
|
-
},
|
426
|
-
tags: {
|
427
|
-
"b": {},
|
428
|
-
"i": {},
|
429
|
-
"br": {},
|
430
|
-
"ol": {},
|
431
|
-
"ul": {},
|
432
|
-
"li": {},
|
433
|
-
"h1": {},
|
434
|
-
"h2": {},
|
435
|
-
"h3": {},
|
436
|
-
"h4": {},
|
437
|
-
"h5": {},
|
438
|
-
"h6": {},
|
439
|
-
"blockquote": {},
|
440
|
-
"u": 1,
|
441
|
-
"img": {
|
442
|
-
"check_attributes": {
|
443
|
-
"width": "numbers",
|
444
|
-
"alt": "alt",
|
445
|
-
"src": "url",
|
446
|
-
"height": "numbers"
|
447
|
-
}
|
448
|
-
},
|
449
|
-
"a": {
|
450
|
-
check_attributes: {
|
451
|
-
'href': "url", // important to avoid XSS
|
452
|
-
'target': 'alt',
|
453
|
-
'rel': 'alt'
|
454
|
-
}
|
455
|
-
},
|
456
|
-
"span": 1,
|
457
|
-
"div": 1,
|
458
|
-
// to allow save and edit files with code tag hacks
|
459
|
-
"code": 1,
|
460
|
-
"pre": 1
|
461
|
-
}
|
462
|
-
},
|
463
|
-
stylesheets: ["./css/bootstrap3-wysiwyg5-color.css"], // (path_to_project/lib/css/bootstrap3-wysiwyg5-color.css)
|
464
|
-
locale: "en"
|
465
|
-
};
|
466
|
-
|
467
|
-
if (typeof $.fn.wysihtml5.defaultOptionsCache === 'undefined') {
|
468
|
-
$.fn.wysihtml5.defaultOptionsCache = $.extend(true, {}, $.fn.wysihtml5.defaultOptions);
|
469
|
-
}
|
470
|
-
|
471
|
-
var locale = $.fn.wysihtml5.locale = {
|
472
|
-
en: {
|
473
|
-
font_styles: {
|
474
|
-
normal: "Normal text",
|
475
|
-
h1: "Heading 1",
|
476
|
-
h2: "Heading 2",
|
477
|
-
h3: "Heading 3",
|
478
|
-
h4: "Heading 4",
|
479
|
-
h5: "Heading 5",
|
480
|
-
h6: "Heading 6"
|
481
|
-
},
|
482
|
-
emphasis: {
|
483
|
-
bold: "Bold",
|
484
|
-
italic: "Italic",
|
485
|
-
underline: "Underline"
|
486
|
-
},
|
487
|
-
lists: {
|
488
|
-
unordered: "Unordered list",
|
489
|
-
ordered: "Ordered list",
|
490
|
-
outdent: "Outdent",
|
491
|
-
indent: "Indent"
|
492
|
-
},
|
493
|
-
link: {
|
494
|
-
insert: "Insert link",
|
495
|
-
cancel: "Cancel",
|
496
|
-
target: "Open link in new window"
|
497
|
-
},
|
498
|
-
image: {
|
499
|
-
insert: "Insert image",
|
500
|
-
cancel: "Cancel"
|
501
|
-
},
|
502
|
-
html: {
|
503
|
-
edit: "Edit HTML"
|
504
|
-
},
|
505
|
-
colours: {
|
506
|
-
black: "Black",
|
507
|
-
silver: "Silver",
|
508
|
-
gray: "Grey",
|
509
|
-
maroon: "Maroon",
|
510
|
-
red: "Red",
|
511
|
-
purple: "Purple",
|
512
|
-
green: "Green",
|
513
|
-
olive: "Olive",
|
514
|
-
navy: "Navy",
|
515
|
-
blue: "Blue",
|
516
|
-
orange: "Orange"
|
517
|
-
}
|
518
|
-
}
|
519
|
-
};
|
520
|
-
|
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 dropdown-toggle " + size + " btn-default' data-toggle='dropdown' href='#'>" +
|
9
|
+
"<i class='glyphicon glyphicon-font'></i> <span class='current-font'>" + locale.font_styles.normal + "</span> <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'>" + 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) ? ' btn-'+options.size : '';
|
25
|
+
return "<li>" +
|
26
|
+
"<div class='btn-group'>" +
|
27
|
+
"<a class='btn " + size + " btn-default' data-wysihtml5-command='bold' title='CTRL+B' tabindex='-1'>" + locale.emphasis.bold + "</a>" +
|
28
|
+
"<a class='btn " + size + " btn-default' data-wysihtml5-command='italic' title='CTRL+I' tabindex='-1'>" + locale.emphasis.italic + "</a>" +
|
29
|
+
"<a class='btn " + size + " btn-default' 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) ? ' btn-'+options.size : '';
|
36
|
+
return "<li>" +
|
37
|
+
"<div class='btn-group'>" +
|
38
|
+
"<a class='btn " + size + " btn-default' data-wysihtml5-command='insertUnorderedList' title='" + locale.lists.unordered + "' tabindex='-1'><i class='glyphicon glyphicon-list'></i></a>" +
|
39
|
+
"<a class='btn " + size + " btn-default' data-wysihtml5-command='insertOrderedList' title='" + locale.lists.ordered + "' tabindex='-1'><i class='glyphicon glyphicon-th-list'></i></a>" +
|
40
|
+
"<a class='btn " + size + " btn-default' data-wysihtml5-command='Outdent' title='" + locale.lists.outdent + "' tabindex='-1'><i class='glyphicon glyphicon-indent-right'></i></a>" +
|
41
|
+
"<a class='btn -" + size + " btn-default' data-wysihtml5-command='Indent' title='" + locale.lists.indent + "' tabindex='-1'><i class='glyphicon glyphicon-indent-left'></i></a>" +
|
42
|
+
"</div>" +
|
43
|
+
"</li>";
|
44
|
+
},
|
45
|
+
|
46
|
+
"link": function(locale, options) {
|
47
|
+
var size = (options && options.size) ? ' btn-'+options.size : '';
|
48
|
+
return "<li>" +
|
49
|
+
""+
|
50
|
+
"<div class='bootstrap-wysihtml5-insert-link-modal modal fade'>" +
|
51
|
+
"<div class='modal-dialog'>"+
|
52
|
+
"<div class='modal-content'>"+
|
53
|
+
"<div class='modal-header'>" +
|
54
|
+
"<a class='close' data-dismiss='modal'>×</a>" +
|
55
|
+
"<h4>" + locale.link.insert + "</h4>" +
|
56
|
+
"</div>" +
|
57
|
+
"<div class='modal-body'>" +
|
58
|
+
"<input value='http://' class='bootstrap-wysihtml5-insert-link-url form-control'>" +
|
59
|
+
"<label class='checkbox'> <input type='checkbox' class='bootstrap-wysihtml5-insert-link-target' checked>" + locale.link.target + "</label>" +
|
60
|
+
"</div>" +
|
61
|
+
"<div class='modal-footer'>" +
|
62
|
+
"<button class='btn btn-default' data-dismiss='modal'>" + locale.link.cancel + "</button>" +
|
63
|
+
"<button href='#' class='btn btn-primary' data-dismiss='modal'>" + locale.link.insert + "</button>" +
|
64
|
+
"</div>" +
|
65
|
+
"</div>" +
|
66
|
+
"</div>" +
|
67
|
+
"</div>" +
|
68
|
+
"<a class='btn " + size + " btn-default' data-wysihtml5-command='createLink' title='" + locale.link.insert + "' tabindex='-1'><i class='glyphicon glyphicon-share'></i></a>" +
|
69
|
+
"</li>";
|
70
|
+
},
|
71
|
+
|
72
|
+
"image": function(locale, options) {
|
73
|
+
var size = (options && options.size) ? ' btn-'+options.size : '';
|
74
|
+
return "<li>" +
|
75
|
+
"<div class='bootstrap-wysihtml5-insert-image-modal modal fade'>" +
|
76
|
+
"<div class='modal-dialog'>"+
|
77
|
+
"<div class='modal-content'>"+
|
78
|
+
"<div class='modal-header'>" +
|
79
|
+
"<a class='close' data-dismiss='modal'>×</a>" +
|
80
|
+
"<h4>" + locale.image.insert + "</h4>" +
|
81
|
+
"</div>" +
|
82
|
+
"<div class='modal-body'>" +
|
83
|
+
"<input value='http://' class='bootstrap-wysihtml5-insert-image-url form-control'>" +
|
84
|
+
"</div>" +
|
85
|
+
"<div class='modal-footer'>" +
|
86
|
+
"<button class='btn btn-default' data-dismiss='modal'>" + locale.image.cancel + "</button>" +
|
87
|
+
"<button class='btn btn-primary' data-dismiss='modal'>" + locale.image.insert + "</button>" +
|
88
|
+
"</div>" +
|
89
|
+
"</div>" +
|
90
|
+
"</div>" +
|
91
|
+
"</div>" +
|
92
|
+
"<a class='btn " + size + " btn-default' data-wysihtml5-command='insertImage' title='" + locale.image.insert + "' tabindex='-1'><i class='glyphicon glyphicon-picture'></i></a>" +
|
93
|
+
"</li>";
|
94
|
+
},
|
95
|
+
|
96
|
+
"html": function(locale, options) {
|
97
|
+
var size = (options && options.size) ? ' btn-'+options.size : '';
|
98
|
+
return "<li>" +
|
99
|
+
"<div class='btn-group'>" +
|
100
|
+
"<a class='btn " + size + " btn-default' data-wysihtml5-action='change_view' title='" + locale.html.edit + "' tabindex='-1'><i class='glyphicon glyphicon-pencil'></i></a>" +
|
101
|
+
"</div>" +
|
102
|
+
"</li>";
|
103
|
+
},
|
104
|
+
|
105
|
+
"color": function(locale, options) {
|
106
|
+
var size = (options && options.size) ? ' btn-'+options.size : '';
|
107
|
+
return "<li class='dropdown'>" +
|
108
|
+
"<a class='btn dropdown-toggle " + size + " btn-default' data-toggle='dropdown' href='#' tabindex='-1'>" +
|
109
|
+
"<span class='current-color'>" + locale.colours.black + "</span> <b class='caret'></b>" +
|
110
|
+
"</a>" +
|
111
|
+
"<ul class='dropdown-menu'>" +
|
112
|
+
"<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>" +
|
113
|
+
"<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>" +
|
114
|
+
"<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>" +
|
115
|
+
"<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>" +
|
116
|
+
"<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>" +
|
117
|
+
"<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>" +
|
118
|
+
"<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>" +
|
119
|
+
"<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>" +
|
120
|
+
"<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>" +
|
121
|
+
"<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>" +
|
122
|
+
"<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>" +
|
123
|
+
"</ul>" +
|
124
|
+
"</li>";
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
var templates = function(key, locale, options) {
|
129
|
+
return tpl[key](locale, options);
|
130
|
+
};
|
131
|
+
|
132
|
+
|
133
|
+
var Wysihtml5 = function(el, options) {
|
134
|
+
this.el = el;
|
135
|
+
var toolbarOpts = options || defaultOptions;
|
136
|
+
for(var t in toolbarOpts.customTemplates) {
|
137
|
+
tpl[t] = toolbarOpts.customTemplates[t];
|
138
|
+
}
|
139
|
+
this.toolbar = this.createToolbar(el, toolbarOpts);
|
140
|
+
this.editor = this.createEditor(options);
|
141
|
+
|
142
|
+
window.editor = this.editor;
|
143
|
+
|
144
|
+
$('iframe.wysihtml5-sandbox').each(function(i, el){
|
145
|
+
$(el.contentWindow).off('focus.wysihtml5').on({
|
146
|
+
'focus.wysihtml5' : function(){
|
147
|
+
$('li.dropdown').removeClass('open');
|
148
|
+
}
|
149
|
+
});
|
150
|
+
});
|
151
|
+
};
|
152
|
+
|
153
|
+
Wysihtml5.prototype = {
|
154
|
+
|
155
|
+
constructor: Wysihtml5,
|
156
|
+
|
157
|
+
createEditor: function(options) {
|
158
|
+
options = options || {};
|
159
|
+
|
160
|
+
// Add the toolbar to a clone of the options object so multiple instances
|
161
|
+
// of the WYISYWG don't break because "toolbar" is already defined
|
162
|
+
options = $.extend(true, {}, options);
|
163
|
+
options.toolbar = this.toolbar[0];
|
164
|
+
|
165
|
+
var editor = new wysi.Editor(this.el[0], options);
|
166
|
+
|
167
|
+
if(options && options.events) {
|
168
|
+
for(var eventName in options.events) {
|
169
|
+
editor.on(eventName, options.events[eventName]);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
return editor;
|
173
|
+
},
|
174
|
+
|
175
|
+
createToolbar: function(el, options) {
|
176
|
+
var self = this;
|
177
|
+
var toolbar = $("<ul/>", {
|
178
|
+
'class' : "wysihtml5-toolbar",
|
179
|
+
'style': "display:none"
|
180
|
+
});
|
181
|
+
var culture = options.locale || defaultOptions.locale || "en";
|
182
|
+
for(var key in defaultOptions) {
|
183
|
+
var value = false;
|
184
|
+
|
185
|
+
if(options[key] !== undefined) {
|
186
|
+
if(options[key] === true) {
|
187
|
+
value = true;
|
188
|
+
}
|
189
|
+
} else {
|
190
|
+
value = defaultOptions[key];
|
191
|
+
}
|
192
|
+
|
193
|
+
if(value === true) {
|
194
|
+
toolbar.append(templates(key, locale[culture], options));
|
195
|
+
|
196
|
+
if(key === "html") {
|
197
|
+
this.initHtml(toolbar);
|
198
|
+
}
|
199
|
+
|
200
|
+
if(key === "link") {
|
201
|
+
this.initInsertLink(toolbar);
|
202
|
+
}
|
203
|
+
|
204
|
+
if(key === "image") {
|
205
|
+
this.initInsertImage(toolbar);
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
if(options.toolbar) {
|
211
|
+
for(key in options.toolbar) {
|
212
|
+
toolbar.append(options.toolbar[key]);
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
toolbar.find("a[data-wysihtml5-command='formatBlock']").click(function(e) {
|
217
|
+
var target = e.target || e.srcElement;
|
218
|
+
var el = $(target);
|
219
|
+
self.toolbar.find('.current-font').text(el.html());
|
220
|
+
});
|
221
|
+
|
222
|
+
toolbar.find("a[data-wysihtml5-command='foreColor']").click(function(e) {
|
223
|
+
var target = e.target || e.srcElement;
|
224
|
+
var el = $(target);
|
225
|
+
self.toolbar.find('.current-color').text(el.html());
|
226
|
+
});
|
227
|
+
|
228
|
+
this.el.before(toolbar);
|
229
|
+
|
230
|
+
return toolbar;
|
231
|
+
},
|
232
|
+
|
233
|
+
initHtml: function(toolbar) {
|
234
|
+
var changeViewSelector = "a[data-wysihtml5-action='change_view']";
|
235
|
+
toolbar.find(changeViewSelector).click(function(e) {
|
236
|
+
toolbar.find('a.btn').not(changeViewSelector).toggleClass('disabled');
|
237
|
+
});
|
238
|
+
},
|
239
|
+
|
240
|
+
initInsertImage: function(toolbar) {
|
241
|
+
var self = this;
|
242
|
+
var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal');
|
243
|
+
var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url');
|
244
|
+
var insertButton = insertImageModal.find('.btn-primary');
|
245
|
+
var initialValue = urlInput.val();
|
246
|
+
var caretBookmark;
|
247
|
+
|
248
|
+
var insertImage = function() {
|
249
|
+
var url = urlInput.val();
|
250
|
+
urlInput.val(initialValue);
|
251
|
+
self.editor.currentView.element.focus();
|
252
|
+
if (caretBookmark) {
|
253
|
+
self.editor.composer.selection.setBookmark(caretBookmark);
|
254
|
+
caretBookmark = null;
|
255
|
+
}
|
256
|
+
self.editor.composer.commands.exec("insertImage", url);
|
257
|
+
};
|
258
|
+
|
259
|
+
urlInput.keypress(function(e) {
|
260
|
+
if(e.which == 13) {
|
261
|
+
insertImage();
|
262
|
+
insertImageModal.modal('hide');
|
263
|
+
}
|
264
|
+
});
|
265
|
+
|
266
|
+
insertButton.click(insertImage);
|
267
|
+
|
268
|
+
insertImageModal.on('shown', function() {
|
269
|
+
urlInput.focus();
|
270
|
+
});
|
271
|
+
|
272
|
+
insertImageModal.on('hide', function() {
|
273
|
+
self.editor.currentView.element.focus();
|
274
|
+
});
|
275
|
+
|
276
|
+
toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() {
|
277
|
+
var activeButton = $(this).hasClass("wysihtml5-command-active");
|
278
|
+
|
279
|
+
if (!activeButton) {
|
280
|
+
self.editor.currentView.element.focus(false);
|
281
|
+
caretBookmark = self.editor.composer.selection.getBookmark();
|
282
|
+
insertImageModal.appendTo('body').modal('show');
|
283
|
+
insertImageModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {
|
284
|
+
e.stopPropagation();
|
285
|
+
});
|
286
|
+
return false;
|
287
|
+
}
|
288
|
+
else {
|
289
|
+
return true;
|
290
|
+
}
|
291
|
+
});
|
292
|
+
},
|
293
|
+
|
294
|
+
initInsertLink: function(toolbar) {
|
295
|
+
var self = this;
|
296
|
+
var insertLinkModal = toolbar.find('.bootstrap-wysihtml5-insert-link-modal');
|
297
|
+
var urlInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-url');
|
298
|
+
var targetInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-target');
|
299
|
+
var insertButton = insertLinkModal.find('.btn-primary');
|
300
|
+
var initialValue = urlInput.val();
|
301
|
+
var caretBookmark;
|
302
|
+
|
303
|
+
var insertLink = function() {
|
304
|
+
var url = urlInput.val();
|
305
|
+
urlInput.val(initialValue);
|
306
|
+
self.editor.currentView.element.focus();
|
307
|
+
if (caretBookmark) {
|
308
|
+
self.editor.composer.selection.setBookmark(caretBookmark);
|
309
|
+
caretBookmark = null;
|
310
|
+
}
|
311
|
+
|
312
|
+
var newWindow = targetInput.prop("checked");
|
313
|
+
self.editor.composer.commands.exec("createLink", {
|
314
|
+
'href' : url,
|
315
|
+
'target' : (newWindow ? '_blank' : '_self'),
|
316
|
+
'rel' : (newWindow ? 'nofollow' : '')
|
317
|
+
});
|
318
|
+
};
|
319
|
+
var pressedEnter = false;
|
320
|
+
|
321
|
+
urlInput.keypress(function(e) {
|
322
|
+
if(e.which == 13) {
|
323
|
+
insertLink();
|
324
|
+
insertLinkModal.modal('hide');
|
325
|
+
}
|
326
|
+
});
|
327
|
+
|
328
|
+
insertButton.click(insertLink);
|
329
|
+
|
330
|
+
insertLinkModal.on('shown', function() {
|
331
|
+
urlInput.focus();
|
332
|
+
});
|
333
|
+
|
334
|
+
insertLinkModal.on('hide', function() {
|
335
|
+
self.editor.currentView.element.focus();
|
336
|
+
});
|
337
|
+
|
338
|
+
toolbar.find('a[data-wysihtml5-command=createLink]').click(function() {
|
339
|
+
var activeButton = $(this).hasClass("wysihtml5-command-active");
|
340
|
+
|
341
|
+
if (!activeButton) {
|
342
|
+
self.editor.currentView.element.focus(false);
|
343
|
+
caretBookmark = self.editor.composer.selection.getBookmark();
|
344
|
+
insertLinkModal.appendTo('body').modal('show');
|
345
|
+
insertLinkModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {
|
346
|
+
e.stopPropagation();
|
347
|
+
});
|
348
|
+
return false;
|
349
|
+
}
|
350
|
+
else {
|
351
|
+
return true;
|
352
|
+
}
|
353
|
+
});
|
354
|
+
}
|
355
|
+
};
|
356
|
+
|
357
|
+
// these define our public api
|
358
|
+
var methods = {
|
359
|
+
resetDefaults: function() {
|
360
|
+
$.fn.wysihtml5.defaultOptions = $.extend(true, {}, $.fn.wysihtml5.defaultOptionsCache);
|
361
|
+
},
|
362
|
+
bypassDefaults: function(options) {
|
363
|
+
return this.each(function () {
|
364
|
+
var $this = $(this);
|
365
|
+
$this.data('wysihtml5', new Wysihtml5($this, options));
|
366
|
+
});
|
367
|
+
},
|
368
|
+
shallowExtend: function (options) {
|
369
|
+
var settings = $.extend({}, $.fn.wysihtml5.defaultOptions, options || {}, $(this).data());
|
370
|
+
var that = this;
|
371
|
+
return methods.bypassDefaults.apply(that, [settings]);
|
372
|
+
},
|
373
|
+
deepExtend: function(options) {
|
374
|
+
var settings = $.extend(true, {}, $.fn.wysihtml5.defaultOptions, options || {});
|
375
|
+
var that = this;
|
376
|
+
return methods.bypassDefaults.apply(that, [settings]);
|
377
|
+
},
|
378
|
+
init: function(options) {
|
379
|
+
var that = this;
|
380
|
+
return methods.shallowExtend.apply(that, [options]);
|
381
|
+
}
|
382
|
+
};
|
383
|
+
|
384
|
+
$.fn.wysihtml5 = function ( method ) {
|
385
|
+
if ( methods[method] ) {
|
386
|
+
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
|
387
|
+
} else if ( typeof method === 'object' || ! method ) {
|
388
|
+
return methods.init.apply( this, arguments );
|
389
|
+
} else {
|
390
|
+
$.error( 'Method ' + method + ' does not exist on jQuery.wysihtml5' );
|
391
|
+
}
|
392
|
+
};
|
393
|
+
|
394
|
+
$.fn.wysihtml5.Constructor = Wysihtml5;
|
395
|
+
|
396
|
+
var defaultOptions = $.fn.wysihtml5.defaultOptions = {
|
397
|
+
"font-styles": true,
|
398
|
+
"color": false,
|
399
|
+
"emphasis": true,
|
400
|
+
"lists": true,
|
401
|
+
"html": false,
|
402
|
+
"link": true,
|
403
|
+
"image": true,
|
404
|
+
"size": 'sm',
|
405
|
+
events: {},
|
406
|
+
parserRules: {
|
407
|
+
classes: {
|
408
|
+
// (path_to_project/lib/css/bootstrap3-wysiwyg5-color.css)
|
409
|
+
"wysiwyg-color-silver" : 1,
|
410
|
+
"wysiwyg-color-gray" : 1,
|
411
|
+
"wysiwyg-color-white" : 1,
|
412
|
+
"wysiwyg-color-maroon" : 1,
|
413
|
+
"wysiwyg-color-red" : 1,
|
414
|
+
"wysiwyg-color-purple" : 1,
|
415
|
+
"wysiwyg-color-fuchsia" : 1,
|
416
|
+
"wysiwyg-color-green" : 1,
|
417
|
+
"wysiwyg-color-lime" : 1,
|
418
|
+
"wysiwyg-color-olive" : 1,
|
419
|
+
"wysiwyg-color-yellow" : 1,
|
420
|
+
"wysiwyg-color-navy" : 1,
|
421
|
+
"wysiwyg-color-blue" : 1,
|
422
|
+
"wysiwyg-color-teal" : 1,
|
423
|
+
"wysiwyg-color-aqua" : 1,
|
424
|
+
"wysiwyg-color-orange" : 1
|
425
|
+
},
|
426
|
+
tags: {
|
427
|
+
"b": {},
|
428
|
+
"i": {},
|
429
|
+
"br": {},
|
430
|
+
"ol": {},
|
431
|
+
"ul": {},
|
432
|
+
"li": {},
|
433
|
+
"h1": {},
|
434
|
+
"h2": {},
|
435
|
+
"h3": {},
|
436
|
+
"h4": {},
|
437
|
+
"h5": {},
|
438
|
+
"h6": {},
|
439
|
+
"blockquote": {},
|
440
|
+
"u": 1,
|
441
|
+
"img": {
|
442
|
+
"check_attributes": {
|
443
|
+
"width": "numbers",
|
444
|
+
"alt": "alt",
|
445
|
+
"src": "url",
|
446
|
+
"height": "numbers"
|
447
|
+
}
|
448
|
+
},
|
449
|
+
"a": {
|
450
|
+
check_attributes: {
|
451
|
+
'href': "url", // important to avoid XSS
|
452
|
+
'target': 'alt',
|
453
|
+
'rel': 'alt'
|
454
|
+
}
|
455
|
+
},
|
456
|
+
"span": 1,
|
457
|
+
"div": 1,
|
458
|
+
// to allow save and edit files with code tag hacks
|
459
|
+
"code": 1,
|
460
|
+
"pre": 1
|
461
|
+
}
|
462
|
+
},
|
463
|
+
stylesheets: ["./css/bootstrap3-wysiwyg5-color.css"], // (path_to_project/lib/css/bootstrap3-wysiwyg5-color.css)
|
464
|
+
locale: "en"
|
465
|
+
};
|
466
|
+
|
467
|
+
if (typeof $.fn.wysihtml5.defaultOptionsCache === 'undefined') {
|
468
|
+
$.fn.wysihtml5.defaultOptionsCache = $.extend(true, {}, $.fn.wysihtml5.defaultOptions);
|
469
|
+
}
|
470
|
+
|
471
|
+
var locale = $.fn.wysihtml5.locale = {
|
472
|
+
en: {
|
473
|
+
font_styles: {
|
474
|
+
normal: "Normal text",
|
475
|
+
h1: "Heading 1",
|
476
|
+
h2: "Heading 2",
|
477
|
+
h3: "Heading 3",
|
478
|
+
h4: "Heading 4",
|
479
|
+
h5: "Heading 5",
|
480
|
+
h6: "Heading 6"
|
481
|
+
},
|
482
|
+
emphasis: {
|
483
|
+
bold: "Bold",
|
484
|
+
italic: "Italic",
|
485
|
+
underline: "Underline"
|
486
|
+
},
|
487
|
+
lists: {
|
488
|
+
unordered: "Unordered list",
|
489
|
+
ordered: "Ordered list",
|
490
|
+
outdent: "Outdent",
|
491
|
+
indent: "Indent"
|
492
|
+
},
|
493
|
+
link: {
|
494
|
+
insert: "Insert link",
|
495
|
+
cancel: "Cancel",
|
496
|
+
target: "Open link in new window"
|
497
|
+
},
|
498
|
+
image: {
|
499
|
+
insert: "Insert image",
|
500
|
+
cancel: "Cancel"
|
501
|
+
},
|
502
|
+
html: {
|
503
|
+
edit: "Edit HTML"
|
504
|
+
},
|
505
|
+
colours: {
|
506
|
+
black: "Black",
|
507
|
+
silver: "Silver",
|
508
|
+
gray: "Grey",
|
509
|
+
maroon: "Maroon",
|
510
|
+
red: "Red",
|
511
|
+
purple: "Purple",
|
512
|
+
green: "Green",
|
513
|
+
olive: "Olive",
|
514
|
+
navy: "Navy",
|
515
|
+
blue: "Blue",
|
516
|
+
orange: "Orange"
|
517
|
+
}
|
518
|
+
}
|
519
|
+
};
|
520
|
+
|
521
521
|
}(window.jQuery, window.wysihtml5);
|