Koha/koha-tmpl/opac-tmpl/bootstrap/js/global.js
Owen Leonard 9cb89b4639 Bug 20168: Update of the OPAC bootstrap template to bootstrap v4
This patch updates the version of Bootstrap in the OPAC from 2.3.1 to
4.5.0. The Bootstrap JavaScript files have been replaced with custom
builds of the 4.5.0 JavaScript source files. The Bootstrap CSS is now
built into the OPAC CSS by loading the required Bootstrap 4.5.0 SCSS
files in node_modules.

OPAC SCSS now starts with Bootstrap customizations:

/* Bootstrap variable customizations */
$headings-color: #727272;
...

Followed by loading the necessary Bootstrap SCSS files:

/* Bootstrap imports */
@import "../../../../../node_modules/bootstrap/scss/functions";
@import "../../../../../node_modules/bootstrap/scss/variables";
...

Followed by our CSS. The build process for generating compiled CSS now
creates a file which bundles Bootstrap CSS and ours. Removed from the
Koha source: Bootstrap CSS files, Bootstrap "glyphicons" images.

The upgrade to Bootstrap 4 involved a lot of markup changes to conform
with new Bootstrap classes, especially in classes related to the grid.
Besides duplicating the grid we used before, this upgrade adds some new
features made possible by Bootstrap 4.5's use of flexbox as a layout
tool. This includes custom ordering of columns based on class names:
https://getbootstrap.com/docs/4.5/layout/grid/#order-classes.

Other areas where the most changes have been made: Navigation menus,
breadcrumb menus, buttons, dropdowns.

Bootstrap's JavaScript file is now "bootstrap.bundle.min.js" to reflect
the fact that a required JavaScript asset is now distributed separately
in Bootstrap 4. The "bundle" version includes Popper.js.

Unrelated changes: Indentation corrections, removal of invalid
"//<![CDATA[" markers, removal of invalid script type attributes.

To test, apply the patch and run 'yarn install' to install Bootstrap as
an npm module. Run 'yarn build --view opac' to regenerate the OPAC CSS.

Test as many aspect of the OPAC as possible, viewing pages at various
browser widths to confirm that everything adjusts well. Test with
various OPAC interface system preferences enabled and disabled.

Test self checkout and self checkin.

Known issues: RTL support has not been updated.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2020-09-09 14:13:03 +02:00

163 lines
6.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function( w ){
// if the class is already set, the font has already been loaded
if( w.document.documentElement.className.indexOf( "fonts-loaded" ) > -1 ){
return;
}
var PrimaryFont = new w.FontFaceObserver( "NotoSans", {
weight: 400
});
PrimaryFont.load(null, 5000).then(function(){
w.document.documentElement.className += " fonts-loaded";
}, function(){
console.log("Failed");
});
}( this ));
// http://stackoverflow.com/questions/1038746/equivalent-of-string-format-in-jquery/5341855#5341855
String.prototype.format = function() { return formatstr(this, arguments) }
function formatstr(str, col) {
col = typeof col === 'object' ? col : Array.prototype.slice.call(arguments, 1);
var idx = 0;
return str.replace(/%%|%s|%(\d+)\$s/g, function (m, n) {
if (m == "%%") { return "%"; }
if (m == "%s") { return col[idx++]; }
return col[n];
});
};
function confirmDelete(message) {
return (confirm(message) ? true : false);
}
function Dopop(link) {
newin=window.open(link,'popup','width=500,height=400,toolbar=false,scrollbars=yes,resizable=yes');
}
jQuery.fn.preventDoubleFormSubmit = function() {
jQuery(this).submit(function() {
if (this.beenSubmitted)
return false;
else
this.beenSubmitted = true;
});
};
function prefixOf (s, tok) {
var index = s.indexOf(tok);
return s.substring(0, index);
}
function suffixOf (s, tok) {
var index = s.indexOf(tok);
return s.substring(index + 1);
}
$("body").on("keypress", ".noEnterSubmit", function(e){
return checkEnter(e);
});
// http://jennifermadden.com/javascript/stringEnterKeyDetector.html
function checkEnter(e){ //e is event object passed from function invocation
var characterCode; // literal character code will be stored in this variable
if(e && e.which){ //if which property of event object is supported (NN4)
characterCode = e.which; //character code is contained in NN4's which property
} else {
characterCode = e.keyCode; //character code is contained in IE's keyCode property
}
if( characterCode == 13 //if generated character code is equal to ascii 13 (if enter key)
&& e.target.nodeName == "INPUT"
&& e.target.type != "submit" // Allow enter to submit using the submit button
){
return false;
} else {
return true;
}
}
// Adapted from https://gist.github.com/jnormore/7418776
function confirmModal(message, title, yes_label, no_label, callback) {
$("#bootstrap-confirm-box-modal").data('confirm-yes', false);
if($("#bootstrap-confirm-box-modal").length == 0) {
$("body").append('<div id="bootstrap-confirm-box-modal" tabindex="-1" role="dialog" aria-hidden="true" class="modal">\
<div class="modal-dialog">\
<div class="modal-content">\
<div class="modal-header" style="min-height:40px;">\
<h4 class="modal-title"></h4>\
<button type="button" class="closebtn" data-dismiss="modal" aria-label="Close">\
<span aria-hidden="true">×</span>\
</button>\
</div>\
<div class="modal-body"><p></p></div>\
<div class="modal-footer">\
<a href="#" id="bootstrap-confirm-box-modal-submit" class="btn btn-danger"><i class="fa fa-check" aria-hidden="true"></i></a>\
<a href="#" id="bootstrap-confirm-box-modal-cancel" data-dismiss="modal" class="btn btn-default"><i class="fa fa-remove" aria-hidden="true"></i></a>\
</div>\
</div>\
</div>\
</div>');
$("#bootstrap-confirm-box-modal-submit").on('click', function () {
$("#bootstrap-confirm-box-modal").data('confirm-yes', true);
$("#bootstrap-confirm-box-modal").modal('hide');
return false;
});
$("#bootstrap-confirm-box-modal").on('hide.bs.modal', function () {
if(callback) callback($("#bootstrap-confirm-box-modal").data('confirm-yes'));
});
}
$("#bootstrap-confirm-box-modal .modal-header h4").text( title || "" );
if( message && message != "" ){
$("#bootstrap-confirm-box-modal .modal-body").html( message || "" );
} else {
$("#bootstrap-confirm-box-modal .modal-body").remove();
}
$("#bootstrap-confirm-box-modal-submit").text( yes_label || 'Confirm' );
$("#bootstrap-confirm-box-modal-cancel").text( no_label || 'Cancel' );
$("#bootstrap-confirm-box-modal").modal('show');
}
//Add jQuery :focusable selector
(function($) {
function visible(element) {
return $.expr.filters.visible(element) && !$(element).parents().addBack().filter(function() {
return $.css(this, 'visibility') === 'hidden';
}).length;
}
function focusable(element, isTabIndexNotNaN) {
var map, mapName, img, nodeName = element.nodeName.toLowerCase();
if ('area' === nodeName) {
map = element.parentNode;
mapName = map.name;
if (!element.href || !mapName || map.nodeName.toLowerCase() !== 'map') {
return false;
}
img = $('img[usemap=#' + mapName + ']')[0];
return !!img && visible(img);
}
return (/input|select|textarea|button|object/.test(nodeName) ?
!element.disabled :
'a' === nodeName ?
element.href || isTabIndexNotNaN :
isTabIndexNotNaN) &&
// the element and all of its ancestors must be visible
visible(element);
}
$.extend($.expr[':'], {
focusable: function(element) {
return focusable(element, !isNaN($.attr(element, 'tabindex')));
}
});
})(jQuery);
$("#scrolltocontent").click(function() {
var content = $(".maincontent");
if (content.length > 0) {
$('html,body').animate({
scrollTop: content.first().offset().top
},
'slow');
content.first().find(':focusable').eq(0).focus();
}
});