changeset 1051:ad769aaea759

adapt digilibSVG plugin to new plugin architecture
author hertzhaft
date Mon, 26 Mar 2012 09:15:26 +0200
parents 301ef9bf1965
children 0d2491acfe70
files webapp/src/main/webapp/jquery/jquery-test-svg.html webapp/src/main/webapp/jquery/jquery.digilib.dialogs.js webapp/src/main/webapp/jquery/svg/jquery.digilibSVG.js
diffstat 3 files changed, 101 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery-test-svg.html	Mon Mar 26 08:18:40 2012 +0200
+++ b/webapp/src/main/webapp/jquery/jquery-test-svg.html	Mon Mar 26 09:15:26 2012 +0200
@@ -4,39 +4,41 @@
     <head>
         <title>jQuery.digilibSVG test</title>
 
-        <style type="text/css">
-        </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>
+        <link rel="stylesheet" type="text/css" href="jquery.digilib.css" />
         <script type="text/javascript" src="svg/jquery.svg.js"></script>
         <script type="text/javascript" src="svg/jquery.digilibSVG.js"></script>
-        <link rel="stylesheet" type="text/css" href="jquery.digilib.css" />
         <link rel="stylesheet" type="text/css" href="svg/jquery.digilibSVG.css" />
 
-
         <script type="text/javascript">
             $(document).ready(function(){
                 var opts = {
                     interactionMode : 'fullscreen',
-                    scalerBaseUrl : 'http://digilib.biblhertz.it/digilib04/servlet/Scaler'
+                    showRegionNumbers : true
                     };
-                var $div = $('div.digilib');
+                var $div = $('div#digilib');
                 $div.digilib(opts);
-                var svgopts = {};
-                $div.digilibSVG(svgopts);
             });
-
         </script>
     </head>
 
     <body>
 
-        <div id="digilib-1" class="digilib">
-            <img src="http://digilib.biblhertz.it/digilib04/servlet/Scaler?dw=200&amp;dh=200&amp;fn=/digisprint/jquery/FransHals-WillemVanHeythuysen" />
+        <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>
         <div id="debug">DEBUG</div>
     </body>
--- a/webapp/src/main/webapp/jquery/jquery.digilib.dialogs.js	Mon Mar 26 08:18:40 2012 +0200
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.dialogs.js	Mon Mar 26 09:15:26 2012 +0200
@@ -69,7 +69,6 @@
         var $error = $calDiv.find('#'+cssPrefix+'calibrationError');
         var handler = function(event) {
             // var _data = data;
-            console.log("HANDLER calibration");
             if (event.keyCode == 27 || event.target.id == cssPrefix+'calibrationCancel') {
                 fn.withdraw($calDiv);
                 return false;
--- a/webapp/src/main/webapp/jquery/svg/jquery.digilibSVG.js	Mon Mar 26 08:18:40 2012 +0200
+++ b/webapp/src/main/webapp/jquery/svg/jquery.digilibSVG.js	Mon Mar 26 09:15:26 2012 +0200
@@ -36,10 +36,13 @@
 }
 
 (function($) {
-    console.debug('installing jquery.digilibSVG');
 
-    var pluginName = 'digilibSVG';
-    var geom;
+    // plugin object with digilib data
+    var digilib = null;
+    // the functions made available by digilib
+    var fn = null;
+    // affine geometry plugin
+    var geom = null;
 
     var defaults = {
         // choice of colors offered by toolbar
@@ -99,6 +102,46 @@
         gridCopies : 10
         };
 
+    var actions = {
+        "test" : function(options) {
+            var onLoadXML = function (xml) {
+                settings.xml = xml;
+                settings.$toolBar = setupToolBar(settings);
+                $digilib.each(function() {
+                    var $elem = $(this);
+                    $elem.data(pluginName, settings);
+                    });
+                };
+            var onLoadScalerImg = function () {
+                var $svgDiv = $('<div id="svg" />');
+                $('body').append($svgDiv);
+                // size SVG div like scaler img
+                var $scalerImg = $digilib.find('img.pic');
+                var scalerImgRect = geom.rectangle($scalerImg);
+                scalerImgRect.adjustDiv($svgDiv);
+                console.debug('$svgDiv', scalerImgRect);
+                var $svg = $svgDiv.svg({
+                        'onLoad' : drawInitial
+                    });
+                settings.$elem = $digilib;
+                settings.$svgDiv = $svgDiv;
+                settings.$svg = $svg;
+                // set SVG data 
+                $svg.data('digilib', data);
+                $svg.data(pluginName, settings);
+                };
+            // fetch the XML measuring unit list
+            $.ajax({
+                type : "GET",
+                url : "svg/archimedes.xml",
+                dataType : "xml",
+                success : onLoadXML
+                });
+            data.$img.load(onLoadScalerImg);
+            return this;
+            }
+        };
+
     // setup a div for accessing the main SVG functionality
     var setupToolBar = function(settings) {
         var $toolBar = $('<div id="svg-toolbar"/>');
@@ -174,72 +217,48 @@
             {stroke: 'red', strokeWidth: 2});
         };
 
-    var actions = {
-        "init" : function(options) {
-            var $digilib = this;
-            var data = $digilib.data('digilib');
-            var plugins = data.plugins;
-            geom = plugins.geometry.init();
-            var settings = $.extend({}, defaults, options);
-            // prepare the AJAX callback
-            // TODO: return unless interactiveMode === 'fullscreen'?
-            var onLoadXML = function (xml) {
-                settings.xml = xml;
-                settings.$toolBar = setupToolBar(settings);
-                $digilib.each(function() {
-                    var $elem = $(this);
-                    $elem.data(pluginName, settings);
-                    });
-                };
-            var onLoadScalerImg = function () {
-                var $svgDiv = $('<div id="svg" />');
-                $('body').append($svgDiv);
-                // size SVG div like scaler img
-                var $scalerImg = $digilib.find('img.pic');
-                var scalerImgRect = geom.rectangle($scalerImg);
-                scalerImgRect.adjustDiv($svgDiv);
-                console.debug('$svgDiv', scalerImgRect);
-                var $svg = $svgDiv.svg({
-                        'onLoad' : drawInitial
-                    });
-                settings.$elem = $digilib;
-                settings.$svgDiv = $svgDiv;
-                settings.$svg = $svg;
-                // set SVG data 
-                $svg.data('digilib', data);
-                $svg.data(pluginName, settings);
-                };
-            // fetch the XML measuring unit list
-            $.ajax({
-                type : "GET",
-                url : "svg/archimedes.xml",
-                dataType : "xml",
-                success : onLoadXML
-                });
-            data.$img.load(onLoadScalerImg);
-            return this;
-            }
-        };
+    // plugin installation called by digilib on plugin object.
+    var install = function (plugin) {
+        digilib = plugin;
+        console.debug('installing digilibSVG plugin. digilib:', digilib);
+        fn = digilib.fn;
+        // import geometry classes
+        geom = fn.geometry;
+        // add defaults, actions, buttons
+        $.extend(true, digilib.defaults, defaults); // make deep copy
+        $.extend(digilib.actions, actions);
+        // export functions
+        // fn.test = test;
+    };
 
- // hook plugin into jquery
-    $.fn[pluginName] = function(action) {
-        if (actions[action]) {
-            // call action on this with the remaining arguments (inserting data as first argument)
-            var $elem = $(this);
-            var data = $elem.data('digilib');
-            if (!data) {
-                return $.error(pluginName + ' action ' + action + ' needs a digilib element');
-                }
-            var args = Array.prototype.slice.call(arguments, 1);
-            args.unshift(data);
-            return actions[action].apply(this, args);
-        } else if (typeof(action) === 'object' || !action) {
-            // call init on this
-            return actions.init.apply(this, arguments);
-        } else {
-            $.error('action ' + action + ' does not exist on jQuery.' + pluginName);
-        }
+    // plugin initialization
+    var init = function (data) {
+        console.debug('initialising digilibSVG plugin. data:', data);
+        var $data = $(data);
+        $data.bind('setup', handleSetup);
     };
 
+    var handleSetup = function (evt) {
+        console.debug("digilibSVG: handleSetup");
+        var data = this;
+        var settings = data.settings;
+    };
+
+    // plugin object with name and init
+    // shared objects filled by digilib on registration
+    var plugin = {
+            name : 'digilibSVG',
+            install : install,
+            init : init,
+            buttons : {},
+            actions : {},
+            fn : {},
+            plugins : {}
+    };
+
+    if ($.fn.digilib == null) {
+        $.error("jquery.digilibSVG must be loaded after jquery.digilib!");
+    } else {
+        $.fn.digilib('plugin', plugin);
+    }
 })(jQuery);
-