View | Details | Raw Unified | Return to bug 36566
Collapse All | Expand All

(-)a/koha-tmpl/opac-tmpl/bootstrap/js/amazonimages.js (-6 / +8 lines)
Lines 1-14 Link Here
1
/* global __ */
2
/* exported verify_images */
1
// http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
3
// http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
2
function verify_images() {
4
function verify_images() {
3
	$("img").each(function(i){
5
    $("img").each(function(){
4
	       if ((this.src.indexOf('images.amazon.com') >= 0) || (this.src.indexOf('g-images.amazon.com') >=0) || (this.src.indexOf('syndetics.com') >=0) ) {
6
        if ((this.src.indexOf('images.amazon.com') >= 0) || (this.src.indexOf('g-images.amazon.com') >=0) || (this.src.indexOf('syndetics.com') >=0) ) {
5
            w = this.width;
7
            var w = this.width;
6
            h = this.height;
8
            var h = this.height;
7
            if ((w == 1) || (h == 1)) {
9
            if ((w == 1) || (h == 1)) {
8
                $(this).parent().html("<span class=\"no-image\">"+ __("No cover image available") +"</span>");
10
                $(this).parent().html("<span class=\"no-image\">"+ __("No cover image available") +"</span>");
9
            } else if ((this.complete != null) && (!this.complete)) {
11
            } else if ((this.complete != null) && (!this.complete)) {
10
                $(this).parent().html("<span class=\"no-image\">"+ __("No cover image available") +"</span>");
12
                $(this).parent().html("<span class=\"no-image\">"+ __("No cover image available") +"</span>");
11
            }
13
            }
12
        }
14
        }
13
		});
15
    });
14
		}
16
}
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/bakertaylorimages.js (-6 / +8 lines)
Lines 1-11 Link Here
1
/* global __ */
2
/* exported bt_verify_images */
1
// http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
3
// http://www.oreillynet.com/pub/a/javascript/2003/10/21/amazonhacks.html
2
function bt_verify_images() {
4
function bt_verify_images() {
3
	$("img").each(function(i){
5
    $("img").each(function(){
4
	       if (this.src.indexOf('btol.com') >= 0) {
6
        if (this.src.indexOf('btol.com') >= 0) {
5
            h = this.height;
7
            var h = this.height;
6
            if (h == 20) {
8
            if (h == 20) {
7
                $(this).before("<span class=\"no-image\" style=\"margin-bottom:5px;width:80px;\">"+ __("No cover image available" ) +"</span>");
9
                $(this).before("<span class=\"no-image\" style=\"margin-bottom:5px;width:80px;\">"+ __("No cover image available" ) +"</span>");
8
            }
10
            }
9
		}
11
        }
10
		});
12
    });
11
		}
13
}
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/google-jackets.js (-40 / +41 lines)
Lines 1-3 Link Here
1
/* global __ */
1
if (typeof KOHA == "undefined" || !KOHA) {
2
if (typeof KOHA == "undefined" || !KOHA) {
2
    var KOHA = {};
3
    var KOHA = {};
3
}
4
}
Lines 7-13 if (typeof KOHA == "undefined" || !KOHA) { Link Here
7
 */
8
 */
8
KOHA.Google = {
9
KOHA.Google = {
9
10
10
11
    /**
11
    /**
12
     * Search all:
12
     * Search all:
13
     *    <div title="biblionumber" id="isbn" class="gbs-thumbnail"></div>
13
     *    <div title="biblionumber" id="isbn" class="gbs-thumbnail"></div>
Lines 19-25 KOHA.Google = { Link Here
19
     */
19
     */
20
    GetCoverFromIsbn: function(newWindow) {
20
    GetCoverFromIsbn: function(newWindow) {
21
        var bibkeys = [];
21
        var bibkeys = [];
22
        $("[id^=gbs-thumbnail]").each(function(i) {
22
        $("[id^=gbs-thumbnail]").each(function() {
23
            bibkeys.push($(this).attr("class")); // id=isbn
23
            bibkeys.push($(this).attr("class")); // id=isbn
24
        });
24
        });
25
        bibkeys = bibkeys.join(',');
25
        bibkeys = bibkeys.join(',');
Lines 39-83 KOHA.Google = { Link Here
39
     * and link to preview if div id is gbs-thumbnail-preview
39
     * and link to preview if div id is gbs-thumbnail-preview
40
     */
40
     */
41
    gbsCallBack: function(booksInfo) {
41
    gbsCallBack: function(booksInfo) {
42
         var target = '';
42
        var target = '';
43
         if (this.openInNewWindow) {
43
        if (this.openInNewWindow) {
44
            target = 'target="_blank" rel="noreferrer" ';
44
            target = 'target="_blank" rel="noreferrer" ';
45
         }
45
        }
46
         for (id in booksInfo) {
46
        for (var id in booksInfo) {
47
             var book = booksInfo[id];
47
            var book = booksInfo[id];
48
             $("[id^=gbs-thumbnail]."+book.bib_key).each(function() {
48
            $("[id^=gbs-thumbnail]."+book.bib_key).each(function() {
49
                 if (typeof(book.thumbnail_url) != "undefined") {
49
                if (typeof(book.thumbnail_url) != "undefined") {
50
                     if ( $(this).data('use-data-link') ) {
50
                    var img;
51
                         var a = document.createElement("a");
51
                    if ( $(this).data('use-data-link') ) {
52
                         a.href = book.thumbnail_url;
52
                        var a = document.createElement("a");
53
                         var img = document.createElement("img");
53
                        a.href = book.thumbnail_url;
54
                         img.src = book.thumbnail_url;
54
                        img = document.createElement("img");
55
                         img.setAttribute('data-link', book.info_url);
55
                        img.src = book.thumbnail_url;
56
                         a.append(img)
56
                        img.setAttribute('data-link', book.info_url);
57
                         $(this).empty().append(a);
57
                        a.append(img);
58
                     } else {
58
                        $(this).empty().append(a);
59
                         var img = document.createElement("img");
59
                    } else {
60
                         img.src = book.thumbnail_url;
60
                        img = document.createElement("img");
61
                         $(this).empty().append(img);
61
                        img.src = book.thumbnail_url;
62
                         var re = /^gbs-thumbnail-preview/;
62
                        $(this).empty().append(img);
63
                         if ( re.exec($(this).attr("id")) ) {
63
                        var re = /^gbs-thumbnail-preview/;
64
                             $(this).append(
64
                        if ( re.exec($(this).attr("id")) ) {
65
                                 '<div class="google-books-preview">' +
65
                            $(this).append(
66
                                 '<a '+target+'href="' +
66
                                '<div class="google-books-preview">' +
67
                                 book.info_url +
67
                                '<a '+target+'href="' +
68
                                 '"><img src="' +
68
                                book.info_url +
69
                                 'https://books.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.gif' +
69
                                '"><img src="' +
70
                                 '"></a></div>'
70
                                'https://books.google.com/intl/en/googlebooks/images/gbs_preview_sticker1.gif' +
71
                                 );
71
                                '"></a></div>'
72
                         }
72
                            );
73
                     }
73
                        }
74
                 } else {
74
                    }
75
                     var message = document.createElement("span");
75
                } else {
76
                     $(message).attr("class","no-image");
76
                    var message = document.createElement("span");
77
                     $(message).html(__("No cover image available"));
77
                    $(message).attr("class","no-image");
78
                     $(this).empty().append(message);
78
                    $(message).html(__("No cover image available"));
79
                 }
79
                    $(this).empty().append(message);
80
             });
80
                }
81
            });
81
        }
82
        }
82
        this.done = 1;
83
        this.done = 1;
83
    }
84
    }
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/localcovers.js (-7 / +10 lines)
Lines 1-3 Link Here
1
/* global __ */
1
if (typeof KOHA == "undefined" || !KOHA) {
2
if (typeof KOHA == "undefined" || !KOHA) {
2
    var KOHA = {};
3
    var KOHA = {};
3
}
4
}
Lines 17-24 KOHA.LocalCover = { Link Here
17
     * The result is asynchronously returned by OpenLibrary and catched by
18
     * The result is asynchronously returned by OpenLibrary and catched by
18
     * olCallBack().
19
     * olCallBack().
19
     */
20
     */
20
    GetCoverFromBibnumber: function(uselink) {
21
    GetCoverFromBibnumber: function() {
21
        $("div[id^=local-thumbnail],span[id^=local-thumbnail]").each(function(i) {
22
        $("div[id^=local-thumbnail],span[id^=local-thumbnail]").each(function() {
22
            var mydiv = this;
23
            var mydiv = this;
23
            var message = document.createElement("span");
24
            var message = document.createElement("span");
24
            $(message).attr("class","no-image");
25
            $(message).attr("class","no-image");
Lines 36-51 KOHA.LocalCover = { Link Here
36
                            $(mydiv).children('.no-image').remove();
37
                            $(mydiv).children('.no-image').remove();
37
                        }
38
                        }
38
                        catch(err){
39
                        catch(err){
39
                        };
40
                            // Nothing
41
                        }
40
                    } else if (this.width > 1) { // don't show the silly 1px "no image" img
42
                    } else if (this.width > 1) { // don't show the silly 1px "no image" img
41
                        $(mydiv).empty().append(img);
43
                        $(mydiv).empty().append(img);
42
                        $(mydiv).children('.no-image').remove();
44
                        $(mydiv).children('.no-image').remove();
43
                    }
45
                    }
44
                })
46
                });
45
        });
47
        });
46
    },
48
    },
47
    GetCoverFromItemnumber: function(uselink) {
49
    GetCoverFromItemnumber: function(uselink) {
48
        $("div[class^=local-thumbnail],span[class^=local-thumbnail]").each(function(i) {
50
        $("div[class^=local-thumbnail],span[class^=local-thumbnail]").each(function() {
49
            var mydiv = this;
51
            var mydiv = this;
50
            var message = document.createElement("span");
52
            var message = document.createElement("span");
51
            var imagenumber  = $(mydiv).data("imagenumber");
53
            var imagenumber  = $(mydiv).data("imagenumber");
Lines 65-71 KOHA.LocalCover = { Link Here
65
                            $(mydiv).children('.no-image').remove();
67
                            $(mydiv).children('.no-image').remove();
66
                        }
68
                        }
67
                        catch(err){
69
                        catch(err){
68
                        };
70
                            // Nothing
71
                        }
69
                    } else if (this.width > 1) { // don't show the silly 1px "no image" img
72
                    } else if (this.width > 1) { // don't show the silly 1px "no image" img
70
                        if (uselink) {
73
                        if (uselink) {
71
                            var a = $("<a />").attr('href', '/cgi-bin/koha/opac-imageviewer.pl?imagenumber=' + imagenumber + '&biblionumber=' + biblionumber);
74
                            var a = $("<a />").attr('href', '/cgi-bin/koha/opac-imageviewer.pl?imagenumber=' + imagenumber + '&biblionumber=' + biblionumber);
Lines 76-82 KOHA.LocalCover = { Link Here
76
                        }
79
                        }
77
                        $(mydiv).children('.no-image').remove();
80
                        $(mydiv).children('.no-image').remove();
78
                    }
81
                    }
79
                })
82
                });
80
        });
83
        });
81
    },
84
    },
82
};
85
};
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/openlibrary.js (-119 / +113 lines)
Lines 1-3 Link Here
1
/* global __ */
1
if (typeof KOHA == "undefined" || !KOHA) {
2
if (typeof KOHA == "undefined" || !KOHA) {
2
    var KOHA = {};
3
    var KOHA = {};
3
}
4
}
Lines 18-24 KOHA.OpenLibrary = new function() { Link Here
18
     */
19
     */
19
    this.GetCoverFromIsbn = function() {
20
    this.GetCoverFromIsbn = function() {
20
        var bibkeys = [];
21
        var bibkeys = [];
21
        $("[id^=openlibrary-thumbnail]").each(function(i) {
22
        $("[id^=openlibrary-thumbnail]").each(function() {
22
            bibkeys.push("ISBN:" + $(this).attr("class")); // id=isbn
23
            bibkeys.push("ISBN:" + $(this).attr("class")); // id=isbn
23
        });
24
        });
24
        bibkeys = bibkeys.join(',');
25
        bibkeys = bibkeys.join(',');
Lines 29-58 KOHA.OpenLibrary = new function() { Link Here
29
            "&callback=KOHA.OpenLibrary.olCallBack&jscmd=data");
30
            "&callback=KOHA.OpenLibrary.olCallBack&jscmd=data");
30
        scriptElement.setAttribute("type", "text/javascript");
31
        scriptElement.setAttribute("type", "text/javascript");
31
        document.documentElement.firstChild.appendChild(scriptElement);
32
        document.documentElement.firstChild.appendChild(scriptElement);
32
    }
33
    };
33
34
34
    /**
35
    /**
35
     * Add cover pages <div
36
     * Add cover pages <div
36
     * and link to preview if div id is gbs-thumbnail-preview
37
     * and link to preview if div id is gbs-thumbnail-preview
37
     */
38
     */
38
    this.olCallBack = function(booksInfo) {
39
    this.olCallBack = function(booksInfo) {
39
        for (id in booksInfo) {
40
        for (var id in booksInfo) {
40
            var book = booksInfo[id];
41
            var book = booksInfo[id];
41
            var isbn = id.substring(5);
42
            var isbn = id.substring(5);
43
            var a;
42
            $("[id^=openlibrary-thumbnail]."+isbn).each(function() {
44
            $("[id^=openlibrary-thumbnail]."+isbn).each(function() {
43
                var a = document.createElement("a");
45
                a = document.createElement("a");
44
                a.href = booksInfo.url;
46
                a.href = booksInfo.url;
45
                if (book.cover) {
47
                if (book.cover) {
48
                    var img;
46
                    if ( $(this).data('use-data-link') ) {
49
                    if ( $(this).data('use-data-link') ) {
47
                         var a = document.createElement("a");
50
                        a = document.createElement("a");
48
                         a.href = book.cover.large;
51
                        a.href = book.cover.large;
49
                         var img = document.createElement("img");
52
                        img = document.createElement("img");
50
                         img.src = book.cover.medium;
53
                        img.src = book.cover.medium;
51
                         img.setAttribute('data-link', book.cover.large);
54
                        img.setAttribute('data-link', book.cover.large);
52
                         a.append(img)
55
                        a.append(img);
53
                         $(this).empty().append(a);
56
                        $(this).empty().append(a);
54
                    } else {
57
                    } else {
55
                        var img = document.createElement("img");
58
                        img = document.createElement("img");
56
                        img.src = book.cover.medium;
59
                        img.src = book.cover.medium;
57
                        img.height = '110';
60
                        img.height = '110';
58
                        $(this).append(img);
61
                        $(this).append(img);
Lines 66-72 KOHA.OpenLibrary = new function() { Link Here
66
            });
69
            });
67
        }
70
        }
68
        this.done = 1;
71
        this.done = 1;
69
    }
72
    };
70
73
71
    var search_url = 'https://openlibrary.org/search?';
74
    var search_url = 'https://openlibrary.org/search?';
72
    this.searchUrl = function( q ) {
75
    this.searchUrl = function( q ) {
Lines 85-91 KOHA.OpenLibrary = new function() { Link Here
85
            url: search_url_json,
88
            url: search_url_json,
86
            dataType: 'json',
89
            dataType: 'json',
87
            data: params,
90
            data: params,
88
            error: function( xhr, error ) {
91
            error: function( xhr ) {
89
                try {
92
                try {
90
                    callback( JSON.parse( xhr.responseText ));
93
                    callback( JSON.parse( xhr.responseText ));
91
                } catch ( e ) {
94
                } catch ( e ) {
Lines 110-211 A demonstration use of this script is available here: Link Here
110
http://internetarchive.github.com/read_api_extras/readapi_demo.html
113
http://internetarchive.github.com/read_api_extras/readapi_demo.html
111
*/
114
*/
112
115
113
var ol_readapi_automator =
114
(function () { // open anonymous scope for tidiness
116
(function () { // open anonymous scope for tidiness
115
117
116
// 'constants'
118
    // 'constants'
117
var readapi_bibids = ['isbn', 'lccn', 'oclc', 'olid', 'iaid', 'bibkeys'];
119
    var readapi_bibids = ['isbn', 'lccn', 'oclc', 'olid', 'iaid', 'bibkeys'];
118
var magic_classname = 'ol_readapi_book';
120
    var magic_classname = 'ol_readapi_book';
119
var ol_readapi_books = $("." + magic_classname );
121
    var ol_readapi_books = $("." + magic_classname );
120
var result;
122
    var result;
121
123
122
// added to book divs to correlate with API results
124
    // added to book divs to correlate with API results
123
var magic_bookid = 'ol_bookid';
125
    var magic_bookid = 'ol_bookid';
124
var ol_button_classname = 'ol_readapi_button';
126
    var ol_button_classname = 'ol_readapi_button';
125
127
126
// Find all book divs and concatenate ids from them to create a read
128
    // Find all book divs and concatenate ids from them to create a read
127
// API query url
129
    // API query url
128
function create_query() {
130
    function create_query() {
129
    var q = 'https://openlibrary.org/api/volumes/brief/json/';
131
        var q = 'https://openlibrary.org/api/volumes/brief/json/';
130
132
131
    function add_el(i, el) {
133
        function add_el(i, el) {
132
        // tag with number found so it's easy to discover later
134
            // tag with number found so it's easy to discover later
133
        // (necessary?  just go by index?)
135
            // (necessary?  just go by index?)
134
        // (choose better name?)
136
            // (choose better name?)
135
        $(el).attr(magic_bookid, i);
137
            $(el).attr(magic_bookid, i);
136
138
137
        if (i > 0) {
139
            if (i > 0) {
138
            q += '|';
140
                q += '|';
139
        }
141
            }
140
        q += 'id:' + i;
142
            q += 'id:' + i;
141
143
142
        for (bi in readapi_bibids) {
144
            for (var bi in readapi_bibids) {
143
            bibid = readapi_bibids[bi];
145
                var bibid = readapi_bibids[bi];
144
            if ($(el).attr(bibid)) {
146
                if ($(el).attr(bibid)) {
145
                q += ';' + bibid + ':' + $(el).attr(bibid);
147
                    q += ';' + bibid + ':' + $(el).attr(bibid);
148
                }
146
            }
149
            }
147
        }
150
        }
148
    }
149
150
    $('.' + magic_classname).each(add_el);
151
    return q;
152
}
153
151
154
function make_read_button(bookdata) {
152
        $('.' + magic_classname).each(add_el);
155
    buttons = {
153
        return q;
156
        'full access':
157
        "https://openlibrary.org/images/button-read-open-library.png",
158
        'lendable':
159
        "https://openlibrary.org/images/button-borrow-open-library.png",
160
        'checked out':
161
        "https://openlibrary.org/images/button-checked-out-open-library.png"
162
    };
163
    if (bookdata.items.length == 0) {
164
        return false;
165
    }
154
    }
166
    first = bookdata.items[0];
167
    if (!(first.status in buttons)) {
168
        return false;
169
    }
170
    result = '<a target="_blank" href="' + first.itemURL + '">' +
171
      '<img class="' + ol_button_classname +
172
      '" src="' + buttons[first.status] + '"/></a>';
173
    console.log( result );
174
    return result;
175
}
176
155
177
// Default function for decorating document elements with read API data
156
    function make_read_button(bookdata) {
178
function default_decorate_el_fn(el, bookdata) {
157
        var buttons = {
179
    // Note that 'bookdata' may be undefined, if the Read API call
158
            'full access':
180
    // didn't return results for this book
159
            "https://openlibrary.org/images/button-read-open-library.png",
181
    var decoration;
160
            'lendable':
182
    if (bookdata) {
161
            "https://openlibrary.org/images/button-borrow-open-library.png",
183
        decoration = make_read_button(bookdata);
162
            'checked out':
184
    }
163
            "https://openlibrary.org/images/button-checked-out-open-library.png"
185
    if (decoration) {
164
        };
186
        el.innerHTML += decoration;
165
        if (bookdata.items.length == 0) {
187
        el.style.display = 'block'
166
            return false;
188
    } else {
167
        }
189
        el.style.display = 'none';
168
        var first = bookdata.items[0];
169
        if (!(first.status in buttons)) {
170
            return false;
171
        }
172
        result = '<a target="_blank" href="' + first.itemURL + '">' +
173
        '<img class="' + ol_button_classname +
174
        '" src="' + buttons[first.status] + '"/></a>';
175
        return result;
190
    }
176
    }
191
}
192
177
193
function do_query(q, decorate_el_fn) {
178
    // Default function for decorating document elements with read API data
194
    if (!decorate_el_fn) {
179
    function default_decorate_el_fn(el, bookdata) {
195
        decorate_el_fn = default_decorate_el_fn;
180
        // Note that 'bookdata' may be undefined, if the Read API call
181
        // didn't return results for this book
182
        var decoration;
183
        if (bookdata) {
184
            decoration = make_read_button(bookdata);
185
        }
186
        if (decoration) {
187
            el.innerHTML += decoration;
188
            el.style.display = 'block';
189
        } else {
190
            el.style.display = 'none';
191
        }
196
    }
192
    }
197
    var starttime = (new Date()).getTime();
193
198
194
    function do_query(q, decorate_el_fn) {
199
    // Call a function on each <div class="ol_readapi_book"> element
195
        if (!decorate_el_fn) {
200
    // with the target element and the data found for that element.
196
            decorate_el_fn = default_decorate_el_fn;
201
    // Use decorate_el_fn if supplied, falling back to
197
        }
202
    // default_decorate_el_fn, above.
198
        // Call a function on each <div class="ol_readapi_book"> element
203
    function query_callback(data, textStatus, jqXHR) {
199
        // with the target element and the data found for that element.
204
        var endtime = (new Date()).getTime();
200
        // Use decorate_el_fn if supplied, falling back to
205
        var duration = (endtime - starttime) / 1000;
201
        // default_decorate_el_fn, above.
206
        // console.log('took ' + duration + ' seconds');
202
        function query_callback(data) {
207
203
            $('.' + magic_classname).each(function(i, el) {
208
        $('.' + magic_classname).each(function(i, el) {
209
                var bookid = $(el).attr(magic_bookid);
204
                var bookid = $(el).attr(magic_bookid);
210
                if (bookid && bookid in data) {
205
                if (bookid && bookid in data) {
211
                    decorate_el_fn(el, data[bookid]);
206
                    decorate_el_fn(el, data[bookid]);
Lines 213-241 function do_query(q, decorate_el_fn) { Link Here
213
                    decorate_el_fn(el);
208
                    decorate_el_fn(el);
214
                }
209
                }
215
            });
210
            });
216
    }
211
        }
217
212
218
    // console.log('calling ' + q);
213
        // console.log('calling ' + q);
219
    $.ajax({ url: q,
214
        $.ajax({ url: q,
220
                data: { 'show_all_items': 'true' },
215
            data: { 'show_all_items': 'true' },
221
                dataType: 'jsonp',
216
            dataType: 'jsonp',
222
                success: query_callback
217
            success: query_callback
223
                });
218
        });
224
}
219
    }
225
220
226
if( ol_readapi_books.length > 0 ){
221
    if( ol_readapi_books.length > 0 ){
227
    // Do stuff
222
        // Do stuff
228
    var q = create_query();
223
        var q = create_query();
229
    do_query(q);
224
        do_query(q);
230
225
231
    result = {
226
        result = {
232
        do_query: do_query,
227
            do_query: do_query,
233
        create_query: create_query,
228
            create_query: create_query,
234
        make_read_button: make_read_button
229
            make_read_button: make_read_button
235
    };
230
        };
236
}
231
    }
237
232
238
return result;
233
    return result;
239
})(); // close anonymous scope
234
})(); // close anonymous scope
240
235
241
/*
236
/*
242
- 

Return to bug 36566