summaryrefslogtreecommitdiffstats
path: root/client/lib
diff options
context:
space:
mode:
authorSam X. Chen <sam.xi.chen@gmail.com>2019-08-07 23:44:45 -0400
committerSam X. Chen <sam.xi.chen@gmail.com>2019-08-07 23:44:45 -0400
commit71d1d9ad981750cac1e3f05d36c8efa8a1f1dded (patch)
tree85009287d2aa1eabead6d178e8c3c4428c08dcd6 /client/lib
parent9ed0c3029f7a61a9e5cc31d52156055e08e53f9a (diff)
downloadwekan-71d1d9ad981750cac1e3f05d36c8efa8a1f1dded.tar.gz
wekan-71d1d9ad981750cac1e3f05d36c8efa8a1f1dded.tar.bz2
wekan-71d1d9ad981750cac1e3f05d36c8efa8a1f1dded.zip
Bug fix: bug#2589 #2575, Add Features: allowing user to insert/paste link, image, video
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/utils.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/client/lib/utils.js b/client/lib/utils.js
index 5681273e..f81e691c 100644
--- a/client/lib/utils.js
+++ b/client/lib/utils.js
@@ -24,6 +24,58 @@ Utils = {
);
},
+ MAX_IMAGE_PIXEL: Meteor.settings.public.MAX_IMAGE_PIXEL,
+ COMPRESS_RATIO: Meteor.settings.public.IMAGE_COMPRESS_RATIO,
+ shrinkImage(options) {
+ // shrink image to certain size
+ const dataurl = options.dataurl,
+ callback = options.callback,
+ toBlob = options.toBlob;
+ let canvas = document.createElement('canvas'),
+ image = document.createElement('img');
+ const maxSize = options.maxSize || 1024;
+ const ratio = options.ratio || 1.0;
+ const next = function(result) {
+ image = null;
+ canvas = null;
+ if (typeof callback === 'function') {
+ callback(result);
+ }
+ };
+ image.onload = function() {
+ let width = this.width,
+ height = this.height;
+ let changed = false;
+ if (width > height) {
+ if (width > maxSize) {
+ height *= maxSize / width;
+ width = maxSize;
+ changed = true;
+ }
+ } else if (height > maxSize) {
+ width *= maxSize / height;
+ height = maxSize;
+ changed = true;
+ }
+ canvas.width = width;
+ canvas.height = height;
+ canvas.getContext('2d').drawImage(this, 0, 0, width, height);
+ if (changed === true) {
+ const type = 'image/jpeg';
+ if (toBlob) {
+ canvas.toBlob(next, type, ratio);
+ } else {
+ next(canvas.toDataURL(type, ratio));
+ }
+ } else {
+ next(changed);
+ }
+ };
+ image.onerror = function() {
+ next(false);
+ };
+ image.src = dataurl;
+ },
capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},