changeset 1185:d39cdbbe21da

first version of digilib client auth plugin. digillib sends event if loading image fails.
author robcast
date Sun, 14 Apr 2013 18:16:33 +0200
parents 72c68a2dc14e
children 7f7e31a4a71e
files webapp/src/main/webapp/jquery/digilib-auth.html webapp/src/main/webapp/jquery/jquery.digilib.auth.js webapp/src/main/webapp/jquery/jquery.digilib.js
diffstat 3 files changed, 173 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /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 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+    <head>
+        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+        <meta name="viewport" content="initial-scale=1.0"/>
+        <title>Digilib jQuery: fullscreen</title>
+
+        <style type="text/css">
+            body {
+                 background: silver;
+            }
+        </style>
+
+        <script type="text/javascript" src="jquery.js"></script>
+        <script type="text/javascript" src="jquery.cookie.js"></script>
+        <script type="text/javascript" src="jquery.digilib.js"></script>
+        <script type="text/javascript" src="jquery.digilib.geometry.js"></script>
+        <script type="text/javascript" src="jquery.digilib.arrows.js"></script>
+        <script type="text/javascript" src="jquery.range.js"></script>
+        <link rel="stylesheet" type="text/css" href="jquery.range.css" />
+        <script type="text/javascript" src="jquery.digilib.buttons.js"></script>
+        <script type="text/javascript" src="jquery.digilib.dialogs.js"></script>
+        <script type="text/javascript" src="jquery.digilib.sliders.js"></script>
+        <script type="text/javascript" src="jquery.digilib.birdseye.js"></script>
+        <script type="text/javascript" src="jquery.digilib.marks.js"></script>
+        <script type="text/javascript" src="jquery.digilib.regions.js"></script>
+        <script type="text/javascript" src="jquery.digilib.auth.js"></script>
+        <link rel="stylesheet" type="text/css" href="jquery.digilib.css" />
+
+        <script type="text/javascript">
+            $(document).ready(function(){
+                var opts = {
+                    interactionMode : 'fullscreen',
+                    showRegionNumbers : true,
+                    authScalerBaseUrl : 'http://localhost:18080/digilib-webapp/authenticated/servlet/Scaler'
+                    };
+                var $div = $('div#digilib');
+                $div.digilib(opts);
+            });
+
+        </script>
+    </head>
+
+    <body>
+        <div id="digilib">
+            <p>digilib doesn't work! Please switch on Javascript or notify the server administrator!</p>
+            <img src="http://digilib.berlios.de/images/digilib-logo-big.png" />
+        </div>
+    </body>
+</html>
+
--- /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
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #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);
--- 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
      * 
      */