1054
|
1 /* Copyright (c) 2011 Martin Raspe, Robert Casties
|
|
2
|
|
3 This program is free software: you can redistribute it and/or modify
|
|
4 it under the terms of the GNU Lesser General Public License as published by
|
|
5 the Free Software Foundation, either version 2 of the License, or
|
|
6 (at your option) any later version.
|
|
7
|
|
8 This program is distributed in the hope that it will be useful,
|
|
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 GNU Lesser General Public License for more details.
|
|
12
|
|
13 You should have received a copy of the GNU Lesser General Public License
|
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15
|
|
16 Authors:
|
|
17 Martin Raspe, Robert Casties, 26.3.2012
|
|
18 */
|
|
19
|
|
20 /**
|
|
21 * digilib SVG plugin (display a SVG on top if scaler image and zoom/rotate/mirror etc.)
|
|
22 **/
|
|
23
|
|
24 /* jslint browser: true, debug: true, forin: true
|
|
25 */
|
|
26
|
|
27 (function($) {
|
|
28
|
|
29 // plugin object with digilib data
|
|
30 var digilib = null;
|
|
31 // the functions made available by digilib
|
|
32 var fn = null;
|
|
33 // affine geometry plugin
|
|
34 var geom = null;
|
|
35
|
|
36 var defaults = {};
|
|
37
|
|
38 var actions = {
|
|
39 "test" : function(options) {
|
|
40 var onLoadXML = function (xml) {
|
|
41 settings.xml = xml;
|
|
42 settings.$toolBar = setupToolBar(settings);
|
|
43 $digilib.each(function() {
|
|
44 var $elem = $(this);
|
|
45 $elem.data(pluginName, settings);
|
|
46 });
|
|
47 };
|
|
48 var onLoadScalerImg = function () {
|
|
49 var $svgDiv = $('<div id="svg" />');
|
|
50 $('body').append($svgDiv);
|
|
51 // size SVG div like scaler img
|
|
52 var $scalerImg = $digilib.find('img.pic');
|
|
53 var scalerImgRect = geom.rectangle($scalerImg);
|
|
54 scalerImgRect.adjustDiv($svgDiv);
|
|
55 console.debug('$svgDiv', scalerImgRect);
|
|
56 var $svg = $svgDiv.svg({
|
|
57 'onLoad' : drawInitial
|
|
58 });
|
|
59 settings.$elem = $digilib;
|
|
60 settings.$svgDiv = $svgDiv;
|
|
61 settings.$svg = $svg;
|
|
62 // set SVG data
|
|
63 $svg.data('digilib', data);
|
|
64 $svg.data(pluginName, settings);
|
|
65 };
|
|
66 // fetch the XML measuring unit list
|
|
67 $.ajax({
|
|
68 type : "GET",
|
|
69 url : "svg/archimedes.xml",
|
|
70 dataType : "xml",
|
|
71 success : onLoadXML
|
|
72 });
|
|
73 data.$img.load(onLoadScalerImg);
|
|
74 return this;
|
|
75 }
|
|
76 };
|
|
77
|
|
78 // plugin installation called by digilib on plugin object.
|
|
79 var install = function (plugin) {
|
|
80 digilib = plugin;
|
|
81 console.debug('installing svg plugin. digilib:', digilib);
|
|
82 fn = digilib.fn;
|
|
83 // import geometry classes
|
|
84 geom = fn.geometry;
|
|
85 // add defaults, actions, buttons
|
|
86 $.extend(true, digilib.defaults, defaults); // make deep copy
|
|
87 $.extend(digilib.actions, actions);
|
|
88 // export functions
|
|
89 // fn.test = test;
|
|
90 };
|
|
91
|
|
92 // plugin initialization
|
|
93 var init = function (data) {
|
|
94 console.debug('initialising digilibSVG plugin. data:', data);
|
|
95 var $data = $(data);
|
|
96 $data.bind('setup', handleSetup);
|
|
97 };
|
|
98
|
|
99 var handleSetup = function (evt) {
|
|
100 console.debug("svg: handleSetup");
|
|
101 var data = this;
|
|
102 var settings = data.settings;
|
|
103 };
|
|
104
|
|
105 // plugin object with name and init
|
|
106 // shared objects filled by digilib on registration
|
|
107 var plugin = {
|
|
108 name : 'svg',
|
|
109 install : install,
|
|
110 init : init,
|
|
111 buttons : {},
|
|
112 actions : {},
|
|
113 fn : {},
|
|
114 plugins : {}
|
|
115 };
|
|
116
|
|
117 if ($.fn.digilib == null) {
|
|
118 $.error("jquery.digilib.svg must be loaded after jquery.digilib!");
|
|
119 } else {
|
|
120 $.fn.digilib('plugin', plugin);
|
|
121 }
|
|
122 })(jQuery);
|