blacklight-frontend
Advanced tools
Comparing version 8.0.0-beta.5 to 8.0.0-beta.6
@@ -1,54 +0,1 @@ | ||
const Blacklight = function() { | ||
const buffer = new Array; | ||
return { | ||
onLoad: function(func) { | ||
buffer.push(func); | ||
}, | ||
activate: function() { | ||
for(let i = 0; i < buffer.length; i++) { | ||
buffer[i].call(); | ||
} | ||
}, | ||
listeners: function () { | ||
const listeners = []; | ||
if (typeof Turbo !== 'undefined') { | ||
listeners.push('turbo:load', 'turbo:frame-load'); | ||
} else if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) { | ||
// Turbolinks 5 | ||
if (Turbolinks.BrowserAdapter) { | ||
listeners.push('turbolinks:load'); | ||
} else { | ||
// Turbolinks < 5 | ||
listeners.push('page:load', 'DOMContentLoaded'); | ||
} | ||
} else { | ||
listeners.push('DOMContentLoaded'); | ||
} | ||
return listeners; | ||
} | ||
}; | ||
}(); | ||
// turbolinks triggers page:load events on page transition | ||
// If app isn't using turbolinks, this event will never be triggered, no prob. | ||
Blacklight.listeners().forEach(function(listener) { | ||
document.addEventListener(listener, function() { | ||
Blacklight.activate(); | ||
}); | ||
}); | ||
Blacklight.onLoad(function () { | ||
const elem = document.querySelector('.no-js'); | ||
// The "no-js" class may already have been removed because this function is | ||
// run on every turbo:load event, in that case, it won't find an element. | ||
if (!elem) return; | ||
elem.classList.remove('no-js'); | ||
elem.classList.add('js'); | ||
}); | ||
/* Converts a "toggle" form, with single submit button to add/remove | ||
@@ -135,28 +82,22 @@ something, like used for Bookmarks, into an AJAXy checkbox instead. | ||
const BookmarkToggle = (() => { | ||
// change form submit toggle to checkbox | ||
Blacklight.doBookmarkToggleBehavior = function() { | ||
document.addEventListener('click', (e) => { | ||
if (e.target.matches('[data-checkboxsubmit-target="checkbox"]')) { | ||
const form = e.target.closest('form'); | ||
if (form) new CheckboxSubmit(form).clicked(e); | ||
} | ||
}); | ||
}; | ||
Blacklight.doBookmarkToggleBehavior.selector = 'form.bookmark-toggle'; | ||
const BookmarkToggle = (e) => { | ||
if (e.target.matches('[data-checkboxsubmit-target="checkbox"]')) { | ||
const form = e.target.closest('form'); | ||
if (form) new CheckboxSubmit(form).clicked(e); | ||
} | ||
}; | ||
Blacklight.doBookmarkToggleBehavior(); | ||
})(); | ||
document.addEventListener('click', BookmarkToggle); | ||
const ButtonFocus = (() => { | ||
document.addEventListener('click', (e) => { | ||
// Button clicks should change focus. As of 10/3/19, Firefox for Mac and | ||
// Safari both do not set focus to a button on button click. | ||
// See https://zellwk.com/blog/inconsistent-button-behavior/ for background information | ||
if (e.target.matches('[data-toggle="collapse"]') || e.target.matches('[data-bs-toggle="collapse"]')) { | ||
e.target.focus(); | ||
} | ||
}); | ||
})(); | ||
const ButtonFocus = (e) => { | ||
// Button clicks should change focus. As of 10/3/19, Firefox for Mac and | ||
// Safari both do not set focus to a button on button click. | ||
// See https://zellwk.com/blog/inconsistent-button-behavior/ for background information | ||
if (e.target.matches('[data-toggle="collapse"]') || e.target.matches('[data-bs-toggle="collapse"]')) { | ||
e.target.focus(); | ||
} | ||
}; | ||
document.addEventListener('click', ButtonFocus); | ||
/* | ||
@@ -218,10 +159,4 @@ The blacklight modal plugin can display some interactions inside a Bootstrap | ||
const Modal = (() => { | ||
// We keep all our data in Blacklight.modal object. | ||
// Create lazily if someone else created first. | ||
if (Blacklight.modal === undefined) { | ||
Blacklight.modal = {}; | ||
} | ||
const modal = {}; | ||
const modal = Blacklight.modal; | ||
// a Bootstrap modal div that should be already on the page hidden | ||
@@ -310,3 +245,3 @@ modal.modalSelector = '#blacklight-modal'; | ||
modal.hide = function (el) { | ||
const dom = document.querySelector(Blacklight.modal.modalSelector); | ||
const dom = document.querySelector(modal.modalSelector); | ||
@@ -318,3 +253,3 @@ if (!dom.open) return | ||
modal.show = function(el) { | ||
const dom = document.querySelector(Blacklight.modal.modalSelector); | ||
const dom = document.querySelector(modal.modalSelector); | ||
@@ -326,60 +261,111 @@ if (dom.open) return | ||
modal.setupModal(); | ||
return modal; | ||
})(); | ||
const SearchContext = (() => { | ||
Blacklight.doSearchContextBehavior = function() { | ||
document.addEventListener('click', (e) => { | ||
if (e.target.matches('[data-context-href]')) { | ||
Blacklight.handleSearchContextMethod.call(e.target, e); | ||
} | ||
}); | ||
}; | ||
const SearchContext = (e) => { | ||
if (e.target.matches('[data-context-href]')) { | ||
SearchContext.handleSearchContextMethod.call(e.target, e); | ||
} | ||
}; | ||
Blacklight.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content; | ||
Blacklight.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content; | ||
SearchContext.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content; | ||
SearchContext.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content; | ||
// this is the Rails.handleMethod with a couple adjustments, described inline: | ||
// first, we're attaching this directly to the event handler, so we can check for meta-keys | ||
Blacklight.handleSearchContextMethod = function(event) { | ||
const link = this; | ||
// this is the Rails.handleMethod with a couple adjustments, described inline: | ||
// first, we're attaching this directly to the event handler, so we can check for meta-keys | ||
SearchContext.handleSearchContextMethod = function(event) { | ||
const link = this; | ||
// instead of using the normal href, we need to use the context href instead | ||
let href = link.getAttribute('data-context-href'); | ||
let target = link.getAttribute('target'); | ||
let csrfToken = Blacklight.csrfToken(); | ||
let csrfParam = Blacklight.csrfParam(); | ||
let form = document.createElement('form'); | ||
form.method = 'post'; | ||
form.action = href; | ||
// instead of using the normal href, we need to use the context href instead | ||
let href = link.getAttribute('data-context-href'); | ||
let target = link.getAttribute('target'); | ||
let csrfToken = SearchContext.csrfToken(); | ||
let csrfParam = SearchContext.csrfParam(); | ||
let form = document.createElement('form'); | ||
form.method = 'post'; | ||
form.action = href; | ||
let formContent = `<input name="_method" value="post" type="hidden" /> | ||
<input name="redirect" value="${link.getAttribute('href')}" type="hidden" />`; | ||
let formContent = `<input name="_method" value="post" type="hidden" /> | ||
<input name="redirect" value="${link.getAttribute('href')}" type="hidden" />`; | ||
// check for meta keys.. if set, we should open in a new tab | ||
if(event.metaKey || event.ctrlKey) { | ||
target = '_blank'; | ||
} | ||
// check for meta keys.. if set, we should open in a new tab | ||
if(event.metaKey || event.ctrlKey) { | ||
target = '_blank'; | ||
} | ||
if (csrfParam !== undefined && csrfToken !== undefined) { | ||
formContent += `<input name="${csrfParam}" value="${csrfToken}" type="hidden" />`; | ||
} | ||
if (csrfParam !== undefined && csrfToken !== undefined) { | ||
formContent += `<input name="${csrfParam}" value="${csrfToken}" type="hidden" />`; | ||
} | ||
// Must trigger submit by click on a button, else "submit" event handler won't work! | ||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit | ||
formContent += '<input type="submit" />'; | ||
// Must trigger submit by click on a button, else "submit" event handler won't work! | ||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit | ||
formContent += '<input type="submit" />'; | ||
if (target) { form.setAttribute('target', target); } | ||
if (target) { form.setAttribute('target', target); } | ||
form.style.display = 'none'; | ||
form.innerHTML = formContent; | ||
document.body.appendChild(form); | ||
form.querySelector('[type="submit"]').click(); | ||
form.style.display = 'none'; | ||
form.innerHTML = formContent; | ||
document.body.appendChild(form); | ||
form.querySelector('[type="submit"]').click(); | ||
event.preventDefault(); | ||
event.preventDefault(); | ||
}; | ||
document.addEventListener('click', SearchContext); | ||
const Blacklight = function() { | ||
const buffer = new Array; | ||
return { | ||
onLoad: function(func) { | ||
buffer.push(func); | ||
}, | ||
activate: function() { | ||
for(let i = 0; i < buffer.length; i++) { | ||
buffer[i].call(); | ||
} | ||
}, | ||
listeners: function () { | ||
const listeners = []; | ||
if (typeof Turbo !== 'undefined') { | ||
listeners.push('turbo:load', 'turbo:frame-load'); | ||
} else if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) { | ||
// Turbolinks 5 | ||
if (Turbolinks.BrowserAdapter) { | ||
listeners.push('turbolinks:load'); | ||
} else { | ||
// Turbolinks < 5 | ||
listeners.push('page:load', 'DOMContentLoaded'); | ||
} | ||
} else { | ||
listeners.push('DOMContentLoaded'); | ||
} | ||
return listeners; | ||
} | ||
}; | ||
}(); | ||
Blacklight.doSearchContextBehavior(); | ||
})(); | ||
// turbolinks triggers page:load events on page transition | ||
// If app isn't using turbolinks, this event will never be triggered, no prob. | ||
Blacklight.listeners().forEach(function(listener) { | ||
document.addEventListener(listener, function() { | ||
Blacklight.activate(); | ||
}); | ||
}); | ||
Blacklight.onLoad(function () { | ||
const elem = document.querySelector('.no-js'); | ||
// The "no-js" class may already have been removed because this function is | ||
// run on every turbo:load event, in that case, it won't find an element. | ||
if (!elem) return; | ||
elem.classList.remove('no-js'); | ||
elem.classList.add('js'); | ||
}); | ||
const index = { | ||
@@ -386,0 +372,0 @@ BookmarkToggle, |
@@ -7,55 +7,2 @@ (function (global, factory) { | ||
const Blacklight = function() { | ||
const buffer = new Array; | ||
return { | ||
onLoad: function(func) { | ||
buffer.push(func); | ||
}, | ||
activate: function() { | ||
for(let i = 0; i < buffer.length; i++) { | ||
buffer[i].call(); | ||
} | ||
}, | ||
listeners: function () { | ||
const listeners = []; | ||
if (typeof Turbo !== 'undefined') { | ||
listeners.push('turbo:load', 'turbo:frame-load'); | ||
} else if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) { | ||
// Turbolinks 5 | ||
if (Turbolinks.BrowserAdapter) { | ||
listeners.push('turbolinks:load'); | ||
} else { | ||
// Turbolinks < 5 | ||
listeners.push('page:load', 'DOMContentLoaded'); | ||
} | ||
} else { | ||
listeners.push('DOMContentLoaded'); | ||
} | ||
return listeners; | ||
} | ||
}; | ||
}(); | ||
// turbolinks triggers page:load events on page transition | ||
// If app isn't using turbolinks, this event will never be triggered, no prob. | ||
Blacklight.listeners().forEach(function(listener) { | ||
document.addEventListener(listener, function() { | ||
Blacklight.activate(); | ||
}); | ||
}); | ||
Blacklight.onLoad(function () { | ||
const elem = document.querySelector('.no-js'); | ||
// The "no-js" class may already have been removed because this function is | ||
// run on every turbo:load event, in that case, it won't find an element. | ||
if (!elem) return; | ||
elem.classList.remove('no-js'); | ||
elem.classList.add('js'); | ||
}); | ||
/* Converts a "toggle" form, with single submit button to add/remove | ||
@@ -142,28 +89,22 @@ something, like used for Bookmarks, into an AJAXy checkbox instead. | ||
const BookmarkToggle = (() => { | ||
// change form submit toggle to checkbox | ||
Blacklight.doBookmarkToggleBehavior = function() { | ||
document.addEventListener('click', (e) => { | ||
if (e.target.matches('[data-checkboxsubmit-target="checkbox"]')) { | ||
const form = e.target.closest('form'); | ||
if (form) new CheckboxSubmit(form).clicked(e); | ||
} | ||
}); | ||
}; | ||
Blacklight.doBookmarkToggleBehavior.selector = 'form.bookmark-toggle'; | ||
const BookmarkToggle = (e) => { | ||
if (e.target.matches('[data-checkboxsubmit-target="checkbox"]')) { | ||
const form = e.target.closest('form'); | ||
if (form) new CheckboxSubmit(form).clicked(e); | ||
} | ||
}; | ||
Blacklight.doBookmarkToggleBehavior(); | ||
})(); | ||
document.addEventListener('click', BookmarkToggle); | ||
const ButtonFocus = (() => { | ||
document.addEventListener('click', (e) => { | ||
// Button clicks should change focus. As of 10/3/19, Firefox for Mac and | ||
// Safari both do not set focus to a button on button click. | ||
// See https://zellwk.com/blog/inconsistent-button-behavior/ for background information | ||
if (e.target.matches('[data-toggle="collapse"]') || e.target.matches('[data-bs-toggle="collapse"]')) { | ||
e.target.focus(); | ||
} | ||
}); | ||
})(); | ||
const ButtonFocus = (e) => { | ||
// Button clicks should change focus. As of 10/3/19, Firefox for Mac and | ||
// Safari both do not set focus to a button on button click. | ||
// See https://zellwk.com/blog/inconsistent-button-behavior/ for background information | ||
if (e.target.matches('[data-toggle="collapse"]') || e.target.matches('[data-bs-toggle="collapse"]')) { | ||
e.target.focus(); | ||
} | ||
}; | ||
document.addEventListener('click', ButtonFocus); | ||
/* | ||
@@ -225,10 +166,4 @@ The blacklight modal plugin can display some interactions inside a Bootstrap | ||
const Modal = (() => { | ||
// We keep all our data in Blacklight.modal object. | ||
// Create lazily if someone else created first. | ||
if (Blacklight.modal === undefined) { | ||
Blacklight.modal = {}; | ||
} | ||
const modal = {}; | ||
const modal = Blacklight.modal; | ||
// a Bootstrap modal div that should be already on the page hidden | ||
@@ -317,3 +252,3 @@ modal.modalSelector = '#blacklight-modal'; | ||
modal.hide = function (el) { | ||
const dom = document.querySelector(Blacklight.modal.modalSelector); | ||
const dom = document.querySelector(modal.modalSelector); | ||
@@ -325,3 +260,3 @@ if (!dom.open) return | ||
modal.show = function(el) { | ||
const dom = document.querySelector(Blacklight.modal.modalSelector); | ||
const dom = document.querySelector(modal.modalSelector); | ||
@@ -333,60 +268,111 @@ if (dom.open) return | ||
modal.setupModal(); | ||
return modal; | ||
})(); | ||
const SearchContext = (() => { | ||
Blacklight.doSearchContextBehavior = function() { | ||
document.addEventListener('click', (e) => { | ||
if (e.target.matches('[data-context-href]')) { | ||
Blacklight.handleSearchContextMethod.call(e.target, e); | ||
} | ||
}); | ||
}; | ||
const SearchContext = (e) => { | ||
if (e.target.matches('[data-context-href]')) { | ||
SearchContext.handleSearchContextMethod.call(e.target, e); | ||
} | ||
}; | ||
Blacklight.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content; | ||
Blacklight.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content; | ||
SearchContext.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content; | ||
SearchContext.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content; | ||
// this is the Rails.handleMethod with a couple adjustments, described inline: | ||
// first, we're attaching this directly to the event handler, so we can check for meta-keys | ||
Blacklight.handleSearchContextMethod = function(event) { | ||
const link = this; | ||
// this is the Rails.handleMethod with a couple adjustments, described inline: | ||
// first, we're attaching this directly to the event handler, so we can check for meta-keys | ||
SearchContext.handleSearchContextMethod = function(event) { | ||
const link = this; | ||
// instead of using the normal href, we need to use the context href instead | ||
let href = link.getAttribute('data-context-href'); | ||
let target = link.getAttribute('target'); | ||
let csrfToken = Blacklight.csrfToken(); | ||
let csrfParam = Blacklight.csrfParam(); | ||
let form = document.createElement('form'); | ||
form.method = 'post'; | ||
form.action = href; | ||
// instead of using the normal href, we need to use the context href instead | ||
let href = link.getAttribute('data-context-href'); | ||
let target = link.getAttribute('target'); | ||
let csrfToken = SearchContext.csrfToken(); | ||
let csrfParam = SearchContext.csrfParam(); | ||
let form = document.createElement('form'); | ||
form.method = 'post'; | ||
form.action = href; | ||
let formContent = `<input name="_method" value="post" type="hidden" /> | ||
<input name="redirect" value="${link.getAttribute('href')}" type="hidden" />`; | ||
let formContent = `<input name="_method" value="post" type="hidden" /> | ||
<input name="redirect" value="${link.getAttribute('href')}" type="hidden" />`; | ||
// check for meta keys.. if set, we should open in a new tab | ||
if(event.metaKey || event.ctrlKey) { | ||
target = '_blank'; | ||
} | ||
// check for meta keys.. if set, we should open in a new tab | ||
if(event.metaKey || event.ctrlKey) { | ||
target = '_blank'; | ||
} | ||
if (csrfParam !== undefined && csrfToken !== undefined) { | ||
formContent += `<input name="${csrfParam}" value="${csrfToken}" type="hidden" />`; | ||
} | ||
if (csrfParam !== undefined && csrfToken !== undefined) { | ||
formContent += `<input name="${csrfParam}" value="${csrfToken}" type="hidden" />`; | ||
} | ||
// Must trigger submit by click on a button, else "submit" event handler won't work! | ||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit | ||
formContent += '<input type="submit" />'; | ||
// Must trigger submit by click on a button, else "submit" event handler won't work! | ||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit | ||
formContent += '<input type="submit" />'; | ||
if (target) { form.setAttribute('target', target); } | ||
if (target) { form.setAttribute('target', target); } | ||
form.style.display = 'none'; | ||
form.innerHTML = formContent; | ||
document.body.appendChild(form); | ||
form.querySelector('[type="submit"]').click(); | ||
form.style.display = 'none'; | ||
form.innerHTML = formContent; | ||
document.body.appendChild(form); | ||
form.querySelector('[type="submit"]').click(); | ||
event.preventDefault(); | ||
event.preventDefault(); | ||
}; | ||
document.addEventListener('click', SearchContext); | ||
const Blacklight = function() { | ||
const buffer = new Array; | ||
return { | ||
onLoad: function(func) { | ||
buffer.push(func); | ||
}, | ||
activate: function() { | ||
for(let i = 0; i < buffer.length; i++) { | ||
buffer[i].call(); | ||
} | ||
}, | ||
listeners: function () { | ||
const listeners = []; | ||
if (typeof Turbo !== 'undefined') { | ||
listeners.push('turbo:load', 'turbo:frame-load'); | ||
} else if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) { | ||
// Turbolinks 5 | ||
if (Turbolinks.BrowserAdapter) { | ||
listeners.push('turbolinks:load'); | ||
} else { | ||
// Turbolinks < 5 | ||
listeners.push('page:load', 'DOMContentLoaded'); | ||
} | ||
} else { | ||
listeners.push('DOMContentLoaded'); | ||
} | ||
return listeners; | ||
} | ||
}; | ||
}(); | ||
Blacklight.doSearchContextBehavior(); | ||
})(); | ||
// turbolinks triggers page:load events on page transition | ||
// If app isn't using turbolinks, this event will never be triggered, no prob. | ||
Blacklight.listeners().forEach(function(listener) { | ||
document.addEventListener(listener, function() { | ||
Blacklight.activate(); | ||
}); | ||
}); | ||
Blacklight.onLoad(function () { | ||
const elem = document.querySelector('.no-js'); | ||
// The "no-js" class may already have been removed because this function is | ||
// run on every turbo:load event, in that case, it won't find an element. | ||
if (!elem) return; | ||
elem.classList.remove('no-js'); | ||
elem.classList.add('js'); | ||
}); | ||
const index = { | ||
@@ -393,0 +379,0 @@ BookmarkToggle, |
{ | ||
"name": "blacklight-frontend", | ||
"version": "8.0.0-beta.5", | ||
"version": "8.0.0-beta.6", | ||
"description": "[![Build Status](https://travis-ci.com/projectblacklight/blacklight.png?branch=main)](https://travis-ci.com/projectblacklight/blacklight) [![Gem Version](https://badge.fury.io/rb/blacklight.png)](http://badge.fury.io/rb/blacklight) [![Coverage Status](https://coveralls.io/repos/github/projectblacklight/blacklight/badge.svg?branch=main)](https://coveralls.io/github/projectblacklight/blacklight?branch=main)", | ||
"main": "app/assets/javascripts/blacklight", | ||
"module": "app/assets/javascripts/blacklight/blacklight.esm.js", | ||
"scripts": { | ||
"js-compile-bundle": "rollup --config rollup.config.js --sourcemap && ESM=true rollup --config rollup.config.js --sourcemap" | ||
"prepare": "rollup --config rollup.config.js --sourcemap && ESM=true rollup --config rollup.config.js --sourcemap" | ||
}, | ||
@@ -14,3 +15,4 @@ "repository": { | ||
"files": [ | ||
"app/assets" | ||
"app/assets", | ||
"app/javascript" | ||
], | ||
@@ -24,3 +26,4 @@ "author": "", | ||
"devDependencies": { | ||
"rollup": "^2.60.0" | ||
"rollup": "^2.60.0", | ||
"rollup-plugin-includepaths": "^0.2.4" | ||
}, | ||
@@ -27,0 +30,0 @@ "browserslist": [ |
@@ -63,3 +63,3 @@ # Blacklight | ||
1. run `npm install` to download dependencies | ||
1. run `npm run js-compile-bundle` to build the bundle | ||
1. run `npm run prepare` to build the bundle | ||
1. run `npm publish` to push the javascript package to https://npmjs.org/package/blacklight-frontend | ||
@@ -66,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117698
38
996
2
7