# HG changeset patch # User robcast # Date 1294857371 -3600 # Node ID aee94e4a8c481009502a386fdbd2be8a1e1334a7 # Parent 3a2942d2d5cd22bba240d1a06fcd94bf9c0cc1a3 next version zero of jquery.digilib diff -r 3a2942d2d5cd -r aee94e4a8c48 client/digitallibrary/jquery/jquery.digilib.js --- a/client/digitallibrary/jquery/jquery.digilib.js Wed Jan 12 09:51:26 2011 +0100 +++ b/client/digitallibrary/jquery/jquery.digilib.js Wed Jan 12 19:36:11 2011 +0100 @@ -4,22 +4,37 @@ */ (function($) { + + var defaults = { + /* base URL to Scaler servlet */ + 'scalerUrl' : 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler', + /* digilib image path i.e. fn */ + 'imagePath' : '', + /* mode of operation. + * fullscreen: takes parameters from page URL, keeps state in page URL + * embedded: takes parameters from Javascript options, keeps state inside object + */ + 'interactionMode' : 'fullscreen' + }; + + /* parameters from the query string */ + var params = {}; var methods = { init : function(options) { return this.each(function() { - var $this = $(this); - var data = $this.data('digilib'); - + var $elem = $(this); + var data = $elem.data('digilib'); // If the plugin hasn't been initialized yet if (!data) { - - /* - * Do more setup stuff here - */ - - $(this).data('digilib', { - target : $this + // settings for this digilib instance are merged from defaults and options + var settings = $.extend({}, defaults, options); + // merge query parameters + settings = $.extend(settings, parseParams(settings.interactionMode)); + // store in data element + $elem.data('digilib', { + target : $elem, + settings : settings }); } }); @@ -29,23 +44,27 @@ var $this = $(this); var data = $this.data('digilib'); // Namespacing FTW - $(window).unbind('.digilib'); // FIXME: unbinds all digilibs + $(window).unbind('.digilib'); // unbinds all digilibs(?) data.digilib.remove(); $this.removeData('digilib'); }); } - }; + }; - $.fn.digilib = function(method) { - - if (methods[method]) { - return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); - } else if (typeof(method) === 'object' || !method) { - return methods.init.apply(this, arguments); - } else { - $.error( 'Method ' + method + ' does not exist on jQuery.digilib' ); - } - }; + // returns object with parameters from the query string or an embedded img-tag (depending on interactionMode) + var parseParams = function(interactionMode) { + alert("parseParams() not implemented"); + }; + // hook plugin into jquery + $.fn.digilib = function(method) { + if (methods[method]) { + return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); + } else if (typeof(method) === 'object' || !method) { + return methods.init.apply(this, arguments); + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.digilib' ); + } + }; })(jQuery); \ No newline at end of file