annotate client/digitallibrary/jquery/svg/jquery.digilibSVG.js @ 788:ddb28f6b066a jquery

make plugins available to other plugins
author hertzhaft
date Thu, 17 Feb 2011 22:50:32 +0100
parents 7703ff1f2173
children 61e4e5d679ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
1 /* Copyright (c) 2011 Martin Raspe, Robert Casties
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
2
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
3 This program is free software: you can redistribute it and/or modify
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
4 it under the terms of the GNU Lesser General Public License as published by
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
5 the Free Software Foundation, either version 2 of the License, or
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
6 (at your option) any later version.
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
7
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
8 This program is distributed in the hope that it will be useful,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
11 GNU Lesser General Public License for more details.
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
12
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
13 You should have received a copy of the GNU Lesser General Public License
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
15
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
16 Authors:
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
17 Martin Raspe, Robert Casties, 9.2.2011
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
18 */
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
19
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
20 /**
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
21 * digilib SVG plugin (measuring tool for use within the digilib jQuery plugin)
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
22 **/
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
23
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
24
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
25 /* jslint browser: true, debug: true, forin: true
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
26 */
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
27
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
28 // fallback for console.log calls
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
29 if (typeof(console) === 'undefined') {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
30 var console = {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
31 log : function(){},
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
32 debug : function(){},
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
33 error : function(){}
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
34 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
35 var customConsole = true;
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
36 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
37
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
38 (function($) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
39 console.debug('installing jquery.digilibSVG');
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
40
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
41 var pluginName = 'digilibSVG';
788
ddb28f6b066a make plugins available to other plugins
hertzhaft
parents: 782
diff changeset
42 var geom;
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
43
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
44 var defaults = {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
45 // choice of colors offered by toolbar
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
46 lineColors : ['white', 'red', 'yellow', 'green', 'blue', 'black'],
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
47 // default color
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
48 lineColor : 'white',
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
49 // color while the line is drawn
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
50 drawColor : 'green',
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
51 // color of selected objects
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
52 selectColor : 'red',
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
53 // drawing shapes
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
54 shapes : ['line', 'polyline', 'rectangle', 'square', 'circle', 'arch',
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
55 'ratio', 'intercolumn', 'line grid'],
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
56 // default shape
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
57 shape : 'line',
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
58 // measuring unit (index into list)
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
59 unit : 1,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
60 // converted unit (index into list)
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
61 converted : 2,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
62 // last measured distance
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
63 lastDistance : 0,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
64 // last measured angle
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
65 lastAngle : 0,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
66 // maximal denominator for mixed fractions
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
67 maxDenominator : 20,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
68 // number of decimal places for convert results
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
69 maxDecimals : 3,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
70 // show convert result as mixed fraction?
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
71 showMixedFraction : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
72 // show angle relative to last line?
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
73 showRelativeAngle : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
74 // show distance numbers?
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
75 showDistanceNumbers : true,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
76 // show ratio of rectangle sides?
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
77 showRectangleRatios : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
78 // draw line ends as small crosses
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
79 drawEndPoints : true,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
80 // draw mid points of lines
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
81 drawMidPoints : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
82 // draw circle centers
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
83 drawCenters : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
84 // draw rectangles from the diagonal and one point
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
85 drawFromDiagonal : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
86 // draw circles from center
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
87 drawFromCenter : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
88 // snap to endpoints
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
89 snapEndPoints : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
90 // snap to mid points of lines
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
91 snapMidPoints : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
92 // snap to circle centers
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
93 snapCenters : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
94 // keep original object when moving/scaling/rotating
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
95 keepOriginal : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
96 // number of copies when drawing grids
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
97 gridCopies : 10
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
98 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
99
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
100 // setup a div for accessing the main SVG functionality
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
101 var setupToolBar = function(settings) {
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
102 var $toolBar = $('<div id="svg-toolbar"/>');
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
103 // shapes select
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
104 var $shape = $('<select id="svg-shapes"/>');
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
105 for (var i = 0; i < settings.shapes.length; i++) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
106 var name = settings.shapes[i];
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
107 var $opt = $('<option value="' + i + '">' + name + '</option>');
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
108 $shape.append($opt);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
109 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
110 // console.debug($xml);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
111 var $xml = $(settings.xml);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
112 var units = [];
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
113 $xml.find("unit").each(function() {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
114 units.push({
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
115 'name' : $(this).attr("name"),
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
116 'factor' : $(this).attr("factor"),
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
117 'add' : $(this).attr("add"),
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
118 'subunits' : $(this).attr("subunits")
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
119 });
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
120 });
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
121 settings.units = units;
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
122 // unit selects
781
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
123 var $unit1 = $('<select id="svg-convert1"/>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
124 var $unit2 = $('<select id="svg-convert2"/>');
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
125 for (var i = 0; i < units.length; i++) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
126 var name = units[i].name;
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
127 var $opt = $('<option value="' + i + '">' + name + '</option>');
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
128 $opt.data(pluginName, units[i]);
781
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
129 $unit1.append($opt);
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
130 $unit2.append($opt.clone());
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
131 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
132 // other elements
781
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
133 var $la1 = $('<span class="svg-label">pixel</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
134 var $la2 = $('<span class="svg-label">factor</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
135 var $la3 = $('<span class="svg-label">=</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
136 var $la4 = $('<span class="svg-label">=</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
137 var $px = $('<span id="svg-pixel" class="svg-number">0.0</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
138 var $factor = $('<span id="svg-factor" class="svg-number">0.0</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
139 var $result1 = $('<input id="svg-unit1" class="svg-input" value="0.0"/>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
140 var $result2 = $('<input id="svg-unit2" class="svg-input" value="0.0"/>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
141 var $angle = $('<span id="svg-angle" class="svg-number">0.0</span>');
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
142 $('body').append($toolBar);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
143 $toolBar.append($shape);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
144 $toolBar.append($la1);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
145 $toolBar.append($px);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
146 $toolBar.append($la2);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
147 $toolBar.append($factor);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
148 $toolBar.append($la3);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
149 $toolBar.append($result1);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
150 $toolBar.append($unit1);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
151 $toolBar.append($la4);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
152 $toolBar.append($result2);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
153 $toolBar.append($unit2);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
154 $toolBar.append($angle);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
155 return $toolBar;
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
156 };
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
157
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
158 var drawInitial = function ($svg) {
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
159 console.debug('SVG is ready');
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
160 var $svgDiv = $(this);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
161 var rect = geom.rectangle($svgDiv);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
162 $svg.line(0, 0, rect.width, rect.height,
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
163 {stroke: 'white', strokeWidth: 2});
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
164 $svg.line(0, rect.height, rect.width, 0,
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
165 {stroke: 'red', strokeWidth: 2});
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
166 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
167
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
168 var actions = {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
169 "init" : function(options) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
170 var $digilib = this;
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
171 var data = $digilib.data('digilib');
788
ddb28f6b066a make plugins available to other plugins
hertzhaft
parents: 782
diff changeset
172 var plugins = data.plugins;
ddb28f6b066a make plugins available to other plugins
hertzhaft
parents: 782
diff changeset
173 geom = plugins.geometry.init();
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
174 var settings = $.extend({}, defaults, options);
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
175 // prepare the AJAX callback
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
176 // TODO: return unless interactiveMode === 'fullscreen'?
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
177 var onLoadXML = function (xml) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
178 settings.xml = xml;
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
179 settings.$toolBar = setupToolBar(settings);
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
180 $digilib.each(function() {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
181 var $elem = $(this);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
182 $elem.data(pluginName, settings);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
183 });
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
184 };
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
185 var onLoadScalerImg = function () {
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
186 var $svgDiv = $('<div id="svg" />');
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
187 $('body').append($svgDiv);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
188 // size SVG div like scaler img
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
189 var $scalerImg = $digilib.find('img.pic');
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
190 var scalerImgRect = geom.rectangle($scalerImg);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
191 scalerImgRect.adjustDiv($svgDiv);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
192 console.debug('$svgDiv', scalerImgRect);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
193 var $svg = $svgDiv.svg({
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
194 'onLoad' : drawInitial
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
195 });
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
196 settings.$elem = $digilib;
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
197 settings.$svgDiv = $svgDiv;
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
198 settings.$svg = $svg;
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
199 // set SVG data
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
200 $svg.data('digilib', data);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
201 $svg.data(pluginName, settings);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
202 };
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
203 // fetch the XML measuring unit list
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
204 $.ajax({
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
205 type : "GET",
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
206 url : "svg/archimedes.xml",
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
207 dataType : "xml",
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
208 success : onLoadXML
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
209 });
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
210 data.$img.load(onLoadScalerImg);
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
211 return this;
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
212 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
213 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
214
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
215 // hook plugin into jquery
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
216 $.fn[pluginName] = function(action) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
217 if (actions[action]) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
218 // call action on this with the remaining arguments (inserting data as first argument)
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
219 var $elem = $(this);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
220 var data = $elem.data('digilib');
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
221 if (!data) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
222 return $.error(pluginName + ' action ' + action + ' needs a digilib element');
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
223 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
224 var args = Array.prototype.slice.call(arguments, 1);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
225 args.unshift(data);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
226 return actions[action].apply(this, args);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
227 } else if (typeof(action) === 'object' || !action) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
228 // call init on this
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
229 return actions.init.apply(this, arguments);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
230 } else {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
231 $.error('action ' + action + ' does not exist on jQuery.' + pluginName);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
232 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
233 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
234
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
235 })(jQuery);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
236