<div>
<p>
<code>data-max-width="1024" data-max-height="1024"</code><br />
<input
type="hidden"
role="uploadcare-uploader"
data-max-width="1024"
data-max-height="1024"
/>
</p>
<p>
<code
>data-images-only="true" data-max-width="1024"
data-max-height="1024"</code
><br />
<input
type="hidden"
role="uploadcare-uploader"
data-images-only="true"
data-max-width="1024"
data-max-height="1024"
/>
</p>
</div>
body {
margin: 16px;
}
p {
margin: 8px 0;
}
code {
font-family: monospace;
}
function maxDimensions(width, height) {
return function(fileInfo) {
var imageInfo = fileInfo.originalImageInfo
if (imageInfo === null) {
return
}
var heightExceeded = height && imageInfo.height > height
if (width && imageInfo.width > width) {
if (heightExceeded) {
throw new Error('maxDimensions')
}
else {
throw new Error('maxWidth')
}
}
if (heightExceeded) {
throw new Error('maxHeight')
}
}
}
$(function() {
$('[role=uploadcare-uploader]').each(function() {
var input = $(this)
if (!input.data('maxWidth') && !input.data('maxHeight')) {
return
}
var widget = uploadcare.Widget(input)
widget.validators.push(maxDimensions(input.data('maxWidth'), input.data('maxHeight')))
})
})
UPLOADCARE_LOCALE_TRANSLATIONS = {
// messages for widget
errors: {
maxDimensions: 'This image exceeds max dimensions.',
maxWidth: 'This image exceeds max width.',
maxHeight: 'This image exceeds max height.',
},
// messages for dialog’s error page
dialog: {
tabs: {
preview: {
error: {
maxDimensions: {
title: 'Title.',
text: 'Text.',
back: 'Back',
},
maxWidth: {
title: 'Title.',
text: 'Text.',
back: 'Back',
},
maxHeight: {
title: 'Title.',
text: 'Text.',
back: 'Back',
},
},
},
},
},
}
This Pen doesn't use any external CSS resources.