app/assets/javascripts/lalala/modules/editor.module.js in lalala-4.0.0.dev.416 vs app/assets/javascripts/lalala/modules/editor.module.js in lalala-4.1.0.dev.299
- old
+ new
@@ -1,11 +1,17 @@
-var markdown_settings;
+var Overlay = require("./overlay"),
+ MediaSelector = require("./media_selector"),
+ markdown_settings;
+
+
exports.init = function(){
$("textarea.markdown").each(setup);
};
+
+
function setup() {
var $this = $(this);
var settings = $.extend({}, markdown_settings);
settings.previewParserVar = $this.attr("name");
@@ -13,39 +19,34 @@
var $markitup_wrapper = $this.closest('.markItUp');
$markitup_wrapper.find('.fullscreen').click(open_fullscreen);
$markitup_wrapper.find('.close-fullscreen').click(close_fullscreen);
$markitup_wrapper.find('.markdown-cheatsheet').click(toggle_cheatsheet);
- $('body').on('click', '.markdown-cheatsheet-close', toggle_cheatsheet);
+ $markitup_wrapper.find('.add-image').click(add_image_click_handler);
}
+
+
//
-// Go fullscreen
+// Fullscreen
//
function open_fullscreen(event) {
var $markitup_wrapper = $(this).closest('.markItUp');
$markitup_wrapper.find('.markItUpHeader .preview').trigger('mouseup');
$markitup_wrapper.addClass('fullscreen');
-
- $('body').on('keyup.MARKDOWN_FULLSCREEN', function (event) {
- if (event.which === 27) {
- close_fullscreen(event);
- }
- });
}
-//
-// Close fullscreen
-//
+
function close_fullscreen(event) {
- var $markitup_wrapper = $('.close-fullscreen').closest('.markItUp');
+ var $markitup_wrapper = $(this).closest('.markItUp');
$markitup_wrapper.removeClass('fullscreen');
- $('body').off('keyup.MARKDOWN_FULLSCREEN');
}
+
+
//
-// Toggle Markdown cheatsheet
+// Cheatsheet
//
function toggle_cheatsheet(event) {
var $markdown_cheatsheet = $('#markdown-cheatsheet');
// cheatsheet is not yeat loaded
@@ -61,13 +62,11 @@
$markdown_cheatsheet.fadeIn(300);
}
}
-//
-// Load Markdown syntax cheatsheet
-//
+
function load_cheatsheat(options) {
$.get('/lalala/markdown/cheatsheet', function(data) {
var $div = $('<div id="markdown-cheatsheet" />');
$div
@@ -80,13 +79,31 @@
toggle_cheatsheet();
}
});
}
+
+
//
-// Mark It Up settings
+// Images
//
+function add_image_click_handler(e) {
+ var ms, overlay;
+
+ ms = new MediaSelector();
+ ms.$markitup_container = $(e.currentTarget).closest(".markItUpContainer");
+
+ overlay = Overlay.get_instance();
+ overlay.append_content(ms.$el);
+ overlay.show("media-selector");
+}
+
+
+
+//
+// Mark It Up settings
+//
var base_path = window.location.pathname.replace(/[\/][^\/]+$/, "");
markdown_settings = {
nameSpace: 'markdown-editor', // Useful to prevent multi-instances CSS conflict
previewParserPath: base_path + '/preview',
@@ -99,16 +116,13 @@
{ name: 'Bold', key: 'B', openWith: '**', closeWith: '**', className: 'bold' },
{ name: 'Italic', key: 'I', openWith: '_', closeWith: '_', className: 'italic' },
{ separator: '---' },
{ name: 'Unordered list', openWith: '- ', className: 'unordered-list', multiline: true },
{ name: 'Ordered list', openWith: '1. ', closeWith: '\n2. \n3. ', className: 'ordered-list', multiline: true },
- /*
-| column header |\n| ------------- | ------------- |\n| | |
- */
{ name: 'Add table', openWith: '| ', closeWith: ' | column header |\n| ------------- | ------------- |\n| | |', placeHolder: 'Column header', className: 'add-table', multiline: true },
{ separator: '---' },
{ name: 'Link', key: 'L', openWith: '[[![Link text]!]', closeWith: ']([![Url:!:http://]!])', className: 'add-link' },
- //{ name: 'Image', openWith: '![[![Alternative text]!]]', closeWith: '([![Url:!:http://]!] "[![Image title]!]")', className: 'add-image' },
+ { name: 'Image', className: 'add-image' },
{ separator: '---' },
{ name: 'Preview', call: 'preview', className: "preview" },
{ name: 'Fullscreen', className: 'fullscreen' },
{ name: 'Close fullscreen', className: 'close-fullscreen' },
{ separator: '---' },