|
| 1 | +CMS.registerEditorComponent({ |
| 2 | + id: "gist", |
| 3 | + label: "Gist", |
| 4 | + fields: [ |
| 5 | + { |
| 6 | + name: "username", |
| 7 | + label: "Github Username (mandatory)", |
| 8 | + widget: "string" |
| 9 | + }, |
| 10 | + { |
| 11 | + name: "gid", |
| 12 | + label: "Gist ID (mandatory)", |
| 13 | + widget: "string" |
| 14 | + }, |
| 15 | + { |
| 16 | + name: "file", |
| 17 | + label: "by default, the shortcode will pull every file from the URL unless a specific filename is requested (optional)", |
| 18 | + widget: "string" |
| 19 | + }, |
| 20 | + { |
| 21 | + name: "class", |
| 22 | + label: "a class to add to the <div> surrounding the iframe (optional)", |
| 23 | + widget: "string" |
| 24 | + }, |
| 25 | + ], |
| 26 | + pattern: /{{ gist\(url="https:\/\/gist\.github\.com\/([-a-zA-Z0-9]+)\/([a-zA-Z0-9]+)"(, file="([-_.a-zA-Z0-9]+)")?(, class="([a-zA-Z][-_.:a-zA-Z0-9 ]*)")?\) }}/, |
| 27 | + fromBlock: function(match) { |
| 28 | + return { |
| 29 | + username: match[1], |
| 30 | + gid: match[2], |
| 31 | + file: match[4], |
| 32 | + class: match[6], |
| 33 | + }; |
| 34 | + }, |
| 35 | + toBlock: function(obj) { |
| 36 | + const gid = obj.gid || ''; |
| 37 | + const username = obj.username || ''; |
| 38 | + const f = !!obj.file ? `, file="${obj.file}"` : ''; |
| 39 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 40 | + return `{{ gist(url="https://gist.github.com/${username}/${gid}"${f}${c}) }}`; |
| 41 | + }, |
| 42 | + toPreview: function(obj) { |
| 43 | + const gid = obj.gid || ''; |
| 44 | + const username = obj.username || ''; |
| 45 | + const f = !!obj.file ? `, file="${obj.file}"` : ''; |
| 46 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 47 | + return `{{ gist(url="https://gist.github.com/${username}/${gid}"${f}${c}) }}`; |
| 48 | + }, |
| 49 | +}); |
| 50 | +CMS.registerEditorComponent({ |
| 51 | + id: "quote", |
| 52 | + label: "Quote", |
| 53 | + fields: [ |
| 54 | + { |
| 55 | + name: "body", |
| 56 | + label: "the body text", |
| 57 | + widget: "text" |
| 58 | + }, |
| 59 | + { |
| 60 | + name: "author", |
| 61 | + label: "ahuthor name", |
| 62 | + widget: "string" |
| 63 | + }, |
| 64 | + ], |
| 65 | + pattern: /^{% quote\((author="([^\n]*)\")?\) %}\n(.*?)\n^{% end %}$/ms, |
| 66 | + fromBlock: function(match) { |
| 67 | + return { |
| 68 | + author: match[2], |
| 69 | + body: match[3], |
| 70 | + }; |
| 71 | + }, |
| 72 | + toBlock: function(obj) { |
| 73 | + const a = `author="${obj.author || ''}"`; |
| 74 | + const body = obj.body || ''; |
| 75 | + return ` |
| 76 | +{% quote(${a}) %} |
| 77 | +${body} |
| 78 | +{% end %} |
| 79 | +`; |
| 80 | + }, |
| 81 | + toPreview: function(obj) { |
| 82 | + const author = obj.author || undefined; |
| 83 | + const body = obj.body || ''; |
| 84 | + return ` |
| 85 | +{% quote(${a}) %} |
| 86 | +${body} |
| 87 | +{% end %} |
| 88 | +`; |
| 89 | + }, |
| 90 | +}); |
| 91 | +CMS.registerEditorComponent({ |
| 92 | + id: "streamable", |
| 93 | + label: "Streamable", |
| 94 | + fields: [ |
| 95 | + { |
| 96 | + name: "id", |
| 97 | + label: "the video id (mandatory)", |
| 98 | + widget: "string" |
| 99 | + }, |
| 100 | + { |
| 101 | + name: "class", |
| 102 | + label: "a class to add to the <div> surrounding the iframe (optional)", |
| 103 | + widget: "string" |
| 104 | + }, |
| 105 | + ], |
| 106 | + pattern: /{{ streamable\(id="([a-zA-Z0-9]+)"(, class="([a-zA-Z][-_.:a-zA-Z0-9 ]*)")?\) }}/, |
| 107 | + fromBlock: function(match) { |
| 108 | + return { |
| 109 | + id: match[1], |
| 110 | + class: match[3], |
| 111 | + }; |
| 112 | + }, |
| 113 | + toBlock: function(obj) { |
| 114 | + const id = obj.id || ''; |
| 115 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 116 | + return `{{ streamable(id="${id}"${c}) }}`; |
| 117 | + }, |
| 118 | + toPreview: function(obj) { |
| 119 | + const id = obj.id || ''; |
| 120 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 121 | + return `{{ streamable(id="${id}"${c}) }}`; |
| 122 | + }, |
| 123 | +}); |
| 124 | +CMS.registerEditorComponent({ |
| 125 | + id: "vimeo", |
| 126 | + label: "Vimeo", |
| 127 | + fields: [ |
| 128 | + { |
| 129 | + name: "id", |
| 130 | + label: "the video id (mandatory)", |
| 131 | + widget: "string" |
| 132 | + }, |
| 133 | + { |
| 134 | + name: "class", |
| 135 | + label: "a class to add to the <div> surrounding the iframe (optional)", |
| 136 | + widget: "string" |
| 137 | + }, |
| 138 | + ], |
| 139 | + pattern: /{{ vimeo\(id="([0-9]+)"(, class="([a-zA-Z][-_.:a-zA-Z0-9 ]*)")?\) }}/, |
| 140 | + fromBlock: function(match) { |
| 141 | + return { |
| 142 | + id: match[1], |
| 143 | + class: match[3], |
| 144 | + }; |
| 145 | + }, |
| 146 | + toBlock: function(obj) { |
| 147 | + const id = obj.id || ''; |
| 148 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 149 | + return `{{ vimeo(id="${id}"${c}) }}`; |
| 150 | + }, |
| 151 | + toPreview: function(obj) { |
| 152 | + const id = obj.id || ''; |
| 153 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 154 | + return `{{ vimeo(id="${id}"${c}) }}`; |
| 155 | + }, |
| 156 | +}); |
| 157 | +CMS.registerEditorComponent({ |
| 158 | + id: "vm", |
| 159 | + label: "vm (Vimeo)", |
| 160 | + fields: [ |
| 161 | + { |
| 162 | + name: "id", |
| 163 | + label: "the video id (mandatory)", |
| 164 | + widget: "string" |
| 165 | + }, |
| 166 | + { |
| 167 | + name: "class", |
| 168 | + label: "a class to add to the <div> surrounding the iframe (optional)", |
| 169 | + widget: "string" |
| 170 | + }, |
| 171 | + ], |
| 172 | + pattern: /{{ vm\(id="([-a-zA-Z0-9]+)"(, class="([a-zA-Z][-_.:a-zA-Z0-9 ]*)")?\) }}/, |
| 173 | + fromBlock: function(match) { |
| 174 | + return { |
| 175 | + id: match[1], |
| 176 | + class: match[3], |
| 177 | + }; |
| 178 | + }, |
| 179 | + toBlock: function(obj) { |
| 180 | + const id = obj.id || ''; |
| 181 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 182 | + return `{{ vm(id="${id}"${c}) }}`; |
| 183 | + }, |
| 184 | + toPreview: function(obj) { |
| 185 | + const id = obj.id || ''; |
| 186 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 187 | + return `{{ vm(id="${id}"${c}) }}`; |
| 188 | + }, |
| 189 | +}); |
| 190 | +CMS.registerEditorComponent({ |
| 191 | + id: "youtube", |
| 192 | + label: "YouTube", |
| 193 | + fields: [ |
| 194 | + { |
| 195 | + name: "id", |
| 196 | + label: "the video id (mandatory)", |
| 197 | + widget: "string" |
| 198 | + }, |
| 199 | + { |
| 200 | + name: "playlist", |
| 201 | + label: "the playlist id (optional)", |
| 202 | + widget: "string" |
| 203 | + }, |
| 204 | + { |
| 205 | + name: "autoplay", |
| 206 | + label: "when set to \"true\", the video autoplays on load (optional)", |
| 207 | + widget: "boolean" |
| 208 | + }, |
| 209 | + { |
| 210 | + name: "class", |
| 211 | + label: "a class to add to the <div> surrounding the iframe (optional)", |
| 212 | + widget: "string" |
| 213 | + }, |
| 214 | + ], |
| 215 | + pattern: /{{ youtube\(id="([-_a-zA-Z0-9]+)"(, playlist="([-_a-zA-Z0-9]+)")?(, autoplay=(true|false))?(, class="([a-zA-Z][-_.:a-zA-Z0-9 ]*)")?\) }}/, |
| 216 | + fromBlock: function(match) { |
| 217 | + return { |
| 218 | + id: match[1], |
| 219 | + playlist: match[3], |
| 220 | + autoplay: match[5], |
| 221 | + class: match[7], |
| 222 | + }; |
| 223 | + }, |
| 224 | + toBlock: function(obj) { |
| 225 | + const id = obj.id || ''; |
| 226 | + const p = !!obj.playlist ? `, playlist="${obj.playlist}"` : ''; |
| 227 | + const a = !!obj.autoplay ? `, autoplay=${obj.autoplay}` : ''; |
| 228 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 229 | + return `{{ youtube(id="${id}"${p}${a}${c}) }}`; |
| 230 | + }, |
| 231 | + toPreview: function(obj) { |
| 232 | + const id = obj.id || ''; |
| 233 | + return `<img src="http://img.youtube.com/vi/${id}/mqdefault.jpg" alt="Youtube Video"/>`; |
| 234 | + }, |
| 235 | +}); |
| 236 | +CMS.registerEditorComponent({ |
| 237 | + id: "yt", |
| 238 | + label: "yt (YouTube)", |
| 239 | + fields: [ |
| 240 | + { |
| 241 | + name: "id", |
| 242 | + label: "the video id (mandatory)", |
| 243 | + widget: "string" |
| 244 | + }, |
| 245 | + { |
| 246 | + name: "autoplay", |
| 247 | + label: "when set to \"true\", the video autoplays on load (optional)", |
| 248 | + widget: "boolean" |
| 249 | + }, |
| 250 | + { |
| 251 | + name: "class", |
| 252 | + label: "a class to add to the <div> surrounding the iframe (optional)", |
| 253 | + widget: "string" |
| 254 | + }, |
| 255 | + ], |
| 256 | + pattern: /{{ youtube\(id="([-_a-zA-Z0-9]+)"(, autoplay=(true|false))?(, class="([a-zA-Z][-_.:a-zA-Z0-9 ]*)")?\) }}/, |
| 257 | + fromBlock: function(match) { |
| 258 | + return { |
| 259 | + id: match[1], |
| 260 | + autoplay: match[3], |
| 261 | + class: match[5], |
| 262 | + }; |
| 263 | + }, |
| 264 | + toBlock: function(obj) { |
| 265 | + const id = obj.id || ''; |
| 266 | + const a = !!obj.autoplay ? `, autoplay=${obj.autoplay}` : ''; |
| 267 | + const c = !!obj.class ? `, class="${obj.class}"` : ''; |
| 268 | + return `{{ youtube(id="${id}"${a}${c}) }}`; |
| 269 | + }, |
| 270 | + toPreview: function(obj) { |
| 271 | + const id = obj.id || ''; |
| 272 | + return `<img src="http://img.youtube.com/vi/${id}/mqdefault.jpg" alt="Youtube Video"/>`; |
| 273 | + }, |
| 274 | +}); |
0 commit comments