19
19
//,+ "<a class='btn' data-wysihtml5-command='underline' title='CTRL+U'>Underline</a>"
20
20
+ "</div>"
21
21
+ "</li>" ,
22
- "lists" : "<li>"
23
- + "<div class='btn-group'>"
24
- + "<a class='btn' data-wysihtml5-command='insertUnorderedList' title='Unordered List'><i class='icon-list'></i></a>"
25
- + "<a class='btn' data-wysihtml5-command='insertOrderedList' title='Ordered List'><i class='icon-th-list'></i></a>"
26
- + "<a class='btn' data-wysihtml5-command='Outdent' title='Outdent'><i class='icon-indent-right'></i></a>"
27
- + "<a class='btn' data-wysihtml5-command='Indent' title='Indent'><i class='icon-indent-left'></i></a>"
28
- + "</div>"
29
- + "</li>" ,
22
+ "lists" : "<li>"
23
+ + "<div class='btn-group'>"
24
+ + "<a class='btn' data-wysihtml5-command='insertUnorderedList' title='Unordered List'><i class='icon-list'></i></a>"
25
+ + "<a class='btn' data-wysihtml5-command='insertOrderedList' title='Ordered List'><i class='icon-th-list'></i></a>"
26
+ + "<a class='btn' data-wysihtml5-command='Outdent' title='Outdent'><i class='icon-indent-right'></i></a>"
27
+ + "<a class='btn' data-wysihtml5-command='Indent' title='Indent'><i class='icon-indent-left'></i></a>"
28
+ + "</div>"
29
+ + "</li>" ,
30
+
31
+ "link" : "<li>"
32
+
33
+ + "<div class='bootstrap-wysihtml5-insert-link-modal modal hide fade'>"
34
+ + "<div class='modal-header'>"
35
+ + "<a class='close' data-dismiss='modal'>×</a>"
36
+ + "<h3>Insert Link</h3>"
37
+ + "</div>"
38
+ + "<div class='modal-body'>"
39
+ + "<input value='http://' class='bootstrap-wysihtml5-insert-link-url input-xlarge'>"
40
+ + "</div>"
41
+ + "<div class='modal-footer'>"
42
+ + "<a href='#' class='btn' data-dismiss='modal'>Cancel</a>"
43
+ + "<a href='#' class='btn btn-primary' data-dismiss='modal'>Insert link</a>"
44
+ + "</div>"
45
+ + "</div>"
46
+
47
+ + "<a class='btn' data-wysihtml5-command='createLink' title='Link'><i class='icon-share'></i></a>"
48
+
49
+ + "</li>" ,
50
+
51
+ "image" : "<li>"
52
+
53
+ + "<div class='bootstrap-wysihtml5-insert-image-modal modal hide fade'>"
54
+ + "<div class='modal-header'>"
55
+ + "<a class='close' data-dismiss='modal'>×</a>"
56
+ + "<h3>Insert Image</h3>"
57
+ + "</div>"
58
+ + "<div class='modal-body'>"
59
+ + "<input value='http://' class='bootstrap-wysihtml5-insert-link-url input-xlarge'>"
60
+ + "</div>"
61
+ + "<div class='modal-footer'>"
62
+ + "<a href='#' class='btn' data-dismiss='modal'>Cancel</a>"
63
+ + "<a href='#' class='btn btn-primary' data-dismiss='modal'>Insert image</a>"
64
+ + "</div>"
65
+ + "</div>"
66
+
67
+ + "<a class='btn' data-wysihtml5-command='insertImage' title='Insert image'><i class='icon-picture'></i></a>"
68
+
69
+ + "</li>" ,
30
70
31
71
"html" :
32
72
"<li>"
41
81
"emphasis" : true ,
42
82
"lists" : true ,
43
83
"html" : false ,
84
+ "link" : true ,
85
+ "image" : false ,
44
86
events : { } ,
45
87
parserRules : {
46
88
tags : {
53
95
"h1" : { } ,
54
96
"h2" : { } ,
55
97
"u" : 1 ,
98
+ "img" : {
99
+ "check_attributes" : {
100
+ "width" : "numbers" ,
101
+ "alt" : "alt" ,
102
+ "src" : "url" ,
103
+ "height" : "numbers"
104
+ }
105
+ } ,
56
106
"a" : {
57
107
set_attributes : {
58
108
target : "_blank" ,
70
120
this . el = el ;
71
121
this . toolbar = this . createToolbar ( el , options || defaultOptions ) ;
72
122
this . editor = this . createEditor ( options ) ;
123
+
124
+ window . editor = this . editor ;
73
125
74
126
$ ( 'iframe.wysihtml5-sandbox' ) . each ( function ( i , el ) {
75
127
$ ( el . contentWindow ) . off ( 'focus.wysihtml5' ) . on ( {
78
130
}
79
131
} ) ;
80
132
} ) ;
133
+
134
+
81
135
} ;
82
136
83
137
Wysihtml5 . prototype = {
105
159
} ,
106
160
107
161
createToolbar : function ( el , options ) {
162
+ var self = this ;
108
163
var toolbar = $ ( "<ul/>" , {
109
- id : el . attr ( 'id' ) + "-wysihtml5-toolbar" ,
110
- class : "wysihtml5-toolbar" ,
111
- style : "display:none"
112
- } ) ;
164
+ 'id' : el . attr ( 'id' ) + "-wysihtml5-toolbar" ,
165
+ ' class' : "wysihtml5-toolbar" ,
166
+ ' style' : "display:none"
167
+ } ) ;
113
168
114
169
for ( var key in defaultOptions ) {
115
170
var value = false ;
126
181
toolbar . append ( templates [ key ] ) ;
127
182
128
183
if ( key == "html" ) {
129
- var changeViewSelector = "a[data-wysihtml5-action='change_view']" ;
130
- toolbar . find ( changeViewSelector ) . click ( function ( e ) {
131
- toolbar . find ( 'a.btn' ) . not ( changeViewSelector ) . toggleClass ( 'disabled' ) ;
132
- } ) ;
184
+ this . initHtml ( toolbar ) ;
185
+ }
186
+
187
+ if ( key == "link" ) {
188
+ this . initInsertLink ( toolbar ) ;
189
+ }
190
+
191
+ if ( key == "image" ) {
192
+ this . initInsertImage ( toolbar ) ;
133
193
}
134
194
}
135
195
}
144
204
this . el . before ( toolbar ) ;
145
205
146
206
return toolbar ;
207
+ } ,
208
+
209
+ initHtml : function ( toolbar ) {
210
+ var changeViewSelector = "a[data-wysihtml5-action='change_view']" ;
211
+ toolbar . find ( changeViewSelector ) . click ( function ( e ) {
212
+ toolbar . find ( 'a.btn' ) . not ( changeViewSelector ) . toggleClass ( 'disabled' ) ;
213
+ } ) ;
214
+ } ,
215
+
216
+ initInsertImage : function ( toolbar ) {
217
+ var self = this ;
218
+ var insertImageModal = toolbar . find ( '.bootstrap-wysihtml5-insert-image-modal' ) ;
219
+ var urlInput = insertImageModal . find ( '.bootstrap-wysihtml5-insert-image-url' ) ;
220
+ var insertButton = insertImageModal . find ( 'a.btn-primary' ) ;
221
+
222
+ var insertImage = function ( ) {
223
+ var url = urlInput . val ( ) ;
224
+ urlInput . val ( '' ) ;
225
+ self . editor . composer . commands . exec ( "createLink" , {
226
+ href : url ,
227
+ target : "_blank" ,
228
+ rel : "nofollow"
229
+ } ) ;
230
+ } ;
231
+
232
+ urlInput . keypress ( function ( e ) {
233
+ if ( e . which == 13 ) {
234
+ insertImage ( ) ;
235
+ insertImageModal . modal ( 'hide' ) ;
236
+ }
237
+ } ) ;
238
+
239
+ insertButton . click ( insertImage ) ;
240
+
241
+ insertImageModal . on ( 'shown' , function ( ) {
242
+ urlInput . focus ( ) ;
243
+ } ) ;
244
+
245
+ insertImageModal . on ( 'hide' , function ( ) {
246
+ self . editor . currentView . element . focus ( ) ;
247
+ } ) ;
248
+
249
+ toolbar . find ( 'a[data-wysihtml5-command=insertImage]' ) . click ( function ( ) {
250
+ insertImageModal . modal ( 'show' ) ;
251
+ } ) ;
252
+ } ,
253
+
254
+ initInsertLink : function ( toolbar ) {
255
+ var self = this ;
256
+ var insertLinkModal = toolbar . find ( '.bootstrap-wysihtml5-insert-link-modal' ) ;
257
+ var urlInput = insertLinkModal . find ( '.bootstrap-wysihtml5-insert-link-url' ) ;
258
+ var insertButton = insertLinkModal . find ( 'a.btn-primary' ) ;
259
+ var initialValue = urlInput . val ( ) ;
260
+
261
+ var insertLink = function ( ) {
262
+ var url = urlInput . val ( ) ;
263
+ urlInput . val ( initialValue ) ;
264
+ self . editor . composer . commands . exec ( "createLink" , {
265
+ href : url ,
266
+ target : "_blank" ,
267
+ rel : "nofollow"
268
+ } ) ;
269
+ } ;
270
+ var pressedEnter = false ;
271
+
272
+ urlInput . keypress ( function ( e ) {
273
+ if ( e . which == 13 ) {
274
+ insertLink ( ) ;
275
+ insertLinkModal . modal ( 'hide' ) ;
276
+ }
277
+ } ) ;
278
+
279
+ insertButton . click ( insertLink ) ;
280
+
281
+ insertLinkModal . on ( 'shown' , function ( ) {
282
+ urlInput . focus ( ) ;
283
+ } ) ;
284
+
285
+ insertLinkModal . on ( 'hide' , function ( ) {
286
+ self . editor . currentView . element . focus ( ) ;
287
+ } ) ;
288
+
289
+ toolbar . find ( 'a[data-wysihtml5-command=createLink]' ) . click ( function ( ) {
290
+ insertLinkModal . modal ( 'show' ) ;
291
+ } ) ;
147
292
}
148
293
} ;
149
294
156
301
157
302
$ . fn . wysihtml5 . Constructor = Wysihtml5 ;
158
303
159
- } ( window . jQuery , window . wysihtml5 ) ;
304
+ } ( window . jQuery , window . wysihtml5 ) ;
0 commit comments