2012-09-19 21:27:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl {
|
|
|
|
|
2012-10-02 03:46:34 +02:00
|
|
|
protected function renderInput() {
|
2012-10-08 22:26:57 +02:00
|
|
|
$id = $this->getID();
|
|
|
|
if (!$id) {
|
|
|
|
$id = celerity_generate_unique_node_id();
|
|
|
|
$this->setID($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
Javelin::initBehavior(
|
|
|
|
'aphront-drag-and-drop-textarea',
|
|
|
|
array(
|
|
|
|
'target' => $id,
|
|
|
|
'activatedClass' => 'aphront-textarea-drag-and-drop',
|
|
|
|
'uri' => '/file/dropupload/',
|
|
|
|
));
|
2012-09-19 21:27:28 +02:00
|
|
|
|
2012-10-02 03:46:34 +02:00
|
|
|
Javelin::initBehavior('phabricator-remarkup-assist', array());
|
2012-10-07 01:21:25 +02:00
|
|
|
Javelin::initBehavior('phabricator-tooltips', array());
|
2012-09-19 21:27:28 +02:00
|
|
|
|
2012-10-02 03:46:34 +02:00
|
|
|
$actions = array(
|
|
|
|
'b' => array(
|
2012-10-07 01:21:25 +02:00
|
|
|
'tip' => pht('Bold'),
|
2012-10-02 03:46:34 +02:00
|
|
|
),
|
|
|
|
'i' => array(
|
2012-10-07 01:21:25 +02:00
|
|
|
'tip' => pht('Italics'),
|
2012-10-02 03:46:34 +02:00
|
|
|
),
|
|
|
|
'tt' => array(
|
2012-10-07 01:21:25 +02:00
|
|
|
'tip' => pht('Monospaced'),
|
2012-10-02 03:46:34 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'spacer' => true,
|
|
|
|
),
|
|
|
|
'ul' => array(
|
2012-10-07 01:21:25 +02:00
|
|
|
'tip' => pht('Bulleted List'),
|
2012-10-02 03:46:34 +02:00
|
|
|
),
|
|
|
|
'ol' => array(
|
2012-10-07 01:21:25 +02:00
|
|
|
'tip' => pht('Numbered List'),
|
2012-10-02 03:46:34 +02:00
|
|
|
),
|
|
|
|
'code' => array(
|
2012-10-07 01:21:25 +02:00
|
|
|
'tip' => pht('Code Block'),
|
2012-10-02 03:46:34 +02:00
|
|
|
),
|
|
|
|
'help' => array(
|
2012-10-07 01:21:25 +02:00
|
|
|
'tip' => pht('Help'),
|
2012-10-02 03:46:34 +02:00
|
|
|
'align' => 'right',
|
|
|
|
'href' => PhabricatorEnv::getDoclink(
|
2012-09-19 21:27:28 +02:00
|
|
|
'article/Remarkup_Reference.html'),
|
|
|
|
),
|
2012-10-02 03:46:34 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$buttons = array();
|
|
|
|
foreach ($actions as $action => $spec) {
|
|
|
|
if (idx($spec, 'spacer')) {
|
2012-10-07 01:21:25 +02:00
|
|
|
$buttons[] = phutil_render_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'remarkup-assist-separator',
|
|
|
|
),
|
|
|
|
'');
|
2012-10-02 03:46:34 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
$classes[] = 'remarkup-assist-button';
|
|
|
|
if (idx($spec, 'align') == 'right') {
|
|
|
|
$classes[] = 'remarkup-assist-right';
|
|
|
|
}
|
|
|
|
|
|
|
|
$href = idx($spec, 'href', '#');
|
|
|
|
if ($href == '#') {
|
|
|
|
$meta = array('action' => $action);
|
|
|
|
$mustcapture = true;
|
|
|
|
$target = null;
|
|
|
|
} else {
|
2012-10-07 01:21:25 +02:00
|
|
|
$meta = array();
|
2012-10-02 03:46:34 +02:00
|
|
|
$mustcapture = null;
|
|
|
|
$target = '_blank';
|
|
|
|
}
|
|
|
|
|
2012-10-07 01:21:25 +02:00
|
|
|
$tip = idx($spec, 'tip');
|
|
|
|
if ($tip) {
|
|
|
|
$meta['tip'] = $tip;
|
|
|
|
}
|
|
|
|
|
2012-10-02 03:46:34 +02:00
|
|
|
$buttons[] = javelin_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'class' => implode(' ', $classes),
|
|
|
|
'href' => $href,
|
2012-10-07 01:21:25 +02:00
|
|
|
'sigil' => 'remarkup-assist has-tooltip',
|
2012-10-02 03:46:34 +02:00
|
|
|
'meta' => $meta,
|
|
|
|
'mustcapture' => $mustcapture,
|
|
|
|
'target' => $target,
|
|
|
|
'tabindex' => -1,
|
|
|
|
),
|
|
|
|
phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2012-10-07 01:21:25 +02:00
|
|
|
'class' => 'remarkup-assist autosprite remarkup-assist-'.$action,
|
2012-10-02 03:46:34 +02:00
|
|
|
),
|
2012-10-07 01:21:25 +02:00
|
|
|
''));
|
2012-10-02 03:46:34 +02:00
|
|
|
}
|
|
|
|
|
2012-10-07 01:21:25 +02:00
|
|
|
$buttons = phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'remarkup-assist-bar',
|
|
|
|
),
|
|
|
|
implode('', $buttons));
|
|
|
|
|
|
|
|
$this->setCustomClass('remarkup-assist-textarea');
|
2012-10-02 03:46:34 +02:00
|
|
|
|
|
|
|
return javelin_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'sigil' => 'remarkup-assist-control',
|
|
|
|
),
|
|
|
|
$buttons.
|
|
|
|
parent::renderInput());
|
2012-09-19 21:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|