Mercurial > hg > digilib-old
changeset 760:f0be4432f515 jquery
primitive plugin extension mechanism - unsure how useful this is
author | hertzhaft |
---|---|
date | Tue, 08 Feb 2011 23:57:39 +0100 |
parents | ccf67eaf97ee |
children | 16778bd2de7c |
files | client/digitallibrary/jquery/jquery-test-full.html client/digitallibrary/jquery/jquery.digilib.js |
diffstat | 2 files changed, 40 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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'); }); </script>
--- 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');