diff --git a/src/Orchard.Web/Modules/Markdown/Markdown.csproj b/src/Orchard.Web/Modules/Markdown/Markdown.csproj index e4b925679..5414e352d 100644 --- a/src/Orchard.Web/Modules/Markdown/Markdown.csproj +++ b/src/Orchard.Web/Modules/Markdown/Markdown.csproj @@ -25,6 +25,7 @@ + true @@ -71,6 +72,10 @@ {9916839C-39FC-4CEB-A5AF-89CA7E87119F} Orchard.Core + + {73a7688a-5bd3-4f7e-adfa-ce36c5a10e3b} + Orchard.MediaLibrary + diff --git a/src/Orchard.Web/Modules/Markdown/Scripts/orchard-markdown-media-library.js b/src/Orchard.Web/Modules/Markdown/Scripts/orchard-markdown-media-library.js index a5255e97c..37f493fbb 100644 --- a/src/Orchard.Web/Modules/Markdown/Scripts/orchard-markdown-media-library.js +++ b/src/Orchard.Web/Modules/Markdown/Scripts/orchard-markdown-media-library.js @@ -5,70 +5,72 @@ editors.each(function() { var idPostfix = $(this).attr('id').substr('wmd-input'.length); - + var editor = new Markdown.Editor(converter, idPostfix, { handler: function() { window.open("http://daringfireball.net/projects/markdown/syntax"); } }); - editor.hooks.set("insertImageDialog", function(callback) { - // see if there's an image selected that they intend on editing - var wmd = $('#wmd-input' + idPostfix); + if (Boolean($(this).data("manage-media"))) { + editor.hooks.set("insertImageDialog", function (callback) { + // see if there's an image selected that they intend on editing + var wmd = $('#wmd-input' + idPostfix); - var editImage, content = wmd.selection ? wmd.selection.createRange().text : null; - var adminIndex = location.href.toLowerCase().indexOf("/admin/"); - if (adminIndex === -1) return; - var url = location.href.substr(0, adminIndex) + "/Admin/Orchard.MediaLibrary?dialog=true"; - $.colorbox({ - href: url, - iframe: true, - reposition: true, - width: "90%", - height: "90%", - onLoad: function () { - // hide the scrollbars from the main window - $('html, body').css('overflow', 'hidden'); - }, - onClosed: function () { - $('html, body').css('overflow', ''); + var editImage, content = wmd.selection ? wmd.selection.createRange().text : null; + var adminIndex = location.href.toLowerCase().indexOf("/admin/"); + if (adminIndex === -1) return; + var url = location.href.substr(0, adminIndex) + "/Admin/Orchard.MediaLibrary?dialog=true"; + $.colorbox({ + href: url, + iframe: true, + reposition: true, + width: "90%", + height: "90%", + onLoad: function () { + // hide the scrollbars from the main window + $('html, body').css('overflow', 'hidden'); + }, + onClosed: function () { + $('html, body').css('overflow', ''); - var selectedData = $.colorbox.selectedData; + var selectedData = $.colorbox.selectedData; - if (selectedData == null) // Dialog cancelled, do nothing - return; + if (selectedData == null) // Dialog cancelled, do nothing + return; - var newContent = ''; - for (var i = 0; i < selectedData.length; i++) { - var renderMedia = location.href.substr(0, adminIndex) + "/Admin/Orchard.MediaLibrary/MediaItem/" + selectedData[i].id + "?displayType=Raw"; - $.ajax({ - async: false, - type: 'GET', - url: renderMedia, - success: function (data) { - newContent += data; - } - }); - } - - var result = $.parseHTML(newContent); - var img = $(result).filter('img'); - // if this is an image, use the callback which will format it in markdown - if (img.length > 0 && img.attr('src')) { - callback(img.attr('src')); - } - - // otherwise, insert the raw HTML - else { - if (wmd.selection) { - wmd.selection.replace('.*', newContent); - } else { - wmd.text(newContent); + var newContent = ''; + for (var i = 0; i < selectedData.length; i++) { + var renderMedia = location.href.substr(0, adminIndex) + "/Admin/Orchard.MediaLibrary/MediaItem/" + selectedData[i].id + "?displayType=Raw"; + $.ajax({ + async: false, + type: 'GET', + url: renderMedia, + success: function (data) { + newContent += data; + } + }); + } + + var result = $.parseHTML(newContent); + var img = $(result).filter('img'); + // if this is an image, use the callback which will format it in markdown + if (img.length > 0 && img.attr('src')) { + callback(img.attr('src')); + } + + // otherwise, insert the raw HTML + else { + if (wmd.selection) { + wmd.selection.replace('.*', newContent); + } else { + wmd.text(newContent); + } + callback(); } - callback(); } - } + }); + return true; }); - return true; - }); + } editor.run(); }); diff --git a/src/Orchard.Web/Modules/Markdown/Views/Body-Markdown.Editor.cshtml b/src/Orchard.Web/Modules/Markdown/Views/Body-Markdown.Editor.cshtml index 71f03b63c..6ae29a19c 100644 --- a/src/Orchard.Web/Modules/Markdown/Views/Body-Markdown.Editor.cshtml +++ b/src/Orchard.Web/Modules/Markdown/Views/Body-Markdown.Editor.cshtml @@ -21,7 +21,8 @@ {"id", "wmd-input" + "-" + idPostfix}, {"class", "wmd-input"}, {"data-mediapicker-uploadpath", Model.AddMediaPath}, - {"data-mediapicker-title", T("Insert/Update Media")} + {"data-mediapicker-title", T("Insert/Update Media")}, + {"data-manage-media", AuthorizedFor(Orchard.MediaLibrary.Permissions.ManageMediaContent) ? "true" : "false" } }; // The markdown editor itself doesn't seem to (yet) support autofocus, but we'll set it on the textarea nonetheless.