2017-08-17 22:00:37 +05:30
|
|
|
/* eslint-disable func-names, space-before-function-paren, wrap-iife, prefer-arrow-callback, no-unused-vars, consistent-return, camelcase, comma-dangle, max-len */
|
|
|
|
/* global Dropzone */
|
|
|
|
/* global Mousetrap */
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
// Zen Mode (full screen) textarea
|
|
|
|
//
|
2016-09-13 17:45:13 +05:30
|
|
|
/*= provides zen_mode:enter */
|
|
|
|
/*= provides zen_mode:leave */
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
require('vendor/jquery.scrollTo');
|
|
|
|
window.Dropzone = require('dropzone');
|
|
|
|
require('mousetrap');
|
|
|
|
require('mousetrap/plugins/pause/mousetrap-pause');
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
//
|
|
|
|
// ### 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
|
|
|
|
//
|
2016-09-13 17:45:13 +05:30
|
|
|
(function() {
|
|
|
|
this.ZenMode = (function() {
|
|
|
|
function ZenMode() {
|
|
|
|
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) {
|
2016-09-29 09:46:39 +05:30
|
|
|
// Esc
|
2016-09-13 17:45:13 +05:30
|
|
|
if (e.keyCode === 27) {
|
|
|
|
e.preventDefault();
|
|
|
|
return $(document).trigger('zen_mode:leave');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ZenMode.prototype.enter = function(backdrop) {
|
|
|
|
Mousetrap.pause();
|
|
|
|
this.active_backdrop = $(backdrop);
|
|
|
|
this.active_backdrop.addClass('fullscreen');
|
|
|
|
this.active_textarea = this.active_backdrop.find('textarea');
|
2016-09-29 09:46:39 +05:30
|
|
|
// Prevent a user-resized textarea from persisting to fullscreen
|
2016-09-13 17:45:13 +05:30
|
|
|
this.active_textarea.removeAttr('style');
|
|
|
|
return this.active_textarea.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
ZenMode.prototype.exit = function() {
|
|
|
|
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;
|
|
|
|
return Dropzone.forElement('.div-dropzone').enable();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ZenMode.prototype.scrollTo = function(zen_area) {
|
|
|
|
return $.scrollTo(zen_area, 0, {
|
|
|
|
offset: -150
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return ZenMode;
|
|
|
|
})();
|
2017-08-17 22:00:37 +05:30
|
|
|
}).call(window);
|