BookStack/resources/assets/js/image-manager.js

86 lines
2.5 KiB
JavaScript
Raw Normal View History

2015-08-12 13:48:26 -04:00
2015-08-12 18:42:42 -04:00
(function() {
2015-08-13 17:15:56 -04:00
var ImageManager = new Vue({
2015-08-12 18:42:42 -04:00
2015-08-13 17:15:56 -04:00
el: '#image-manager',
2015-08-12 18:42:42 -04:00
2015-08-13 17:15:56 -04:00
data: {
images: [],
hasMore: false,
page: 0,
cClickTime: 0
},
2015-08-12 18:42:42 -04:00
2015-08-13 17:15:56 -04:00
created: function() {
// Get initial images
this.fetchData(this.page);
},
2015-08-12 18:42:42 -04:00
2015-08-13 17:15:56 -04:00
ready: function() {
2015-08-12 18:42:42 -04:00
// Create dropzone
2015-08-13 17:15:56 -04:00
this.setupDropZone();
},
methods: {
fetchData: function() {
var _this = this;
$.getJSON('/images/all/' + _this.page, function(data) {
_this.images = _this.images.concat(data.images);
_this.hasMore = data.hasMore;
_this.page++;
});
},
setupDropZone: function() {
var _this = this;
var dropZone = new Dropzone(_this.$$.dropZone, {
url: '/upload/image',
init: function() {
var dz = this;
this.on("sending", function(file, xhr, data) {
data.append("_token", document.querySelector('meta[name=token]').getAttribute('content'));
2015-08-12 18:42:42 -04:00
});
2015-08-13 17:15:56 -04:00
this.on("success", function(file, data) {
_this.images.unshift(data);
$(file.previewElement).fadeOut(400, function() {
dz.removeFile(file);
});
});
}
2015-08-12 18:42:42 -04:00
});
2015-08-13 17:15:56 -04:00
},
imageClick: function(image) {
var dblClickTime = 380;
var cTime = (new Date()).getTime();
var timeDiff = cTime - this.cClickTime;
if(this.cClickTime !== 0 && timeDiff < dblClickTime) {
// DoubleClick
if(this.callback) {
this.callback(image);
}
this.hide();
} else {
// Single Click
}
this.cClickTime = cTime;
},
2015-08-12 13:48:26 -04:00
2015-08-13 17:15:56 -04:00
show: function(callback) {
this.callback = callback;
this.$$.overlay.style.display = 'block';
},
2015-08-13 02:44:10 -04:00
2015-08-13 17:15:56 -04:00
hide: function() {
this.$$.overlay.style.display = 'none';
2015-08-13 02:44:10 -04:00
}
}
2015-08-13 17:15:56 -04:00
});
2015-08-12 13:48:26 -04:00
2015-08-13 17:15:56 -04:00
window.ImageManager = ImageManager;
2015-08-12 18:42:42 -04:00
2015-08-13 17:15:56 -04:00
})();