Skip to content

Commit

Permalink
move admin pack from webpacker to vite
Browse files Browse the repository at this point in the history
  • Loading branch information
jrochkind committed Oct 13, 2022
1 parent f09e7cc commit a3c0c6c
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// includes things not compatible with IE11 -- we consider
// it okay at present that management UI doesn't work on IE11, but we need public UI to.

import '../src/js/admin/member_sortable';
import '../src/js/admin/simple_uppy_file_input';
import '../src/js/admin/uppy_dashboard.js';
import '../src/js/admin/qa_autocomplete.js';
import '../src/js/admin/queue_status_submit.js';
import '../javascript/admin/member_sortable';
import '../javascript/admin/simple_uppy_file_input';
import '../javascript/admin/uppy_dashboard.js';
import '../javascript/admin/qa_autocomplete.js';
import '../javascript/admin/queue_status_submit.js';

import '../src/js/admin/tom_select.js' // has CSS
import '../javascript/admin/tom_select.js' // has CSS
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions app/frontend/javascript/lib/delegate_event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
We want something like JQuery 'on', but without JQuery:
https://api.jquery.com/on/
This is a bit tricky to get right. We cribbed this implementation from:
https://stackoverflow.com/a/25248515/
If in JQuery you'd do:
$(document).on("click", <selector>, handler)
Now do something like:
import delegateEvent from './lib/delegate_event.js';
delegateEvent(document, "click", <selector>, handler);
ALL ARGS ARE REQUIRED for now.
*/

export default function delegateEvent(container, event, selectorStr, handler) {
container.addEventListener(event, function(e) {
for (var target=e.target; target && target!=container; target=target.parentNode) {
// loop parent nodes from the target to the delegation node
if (target.matches(selectorStr)) {
handler.call(target, e);
break;
}
}
}, false);
};
8 changes: 5 additions & 3 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application', defer: true %>

<%# webpacker 'application' js, and 'admin' js and css %>
<%# webpacker 'application' js %>
<%= javascript_pack_tag 'application', defer: true %>
<%= javascript_pack_tag 'admin', defer: true %>
<%= stylesheet_pack_tag "admin" %>

<%# vite 'admin' js, will also include css if needed automatically %>
<%= vite_javascript_tag 'admin', defer: true %>
<%# stylesheet_pack_tag "admin" %>

</head>

Expand Down

0 comments on commit a3c0c6c

Please sign in to comment.