Bugzilla – Attachment 169206 Details for
Bug 36566
Correct ESLlint errors in OPAC enhanced content JS
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36566: Correct eslint errors in OPAC enhanced content JS
Bug-36566-Correct-eslint-errors-in-OPAC-enhanced-c.patch (text/plain), 21.54 KB, created by
Kyle M Hall (khall)
on 2024-07-19 11:45:57 UTC
(
hide
)
Description:
Bug 36566: Correct eslint errors in OPAC enhanced content JS
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2024-07-19 11:45:57 UTC
Size:
21.54 KB
patch
obsolete
>From 30cc49bbab07eb77ace9144488712b4eff4e55bd Mon Sep 17 00:00:00 2001 >From: Owen Leonard <oleonard@myacpl.org> >Date: Wed, 10 Apr 2024 11:30:33 +0000 >Subject: [PATCH] Bug 36566: Correct eslint errors in OPAC enhanced content JS > >This patch fixes various eslint errors in enhanced content JS files: > >- Consistent indentation >- Remove variables which are declared but not used >- Add missing semicolons >- Add missing "var" declarations > >To test, apply the patch and clear your browser cache if necessary. > >- Go to Administration -> System preferences and enable these > preferences: > - OPACAmazonCoverImages > - BakerTaylorEnabled > - GoogleJackets > - OPACLocalCoverImages > - OpenLibraryCovers >- Go to the OPAC and confirm that covers from these services appear > correctly in search results and on detail pages. > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > .../opac-tmpl/bootstrap/js/amazonimages.js | 14 +- > .../bootstrap/js/bakertaylorimages.js | 14 +- > .../opac-tmpl/bootstrap/js/google-jackets.js | 81 +++--- > .../opac-tmpl/bootstrap/js/localcovers.js | 17 +- > .../opac-tmpl/bootstrap/js/openlibrary.js | 231 +++++++++--------- > 5 files changed, 180 insertions(+), 177 deletions(-) > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/amazonimages.js b/koha-tmpl/opac-tmpl/bootstrap/js/amazonimages.js >index acb21518f26..8bfa357c54e 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/amazonimages.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/amazonimages.js >@@ -1,14 +1,16 @@ >+/* global __ */ >+/* exported verify_images */ > // http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html > function verify_images() { >- $("img").each(function(i){ >- if ((this.src.indexOf('images.amazon.com') >= 0) || (this.src.indexOf('g-images.amazon.com') >=0) || (this.src.indexOf('syndetics.com') >=0) ) { >- w = this.width; >- h = this.height; >+ $("img").each(function(){ >+ if ((this.src.indexOf('images.amazon.com') >= 0) || (this.src.indexOf('g-images.amazon.com') >=0) || (this.src.indexOf('syndetics.com') >=0) ) { >+ var w = this.width; >+ var h = this.height; > if ((w == 1) || (h == 1)) { > $(this).parent().html("<span class=\"no-image\">"+ __("No cover image available") +"</span>"); > } else if ((this.complete != null) && (!this.complete)) { > $(this).parent().html("<span class=\"no-image\">"+ __("No cover image available") +"</span>"); > } > } >- }); >- } >+ }); >+} >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/bakertaylorimages.js b/koha-tmpl/opac-tmpl/bootstrap/js/bakertaylorimages.js >index cda542e277a..85d8f332449 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/bakertaylorimages.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/bakertaylorimages.js >@@ -1,11 +1,13 @@ >+/* global __ */ >+/* exported bt_verify_images */ > // http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html > function bt_verify_images() { >- $("img").each(function(i){ >- if (this.src.indexOf('btol.com') >= 0) { >- h = this.height; >+ $("img").each(function(){ >+ if (this.src.indexOf('btol.com') >= 0) { >+ var h = this.height; > if (h == 20) { > $(this).before("<span class=\"no-image\" style=\"margin-bottom:5px;width:80px;\">"+ __("No cover image available" ) +"</span>"); > } >- } >- }); >- } >+ } >+ }); >+} >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/google-jackets.js b/koha-tmpl/opac-tmpl/bootstrap/js/google-jackets.js >index c030fff2d20..6e258702e13 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/google-jackets.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/google-jackets.js >@@ -1,3 +1,4 @@ >+/* global __ */ > if (typeof KOHA == "undefined" || !KOHA) { > var KOHA = {}; > } >@@ -7,7 +8,6 @@ if (typeof KOHA == "undefined" || !KOHA) { > */ > KOHA.Google = { > >- > /** > * Search all: > * <div title="biblionumber" id="isbn" class="gbs-thumbnail"></div> >@@ -19,7 +19,7 @@ KOHA.Google = { > */ > GetCoverFromIsbn: function(newWindow) { > var bibkeys = []; >- $("[id^=gbs-thumbnail]").each(function(i) { >+ $("[id^=gbs-thumbnail]").each(function() { > bibkeys.push($(this).attr("class")); // id=isbn > }); > bibkeys = bibkeys.join(','); >@@ -39,45 +39,46 @@ KOHA.Google = { > * and link to preview if div id is gbs-thumbnail-preview > */ > gbsCallBack: function(booksInfo) { >- var target = ''; >- if (this.openInNewWindow) { >+ var target = ''; >+ if (this.openInNewWindow) { > target = 'target="_blank" rel="noreferrer" '; >- } >- for (id in booksInfo) { >- var book = booksInfo[id]; >- $("[id^=gbs-thumbnail]."+book.bib_key).each(function() { >- if (typeof(book.thumbnail_url) != "undefined") { >- if ( $(this).data('use-data-link') ) { >- var a = document.createElement("a"); >- a.href = book.thumbnail_url; >- var img = document.createElement("img"); >- img.src = book.thumbnail_url; >- img.setAttribute('data-link', book.info_url); >- a.append(img) >- $(this).empty().append(a); >- } else { >- var img = document.createElement("img"); >- img.src = book.thumbnail_url; >- $(this).empty().append(img); >- var re = /^gbs-thumbnail-preview/; >- if ( re.exec($(this).attr("id")) ) { >- $(this).append( >- '<div class="google-books-preview">' + >- '<a '+target+'href="' + >- book.info_url + >- '"><img src="' + >- 'https://books.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.gif' + >- '"></a></div>' >- ); >- } >- } >- } else { >- var message = document.createElement("span"); >- $(message).attr("class","no-image"); >- $(message).html(__("No cover image available")); >- $(this).empty().append(message); >- } >- }); >+ } >+ for (var id in booksInfo) { >+ var book = booksInfo[id]; >+ $("[id^=gbs-thumbnail]."+book.bib_key).each(function() { >+ if (typeof(book.thumbnail_url) != "undefined") { >+ var img; >+ if ( $(this).data('use-data-link') ) { >+ var a = document.createElement("a"); >+ a.href = book.thumbnail_url; >+ img = document.createElement("img"); >+ img.src = book.thumbnail_url; >+ img.setAttribute('data-link', book.info_url); >+ a.append(img); >+ $(this).empty().append(a); >+ } else { >+ img = document.createElement("img"); >+ img.src = book.thumbnail_url; >+ $(this).empty().append(img); >+ var re = /^gbs-thumbnail-preview/; >+ if ( re.exec($(this).attr("id")) ) { >+ $(this).append( >+ '<div class="google-books-preview">' + >+ '<a '+target+'href="' + >+ book.info_url + >+ '"><img src="' + >+ 'https://books.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.gif' + >+ '"></a></div>' >+ ); >+ } >+ } >+ } else { >+ var message = document.createElement("span"); >+ $(message).attr("class","no-image"); >+ $(message).html(__("No cover image available")); >+ $(this).empty().append(message); >+ } >+ }); > } > this.done = 1; > } >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js b/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js >index 21ffaf872fe..5b698a71317 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js >@@ -1,3 +1,4 @@ >+/* global __ */ > if (typeof KOHA == "undefined" || !KOHA) { > var KOHA = {}; > } >@@ -17,8 +18,8 @@ KOHA.LocalCover = { > * The result is asynchronously returned by OpenLibrary and catched by > * olCallBack(). > */ >- GetCoverFromBibnumber: function(uselink) { >- $("div[id^=local-thumbnail],span[id^=local-thumbnail]").each(function(i) { >+ GetCoverFromBibnumber: function() { >+ $("div[id^=local-thumbnail],span[id^=local-thumbnail]").each(function() { > var mydiv = this; > var message = document.createElement("span"); > $(message).attr("class","no-image"); >@@ -36,16 +37,17 @@ KOHA.LocalCover = { > $(mydiv).children('.no-image').remove(); > } > catch(err){ >- }; >+ // Nothing >+ } > } else if (this.width > 1) { // don't show the silly 1px "no image" img > $(mydiv).empty().append(img); > $(mydiv).children('.no-image').remove(); > } >- }) >+ }); > }); > }, > GetCoverFromItemnumber: function(uselink) { >- $("div[class^=local-thumbnail],span[class^=local-thumbnail]").each(function(i) { >+ $("div[class^=local-thumbnail],span[class^=local-thumbnail]").each(function() { > var mydiv = this; > var message = document.createElement("span"); > var imagenumber = $(mydiv).data("imagenumber"); >@@ -65,7 +67,8 @@ KOHA.LocalCover = { > $(mydiv).children('.no-image').remove(); > } > catch(err){ >- }; >+ // Nothing >+ } > } else if (this.width > 1) { // don't show the silly 1px "no image" img > if (uselink) { > var a = $("<a />").attr('href', '/cgi-bin/koha/opac-imageviewer.pl?imagenumber=' + imagenumber + '&biblionumber=' + biblionumber); >@@ -76,7 +79,7 @@ KOHA.LocalCover = { > } > $(mydiv).children('.no-image').remove(); > } >- }) >+ }); > }); > }, > }; >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/openlibrary.js b/koha-tmpl/opac-tmpl/bootstrap/js/openlibrary.js >index ee08b535c1f..e05ffd30f33 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/openlibrary.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/openlibrary.js >@@ -1,3 +1,4 @@ >+/* global __ */ > if (typeof KOHA == "undefined" || !KOHA) { > var KOHA = {}; > } >@@ -18,7 +19,7 @@ KOHA.OpenLibrary = new function() { > */ > this.GetCoverFromIsbn = function() { > var bibkeys = []; >- $("[id^=openlibrary-thumbnail]").each(function(i) { >+ $("[id^=openlibrary-thumbnail]").each(function() { > bibkeys.push("ISBN:" + $(this).attr("class")); // id=isbn > }); > bibkeys = bibkeys.join(','); >@@ -29,30 +30,32 @@ KOHA.OpenLibrary = new function() { > "&callback=KOHA.OpenLibrary.olCallBack&jscmd=data"); > scriptElement.setAttribute("type", "text/javascript"); > document.documentElement.firstChild.appendChild(scriptElement); >- } >+ }; > > /** > * Add cover pages <div > * and link to preview if div id is gbs-thumbnail-preview > */ > this.olCallBack = function(booksInfo) { >- for (id in booksInfo) { >+ for (var id in booksInfo) { > var book = booksInfo[id]; > var isbn = id.substring(5); >+ var a; > $("[id^=openlibrary-thumbnail]."+isbn).each(function() { >- var a = document.createElement("a"); >+ a = document.createElement("a"); > a.href = booksInfo.url; > if (book.cover) { >+ var img; > if ( $(this).data('use-data-link') ) { >- var a = document.createElement("a"); >- a.href = book.cover.large; >- var img = document.createElement("img"); >- img.src = book.cover.medium; >- img.setAttribute('data-link', book.cover.large); >- a.append(img) >- $(this).empty().append(a); >+ a = document.createElement("a"); >+ a.href = book.cover.large; >+ img = document.createElement("img"); >+ img.src = book.cover.medium; >+ img.setAttribute('data-link', book.cover.large); >+ a.append(img); >+ $(this).empty().append(a); > } else { >- var img = document.createElement("img"); >+ img = document.createElement("img"); > img.src = book.cover.medium; > img.height = '110'; > $(this).append(img); >@@ -66,7 +69,7 @@ KOHA.OpenLibrary = new function() { > }); > } > this.done = 1; >- } >+ }; > > var search_url = 'https://openlibrary.org/search?'; > this.searchUrl = function( q ) { >@@ -85,7 +88,7 @@ KOHA.OpenLibrary = new function() { > url: search_url_json, > dataType: 'json', > data: params, >- error: function( xhr, error ) { >+ error: function( xhr ) { > try { > callback( JSON.parse( xhr.responseText )); > } catch ( e ) { >@@ -110,102 +113,94 @@ A demonstration use of this script is available here: > http://internetarchive.github.com/read_api_extras/readapi_demo.html > */ > >-var ol_readapi_automator = > (function () { // open anonymous scope for tidiness > >-// 'constants' >-var readapi_bibids = ['isbn', 'lccn', 'oclc', 'olid', 'iaid', 'bibkeys']; >-var magic_classname = 'ol_readapi_book'; >-var ol_readapi_books = $("." + magic_classname ); >-var result; >- >-// added to book divs to correlate with API results >-var magic_bookid = 'ol_bookid'; >-var ol_button_classname = 'ol_readapi_button'; >- >-// Find all book divs and concatenate ids from them to create a read >-// API query url >-function create_query() { >- var q = 'https://openlibrary.org/api/volumes/brief/json/'; >- >- function add_el(i, el) { >- // tag with number found so it's easy to discover later >- // (necessary? just go by index?) >- // (choose better name?) >- $(el).attr(magic_bookid, i); >- >- if (i > 0) { >- q += '|'; >- } >- q += 'id:' + i; >+ // 'constants' >+ var readapi_bibids = ['isbn', 'lccn', 'oclc', 'olid', 'iaid', 'bibkeys']; >+ var magic_classname = 'ol_readapi_book'; >+ var ol_readapi_books = $("." + magic_classname ); >+ var result; >+ >+ // added to book divs to correlate with API results >+ var magic_bookid = 'ol_bookid'; >+ var ol_button_classname = 'ol_readapi_button'; >+ >+ // Find all book divs and concatenate ids from them to create a read >+ // API query url >+ function create_query() { >+ var q = 'https://openlibrary.org/api/volumes/brief/json/'; >+ >+ function add_el(i, el) { >+ // tag with number found so it's easy to discover later >+ // (necessary? just go by index?) >+ // (choose better name?) >+ $(el).attr(magic_bookid, i); >+ >+ if (i > 0) { >+ q += '|'; >+ } >+ q += 'id:' + i; > >- for (bi in readapi_bibids) { >- bibid = readapi_bibids[bi]; >- if ($(el).attr(bibid)) { >- q += ';' + bibid + ':' + $(el).attr(bibid); >+ for (var bi in readapi_bibids) { >+ var bibid = readapi_bibids[bi]; >+ if ($(el).attr(bibid)) { >+ q += ';' + bibid + ':' + $(el).attr(bibid); >+ } > } > } >- } >- >- $('.' + magic_classname).each(add_el); >- return q; >-} > >-function make_read_button(bookdata) { >- buttons = { >- 'full access': >- "https://openlibrary.org/images/button-read-open-library.png", >- 'lendable': >- "https://openlibrary.org/images/button-borrow-open-library.png", >- 'checked out': >- "https://openlibrary.org/images/button-checked-out-open-library.png" >- }; >- if (bookdata.items.length == 0) { >- return false; >+ $('.' + magic_classname).each(add_el); >+ return q; > } >- first = bookdata.items[0]; >- if (!(first.status in buttons)) { >- return false; >- } >- result = '<a target="_blank" href="' + first.itemURL + '">' + >- '<img class="' + ol_button_classname + >- '" src="' + buttons[first.status] + '"/></a>'; >- console.log( result ); >- return result; >-} > >-// Default function for decorating document elements with read API data >-function default_decorate_el_fn(el, bookdata) { >- // Note that 'bookdata' may be undefined, if the Read API call >- // didn't return results for this book >- var decoration; >- if (bookdata) { >- decoration = make_read_button(bookdata); >- } >- if (decoration) { >- el.innerHTML += decoration; >- el.style.display = 'block' >- } else { >- el.style.display = 'none'; >+ function make_read_button(bookdata) { >+ var buttons = { >+ 'full access': >+ "https://openlibrary.org/images/button-read-open-library.png", >+ 'lendable': >+ "https://openlibrary.org/images/button-borrow-open-library.png", >+ 'checked out': >+ "https://openlibrary.org/images/button-checked-out-open-library.png" >+ }; >+ if (bookdata.items.length == 0) { >+ return false; >+ } >+ var first = bookdata.items[0]; >+ if (!(first.status in buttons)) { >+ return false; >+ } >+ result = '<a target="_blank" href="' + first.itemURL + '">' + >+ '<img class="' + ol_button_classname + >+ '" src="' + buttons[first.status] + '"/></a>'; >+ return result; > } >-} > >-function do_query(q, decorate_el_fn) { >- if (!decorate_el_fn) { >- decorate_el_fn = default_decorate_el_fn; >+ // Default function for decorating document elements with read API data >+ function default_decorate_el_fn(el, bookdata) { >+ // Note that 'bookdata' may be undefined, if the Read API call >+ // didn't return results for this book >+ var decoration; >+ if (bookdata) { >+ decoration = make_read_button(bookdata); >+ } >+ if (decoration) { >+ el.innerHTML += decoration; >+ el.style.display = 'block'; >+ } else { >+ el.style.display = 'none'; >+ } > } >- var starttime = (new Date()).getTime(); >- >- // Call a function on each <div class="ol_readapi_book"> element >- // with the target element and the data found for that element. >- // Use decorate_el_fn if supplied, falling back to >- // default_decorate_el_fn, above. >- function query_callback(data, textStatus, jqXHR) { >- var endtime = (new Date()).getTime(); >- var duration = (endtime - starttime) / 1000; >- // console.log('took ' + duration + ' seconds'); >- >- $('.' + magic_classname).each(function(i, el) { >+ >+ function do_query(q, decorate_el_fn) { >+ if (!decorate_el_fn) { >+ decorate_el_fn = default_decorate_el_fn; >+ } >+ // Call a function on each <div class="ol_readapi_book"> element >+ // with the target element and the data found for that element. >+ // Use decorate_el_fn if supplied, falling back to >+ // default_decorate_el_fn, above. >+ function query_callback(data) { >+ $('.' + magic_classname).each(function(i, el) { > var bookid = $(el).attr(magic_bookid); > if (bookid && bookid in data) { > decorate_el_fn(el, data[bookid]); >@@ -213,29 +208,29 @@ function do_query(q, decorate_el_fn) { > decorate_el_fn(el); > } > }); >- } >+ } > >- // console.log('calling ' + q); >- $.ajax({ url: q, >- data: { 'show_all_items': 'true' }, >- dataType: 'jsonp', >- success: query_callback >- }); >-} >+ // console.log('calling ' + q); >+ $.ajax({ url: q, >+ data: { 'show_all_items': 'true' }, >+ dataType: 'jsonp', >+ success: query_callback >+ }); >+ } > >-if( ol_readapi_books.length > 0 ){ >- // Do stuff >- var q = create_query(); >- do_query(q); >+ if( ol_readapi_books.length > 0 ){ >+ // Do stuff >+ var q = create_query(); >+ do_query(q); > >- result = { >- do_query: do_query, >- create_query: create_query, >- make_read_button: make_read_button >- }; >-} >+ result = { >+ do_query: do_query, >+ create_query: create_query, >+ make_read_button: make_read_button >+ }; >+ } > >-return result; >+ return result; > })(); // close anonymous scope > > /* >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36566
:
164608
|
165694
| 169206