-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdocumentation.html
272 lines (236 loc) · 10.7 KB
/
documentation.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Easy editor - documentation</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container container-fluid">
<h1>Easy editor <span>documentation</span></h1>
<p class="p"><a href="examples.html">Checkout all examples</a>. Following documentation seems wired but you will get what you need.</p>
<p class="p">Usage: </p>
<pre class="code">new EasyEditor('#selector', {
options: options
});
or
$('#selector').easyEditor({
options: options
});
</pre>
<p class="p">Supported default buttons: </p>
<pre class="code">['bold', 'italic', 'link', 'h2', 'h3', 'h4', 'alignleft', 'aligncenter', 'alignright', 'quote', 'code', 'x']</pre>
<p class="p">How to use icon font in button text: e.g. If you are planning to use font awesome then include fontawesome css and do like this - </p>
<pre class="code">var easyEditor = new EasyEditor('#editor', {
buttons: ['bold', 'italic', 'link', 'h2', 'h3', 'h4', 'alignleft', 'aligncenter', 'alignright', 'quote', 'code', 'image', 'youtube', 'x'],
<mark>buttonsHtml</mark>: {
'bold': '<i class="fa fa-bold"></i>',
'italic': '<i class="fa fa-italic"></i>',
'link': '<i class="fa fa-link"></i>',
'header-2': '<i class="fa fa-header"></i>2',
'header-3': '<i class="fa fa-header"></i>3',
'header-4': '<i class="fa fa-header"></i>4',
'align-left': '<i class="fa fa-align-left"></i>',
'align-center': '<i class="fa fa-align-center"></i>',
'align-right': '<i class="fa fa-align-right"></i>',
'quote': '<i class="fa fa-quote-left"></i>',
'code': '<i class="fa fa-code"></i>',
'insert-image': '<i class="fa fa-picture-o"></i>',
'insert-youtube-video': '<i class="fa fa-youtube"></i>',
'remove-formatting': '<i class="fa fa-ban"></i>'
}
});
// list of button identifier
// =========================
// bold
// italic
// link
// header-2
// header-3
// header-4
// align-left
// align-center
// align-right
// quote
// code
// insert-image
// insert-youtube-video
// remove-formatting</pre>
<p class="p">Insert custom button: </p>
<pre class="code">EasyEditor.prototype.<mark>custombutton</mark> = function(){
var _this = this;
var settings = {
buttonIdentifier: 'custombutton',
buttonHtml: 'My custom button',
clickHandler: function(){
console.log('Custom button clicked!');
}
};
_this.injectButton(settings);
};
jQuery(document).ready(function($) {
new EasyEditor('#editor', {
buttons: ['bold', 'italic', 'link', 'h2', 'h3', 'h4', 'alignleft', 'aligncenter', 'alignright', '<mark>custombutton</mark>']
});
});</pre>
<p class="p">Wrap with HTML tag: </p>
<pre class="code">EasyEditor.prototype.<mark>wrapSelectionWithNodeName</mark>(arg)
arg = {
name: 'Tag name e.g h2',
blockElement: 'boolean',
style: 'e.g color: #ff0000; background: pink',
class: 'class name',
attribute: '[arg1, arg2]',
keepHtml: 'boolean'
};
Usage:
------
EasyEditor.prototype.h5 = function(){
var _this = this;
var settings = {
buttonIdentifier: 'h5',
buttonHtml: 'h5',
clickHandler: function(){
_this.<mark>wrapSelectionWithNodeName</mark>({ nodeName: 'span' });
// or
_this.<mark>wrapSelectionWithNodeName</mark>({ nodeName: 'a', attribute: ['href', prompt('Insert link', '')] });
_this.<mark>wrapSelectionWithNodeName</mark>({ nodeName: 'a', attribute: { 'data-value': 1, 'data-item': 'item-value' } });
// or
_this.<mark>wrapSelectionWithNodeName</mark>({ nodeName: 'p', style: 'text-align: right', class: 'text-right', keepHtml: true });
// or
_this.<mark>wrapSelectionWithNodeName</mark>({ nodeName: 'h4', blockElement: true });
}
};
_this.injectButton(settings);
};
</pre>
<p class="p">Overwrite default button settings: </p>
<pre class="code">var easyEditor = new EasyEditor('#editor', {
buttons: ['bold', 'italic', 'link', 'h2', 'h3', 'h4', 'alignleft', 'aligncenter', 'alignright'],
overwriteButtonSettings: {
'bold' : {
buttonIdentifier: 'overwritten-bold',
buttonHtml: 'Overwritten Bold',
buttonTitle: 'Make text bold',
clickHandler: function(){
easyEditor.wrapSelectionWithNodeName({ nodeName: 'b', keepHtml: true });
}
},
'italic': {
buttonHtml: 'Overwritten Italic',
buttonTitle: 'Make text italic',
}
}
});
// default bold button settings was
// ================================
// buttonIdentifier: 'bold',
// buttonHtml: 'B',
// clickHandler: function(){
// _this.wrapSelectionWithNodeName({ nodeName: 'strong', keepHtml: true });
// }</pre>
<p class="p">Insert node at caret or cursor position: </p>
<pre class="code">EasyEditor.prototype.imageurl = function(){
var _this = this;
var settings = {
buttonIdentifier: 'insert-image-url',
buttonHtml: 'Insert image url',
clickHandler: function(){
var link = prompt('Insert direct image path', '');
if(link.length > 0) {
var figure = document.createElement('figure');
$(figure).html('<img src="'+ link +'" alt="">');
_this.<mark>insertAtCaret</mark>(figure);
}
else {
alert('Invalid URL!');
}
}
};
_this.injectButton(settings);
};</pre>
<p class="p">Modal template: This should be inserted when needed only and before body closing tag</p>
<pre class="code"><div class="easyeditor-modal is-hidden" id="<mark>your-selector-id-here</mark>">
<div class="easyeditor-modal-content">
<div class="easyeditor-modal-content-header"><mark>{{ Modal title here }}</mark></div>
<div class="easyeditor-modal-content-body">
<button class="easyeditor-modal-close">x</button>
<mark>{{ Modal body html here }}</mark>
</div>
</div>
</div></pre>
<p class="p">Working with modal window: </p>
<pre class="code">this.<mark>openModal</mark>('#your-selector-ID-not-class');
Usage:
------
EasyEditor.prototype.image = function(){
var _this = this;
var settings = {
buttonIdentifier: 'insert-image',
buttonHtml: 'Insert image',
clickHandler: function(){
_this.<mark>openModal</mark>('#easyeditor-modal-1');
}
};
_this.injectButton(settings);
};
</pre>
<p class="p">When you open modal you must close it by closeModal('#selection-id-name') and when modal opened <mark>insertAtCaret</mark> will not work. In that case you <mark>insertHtml</mark>. <mark>insertHtml</mark> only works when modal has opened!</p>
<pre class="code">easyEditor.insertHtml('<figure><img src="http://placehold.it/500x300" alt=""></figure>');
easyEditor.closeModal('#easyeditor-modal-1');
Usage:
------
EasyEditor.prototype.image = function(){
var _this = this;
var settings = {
buttonIdentifier: 'insert-image',
buttonHtml: 'Insert image',
clickHandler: function(){
_this.<mark>openModal</mark>('#easyeditor-modal-1');
}
};
_this.injectButton(settings);
};
jQuery(document).ready(function($) {
var <mark>easyEditor</mark> = new EasyEditor('#editor', {
buttons: ['bold', 'italic', 'link', 'image']
});
$loader = $('.easyeditor-modal-content-body-loader');
$('.easyeditor-modal-content-body').find('form').ajaxForm({
beforeSend: function() {
$loader.css('width', '0%');
},
uploadProgress: function(event, position, total, percentComplete) {
$loader.css('width', percentComplete + '%');
},
success: function() {
$loader.css('width', '100%');
},
complete: function(get) {
if(get.responseText != 'null') {
<mark>easyEditor</mark>.<mark>insertHtml</mark>('<figure><img src="uploader_sdk/images/'+ get.responseText +'" alt=""></figure>');
<mark>easyEditor</mark>.<mark>closeModal</mark>('#easyeditor-modal-1');
}
}
});
});</pre>
<footer>
EasyEditor is completely free and open source for educational and commercial purpose. Do whatever you want, i don't give a F!
<br>Github URL - <a href="https://github.com/im4aLL/easyeditor" target="_blank">https://github.com/im4aLL/easyeditor</a> Made with ❤ by <a href="http://habibhadi.com" target="_blank">Habib Hadi</a>
<br>Hadi: I'm not that good in JS, please improve it as the way you want. As it requires hard work & time to accomplish that so i expect a thanks at least :)
</footer>
<!-- comment starts -->
<script src="https://apis.google.com/js/plusone.js"></script>
<div id="comments"></div>
<script>
gapi.comments.render('comments', {
href: window.location,
width: '960',
first_party_property: 'BLOGGER',
view_type: 'FILTERED_POSTMOD'
});
</script>
<!-- comment starts -->
</div>
</body>
</html>