|
1 | 1 | /** |
2 | | - * Name : Martor v1.3.0 |
| 2 | + * Name : Martor v1.3.1 |
3 | 3 | * Created by : Agus Makmun (Summon Agus) |
4 | | - * Release date : 20-Aug-2018 |
| 4 | + * Release date : 02-Sep-2018 |
5 | 5 | * License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 |
6 | 6 | * Repository : https://github.com/agusmakmun/django-markdown-editor |
7 | 7 | **/ |
|
144 | 144 | // update the preview if this menu is clicked |
145 | 145 | var currentTab = $('.tab.segment[data-tab=preview-tab-'+field_name+']'); |
146 | 146 | var previewTabButton = $('.item[data-tab=preview-tab-'+field_name+']'); |
147 | | - refreshPreview = function() { |
| 147 | + var refreshPreview = function() { |
148 | 148 | var value = editor.getValue(); |
149 | 149 | var form = new FormData(); |
150 | 150 | form.append('content', value); |
|
169 | 169 | } |
170 | 170 | }); |
171 | 171 | }; |
172 | | - previewTabButton.click(function(){ |
173 | | - // hide the `.martor-toolbar` for this current editor if under preview. |
174 | | - $(this).closest('.tab-martor-menu').find('.martor-toolbar').hide(); |
175 | | - refreshPreview(); |
176 | | - });// end click `previewTabButton` |
| 172 | + |
177 | 173 | if (editorConfig.living === 'true') { |
178 | 174 | editor.on('change', refreshPreview); |
| 175 | + }else { |
| 176 | + previewTabButton.click(function(){ |
| 177 | + // hide the `.martor-toolbar` for this current editor if under preview. |
| 178 | + $(this).closest('.tab-martor-menu').find('.martor-toolbar').hide(); |
| 179 | + refreshPreview(); |
| 180 | + }); |
179 | 181 | } |
180 | 182 |
|
181 | 183 | var editorTabButton = $('.item[data-tab=editor-tab-'+field_name+']'); |
|
191 | 193 | if (editor.selection.isEmpty()) { |
192 | 194 | var curpos = editor.getCursorPosition(); |
193 | 195 | editor.session.insert(curpos, ' **** '); |
| 196 | + editor.focus(); |
194 | 197 | editor.selection.moveTo(curpos.row, curpos.column+3); |
195 | 198 | }else { |
196 | 199 | var range = editor.getSelectionRange(); |
197 | 200 | var text = editor.session.getTextRange(range); |
198 | 201 | editor.session.replace(range, '**'+text+'**'); |
199 | 202 | originalRange.end.column += 4; // this because injected from 4 `*` characters. |
| 203 | + editor.focus(); |
200 | 204 | editor.selection.setSelectionRange(originalRange); |
201 | 205 | } |
202 | 206 | }; |
|
206 | 210 | if (editor.selection.isEmpty()) { |
207 | 211 | var curpos = editor.getCursorPosition(); |
208 | 212 | editor.session.insert(curpos, ' __ '); |
| 213 | + editor.focus(); |
209 | 214 | editor.selection.moveTo(curpos.row, curpos.column+2); |
210 | 215 | }else { |
211 | 216 | var range = editor.getSelectionRange(); |
212 | 217 | var text = editor.session.getTextRange(range); |
213 | 218 | editor.session.replace(range, '_'+text+'_'); |
214 | 219 | originalRange.end.column += 2; // this because injected from 2 `_` characters. |
| 220 | + editor.focus(); |
215 | 221 | editor.selection.setSelectionRange(originalRange); |
216 | 222 | } |
217 | 223 | }; |
|
221 | 227 | if (editor.selection.isEmpty()) { |
222 | 228 | var curpos = editor.getCursorPosition(); |
223 | 229 | editor.session.insert(curpos, ' ++++ '); |
| 230 | + editor.focus(); |
224 | 231 | editor.selection.moveTo(curpos.row, curpos.column+3); |
225 | 232 | }else { |
226 | 233 | var range = editor.getSelectionRange(); |
227 | 234 | var text = editor.session.getTextRange(range); |
228 | 235 | editor.session.replace(range, '++'+text+'++'); |
229 | 236 | originalRange.end.column += 4; // this because injected from 4 `*` characters. |
| 237 | + editor.focus(); |
230 | 238 | editor.selection.setSelectionRange(originalRange); |
231 | 239 | } |
232 | 240 | }; |
|
236 | 244 | if (editor.selection.isEmpty()) { |
237 | 245 | var curpos = editor.getCursorPosition(); |
238 | 246 | editor.session.insert(curpos, ' ~~~~ '); |
| 247 | + editor.focus(); |
239 | 248 | editor.selection.moveTo(curpos.row, curpos.column+3); |
240 | 249 | }else { |
241 | 250 | var range = editor.getSelectionRange(); |
242 | 251 | var text = editor.session.getTextRange(range); |
243 | 252 | editor.session.replace(range, '~~'+text+'~~'); |
244 | 253 | originalRange.end.column += 4; // this because injected from 4 `*` characters. |
| 254 | + editor.focus(); |
245 | 255 | editor.selection.setSelectionRange(originalRange); |
246 | 256 | } |
247 | 257 | }; |
|
251 | 261 | if (editor.selection.isEmpty()) { |
252 | 262 | var curpos = editor.getCursorPosition(); |
253 | 263 | editor.session.insert(curpos, '\n\n----------\n\n'); |
| 264 | + editor.focus(); |
254 | 265 | editor.selection.moveTo(curpos.row+4, curpos.column+10); |
255 | 266 | } |
256 | 267 | else { |
257 | 268 | var range = editor.getSelectionRange(); |
258 | 269 | var text = editor.session.getTextRange(range); |
259 | 270 | editor.session.replace(range, '\n\n----------\n\n'+text); |
| 271 | + editor.focus(); |
260 | 272 | editor.selection.moveTo( |
261 | 273 | originalRange.end.row+4, |
262 | 274 | originalRange.end.column+10 |
|
269 | 281 | if (editor.selection.isEmpty()) { |
270 | 282 | var curpos = editor.getCursorPosition(); |
271 | 283 | editor.session.insert(curpos, '\n\n# '); |
| 284 | + editor.focus(); |
272 | 285 | editor.selection.moveTo(curpos.row+2, curpos.column+2); |
273 | 286 | } |
274 | 287 | else { |
275 | 288 | var range = editor.getSelectionRange(); |
276 | 289 | var text = editor.session.getTextRange(range); |
277 | 290 | editor.session.replace(range, '\n\n# '+text+'\n'); |
| 291 | + editor.focus(); |
278 | 292 | editor.selection.moveTo( |
279 | 293 | originalRange.end.row+2, |
280 | 294 | originalRange.end.column+2 |
|
287 | 301 | if (editor.selection.isEmpty()) { |
288 | 302 | var curpos = editor.getCursorPosition(); |
289 | 303 | editor.session.insert(curpos, '\n\n## '); |
| 304 | + editor.focus(); |
290 | 305 | editor.selection.moveTo(curpos.row+2, curpos.column+3); |
291 | 306 | } |
292 | 307 | else { |
293 | 308 | var range = editor.getSelectionRange(); |
294 | 309 | var text = editor.session.getTextRange(range); |
295 | 310 | editor.session.replace(range, '\n\n## '+text+'\n'); |
| 311 | + editor.focus(); |
296 | 312 | editor.selection.moveTo( |
297 | 313 | originalRange.end.row+2, |
298 | 314 | originalRange.end.column+3 |
|
305 | 321 | if (editor.selection.isEmpty()) { |
306 | 322 | var curpos = editor.getCursorPosition(); |
307 | 323 | editor.session.insert(curpos, '\n\n### '); |
| 324 | + editor.focus(); |
308 | 325 | editor.selection.moveTo(curpos.row+2, curpos.column+4); |
309 | 326 | } |
310 | 327 | else { |
311 | 328 | var range = editor.getSelectionRange(); |
312 | 329 | var text = editor.session.getTextRange(range); |
313 | 330 | editor.session.replace(range, '\n\n### '+text+'\n'); |
| 331 | + editor.focus(); |
314 | 332 | editor.selection.moveTo( |
315 | 333 | originalRange.end.row+2, |
316 | 334 | originalRange.end.column+4 |
|
323 | 341 | if (editor.selection.isEmpty()) { |
324 | 342 | var curpos = editor.getCursorPosition(); |
325 | 343 | editor.session.insert(curpos, '\n\n```\n\n```\n'); |
| 344 | + editor.focus(); |
326 | 345 | editor.selection.moveTo(curpos.row+3, curpos.column); |
327 | 346 | } |
328 | 347 | else { |
329 | 348 | var range = editor.getSelectionRange(); |
330 | 349 | var text = editor.session.getTextRange(range); |
331 | 350 | editor.session.replace(range, '\n\n```\n'+text+'\n```\n'); |
| 351 | + editor.focus(); |
332 | 352 | editor.selection.moveTo( |
333 | 353 | originalRange.end.row+3, |
334 | 354 | originalRange.end.column+3 |
|
341 | 361 | if (editor.selection.isEmpty()) { |
342 | 362 | var curpos = editor.getCursorPosition(); |
343 | 363 | editor.session.insert(curpos, ' `` '); |
| 364 | + editor.focus(); |
344 | 365 | editor.selection.moveTo(curpos.row, curpos.column+2); |
345 | 366 | }else { |
346 | 367 | var range = editor.getSelectionRange(); |
347 | 368 | var text = editor.session.getTextRange(range); |
348 | 369 | editor.session.replace(range, '`'+text+'`'); |
349 | 370 | originalRange.end.column += 2; // this because injected from 2 `_` characters. |
| 371 | + editor.focus(); |
350 | 372 | editor.selection.setSelectionRange(originalRange); |
351 | 373 | } |
352 | 374 | }; |
|
356 | 378 | if (editor.selection.isEmpty()) { |
357 | 379 | var curpos = editor.getCursorPosition(); |
358 | 380 | editor.session.insert(curpos, '\n\n> \n'); |
| 381 | + editor.focus(); |
359 | 382 | editor.selection.moveTo(curpos.row+2, curpos.column+2); |
360 | 383 | } |
361 | 384 | else { |
362 | 385 | var range = editor.getSelectionRange(); |
363 | 386 | var text = editor.session.getTextRange(range); |
364 | 387 | editor.session.replace(range, '\n\n> '+text+'\n'); |
| 388 | + editor.focus(); |
365 | 389 | editor.selection.moveTo( |
366 | 390 | originalRange.end.row+2, |
367 | 391 | originalRange.end.column+2 |
|
374 | 398 | if (editor.selection.isEmpty()) { |
375 | 399 | var curpos = editor.getCursorPosition(); |
376 | 400 | editor.session.insert(curpos, '\n\n* '); |
| 401 | + editor.focus(); |
377 | 402 | editor.selection.moveTo(curpos.row+2, curpos.column+2); |
378 | 403 | } |
379 | 404 | else { |
380 | 405 | var range = editor.getSelectionRange(); |
381 | 406 | var text = editor.session.getTextRange(range); |
382 | 407 | editor.session.replace(range, '\n\n* '+text); |
| 408 | + editor.focus(); |
383 | 409 | editor.selection.moveTo( |
384 | 410 | originalRange.end.row+2, |
385 | 411 | originalRange.end.column+2 |
|
392 | 418 | if (editor.selection.isEmpty()) { |
393 | 419 | var curpos = editor.getCursorPosition(); |
394 | 420 | editor.session.insert(curpos, '\n\n1. '); |
| 421 | + editor.focus(); |
395 | 422 | editor.selection.moveTo(curpos.row+2, curpos.column+3); |
396 | 423 | } |
397 | 424 | else { |
398 | 425 | var range = editor.getSelectionRange(); |
399 | 426 | var text = editor.session.getTextRange(range); |
400 | 427 | editor.session.replace(range, '\n\n1. '+text); |
| 428 | + editor.focus(); |
401 | 429 | editor.selection.moveTo( |
402 | 430 | originalRange.end.row+2, |
403 | 431 | originalRange.end.column+3 |
|
410 | 438 | if (editor.selection.isEmpty()) { |
411 | 439 | var curpos = editor.getCursorPosition(); |
412 | 440 | editor.session.insert(curpos, ' [](http://) '); |
| 441 | + editor.focus(); |
413 | 442 | editor.selection.moveTo(curpos.row, curpos.column+2); |
414 | 443 | }else { |
415 | 444 | var range = editor.getSelectionRange(); |
416 | 445 | var text = editor.session.getTextRange(range); |
417 | 446 | editor.session.replace(range, '['+text+'](http://) '); |
| 447 | + editor.focus(); |
418 | 448 | editor.selection.moveTo( |
419 | 449 | originalRange.end.row, |
420 | 450 | originalRange.end.column+10 |
|
429 | 459 | if (editor.selection.isEmpty()) { |
430 | 460 | var curpos = editor.getCursorPosition(); |
431 | 461 | editor.session.insert(curpos, '  '); |
| 462 | + editor.focus(); |
432 | 463 | editor.selection.moveTo(curpos.row, curpos.column+3); |
433 | 464 | }else { |
434 | 465 | var range = editor.getSelectionRange(); |
435 | 466 | var text = editor.session.getTextRange(range); |
436 | 467 | editor.session.replace(range, ' '); |
| 468 | + editor.focus(); |
437 | 469 | editor.selection.moveTo( |
438 | 470 | originalRange.end.row, |
439 | 471 | originalRange.end.column+11 |
|
442 | 474 | }else { // this if use image upload to imgur. |
443 | 475 | var curpos = editor.getCursorPosition(); |
444 | 476 | editor.session.insert(curpos, ' '); |
| 477 | + editor.focus(); |
445 | 478 | editor.selection.moveTo( |
446 | 479 | curpos.row, |
447 | 480 | curpos.column+imageData.name.length+2 |
|
454 | 487 | if (editor.selection.isEmpty()) { |
455 | 488 | var curpos = editor.getCursorPosition(); |
456 | 489 | editor.session.insert(curpos, ' @[]'); |
| 490 | + editor.focus(); |
457 | 491 | editor.selection.moveTo(curpos.row, curpos.column+3); |
458 | 492 | }else { |
459 | 493 | var range = editor.getSelectionRange(); |
460 | 494 | var text = editor.session.getTextRange(range); |
461 | 495 | editor.session.replace(range, '@['+text+']'); |
| 496 | + editor.focus(); |
462 | 497 | editor.selection.moveTo( |
463 | 498 | originalRange.end.row, |
464 | 499 | originalRange.end.column+3 |
|
469 | 504 | var markdownToEmoji = function(editor, data_target) { |
470 | 505 | var curpos = editor.getCursorPosition(); |
471 | 506 | editor.session.insert(curpos, ' '+data_target+' '); |
| 507 | + editor.focus(); |
472 | 508 | editor.selection.moveTo(curpos.row, curpos.column+data_target.length+2); |
473 | 509 | }; |
474 | 510 | // Markdown Image Uploader auto insert to editor. |
|
0 commit comments