comparison client/digitallibrary/jquery/jquery.digilib.js @ 598:81723e7efe82 jquery

next version zero of jquery.digilib
author robcast
date Wed, 12 Jan 2011 19:36:11 +0100
parents 33605dd3e9c6
children 9da729b90004
comparison
equal deleted inserted replaced
597:33605dd3e9c6 598:81723e7efe82
2 * digilib jQuery plugin 2 * digilib jQuery plugin
3 * 3 *
4 */ 4 */
5 5
6 (function($) { 6 (function($) {
7
8 var defaults = {
9 /* base URL to Scaler servlet */
10 'scalerUrl' : 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler',
11 /* digilib image path i.e. fn */
12 'imagePath' : '',
13 /* mode of operation.
14 * fullscreen: takes parameters from page URL, keeps state in page URL
15 * embedded: takes parameters from Javascript options, keeps state inside object
16 */
17 'interactionMode' : 'fullscreen'
18 };
19
20 /* parameters from the query string */
21 var params = {};
7 22
8 var methods = { 23 var methods = {
9 init : function(options) { 24 init : function(options) {
10 return this.each(function() { 25 return this.each(function() {
11 var $this = $(this); 26 var $elem = $(this);
12 var data = $this.data('digilib'); 27 var data = $elem.data('digilib');
13
14 // If the plugin hasn't been initialized yet 28 // If the plugin hasn't been initialized yet
15 if (!data) { 29 if (!data) {
16 30 // settings for this digilib instance are merged from defaults and options
17 /* 31 var settings = $.extend({}, defaults, options);
18 * Do more setup stuff here 32 // merge query parameters
19 */ 33 settings = $.extend(settings, parseParams(settings.interactionMode));
20 34 // store in data element
21 $(this).data('digilib', { 35 $elem.data('digilib', {
22 target : $this 36 target : $elem,
37 settings : settings
23 }); 38 });
24 } 39 }
25 }); 40 });
26 }, 41 },
27 destroy : function() { 42 destroy : function() {
28 return this.each(function(){ 43 return this.each(function(){
29 var $this = $(this); 44 var $this = $(this);
30 var data = $this.data('digilib'); 45 var data = $this.data('digilib');
31 // Namespacing FTW 46 // Namespacing FTW
32 $(window).unbind('.digilib'); // FIXME: unbinds all digilibs 47 $(window).unbind('.digilib'); // unbinds all digilibs(?)
33 data.digilib.remove(); 48 data.digilib.remove();
34 $this.removeData('digilib'); 49 $this.removeData('digilib');
35 }); 50 });
36 } 51 }
37 }; 52 };
38 53
39 $.fn.digilib = function(method) { 54 // returns object with parameters from the query string or an embedded img-tag (depending on interactionMode)
40 55 var parseParams = function(interactionMode) {
41 if (methods[method]) { 56 alert("parseParams() not implemented");
42 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 57 };
43 } else if (typeof(method) === 'object' || !method) {
44 return methods.init.apply(this, arguments);
45 } else {
46 $.error( 'Method ' + method + ' does not exist on jQuery.digilib' );
47 }
48 };
49 58
59 // hook plugin into jquery
60 $.fn.digilib = function(method) {
61 if (methods[method]) {
62 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
63 } else if (typeof(method) === 'object' || !method) {
64 return methods.init.apply(this, arguments);
65 } else {
66 $.error( 'Method ' + method + ' does not exist on jQuery.digilib' );
67 }
68 };
50 69
51 })(jQuery); 70 })(jQuery);