index.html 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <title>Documentation | Trumbowyg : a lightweight WYSIWYG editor | Alex-D / Alexandre Demode</title>
  7. <meta name="description" content="Trumbowyg is a jQuery plugin for create WYSIWYG editor">
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <link rel="icon" type="image/png" href="../favicon.png">
  10. <link rel="stylesheet" href="../css/main.css">
  11. <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
  12. </head>
  13. <body class="documentation-body">
  14. <svg xmlns="http://www.w3.org/2000/svg" style="overflow: hidden;visibility: hidden;height: 0;width: 0;">
  15. <symbol id="trumbowyg-link" viewBox="0 0 72 72">
  16. <path d="M30.9 49.1l-6.7 6.7c-.8.8-1.6.9-2.1.9s-1.4-.1-2.1-.9l-5.2-5.2c-1.1-1.1-1.1-3.1 0-4.2l6.1-6.1.2-.2 6.5-6.5c-1.2-.6-2.5-.9-3.8-.9-2.3 0-4.6.9-6.3 2.6L10.8 42c-3.5 3.5-3.5 9.2 0 12.7l5.2 5.2c1.7 1.7 4 2.6 6.3 2.6s4.6-.9 6.3-2.6l6.7-6.7C38 50.5 38.6 46.3 37 43l-6.1 6.1zM38.5 22.7l6.7-6.7c.8-.8 1.6-.9 2.1-.9s1.4.1 2.1.9l5.2 5.2c1.1 1.1 1.1 3.1 0 4.2l-6.1 6.1-.2.2-6.5 6.5c1.2.6 2.5.9 3.8.9 2.3 0 4.6-.9 6.3-2.6l6.7-6.7c3.5-3.5 3.5-9.2 0-12.7l-5.2-5.2c-1.7-1.7-4-2.6-6.3-2.6s-4.6.9-6.3 2.6l-6.7 6.7c-2.7 2.7-3.3 6.9-1.7 10.2l6.1-6.1z"/>
  17. <path d="M44.1 30.7c.2-.2.4-.6.4-.9 0-.3-.1-.6-.4-.9l-2.3-2.3c-.2-.2-.6-.4-.9-.4-.3 0-.6.1-.9.4L25.8 40.8c-.2.2-.4.6-.4.9 0 .3.1.6.4.9l2.3 2.3c.2.2.6.4.9.4.3 0 .6-.1.9-.4l14.2-14.2z"/>
  18. </symbol>
  19. </svg>
  20. <div class="sidebar">
  21. <div class="sidebar-inner">
  22. <header class="header-documentation">
  23. <a href="../" class="documentation-logo-link" title="Back to Trumbowyg landing">
  24. <img src="../img/logo-doc.svg" alt="" class="documentation-logo">
  25. </a>
  26. <h1 class="documentation-title">
  27. Documentation
  28. </h1>
  29. <nav class="documentation-menu">
  30. <a href="./">Docs</a> &bull;
  31. <a href="./plugins/">Plugins</a> &bull;
  32. <a href="./core/">Core</a> &bull;
  33. <a href="../demos/">Demos</a>
  34. </nav>
  35. </header>
  36. <aside class="documentation-summary">
  37. <ul>
  38. <li>
  39. <a href="#get-started">Get started</a>
  40. <ul>
  41. <li><a href="#installation">Installation</a></li>
  42. <li><a href="#basics">Basics</a></li>
  43. <li><a href="#common-issues">Common issues</a></li>
  44. <li><a href="#use-plugins">Use plugins</a></li>
  45. <li><a href="./plugins/#create-your-own">Create a plugin</a></li>
  46. </ul>
  47. </li>
  48. <li>
  49. <a href="#general">General</a>
  50. <ul>
  51. <li><a href="#prefix">Prefix</a></li>
  52. <li><a href="#localization">Localization</a></li>
  53. <li><a href="#custom-skin">Custom skin</a></li>
  54. <li><a href="#svg-icons">SVG icons</a></li>
  55. <li><a href="#placeholder">Placeholder</a></li>
  56. <li><a href="#disabled">Disabled</a></li>
  57. </ul>
  58. </li>
  59. <li>
  60. <a href="#basic-options">Basic Options</a>
  61. <ul>
  62. <li><a href="#button-pane">Button pane</a></li>
  63. <li><a href="#hide-button-texts">Hide button texts</a></li>
  64. <li><a href="#semantic">Semantic</a></li>
  65. <li><a href="#reset-css">Reset CSS</a></li>
  66. <li><a href="#remove-format-pasted">Remove format pasted</a></li>
  67. <li><a href="#tags-to-remove">Tags to remove</a></li>
  68. <li><a href="#tags-to-keep">Tags to keep</a></li>
  69. <li><a href="#auto-grow">Auto grow</a></li>
  70. <li><a href="#auto-grow-on-enter">Auto grow on enter</a></li>
  71. <li><a href="#image-width-modal-edit">Image width modal edit</a></li>
  72. <li><a href="#url-protocol">URL protocol</a></li>
  73. <li><a href="#minimal-links">Minimal links</a></li>
  74. </ul>
  75. </li>
  76. <li>
  77. <a href="#advanced-options">Advanced Options</a>
  78. <ul>
  79. <li><a href="#add-localization">Add a localization</a></li>
  80. <li><a href="#custom-buttons">Custom buttons</a></li>
  81. <li><a href="#custom-dropdowns">Custom dropdowns</a></li>
  82. </ul>
  83. </li>
  84. <li>
  85. <a href="#api">API</a>
  86. <ul>
  87. <li><a href="#modal-box">Modal box</a></li>
  88. <li><a href="#range">Range</a></li>
  89. <li><a href="#manage-content">Manage content</a></li>
  90. <li><a href="#empty">Empty</a></li>
  91. <li><a href="#enable-disable-edition">Enable/disable edition</a></li>
  92. <li><a href="#toggle">Toggle HTML/WYSIWYG</a></li>
  93. <li><a href="#destroy-editor">Destroy editor</a></li>
  94. <li><a href="#events">Events</a></li>
  95. </ul>
  96. </li>
  97. </ul>
  98. </aside>
  99. <div class="documentation-sidebar-beer">
  100. <a href="../#donate">
  101. <img src="../img/beer.svg" alt="" class="beer-icon">
  102. <span class="beer-label">
  103. Do you enjoy Trumbowyg? <br>
  104. Buy me some beers :)
  105. </span>
  106. </a>
  107. </div>
  108. </div>
  109. </div>
  110. <main class="main">
  111. <section id="get-started" class="wrapper section">
  112. <h2 class="section-title">Get started</h2>
  113. <div class="feature">
  114. <h3 id="installation">Installation</h3>
  115. <div class="installation-first-step">
  116. <div class="installation-package-managers">
  117. <div class="installation-col-title">
  118. Via a package manager
  119. </div>
  120. <code>npm install trumbowyg</code>
  121. <code>bower install trumbowyg</code>
  122. </div>
  123. <div class="installation-or">
  124. or
  125. </div>
  126. <div class="installation-download">
  127. <div class="installation-col-title">
  128. Download the package
  129. </div>
  130. <a href="https://github.com/Alex-D/Trumbowyg/archive/master.zip" class="button button-primary">Download</a>
  131. </div>
  132. </div>
  133. <p>
  134. If you don't already do it, load jQuery at bottom of <code>&lt;body&gt;</code> like so:
  135. </p>
  136. <pre><code class="html">
  137. &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">&lt;/script>
  138. &lt;script>window.jQuery || document.write('&lt;script src="js/vendor/jquery-3.2.1.min.js">&lt;\/script>')&lt;/script>
  139. </code></pre>
  140. <p class="note">
  141. Trumbowyg requires jQuery >= 1.8
  142. </p>
  143. <p>
  144. After these lines, you have to load Trumbowyg.
  145. </p>
  146. <pre><code class="html">
  147. &lt;script src="node_modules/trumbowyg/dist/trumbowyg.min.js">&lt;/script>
  148. </code></pre>
  149. <p>
  150. Don't forget to load Trumbowyg CSS in the <code>&lt;head&gt;</code>, or load your own style for the
  151. editor.
  152. </p>
  153. <pre><code class="html">
  154. &lt;link rel="stylesheet" href="node_modules/trumbowyg/dist/ui/trumbowyg.min.css">
  155. </code></pre>
  156. </div>
  157. <div class="feature">
  158. <h3 id="basics">Basics</h3>
  159. <p>
  160. This the minimal code to transform a simple div into the amazing WYSIWYG editor which is Trumbowyg.
  161. </p>
  162. <pre><code class="javascript">
  163. $('#trumbowyg-demo').trumbowyg();
  164. </code></pre>
  165. <p>
  166. If you want to set options to Trumbowyg, add an object which contains your options as parameters.
  167. </p>
  168. <pre><code class="javascript">
  169. $('#trumbowyg-demo').trumbowyg({
  170. btns: [['strong', 'em',], ['insertImage']],
  171. autogrow: true
  172. });
  173. </code></pre>
  174. </div>
  175. <div class="feature">
  176. <h3 id="common-issues">Common issues</h3>
  177. <h4>SVG icons does not load</h4>
  178. <ul>
  179. <li>check if you are in HTTP(S) protocol;</li>
  180. <li>check if you do not have cross domain error (XHR request is used).</li>
  181. </ul>
  182. <p>
  183. If your problem is not solved by these tips, check the
  184. <a href="#svg-icons">SVG icons section</a>.
  185. </p>
  186. </div>
  187. <div class="feature">
  188. <h3 id="use-plugins">Use plugins</h3>
  189. <h4>Add a plugin to your page</h4>
  190. <p>
  191. Basically you need to add the plugin JS to your page, at the bottom of your <code>&lt;body></code>,
  192. <strong>after</strong> jQuery and Trumbowyg imports (in this order), but before your custom JS which
  193. initialize Trumbowyg:
  194. </p>
  195. <pre><code class="html">
  196. &lt;-- Import jQuery -->
  197. &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">&lt;/script>
  198. &lt;script>window.jQuery || document.write('&lt;script src="js/vendor/jquery-3.2.1.min.js">&lt;\/script>')&lt;/script>
  199. &lt;-- Import Trumbowyg -->
  200. &lt;script src="node_modules/trumbowyg/dist/trumbowyg.min.js">&lt;/script>
  201. &lt;-- Import Trumbowyg plugins... -->
  202. &lt;script src="node_modules/trumbowyg/dist/plugins/upload/trumbowyg.cleanpaste.min.js">&lt;/script>
  203. &lt;script src="node_modules/trumbowyg/dist/plugins/upload/trumbowyg.pasteimage.min.js">&lt;/script>
  204. &lt;-- Init Trumbowyg -->
  205. &lt;script>
  206. // Doing this in a loaded JS file is better, I put this here for simplicity
  207. $('#my-editor').trumbowyg();
  208. &lt;/script>
  209. </code></pre>
  210. <p>
  211. In the previous case, plugins are "auto registering" themself into Trumbowyg and be activated in
  212. <strong>all</strong> future Trumbowyg instances.
  213. </p>
  214. <p>
  215. But most popular plugins are button-based, like
  216. <a href="./plugins/#plugin-upload">upload</a> or
  217. <a href="./plugins/#plugin-colors">colors</a> ones.
  218. If you want to use these plugins, load them like explained before, then add the plugin button to your editor
  219. by <a href="#button-pane">checking the button pane doc section</a>.
  220. </p>
  221. <p>
  222. For more informations on plugins, check <a href="./plugins/">the plugins documentation page.</a>
  223. </p>
  224. </div>
  225. </section>
  226. <section id="general" class="wrapper section">
  227. <h2 class="section-title">General</h2>
  228. <div class="feature" data-added="1.0.0">
  229. <h3 id="prefix">Prefix</h3>
  230. <p>
  231. You can change prefix of all class added on elements of Trumbowyg using this option:
  232. </p>
  233. <pre><code class="javascript">
  234. $('textarea').trumbowyg({
  235. prefix: 'custom-prefix'
  236. });
  237. </code></pre>
  238. <p>
  239. For example, the bold button class is now <code class="javascript">custom-prefix-bold-button</code>
  240. </p>
  241. <p class="note">
  242. Default value is <code>trumbowyg</code>
  243. </p>
  244. </div>
  245. <div class="feature" data-added="1.0.0">
  246. <h3 id="localization">Localization</h3>
  247. <p>
  248. Your users don't speak english? No problem, Trumbowyg has a language parameter. You have to load the
  249. appropriate lang file. Search in <code>/dist/langs</code> folder to see if a language file already
  250. exists, if not create it and share it :). See <a href="#add-localization">add a localization</a> for
  251. more details on language file.
  252. </p>
  253. <p>
  254. Don't forget include the lang file in your pages:
  255. </p>
  256. <pre><code class="html">
  257. &lt;script type="text/javascript" src="js/dist/langs/fr.min.js"&gt;&lt;/script&gt;
  258. </code></pre>
  259. <p class="note">
  260. Warning, include lang file after Trumbowyg and before instantiating the editor!
  261. </p>
  262. <p>
  263. Usage of language parameter:
  264. </p>
  265. <pre><code class="javascript">
  266. $('textarea').trumbowyg({
  267. lang: 'fr'
  268. });
  269. </code></pre>
  270. <p class="note">
  271. If the lang was not found, english values are used by default.
  272. </p>
  273. </div>
  274. <div class="feature" data-added="1.0.0">
  275. <h3 id="custom-skin">Custom skin</h3>
  276. <p>
  277. Trumbowyg is flexible and simple. You want a different look?
  278. </p>
  279. <h4>Replace existing CSS file</h4>
  280. <p>
  281. Copy <code>/src/ui/</code> folder somewhere and customize style. Finally, link your new CSS file and
  282. remove link to Trumbowyg default style.
  283. </p>
  284. <p class="note">
  285. It is not recommended to directly edit the CSS file in the trumbowyg folder. When you update the plugin,
  286. your modifications will be erased.
  287. </p>
  288. <br>
  289. <h4>Multiple skins for multiple Trumbowyg</h4>
  290. <p>
  291. This is useful when you do not want same design for all instances of Trumbowyg.
  292. </p>
  293. <p>
  294. Use the prefix option:
  295. </p>
  296. <pre><code class="javascript">
  297. $('.editor-modern-ui').trumbowyg({
  298. prefix: 'modern-ui'
  299. });
  300. </code></pre>
  301. <p>
  302. In your CSS, you can now stylize <code>.modern-ui-link-button</code> for example, whitout conflicts with
  303. the default skin. It's necessary to redefine style for all elements. If you want to start from the
  304. default skin, copy <code>/src/ui/</code> folder, replace all <code>trumbowyg-</code> by your prefix and
  305. work from here.
  306. </p>
  307. </div>
  308. <div class="feature" data-added="2.1.0">
  309. <h3 id="svg-icons">SVG icons</h3>
  310. <p class="added-feature">Added in 2.1.0</p>
  311. <p>
  312. A pack of SVG icons is available and enabled by default. This file is loaded via XHR request
  313. in JavaScript so it is possible the path is not matching with your assets file paths.
  314. You can change the path of the SVG or disable this feature.
  315. </p>
  316. <h4>Change SVG path globally</h4>
  317. <p>
  318. To change SVG path, you need to set the path in global Trumbowyg configuration object:
  319. </p>
  320. <pre><code class="javascript">
  321. $.trumbowyg.svgPath = '/assets/my-custom-path/icons.svg';
  322. </code></pre>
  323. <p class="note">
  324. This global way needs to be done before initialize any Trumbowyg instance.
  325. </p>
  326. <h4>Disable SVG icons globally</h4>
  327. <p>
  328. If you do not want SVG icons, you can set this option to false. Then, you can add your custom
  329. icons by CSS or what you want.
  330. </p>
  331. <pre><code class="javascript">
  332. $.trumbowyg.svgPath = false:
  333. </code></pre>
  334. <p>
  335. Check <a href="#hide-button-texts">hide button texts</a> option if you did not want button content at all
  336. and customize it by yourself.
  337. </p>
  338. <p class="note">
  339. This global way needs to be done before initialize any Trumbowyg instance.
  340. </p>
  341. <h4>Change SVG path or disable SVG icons locally</h4>
  342. <p>
  343. You can also apply <code>svgPath</code> option for an isolated editor only.
  344. </p>
  345. <pre><code class="javascript">
  346. $('.editor').trumbowyg({
  347. svgPath: false // or a path like '/assets/my-custom-path/icons.svg'
  348. });
  349. </code></pre>
  350. <h4>Use SVG icons without XHR or via an another protocol than HTTP(S)</h4>
  351. <p class="note">
  352. If you want to be IE9-complient you should use this option.
  353. </p>
  354. <p>
  355. If you do not want use HTTP(S) protocol or use XHR to load icons, you can load icons in your HTML
  356. by your own. You just need to include the
  357. <a href="https://raw.githubusercontent.com/Alex-D/Trumbowyg/master/dist/ui/icons.svg">icons.svg file</a>
  358. inline in your <code>&lt;body></code>:
  359. </p>
  360. <pre><code class="html">
  361. &lt;div id="trumbowyg-icons">
  362. &lt;svg xmlns="http://www.w3.org/2000/svg">
  363. &lt;symbol id="trumbowyg-blockquote" viewBox="0 0 72 72">&lt;path d="...">&lt;/path>&lt;/symbol>
  364. &lt;symbol id="trumbowyg-bold" viewBox="0 0 72 72">&lt;path d="...">&lt;/path>&lt;/symbol>
  365. &lt;symbol id="trumbowyg-close" viewBox="0 0 72 72">&lt;path d="...">&lt;/path>&lt;/symbol>
  366. &lt;!-- ... all other icons here -->
  367. &lt;/svg>
  368. &lt;/div>
  369. </code></pre>
  370. <p class="note">
  371. You need to use this id: <code>&lt;prefix&gt;-icons</code>.
  372. </p>
  373. <p>
  374. Trumbowyg check if a <code>#&lt;prefix&gt;-icons</code> exists. If not, it loads SVG icons file via
  375. XHR and put it in a div with this id. Next editor on the page do not load icons again. By adding
  376. this div in the page, you "hack" this mecanism to load it by your own.
  377. </p>
  378. </div>
  379. <div class="feature" data-added="1.1.3">
  380. <h3 id="placeholder">Placeholder</h3>
  381. <p>
  382. Like the HTML5 attribute on input and textarea, you can add a placeholder with Trumbowyg.
  383. </p>
  384. <pre><code class="html">
  385. &lt;div class="my-editor" placeholder="Your text as placeholder">&lt;/div>
  386. </code></pre>
  387. <p class="note">
  388. Placeholder is visible only if the element is empty (no HTML/text).
  389. </p>
  390. <div class="note">
  391. <p>
  392. Placeholder is both managed in JS and CSS with the default style. If you create your own style, you
  393. need to apply the following style (replace <code>trumbowyg</code> by your prefix):
  394. </p>
  395. <pre><code class="css">
  396. .trumbowyg-editor[contenteditable=true]:empty::before{
  397. content: attr(placeholder);
  398. color: #999;
  399. }
  400. </code></pre>
  401. </div>
  402. </div>
  403. <div class="feature" data-added="2.1.0">
  404. <h3 id="disabled">Disabled</h3>
  405. <p class="added-feature">Added in 2.1.0</p>
  406. <p>
  407. Trumbowyg supports <code>disabled</code> attribute on a textarea and an option.
  408. </p>
  409. <pre><code class="html">
  410. &lt;textarea class="my-editor" disabled>&lt;/textarea>
  411. </code></pre>
  412. <pre><code class="javascript">
  413. $('.a-disabled-editor').trumbowyg({
  414. disabled: true
  415. });
  416. </code></pre>
  417. <p class="note">
  418. You can switch between disabled and enabled states by <a href="#enable-disable-edition">using API</a>
  419. </p>
  420. </div>
  421. </section>
  422. <section id="basic-options" class="wrapper section">
  423. <h2 class="section-title">Basic Options</h2>
  424. <div class="feature" data-added="1.0.0">
  425. <h3 id="button-pane">Button pane</h3>
  426. <p>
  427. It's probably the most interesting option, it allows you to choose the buttons that appears in the
  428. button pane. This option is an array containing string values representing the buttons or vertical
  429. separators (using the pipe character). To create your own custom button pane, define an array and pass
  430. it to the <code>btns</code> option.
  431. </p>
  432. <pre><code class="javascript">
  433. $('.simple-editor').trumbowyg({
  434. btns: [['bold', 'italic'], ['link']]
  435. });
  436. </code></pre>
  437. <div class="note">
  438. <p>
  439. By default, <code>btns</code> option value is:
  440. </p>
  441. <pre><code class="javascript">
  442. $('.simple-editor').trumbowyg({
  443. btns: [
  444. ['viewHTML'],
  445. ['undo', 'redo'], // Only supported in Blink browsers
  446. ['formatting'],
  447. ['strong', 'em', 'del'],
  448. ['superscript', 'subscript'],
  449. ['link'],
  450. ['insertImage'],
  451. ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
  452. ['unorderedList', 'orderedList'],
  453. ['horizontalRule'],
  454. ['removeformat'],
  455. ['fullscreen']
  456. ]
  457. });
  458. </code></pre>
  459. </div>
  460. </div>
  461. <div class="feature" data-added="2.5.0">
  462. <h3 id="hide-button-texts">Hide button texts</h3>
  463. <p class="added-feature">Added in 2.5.0</p>
  464. <p>
  465. You can hide button texts showed when you put <a href="#svg-icons">svgPath to false</a>.
  466. </p>
  467. <pre><code class="javascript">
  468. // Globally
  469. $.trumbowyg.hideButtonTexts = true
  470. // Or locally
  471. $('.trumbowyg').trumbowyg({
  472. hideButtonTexts: true
  473. });
  474. </code></pre>
  475. <p class="note">
  476. If you disable SVG icons and button texts, you should design them by yourself.
  477. </p>
  478. </div>
  479. <div class="feature" data-added="1.0.0">
  480. <h3 id="semantic">Semantic</h3>
  481. <p>
  482. Generates a better, more semantic oriented HTML (i.e. <code>&lt;em&gt;</code> instead of <code>
  483. &lt;i&gt;</code>, <code>&lt;strong&gt;</code> intsead of <code>&lt;b&gt;</code>, etc.). It's just a
  484. boolean:
  485. </p>
  486. <pre><code class="javascript">
  487. $('.trumbowyg').trumbowyg({
  488. semantic: false
  489. });
  490. </code></pre>
  491. <p>
  492. This option deactivates the <em>underline</em> button by default because they do not convey any real
  493. semantic. If you want to reactivate them, you have to do it explicitly, see <a href="#button-pane">Button
  494. pane</a>
  495. </p>
  496. <p class="note">
  497. This option is set to <code>true</code> by default
  498. </p>
  499. </div>
  500. <div class="feature" data-added="1.0.0">
  501. <h3 id="reset-css">Reset CSS</h3>
  502. <p>
  503. If you don't want the page style to impact on the look of the text in the editor, you will need to apply
  504. a reset-css on the editor. You can activate this with the <code>resetCss</code> option:
  505. </p>
  506. <pre><code class="javascript">
  507. $('.trumbowyg').trumbowyg({
  508. resetCss: true
  509. });
  510. </code></pre>
  511. <p class="note">
  512. This option is set to <code>false</code> by default. The reset only applies to the editor, not to the
  513. generated HTML code.
  514. </p>
  515. </div>
  516. <div class="feature" data-added="2.0.0">
  517. <h3 id="remove-format-pasted">Remove format pasted</h3>
  518. <p>
  519. If you don't want styles pasted from clipboard (from Word or other webpage for example), pass the <code>removeformatPasted</code>
  520. option to <code>true</code>
  521. </p>
  522. <pre><code class="javascript">
  523. $('.trumbowyg').trumbowyg({
  524. removeformatPasted: true
  525. });
  526. </code></pre>
  527. <p class="note">
  528. In order to use this option, you need to define a font size in your CSS or use a reset like normalize.
  529. </p>
  530. <p class="note">
  531. Remove format pasted is not active by default (set to <code>false</code>).
  532. </p>
  533. </div>
  534. <div class="feature" data-added="2.0.0">
  535. <h3 id="tags-to-remove">Tags to remove</h3>
  536. <p>
  537. Allow to sanitize the code by removing all tags you want. The <code>tagsToRemove</code>
  538. option is an array.
  539. </p>
  540. <pre><code class="javascript">
  541. $('.trumbowyg').trumbowyg({
  542. tagsToRemove: ['script', 'link']
  543. });
  544. </code></pre>
  545. <p class="note">
  546. You must do the sanitize server-side too to avoid some security issues like XSS.
  547. </p>
  548. <p class="note">
  549. Tags to remove is an empty array by default (set to <code>[]</code>).
  550. </p>
  551. </div>
  552. <div class="feature" data-added="2.12.0">
  553. <h3 id="tags-to-keep">Tags to keep</h3>
  554. <p class="added-feature">Added in 2.12.0</p>
  555. <p>
  556. Sometimes you want to keep some empty <code>i</code> tags for <em>Font Awesome</em> or anything else. You can define this list via the <code>tagsToKeep</code>
  557. option.
  558. </p>
  559. <pre><code class="javascript">
  560. $('.trumbowyg').trumbowyg({
  561. tagsToKeep: ['i', 'script[src]']
  562. });
  563. </code></pre>
  564. <p class="note">
  565. Default tags to keep are <code>['hr', 'img', 'embed', 'iframe', 'input']</code>.
  566. </p>
  567. </div>
  568. <div class="feature" data-added="1.0.0">
  569. <h3 id="auto-grow">Auto grow</h3>
  570. <p>
  571. The text editing zone can extend itself when writing a long text. To activate this feature, use the
  572. autogrow option:
  573. </p>
  574. <pre><code class="javascript">
  575. $('.trumbowyg').trumbowyg({
  576. autogrow: true
  577. });
  578. </code></pre>
  579. <p class="note">
  580. Autogrow is not active by default (set to <code>false</code>).
  581. </p>
  582. </div>
  583. <div class="feature" data-added="2.7.0">
  584. <h3 id="auto-grow-on-enter">Auto grow on enter</h3>
  585. <p class="added-feature">Added in 2.7.0</p>
  586. <p>
  587. The text editing zone can extend itself when editor get focus and reduce on blur.
  588. To activate this feature, use the following option:
  589. </p>
  590. <pre><code class="javascript">
  591. $('.trumbowyg').trumbowyg({
  592. autogrowOnEnter: true
  593. });
  594. </code></pre>
  595. <p class="note">
  596. Autogrow on enter is not active by default (set to <code>false</code>).
  597. </p>
  598. </div>
  599. <div class="feature" data-added="2.9.0">
  600. <h3 id="image-width-modal-edit">Image width modal edit</h3>
  601. <p class="added-feature">Added in 2.9.0</p>
  602. <p>
  603. Add a field in image insert/edit modal which allow users to set the image width.
  604. To activate this feature, use the following option:
  605. </p>
  606. <pre><code class="javascript">
  607. $('.trumbowyg').trumbowyg({
  608. imageWidthModalEdit: true
  609. });
  610. </code></pre>
  611. <p class="note">
  612. Image width modal edit is not active by default (set to <code>false</code>).
  613. </p>
  614. </div>
  615. <div class="feature" data-added="2.9.4">
  616. <h3 id="url-protocol">URL protocol</h3>
  617. <p class="added-feature">Added in 2.9.4</p>
  618. <p>
  619. An option to auto-prefix URLs with a protocol.
  620. </p>
  621. <p>
  622. When this option
  623. is set to <code>true</code>, URLs missing a protocol will be
  624. prefixed with <code>https://</code>. Alternatively, a string can
  625. be provided for a custom prefix.
  626. </p>
  627. <p>
  628. For example, a value of <code>true</code> would convert
  629. <code>example.com</code> to
  630. <code>https://example.com</code>, while a value of
  631. <code>ftp</code> converts to
  632. <code>ftp://example.com</code>.
  633. </p>
  634. <pre><code class="javascript">
  635. $('.trumbowyg').trumbowyg({
  636. urlProtocol: true
  637. });
  638. </code></pre>
  639. <p class="note">
  640. Anchors, email addresses and relative links are left unchanged.
  641. </p>
  642. <p class="note">
  643. URL protocol is not active by default (set to <code>false</code>).
  644. </p>
  645. </div>
  646. <div class="feature" data-added="2.9.4">
  647. <h3 id="minimal-links">Minimal links</h3>
  648. <p class="added-feature">Added in 2.9.4</p>
  649. <p>
  650. Reduce the link overlay to use only <code>url</code> and
  651. <code>text</code> fields, omitting <code>title</code> and
  652. <code>target</code>.
  653. </p>
  654. <pre><code class="javascript">
  655. $('.trumbowyg').trumbowyg({
  656. minimalLinks: true
  657. });
  658. </code></pre>
  659. <p class="note">
  660. The minimal links option is not active by default (set to
  661. <code>false</code>).
  662. </p>
  663. </div>
  664. </section>
  665. <section id="advanced-options" class="wrapper section">
  666. <h2 class="section-title">Advanced Options</h2>
  667. <div class="feature" data-added="1.0.0">
  668. <h3 id="add-localization">Add a localization</h3>
  669. <p>
  670. The structure of a language file is simple, it is a JavaScript Object which associate a translation to
  671. any key. For example:
  672. </p>
  673. <pre><code class="javascript">
  674. jQuery.trumbowyg.langs.fr = {
  675. _dir: "ltr", // Changes the editor dir
  676. bold: "Gras",
  677. close: "Fermer"
  678. };
  679. </code></pre>
  680. <p>
  681. Some localizations are added each day, you can find them in
  682. <a href="https://github.com/Alex-D/Trumbowyg/tree/master/dist/langs">the langs folder on GitHub</a>
  683. </p>
  684. <p>
  685. You can submit a new localization file by creating a new pull request on the Github repository.
  686. </p>
  687. <p class="note">
  688. English is the default localization, you don't need to include any file to get Trumbowyg in English.
  689. </p>
  690. </div>
  691. <div class="feature" data-added="1.0.0">
  692. <h3 id="custom-buttons">Custom buttons</h3>
  693. <p>
  694. If Trumbowyg does not fit your needs, maybe you can create your very own custom button to solve this.
  695. The following code (which does not works as is) show you all available button parameters.
  696. </p>
  697. <pre><code class="javascript">
  698. $('.trumbowyg').trumbowyg({
  699. btnsDef: {
  700. buttonName: {
  701. fn: 'functionName',
  702. tag: 'tagName',
  703. title: 'Button tooltip',
  704. text: 'Displayed button name',
  705. isSupported: function () { return true; },
  706. key: 'K',
  707. param: '' ,
  708. forceCSS: false,
  709. class: '',
  710. hasIcon: true
  711. }
  712. }
  713. });
  714. </code></pre>
  715. <p>
  716. The key (here <code>buttonName</code>) is the button name used in <code>btns</code> and in <code>dropdown</code>.
  717. It is used as many default in options below.
  718. </p>
  719. <h4>Parameters</h4>
  720. <dl>
  721. <dt><strong><code>fn</code></strong> <code class="type">string</code>|<code class="type">function</code></dt>
  722. <dd>
  723. The name of a Trumbowyg internal method OR a callable function OR browser native execCommand name.
  724. In any case, the function is called when the user click on the button or use the associated shortcut.
  725. <br>
  726. <strong>Default</strong>: button name
  727. </dd>
  728. <dt><strong><code>tag</code></strong> <code class="type">string</code></dt>
  729. <dd>
  730. The HTML tag name which highlight the button if cursor is in a tag which this tag name.
  731. <br>
  732. <strong>Default</strong>: button name
  733. </dd>
  734. <dt><strong><code>title</code></strong> <code class="type">string</code></dt>
  735. <dd>
  736. The text displayed in a tooltip on mouse over a button.
  737. <br>
  738. <strong>Default</strong>: <code>text</code> parameter OR translated button name OR raw button name
  739. </dd>
  740. <dt><strong><code>text</code></strong> <code class="type">string</code></dt>
  741. <dd>
  742. The text of the button used when <a href="#svg-icons">svgPath is set to false</a>.
  743. This text can be hidden via <code><a href="#hide-button-texts">hideButtonTexts</a></code> option.
  744. <br>
  745. <strong>Default</strong>: <code>title</code> parameter OR translated button name OR raw button name
  746. </dd>
  747. <dt><strong><code>isSupported</code></strong> <code class="type">function</code></dt>
  748. <dd>
  749. A function which returns a Boolean to know if the custom button is supported (browser compatibility
  750. check, context check, ...)
  751. <br>
  752. <strong>Default</strong>: <code>null</code> (no check)
  753. </dd>
  754. <dt><strong><code>key</code></strong> <code class="type">string</code></dt>
  755. <dd>
  756. Shortcut key which triggers the button function (<code>fn</code>)
  757. <br>
  758. <strong>Default</strong>: <code>null</code> (no shortcut defined)
  759. </dd>
  760. <dt><strong><code>param</code></strong> <code class="type">string</code></dt>
  761. <dd>
  762. In case of using browser native execCommand, give this as parameter.
  763. <br>
  764. <strong>Default</strong>: button name
  765. </dd>
  766. <dt><strong><code>forceCSS</code></strong> <code class="type">string</code></dt>
  767. <dd>
  768. In case of using browser native execCommand, force usage of inline CSS insteed of a tag.
  769. <br>
  770. <strong>Default</strong>: <code>false</code>
  771. </dd>
  772. <dt><strong><code>class</code></strong> <code class="type">string</code></dt>
  773. <dd>
  774. A string which is added to the button class attribute.
  775. <br>
  776. <strong>Default</strong>: Trumbowyg adds a <code>prefix + '-' + buttonName</code> class
  777. </dd>
  778. <dt><strong><code>hasIcon</code></strong> <code class="type">boolean</code></dt>
  779. <dd>
  780. Allow us to force the display of the text for a specific button.
  781. <br>
  782. <strong>Default</strong>: <code>true</code>
  783. </dd>
  784. </dl>
  785. <p>
  786. Working example:
  787. </p>
  788. <pre><code class="javascript">
  789. $('.trumbowyg').trumbowyg({
  790. btnsDef: {
  791. alert: {
  792. fn: function() {
  793. alert('some text')
  794. },
  795. ico: 'blockquote'
  796. }
  797. },
  798. btns: [
  799. ['alert']
  800. ]
  801. });
  802. </code></pre>
  803. </div>
  804. <div class="feature" data-added="1.0.0">
  805. <h3 id="custom-dropdowns">Custom dropdowns</h3>
  806. <p>
  807. You can also create your own dropdown, like buttons. The following code (which does not works as is)
  808. show use all options which can be used to make our own customized dropdown.
  809. </p>
  810. <pre><code class="javascript">
  811. $('.trumbowyg').trumbowyg({
  812. btnsDef: {
  813. dropdownButtonName: {
  814. dropdown: ['btnA', 'btnB'],
  815. title: 'Displayed dropdown button name',
  816. ico: 'iconName',
  817. hasIcon: true
  818. }
  819. }
  820. });
  821. </code></pre>
  822. <h4>Parameters</h4>
  823. <dl>
  824. <dt><strong><code>dropdown</code></strong> <code class="type">array&lt;string></code></dt>
  825. <dd>
  826. A list of button names to list in the dropdown.
  827. <br>
  828. <strong>Default</strong>: <code>[]</code>
  829. </dd>
  830. <dt><strong><code>title</code></strong> <code class="type">string</code></dt>
  831. <dd>
  832. The text displayed in a tooltip on mouse over the dropdown button.
  833. <br>
  834. <strong>Default</strong>: translated dropdown button name OR raw dropdown button name
  835. </dd>
  836. <dt><strong><code>ico</code></strong> <code class="type">string</code></dt>
  837. <dd>
  838. The icon name for the dropdown. You can reuse <a href="https://github.com/Alex-D/Trumbowyg/tree/develop/src/ui/icons">some existing icons from Trumbowyg</a>.
  839. <br>
  840. <strong>Default</strong>: icon with button name in snake case
  841. </dd>
  842. <dt><strong><code>hasIcon</code></strong> <code class="type">boolean</code></dt>
  843. <dd>
  844. Allow us to force the display of the text for a specific button.
  845. <br>
  846. <strong>Default</strong>: <code>true</code>
  847. </dd>
  848. </dl>
  849. <p>
  850. Working example which groups all justify buttons in one dropdown:
  851. </p>
  852. <pre><code class="javascript">
  853. $('.trumbowyg').trumbowyg({
  854. btnsDef: {
  855. align: {
  856. dropdown: ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
  857. ico: 'justifyLeft'
  858. }
  859. },
  860. btns: [
  861. ['align']
  862. ]
  863. });
  864. </code></pre>
  865. </div>
  866. </section>
  867. <section id="api" class="wrapper section">
  868. <h2 class="section-title">API</h2>
  869. <div class="feature" data-added="1.0.0">
  870. <h3 id="modal-box">Modal box</h3>
  871. <p>
  872. When you want create your custom extension for Trumbowyg, you can open and close a modal box with custom
  873. inner HTML code, listen events and more.
  874. </p>
  875. <h4>Open and close</h4>
  876. <p>
  877. For that use the <code class="javascript">.trumbowyg()</code> method and give parameters <code>'openModal'</code>
  878. or <code>'closeModal'</code> like that:
  879. </p>
  880. <pre><code class="javascript">
  881. // Open a modal box
  882. var $modal = $('#editor').trumbowyg('openModal', {
  883. title: 'A title for modal box',
  884. content: '&lt;p&gt;Content in HTML which you want include in created modal box&lt;/p&gt;'
  885. });
  886. // Close current modal box
  887. $('#editor').trumbowyg('closeModal');
  888. </code></pre>
  889. <p>
  890. An <code>openModal</code> call returns a jQuery object which contains the modal box. You need this
  891. object if you want to use listen events (see below).
  892. </p>
  893. <p class="note">
  894. Only one modal box can open at any given moment. So, <code>openModal</code> return false if a modal is
  895. curently opened.
  896. </p>
  897. <h4>Events on modal box</h4>
  898. <p>
  899. Modal boxes in Trumbowy come with two buttons: "Confirm" and "Cancel". An event is associated to each
  900. one:
  901. </p>
  902. <ul>
  903. <li><code>tbwsubmit</code>: trigged when form is submit</li>
  904. <li><code>tbwreset</code>: trigged when user cancel operation</li>
  905. </ul>
  906. <pre><code class="javascript">
  907. // Open a modal box
  908. var $modal = $('#editor').trumbowyg('openModal', {
  909. title: 'A title for modal box',
  910. content: '&lt;p&gt;Content in HTML which you want include in created modal box&lt;/p&gt;'
  911. });
  912. // Listen clicks on modal box buttons
  913. $modal.on('tbwconfirm', function(e){
  914. // Save datas
  915. $("#editor").trumbowyg('closeModal');
  916. });
  917. $modal.on('tbwcancel', function(e){
  918. $('#editor').trumbowyg('closeModal');
  919. });
  920. </code></pre>
  921. <h4>Only build inputs in modal</h4>
  922. <p>
  923. If you want only add inputs in the modal box, this function is more simple. Indeed, you do not manage
  924. confirm and close buttons, and get all input value on confirm.
  925. </p>
  926. <pre><code class="javascript">
  927. var img = $('img#an-img');
  928. $("#editor").trumbowyg('openModalInsert', {
  929. title: 'A title for modal box',
  930. fields: {
  931. url: {
  932. value: img.attr('src')
  933. },
  934. alt: {
  935. label: 'Alt',
  936. name: 'alt',
  937. value: img.attr('alt'),
  938. type: 'text'.
  939. attributes: {}
  940. },
  941. example: {
  942. // Missing label is replaced by the key of this object (here 'example')
  943. // Missing name is the key
  944. // When value is missing, value = ''
  945. // When type is missing, 'text' is assumed. You can use all the input field types,
  946. // plus checkbox and radio (select and textarea are not supported)
  947. // When attributes is missing, {} is used. Attributes are added as attributes to
  948. // the input element.
  949. // For radio and checkbox fields, you will need to use attributes if you want it
  950. // to be checked by default. }
  951. },
  952. callback: function(values){
  953. img.attr('src', values['url']);
  954. img.attr('alt', values['alt']);
  955. return true; // Return true if you have finished with this modal box
  956. // If you do not return anything, you must manage the closing of the modal box yourself
  957. }
  958. });
  959. // You can also listen for modal confirm/cancel events to do some custom things
  960. // Note: the openModalInsert callback is called on tbwconfirm
  961. $modal.on('tbwconfirm', function(e){
  962. // Do what you want
  963. });
  964. $modal.on('tbwcancel', function(e){
  965. trumbowyg.closeModal();
  966. });
  967. </code></pre>
  968. </div>
  969. <div class="feature" data-added="2.0.0">
  970. <h3 id="range">Range</h3>
  971. <p>
  972. Managing correctly text range, is not so trivial. Trumbowyg has a system to save and restore
  973. selection range which does not involves typical getter/setter.
  974. </p>
  975. <h4>Save and get current range</h4>
  976. <pre><code class="javascript">
  977. // Save current range
  978. $('#editor').trumbowyg('saveRange');
  979. // Restore last saved range
  980. $('#editor').trumbowyg('restoreRange');
  981. </code></pre>
  982. <h4>Get selection range</h4>
  983. <pre><code class="javascript">
  984. // range contains a JavaScript range
  985. var range = $('#editor').trumbowyg('getRange');
  986. </code></pre>
  987. <h4>Get last saved range text</h4>
  988. <pre><code class="javascript">
  989. var text = $('#editor').trumbowyg('getRangeText');
  990. </code></pre>
  991. </div>
  992. <div class="feature" data-added="1.0.0">
  993. <h3 id="manage-content">Manage content</h3>
  994. <p>
  995. You can set and get current HTML content of the editor with a getter/setter:
  996. </p>
  997. <pre><code class="javascript">
  998. // Get HTML content
  999. $('#editor').trumbowyg('html');
  1000. // Set HTML content
  1001. $('#editor').trumbowyg('html', "&lt;p&gt;Your content here&lt;/p&gt;");
  1002. </code></pre>
  1003. </div>
  1004. <div class="feature" data-added="1.0.0">
  1005. <h3 id="empty">Empty</h3>
  1006. <p>
  1007. You can empty the content of the editor.
  1008. </p>
  1009. <pre><code class="javascript">
  1010. $('#editor').trumbowyg('empty');
  1011. </code></pre>
  1012. </div>
  1013. <div class="feature" data-added="2.1.0">
  1014. <h3 id="enable-disable-edition">Enable/disable edition</h3>
  1015. <p class="added-feature">Added in 2.1.0</p>
  1016. <p>
  1017. As you can disable editor by using <a href="#disabled">disabled</a> option, you can also switch between
  1018. enabled and disabled states by using API.
  1019. </p>
  1020. <pre><code class="javascript">
  1021. $('#editor').trumbowyg('disable');
  1022. $('#editor').trumbowyg('enable');
  1023. </code></pre>
  1024. </div>
  1025. <div class="feature" data-added="2.9.0">
  1026. <h3 id="toggle">Toggle between HTML & WYSIWYG modes</h3>
  1027. <p class="added-feature">Added in 2.9.0</p>
  1028. <p>
  1029. You can switch between HTML view and WYSIWYG view via toggle method.
  1030. </p>
  1031. <pre><code class="javascript">
  1032. $('#editor').trumbowyg('toggle');
  1033. </code></pre>
  1034. </div>
  1035. <div class="feature" data-added="1.0.0">
  1036. <h3 id="destroy-editor">Destroy editor</h3>
  1037. <p>
  1038. When you wish, you can restore the previous state of the element was used to create the editor.
  1039. </p>
  1040. <pre><code class="javascript">
  1041. $('#editor').trumbowyg('destroy');
  1042. </code></pre>
  1043. </div>
  1044. <div class="feature" data-added="1.1.0">
  1045. <h3 id="events">Events</h3>
  1046. <p>
  1047. Some events are fired on the jQuery element which is used to build the editor.
  1048. </p>
  1049. <ul>
  1050. <li>Focus on editor: <code>tbwfocus</code></li>
  1051. <li>Blur on editor: <code>tbwblur</code></li>
  1052. <li>Editor is initialized: <code>tbwinit</code> <span class="version-tag">2.0.0</span></li>
  1053. <li>Change in editor: <code>tbwchange</code> <span class="version-tag">2.0.0</span></li>
  1054. <li>Resize the editor on autogrow: <code>tbwresize</code> <span class="version-tag">2.0.0</span></li>
  1055. <li>Paste something in the editor: <code>tbwpaste</code> <span class="version-tag">2.0.0</span></li>
  1056. <li>Switch to fullscreen mode: <code>tbwopenfullscreen</code> <span class="version-tag">2.0.0</span>
  1057. </li>
  1058. <li>Leave editor's fullscreen mode: <code>tbwclosefullscreen</code> <span
  1059. class="version-tag">2.0.0</span></li>
  1060. <li>Close the editor: <code>tbwclose</code> <span class="version-tag">2.0.0</span></li>
  1061. </ul>
  1062. <pre><code class="javascript">
  1063. $('#editor')
  1064. .trumbowyg() // Build Trumbowyg on the #editor element
  1065. .on('tbwfocus', function(){ console.log('Focus!'); }); // Listen for `tbwfocus` event
  1066. .on('tbwblur', function(){ console.log('Blur!'); }); // Listen for `tbwblur` event
  1067. </code></pre>
  1068. </div>
  1069. </section>
  1070. </main>
  1071. <script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  1072. <script>window.jQuery || document.write('<script src="../js/vendor/jquery-1.11.1.min.js"><\/script>')</script>
  1073. <script src="../js/vendor/highlight.js"></script>
  1074. <script src="../js/main.js"></script>
  1075. </body>
  1076. </html>