This project is read-only.

Incorporating the Orchard.MediaLibrary into my own custom module

Topics: Customizing Orchard, Writing modules
Nov 7, 2013 at 6:44 PM
I have created a custom module that allows the user to create quizes and for each question we have the ability to select an image via the Media Picker. I was able to hook into the Media Picker's functionality rather easily. Now my client wants me to use the new Media Library but I have not been able to find a trigger or a way to launch the Media Library as easily as I did for the Media Picker. My code for the Media Picker is as follows.
$("#admin-list-questions").on("click", "div > div > .image-question-link", function () {
        $("#media-picker-link-id").val($(".question-image-url", $(this).parent()).attr("id"));
        $(this).trigger("orchard-admin-pickimage-open", {
            img: null,
            uploadMediaPath: "images",
            callback: function (data) {
                var applicationPath = $("#app-path").val();
                if (!/\/$/.test(applicationPath)) {
                    applicationPath += '/';
                var url = data.img.src;
                if (url.substr(0, 4) != "http") {
                    url = "/" + url.substr(applicationPath.length);

                var imageUrlInputId = $("#media-picker-link-id").val();
                var $imageUrlInput = $("#" + imageUrlInputId);
                $("a.image-question-link > img.question-image", $imageUrlInput.parent()).attr("src", url);
So here when the user clicks on the image link in the admin the trigger here is fired and the Media Picker popup shows up. I also capture the url of the image selected and store it in a hidden field. My question is can this be done with the Media Library as well?