Mercurial > hg > digilib-old
comparison client/digitallibrary/jquery/jquery.digilib.js @ 787:b322f553f92e jquery
more new plugin architecture.
author | robcast |
---|---|
date | Thu, 17 Feb 2011 22:36:49 +0100 |
parents | 868c2e795aca |
children | ddb28f6b066a |
comparison
equal
deleted
inserted
replaced
786:868c2e795aca | 787:b322f553f92e |
---|---|
252 }; | 252 }; |
253 | 253 |
254 // list of plugins | 254 // list of plugins |
255 var plugins = {}; | 255 var plugins = {}; |
256 | 256 |
257 // object to export functions to plugins | |
258 var fn; | |
259 | |
257 // affine geometry plugin stub | 260 // affine geometry plugin stub |
258 var geom; | 261 var geom; |
259 | 262 |
260 var FULL_AREA; | 263 var FULL_AREA; |
261 | 264 |
350 elemSettings.digilibBaseUrl = url.substring(0, bp) + '/digilib.jsp'; | 353 elemSettings.digilibBaseUrl = url.substring(0, bp) + '/digilib.jsp'; |
351 } | 354 } |
352 } | 355 } |
353 } | 356 } |
354 // initialise plugins | 357 // initialise plugins |
355 for (p in plugins) { | 358 for (n in plugins) { |
356 plugins[p].init(data); | 359 var p = plugins[n]; |
360 // share common objects | |
361 p.buttons = buttons; | |
362 p.actions = actions; | |
363 p.fn = fn; | |
364 // and init | |
365 p.init(data); | |
357 } | 366 } |
358 // get image info from server if needed | 367 // get image info from server if needed |
359 if (data.scaleMode === 'pixel' || data.scaleMode === 'size') { | 368 if (data.scaleMode === 'pixel' || data.scaleMode === 'size') { |
360 loadImageInfo(data, updateDisplay); // updateDisplay(data) on completion | 369 loadImageInfo(data, updateDisplay); // updateDisplay(data) on completion |
361 } | 370 } |
1765 console.log = logFunction('_log'); | 1774 console.log = logFunction('_log'); |
1766 console.debug = logFunction('_debug'); | 1775 console.debug = logFunction('_debug'); |
1767 console.error = logFunction('_error'); | 1776 console.error = logFunction('_error'); |
1768 } | 1777 } |
1769 | 1778 |
1779 // functions to export to plugins | |
1780 fn = { | |
1781 parseQueryString : parseQueryString, | |
1782 getScalerUrl : getScalerUrl, | |
1783 getParamString : getParamString, | |
1784 getDigilibUrl : getDigilibUrl, | |
1785 unpackParams : unpackParams, | |
1786 packParams : packParams, | |
1787 redisplay : redisplay, | |
1788 updateDisplay : updateDisplay, | |
1789 getImgTrafo : getImgTrafo, | |
1790 getQuality : getQuality, | |
1791 setQuality : setQuality, | |
1792 getScaleMode : getScaleMode, | |
1793 setScaleMode : setScaleMode, | |
1794 isFullArea : isFullArea | |
1795 }; | |
1796 | |
1770 // hook plugin into jquery | 1797 // hook plugin into jquery |
1771 $.fn.digilib = function (action) { | 1798 $.fn.digilib = function (action) { |
1772 // plugin extension mechanism | 1799 // plugin extension mechanism |
1773 if (action === 'plugin') { | 1800 if (action === 'plugin') { |
1774 var plugin = arguments[1]; | 1801 var plugin = arguments[1]; |
1775 // each plugin needs a name | 1802 // each plugin needs a name |
1776 if (plugin.name != null) { | 1803 if (plugin.name != null) { |
1777 plugins[plugin.name] = plugin; | 1804 plugins[plugin.name] = plugin; |
1778 } | 1805 } |
1779 /* for each digilib $elem extend data.settings with obj.options | 1806 // initialisation of plugins done later |
1780 // TODO: couldn't other plugins just access $elem.data('digilib')? | |
1781 if (obj.options) { | |
1782 this.each(function() { | |
1783 var $elem = $(this); | |
1784 // console.debug('extending:', $elem); | |
1785 var data = $elem.data('digilib'); | |
1786 if (!data) { | |
1787 return console.log('cannot extend digilib plugin, element not initialised!'); | |
1788 } | |
1789 var settings = data.settings; | |
1790 $.extend(settings, obj.options); | |
1791 // console.log('settings:', settings); | |
1792 }); | |
1793 delete(obj.options); | |
1794 } | |
1795 // extend the plugin actions (to make this useful, | |
1796 // maybe we need to expose some more internal functions) | |
1797 $.extend(actions, obj); */ | |
1798 } else if (actions[action]) { | 1807 } else if (actions[action]) { |
1799 // call action on this with the remaining arguments (inserting data as first argument) | 1808 // call action on this with the remaining arguments (inserting data as first argument) |
1800 var $elem = $(this); | 1809 var $elem = $(this); |
1801 var data = $elem.data('digilib'); | 1810 var data = $elem.data('digilib'); |
1802 var args = Array.prototype.slice.call(arguments, 1); | 1811 var args = Array.prototype.slice.call(arguments, 1); |