[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl { 4 private $disableMacro = false; 5 6 private $disableFullScreen = false; 7 8 public function setDisableMacros($disable) { 9 $this->disableMacro = $disable; 10 return $this; 11 } 12 13 public function setDisableFullScreen($disable) { 14 $this->disableFullScreen = $disable; 15 return $this; 16 } 17 18 protected function renderInput() { 19 $id = $this->getID(); 20 if (!$id) { 21 $id = celerity_generate_unique_node_id(); 22 $this->setID($id); 23 } 24 25 $viewer = $this->getUser(); 26 if (!$viewer) { 27 throw new Exception( 28 pht('Call setUser() before rendering a PhabricatorRemarkupControl!')); 29 } 30 31 // We need to have this if previews render images, since Ajax can not 32 // currently ship JS or CSS. 33 require_celerity_resource('lightbox-attachment-css'); 34 35 Javelin::initBehavior( 36 'aphront-drag-and-drop-textarea', 37 array( 38 'target' => $id, 39 'activatedClass' => 'aphront-textarea-drag-and-drop', 40 'uri' => '/file/dropupload/', 41 )); 42 43 Javelin::initBehavior( 44 'phabricator-remarkup-assist', 45 array( 46 'pht' => array( 47 'bold text' => pht('bold text'), 48 'italic text' => pht('italic text'), 49 'monospaced text' => pht('monospaced text'), 50 'List Item' => pht('List Item'), 51 'data' => pht('data'), 52 'name' => pht('name'), 53 'URL' => pht('URL'), 54 ), 55 )); 56 Javelin::initBehavior('phabricator-tooltips', array()); 57 58 $actions = array( 59 'fa-bold' => array( 60 'tip' => pht('Bold'), 61 ), 62 'fa-italic' => array( 63 'tip' => pht('Italics'), 64 ), 65 'fa-text-width' => array( 66 'tip' => pht('Monospaced'), 67 ), 68 'fa-link' => array( 69 'tip' => pht('Link'), 70 ), 71 array( 72 'spacer' => true, 73 ), 74 'fa-list-ul' => array( 75 'tip' => pht('Bulleted List'), 76 ), 77 'fa-list-ol' => array( 78 'tip' => pht('Numbered List'), 79 ), 80 'fa-code' => array( 81 'tip' => pht('Code Block'), 82 ), 83 'fa-table' => array( 84 'tip' => pht('Table'), 85 ), 86 'fa-cloud-upload' => array( 87 'tip' => pht('Upload File'), 88 ), 89 ); 90 91 $can_use_macros = 92 (!$this->disableMacro) && 93 (function_exists('imagettftext')); 94 95 if ($can_use_macros) { 96 $can_use_macros = PhabricatorApplication::isClassInstalledForViewer( 97 'PhabricatorMacroApplication', 98 $viewer); 99 } 100 101 if ($can_use_macros) { 102 $actions[] = array( 103 'spacer' => true, 104 ); 105 $actions['fa-meh-o'] = array( 106 'tip' => pht('Meme'), 107 ); 108 } 109 110 $actions['fa-life-bouy'] = array( 111 'tip' => pht('Help'), 112 'align' => 'right', 113 'href' => PhabricatorEnv::getDoclink('Remarkup Reference'), 114 ); 115 116 if (!$this->disableFullScreen) { 117 $actions[] = array( 118 'spacer' => true, 119 'align' => 'right', 120 ); 121 122 $actions['fa-arrows-alt'] = array( 123 'tip' => pht('Fullscreen Mode'), 124 'align' => 'right', 125 ); 126 } 127 128 $buttons = array(); 129 foreach ($actions as $action => $spec) { 130 131 $classes = array(); 132 133 if (idx($spec, 'align') == 'right') { 134 $classes[] = 'remarkup-assist-right'; 135 } 136 137 if (idx($spec, 'spacer')) { 138 $classes[] = 'remarkup-assist-separator'; 139 $buttons[] = phutil_tag( 140 'span', 141 array( 142 'class' => implode(' ', $classes), 143 ), 144 ''); 145 continue; 146 } else { 147 $classes[] = 'remarkup-assist-button'; 148 } 149 150 $href = idx($spec, 'href', '#'); 151 if ($href == '#') { 152 $meta = array('action' => $action); 153 $mustcapture = true; 154 $target = null; 155 } else { 156 $meta = array(); 157 $mustcapture = null; 158 $target = '_blank'; 159 } 160 161 $content = null; 162 163 $tip = idx($spec, 'tip'); 164 if ($tip) { 165 $meta['tip'] = $tip; 166 $content = javelin_tag( 167 'span', 168 array( 169 'aural' => true, 170 ), 171 $tip); 172 } 173 174 $buttons[] = javelin_tag( 175 'a', 176 array( 177 'class' => implode(' ', $classes), 178 'href' => $href, 179 'sigil' => 'remarkup-assist has-tooltip', 180 'meta' => $meta, 181 'mustcapture' => $mustcapture, 182 'target' => $target, 183 'tabindex' => -1, 184 ), 185 phutil_tag( 186 'div', 187 array( 188 'class' => 189 'remarkup-assist phui-icon-view phui-font-fa bluegrey '.$action, 190 ), 191 $content)); 192 } 193 194 $buttons = phutil_tag( 195 'div', 196 array( 197 'class' => 'remarkup-assist-bar', 198 ), 199 $buttons); 200 201 $monospaced_textareas = null; 202 $monospaced_textareas_class = null; 203 204 $monospaced_textareas = $viewer 205 ->loadPreferences() 206 ->getPreference( 207 PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS); 208 if ($monospaced_textareas == 'enabled') { 209 $monospaced_textareas_class = 'PhabricatorMonospaced'; 210 } 211 212 $this->setCustomClass( 213 'remarkup-assist-textarea '.$monospaced_textareas_class); 214 215 return javelin_tag( 216 'div', 217 array( 218 'sigil' => 'remarkup-assist-control', 219 ), 220 array( 221 $buttons, 222 parent::renderInput(), 223 )); 224 } 225 226 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |