Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/core/behavior-phabricator-remarkup-assist.js
Show All 14 Lines | JX.behavior('phabricator-remarkup-assist', function(config) { | ||||
var pht = JX.phtize(config.pht); | var pht = JX.phtize(config.pht); | ||||
var root = JX.$(config.rootID); | var root = JX.$(config.rootID); | ||||
var area = JX.DOM.find(root, 'textarea'); | var area = JX.DOM.find(root, 'textarea'); | ||||
var edit_mode = 'normal'; | var edit_mode = 'normal'; | ||||
var edit_root = null; | var edit_root = null; | ||||
var preview = null; | var preview = null; | ||||
var pinned = false; | var pinned = false; | ||||
var in_fullscreen = false; | |||||
epriestley: Consider renaming the `'fa-arrows-alt'` mode (which I think is just named that for legacy… | |||||
// When we pin the comment area to the bottom of the window, we need to put | // When we pin the comment area to the bottom of the window, we need to put | ||||
// an extra spacer element at the bottom of the document so that it is | // an extra spacer element at the bottom of the document so that it is | ||||
// possible to scroll down far enough to see content at the end. Otherwise, | // possible to scroll down far enough to see content at the end. Otherwise, | ||||
// the last part of the document will be hidden behind the comment area when | // the last part of the document will be hidden behind the comment area when | ||||
// the document is fully scrolled. | // the document is fully scrolled. | ||||
var pinned_spacer = JX.$N( | var pinned_spacer = JX.$N( | ||||
'div', | 'div', | ||||
{className: 'remarkup-assist-pinned-spacer'}); | {className: 'remarkup-assist-pinned-spacer'}); | ||||
function set_edit_mode(root, mode) { | function set_edit_mode(root, mode) { | ||||
if (mode == edit_mode) { | if (mode == edit_mode) { | ||||
return; | return; | ||||
} | } | ||||
// First, disable any active mode. | // First, disable any active mode. | ||||
if (edit_root) { | if (edit_root) { | ||||
if (edit_mode == 'fa-arrows-alt') { | if (edit_mode == 'fa-arrows-alt') { | ||||
JX.DOM.alterClass(edit_root, 'remarkup-control-fullscreen-mode', false); | JX.DOM.alterClass(edit_root, 'remarkup-control-fullscreen-mode', false); | ||||
JX.DOM.alterClass(document.body, 'remarkup-fullscreen-mode', false); | JX.DOM.alterClass(document.body, 'remarkup-fullscreen-mode', false); | ||||
JX.Mask.hide('jx-light-mask'); | JX.Mask.hide('jx-light-mask'); | ||||
in_fullscreen = false; | |||||
} | } | ||||
area.style.height = ''; | area.style.height = ''; | ||||
// If we're in preview mode, kick the preview back down to default | // If we're in preview mode, kick the preview back down to default | ||||
// size. | // size. | ||||
if (preview) { | if (preview) { | ||||
JX.DOM.show(area); | JX.DOM.show(area); | ||||
resize_preview(); | resize_preview(); | ||||
JX.DOM.hide(area); | JX.DOM.hide(area); | ||||
} | } | ||||
} | } | ||||
edit_root = root; | edit_root = root; | ||||
edit_mode = mode; | edit_mode = mode; | ||||
// Now, apply the new mode. | // Now, apply the new mode. | ||||
if (mode == 'fa-arrows-alt') { | if (mode == 'fa-arrows-alt') { | ||||
JX.DOM.alterClass(edit_root, 'remarkup-control-fullscreen-mode', true); | JX.DOM.alterClass(edit_root, 'remarkup-control-fullscreen-mode', true); | ||||
JX.DOM.alterClass(document.body, 'remarkup-fullscreen-mode', true); | JX.DOM.alterClass(document.body, 'remarkup-fullscreen-mode', true); | ||||
JX.Mask.show('jx-light-mask'); | JX.Mask.show('jx-light-mask'); | ||||
in_fullscreen = true; | |||||
// If we're in preview mode, expand the preview to full-size. | // If we're in preview mode, expand the preview to full-size. | ||||
if (preview) { | if (preview) { | ||||
JX.DOM.show(area); | JX.DOM.show(area); | ||||
} | } | ||||
resizearea(); | resizearea(); | ||||
▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | JX.behavior('phabricator-remarkup-assist', function(config) { | ||||
if (config.canPin) { | if (config.canPin) { | ||||
new JX.KeyboardShortcut('z', pht('key-help')) | new JX.KeyboardShortcut('z', pht('key-help')) | ||||
.setHandler(function() { | .setHandler(function() { | ||||
set_pinned_mode(root, !pinned); | set_pinned_mode(root, !pinned); | ||||
}) | }) | ||||
.register(); | .register(); | ||||
} | } | ||||
if (config.sendonEnter) { | |||||
// Send on enter if the shift key is not held. | |||||
JX.Stratcom.listen( | |||||
'keydown', | |||||
'remarkup-send-on-enter', | |||||
Not Done Inline ActionsYou should be able to JX.DOM.listen(area, 'keydown', null, ...) without needing to put remarkup-send-on-enter on the form. epriestley: You should be able to `JX.DOM.listen(area, 'keydown', null, ...)` without needing to put… | |||||
function(e) { | |||||
if (e.getSpecialKey() != 'return') { | |||||
return; | |||||
} | |||||
var raw = e.getRawEvent(); | |||||
if (raw.shiftKey) { | |||||
// If the shift key is pressed, let the browser write a newline into | |||||
// the textarea. | |||||
return; | |||||
} | |||||
if (in_fullscreen) { | |||||
// Don't send on enter in fullscreen | |||||
return; | |||||
} | |||||
// From here on, interpret this as a "send" action, not a literal | |||||
// newline. | |||||
e.kill(); | |||||
// TODO... works, but no Conpherence AJAX | |||||
var form = e.getNode('tag:form'); | |||||
form.submit(); | |||||
}); | |||||
} | |||||
Not Done Inline ActionsThis has no effect again :3 epriestley: This has no effect again :3 | |||||
}); | }); | ||||
Not Done Inline ActionsThis has no effect. epriestley: This has no effect. | |||||
Not Done Inline ActionsI think I had a form.submit() that's supposed to go after this. The main problem I was working on was the conpherence listener wasn't getting executed before form.submit() and the page would reload vs. ajax a message. chad: I think I had a `form.submit()` that's supposed to go after this. The main problem I was… |
Consider renaming the 'fa-arrows-alt' mode (which I think is just named that for legacy reasons) into 'fullscreen', then testing edit_mode == 'fullscreen' instead of using a separate flag which stores the same state information.