Created
April 26, 2013 12:01
-
-
Save luniki/5466967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.5.0 | |
(function() { | |
var $, dialog, dialog_template, getCid, getWikiPages, intermap, openLinkDialog, url; | |
$ = jQuery; | |
dialog_template = _.template("<div title='Stud.IP-Link einfügen'>\n <select>\n <% _.each(keywords, function(keyword) { %>\n <option><%= keyword %></option> <% }); %>\n </select>\n <button class=submit>Einfügen</button>\n</div>"); | |
url = function(cid) { | |
return STUDIP.ABSOLUTE_URI_STUDIP + ("plugins.php/restipplugin/api/courses/" + cid + "/wiki"); | |
}; | |
getCid = function() { | |
return document.location.search.match(/cid=([a-f0-9]{32})/)[1]; | |
}; | |
getWikiPages = function(cid) { | |
return $.getJSON(url(getCid())); | |
}; | |
dialog = false; | |
openLinkDialog = function(selection, textarea, button) { | |
if (dialog) { | |
dialog.dialog("open"); | |
} else { | |
$(button).showAjaxNotification(); | |
getWikiPages().always(function() { | |
return $(button).hideAjaxNotification(); | |
}).then(function(pages) { | |
dialog = $(dialog_template(pages)).dialog(); | |
return dialog.on("click", "button.submit", function() { | |
var selected_page; | |
selected_page = dialog.find("select").val(); | |
dialog.dialog("close"); | |
return textarea.replaceSelection("{{wiki:" + selected_page + "}}"); | |
}); | |
}); | |
} | |
return false; | |
}; | |
intermap = { | |
label: "Stud.IP-Link", | |
evaluate: openLinkDialog | |
}; | |
STUDIP.Toolbar.buttonSet.right = _.extend({ | |
intermap: intermap | |
}, STUDIP.Toolbar.buttonSet.right); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment