blacklight-frontend
Advanced tools
Comparing version 7.0.0-alpha.1 to 7.0.0
@@ -22,9 +22,9 @@ Blacklight = function () { | ||
// Turbolinks < 5 | ||
listeners.push('page:load', 'ready'); | ||
listeners.push('page:load', 'DOMContentLoaded'); | ||
} | ||
} else { | ||
listeners.push('ready'); | ||
listeners.push('DOMContentLoaded'); | ||
} | ||
return listeners.join(' '); | ||
return listeners; | ||
} | ||
@@ -36,4 +36,6 @@ }; | ||
// If app isn't using turbolinks, this event will never be triggered, no prob. | ||
$(document).on(Blacklight.listeners(), function () { | ||
Blacklight.activate(); | ||
Blacklight.listeners().forEach(function (listener) { | ||
document.addEventListener(listener, function () { | ||
Blacklight.activate(); | ||
}); | ||
}); | ||
@@ -78,6 +80,10 @@ | ||
//change form submit toggle to checkbox | ||
Blacklight.do_bookmark_toggle_behavior = function () { | ||
$(Blacklight.do_bookmark_toggle_behavior.selector).bl_checkbox_submit({ | ||
// css_class is added to elements added, plus used for id base | ||
css_class: "toggle-bookmark", | ||
Blacklight.doBookmarkToggleBehavior = function () { | ||
if (typeof Blacklight.do_bookmark_toggle_behavior == 'function') { | ||
console.warn("do_bookmark_toggle_behavior is deprecated. Use doBookmarkToggleBehavior instead."); | ||
return Blacklight.do_bookmark_toggle_behavior(); | ||
} | ||
$(Blacklight.doBookmarkToggleBehavior.selector).blCheckboxSubmit({ | ||
// cssClass is added to elements added, plus used for id base | ||
cssClass: 'toggle-bookmark', | ||
success: function (checked, response) { | ||
@@ -90,6 +96,6 @@ if (response.bookmarks) { | ||
}; | ||
Blacklight.do_bookmark_toggle_behavior.selector = "form.bookmark-toggle"; | ||
Blacklight.doBookmarkToggleBehavior.selector = 'form.bookmark-toggle'; | ||
Blacklight.onLoad(function () { | ||
Blacklight.do_bookmark_toggle_behavior(); | ||
Blacklight.doBookmarkToggleBehavior(); | ||
}); | ||
@@ -99,4 +105,4 @@ })(jQuery); | ||
that will convert a "toggle" form, with single submit button to add/remove | ||
something, like used for Bookmarks, into an AJAXy checkbox instead. | ||
something, like used for Bookmarks, into an AJAXy checkbox instead. | ||
Apply to a form. Does require certain assumption about the form: | ||
@@ -107,18 +113,18 @@ 1) The same form 'action' href must be used for both ADD and REMOVE | ||
to be doing a certain HTTP verb. So same URL, PUT to add, DELETE | ||
to remove. This plugin assumes that. | ||
Plus, the form this is applied to should provide a data-doc-id | ||
to remove. This plugin assumes that. | ||
Plus, the form this is applied to should provide a data-doc-id | ||
attribute (HTML5-style doc-*) that contains the id/primary key | ||
of the object in question -- used by plugin for a unique value for | ||
DOM id's. | ||
DOM id's. | ||
Uses HTML for a checkbox compatible with Bootstrap 3. | ||
Uses HTML for a checkbox compatible with Bootstrap 3. | ||
Pass in options for your class name and labels: | ||
$("form.something").bl_checkbox_submit({ | ||
checked_label: "Selected", | ||
unchecked_label: "Select", | ||
progress_label: "Saving...", | ||
//css_class is added to elements added, plus used for id base | ||
css_class: "toggle_my_kinda_form", | ||
$("form.something").blCheckboxSubmit({ | ||
//cssClass is added to elements added, plus used for id base | ||
cssClass: "toggle_my_kinda_form", | ||
error: function() { | ||
#optional callback | ||
}, | ||
success: function(after_success_check_state) { | ||
@@ -130,6 +136,5 @@ #optional callback | ||
(function ($) { | ||
$.fn.bl_checkbox_submit = function (arg_opts) { | ||
$.fn.blCheckboxSubmit = function (argOpts) { | ||
this.each(function () { | ||
var options = $.extend({}, $.fn.bl_checkbox_submit.defaults, arg_opts); | ||
var options = $.extend({}, $.fn.blCheckboxSubmit.defaults, argOpts); | ||
@@ -141,32 +146,32 @@ var form = $(this); | ||
//for both bookmarks/$doc_id. But let's take out the irrelevant parts | ||
//of the form to avoid any future confusion. | ||
form.find("input[type=submit]").remove(); | ||
//of the form to avoid any future confusion. | ||
form.find('input[type=submit]').remove(); | ||
//View needs to set data-doc-id so we know a unique value | ||
//for making DOM id | ||
var unique_id = form.attr("data-doc-id") || Math.random(); | ||
// if form is currently using method delete to change state, | ||
var uniqueId = form.attr('data-doc-id') || Math.random(); | ||
// if form is currently using method delete to change state, | ||
// then checkbox is currently checked | ||
var checked = form.find("input[name=_method][value=delete]").size() != 0; | ||
var checked = form.find('input[name=_method][value=delete]').length != 0; | ||
var checkbox = $('<input type="checkbox">').addClass(options.css_class).attr("id", options.css_class + "_" + unique_id); | ||
var label = $('<label>').addClass(options.css_class).attr("for", options.css_class + '_' + unique_id).attr("title", form.attr("title") || ""); | ||
var checkbox = $('<input type="checkbox">').addClass(options.cssClass).attr('id', options.cssClass + '_' + uniqueId); | ||
var label = $('<label>').addClass(options.cssClass).attr('for', options.cssClass + '_' + uniqueId).attr('title', form.attr('title') || ''); | ||
var span = $('<span>'); | ||
label.append(checkbox); | ||
label.append(" "); | ||
label.append(' '); | ||
label.append(span); | ||
var checkbox_div = $("<div class='checkbox' />").addClass(options.css_class).append(label); | ||
var checkboxDiv = $('<div class="checkbox" />').addClass(options.cssClass).append(label); | ||
function update_state_for(state) { | ||
checkbox.prop("checked", state); | ||
label.toggleClass("checked", state); | ||
function updateStateFor(state) { | ||
checkbox.prop('checked', state); | ||
label.toggleClass('checked', state); | ||
if (state) { | ||
//Set the Rails hidden field that fakes an HTTP verb | ||
//properly for current state action. | ||
form.find("input[name=_method]").val("delete"); | ||
//properly for current state action. | ||
form.find('input[name=_method]').val('delete'); | ||
span.text(form.attr('data-present')); | ||
} else { | ||
form.find("input[name=_method]").val("put"); | ||
form.find('input[name=_method]').val('put'); | ||
span.text(form.attr('data-absent')); | ||
@@ -176,35 +181,33 @@ } | ||
form.append(checkbox_div); | ||
update_state_for(checked); | ||
form.append(checkboxDiv); | ||
updateStateFor(checked); | ||
checkbox.click(function () { | ||
span.text(form.attr('data-inprogress')); | ||
label.attr("disabled", "disabled"); | ||
checkbox.attr("disabled", "disabled"); | ||
label.attr('disabled', 'disabled'); | ||
checkbox.attr('disabled', 'disabled'); | ||
$.ajax({ | ||
url: form.attr("action"), | ||
url: form.attr('action'), | ||
dataType: 'json', | ||
type: form.attr("method").toUpperCase(), | ||
type: form.attr('method').toUpperCase(), | ||
data: form.serialize(), | ||
error: function () { | ||
alert("Error"); | ||
update_state_for(checked); | ||
label.removeAttr("disabled"); | ||
checkbox.removeAttr("disabled"); | ||
label.removeAttr('disabled'); | ||
checkbox.removeAttr('disabled'); | ||
options.error.call(); | ||
}, | ||
success: function (data, status, xhr) { | ||
//if app isn't running at all, xhr annoyingly | ||
//reports success with status 0. | ||
//reports success with status 0. | ||
if (xhr.status != 0) { | ||
checked = !checked; | ||
update_state_for(checked); | ||
label.removeAttr("disabled"); | ||
checkbox.removeAttr("disabled"); | ||
updateStateFor(checked); | ||
label.removeAttr('disabled'); | ||
checkbox.removeAttr('disabled'); | ||
options.success.call(form, checked, xhr.responseJSON); | ||
} else { | ||
alert("Error"); | ||
update_state_for(checked); | ||
label.removeAttr("disabled"); | ||
checkbox.removeAttr("disabled"); | ||
label.removeAttr('disabled'); | ||
checkbox.removeAttr('disabled'); | ||
options.error.call(); | ||
} | ||
@@ -217,9 +220,12 @@ } | ||
}); //this.each | ||
}); //this.each | ||
return this; | ||
}; | ||
$.fn.bl_checkbox_submit.defaults = { | ||
//css_class is added to elements added, plus used for id base | ||
css_class: "bl_checkbox_submit", | ||
$.fn.blCheckboxSubmit.defaults = { | ||
//cssClass is added to elements added, plus used for id base | ||
cssClass: 'blCheckboxSubmit', | ||
error: function () { | ||
alert("Error"); | ||
}, | ||
success: function () {} //callback | ||
@@ -232,3 +238,3 @@ }; | ||
// with the hash or the page could jump around. | ||
$(document).on("click", "a[data-toggle=collapse][href='#'], [data-toggle=collapse] a[href='#']", function (event) { | ||
$(document).on('click', 'a[data-toggle=collapse][href="#"], [data-toggle=collapse] a[href="#"]', function (event) { | ||
event.preventDefault(); | ||
@@ -263,4 +269,2 @@ }); | ||
})(jQuery); | ||
//= require blacklight/core | ||
/* | ||
@@ -346,8 +350,8 @@ The blacklight modal plugin can display some interactions inside a Bootstrap | ||
// a Bootstrap modal div that should be already on the page hidden | ||
Blacklight.modal.modalSelector = "#blacklight-modal"; | ||
Blacklight.modal.modalSelector = '#blacklight-modal'; | ||
// Trigger selectors identify forms or hyperlinks that should open | ||
// inside a modal dialog. | ||
Blacklight.modal.triggerLinkSelector = "a[data-blacklight-modal~=trigger]"; | ||
Blacklight.modal.triggerFormSelector = "form[data-blacklight-modal~=trigger]"; | ||
Blacklight.modal.triggerLinkSelector = 'a[data-blacklight-modal~=trigger]'; | ||
Blacklight.modal.triggerFormSelector = 'form[data-blacklight-modal~=trigger]'; | ||
@@ -362,7 +366,6 @@ // preserve selectors identify forms or hyperlinks that, if activated already | ||
Blacklight.modal.preserveLinkSelector = Blacklight.modal.modalSelector + ' a[data-blacklight-modal~=preserve]'; | ||
Blacklight.modal.preserveFormSelector = Blacklight.modal.modalSelector + ' form[data-blacklight-modal~=preserve]'; | ||
Blacklight.modal.containerSelector = "[data-blacklight-modal~=container]"; | ||
Blacklight.modal.containerSelector = '[data-blacklight-modal~=container]'; | ||
Blacklight.modal.modalCloseSelector = "[data-blacklight-modal~=close]"; | ||
Blacklight.modal.modalCloseSelector = '[data-blacklight-modal~=close]'; | ||
@@ -373,3 +376,3 @@ // Called on fatal failure of ajax load, function returns content | ||
Blacklight.modal.onFailure = function (data) { | ||
var contents = "<div class='modal-header'>" + "<div class='modal-title'>Network Error</div>" + '<button type="button" class="blacklight-modal-close close" data-dismiss="modal" aria-label="Close">' + ' <span aria-hidden="true">×</span>' + '</button>'; | ||
var contents = '<div class="modal-header">' + '<div class="modal-title">Network Error</div>' + '<button type="button" class="blacklight-modal-close close" data-dismiss="modal" aria-label="Close">' + ' <span aria-hidden="true">×</span>' + '</button>'; | ||
$(Blacklight.modal.modalSelector).find('.modal-content').html(contents); | ||
@@ -383,3 +386,3 @@ $(Blacklight.modal.modalSelector).modal('show'); | ||
// code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/master/src/ajax/load.js?source=c#L62 | ||
var container = $("<div>").append(jQuery.parseHTML(contents)).find(Blacklight.modal.containerSelector).first(); | ||
var container = $('<div>').append(jQuery.parseHTML(contents)).find(Blacklight.modal.containerSelector).first(); | ||
if (container.length !== 0) { | ||
@@ -418,3 +421,3 @@ contents = container.html(); | ||
Blacklight.modal.setup_modal = function () { | ||
Blacklight.modal.setupModal = function () { | ||
// Event indicating blacklight is setting up a modal link, | ||
@@ -424,3 +427,3 @@ // you can catch it and call e.preventDefault() to abort | ||
var e = $.Event('setup.blacklight.blacklight-modal'); | ||
$("body").trigger(e); | ||
$('body').trigger(e); | ||
if (e.isDefaultPrevented()) return; | ||
@@ -431,7 +434,7 @@ | ||
// still only gets the event handler called once. | ||
$("body").on("click", Blacklight.modal.triggerLinkSelector + ", " + Blacklight.modal.preserveLinkSelector, Blacklight.modal.modalAjaxLinkClick); | ||
$("body").on("submit", Blacklight.modal.triggerFormSelector + ", " + Blacklight.modal.preserveFormSelector, Blacklight.modal.modalAjaxFormSubmit); | ||
$('body').on('click', Blacklight.modal.triggerLinkSelector + ', ' + Blacklight.modal.preserveLinkSelector, Blacklight.modal.modalAjaxLinkClick); | ||
$('body').on('submit', Blacklight.modal.triggerFormSelector + ', ' + Blacklight.modal.preserveFormSelector, Blacklight.modal.modalAjaxFormSubmit); | ||
// Catch our own custom loaded event to implement data-blacklight-modal=closed | ||
$("body").on("loaded.blacklight.blacklight-modal", Blacklight.modal.check_close_modal); | ||
$('body').on('loaded.blacklight.blacklight-modal', Blacklight.modal.checkCloseModal); | ||
@@ -441,3 +444,3 @@ // we support doing data-dismiss=modal on a <a> with a href for non-ajax | ||
// non-JS contexts. | ||
$("body ").on("click", Blacklight.modal.modalSelector + " a[data-dismiss~=modal]", function (e) { | ||
$('body').on('click', Blacklight.modal.modalSelector + ' a[data-dismiss~=modal]', function (e) { | ||
e.preventDefault(); | ||
@@ -449,12 +452,12 @@ }); | ||
// to catch contained data-blacklight-modal=closed directions | ||
Blacklight.modal.check_close_modal = function (event) { | ||
Blacklight.modal.checkCloseModal = function (event) { | ||
if ($(event.target).find(Blacklight.modal.modalCloseSelector).length) { | ||
modal_flashes = $(this).find('.flash_messages'); | ||
var modalFlashes = $(this).find('.flash_messages'); | ||
$(event.target).modal("hide"); | ||
$(event.target).modal('hide'); | ||
event.preventDefault(); | ||
main_flashes = $('#main-flashes'); | ||
main_flashes.append(modal_flashes); | ||
modal_flashes.fadeIn(500); | ||
var mainFlashes = $('#main-flashes'); | ||
mainFlashes.append(modalFlashes); | ||
modalFlashes.fadeIn(500); | ||
} | ||
@@ -464,7 +467,10 @@ }; | ||
Blacklight.onLoad(function () { | ||
Blacklight.modal.setup_modal(); | ||
Blacklight.modal.setupModal(); | ||
}); | ||
//= require blacklight/core | ||
(function ($) { | ||
Blacklight.do_search_context_behavior = function () { | ||
Blacklight.doSearchContextBehavior = function () { | ||
if (typeof Blacklight.do_search_context_behavior == 'function') { | ||
console.warn("do_search_context_behavior is deprecated. Use doSearchContextBehavior instead."); | ||
return Blacklight.do_search_context_behavior(); | ||
} | ||
$('a[data-context-href]').on('click.search-context', Blacklight.handleSearchContextMethod); | ||
@@ -476,2 +482,6 @@ }; | ||
Blacklight.handleSearchContextMethod = function (event) { | ||
if (typeof Blacklight.handle_search_context_method == 'function') { | ||
console.warn("handle_search_context_method is deprecated. Use handleSearchContextMethod instead."); | ||
return Blacklight.handle_search_context_method(event); | ||
} | ||
var link = $(this); | ||
@@ -509,5 +519,5 @@ | ||
Blacklight.onLoad(function () { | ||
Blacklight.do_search_context_behavior(); | ||
Blacklight.doSearchContextBehavior(); | ||
}); | ||
})(jQuery); | ||
(function($) { | ||
//change form submit toggle to checkbox | ||
Blacklight.do_bookmark_toggle_behavior = function() { | ||
$(Blacklight.do_bookmark_toggle_behavior.selector).bl_checkbox_submit({ | ||
// css_class is added to elements added, plus used for id base | ||
css_class: "toggle-bookmark", | ||
//change form submit toggle to checkbox | ||
Blacklight.doBookmarkToggleBehavior = function() { | ||
if (typeof Blacklight.do_bookmark_toggle_behavior == 'function') { | ||
console.warn("do_bookmark_toggle_behavior is deprecated. Use doBookmarkToggleBehavior instead."); | ||
return Blacklight.do_bookmark_toggle_behavior(); | ||
} | ||
$(Blacklight.doBookmarkToggleBehavior.selector).blCheckboxSubmit({ | ||
// cssClass is added to elements added, plus used for id base | ||
cssClass: 'toggle-bookmark', | ||
success: function(checked, response) { | ||
@@ -14,6 +18,6 @@ if (response.bookmarks) { | ||
}; | ||
Blacklight.do_bookmark_toggle_behavior.selector = "form.bookmark-toggle"; | ||
Blacklight.doBookmarkToggleBehavior.selector = 'form.bookmark-toggle'; | ||
Blacklight.onLoad(function() { | ||
Blacklight.do_bookmark_toggle_behavior(); | ||
Blacklight.doBookmarkToggleBehavior(); | ||
}); | ||
@@ -20,0 +24,0 @@ |
/* A JQuery plugin (should this be implemented as a widget instead? not sure) | ||
that will convert a "toggle" form, with single submit button to add/remove | ||
something, like used for Bookmarks, into an AJAXy checkbox instead. | ||
something, like used for Bookmarks, into an AJAXy checkbox instead. | ||
Apply to a form. Does require certain assumption about the form: | ||
@@ -10,18 +10,18 @@ 1) The same form 'action' href must be used for both ADD and REMOVE | ||
to be doing a certain HTTP verb. So same URL, PUT to add, DELETE | ||
to remove. This plugin assumes that. | ||
Plus, the form this is applied to should provide a data-doc-id | ||
to remove. This plugin assumes that. | ||
Plus, the form this is applied to should provide a data-doc-id | ||
attribute (HTML5-style doc-*) that contains the id/primary key | ||
of the object in question -- used by plugin for a unique value for | ||
DOM id's. | ||
DOM id's. | ||
Uses HTML for a checkbox compatible with Bootstrap 3. | ||
Uses HTML for a checkbox compatible with Bootstrap 3. | ||
Pass in options for your class name and labels: | ||
$("form.something").bl_checkbox_submit({ | ||
checked_label: "Selected", | ||
unchecked_label: "Select", | ||
progress_label: "Saving...", | ||
//css_class is added to elements added, plus used for id base | ||
css_class: "toggle_my_kinda_form", | ||
$("form.something").blCheckboxSubmit({ | ||
//cssClass is added to elements added, plus used for id base | ||
cssClass: "toggle_my_kinda_form", | ||
error: function() { | ||
#optional callback | ||
}, | ||
success: function(after_success_check_state) { | ||
@@ -32,9 +32,8 @@ #optional callback | ||
*/ | ||
(function($) { | ||
$.fn.bl_checkbox_submit = function(arg_opts) { | ||
(function($) { | ||
$.fn.blCheckboxSubmit = function(argOpts) { | ||
this.each(function() { | ||
var options = $.extend({}, $.fn.bl_checkbox_submit.defaults, arg_opts); | ||
var options = $.extend({}, $.fn.blCheckboxSubmit.defaults, argOpts); | ||
var form = $(this); | ||
@@ -45,93 +44,94 @@ form.children().hide(); | ||
//for both bookmarks/$doc_id. But let's take out the irrelevant parts | ||
//of the form to avoid any future confusion. | ||
form.find("input[type=submit]").remove(); | ||
//of the form to avoid any future confusion. | ||
form.find('input[type=submit]').remove(); | ||
//View needs to set data-doc-id so we know a unique value | ||
//for making DOM id | ||
var unique_id = form.attr("data-doc-id") || Math.random(); | ||
// if form is currently using method delete to change state, | ||
var uniqueId = form.attr('data-doc-id') || Math.random(); | ||
// if form is currently using method delete to change state, | ||
// then checkbox is currently checked | ||
var checked = (form.find("input[name=_method][value=delete]").size() != 0); | ||
var checkbox = $('<input type="checkbox">') | ||
.addClass( options.css_class ) | ||
.attr("id", options.css_class + "_" + unique_id); | ||
var checked = (form.find('input[name=_method][value=delete]').length != 0); | ||
var checkbox = $('<input type="checkbox">') | ||
.addClass( options.cssClass ) | ||
.attr('id', options.cssClass + '_' + uniqueId); | ||
var label = $('<label>') | ||
.addClass( options.css_class ) | ||
.attr("for", options.css_class + '_' + unique_id) | ||
.attr("title", form.attr("title") || ""); | ||
.addClass( options.cssClass ) | ||
.attr('for', options.cssClass + '_' + uniqueId) | ||
.attr('title', form.attr('title') || ''); | ||
var span = $('<span>'); | ||
label.append(checkbox); | ||
label.append(" "); | ||
label.append(span); | ||
label.append(' '); | ||
label.append(span); | ||
var checkbox_div = $("<div class='checkbox' />") | ||
.addClass(options.css_class) | ||
var checkboxDiv = $('<div class="checkbox" />') | ||
.addClass(options.cssClass) | ||
.append(label); | ||
function update_state_for(state) { | ||
checkbox.prop("checked", state); | ||
label.toggleClass("checked", state); | ||
if (state) { | ||
function updateStateFor(state) { | ||
checkbox.prop('checked', state); | ||
label.toggleClass('checked', state); | ||
if (state) { | ||
//Set the Rails hidden field that fakes an HTTP verb | ||
//properly for current state action. | ||
form.find("input[name=_method]").val("delete"); | ||
//properly for current state action. | ||
form.find('input[name=_method]').val('delete'); | ||
span.text(form.attr('data-present')); | ||
} else { | ||
form.find("input[name=_method]").val("put"); | ||
form.find('input[name=_method]').val('put'); | ||
span.text(form.attr('data-absent')); | ||
} | ||
} | ||
form.append(checkbox_div); | ||
update_state_for(checked); | ||
form.append(checkboxDiv); | ||
updateStateFor(checked); | ||
checkbox.click(function() { | ||
span.text(form.attr('data-inprogress')); | ||
label.attr("disabled", "disabled"); | ||
checkbox.attr("disabled", "disabled"); | ||
label.attr('disabled', 'disabled'); | ||
checkbox.attr('disabled', 'disabled'); | ||
$.ajax({ | ||
url: form.attr("action"), | ||
url: form.attr('action'), | ||
dataType: 'json', | ||
type: form.attr("method").toUpperCase(), | ||
type: form.attr('method').toUpperCase(), | ||
data: form.serialize(), | ||
error: function() { | ||
alert("Error"); | ||
update_state_for(checked); | ||
label.removeAttr("disabled"); | ||
checkbox.removeAttr("disabled"); | ||
label.removeAttr('disabled'); | ||
checkbox.removeAttr('disabled'); | ||
options.error.call(); | ||
}, | ||
success: function(data, status, xhr) { | ||
//if app isn't running at all, xhr annoyingly | ||
//reports success with status 0. | ||
//reports success with status 0. | ||
if (xhr.status != 0) { | ||
checked = ! checked; | ||
update_state_for(checked); | ||
label.removeAttr("disabled"); | ||
checkbox.removeAttr("disabled"); | ||
updateStateFor(checked); | ||
label.removeAttr('disabled'); | ||
checkbox.removeAttr('disabled'); | ||
options.success.call(form, checked, xhr.responseJSON); | ||
} else { | ||
alert("Error"); | ||
update_state_for(checked); | ||
label.removeAttr("disabled"); | ||
checkbox.removeAttr("disabled"); | ||
label.removeAttr('disabled'); | ||
checkbox.removeAttr('disabled'); | ||
options.error.call(); | ||
} | ||
} | ||
}); | ||
return false; | ||
}); //checkbox.click | ||
}); //this.each | ||
}); //this.each | ||
return this; | ||
}; | ||
$.fn.bl_checkbox_submit.defaults = { | ||
//css_class is added to elements added, plus used for id base | ||
css_class: "bl_checkbox_submit", | ||
$.fn.blCheckboxSubmit.defaults = { | ||
//cssClass is added to elements added, plus used for id base | ||
cssClass: 'blCheckboxSubmit', | ||
error: function() { | ||
alert("Error"); | ||
}, | ||
success: function() {} //callback | ||
}; | ||
})(jQuery); |
@@ -5,3 +5,3 @@ (function($) { | ||
// with the hash or the page could jump around. | ||
$(document).on("click", "a[data-toggle=collapse][href='#'], [data-toggle=collapse] a[href='#']", function(event) { | ||
$(document).on('click', 'a[data-toggle=collapse][href="#"], [data-toggle=collapse] a[href="#"]', function(event) { | ||
event.preventDefault(); | ||
@@ -8,0 +8,0 @@ }); |
@@ -22,9 +22,9 @@ Blacklight = function() { | ||
// Turbolinks < 5 | ||
listeners.push('page:load', 'ready'); | ||
listeners.push('page:load', 'DOMContentLoaded'); | ||
} | ||
} else { | ||
listeners.push('ready'); | ||
listeners.push('DOMContentLoaded'); | ||
} | ||
return listeners.join(' '); | ||
return listeners; | ||
} | ||
@@ -36,6 +36,8 @@ }; | ||
// If app isn't using turbolinks, this event will never be triggered, no prob. | ||
$(document).on(Blacklight.listeners(), function() { | ||
Blacklight.activate(); | ||
}); | ||
Blacklight.listeners().forEach(function(listener) { | ||
document.addEventListener(listener, function() { | ||
Blacklight.activate() | ||
}) | ||
}) | ||
$('.no-js').removeClass('no-js').addClass('js'); |
@@ -1,3 +0,1 @@ | ||
//= require blacklight/core | ||
/* | ||
@@ -83,8 +81,8 @@ The blacklight modal plugin can display some interactions inside a Bootstrap | ||
// a Bootstrap modal div that should be already on the page hidden | ||
Blacklight.modal.modalSelector = "#blacklight-modal"; | ||
Blacklight.modal.modalSelector = '#blacklight-modal'; | ||
// Trigger selectors identify forms or hyperlinks that should open | ||
// inside a modal dialog. | ||
Blacklight.modal.triggerLinkSelector = "a[data-blacklight-modal~=trigger]"; | ||
Blacklight.modal.triggerFormSelector = "form[data-blacklight-modal~=trigger]"; | ||
Blacklight.modal.triggerLinkSelector = 'a[data-blacklight-modal~=trigger]'; | ||
Blacklight.modal.triggerFormSelector = 'form[data-blacklight-modal~=trigger]'; | ||
@@ -99,7 +97,6 @@ // preserve selectors identify forms or hyperlinks that, if activated already | ||
Blacklight.modal.preserveLinkSelector = Blacklight.modal.modalSelector + ' a[data-blacklight-modal~=preserve]'; | ||
Blacklight.modal.preserveFormSelector = Blacklight.modal.modalSelector + ' form[data-blacklight-modal~=preserve]' | ||
Blacklight.modal.containerSelector = "[data-blacklight-modal~=container]"; | ||
Blacklight.modal.containerSelector = '[data-blacklight-modal~=container]'; | ||
Blacklight.modal.modalCloseSelector = "[data-blacklight-modal~=close]"; | ||
Blacklight.modal.modalCloseSelector = '[data-blacklight-modal~=close]'; | ||
@@ -110,4 +107,4 @@ // Called on fatal failure of ajax load, function returns content | ||
Blacklight.modal.onFailure = function(data) { | ||
var contents = "<div class='modal-header'>" + | ||
"<div class='modal-title'>Network Error</div>" + | ||
var contents = '<div class="modal-header">' + | ||
'<div class="modal-title">Network Error</div>' + | ||
'<button type="button" class="blacklight-modal-close close" data-dismiss="modal" aria-label="Close">' + | ||
@@ -124,3 +121,3 @@ ' <span aria-hidden="true">×</span>' + | ||
// code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/master/src/ajax/load.js?source=c#L62 | ||
var container = $("<div>"). | ||
var container = $('<div>'). | ||
append( jQuery.parseHTML(contents) ).find( Blacklight.modal.containerSelector ).first(); | ||
@@ -167,3 +164,3 @@ if (container.length !== 0) { | ||
Blacklight.modal.setup_modal = function() { | ||
Blacklight.modal.setupModal = function() { | ||
// Event indicating blacklight is setting up a modal link, | ||
@@ -173,3 +170,3 @@ // you can catch it and call e.preventDefault() to abort | ||
var e = $.Event('setup.blacklight.blacklight-modal'); | ||
$("body").trigger(e); | ||
$('body').trigger(e); | ||
if (e.isDefaultPrevented()) return; | ||
@@ -180,9 +177,9 @@ | ||
// still only gets the event handler called once. | ||
$("body").on("click", Blacklight.modal.triggerLinkSelector + ", " + Blacklight.modal.preserveLinkSelector, | ||
$('body').on('click', Blacklight.modal.triggerLinkSelector + ', ' + Blacklight.modal.preserveLinkSelector, | ||
Blacklight.modal.modalAjaxLinkClick); | ||
$("body").on("submit", Blacklight.modal.triggerFormSelector + ", " + Blacklight.modal.preserveFormSelector, | ||
$('body').on('submit', Blacklight.modal.triggerFormSelector + ', ' + Blacklight.modal.preserveFormSelector, | ||
Blacklight.modal.modalAjaxFormSubmit); | ||
// Catch our own custom loaded event to implement data-blacklight-modal=closed | ||
$("body").on("loaded.blacklight.blacklight-modal", Blacklight.modal.check_close_modal); | ||
$('body').on('loaded.blacklight.blacklight-modal', Blacklight.modal.checkCloseModal); | ||
@@ -192,3 +189,3 @@ // we support doing data-dismiss=modal on a <a> with a href for non-ajax | ||
// non-JS contexts. | ||
$("body ").on("click", Blacklight.modal.modalSelector + " a[data-dismiss~=modal]", function (e) { | ||
$('body').on('click', Blacklight.modal.modalSelector + ' a[data-dismiss~=modal]', function (e) { | ||
e.preventDefault(); | ||
@@ -200,12 +197,12 @@ }); | ||
// to catch contained data-blacklight-modal=closed directions | ||
Blacklight.modal.check_close_modal = function(event) { | ||
Blacklight.modal.checkCloseModal = function(event) { | ||
if ($(event.target).find(Blacklight.modal.modalCloseSelector).length) { | ||
modal_flashes = $(this).find('.flash_messages'); | ||
var modalFlashes = $(this).find('.flash_messages'); | ||
$(event.target).modal("hide"); | ||
$(event.target).modal('hide'); | ||
event.preventDefault(); | ||
main_flashes = $('#main-flashes'); | ||
main_flashes.append(modal_flashes); | ||
modal_flashes.fadeIn(500); | ||
var mainFlashes = $('#main-flashes'); | ||
mainFlashes.append(modalFlashes); | ||
modalFlashes.fadeIn(500); | ||
} | ||
@@ -215,3 +212,3 @@ } | ||
Blacklight.onLoad(function() { | ||
Blacklight.modal.setup_modal(); | ||
Blacklight.modal.setupModal(); | ||
}); |
@@ -1,4 +0,7 @@ | ||
//= require blacklight/core | ||
(function($) { | ||
Blacklight.do_search_context_behavior = function() { | ||
Blacklight.doSearchContextBehavior = function() { | ||
if (typeof Blacklight.do_search_context_behavior == 'function') { | ||
console.warn("do_search_context_behavior is deprecated. Use doSearchContextBehavior instead."); | ||
return Blacklight.do_search_context_behavior(); | ||
} | ||
$('a[data-context-href]').on('click.search-context', Blacklight.handleSearchContextMethod); | ||
@@ -10,2 +13,6 @@ }; | ||
Blacklight.handleSearchContextMethod = function(event) { | ||
if (typeof Blacklight.handle_search_context_method == 'function') { | ||
console.warn("handle_search_context_method is deprecated. Use handleSearchContextMethod instead."); | ||
return Blacklight.handle_search_context_method(event); | ||
} | ||
var link = $(this); | ||
@@ -41,4 +48,4 @@ | ||
Blacklight.onLoad(function() { | ||
Blacklight.do_search_context_behavior(); | ||
Blacklight.doSearchContextBehavior(); | ||
}); | ||
})(jQuery); |
{ | ||
"name": "blacklight-frontend", | ||
"version": "7.0.0-alpha.1", | ||
"version": "7.0.0", | ||
"description": "[![Build Status](https://travis-ci.org/projectblacklight/blacklight.png?branch=master)](https://travis-ci.org/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=master)](https://coveralls.io/github/projectblacklight/blacklight?branch=master)", | ||
@@ -24,6 +24,7 @@ "main": "app/assets/javascripts/blacklight", | ||
"dependencies": { | ||
"bootstrap": "4.0.0", | ||
"jquery": "^3.2.1", | ||
"bloodhound-js": "^1.2.3", | ||
"bootstrap": "^4.1.3", | ||
"jquery": "^3.3.1", | ||
"typeahead.js": "^0.11.1" | ||
} | ||
} |
# Blacklight | ||
[![Build Status](https://travis-ci.org/projectblacklight/blacklight.png?branch=master)](https://travis-ci.org/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=master)](https://coveralls.io/github/projectblacklight/blacklight?branch=master) | ||
[![Build Status](https://travis-ci.org/projectblacklight/blacklight.png?branch=master)](https://travis-ci.org/projectblacklight/blacklight) [![Gem Version](https://badge.fury.io/rb/blacklight.png)](http://badge.fury.io/rb/blacklight) [![Test Coverage](https://api.codeclimate.com/v1/badges/83fd270492c136594e59/test_coverage)](https://codeclimate.com/github/projectblacklight/blacklight/test_coverage) | ||
@@ -37,5 +37,5 @@ Blacklight is an open source Solr user interface discovery platform. | ||
* Ruby 2.1+ | ||
* Ruby 2.2+ | ||
* Bundler | ||
* Rails 5.0+ | ||
* Rails 5.1+ | ||
@@ -48,73 +48,14 @@ ## Configuring Apache Solr | ||
in `app/assets/javascripts/blacklight/blacklight.js`. This file should not be edited | ||
by hand as any changes would be overwritten. | ||
This is accomplished with the following steps: | ||
1. Install npm | ||
by hand as any changes would be overwritten. When any of the javascript | ||
components in the gem are changed, this bundle should be rebuild with the | ||
following steps: | ||
1. [Install npm](https://www.npmjs.com/get-npm) | ||
1. run `npm install` to download dependencies | ||
1. run `npm run-script js-compile-bundle` to build the bundle | ||
1. run `npm run js-compile-bundle` to build the bundle | ||
1. run `npm publish` to push the javascript package to https://npmjs.org/package/blacklight-frontend | ||
## Using the javascript | ||
Install Webpacker | ||
Add blacklight-frontend as a dependency by doing: | ||
``` | ||
yarn add blacklight-frontend | ||
``` | ||
Blacklight ships with Javascript that can be compiled either by Webpacker or by | ||
Sprockets. To use Webpacker see the directions at https://github.com/projectblacklight/blacklight/wiki/Using-Webpacker-to-compile-javascript-assets | ||
Then add these lines to `config/webpack/environment.js` as per https://getbootstrap.com/docs/4.0/getting-started/webpack/ | ||
and https://github.com/rails/webpacker/blob/master/docs/webpack.md#plugins | ||
```js | ||
const webpack = require('webpack') | ||
environment.plugins.set( | ||
'Provide', | ||
new webpack.ProvidePlugin({ | ||
$: 'jquery', | ||
jQuery: 'jquery', | ||
jquery: 'jquery', | ||
'window.jQuery': 'jquery', | ||
Popper: ['popper.js', 'default'], | ||
}) | ||
) | ||
module.exports = environment | ||
``` | ||
In you pack file (`app/javascript/packs/application.js`), require blacklight: | ||
``` | ||
require('blacklight-frontend/app/assets/javascripts/blacklight/blacklight') | ||
``` | ||
Then remove these requires from `app/assets/javascripts/application.js`: | ||
``` | ||
//= require jquery | ||
//= require popper | ||
//= require twitter/typeahead | ||
//= require bootstrap | ||
``` | ||
Add the following to the app/views/layouts/blacklight/base.html.erb (maybe this can be simpler) | ||
``` | ||
<%= javascript_pack_tag 'application' %> | ||
``` | ||
You can probably remove the `<%= javascript_include_tag %>` | ||
### Using sprockets (not webpacker) | ||
If you want to use sprockets rather than webpacker, you must ensure these dependencies are in your Gemfile (done automatically by the install generator): | ||
``` | ||
gem 'bootstrap', '~> 4.0' | ||
gem 'popper_js' | ||
gem 'twitter-typeahead-rails' | ||
``` | ||
Then insure these requires are in `app/assets/javascripts/application.js` (done automatically by the install generator): | ||
``` | ||
//= require jquery | ||
//= require popper | ||
//= require twitter/typeahead | ||
//= require bootstrap | ||
``` | ||
If you prefer to use Sprockets, simply run the install generator, which will run the assets generator. For details see https://github.com/projectblacklight/blacklight/wiki/Using-Sprockets-to-compile-javascript-assets |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
66167
37
928
0
4
60
1
+ Addedbloodhound-js@^1.2.3
+ Addedasynckit@0.4.0(transitive)
+ Addedbloodhound-js@1.2.3(transitive)
+ Addedbootstrap@4.6.2(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcookiejar@2.1.4(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@3.2.7(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedes6-promise@3.3.1(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedform-data@2.5.2(transitive)
+ Addedformidable@1.2.6(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.1.3(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedqs@6.14.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedstorage2@0.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedsuperagent@3.8.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedbootstrap@4.0.0(transitive)
Updatedbootstrap@^4.1.3
Updatedjquery@^3.3.1