wysiwyg.html
8.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<title>Wysiwyg & Markdown Editor - Ace Admin</title>
<link rel="stylesheet" href="../../assets/css/jquery-ui.custom.css" />
<!-- ajax layout which only needs content area -->
<div class="page-header">
<h1>Wysiwyg & Markdown Editor </h1>
</div><!-- /.page-header -->
<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->
<h4 class="header green clearfix">
Bootstrap Lightweight Editor
<span class="block pull-right">
<small class="grey middle">Choose style: </small>
<span class="btn-toolbar inline middle no-margin">
<span data-toggle="buttons" class="btn-group no-margin">
<label class="btn btn-sm btn-yellow">
1
<input type="radio" value="1" />
</label>
<label class="btn btn-sm btn-yellow active">
2
<input type="radio" value="2" />
</label>
<label class="btn btn-sm btn-yellow">
3
<input type="radio" value="3" />
</label>
<label class="btn btn-sm btn-yellow">
4
<input type="radio" value="4" />
</label>
</span>
</span>
</span>
</h4>
<div class="wysiwyg-editor" id="editor1"></div>
<div class="hr hr-double dotted"></div>
<div class="row">
<div class="col-sm-5">
<h4 class="header blue">Inside Widget</h4>
<div class="widget-box widget-color-green">
<div class="widget-header widget-header-small"> </div>
<div class="widget-body">
<div class="widget-main no-padding">
<div class="wysiwyg-editor" id="editor2"></div>
</div>
<div class="widget-toolbox padding-4 clearfix">
<div class="btn-group pull-left">
<button class="btn btn-sm btn-default btn-white btn-round">
<i class="ace-icon fa fa-times bigger-125"></i>
Cancel
</button>
</div>
<div class="btn-group pull-right">
<button class="btn btn-sm btn-danger btn-white btn-round">
<i class="ace-icon fa fa-floppy-o bigger-125"></i>
Save
</button>
<button class="btn btn-sm btn-success btn-white btn-round">
<i class="ace-icon fa fa-globe bigger-125"></i>
Publish
<i class="ace-icon fa fa-arrow-right icon-on-right bigger-125"></i>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-7">
<h4 class="header green">Markdown Editor</h4>
<div class="widget-box widget-color-blue">
<div class="widget-header widget-header-small"> </div>
<div class="widget-body">
<div class="widget-main no-padding">
<textarea name="content" data-provide="markdown" data-iconlibrary="fa" rows="10">**Markdown Editor** inside a *widget box*
- list item 1
- list item 2
- list item 3</textarea>
</div>
<div class="widget-toolbox padding-4 clearfix">
<div class="btn-group pull-left">
<button class="btn btn-sm btn-info">
<i class="ace-icon fa fa-times bigger-125"></i>
Cancel
</button>
</div>
<div class="btn-group pull-right">
<button class="btn btn-sm btn-purple">
<i class="ace-icon fa fa-floppy-o bigger-125"></i>
Save
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var $path_assets = "../../assets";//this will be used in loading jQuery UI if needed!
</script>
<!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div><!-- /.row -->
<!-- page specific plugin scripts -->
<script type="text/javascript">
var scripts = [null,"../../assets/js/jquery-ui.custom.js","../../assets/js/jquery.ui.touch-punch.js","../../assets/js/markdown/markdown.js","../../assets/js/markdown/bootstrap-markdown.js","../../assets/js/jquery.hotkeys.js","../../assets/js/bootstrap-wysiwyg.js","../../assets/js/bootbox.js", null]
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
//inline scripts related to this page
jQuery(function($){
function showErrorAlert (reason, detail) {
var msg='';
if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
else {
//console.log("error uploading file", reason, detail);
}
$('<div class="alert"> <button type="button" class="close" data-dismiss="alert">×</button>'+
'<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
}
//$('#editor1').ace_wysiwyg();//this will create the default editor will all buttons
//but we want to change a few buttons colors for the third style
$('#editor1').ace_wysiwyg({
toolbar:
[
'font',
null,
'fontSize',
null,
{name:'bold', className:'btn-info'},
{name:'italic', className:'btn-info'},
{name:'strikethrough', className:'btn-info'},
{name:'underline', className:'btn-info'},
null,
{name:'insertunorderedlist', className:'btn-success'},
{name:'insertorderedlist', className:'btn-success'},
{name:'outdent', className:'btn-purple'},
{name:'indent', className:'btn-purple'},
null,
{name:'justifyleft', className:'btn-primary'},
{name:'justifycenter', className:'btn-primary'},
{name:'justifyright', className:'btn-primary'},
{name:'justifyfull', className:'btn-inverse'},
null,
{name:'createLink', className:'btn-pink'},
{name:'unlink', className:'btn-pink'},
null,
{name:'insertImage', className:'btn-success'},
null,
'foreColor',
null,
{name:'undo', className:'btn-grey'},
{name:'redo', className:'btn-grey'}
],
'wysiwyg': {
fileUploadError: showErrorAlert
}
}).prev().addClass('wysiwyg-style2');
/**
//make the editor have all the available height
$(window).on('resize.editor', function() {
var offset = $('#editor1').parent().offset();
var winHeight = $(this).height();
$('#editor1').css({'height':winHeight - offset.top - 10, 'max-height': 'none'});
}).triggerHandler('resize.editor');
*/
$('#editor2').css({'height':'200px'}).ace_wysiwyg({
toolbar_place: function(toolbar) {
return $(this).closest('.widget-box')
.find('.widget-header').prepend(toolbar)
.find('.wysiwyg-toolbar').addClass('inline');
},
toolbar:
[
'bold',
{name:'italic' , title:'Change Title!', icon: 'ace-icon fa fa-leaf'},
'strikethrough',
null,
'insertunorderedlist',
'insertorderedlist',
null,
'justifyleft',
'justifycenter',
'justifyright'
],
speech_button: false
});
$('[data-toggle="buttons"] .btn').on('click', function(e){
var target = $(this).find('input[type=radio]');
var which = parseInt(target.val());
var toolbar = $('#editor1').prev().get(0);
if(which >= 1 && which <= 4) {
toolbar.className = toolbar.className.replace(/wysiwyg\-style(1|2)/g , '');
if(which == 1) $(toolbar).addClass('wysiwyg-style1');
else if(which == 2) $(toolbar).addClass('wysiwyg-style2');
if(which == 4) {
$(toolbar).find('.btn-group > .btn').addClass('btn-white btn-round');
} else $(toolbar).find('.btn-group > .btn-white').removeClass('btn-white btn-round');
}
});
//RESIZE IMAGE
//Add Image Resize Functionality to Chrome and Safari
//webkit browsers don't have image resize functionality when content is editable
//so let's add something using jQuery UI resizable
//another option would be opening a dialog for user to enter dimensions.
if ( typeof jQuery.ui !== 'undefined' && ace.vars['webkit'] ) {
var lastResizableImg = null;
function destroyResizable() {
if(lastResizableImg == null) return;
lastResizableImg.resizable( "destroy" );
lastResizableImg.removeData('resizable');
lastResizableImg = null;
}
var enableImageResize = function() {
$('.wysiwyg-editor')
.on('mousedown', function(e) {
var target = $(e.target);
if( e.target instanceof HTMLImageElement ) {
if( !target.data('resizable') ) {
target.resizable({
aspectRatio: e.target.width / e.target.height,
});
target.data('resizable', true);
if( lastResizableImg != null ) {
//disable previous resizable image
lastResizableImg.resizable( "destroy" );
lastResizableImg.removeData('resizable');
}
lastResizableImg = target;
}
}
})
.on('click', function(e) {
if( lastResizableImg != null && !(e.target instanceof HTMLImageElement) ) {
destroyResizable();
}
})
.on('keydown', function() {
destroyResizable();
});
}
enableImageResize();
/**
//or we can load the jQuery UI dynamically only if needed
if (typeof jQuery.ui !== 'undefined') enableImageResize();
else {//load jQuery UI if not loaded
$.getScript($path_assets+"/js/jquery-ui.custom.min.js", function(data, textStatus, jqxhr) {
enableImageResize()
});
}
*/
}
});
});
</script>