alchemy-media 0.5.1 → 0.6.1
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/CHANGELOG.md +7 -2
- package/assets/fonts/fontawesome5.15/fa-brands-400.eot +0 -0
- package/assets/fonts/fontawesome5.15/fa-brands-400.svg +3717 -0
- package/assets/fonts/fontawesome5.15/fa-brands-400.ttf +0 -0
- package/assets/fonts/fontawesome5.15/fa-brands-400.woff +0 -0
- package/assets/fonts/fontawesome5.15/fa-brands-400.woff2 +0 -0
- package/assets/fonts/fontawesome5.15/fa-regular-400.eot +0 -0
- package/assets/fonts/fontawesome5.15/fa-regular-400.svg +801 -0
- package/assets/fonts/fontawesome5.15/fa-regular-400.ttf +0 -0
- package/assets/fonts/fontawesome5.15/fa-regular-400.woff +0 -0
- package/assets/fonts/fontawesome5.15/fa-regular-400.woff2 +0 -0
- package/assets/fonts/fontawesome5.15/fa-solid-900.eot +0 -0
- package/assets/fonts/fontawesome5.15/fa-solid-900.svg +5028 -0
- package/assets/fonts/fontawesome5.15/fa-solid-900.ttf +0 -0
- package/assets/fonts/fontawesome5.15/fa-solid-900.woff +0 -0
- package/assets/fonts/fontawesome5.15/fa-solid-900.woff2 +0 -0
- package/assets/stylesheets/alchemy_icons.scss +60 -0
- package/assets/stylesheets/alchemy_svg.scss +9 -0
- package/assets/stylesheets/chimera/mediafield.less +0 -0
- package/assets/stylesheets/element/alchemy_file.scss +3 -0
- package/assets/stylesheets/fontawesome5.15/_animated.scss +20 -0
- package/assets/stylesheets/fontawesome5.15/_bordered-pulled.scss +20 -0
- package/assets/stylesheets/fontawesome5.15/_core.scss +21 -0
- package/assets/stylesheets/fontawesome5.15/_fixed-width.scss +6 -0
- package/assets/stylesheets/fontawesome5.15/_icons.scss +1462 -0
- package/assets/stylesheets/fontawesome5.15/_larger.scss +23 -0
- package/assets/stylesheets/fontawesome5.15/_list.scss +18 -0
- package/assets/stylesheets/fontawesome5.15/_mixins.scss +56 -0
- package/assets/stylesheets/fontawesome5.15/_rotated-flipped.scss +24 -0
- package/assets/stylesheets/fontawesome5.15/_screen-reader.scss +5 -0
- package/assets/stylesheets/fontawesome5.15/_shims.scss +2066 -0
- package/assets/stylesheets/fontawesome5.15/_stacked.scss +31 -0
- package/assets/stylesheets/fontawesome5.15/_variables.scss +1479 -0
- package/assets/stylesheets/fontawesome5.15/brands.scss +23 -0
- package/assets/stylesheets/fontawesome5.15/fontawesome.scss +16 -0
- package/assets/stylesheets/fontawesome5.15/regular.scss +23 -0
- package/assets/stylesheets/fontawesome5.15/solid.scss +24 -0
- package/assets/stylesheets/fontawesome5.15/v4-shims.scss +6 -0
- package/bootstrap.js +1 -0
- package/controller/media_files_controller.js +20 -0
- package/controller/media_gallery_chimera_controller.js +1 -0
- package/element/al_file.js +195 -0
- package/element/al_ico_element.js +17 -0
- package/element/al_svg.js +81 -0
- package/helper/media_helper.js +50 -10
- package/helper/widgets/image_widget.js +46 -0
- package/{lib/field_type → helper_field}/file_field_type.js +5 -3
- package/lib/media_types/image_media_type.js +34 -9
- package/model/media_file_model.js +9 -3
- package/model/media_raw_model.js +529 -529
- package/package.json +6 -6
- package/view/element/al_file.hwk +7 -0
- package/view/form/inputs/edit/file.hwk +8 -0
- package/assets/scripts/chimera/mediafield.js +0 -451
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Font Awesome Free 5.15.1 by @fontawesome - https://fontawesome.com
|
|
3
|
+
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
|
4
|
+
*/
|
|
5
|
+
@import 'variables';
|
|
6
|
+
|
|
7
|
+
@font-face {
|
|
8
|
+
font-family: 'Font Awesome 5 Brands';
|
|
9
|
+
font-style: normal;
|
|
10
|
+
font-weight: 400;
|
|
11
|
+
font-display: $fa-font-display;
|
|
12
|
+
src: url('#{$fa-font-path}/fa-brands-400.eot');
|
|
13
|
+
src: url('#{$fa-font-path}/fa-brands-400.eot?#iefix') format('embedded-opentype'),
|
|
14
|
+
url('#{$fa-font-path}/fa-brands-400.woff2') format('woff2'),
|
|
15
|
+
url('#{$fa-font-path}/fa-brands-400.woff') format('woff'),
|
|
16
|
+
url('#{$fa-font-path}/fa-brands-400.ttf') format('truetype'),
|
|
17
|
+
url('#{$fa-font-path}/fa-brands-400.svg#fontawesome') format('svg');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.fab {
|
|
21
|
+
font-family: 'Font Awesome 5 Brands';
|
|
22
|
+
font-weight: 400;
|
|
23
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Font Awesome Free 5.15.1 by @fontawesome - https://fontawesome.com
|
|
3
|
+
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
|
4
|
+
*/
|
|
5
|
+
@import 'variables';
|
|
6
|
+
@import 'mixins';
|
|
7
|
+
@import 'core';
|
|
8
|
+
@import 'larger';
|
|
9
|
+
@import 'fixed-width';
|
|
10
|
+
@import 'list';
|
|
11
|
+
@import 'bordered-pulled';
|
|
12
|
+
@import 'animated';
|
|
13
|
+
@import 'rotated-flipped';
|
|
14
|
+
@import 'stacked';
|
|
15
|
+
@import 'icons';
|
|
16
|
+
@import 'screen-reader';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Font Awesome Free 5.15.1 by @fontawesome - https://fontawesome.com
|
|
3
|
+
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
|
4
|
+
*/
|
|
5
|
+
@import 'variables';
|
|
6
|
+
|
|
7
|
+
@font-face {
|
|
8
|
+
font-family: 'Font Awesome 5 Free';
|
|
9
|
+
font-style: normal;
|
|
10
|
+
font-weight: 400;
|
|
11
|
+
font-display: $fa-font-display;
|
|
12
|
+
src: url('#{$fa-font-path}/fa-regular-400.eot');
|
|
13
|
+
src: url('#{$fa-font-path}/fa-regular-400.eot?#iefix') format('embedded-opentype'),
|
|
14
|
+
url('#{$fa-font-path}/fa-regular-400.woff2') format('woff2'),
|
|
15
|
+
url('#{$fa-font-path}/fa-regular-400.woff') format('woff'),
|
|
16
|
+
url('#{$fa-font-path}/fa-regular-400.ttf') format('truetype'),
|
|
17
|
+
url('#{$fa-font-path}/fa-regular-400.svg#fontawesome') format('svg');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.far {
|
|
21
|
+
font-family: 'Font Awesome 5 Free';
|
|
22
|
+
font-weight: 400;
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Font Awesome Free 5.15.1 by @fontawesome - https://fontawesome.com
|
|
3
|
+
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
|
4
|
+
*/
|
|
5
|
+
@import 'variables';
|
|
6
|
+
|
|
7
|
+
@font-face {
|
|
8
|
+
font-family: 'Font Awesome 5 Free';
|
|
9
|
+
font-style: normal;
|
|
10
|
+
font-weight: 900;
|
|
11
|
+
font-display: $fa-font-display;
|
|
12
|
+
src: url('#{$fa-font-path}/fa-solid-900.eot');
|
|
13
|
+
src: url('#{$fa-font-path}/fa-solid-900.eot?#iefix') format('embedded-opentype'),
|
|
14
|
+
url('#{$fa-font-path}/fa-solid-900.woff2') format('woff2'),
|
|
15
|
+
url('#{$fa-font-path}/fa-solid-900.woff') format('woff'),
|
|
16
|
+
url('#{$fa-font-path}/fa-solid-900.ttf') format('truetype'),
|
|
17
|
+
url('#{$fa-font-path}/fa-solid-900.svg#fontawesome') format('svg');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.fa,
|
|
21
|
+
.fas {
|
|
22
|
+
font-family: 'Font Awesome 5 Free';
|
|
23
|
+
font-weight: 900;
|
|
24
|
+
}
|
package/bootstrap.js
CHANGED
|
@@ -40,6 +40,7 @@ alchemy.createDir(options.cache);
|
|
|
40
40
|
Router.get('Media::static', /\/media\/static\/(.*)*/, 'MediaFile#serveStatic');
|
|
41
41
|
Router.get('Media::image', options.url + '/{id}', 'MediaFile#image');
|
|
42
42
|
|
|
43
|
+
Router.get('MediaFile#data', '/media/data/{[MediaFile._id]id}', 'MediaFile#data');
|
|
43
44
|
Router.get('MediaFile#info', '/media/info', 'MediaFile#info');
|
|
44
45
|
|
|
45
46
|
// Allow dummy extensions
|
|
@@ -312,6 +312,26 @@ MediaFiles.setAction(function uploadsingle(conduit) {
|
|
|
312
312
|
});
|
|
313
313
|
});
|
|
314
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Get the file data
|
|
317
|
+
*
|
|
318
|
+
* @author Jelle De Loecker <jelle@develry.be>
|
|
319
|
+
* @since 0.5.1
|
|
320
|
+
* @version 0.5.1
|
|
321
|
+
*
|
|
322
|
+
* @param {Conduit} conduit
|
|
323
|
+
* @param {Document.MediaFile} media_file
|
|
324
|
+
*/
|
|
325
|
+
MediaFiles.setAction(function data(conduit, media_file) {
|
|
326
|
+
conduit.setHeader('cache-control', 'public, max-age=3600, must-revalidate');
|
|
327
|
+
|
|
328
|
+
conduit.end({
|
|
329
|
+
name : media_file.name,
|
|
330
|
+
alt : media_file.alt,
|
|
331
|
+
title : media_file.title
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
315
335
|
/**
|
|
316
336
|
* Get info on a file
|
|
317
337
|
*
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The al-image custom element
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.6.0
|
|
6
|
+
* @version 0.6.0
|
|
7
|
+
*/
|
|
8
|
+
const AlFile = Function.inherits('Alchemy.Element.App', function AlFile() {
|
|
9
|
+
return AlFile.super.call(this);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The template code
|
|
14
|
+
*
|
|
15
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
16
|
+
* @since 0.6.0
|
|
17
|
+
* @version 0.6.0
|
|
18
|
+
*/
|
|
19
|
+
AlFile.setTemplateFile('element/al_file');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The stylesheet to load for this element
|
|
23
|
+
*
|
|
24
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
25
|
+
* @since 0.6.0
|
|
26
|
+
* @version 0.6.0
|
|
27
|
+
*/
|
|
28
|
+
AlFile.setStylesheetFile('element/alchemy_file');
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Getter for the select button
|
|
32
|
+
*
|
|
33
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
34
|
+
* @since 0.2.0
|
|
35
|
+
* @version 0.2.0
|
|
36
|
+
*/
|
|
37
|
+
AlFile.addElementGetter('select_button', '.al-file-select-file');
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Getter for the file input
|
|
41
|
+
*
|
|
42
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
43
|
+
* @since 0.2.0
|
|
44
|
+
* @version 0.2.0
|
|
45
|
+
*/
|
|
46
|
+
AlFile.addElementGetter('file_input', '.al-file-input');
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Getter for the preview
|
|
50
|
+
*
|
|
51
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
52
|
+
* @since 0.2.0
|
|
53
|
+
* @version 0.2.0
|
|
54
|
+
*/
|
|
55
|
+
AlFile.addElementGetter('preview_element', '.al-file-preview');
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Set the value
|
|
59
|
+
*
|
|
60
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
61
|
+
* @since 0.6.0
|
|
62
|
+
* @version 0.6.0
|
|
63
|
+
*/
|
|
64
|
+
AlFile.setAttribute('value', null, function setValue(value) {
|
|
65
|
+
this.updatePreview(value);
|
|
66
|
+
return value;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Update the preview image
|
|
71
|
+
*
|
|
72
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
73
|
+
* @since 0.6.0
|
|
74
|
+
* @version 0.6.0
|
|
75
|
+
*/
|
|
76
|
+
AlFile.setMethod(function updatePreview(value) {
|
|
77
|
+
|
|
78
|
+
if (arguments.length == 0) {
|
|
79
|
+
value = this.value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (this.preview_element) {
|
|
83
|
+
Hawkejs.removeChildren(this.preview_element);
|
|
84
|
+
|
|
85
|
+
if (value) {
|
|
86
|
+
let img = this.createElement('img');
|
|
87
|
+
img.setAttribute('src', '/media/thumbnail/' + value);
|
|
88
|
+
img.setAttribute('srcset', '/media/thumbnail/' + value + '?dpr=2 2x');
|
|
89
|
+
|
|
90
|
+
this.preview_element.append(img);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Upload the file
|
|
97
|
+
*
|
|
98
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
99
|
+
* @since 0.6.0
|
|
100
|
+
* @version 0.6.0
|
|
101
|
+
*/
|
|
102
|
+
AlFile.setMethod(async function uploadFile(config) {
|
|
103
|
+
|
|
104
|
+
const that = this;
|
|
105
|
+
|
|
106
|
+
let file = config.file,
|
|
107
|
+
filename = config.filename,
|
|
108
|
+
format = config.format;
|
|
109
|
+
|
|
110
|
+
let form_data = new FormData(),
|
|
111
|
+
url = this.dataset.uploadUrl;
|
|
112
|
+
|
|
113
|
+
if (!url) {
|
|
114
|
+
url = '/media/upload';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
form_data.append('uploaded_file', file);
|
|
118
|
+
form_data.append('filename', filename);
|
|
119
|
+
|
|
120
|
+
if (format) {
|
|
121
|
+
form_data.append('format', format);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let response = await Blast.fetch({
|
|
125
|
+
url : url,
|
|
126
|
+
post : form_data,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (!response || !response.files || !response.files[0]) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let uploaded_file = response.files[0];
|
|
134
|
+
|
|
135
|
+
this.value = uploaded_file.id;
|
|
136
|
+
|
|
137
|
+
// uploaded_file.name
|
|
138
|
+
// uploaded_file.media_raw_id
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Test image
|
|
143
|
+
*
|
|
144
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
145
|
+
* @since 0.6.0
|
|
146
|
+
* @version 0.6.0
|
|
147
|
+
*/
|
|
148
|
+
AlFile.setMethod(function introduced() {
|
|
149
|
+
|
|
150
|
+
const that = this;
|
|
151
|
+
|
|
152
|
+
this.updatePreview();
|
|
153
|
+
|
|
154
|
+
this.select_button.addEventListener('click', e => {
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
this.file_input.click();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
this.file_input.addEventListener('change', function onChange(e) {
|
|
160
|
+
|
|
161
|
+
that.uploadFile({
|
|
162
|
+
file : this.files[0],
|
|
163
|
+
filename : this.files[0].name,
|
|
164
|
+
format : null,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Get the content for hawkejs
|
|
172
|
+
*
|
|
173
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
174
|
+
* @since 0.6.0
|
|
175
|
+
* @version 0.6.0
|
|
176
|
+
*/
|
|
177
|
+
AlFile.setMethod(function _getContent(callback) {
|
|
178
|
+
|
|
179
|
+
var that = this,
|
|
180
|
+
src = this.getAttribute('src');
|
|
181
|
+
|
|
182
|
+
this.viewRender.helpers.Alchemy.getResource({name: 'MediaFile#info', params: {path: src}}, function gotResult(err, info) {
|
|
183
|
+
|
|
184
|
+
if (err) {
|
|
185
|
+
return callback(err);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
console.log('Size:', info);
|
|
189
|
+
|
|
190
|
+
that.innerHTML = '<img class="final" src="/media/static/' + src + '?width=50%25" width=' + info.width + ' height=' + info.height +' style="width:400px">'
|
|
191
|
+
+ '<img class="placeholder" src="/media/static/' + src + '?width=20px">';
|
|
192
|
+
|
|
193
|
+
callback(null);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The al-ico element
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.6.0
|
|
6
|
+
* @version 0.6.0
|
|
7
|
+
*/
|
|
8
|
+
const Icon = Function.inherits('Alchemy.Element', 'AlIco');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The stylesheet to load for this element
|
|
12
|
+
*
|
|
13
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
+
* @since 0.6.0
|
|
15
|
+
* @version 0.6.0
|
|
16
|
+
*/
|
|
17
|
+
Icon.setStylesheetFile('alchemy_icons');
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The al-svg element
|
|
3
|
+
*
|
|
4
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
5
|
+
* @since 0.5.1
|
|
6
|
+
* @version 0.5.1
|
|
7
|
+
*/
|
|
8
|
+
const Svg = Function.inherits('Alchemy.Element', 'AlSvg');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The stylesheet to load for this element
|
|
12
|
+
*
|
|
13
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
14
|
+
* @since 0.5.1
|
|
15
|
+
* @version 0.5.1
|
|
16
|
+
*/
|
|
17
|
+
Svg.setStylesheetFile('alchemy_svg');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The location of the svg
|
|
21
|
+
*
|
|
22
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
23
|
+
* @since 0.5.1
|
|
24
|
+
* @version 0.5.1
|
|
25
|
+
*/
|
|
26
|
+
Svg.setAttribute('src');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the contents of this SVG
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.5.1
|
|
33
|
+
* @version 0.5.1
|
|
34
|
+
*/
|
|
35
|
+
Svg.setMethod(async function injectSvg() {
|
|
36
|
+
|
|
37
|
+
let contents,
|
|
38
|
+
src = this.src;
|
|
39
|
+
|
|
40
|
+
if (!src.endsWith('.svg')) {
|
|
41
|
+
src += '.svg';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Remove all the content
|
|
45
|
+
Hawkejs.removeChildren(this);
|
|
46
|
+
|
|
47
|
+
if (Blast.isNode) {
|
|
48
|
+
let path = await alchemy.findImagePath(src);
|
|
49
|
+
|
|
50
|
+
if (path) {
|
|
51
|
+
let file = new Classes.Alchemy.Inode.File(path);
|
|
52
|
+
contents = await file.readString();
|
|
53
|
+
} else {
|
|
54
|
+
contents = '';
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
contents = await Blast.fetch('/media/static/' + src, {cache: 60 * 60 * 1000});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.innerHTML = contents;
|
|
61
|
+
|
|
62
|
+
if (this._resolve_me_too) {
|
|
63
|
+
this._resolve_me_too.resolve();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Cached render method for Hawkejs
|
|
69
|
+
*
|
|
70
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
71
|
+
* @since 0.5.1
|
|
72
|
+
* @version 0.5.1
|
|
73
|
+
*/
|
|
74
|
+
Hawkejs.setCachedMethod(Svg, Hawkejs.RENDER_CONTENT, function doRender() {
|
|
75
|
+
|
|
76
|
+
if (!this.src) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return this.injectSvg();
|
|
81
|
+
});
|
package/helper/media_helper.js
CHANGED
|
@@ -93,7 +93,7 @@ Media.setStatic(function loadImagesBasedOnSize() {
|
|
|
93
93
|
*
|
|
94
94
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
95
95
|
* @since 0.5.0
|
|
96
|
-
* @version 0.5.
|
|
96
|
+
* @version 0.5.1
|
|
97
97
|
*
|
|
98
98
|
* @param {Element} element The element to apply to
|
|
99
99
|
* @param {String} image The image identifier
|
|
@@ -103,13 +103,12 @@ Media.setStatic(function loadImagesBasedOnSize() {
|
|
|
103
103
|
*/
|
|
104
104
|
Media.setMethod(function applyDirective(element, image, options) {
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
let record,
|
|
107
107
|
height = element.getAttribute('height'),
|
|
108
|
-
|
|
109
|
-
width = element.getAttribute('width'),
|
|
110
|
-
url;
|
|
108
|
+
width = element.getAttribute('width');
|
|
111
109
|
|
|
112
110
|
if (image && typeof image == 'object' && image._id) {
|
|
111
|
+
record = image;
|
|
113
112
|
image = image._id;
|
|
114
113
|
}
|
|
115
114
|
|
|
@@ -133,16 +132,57 @@ Media.setMethod(function applyDirective(element, image, options) {
|
|
|
133
132
|
options.height = height;
|
|
134
133
|
}
|
|
135
134
|
|
|
136
|
-
url = this.imageUrl(image, options)
|
|
137
|
-
|
|
135
|
+
let url = this.imageUrl(image, options),
|
|
136
|
+
clone = url.clone();
|
|
137
|
+
|
|
138
138
|
clone.addQuery('dpr', 2);
|
|
139
139
|
|
|
140
|
-
srcset = clone + ' 2x';
|
|
140
|
+
let srcset = clone + ' 2x';
|
|
141
141
|
|
|
142
142
|
// Set the source attribute
|
|
143
143
|
element.setAttribute('src', url);
|
|
144
144
|
|
|
145
145
|
element.setAttribute('srcset', srcset);
|
|
146
|
+
|
|
147
|
+
if (element.hasAttribute('alt')) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (record && record.alt) {
|
|
152
|
+
element.setAttribute('alt', record.alt);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!String(image).isHex()) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let pledge = new Pledge();
|
|
161
|
+
|
|
162
|
+
this.view.helpers.Alchemy.getResource({
|
|
163
|
+
name: 'MediaFile#data',
|
|
164
|
+
params: {
|
|
165
|
+
id: image
|
|
166
|
+
}
|
|
167
|
+
}, function gotResult(err, data) {
|
|
168
|
+
|
|
169
|
+
if (!err && data) {
|
|
170
|
+
if (data.alt) {
|
|
171
|
+
element.setAttribute('alt', data.alt);
|
|
172
|
+
} else {
|
|
173
|
+
element.setAttribute('alt', '');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (data.title && !element.hasAttribute('title')) {
|
|
177
|
+
element.setAttribute('title', data.title);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
pledge.resolve();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return pledge;
|
|
146
186
|
});
|
|
147
187
|
|
|
148
188
|
/**
|
|
@@ -168,7 +208,7 @@ Media.setMethod(function fileAnchor(file_id, options) {
|
|
|
168
208
|
*
|
|
169
209
|
* @author Jelle De Loecker <jelle@develry.be>
|
|
170
210
|
* @since 0.2.0
|
|
171
|
-
* @version 0.
|
|
211
|
+
* @version 0.5.1
|
|
172
212
|
*
|
|
173
213
|
* @param {String} image_id
|
|
174
214
|
*
|
|
@@ -184,7 +224,7 @@ Media.setMethod(function imageUrl(image_id, options) {
|
|
|
184
224
|
options = {};
|
|
185
225
|
}
|
|
186
226
|
|
|
187
|
-
if (String(image_id).
|
|
227
|
+
if (String(image_id).isHex()) {
|
|
188
228
|
|
|
189
229
|
if (options.route) {
|
|
190
230
|
routeName = options.route;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Widget Image class
|
|
3
|
+
*
|
|
4
|
+
* @constructor
|
|
5
|
+
*
|
|
6
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} data
|
|
11
|
+
*/
|
|
12
|
+
const Image = Function.inherits('Alchemy.Widget', 'Image');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prepare the schema
|
|
16
|
+
*
|
|
17
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
18
|
+
* @since 0.1.0
|
|
19
|
+
* @version 0.1.0
|
|
20
|
+
*/
|
|
21
|
+
Image.constitute(function prepareSchema() {
|
|
22
|
+
|
|
23
|
+
this.schema.addField('image', 'File', {
|
|
24
|
+
widget_config_editable: true,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Populate the widget
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.1.0
|
|
33
|
+
* @version 0.1.0
|
|
34
|
+
*
|
|
35
|
+
* @param {HTMLElement} widget
|
|
36
|
+
*/
|
|
37
|
+
Image.setMethod(function populateWidget() {
|
|
38
|
+
|
|
39
|
+
let img = this.createElement('img');
|
|
40
|
+
|
|
41
|
+
this.hawkejs_renderer.helpers.Media.applyDirective(img, this.config.image);
|
|
42
|
+
|
|
43
|
+
populateWidget.super.call(this);
|
|
44
|
+
|
|
45
|
+
this.widget.append(img);
|
|
46
|
+
});
|
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
* @since 0.2.0
|
|
8
8
|
* @version 0.6.0
|
|
9
9
|
*/
|
|
10
|
-
var FileField = Function.inherits('Alchemy.Field.ObjectId',
|
|
11
|
-
File.super.call(this, schema, name, options);
|
|
12
|
-
});
|
|
10
|
+
var FileField = Function.inherits('Alchemy.Field.ObjectId', 'File');
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Defer casting when processing data?
|
|
@@ -18,6 +16,10 @@ var FileField = Function.inherits('Alchemy.Field.ObjectId', function File(schema
|
|
|
18
16
|
*/
|
|
19
17
|
FileField.setProperty('deferCast', true);
|
|
20
18
|
|
|
19
|
+
if (Blast.isBrowser) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
21
23
|
/**
|
|
22
24
|
* Make sure the file is really a file,
|
|
23
25
|
* download urls first
|