diff client/digitallibrary/jquery/jquery.digilib.js @ 786:868c2e795aca jquery

new plugin architecture.
author robcast
date Thu, 17 Feb 2011 14:32:48 +0100
parents b9a75079aece
children b322f553f92e
line wrap: on
line diff
--- a/client/digitallibrary/jquery/jquery.digilib.js	Wed Feb 16 14:31:50 2011 +0100
+++ b/client/digitallibrary/jquery/jquery.digilib.js	Thu Feb 17 14:32:48 2011 +0100
@@ -251,7 +251,10 @@
         'scalerInset' : 10
         };
 
-    // affine geometry classes
+    // list of plugins
+    var plugins = {};
+    
+    // affine geometry plugin stub
     var geom;
 
     var FULL_AREA;
@@ -259,12 +262,12 @@
     var actions = {
         // init: digilib initialization
         init : function(options) {
-            // import geometry classes TODO: move to general plugin mechanism?
-            if ($.fn.digilib.geometry == null) {
-                console.error("You should use jquery.digilib.geometry");
+            // import geometry classes
+            if (plugins.geometry == null) {
+                $.error("jquery.digilib.geometry plugin not found!");
                 geom = dlGeometry();
             } else {
-                geom = $.fn.digilib.geometry;
+                geom = plugins.geometry.init();
             }
             FULL_AREA  = geom.rectangle(0, 0, 1, 1);
             
@@ -348,6 +351,10 @@
                         }
                     }
                 }
+                // initialise plugins
+                for (p in plugins) {
+                    plugins[p].init(data);
+                }
                 // get image info from server if needed
                 if (data.scaleMode === 'pixel' || data.scaleMode === 'size') {
                     loadImageInfo(data, updateDisplay); // updateDisplay(data) on completion
@@ -1763,8 +1770,13 @@
     // hook plugin into jquery
     $.fn.digilib = function (action) {
         // plugin extension mechanism
-        if (action === 'extendPlugin') {
-            // for each digilib $elem extend data.settings with obj.options
+        if (action === 'plugin') {
+            var plugin = arguments[1];
+            // each plugin needs a name
+            if (plugin.name != null) {
+                plugins[plugin.name] = plugin;
+            }
+            /* for each digilib $elem extend data.settings with obj.options
             // TODO: couldn't other plugins just access $elem.data('digilib')?
             if (obj.options) {
                 this.each(function() {
@@ -1782,7 +1794,7 @@
                 }
             // extend the plugin actions (to make this useful, 
             // maybe we need to expose some more internal functions)
-            $.extend(actions, obj);
+            $.extend(actions, obj); */
         } else if (actions[action]) {
             // call action on this with the remaining arguments (inserting data as first argument)
             var $elem = $(this);