Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/core/behavior-phabricator-remarkup-assist.js
/** | /** | ||||
* @provides javelin-behavior-phabricator-remarkup-assist | * @provides javelin-behavior-phabricator-remarkup-assist | ||||
* @requires javelin-behavior | * @requires javelin-behavior | ||||
* javelin-stratcom | * javelin-stratcom | ||||
* javelin-dom | * javelin-dom | ||||
* phabricator-phtize | * phabricator-phtize | ||||
* phabricator-textareautils | * phabricator-textareautils | ||||
* javelin-workflow | * javelin-workflow | ||||
* javelin-vector | * javelin-vector | ||||
* javelin-util | |||||
*/ | */ | ||||
JX.behavior('phabricator-remarkup-assist', function(config) { | JX.behavior('phabricator-remarkup-assist', function(config) { | ||||
var pht = JX.phtize(config.pht); | var pht = JX.phtize(config.pht); | ||||
var edit_mode = 'normal'; | var edit_mode = 'normal'; | ||||
var edit_root = null; | var edit_root = null; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | function update(area, l, m, r) { | ||||
// "bold" so if they type stuff they'll be editing the bold text. | // "bold" so if they type stuff they'll be editing the bold text. | ||||
var range = JX.TextAreaUtils.getSelectionRange(area); | var range = JX.TextAreaUtils.getSelectionRange(area); | ||||
JX.TextAreaUtils.setSelectionRange( | JX.TextAreaUtils.setSelectionRange( | ||||
area, | area, | ||||
range.start + l.length, | range.start + l.length, | ||||
range.start + l.length + m.length); | range.start + l.length + m.length); | ||||
} | } | ||||
function onupload(area, response) { | |||||
var ref = '{F' + response.id + '}'; | |||||
JX.TextAreaUtils.setSelectionText(area, ref); | |||||
} | |||||
function assist(area, action, root) { | function assist(area, action, root) { | ||||
// If the user has some text selected, we'll try to use that (for example, | // If the user has some text selected, we'll try to use that (for example, | ||||
// if they have a word selected and want to bold it). Otherwise we'll insert | // if they have a word selected and want to bold it). Otherwise we'll insert | ||||
// generic text. | // generic text. | ||||
var sel = JX.TextAreaUtils.getSelectionText(area); | var sel = JX.TextAreaUtils.getSelectionText(area); | ||||
var r = JX.TextAreaUtils.getSelectionRange(area); | var r = JX.TextAreaUtils.getSelectionRange(area); | ||||
switch (action) { | switch (action) { | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | switch (action) { | ||||
area, | area, | ||||
'', | '', | ||||
sel, | sel, | ||||
(r.start === 0 ? '' : '\n\n') + response.text + '\n\n'); | (r.start === 0 ? '' : '\n\n') + response.text + '\n\n'); | ||||
}) | }) | ||||
.start(); | .start(); | ||||
break; | break; | ||||
case 'fa-cloud-upload': | case 'fa-cloud-upload': | ||||
new JX.Workflow('/file/uploaddialog/').start(); | new JX.Workflow('/file/uploaddialog/') | ||||
.setHandler(JX.bind(null, onupload, area)) | |||||
.start(); | |||||
break; | break; | ||||
case 'fa-arrows-alt': | case 'fa-arrows-alt': | ||||
if (edit_mode == 'fa-arrows-alt') { | if (edit_mode == 'fa-arrows-alt') { | ||||
set_edit_mode(root, 'normal'); | set_edit_mode(root, 'normal'); | ||||
} else { | } else { | ||||
set_edit_mode(root, 'fa-arrows-alt'); | set_edit_mode(root, 'fa-arrows-alt'); | ||||
} | } | ||||
break; | break; | ||||
Show All 21 Lines |