Mercurial > hg > digilib-old
comparison client/digitallibrary/jquery/jquery.digilib.js @ 786:868c2e795aca jquery
new plugin architecture.
| author | robcast |
|---|---|
| date | Thu, 17 Feb 2011 14:32:48 +0100 |
| parents | b9a75079aece |
| children | b322f553f92e |
comparison
equal
deleted
inserted
replaced
| 785:b9a75079aece | 786:868c2e795aca |
|---|---|
| 249 'maxBgSize' : 10000, | 249 'maxBgSize' : 10000, |
| 250 // space to be left free in full page display, default value is for scrollbar | 250 // space to be left free in full page display, default value is for scrollbar |
| 251 'scalerInset' : 10 | 251 'scalerInset' : 10 |
| 252 }; | 252 }; |
| 253 | 253 |
| 254 // affine geometry classes | 254 // list of plugins |
| 255 var plugins = {}; | |
| 256 | |
| 257 // affine geometry plugin stub | |
| 255 var geom; | 258 var geom; |
| 256 | 259 |
| 257 var FULL_AREA; | 260 var FULL_AREA; |
| 258 | 261 |
| 259 var actions = { | 262 var actions = { |
| 260 // init: digilib initialization | 263 // init: digilib initialization |
| 261 init : function(options) { | 264 init : function(options) { |
| 262 // import geometry classes TODO: move to general plugin mechanism? | 265 // import geometry classes |
| 263 if ($.fn.digilib.geometry == null) { | 266 if (plugins.geometry == null) { |
| 264 console.error("You should use jquery.digilib.geometry"); | 267 $.error("jquery.digilib.geometry plugin not found!"); |
| 265 geom = dlGeometry(); | 268 geom = dlGeometry(); |
| 266 } else { | 269 } else { |
| 267 geom = $.fn.digilib.geometry; | 270 geom = plugins.geometry.init(); |
| 268 } | 271 } |
| 269 FULL_AREA = geom.rectangle(0, 0, 1, 1); | 272 FULL_AREA = geom.rectangle(0, 0, 1, 1); |
| 270 | 273 |
| 271 // settings for this digilib instance are merged from defaults and options | 274 // settings for this digilib instance are merged from defaults and options |
| 272 var settings = $.extend({}, defaults, options); | 275 var settings = $.extend({}, defaults, options); |
| 346 var bp = url.indexOf('/servlet/Scaler'); | 349 var bp = url.indexOf('/servlet/Scaler'); |
| 347 elemSettings.digilibBaseUrl = url.substring(0, bp) + '/digilib.jsp'; | 350 elemSettings.digilibBaseUrl = url.substring(0, bp) + '/digilib.jsp'; |
| 348 } | 351 } |
| 349 } | 352 } |
| 350 } | 353 } |
| 354 // initialise plugins | |
| 355 for (p in plugins) { | |
| 356 plugins[p].init(data); | |
| 357 } | |
| 351 // get image info from server if needed | 358 // get image info from server if needed |
| 352 if (data.scaleMode === 'pixel' || data.scaleMode === 'size') { | 359 if (data.scaleMode === 'pixel' || data.scaleMode === 'size') { |
| 353 loadImageInfo(data, updateDisplay); // updateDisplay(data) on completion | 360 loadImageInfo(data, updateDisplay); // updateDisplay(data) on completion |
| 354 } | 361 } |
| 355 // create buttons before scaler | 362 // create buttons before scaler |
| 1761 } | 1768 } |
| 1762 | 1769 |
| 1763 // hook plugin into jquery | 1770 // hook plugin into jquery |
| 1764 $.fn.digilib = function (action) { | 1771 $.fn.digilib = function (action) { |
| 1765 // plugin extension mechanism | 1772 // plugin extension mechanism |
| 1766 if (action === 'extendPlugin') { | 1773 if (action === 'plugin') { |
| 1767 // for each digilib $elem extend data.settings with obj.options | 1774 var plugin = arguments[1]; |
| 1775 // each plugin needs a name | |
| 1776 if (plugin.name != null) { | |
| 1777 plugins[plugin.name] = plugin; | |
| 1778 } | |
| 1779 /* for each digilib $elem extend data.settings with obj.options | |
| 1768 // TODO: couldn't other plugins just access $elem.data('digilib')? | 1780 // TODO: couldn't other plugins just access $elem.data('digilib')? |
| 1769 if (obj.options) { | 1781 if (obj.options) { |
| 1770 this.each(function() { | 1782 this.each(function() { |
| 1771 var $elem = $(this); | 1783 var $elem = $(this); |
| 1772 // console.debug('extending:', $elem); | 1784 // console.debug('extending:', $elem); |
| 1780 }); | 1792 }); |
| 1781 delete(obj.options); | 1793 delete(obj.options); |
| 1782 } | 1794 } |
| 1783 // extend the plugin actions (to make this useful, | 1795 // extend the plugin actions (to make this useful, |
| 1784 // maybe we need to expose some more internal functions) | 1796 // maybe we need to expose some more internal functions) |
| 1785 $.extend(actions, obj); | 1797 $.extend(actions, obj); */ |
| 1786 } else if (actions[action]) { | 1798 } else if (actions[action]) { |
| 1787 // call action on this with the remaining arguments (inserting data as first argument) | 1799 // call action on this with the remaining arguments (inserting data as first argument) |
| 1788 var $elem = $(this); | 1800 var $elem = $(this); |
| 1789 var data = $elem.data('digilib'); | 1801 var data = $elem.data('digilib'); |
| 1790 var args = Array.prototype.slice.call(arguments, 1); | 1802 var args = Array.prototype.slice.call(arguments, 1); |
