vue_crud 0.1.9.6 → 0.1.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/vue_crud/froala_generator.rb +12 -0
  3. data/lib/generators/vue_crud/sortable.rb +10 -0
  4. data/lib/generators/vue_crud/templates/assets/images/froala_editor/color_picker.png +0 -0
  5. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/froala_editor.js +11089 -0
  6. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/languages/en_gb.js +178 -0
  7. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/languages/zh_cn.js +234 -0
  8. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/languages/zh_tw.js +234 -0
  9. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/align.js +119 -0
  10. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/char_counter.js +150 -0
  11. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/code_beautifier.js +3271 -0
  12. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/code_view.js +311 -0
  13. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/colors.js +350 -0
  14. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/draggable.js +379 -0
  15. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/emoticons.js +347 -0
  16. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/entities.js +113 -0
  17. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/file.js +609 -0
  18. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/font_family.js +178 -0
  19. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/font_size.js +116 -0
  20. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/forms.js +415 -0
  21. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/fullscreen.js +209 -0
  22. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/image.js +2401 -0
  23. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/image_manager.js +921 -0
  24. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/inline_style.js +86 -0
  25. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/line_breaker.js +435 -0
  26. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/link.js +997 -0
  27. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/lists.js +382 -0
  28. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/paragraph_format.js +293 -0
  29. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/paragraph_style.js +139 -0
  30. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/quick_insert.js +342 -0
  31. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/quote.js +138 -0
  32. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/save.js +176 -0
  33. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/table.js +3123 -0
  34. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/url.js +113 -0
  35. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/video.js +1135 -0
  36. data/lib/generators/vue_crud/templates/assets/javascripts/sortable.js +1249 -0
  37. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/froala_editor.scss +1008 -0
  38. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/froala_style.scss +273 -0
  39. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/char_counter.scss +46 -0
  40. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/code_view.scss +102 -0
  41. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/colors.scss +129 -0
  42. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/draggable.scss +32 -0
  43. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/emoticons.scss +27 -0
  44. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/file.scss +135 -0
  45. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/fullscreen.scss +28 -0
  46. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/image.scss +233 -0
  47. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/image_manager.scss +370 -0
  48. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/line_breaker.scss +26 -0
  49. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/quick_insert.scss +56 -0
  50. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/table.scss +156 -0
  51. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/video.scss +136 -0
  52. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/themes/dark.scss +1087 -0
  53. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/themes/gray.scss +1087 -0
  54. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/themes/red.scss +1087 -0
  55. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/themes/royal.scss +1087 -0
  56. data/lib/generators/vue_crud/templates/vue_crud.html +54 -71
  57. data/lib/vue_crud/version.rb +1 -1
  58. data/vendor/assets/javascripts/vue_crud.js +212 -59
  59. metadata +56 -2
@@ -0,0 +1,609 @@
1
+ /*!
2
+ * froala_editor v2.3.3 (https://www.froala.com/wysiwyg-editor)
3
+ * License https://froala.com/wysiwyg-editor/terms/
4
+ * Copyright 2014-2016 Froala Labs
5
+ */
6
+
7
+ (function (factory) {
8
+ if (typeof define === 'function' && define.amd) {
9
+ // AMD. Register as an anonymous module.
10
+ define(['jquery'], factory);
11
+ } else if (typeof module === 'object' && module.exports) {
12
+ // Node/CommonJS
13
+ module.exports = function( root, jQuery ) {
14
+ if ( jQuery === undefined ) {
15
+ // require('jQuery') returns a factory that requires window to
16
+ // build a jQuery instance, we normalize how we use modules
17
+ // that require this pattern but the window provided is a noop
18
+ // if it's defined (how jquery works)
19
+ if ( typeof window !== 'undefined' ) {
20
+ jQuery = require('jquery');
21
+ }
22
+ else {
23
+ jQuery = require('jquery')(root);
24
+ }
25
+ }
26
+ factory(jQuery);
27
+ return jQuery;
28
+ };
29
+ } else {
30
+ // Browser globals
31
+ factory(jQuery);
32
+ }
33
+ }(function ($) {
34
+
35
+ 'use strict';
36
+
37
+ $.extend($.FE.POPUP_TEMPLATES, {
38
+ 'file.insert': '[_BUTTONS_][_UPLOAD_LAYER_][_PROGRESS_BAR_]'
39
+ })
40
+
41
+ // Extend defaults.
42
+ $.extend($.FE.DEFAULTS, {
43
+ fileUploadURL: 'http://i.froala.com/upload',
44
+ fileUploadParam: 'file',
45
+ fileUploadParams: {},
46
+ fileUploadToS3: false,
47
+ fileUploadMethod: 'POST',
48
+ fileMaxSize: 10 * 1024 * 1024,
49
+ fileAllowedTypes: ['*'],
50
+ fileInsertButtons: ['fileBack', '|'],
51
+ fileUseSelectedText: false
52
+ });
53
+
54
+
55
+ $.FE.PLUGINS.file = function (editor) {
56
+ var BAD_LINK = 1;
57
+ var MISSING_LINK = 2;
58
+ var ERROR_DURING_UPLOAD = 3;
59
+ var BAD_RESPONSE = 4;
60
+ var MAX_SIZE_EXCEEDED = 5;
61
+ var BAD_FILE_TYPE = 6;
62
+ var NO_CORS_IE = 7;
63
+
64
+ var error_messages = {};
65
+ error_messages[BAD_LINK] = 'File cannot be loaded from the passed link.';
66
+ error_messages[MISSING_LINK] = 'No link in upload response.';
67
+ error_messages[ERROR_DURING_UPLOAD] = 'Error during file upload.';
68
+ error_messages[BAD_RESPONSE] = 'Parsing response failed.';
69
+ error_messages[MAX_SIZE_EXCEEDED] = 'File is too large.';
70
+ error_messages[BAD_FILE_TYPE] = 'File file type is invalid.';
71
+ error_messages[NO_CORS_IE] = 'Files can be uploaded only to same domain in IE 8 and IE 9.';
72
+
73
+ function showInsertPopup () {
74
+ var $btn = editor.$tb.find('.fr-command[data-cmd="insertFile"]');
75
+
76
+ var $popup = editor.popups.get('file.insert');
77
+ if (!$popup) $popup = _initInsertPopup();
78
+
79
+ hideProgressBar();
80
+ if (!$popup.hasClass('fr-active')) {
81
+ editor.popups.refresh('file.insert');
82
+ editor.popups.setContainer('file.insert', editor.$tb);
83
+
84
+ var left = $btn.offset().left + $btn.outerWidth() / 2;
85
+ var top = $btn.offset().top + (editor.opts.toolbarBottom ? 0 : $btn.outerHeight());
86
+ editor.popups.show('file.insert', left, top, $btn.outerHeight());
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Show progress bar.
92
+ */
93
+ function showProgressBar () {
94
+ var $popup = editor.popups.get('file.insert');
95
+ if (!$popup) $popup = _initInsertPopup();
96
+
97
+ $popup.find('.fr-layer.fr-active').removeClass('fr-active').addClass('fr-pactive');
98
+ $popup.find('.fr-file-progress-bar-layer').addClass('fr-active');
99
+ $popup.find('.fr-buttons').hide();
100
+
101
+ _setProgressMessage('Uploading', 0);
102
+ }
103
+
104
+ /**
105
+ * Hide progress bar.
106
+ */
107
+ function hideProgressBar (dismiss) {
108
+ var $popup = editor.popups.get('file.insert');
109
+
110
+ if ($popup) {
111
+ $popup.find('.fr-layer.fr-pactive').addClass('fr-active').removeClass('fr-pactive');
112
+ $popup.find('.fr-file-progress-bar-layer').removeClass('fr-active');
113
+ $popup.find('.fr-buttons').show();
114
+
115
+ if (dismiss) {
116
+ editor.popups.show('file.insert', null, null);
117
+ }
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Set a progress message.
123
+ */
124
+ function _setProgressMessage (message, progress) {
125
+ var $popup = editor.popups.get('file.insert');
126
+
127
+ if ($popup) {
128
+ var $layer = $popup.find('.fr-file-progress-bar-layer');
129
+ $layer.find('h3').text(message + (progress ? ' ' + progress + '%' : ''));
130
+
131
+ $layer.removeClass('fr-error');
132
+
133
+ if (progress) {
134
+ $layer.find('div').removeClass('fr-indeterminate');
135
+ $layer.find('div > span').css('width', progress + '%');
136
+ }
137
+ else {
138
+ $layer.find('div').addClass('fr-indeterminate');
139
+ }
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Show error message to the user.
145
+ */
146
+ function _showErrorMessage (message) {
147
+ showProgressBar();
148
+ var $popup = editor.popups.get('file.insert');
149
+ var $layer = $popup.find('.fr-file-progress-bar-layer');
150
+ $layer.addClass('fr-error')
151
+ $layer.find('h3').text(message);
152
+ }
153
+
154
+ /**
155
+ * Insert the uploaded file.
156
+ */
157
+ function insert (link, text, response) {
158
+ editor.edit.on();
159
+
160
+ // Focus in the editor.
161
+ editor.events.focus(true);
162
+ editor.selection.restore();
163
+
164
+ // Insert the link.
165
+ editor.html.insert('<a href="' + link + '" id="fr-inserted-file" class="fr-file">' + (text || editor.selection.text()) + '</a>');
166
+
167
+ // Get the file.
168
+ var $file = editor.$el.find('#fr-inserted-file');
169
+ $file.removeAttr('id');
170
+
171
+ editor.popups.hide('file.insert');
172
+
173
+ editor.undo.saveStep();
174
+
175
+ editor.events.trigger('file.inserted', [$file, response]);
176
+ }
177
+
178
+ /**
179
+ * Parse file response.
180
+ */
181
+ function _parseResponse (response) {
182
+ try {
183
+ if (editor.events.trigger('file.uploaded', [response], true) === false) {
184
+ editor.edit.on();
185
+ return false;
186
+ }
187
+
188
+ var resp = $.parseJSON(response);
189
+ if (resp.link) {
190
+ return resp;
191
+ } else {
192
+ // No link in upload request.
193
+ _throwError(MISSING_LINK, response);
194
+ return false;
195
+ }
196
+ } catch (ex) {
197
+
198
+ // Bad response.
199
+ _throwError(BAD_RESPONSE, response);
200
+ return false;
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Parse file response.
206
+ */
207
+ function _parseXMLResponse (response) {
208
+ try {
209
+ var link = $(response).find('Location').text();
210
+ var key = $(response).find('Key').text();
211
+
212
+ if (editor.events.trigger('file.uploadedToS3', [link, key, response], true) === false) {
213
+ editor.edit.on();
214
+ return false;
215
+ }
216
+
217
+ return link;
218
+ } catch (ex) {
219
+ // Bad response.
220
+ _throwError(BAD_RESPONSE, response);
221
+ return false;
222
+ }
223
+ }
224
+
225
+ /**
226
+ * File was uploaded to the server and we have a response.
227
+ */
228
+ function _fileUploaded (text) {
229
+ var status = this.status;
230
+ var response = this.response;
231
+ var responseXML = this.responseXML;
232
+ var responseText = this.responseText;
233
+
234
+ try {
235
+ if (editor.opts.fileUploadToS3) {
236
+ if (status == 201) {
237
+ var link = _parseXMLResponse(responseXML);
238
+ if (link) {
239
+ insert(link, text, response || responseXML);
240
+ }
241
+ } else {
242
+ _throwError(BAD_RESPONSE, response || responseXML);
243
+ }
244
+ }
245
+ else {
246
+ if (status >= 200 && status < 300) {
247
+ var resp = _parseResponse(responseText);
248
+ if (resp) {
249
+ insert(resp.link, text, response || responseText);
250
+ }
251
+ }
252
+ else {
253
+ _throwError(ERROR_DURING_UPLOAD, response || responseText);
254
+ }
255
+ }
256
+ } catch (ex) {
257
+ // Bad response.
258
+ _throwError(BAD_RESPONSE, response || responseText);
259
+ }
260
+ }
261
+
262
+ /**
263
+ * File upload error.
264
+ */
265
+ function _fileUploadError () {
266
+ _throwError(BAD_RESPONSE, this.response || this.responseText || this.responseXML);
267
+ }
268
+
269
+ /**
270
+ * File upload progress.
271
+ */
272
+ function _fileUploadProgress (e) {
273
+ if (e.lengthComputable) {
274
+ var complete = (e.loaded / e.total * 100 | 0);
275
+ _setProgressMessage('Uploading', complete);
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Throw an file error.
281
+ */
282
+ function _throwError (code, response) {
283
+ editor.edit.on();
284
+ _showErrorMessage(editor.language.translate('Something went wrong. Please try again.'));
285
+
286
+ editor.events.trigger('file.error', [{
287
+ code: code,
288
+ message: error_messages[code]
289
+ }, response]);
290
+ }
291
+
292
+ /**
293
+ * File upload aborted.
294
+ */
295
+ function _fileUploadAborted () {
296
+ editor.edit.on();
297
+ hideProgressBar(true);
298
+ }
299
+
300
+ function upload (files) {
301
+ // Check if we should cancel the file upload.
302
+ if (editor.events.trigger('file.beforeUpload', [files]) === false) {
303
+ return false;
304
+ }
305
+
306
+ // Make sure we have what to upload.
307
+ if (typeof files != 'undefined' && files.length > 0) {
308
+ var file = files[0];
309
+
310
+ // Check file max size.
311
+ if (file.size > editor.opts.fileMaxSize) {
312
+ _throwError(MAX_SIZE_EXCEEDED);
313
+ return false;
314
+ }
315
+
316
+ // Check file types.
317
+ if (editor.opts.fileAllowedTypes.indexOf('*') < 0 && editor.opts.fileAllowedTypes.indexOf(file.type.replace(/file\//g,'')) < 0) {
318
+ _throwError(BAD_FILE_TYPE);
319
+ return false;
320
+ }
321
+
322
+ // Create form Data.
323
+ var form_data;
324
+ if (editor.drag_support.formdata) {
325
+ form_data = editor.drag_support.formdata ? new FormData() : null;
326
+ }
327
+
328
+ // Prepare form data for request.
329
+ if (form_data) {
330
+ var key;
331
+
332
+ // Upload to S3.
333
+ if (editor.opts.fileUploadToS3 !== false) {
334
+ form_data.append('key', editor.opts.fileUploadToS3.keyStart + (new Date()).getTime() + '-' + (file.name || 'untitled'));
335
+ form_data.append('success_action_status', '201');
336
+ form_data.append('X-Requested-With', 'xhr');
337
+ form_data.append('Content-Type', file.type);
338
+
339
+ for (key in editor.opts.fileUploadToS3.params) {
340
+ if (editor.opts.fileUploadToS3.params.hasOwnProperty(key)) {
341
+ form_data.append(key, editor.opts.fileUploadToS3.params[key]);
342
+ }
343
+ }
344
+ }
345
+
346
+ // Add upload params.
347
+ for (key in editor.opts.fileUploadParams) {
348
+ if (editor.opts.fileUploadParams.hasOwnProperty(key)) {
349
+ form_data.append(key, editor.opts.fileUploadParams[key]);
350
+ }
351
+ }
352
+
353
+ // Set the file in the request.
354
+ form_data.append(editor.opts.fileUploadParam, file);
355
+
356
+ // Create XHR request.
357
+ var url = editor.opts.fileUploadURL;
358
+ if (editor.opts.fileUploadToS3) {
359
+ url = 'https://' + editor.opts.fileUploadToS3.region + '.amazonaws.com/' + editor.opts.fileUploadToS3.bucket;
360
+ }
361
+ var xhr = editor.core.getXHR(url, editor.opts.fileUploadMethod);
362
+
363
+ // Set upload events.
364
+ xhr.onload = function () {
365
+ _fileUploaded.call(xhr, [(editor.opts.fileUseSelectedText ? null : file.name)]);
366
+ };
367
+ xhr.onerror = _fileUploadError;
368
+ xhr.upload.onprogress = _fileUploadProgress;
369
+ xhr.onabort = _fileUploadAborted;
370
+
371
+ showProgressBar();
372
+ editor.edit.off();
373
+
374
+ var $popup = editor.popups.get('file.insert');
375
+ if ($popup) {
376
+ $popup.off('abortUpload').on('abortUpload', function () {
377
+ if (xhr.readyState != 4) {
378
+ xhr.abort();
379
+ }
380
+ })
381
+ }
382
+
383
+ // Send data.
384
+ xhr.send(form_data);
385
+ }
386
+ }
387
+ }
388
+
389
+ function _bindInsertEvents ($popup) {
390
+ // Drag over the dropable area.
391
+ editor.events.$on($popup, 'dragover dragenter', '.fr-file-upload-layer', function () {
392
+ $(this).addClass('fr-drop');
393
+ return false;
394
+ }, true);
395
+
396
+ // Drag end.
397
+ editor.events.$on($popup, 'dragleave dragend', '.fr-file-upload-layer', function () {
398
+ $(this).removeClass('fr-drop');
399
+ return false;
400
+ }, true);
401
+
402
+ // Drop.
403
+ editor.events.$on($popup, 'drop', '.fr-file-upload-layer', function (e) {
404
+ e.preventDefault();
405
+ e.stopPropagation();
406
+
407
+ $(this).removeClass('fr-drop');
408
+
409
+ var dt = e.originalEvent.dataTransfer;
410
+ if (dt && dt.files) {
411
+ var inst = $popup.data('instance') || editor;
412
+ inst.file.upload(dt.files);
413
+ }
414
+ }, true);
415
+
416
+ editor.events.$on($popup, 'change', '.fr-file-upload-layer input[type="file"]', function () {
417
+ if (this.files) {
418
+ var inst = $popup.data('instance') || editor;
419
+ inst.file.upload(this.files);
420
+ }
421
+
422
+ // Else IE 9 case.
423
+
424
+ // Chrome fix.
425
+ $(this).val('');
426
+ }, true);
427
+ }
428
+
429
+ function _hideInsertPopup () {
430
+ hideProgressBar();
431
+ }
432
+
433
+ function _initInsertPopup (delayed) {
434
+ if (delayed) {
435
+ editor.popups.onHide('file.insert', _hideInsertPopup);
436
+
437
+ return true;
438
+ }
439
+
440
+ // Image buttons.
441
+ var file_buttons = '';
442
+ file_buttons = '<div class="fr-buttons">' + editor.button.buildList(editor.opts.fileInsertButtons) + '</div>';
443
+
444
+ // File upload layer.
445
+ var upload_layer = '';
446
+ upload_layer = '<div class="fr-file-upload-layer fr-layer fr-active" id="fr-file-upload-layer-' + editor.id + '"><strong>' + editor.language.translate('Drop file') + '</strong><br>(' + editor.language.translate('or click') + ')<div class="fr-form"><input type="file" name="' + editor.opts.fileUploadParam + '" accept="/*" tabIndex="-1"></div></div>'
447
+
448
+
449
+ // Progress bar.
450
+ var progress_bar_layer = '<div class="fr-file-progress-bar-layer fr-layer"><h3 class="fr-message">Uploading</h3><div class="fr-loader"><span class="fr-progress"></span></div><div class="fr-action-buttons"><button type="button" class="fr-command" data-cmd="fileDismissError" tabIndex="2">OK</button></div></div>';
451
+
452
+ var template = {
453
+ buttons: file_buttons,
454
+ upload_layer: upload_layer,
455
+ progress_bar: progress_bar_layer
456
+ };
457
+
458
+ // Set the template in the popup.
459
+ var $popup = editor.popups.create('file.insert', template);
460
+
461
+ _bindInsertEvents($popup);
462
+
463
+ return $popup;
464
+ }
465
+
466
+ function _onRemove (link) {
467
+ if ($(link).hasClass('fr-file')) {
468
+ return editor.events.trigger('file.unlink', [link]);
469
+ }
470
+ }
471
+
472
+ function _drop (e) {
473
+ // Check if we are dropping files.
474
+ var dt = e.originalEvent.dataTransfer;
475
+ if (dt && dt.files && dt.files.length) {
476
+ var file = dt.files[0];
477
+ if (file && typeof file.type != 'undefined') {
478
+ // Dropped file is an file that we allow.
479
+ if (file.type.indexOf('image') < 0 && (editor.opts.fileAllowedTypes.indexOf(file.type) >= 0 || editor.opts.fileAllowedTypes.indexOf('*') >= 0)) {
480
+ editor.markers.remove();
481
+ editor.markers.insertAtPoint(e.originalEvent);
482
+ editor.$el.find('.fr-marker').replaceWith($.FE.MARKERS);
483
+
484
+ // Hide popups.
485
+ editor.popups.hideAll();
486
+
487
+ // Show the file insert popup.
488
+ var $popup = editor.popups.get('file.insert');
489
+ if (!$popup) $popup = _initInsertPopup();
490
+ editor.popups.setContainer('file.insert', $(editor.opts.scrollableContainer));
491
+ editor.popups.show('file.insert', e.originalEvent.pageX, e.originalEvent.pageY);
492
+ showProgressBar();
493
+
494
+ // Upload files.
495
+ upload(dt.files);
496
+
497
+ // Cancel anything else.
498
+ e.preventDefault();
499
+ e.stopPropagation();
500
+
501
+ return false;
502
+ }
503
+ }
504
+ }
505
+ }
506
+
507
+ function _initEvents() {
508
+ // Drop inside the editor.
509
+ editor.events.on('drop', _drop);
510
+
511
+ editor.events.$on(editor.$win, 'keydown', function (e) {
512
+ var key_code = e.which;
513
+ var $popup = editor.popups.get('file.insert');
514
+ if ($popup && key_code == $.FE.KEYCODE.ESC) {
515
+ $popup.trigger('abortUpload');
516
+ }
517
+ });
518
+
519
+ editor.events.on('destroy', function () {
520
+ var $popup = editor.popups.get('file.insert');
521
+ if ($popup) {
522
+ $popup.trigger('abortUpload');
523
+ }
524
+ });
525
+ }
526
+
527
+ function back () {
528
+ editor.events.disableBlur();
529
+ editor.selection.restore();
530
+ editor.events.enableBlur();
531
+
532
+ editor.popups.hide('file.insert');
533
+ editor.toolbar.showInline();
534
+ }
535
+
536
+ /*
537
+ * Initialize.
538
+ */
539
+ function _init () {
540
+ _initEvents();
541
+
542
+ editor.events.on('link.beforeRemove', _onRemove);
543
+
544
+ _initInsertPopup(true);
545
+ }
546
+
547
+ return {
548
+ _init: _init,
549
+ showInsertPopup: showInsertPopup,
550
+ upload: upload,
551
+ insert: insert,
552
+ back: back,
553
+ hideProgressBar: hideProgressBar
554
+ }
555
+ }
556
+
557
+ // Insert file button.
558
+ $.FE.DefineIcon('insertFile', { NAME: 'file-o' });
559
+ $.FE.RegisterCommand('insertFile', {
560
+ title: 'Upload File',
561
+ undo: false,
562
+ focus: true,
563
+ refreshAfterCallback: false,
564
+ popup: true,
565
+ callback: function () {
566
+ if (!this.popups.isVisible('file.insert')) {
567
+ this.file.showInsertPopup();
568
+ }
569
+ else {
570
+ if (this.$el.find('.fr-marker')) {
571
+ this.events.disableBlur();
572
+ this.selection.restore();
573
+ }
574
+ this.popups.hide('file.insert');
575
+ }
576
+ },
577
+ plugin: 'file'
578
+ });
579
+
580
+ $.FE.DefineIcon('fileBack', { NAME: 'arrow-left' });
581
+ $.FE.RegisterCommand('fileBack', {
582
+ title: 'Back',
583
+ undo: false,
584
+ focus: false,
585
+ back: true,
586
+ refreshAfterCallback: false,
587
+ callback: function () {
588
+ this.file.back();
589
+ },
590
+ refresh: function ($btn) {
591
+ if (!this.opts.toolbarInline) {
592
+ $btn.addClass('fr-hidden');
593
+ $btn.next('.fr-separator').addClass('fr-hidden');
594
+ }
595
+ else {
596
+ $btn.removeClass('fr-hidden');
597
+ $btn.next('.fr-separator').removeClass('fr-hidden');
598
+ }
599
+ }
600
+ });
601
+
602
+ $.FE.RegisterCommand('fileDismissError', {
603
+ title: 'OK',
604
+ callback: function () {
605
+ this.file.hideProgressBar(true);
606
+ }
607
+ })
608
+
609
+ }));