notebook/app/views/javascripts/_content_linking.html.erb
Andrew Brown 05221511d8 todo
2021-07-28 14:51:04 -07:00

32 lines
1.2 KiB
Plaintext

<% if @linkables_cache %>
<%= content_for :javascript do %>
var tribute = new Tribute({
<%#
TODO: tribute allows us to populate values async, so that might be worth exploring the tradeoffs of
https://github.com/zurb/tribute
%>
values: [
<% @linkables_cache.each do |class_name, collection| %>
<% linkable_class = content_class_from_name(class_name) %>
<% collection.each do |page_name, page_id| %>
{
key: "<%= page_name.gsub('"', "\"").gsub("\n", " ").gsub("\r", " ").strip %>",
value: '[[<%= class_name %>-<%= page_id %>]]',
color: '<%= linkable_class.color %>',
icon: '<%= linkable_class.icon %>'
},
<% end %>
<% end %>
],
selectTemplate: function (item) {
// We're overriding the default here so we don't prepend a @
return item.original.value;
},
menuItemTemplate: function (item) {
return '<i class="material-icons right ' + item.original.color + '-text">' + item.original.icon + '</i>' + item.string;
},
spaceSelectsMatch: false
});
tribute.attach(document.querySelectorAll('.js-can-mention-pages'));
<% end %>
<% end %>