# HG changeset patch # User hertzhaft # Date 1297205859 -3600 # Node ID f0be4432f51523accf64edda4116a434968d8280 # Parent ccf67eaf97ee44f0b65edd745f4837399aa1b6df primitive plugin extension mechanism - unsure how useful this is diff -r ccf67eaf97ee -r f0be4432f515 client/digitallibrary/jquery/jquery-test-full.html --- a/client/digitallibrary/jquery/jquery-test-full.html Sun Feb 06 22:17:41 2011 +0100 +++ b/client/digitallibrary/jquery/jquery-test-full.html Tue Feb 08 23:57:39 2011 +0100 @@ -36,7 +36,17 @@ interactionMode : 'fullscreen', scalerBaseUrl : 'http://digilib.biblhertz.it/digilib04/servlet/Scaler' }; - $('div.digilib').digilib(opts); + var $div = $('div.digilib'); + $div.digilib(opts); + var obj = { + 'initExtension' : function() { + var settings = $(this).data('digilib').settings; + console.debug('initExtension:', this, 'settings:', settings); + }, + 'options' : { 'test' : 'content of option "test"' }, + }; + $div.digilib('extendPlugin', obj); + $div.digilib('initExtension'); }); diff -r ccf67eaf97ee -r f0be4432f515 client/digitallibrary/jquery/jquery.digilib.js --- a/client/digitallibrary/jquery/jquery.digilib.js Sun Feb 06 22:17:41 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.js Tue Feb 08 23:57:39 2011 +0100 @@ -585,11 +585,12 @@ redisplay(data); } }, - + // calibrate (only faking) calibrate : function (data) { getImageInfo(data); - } + }, + }; // returns parameters from page url @@ -1121,13 +1122,13 @@ return function () { var $img = $(this); var $scaler = data.$scaler; - // create Transform from current area and picsize + // create Transform from current zoomArea and image size data.imgTrafo = getImgTrafo($img, data.zoomArea, data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir); - console.debug("imgTrafo=", data.imgTrafo); + // console.debug("imgTrafo=", data.imgTrafo); + var imgRect = geom.rectangle($img); + // console.debug("imgrect=", imgRect); // adjust scaler div size - var imgRect = geom.rectangle($img); - console.debug("imgrect=", imgRect); imgRect.adjustDiv($scaler); // show image in case it was hidden (for example in zoomDrag) $img.css('visibility', 'visible'); @@ -1580,8 +1581,28 @@ } // hook plugin into jquery - $.fn.digilib = function(action) { - if (actions[action]) { + $.fn.digilib = function(action, obj) { + // plugin extension mechanism + if (action === 'extendPlugin') { + // for each digilib $elem extend data.settings with obj.options + if (obj.options) { + this.each(function() { + var $elem = $(this); + // console.debug('extending:', $elem); + var data = $elem.data('digilib'); + if (!data) { + return console.log('cannot extend digilib plugin, element not initialised!'); + } + var settings = data.settings; + $.extend(settings, obj.options); + // console.log('settings:', settings); + }); + } + delete(obj.options); + // extend the plugin actions (to make this useful, + // maybe we need to expose some more internal functions) + $.extend(actions, obj); + } else if (actions[action]) { // call action on this with the remaining arguments (inserting data as first argument) var $elem = $(this); var data = $elem.data('digilib');