# HG changeset patch # User robcast # Date 1298279709 -3600 # Node ID e6d0cdaa79236ddd4ed512e399ea3702fa97522d # Parent 5de6c7a738556724c9785859eddb3774981cd199# Parent 60e8cca7ac8125ec431f9b05a829c74aa2ca5ef6 Merge from jquery branch 60e8cca7ac8125ec431f9b05a829c74aa2ca5ef6 diff -r 5de6c7a73855 -r e6d0cdaa7923 client/digitallibrary/jquery/jquery-digilib-plugins.txt --- a/client/digitallibrary/jquery/jquery-digilib-plugins.txt Sun Feb 20 19:34:05 2011 +0100 +++ b/client/digitallibrary/jquery/jquery-digilib-plugins.txt Mon Feb 21 10:15:09 2011 +0100 @@ -40,3 +40,8 @@ "update", updateDisplay(): after small updates in the display, e.g. when the scaler-img finished loading. "redisplay", redisplay(): after changes in the display, e.g. after changing zoom factor. "dragZoom(newZoomArea)": while dragging the zoom area (with parameter newZoomArea). + +* initial options for the plugin can be passed to digilib, together with digilib options, by passing an object to the 'digilib' function: $div.digilib(options); +The passed options extend/override the default digilib options. The options are stored in the "data.settings" array. + +* A functional stub for new digilib plugins is available in the file "jquery.digilib.pluginstub.js" diff -r 5de6c7a73855 -r e6d0cdaa7923 client/digitallibrary/jquery/jquery-test-full.html --- a/client/digitallibrary/jquery/jquery-test-full.html Sun Feb 20 19:34:05 2011 +0100 +++ b/client/digitallibrary/jquery/jquery-test-full.html Mon Feb 21 10:15:09 2011 +0100 @@ -61,6 +61,7 @@ + @@ -68,7 +69,8 @@ $(document).ready(function(){ var opts = { interactionMode : 'fullscreen', - scalerBaseUrl : 'http://digilib.biblhertz.it/digilib04/servlet/Scaler' + scalerBaseUrl : 'http://digilib.biblhertz.it/digilib04/servlet/Scaler', + showRegionNumbers : true }; var $div = $('div.digilib'); $div.digilib(opts); diff -r 5de6c7a73855 -r e6d0cdaa7923 client/digitallibrary/jquery/jquery.digilib.birdseye.js --- a/client/digitallibrary/jquery/jquery.digilib.birdseye.js Sun Feb 20 19:34:05 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.birdseye.js Mon Feb 21 10:15:09 2011 +0100 @@ -7,6 +7,9 @@ // affine geometry plugin stub var geom; + // digilib object + var digilib; + var FULL_AREA; var buttons = { @@ -44,7 +47,9 @@ }; // plugin installation called by digilib on plugin object. - var install = function(digilib) { + var install = function(plugin) { + digilib = plugin; + console.debug('installing birdseye plugin. digilib:', digilib); // import geometry classes geom = digilib.fn.geometry; FULL_AREA = geom.rectangle(0,0,1,1); @@ -61,6 +66,7 @@ // plugin initialization var init = function (data) { + console.debug('initialising birdseye plugin. data:', data); var $data = $(data); // install event handler $data.bind('setup', handleSetup); @@ -227,6 +233,7 @@ birdZoomRect = geom.rectangle($birdZoom); scalerPos = geom.position($scaler); newRect = null; + data.$elem.find(".overlay").hide(); // hide all overlays (marks/regions) fullRect = digilib.fn.setZoomBG(data); // setup zoom background image $document.bind("mousemove.dlBirdMove", birdZoomMove); $document.bind("mouseup.dlBirdMove", birdZoomEndDrag); @@ -305,7 +312,7 @@ // plugin object with name and init // shared objects filled by digilib on registration - var digilib = { + var plugin = { name : 'birdseye', install : install, init : init, @@ -316,8 +323,8 @@ }; if ($.fn.digilib == null) { - $.error("jquery.digilib.birdview must be loaded after jquery.digilib!"); + $.error("jquery.digilib.birdseye must be loaded after jquery.digilib!"); } else { - $.fn.digilib('plugin', digilib); + $.fn.digilib('plugin', plugin); } })(jQuery); diff -r 5de6c7a73855 -r e6d0cdaa7923 client/digitallibrary/jquery/jquery.digilib.css --- a/client/digitallibrary/jquery/jquery.digilib.css Sun Feb 20 19:34:05 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.css Mon Feb 21 10:15:09 2011 +0100 @@ -57,10 +57,24 @@ } div.digilib div.region { + position: absolute; background-color: red; + opacity: 0.3; +} + +div.digilib div.region:hover { opacity: 0.5; } +div.regionnumber { + color: white; + font-size: 11px; + font-weight: bold; + height: 15px; + width: 16px; + margin: 3px; +} + /* special definitions for fullscreen */ div.digilib.dl_fullscreen div.buttons { position: fixed; diff -r 5de6c7a73855 -r e6d0cdaa7923 client/digitallibrary/jquery/jquery.digilib.geometry.js --- a/client/digitallibrary/jquery/jquery.digilib.geometry.js Sun Feb 20 19:34:05 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.geometry.js Mon Feb 21 10:15:09 2011 +0100 @@ -178,8 +178,8 @@ this.y = pos.y; return this; }; + // adds pos to the position that.setPt1 = that.setPosition; // TODO: not really the same - // adds pos to the position that.addPosition = function(pos) { this.x += pos.x; this.y += pos.y; @@ -198,14 +198,14 @@ y : this.y + this.height / 2 }); }; - // moves this Rectangle's center to position pos + // moves this rectangle's center to position pos that.setCenter = function(pos) { this.x = pos.x - this.width / 2; this.y = pos.y - this.height / 2; return this; }; + // returns true if both rectangles have equal position and proportion that.equals = function(other) { - // equal props var eq = (this.x === other.x && this.y === other.y && this.width === other.width); return eq; }; @@ -229,21 +229,20 @@ + this.height)); return ct; }; - // returns if rectangle "rect" is contained in this rectangle + // returns true if rectangle "rect" is contained in this rectangle that.containsRect = function(rect) { return (this.containsPosition(rect.getPt1()) && this .containsPosition(rect.getPt2())); }; + // returns true if rectangle "rect" and this rectangle overlap + that.overlapsRect = function(rect) { + return this.intersect(rect) != null; + }; // changes this rectangle's x/y values so it stays inside of rectangle - // rect - // keeping the proportions + // "rect", keeping the proportions that.stayInside = function(rect) { - if (this.x < rect.x) { - this.x = rect.x; - } - if (this.y < rect.y) { - this.y = rect.y; - } + this.x = Math.max(this.x, rect.x); + this.y = Math.max(this.y, rect.y); if (this.x + this.width > rect.x + rect.width) { this.x = rect.x + rect.width - this.width; } @@ -252,7 +251,7 @@ } return this; }; - // clips this rectangle so it stays inside of rectangle rect + // clips this rectangle so it stays inside of rectangle "rect" that.clipTo = function(rect) { var p1 = rect.getPt1(); var p2 = rect.getPt2(); @@ -261,27 +260,15 @@ this.setPt2(position(Math.min(this2.x, p2.x), Math.min(this2.y, p2.y))); return this; }; - // returns the intersection of the given Rectangle and this one + // returns the intersection of rectangle "rect" and this one that.intersect = function(rect) { - // FIX ME: not really, it should return null if there is no overlap - var sec = rect.copy(); - if (sec.x < this.x) { - sec.width = sec.width - (this.x - sec.x); - sec.x = this.x; - } - if (sec.y < this.y) { - sec.height = sec.height - (this.y - sec.y); - sec.y = this.y; - } - if (sec.x + sec.width > this.x + this.width) { - sec.width = (this.x + this.width) - sec.x; - } - if (sec.y + sec.height > this.y + this.height) { - sec.height = (this.y + this.height) - sec.y; - } - return sec; + var res = rect.clipTo(this); + if (res.width < 0 || res.height < 0) res = null; + return res; }; - // returns a Rectangle that fits into this one (by moving first) + + // returns a copy of rectangle "rect" that fits into this one + // (moving it first) that.fit = function(rect) { var sec = rect.copy(); sec.x = Math.max(sec.x, this.x); @@ -294,7 +281,7 @@ } return sec.intersect(this); }; - // adjusts position and size of $elem to this rectangle + // adjusts position and size of jQuery element "$elem" to this rectangle that.adjustDiv = function($elem) { $elem.offset({ left : this.x, @@ -302,7 +289,7 @@ }); $elem.width(this.width).height(this.height); }; - // returns size and position in css-compatible format + // returns position and size of this rectangle in css-compatible format that.getAsCss = function() { return { left : this.x, @@ -311,6 +298,11 @@ height : this.height }; }; + // returns position and size of this rectangle formatted for SVG attributes + that.getAsSvg = function() { + return [this.x, this.y, this.width, this.height].join(" "); + }; + // returns size and position of this rectangle formatted for ??? (w x h@x,y) that.toString = function() { return this.width + "x" + this.height + "@" + this.x + "," + this.y; }; diff -r 5de6c7a73855 -r e6d0cdaa7923 client/digitallibrary/jquery/jquery.digilib.js --- a/client/digitallibrary/jquery/jquery.digilib.js Sun Feb 20 19:34:05 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.js Mon Feb 21 10:15:09 2011 +0100 @@ -791,8 +791,9 @@ if (i) { settings.mk += ','; } - settings.mk += cropFloat(data.marks[i].x).toString() + - '/' + cropFloat(data.marks[i].y).toString(); + settings.mk += + cropFloatStr(data.marks[i].x) + '/' + + cropFloatStr(data.marks[i].y); } } // Scaler flags @@ -1236,7 +1237,7 @@ var data = this; updateDisplay(data); }; - + // place marks on the image var renderMarks = function (data) { if (data.$img == null || data.imgTrafo == null) return; @@ -1251,8 +1252,9 @@ var mpos = data.imgTrafo.transform(mark); console.debug("renderMarks: mpos=",mpos); // create mark - var html = '
'+(i+1)+'
'; + var html = '
'+(i+1)+'
'; var $mark = $(html); + $mark.attr("id", "digilib-mark-" + i); $elem.append($mark); mpos.adjustDiv($mark); } @@ -1362,8 +1364,6 @@ var $scaler = data.$scaler; var $img = data.$img; var fullRect = null; - // hide marks - data.$elem.find('div.mark').hide(); // hide the scaler img, show background of div instead $img.css('visibility', 'hidden'); var scalerCss = { @@ -1405,9 +1405,10 @@ // drag the image and load a new detail on mouse up var dragStart = function (evt) { - console.debug("dragstart at=",evt); + console.debug("dragstart at=", evt); // don't start dragging if not zoomed if (isFullArea(data.zoomArea)) return false; + $elem.find(".overlay").hide(); // hide all overlays (marks/regions) startPos = geom.position(evt); delta = null; // set low res background immediately on mousedown @@ -1430,7 +1431,7 @@ $scaler.css({ 'background-position' : bgPos.x + "px " + bgPos.y + "px" }); - // set birdview indicator to reflect new zoom position + // send message event with current zoom position var za = geom.rectangle($img); za.addPosition(delta.neg()); $data.trigger('dragZoom', [za]); @@ -1449,6 +1450,7 @@ $scaler.css({'opacity' : '1', 'background-image' : 'none'}); // unhide marks data.$elem.find('div.mark').show(); + $(data).trigger('redisplay'); return false; } // get old zoom area (screen coordinates) @@ -1553,6 +1555,11 @@ return parseInt(10000 * x, 10) / 10000; }; + // idem, string version + var cropFloatStr = function (x) { + return cropFloat(x).toString(); + }; + // fallback for console.log calls if (customConsole) { var logFunction = function(type) { @@ -1593,7 +1600,10 @@ getScaleMode : getScaleMode, setScaleMode : setScaleMode, isFullArea : isFullArea, - getBorderWidth : getBorderWidth + isNumber : isNumber, + getBorderWidth : getBorderWidth, + cropFloat : cropFloat, + cropFloatStr : cropFloatStr }; // hook digilib plugin into jquery diff -r 5de6c7a73855 -r e6d0cdaa7923 client/digitallibrary/jquery/jquery.digilib.pluginstub.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/digitallibrary/jquery/jquery.digilib.pluginstub.js Mon Feb 21 10:15:09 2011 +0100 @@ -0,0 +1,97 @@ +/** +digilib plugin stub + */ + +(function($) { + + // affine geometry + var geom; + // plugin object with digilib data + var digilib; + + var FULL_AREA; + + var buttons = { + stub : { + onclick : ["doStub", 1], + tooltip : "what does this button do?", + icon : "stub.png" + } + }; + + var defaults = { + // is stub active? + 'isStubActive' : true + }; + + var actions = { + // action code goes here + doStub : function (data, param) { + var settings = data.settings; + console.log('isStubActive', settings.isStubActive); + // do some useful stuff ... + } + }; + + // plugin installation called by digilib on plugin object. + var install = function(plugin) { + digilib = plugin; + console.debug('installing stub plugin. digilib:', digilib); + // import geometry classes + geom = digilib.fn.geometry; + FULL_AREA = geom.rectangle(0,0,1,1); + // add defaults, actins, buttons + $.extend(digilib.defaults, defaults); + $.extend(digilib.actions, actions); + $.extend(digilib.buttons, buttons); + }; + + // plugin initialization + var init = function (data) { + console.debug('initialising stub plugin. data:', data); + var $data = $(data); + // install event handler + $data.bind('setup', handleSetup); + $data.bind('update', handleUpdate); + $data.bind('redisplay', handleRedisplay); + $data.bind('dragZoom', handleDragZoom); + }; + + + var handleSetup = function (evt) { + console.debug("stub: handleSetup"); + var data = this; + }; + + var handleUpdate = function (evt) { + console.debug("stub: handleUpdate"); + var data = this; + }; + + var handleRedisplay = function (evt) { + console.debug("stub: handleRedisplay"); + var data = this; + }; + + var handleDragZoom = function (evt, zoomArea) { + var data = this; + }; + + // plugin object with name and init + // shared objects filled by digilib on registration + var plugin = { + name : 'pluginstub', + install : install, + init : init, + buttons : {}, + actions : {}, + fn : {}, + plugins : {} + }; + + if ($.fn.digilib == null) { + $.error("jquery.digilib.pluginstub must be loaded after jquery.digilib!"); + } else { + $.fn.digilib('plugin', plugin); + } +})(jQuery); diff -r 5de6c7a73855 -r e6d0cdaa7923 client/digitallibrary/jquery/jquery.digilib.regions.js --- a/client/digitallibrary/jquery/jquery.digilib.regions.js Sun Feb 20 19:34:05 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.regions.js Mon Feb 21 10:15:09 2011 +0100 @@ -11,19 +11,23 @@ */ (function($) { + // the digilib object + var digilib; // the data object passed by digilib var data; - var buttons; + // the functions made available by digilib var fn; - // affine geometry plugin stub + // affine geometry plugin var geom; var FULL_AREA; + var ID_PREFIX = "digilib-region-"; + var buttons = { addregion : { - onclick : "setRegion", - tooltip : "set a region", + onclick : "defineRegion", + tooltip : "define a region", icon : "addregion.png" }, delregion : { @@ -46,186 +50,260 @@ var defaults = { // are regions shown? 'isRegionVisible' : true, + // are region numbers shown? + 'showRegionNumbers' : false, // buttonset of this plugin 'regionSet' : ['addregion', 'delregion', 'regions', 'regioninfo', 'lessoptions'], - // array of defined regions - 'regions' : [] - }; + // url param for regions + 'rg' : null, + }; var actions = { + // define a region interactively with two clicked points - "setRegion" : function(data) { + "defineRegion" : function(data) { + if (!data.settings.isRegionVisible) { + alert("Please turn on regions visibility!"); + return; + } var $elem = data.$elem; + var $body = $('body'); + var bodyRect = geom.rectangle($body); var $scaler = data.$scaler; - var picRect = geom.rectangle($scaler); + var scalerRect = geom.rectangle($scaler); var pt1, pt2; - // TODO: temporary rectangle only, pass values to "addRegion" factory - var $tempDiv = $('