1 /* global enquire readCookie updateBasket delCookie */
3 // if the class is already set, the font has already been loaded
4 if( w.document.documentElement.className.indexOf( "fonts-loaded" ) > -1 ){
7 var PrimaryFont = new w.FontFaceObserver( "NotoSans", {
11 PrimaryFont.load(null, 5000).then(function(){
12 w.document.documentElement.className += " fonts-loaded";
14 console.log("Failed");
18 // http://stackoverflow.com/questions/1038746/equivalent-of-string-format-in-jquery/5341855#5341855
19 String.prototype.format = function() { return formatstr(this, arguments) }
20 function formatstr(str, col) {
21 col = typeof col === 'object' ? col : Array.prototype.slice.call(arguments, 1);
23 return str.replace(/%%|%s|%(\d+)\$s/g, function (m, n) {
24 if (m == "%%") { return "%"; }
25 if (m == "%s") { return col[idx++]; }
30 function confirmDelete(message) {
31 return (confirm(message) ? true : false);
34 function Dopop(link) {
35 newin=window.open(link,'popup','width=500,height=400,toolbar=false,scrollbars=yes,resizable=yes');
38 jQuery.fn.preventDoubleFormSubmit = function() {
39 jQuery(this).submit(function() {
40 if (this.beenSubmitted)
43 this.beenSubmitted = true;
47 function prefixOf (s, tok) {
48 var index = s.indexOf(tok);
49 return s.substring(0, index);
51 function suffixOf (s, tok) {
52 var index = s.indexOf(tok);
53 return s.substring(index + 1);
56 $("body").on("keypress", ".noEnterSubmit", function(e){
60 // http://jennifermadden.com/javascript/stringEnterKeyDetector.html
61 function checkEnter(e){ //e is event object passed from function invocation
62 var characterCode; // literal character code will be stored in this variable
63 if(e && e.which){ //if which property of event object is supported (NN4)
64 characterCode = e.which; //character code is contained in NN4's which property
66 characterCode = e.keyCode; //character code is contained in IE's keyCode property
68 if( characterCode == 13 //if generated character code is equal to ascii 13 (if enter key)
69 && e.target.nodeName == "INPUT"
70 && e.target.type != "submit" // Allow enter to submit using the submit button
78 // Adapted from https://gist.github.com/jnormore/7418776
79 function confirmModal(message, title, yes_label, no_label, callback) {
80 $("#bootstrap-confirm-box-modal").data('confirm-yes', false);
81 if($("#bootstrap-confirm-box-modal").length == 0) {
82 $("body").append('<div id="bootstrap-confirm-box-modal" tabindex="-1" role="dialog" aria-hidden="true" class="modal">\
83 <div class="modal-dialog">\
84 <div class="modal-content">\
85 <div class="modal-header" style="min-height:40px;">\
86 <h4 class="modal-title"></h4>\
87 <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close">\
88 <span aria-hidden="true">×</span>\
91 <div class="modal-body"><p></p></div>\
92 <div class="modal-footer">\
93 <a href="#" id="bootstrap-confirm-box-modal-submit" class="btn btn-danger"><i class="fa fa-check" aria-hidden="true"></i></a>\
94 <a href="#" id="bootstrap-confirm-box-modal-cancel" data-dismiss="modal" class="btn btn-secondary"><i class="fa fa-remove" aria-hidden="true"></i></a>\
99 $("#bootstrap-confirm-box-modal-submit").on('click', function () {
100 $("#bootstrap-confirm-box-modal").data('confirm-yes', true);
101 $("#bootstrap-confirm-box-modal").modal('hide');
104 $("#bootstrap-confirm-box-modal").on('hide.bs.modal', function () {
105 if(callback) callback($("#bootstrap-confirm-box-modal").data('confirm-yes'));
109 $("#bootstrap-confirm-box-modal .modal-header h4").text( title || "" );
110 if( message && message != "" ){
111 $("#bootstrap-confirm-box-modal .modal-body").html( message || "" );
113 $("#bootstrap-confirm-box-modal .modal-body").remove();
115 $("#bootstrap-confirm-box-modal-submit").text( yes_label || 'Confirm' );
116 $("#bootstrap-confirm-box-modal-cancel").text( no_label || 'Cancel' );
117 $("#bootstrap-confirm-box-modal").modal('show');
120 //Add jQuery :focusable selector
122 function visible(element) {
123 return $.expr.filters.visible(element) && !$(element).parents().addBack().filter(function() {
124 return $.css(this, 'visibility') === 'hidden';
128 function focusable(element, isTabIndexNotNaN) {
129 var map, mapName, img, nodeName = element.nodeName.toLowerCase();
130 if ('area' === nodeName) {
131 map = element.parentNode;
133 if (!element.href || !mapName || map.nodeName.toLowerCase() !== 'map') {
136 img = $('img[usemap=#' + mapName + ']')[0];
137 return !!img && visible(img);
139 return (/input|select|textarea|button|object/.test(nodeName) ?
142 element.href || isTabIndexNotNaN :
144 // the element and all of its ancestors must be visible
148 $.extend($.expr[':'], {
149 focusable: function(element) {
150 return focusable(element, !isNaN($.attr(element, 'tabindex')));
155 enquire.register("screen and (max-width:608px)", {
157 if($("body.scrollto").length > 0){
158 window.scrollTo( 0, $(".maincontent").offset().top );
163 enquire.register("screen and (min-width:992px)", {
167 unmatch : function() {
172 function facetMenu( action ){
173 if( action == "show" ){
174 $(".menu-collapse-toggle").off("click", facetHandler );
175 $(".menu-collapse").show();
177 $(".menu-collapse-toggle").on("click", facetHandler ).removeClass("menu-open");
178 $(".menu-collapse").hide();
182 var facetHandler = function(e){
184 $(this).toggleClass("menu-open");
185 $(".menu-collapse").toggle();
188 $(document).ready(function(){
189 $("html").removeClass("no-js").addClass("js");
190 $(".close").click(function(){
194 $(".js-show").show();
195 $(".js-hide").hide();
197 if( $(window).width() < 991 ){
201 // clear the basket when user logs out
202 $("#logout").click(function(){
203 var nameCookie = "bib_list";
204 var valCookie = readCookie(nameCookie);
205 if (valCookie) { // basket has contents
206 updateBasket(0,null);
207 delCookie(nameCookie);
214 $(".loginModal-trigger").on("click",function(e){
216 $("#loginModal").modal("show");
218 $("#loginModal").on("shown.bs.modal", function(){
219 $("#muserid").focus();
222 $("#scrolltocontent").click(function() {
223 var content = $(".maincontent");
224 if (content.length > 0) {
225 $('html,body').animate({
226 scrollTop: content.first().offset().top
229 content.first().find(':focusable').eq(0).focus();