2017-06-30 17:27:31 -04:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, wrap-iife, prefer-arrow-callback, no-unused-vars, consistent-return, camelcase, comma-dangle, max-len, class-methods-use-this */
|
2016-12-14 00:26:26 -05:00
|
|
|
|
2016-07-26 23:32:10 -04:00
|
|
|
// Zen Mode (full screen) textarea
|
|
|
|
//
|
2016-07-24 16:45:11 -04:00
|
|
|
/*= provides zen_mode:enter */
|
|
|
|
/*= provides zen_mode:leave */
|
2016-11-03 17:38:54 -04:00
|
|
|
|
2017-05-16 16:52:40 -04:00
|
|
|
import 'vendor/jquery.scrollTo';
|
|
|
|
import Dropzone from 'dropzone';
|
2017-12-19 05:12:32 -05:00
|
|
|
import Mousetrap from 'mousetrap';
|
2017-05-16 16:52:40 -04:00
|
|
|
import 'mousetrap/plugins/pause/mousetrap-pause';
|
|
|
|
|
2017-12-19 05:12:32 -05:00
|
|
|
Dropzone.autoDiscover = false;
|
|
|
|
|
2016-07-26 23:32:10 -04:00
|
|
|
//
|
|
|
|
// ### Events
|
|
|
|
//
|
|
|
|
// `zen_mode:enter`
|
|
|
|
//
|
|
|
|
// Fired when the "Edit in fullscreen" link is clicked.
|
|
|
|
//
|
|
|
|
// **Synchronicity** Sync
|
|
|
|
// **Bubbles** Yes
|
|
|
|
// **Cancelable** No
|
|
|
|
// **Target** a.js-zen-enter
|
|
|
|
//
|
|
|
|
// `zen_mode:leave`
|
|
|
|
//
|
|
|
|
// Fired when the "Leave Fullscreen" link is clicked.
|
|
|
|
//
|
|
|
|
// **Synchronicity** Sync
|
|
|
|
// **Bubbles** Yes
|
|
|
|
// **Cancelable** No
|
|
|
|
// **Target** a.js-zen-leave
|
|
|
|
//
|
2017-07-05 13:20:41 -04:00
|
|
|
|
2017-06-30 17:37:31 -04:00
|
|
|
export default class ZenMode {
|
2017-06-30 17:27:31 -04:00
|
|
|
constructor() {
|
2017-07-05 13:20:41 -04:00
|
|
|
this.active_backdrop = null;
|
|
|
|
this.active_textarea = null;
|
|
|
|
$(document).on('click', '.js-zen-enter', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return $(e.currentTarget).trigger('zen_mode:enter');
|
|
|
|
});
|
|
|
|
$(document).on('click', '.js-zen-leave', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
return $(e.currentTarget).trigger('zen_mode:leave');
|
|
|
|
});
|
|
|
|
$(document).on('zen_mode:enter', (function(_this) {
|
|
|
|
return function(e) {
|
|
|
|
return _this.enter($(e.target).closest('.md-area').find('.zen-backdrop'));
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
$(document).on('zen_mode:leave', (function(_this) {
|
|
|
|
return function(e) {
|
|
|
|
return _this.exit();
|
|
|
|
};
|
|
|
|
})(this));
|
|
|
|
$(document).on('keydown', function(e) {
|
|
|
|
// Esc
|
|
|
|
if (e.keyCode === 27) {
|
2016-07-24 16:45:11 -04:00
|
|
|
e.preventDefault();
|
2017-07-05 13:20:41 -04:00
|
|
|
return $(document).trigger('zen_mode:leave');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-06-30 17:27:31 -04:00
|
|
|
enter(backdrop) {
|
2017-07-05 13:20:41 -04:00
|
|
|
Mousetrap.pause();
|
|
|
|
this.active_backdrop = $(backdrop);
|
|
|
|
this.active_backdrop.addClass('fullscreen');
|
|
|
|
this.active_textarea = this.active_backdrop.find('textarea');
|
|
|
|
// Prevent a user-resized textarea from persisting to fullscreen
|
|
|
|
this.active_textarea.removeAttr('style');
|
2017-11-22 18:20:23 -05:00
|
|
|
this.active_textarea.focus();
|
2017-06-30 17:27:31 -04:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-06-30 17:27:31 -04:00
|
|
|
exit() {
|
2017-07-05 13:20:41 -04:00
|
|
|
if (this.active_textarea) {
|
|
|
|
Mousetrap.unpause();
|
|
|
|
this.active_textarea.closest('.zen-backdrop').removeClass('fullscreen');
|
|
|
|
this.scrollTo(this.active_textarea);
|
|
|
|
this.active_textarea = null;
|
|
|
|
this.active_backdrop = null;
|
2017-11-22 18:20:23 -05:00
|
|
|
|
|
|
|
const $dropzone = $('.div-dropzone');
|
|
|
|
if ($dropzone && !$dropzone.hasClass('js-invalid-dropzone')) {
|
|
|
|
Dropzone.forElement('.div-dropzone').enable();
|
|
|
|
}
|
2017-07-05 13:20:41 -04:00
|
|
|
}
|
2017-06-30 17:27:31 -04:00
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-06-30 17:27:31 -04:00
|
|
|
scrollTo(zen_area) {
|
2017-07-05 13:20:41 -04:00
|
|
|
return $.scrollTo(zen_area, 0, {
|
|
|
|
offset: -150
|
|
|
|
});
|
2017-06-30 17:27:31 -04:00
|
|
|
}
|
|
|
|
}
|