frayerjj-frontend 0.1.41 → 0.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ckeupload.js +46 -37
- package/src/init.js +14 -2
package/package.json
CHANGED
package/src/ckeupload.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { message } from
|
|
1
|
+
import { message } from './message';
|
|
2
2
|
|
|
3
3
|
export const ckeupload = {
|
|
4
|
-
|
|
5
4
|
init: () => {
|
|
5
|
+
// Ensure ClassicEditor is available
|
|
6
|
+
if (typeof window.ClassicEditor === 'undefined') {
|
|
7
|
+
message.warn('CKEditor not loaded.');
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
6
10
|
|
|
7
11
|
class CkeUploadAdapter {
|
|
8
12
|
constructor(loader, uri, token) {
|
|
@@ -11,6 +15,7 @@ export const ckeupload = {
|
|
|
11
15
|
this.token = token;
|
|
12
16
|
message.verbose('CKEditor Upload Adapter Initialized');
|
|
13
17
|
}
|
|
18
|
+
|
|
14
19
|
upload() {
|
|
15
20
|
return this.loader.file
|
|
16
21
|
.then(file => new Promise((resolve, reject) => {
|
|
@@ -19,26 +24,33 @@ export const ckeupload = {
|
|
|
19
24
|
this._sendRequest(file);
|
|
20
25
|
}));
|
|
21
26
|
}
|
|
27
|
+
|
|
22
28
|
abort() {
|
|
23
29
|
if (this.xhr) this.xhr.abort();
|
|
24
30
|
}
|
|
31
|
+
|
|
25
32
|
_initRequest() {
|
|
26
33
|
const xhr = this.xhr = new XMLHttpRequest();
|
|
27
34
|
xhr.open('POST', this.uri, true);
|
|
28
35
|
xhr.setRequestHeader('X-CSRFToken', this.token);
|
|
29
36
|
xhr.responseType = 'json';
|
|
30
37
|
}
|
|
38
|
+
|
|
31
39
|
_initListeners(resolve, reject, file) {
|
|
32
40
|
const xhr = this.xhr;
|
|
33
41
|
const loader = this.loader;
|
|
34
|
-
const genericErrorText = `Couldn't upload file: ${
|
|
35
|
-
|
|
36
|
-
xhr.addEventListener(
|
|
37
|
-
xhr.addEventListener(
|
|
42
|
+
const genericErrorText = `Couldn't upload file: ${file.name}.`;
|
|
43
|
+
|
|
44
|
+
xhr.addEventListener('error', () => reject(genericErrorText));
|
|
45
|
+
xhr.addEventListener('abort', () => reject());
|
|
46
|
+
xhr.addEventListener('load', () => {
|
|
38
47
|
const response = xhr.response;
|
|
39
|
-
if (!response || response.error)
|
|
48
|
+
if (!response || response.error) {
|
|
49
|
+
return reject(response && response.error ? response.error.message : genericErrorText);
|
|
50
|
+
}
|
|
40
51
|
resolve({ default: response.url });
|
|
41
52
|
});
|
|
53
|
+
|
|
42
54
|
if (xhr.upload) {
|
|
43
55
|
xhr.upload.addEventListener('progress', evt => {
|
|
44
56
|
if (evt.lengthComputable) {
|
|
@@ -48,47 +60,44 @@ export const ckeupload = {
|
|
|
48
60
|
});
|
|
49
61
|
}
|
|
50
62
|
}
|
|
63
|
+
|
|
51
64
|
_sendRequest(file) {
|
|
52
65
|
const data = new FormData();
|
|
53
66
|
data.append('file', file);
|
|
54
67
|
this.xhr.send(data);
|
|
55
68
|
}
|
|
56
|
-
}
|
|
69
|
+
}
|
|
57
70
|
|
|
58
|
-
|
|
71
|
+
// Register the upload adapter plugin
|
|
72
|
+
window.CkeUploadAdapterPlugin = function (editor) {
|
|
59
73
|
editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
|
|
60
|
-
|
|
74
|
+
const uri = document.querySelector('meta[name="asset-upload"]').getAttribute('content');
|
|
75
|
+
const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
76
|
+
return new CkeUploadAdapter(loader, uri, token);
|
|
61
77
|
};
|
|
62
78
|
};
|
|
63
79
|
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
// Initialize editors
|
|
66
81
|
document.querySelectorAll('.wysiwyg').forEach(el => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
editors[el.id] = editor;
|
|
87
|
-
}).catch( error => {
|
|
88
|
-
console.error( 'There was a problem initializing the editor.', error );
|
|
89
|
-
});
|
|
90
|
-
} else message.warn('CKEditor not loaded.');
|
|
82
|
+
ClassicEditor.create(el, {
|
|
83
|
+
licenseKey: 'GPL',
|
|
84
|
+
htmlSupport: {
|
|
85
|
+
allow: [
|
|
86
|
+
{
|
|
87
|
+
name: /.*/,
|
|
88
|
+
attributes: true,
|
|
89
|
+
classes: true,
|
|
90
|
+
styles: true
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
extraPlugins: [window.CkeUploadAdapterPlugin]
|
|
95
|
+
}).then(editor => {
|
|
96
|
+
if (!window.editors) window.editors = [];
|
|
97
|
+
window.editors[el.id] = editor;
|
|
98
|
+
}).catch(error => {
|
|
99
|
+
console.error('There was a problem initializing the editor.', error);
|
|
100
|
+
});
|
|
91
101
|
});
|
|
92
|
-
|
|
93
102
|
}
|
|
94
103
|
};
|
package/src/init.js
CHANGED
|
@@ -24,11 +24,23 @@ export const init = () => {
|
|
|
24
24
|
loading.init();
|
|
25
25
|
|
|
26
26
|
window.addEventListener('load', () => {
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
message.verbose('Page Loaded, Initializing');
|
|
29
29
|
validate.init();
|
|
30
30
|
modal.ajax.init();
|
|
31
|
-
ckeupload
|
|
31
|
+
// Ensure ClassicEditor is available before initializing ckeupload
|
|
32
|
+
if (typeof window.ClassicEditor !== 'undefined') {
|
|
33
|
+
ckeupload.init();
|
|
34
|
+
} else {
|
|
35
|
+
message.warn('CKEditor not loaded. Retrying in 1 second...');
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
if (typeof window.ClassicEditor !== 'undefined') {
|
|
38
|
+
ckeupload.init();
|
|
39
|
+
} else {
|
|
40
|
+
message.error('CKEditor failed to load.');
|
|
41
|
+
}
|
|
42
|
+
}, 1000); // Retry after 1 second
|
|
43
|
+
}
|
|
32
44
|
|
|
33
45
|
// Updates the id in the form action inside a modal. Used for delete confirm and edit modals.
|
|
34
46
|
document.querySelectorAll('.modal-uuid-update').forEach(el => {
|