cloning-medium-with-parchment.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. export const externalResources = [
  2. 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css',
  3. 'https://fonts.googleapis.com/css?family=Open+Sans%3A300,400,600,700',
  4. 'https://platform.twitter.com/widgets.js',
  5. ];
  6. export const basicHTML = `
  7. <link href="/styles.css" rel="stylesheet">
  8. <div id="tooltip-controls">
  9. <button id="bold-button"><i class="fa fa-bold"></i></button>
  10. <button id="italic-button"><i class="fa fa-italic"></i></button>
  11. <button id="link-button"><i class="fa fa-link"></i></button>
  12. <button id="blockquote-button"><i class="fa fa-quote-right"></i></button>
  13. <button id="header-1-button"><i class="fa fa-header"><sub>1</sub></i></button>
  14. <button id="header-2-button"><i class="fa fa-header"><sub>2</sub></i></button>
  15. </div>
  16. <div id="sidebar-controls">
  17. <button id="image-button"><i class="fa fa-camera"></i></button>
  18. <button id="video-button"><i class="fa fa-play"></i></button>
  19. <button id="tweet-button"><i class="fa fa-twitter"></i></button>
  20. <button id="divider-button"><i class="fa fa-minus"></i></button>
  21. </div>
  22. `;
  23. export const html = `
  24. <link href="{{site.cdn}}/quill.core.css" rel="stylesheet" />
  25. <script src="{{site.cdn}}/quill.core.js"></script>
  26. ${basicHTML}
  27. <div id="editor">Tell your story...</div>
  28. <script type="module" src="/index.js"></script>
  29. `;
  30. export const basicCSS = `
  31. #editor {
  32. border: 1px solid #ccc;
  33. font-family: 'Open Sans', Helvetica, sans-serif;
  34. font-size: 1.2em;
  35. height: 180px;
  36. margin: 0 auto;
  37. width: 450px;
  38. }
  39. #tooltip-controls, #sidebar-controls {
  40. text-align: center;
  41. }
  42. button {
  43. background: transparent;
  44. border: none;
  45. cursor: pointer;
  46. display: inline-block;
  47. font-size: 18px;
  48. padding: 0;
  49. height: 32px;
  50. width: 32px;
  51. text-align: center;
  52. }
  53. button:active, button:focus {
  54. outline: none;
  55. }
  56. `;
  57. export const boldBlot = `
  58. const Inline = Quill.import('blots/inline');
  59. class BoldBlot extends Inline {
  60. static blotName = 'bold';
  61. static tagName = 'strong';
  62. }
  63. Quill.register(BoldBlot);
  64. `;
  65. export const italicBlot = `
  66. const Inline = Quill.import('blots/inline');
  67. class ItalicBlot extends Inline {
  68. static blotName = 'italic';
  69. static tagName = 'em';
  70. }
  71. Quill.register(ItalicBlot);
  72. `;
  73. export const linkBlot = `
  74. const Inline = Quill.import('blots/inline');
  75. class LinkBlot extends Inline {
  76. static blotName = 'link';
  77. static tagName = 'a';
  78. static create(url) {
  79. let node = super.create();
  80. // Sanitize url if desired
  81. node.setAttribute('href', url);
  82. // Okay to set other non-format related attributes
  83. node.setAttribute('target', '_blank');
  84. return node;
  85. }
  86. static formats(node) {
  87. // We will only be called with a node already
  88. // determined to be a Link blot, so we do
  89. // not need to check ourselves
  90. return node.getAttribute('href');
  91. }
  92. }
  93. Quill.register(LinkBlot);
  94. `;
  95. export const blockquoteBlot = `
  96. const Block = Quill.import('blots/block');
  97. class BlockquoteBlot extends Block {
  98. static blotName = 'blockquote';
  99. static tagName = 'blockquote';
  100. }
  101. Quill.register(BlockquoteBlot);
  102. `;
  103. export const headerBlot = `
  104. const Block = Quill.import('blots/block');
  105. class HeaderBlot extends Block {
  106. static blotName = 'header';
  107. static tagName = ['h1', 'h2'];
  108. }
  109. Quill.register(HeaderBlot);
  110. `;
  111. export const cssWithBlockquoteAndHeader = `
  112. ${basicCSS}
  113. #editor h1 + p,
  114. #editor h2 + p {
  115. margin-top: 0.5em;
  116. }
  117. #editor blockquote {
  118. border-left: 4px solid #111;
  119. padding-left: 1em;
  120. }
  121. `;
  122. export const dividerBlot = `
  123. const BlockEmbed = Quill.import('blots/block/embed');
  124. class DividerBlot extends BlockEmbed {
  125. static blotName = 'divider';
  126. static tagName = 'hr';
  127. }
  128. Quill.register(DividerBlot);
  129. `;
  130. export const imageBlot = `
  131. const BlockEmbed = Quill.import('blots/block/embed');
  132. class ImageBlot extends BlockEmbed {
  133. static blotName = 'image';
  134. static tagName = 'img';
  135. static create(value) {
  136. let node = super.create();
  137. node.setAttribute('alt', value.alt);
  138. node.setAttribute('src', value.url);
  139. return node;
  140. }
  141. static value(node) {
  142. return {
  143. alt: node.getAttribute('alt'),
  144. url: node.getAttribute('src')
  145. };
  146. }
  147. }
  148. Quill.register(ImageBlot);
  149. `;
  150. export const videoBlot = `
  151. const BlockEmbed = Quill.import('blots/block/embed');
  152. class VideoBlot extends BlockEmbed {
  153. static blotName = 'video';
  154. static tagName = 'iframe';
  155. static create(url) {
  156. let node = super.create();
  157. node.setAttribute('src', url);
  158. node.setAttribute('frameborder', '0');
  159. node.setAttribute('allowfullscreen', true);
  160. return node;
  161. }
  162. static formats(node) {
  163. let format = {};
  164. if (node.hasAttribute('height')) {
  165. format.height = node.getAttribute('height');
  166. }
  167. if (node.hasAttribute('width')) {
  168. format.width = node.getAttribute('width');
  169. }
  170. return format;
  171. }
  172. static value(node) {
  173. return node.getAttribute('src');
  174. }
  175. format(name, value) {
  176. if (name === 'height' || name === 'width') {
  177. if (value) {
  178. this.domNode.setAttribute(name, value);
  179. } else {
  180. this.domNode.removeAttribute(name, value);
  181. }
  182. } else {
  183. super.format(name, value);
  184. }
  185. }
  186. }
  187. Quill.register(VideoBlot);
  188. `;
  189. export const tweetBlot = `
  190. const BlockEmbed = Quill.import('blots/block/embed');
  191. class TweetBlot extends BlockEmbed {
  192. static blotName = 'tweet';
  193. static tagName = 'div';
  194. static className = 'tweet';
  195. static create(id) {
  196. let node = super.create();
  197. node.dataset.id = id;
  198. twttr.widgets.createTweet(id, node);
  199. return node;
  200. }
  201. static value(domNode) {
  202. return domNode.dataset.id;
  203. }
  204. }
  205. Quill.register(TweetBlot);
  206. `;