Mercurial > hg > digilib-old
changeset 799:12f790cb30de jquery
started to adapt regions plugin to new plugin mechanism
author | hertzhaft |
---|---|
date | Fri, 18 Feb 2011 23:13:26 +0100 |
parents | b07d1824ca2a |
children | 65e70c03870b 225054177f67 |
files | client/digitallibrary/jquery/jquery.digilib.birdseye.js client/digitallibrary/jquery/jquery.digilib.js client/digitallibrary/jquery/jquery.digilib.regions.js |
diffstat | 3 files changed, 112 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/client/digitallibrary/jquery/jquery.digilib.birdseye.js Fri Feb 18 20:09:15 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.birdseye.js Fri Feb 18 23:13:26 2011 +0100 @@ -1,4 +1,5 @@ -/** required digilib geometry plugin +/** +digilib bird's eye view plugin */ (function($) { @@ -25,7 +26,7 @@ // parameters used by bird's eye div 'birdDivParams' : ['fn','pn','dw','dh'] }; - + var actions = { // event handler: toggles the visibility of the bird's eye window showBirdDiv : function (data, show) { @@ -40,8 +41,8 @@ updateBirdDiv(data); digilib.fn.storeOptions(data); } - }; - + }; + // plugin installation called by digilib on plugin object. var install = function(digilib) { // import geometry classes @@ -67,7 +68,7 @@ $data.bind('redisplay', handleRedisplay); $data.bind('dragZoom', handleDragZoom); }; - + var handleSetup = function (evt) { console.debug("birdseye: handleSetup"); @@ -78,7 +79,7 @@ data.$birdDiv.show(); } }; - + var handleUpdate = function (evt) { console.debug("birdseye: handleUpdate"); data = this; @@ -87,7 +88,7 @@ setupBirdDrag(data); } }; - + var handleRedisplay = function (evt) { console.debug("birdseye: handleRedisplay"); data = this; @@ -95,7 +96,7 @@ updateBirdDiv(data); } }; - + var handleDragZoom = function (evt, zoomArea) { //console.debug("birdseye: handleDragZoom za="+zoomArea); data = this; @@ -103,7 +104,7 @@ setBirdZoom(data, zoomArea); } }; - + // returns URL for bird's eye view image var getBirdImgUrl = function (data) { var settings = data.settings; @@ -313,7 +314,7 @@ fn : {}, plugins : {} }; - + if ($.fn.digilib == null) { $.error("jquery.digilib.birdview must be loaded after jquery.digilib!"); } else {
--- a/client/digitallibrary/jquery/jquery.digilib.js Fri Feb 18 20:09:15 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.js Fri Feb 18 23:13:26 2011 +0100 @@ -1596,9 +1596,9 @@ getBorderWidth : getBorderWidth }; - // hook plugin into jquery + // hook digilib plugin into jquery $.fn.digilib = function (action) { - // plugin extension mechanism + // plugin extension mechanism, called when the plugins' code is read if (action === 'plugin') { var plugin = arguments[1]; // each plugin needs a name @@ -1615,7 +1615,7 @@ plugin.install(plugin); } } - // initialisation of plugins done later + // plugins will be initialised when action.init is called } else if (actions[action]) { // call action on this with the remaining arguments (inserting data as first argument) var $elem = $(this); @@ -1624,7 +1624,7 @@ args.unshift(data); return actions[action].apply(this, args); } else if (typeof action === 'object' || !action) { - // call init on this + // call init on the digilib jQuery object return actions.init.apply(this, arguments); } else { $.error('action ' + action + ' does not exist on jQuery.digilib');
--- a/client/digitallibrary/jquery/jquery.digilib.regions.js Fri Feb 18 20:09:15 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.regions.js Fri Feb 18 23:13:26 2011 +0100 @@ -15,8 +15,11 @@ var data; var buttons; var fn; + // affine geometry plugin stub var geom; + var FULL_AREA; + var buttons = { addregion : { onclick : "setRegion", @@ -39,25 +42,33 @@ icon : "regioninfo.png" } }; - var regionSet = ['addregion', 'delregion', 'regions', 'regioninfo', 'lessoptions']; + + var defaults = { + // are regions shown? + 'isRegionVisible' : true, + // buttonset of this plugin + 'regionSet' : ['addregion', 'delregion', 'regions', 'regioninfo', 'lessoptions'], + // array of defined regions + 'regions' : [] + }; var actions = { // define a region interactively with two clicked points "setRegion" : function(data) { - $elem = data.$elem; - $scaler = data.$scaler; + var $elem = data.$elem; + var $scaler = data.$scaler; + var picRect = geom.rectangle($scaler); var pt1, pt2; - var $regionDiv = $('<div class="region" style="display:none"/>'); - $regionDiv.attr("id", "region" + data.regions.length); - $elem.append($regionDiv); - var picRect = geom.rectangle($scaler); + // TODO: temporary rectangle only, pass values to "addRegion" factory + var $tempDiv = $('<div class="region" style="display:none"/>'); + $elem.append($tempDiv); var regionStart = function (evt) { pt1 = geom.position(evt); // setup and show zoom div - pt1.adjustDiv($regionDiv); - $regionDiv.width(0).height(0); - $regionDiv.show(); + pt1.adjustDiv($tempDiv); + $tempDiv.width(0).height(0); + $tempDiv.show(); // register events $elem.bind("mousemove.dlRegion", regionMove); $elem.bind("mouseup.dlRegion", regionEnd); @@ -70,7 +81,7 @@ var rect = geom.rectangle(pt1, pt2); rect.clipTo(picRect); // update zoom div - rect.adjustDiv($regionDiv); + rect.adjustDiv($tempDiv); return false; }; @@ -85,8 +96,9 @@ $elem.unbind("mouseup.dlRegion", regionEnd); // clip and transform clickRect.clipTo(picRect); - clickRect.adjustDiv($regionDiv); - data.regions.push($regionDiv); + clickRect.adjustDiv($tempDiv); + $tempDiv.remove(); + data.settings.regions.push(clickRect); // fn.redisplay(data); return false; }; @@ -100,7 +112,7 @@ // remove the last added region "removeRegion" : function (data) { - var $regionDiv = data.regions.pop(); + var $regionDiv = data.settings.regions.pop(); $regionDiv.remove(); // fn.redisplay(data); }, @@ -170,16 +182,57 @@ } }; - // export constructor functions to digilib plugin - var init = function (digilibdata) { - console.log('initialising regions plugin. data:', digilibdata); - data = digilibdata; - data.regions = []; - // setup geometry object - geom = data.plugins.geometry.init(); - // add buttons and actions from this plugin - $.extend(this.buttons, buttons); - $.extend(this.actions, actions); + var handleSetup = function (evt) { + console.debug("regions: handleSetup"); + data = this; +// if (data.settings.isBirdDivVisible) { +// setupBirdDiv(data); +// data.$birdDiv.show(); +// } + }; + + var handleUpdate = function (evt) { + console.debug("regions: handleUpdate"); + data = this; +// if (data.settings.isBirdDivVisible) { +// renderBirdArea(data); +// setupBirdDrag(data); +// } + }; + + var handleRedisplay = function (evt) { + console.debug("regions: handleRedisplay"); + data = this; +// if (data.settings.isBirdDivVisible) { +// updateBirdDiv(data); +// } + }; + + var handleDragZoom = function (evt, zoomArea) { + console.debug("regions: handleDragZoom, zoomArea:", zoomArea); + data = this; +// if (data.settings.isBirdDivVisible) { +// setBirdZoom(data, zoomArea); +// } + }; + + // plugin installation called by digilib on plugin object. + var install = function(digilib) { + // import geometry classes + geom = digilib.fn.geometry; + FULL_AREA = geom.rectangle(0,0,1,1); + // add defaults + $.extend(digilib.defaults, defaults); + // add actions + $.extend(digilib.actions, actions); + // add buttons + $.extend(digilib.buttons, buttons); + }; + + // plugin initialization + var init = function (data) { + console.debug('initialising regions plugin. data:', data); + var $data = $(data); var buttonSettings = data.settings.buttonSettings.fullscreen; // configure buttons through digilib "regionSet" option var buttonSet = data.settings.regionSet || regionSet; @@ -188,14 +241,28 @@ buttonSettings['regionSet'] = buttonSet; buttonSettings.buttonSets.push('regionSet'); } - fn = this.fn; - // console.log(data.settings.buttonSettings.fullscreen.buttonSets); - return { - }; + // install event handler + $data.bind('setup', handleSetup); + $data.bind('update', handleUpdate); + $data.bind('redisplay', handleRedisplay); + $data.bind('dragZoom', handleDragZoom); }; + + // plugin object with name and init + // shared objects filled by digilib on registration + var pluginProperties = { + name : 'region', + install : install, + init : init, + buttons : {}, + actions : {}, + fn : {}, + plugins : {} + }; + if ($.fn.digilib == null) { - $.error("jquery.digilib.regions must be loaded after jquery.digilib!"); + $.error("jquery.digilib.birdview must be loaded after jquery.digilib!"); } else { - $.fn.digilib('plugin', {name : 'regions', init : init}); + $.fn.digilib('plugin', pluginProperties); } })(jQuery);