# HG changeset patch # User robcast # Date 1365956193 -7200 # Node ID d39cdbbe21da3deb27e79bc2479fcd81260a06c0 # Parent 72c68a2dc14e6f97d8adb24a45b2a47a96a8f22b first version of digilib client auth plugin. digillib sends event if loading image fails. diff -r 72c68a2dc14e -r d39cdbbe21da webapp/src/main/webapp/jquery/digilib-auth.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/src/main/webapp/jquery/digilib-auth.html Sun Apr 14 18:16:33 2013 +0200 @@ -0,0 +1,51 @@ + + + + + + Digilib jQuery: fullscreen + + + + + + + + + + + + + + + + + + + + + + + +
+

digilib doesn't work! Please switch on Javascript or notify the server administrator!

+ +
+ + + diff -r 72c68a2dc14e -r d39cdbbe21da webapp/src/main/webapp/jquery/jquery.digilib.auth.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.auth.js Sun Apr 14 18:16:33 2013 +0200 @@ -0,0 +1,112 @@ +/* + * #%L + * digilib authentication plugin + * %% + * Copyright (C) 2013 MPIWG Berlin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + * Authors: Robert Casties + */ +/** +digilib authentication plugin + */ + +(function($) { + + // plugin object with digilib data + var digilib = null; + + var defaults = { + // URL of Scaler servlet that does authentication + 'authScalerBaseUrl' : null, + // URL of Scaler servlet that does not do authentication + 'unauthScalerBaseUrl' : null + }; + + var actions = { + // action code goes here + doStub : function (data, param) { + var settings = data.settings; + console.log("doStub"); + // do some useful stuff ... + } + }; + + var handleUnpack = function (evt) { + console.debug("auth: handleUnpack"); + var data = this; + var flags = data.scalerFlags; + // remove other error flags + for (f in flags) { + if (f.substr(1, 3) === "err") { + delete flags[f]; + } + } + // set error code flag + flags['errcode'] = 'errcode'; + }; + + var handleImgerror = function (evt) { + console.debug("auth: handleImgerror"); + var data = this; + var settings = data.settings; + if (settings.scalerBaseUrl != settings.authScalerBaseUrl && settings.authScalerBaseUrl != null) { + // not using authScalerBaseUrl -- change + console.debug("auth: switching to authenticated scaler."); + settings.noauthScalerBaseUrl = settings.scalerBaseUrl; + settings.scalerBaseUrl = settings.authScalerBaseUrl; + digilib.fn.redisplay(data); + } + }; + + // plugin installation called by digilib on plugin object. + var install = function(plugin) { + digilib = plugin; + console.debug('installing auth plugin. digilib:', digilib); + // add defaults, actions, buttons + $.extend(digilib.defaults, defaults); + $.extend(digilib.actions, actions); + //$.extend(digilib.buttons, buttons); + }; + + // plugin initialization + var init = function (data) { + console.debug('initialising auth plugin. data:', data); + var $data = $(data); + // install event handler + $data.bind('unpack', handleUnpack); + $data.bind('imgerror', handleImgerror); + }; + + + // plugin object with name and init + // shared objects filled by digilib on registration + var plugin = { + name : 'auth', + install : install, + init : init, + buttons : {}, + actions : {}, + fn : {}, + plugins : {} + }; + + if ($.fn.digilib == null) { + $.error("jquery.digilib.auth must be loaded after jquery.digilib!"); + } else { + $.fn.digilib('plugin', plugin); + } +})(jQuery); diff -r 72c68a2dc14e -r d39cdbbe21da webapp/src/main/webapp/jquery/jquery.digilib.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.js Sun Apr 14 18:14:27 2013 +0200 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.js Sun Apr 14 18:16:33 2013 +0200 @@ -42,12 +42,12 @@ var defaults = { // version of this script - 'version' : 'jquery.digilib.js 2.1.13', + 'version' : 'jquery.digilib.js 2.2.0a', // logo url 'logoUrl' : 'img/digilib-logo-text1.png', // homepage url (behind logo) 'homeUrl' : 'http://digilib.berlios.de', - // base URL to digilib (e.g. 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary') + // base URL to digilib webapp (e.g. 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary') 'digilibBaseUrl' : null, // path to digilib frontend page (inside digilibBaseUrl) 'digilibFrontendPath' : '/jquery/digilib.html', @@ -1081,9 +1081,9 @@ // set busy cursor $('body').css('cursor','progress'); data.$scaler.css('cursor', 'progress'); - // set up image load handler before setting the src attribute (IE bug) - $img.load(scalerImgLoadedHandler(data)); - $img.error(function () {console.error("error loading scaler image");}); + // set up image load handler before setting the src attribute + $img.on('load', scalerImgLoadedHandler(data)); + $img.on('error', function (evt, a, b) { handleScalerImgError(data, evt, a, b); }); $img.attr('src', scalerUrl); }; @@ -1206,6 +1206,11 @@ }; }; + var handleScalerImgError = function (data, evt, a, b) { + console.error("error loading scaler image:", evt); + $(data).trigger('imgerror'); + }; + /** handle imageInfo loaded event * */