diff --git a/gulpfile.js b/gulpfile.js index 6358835a7..f6a86d4c9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,5 +13,5 @@ var elixir = require('laravel-elixir'); elixir(function(mix) { mix.sass('styles.scss'); - mix.babel('image-manager.js', 'public/js/image-manager.js'); + mix.scripts('image-manager.js', 'public/js/image-manager.js'); }); diff --git a/resources/assets/js/image-manager.js b/resources/assets/js/image-manager.js index 4d24e35c8..3fa72c5bd 100644 --- a/resources/assets/js/image-manager.js +++ b/resources/assets/js/image-manager.js @@ -1,176 +1,86 @@ (function() { + var ImageManager = new Vue({ - class ImageManager extends React.Component { + el: '#image-manager', - constructor(props) { - super(props); - this.state = { - images: [], - hasMore: false, - page: 0 - }; - } + data: { + images: [], + hasMore: false, + page: 0, + cClickTime: 0 + }, - show(callback) { - $(React.findDOMNode(this)).show(); - this.callback = callback; - } + created: function() { + // Get initial images + this.fetchData(this.page); + }, - hide() { - console.log('test'); - $(React.findDOMNode(this)).hide(); - } - - selectImage(image) { - if(this.callback) { - this.callback(image); - } - this.hide(); - } - - componentDidMount() { - var _this = this; - // Set initial images - $.getJSON('/images/all', data => { - this.setState({ - images: data.images, - hasMore: data.hasMore - }); - }); + ready: function() { // Create dropzone - this.dropZone = new Dropzone(React.findDOMNode(this.refs.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')); - }); - this.on("success", function(file, data) { - _this.state.images.unshift(data); - _this.setState({ - images: _this.state.images - }); - //$(file.previewElement).fadeOut(400, function() { - // dz.removeFile(file); - //}) - }); - } - }); - } + this.setupDropZone(); + }, - loadMore() { - this.state.page++; - $.getJSON('/images/all/' + this.state.page, data => { - this.setState({ - images: this.state.images.concat(data.images), - hasMore: data.hasMore + 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++; }); - }); - } + }, - overlayClick(e) { - if(e.target.className === 'overlay') { - this.hide(); + 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')); + }); + this.on("success", function(file, data) { + _this.images.unshift(data); + $(file.previewElement).fadeOut(400, function() { + dz.removeFile(file); + }); + }); + } + }); + }, + + 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; + }, + + show: function(callback) { + this.callback = callback; + this.$$.overlay.style.display = 'block'; + }, + + hide: function() { + this.$$.overlay.style.display = 'none'; } - } - - render() { - var loadMore = this.loadMore.bind(this); - var selectImage = this.selectImage.bind(this); - var overlayClick = this.overlayClick.bind(this); - var hide = this.hide.bind(this); - return ( -