annotate client/src/main/webapp/jquery/svg/jquery.digilibSVG.js @ 892:ba1eb2d821a2 mvnify

rearrange sources to maven directory standard
author robcast
date Tue, 19 Apr 2011 18:44:25 +0200
parents client/digitallibrary/jquery/svg/jquery.digilibSVG.js@61e4e5d679ba
children
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,
789
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
94 // snap distance (in screen pixels)
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
95 snapDistance : 5,
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
96 // keep original object when moving/scaling/rotating
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
97 keepOriginal : false,
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
98 // number of copies when drawing grids
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
99 gridCopies : 10
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
100 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
101
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
102 // setup a div for accessing the main SVG functionality
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
103 var setupToolBar = function(settings) {
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
104 var $toolBar = $('<div id="svg-toolbar"/>');
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
105 // shapes select
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
106 var $shape = $('<select id="svg-shapes"/>');
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
107 for (var i = 0; i < settings.shapes.length; i++) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
108 var name = settings.shapes[i];
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
109 var $opt = $('<option value="' + i + '">' + name + '</option>');
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
110 $shape.append($opt);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
111 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
112 // console.debug($xml);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
113 var $xml = $(settings.xml);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
114 // unit selects
781
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
115 var $unit1 = $('<select id="svg-convert1"/>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
116 var $unit2 = $('<select id="svg-convert2"/>');
789
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
117
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
118 $xml.find("section").each(function() {
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
119 var $section = $(this);
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
120 var name = $section.attr("name");
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
121 // append section name as option
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
122 var $opt = $('<option class="section" disabled="disabled">' + name + '</option>');
781
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
123 $unit1.append($opt);
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
124 $unit2.append($opt.clone());
789
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
125 $section.find("unit").each(function() {
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
126 var $unit = $(this);
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
127 var name = $unit.attr("name");
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
128 var factor = $unit.attr("factor");
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
129 var $opt = $('<option class="unit" value="' + factor + '">' + name + '</option>');
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
130 $opt.data(pluginName, {
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
131 'name' : name,
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
132 'factor' : factor,
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
133 'add' : $unit.attr("add"),
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
134 'subunits' : $unit.attr("subunits")
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
135 });
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
136 $unit1.append($opt);
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
137 $unit2.append($opt.clone());
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
138 });
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
139 });
61e4e5d679ba english section headings in unit dropdown
hertzhaft
parents: 788
diff changeset
140 // settings.units = units;
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
141 // other elements
781
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
142 var $la1 = $('<span class="svg-label">pixel</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
143 var $la2 = $('<span class="svg-label">factor</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
144 var $la3 = $('<span class="svg-label">=</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
145 var $la4 = $('<span class="svg-label">=</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
146 var $px = $('<span id="svg-pixel" class="svg-number">0.0</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
147 var $factor = $('<span id="svg-factor" class="svg-number">0.0</span>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
148 var $result1 = $('<input id="svg-unit1" class="svg-input" value="0.0"/>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
149 var $result2 = $('<input id="svg-unit2" class="svg-input" value="0.0"/>');
d5f47dfaf0ce status line for SVG measuring tool
hertzhaft
parents: 778
diff changeset
150 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
151 $('body').append($toolBar);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
152 $toolBar.append($shape);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
153 $toolBar.append($la1);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
154 $toolBar.append($px);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
155 $toolBar.append($la2);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
156 $toolBar.append($factor);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
157 $toolBar.append($la3);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
158 $toolBar.append($result1);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
159 $toolBar.append($unit1);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
160 $toolBar.append($la4);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
161 $toolBar.append($result2);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
162 $toolBar.append($unit2);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
163 $toolBar.append($angle);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
164 return $toolBar;
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
165 };
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
166
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
167 var drawInitial = function ($svg) {
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
168 console.debug('SVG is ready');
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
169 var $svgDiv = $(this);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
170 var rect = geom.rectangle($svgDiv);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
171 $svg.line(0, 0, rect.width, rect.height,
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
172 {stroke: 'white', strokeWidth: 2});
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
173 $svg.line(0, rect.height, rect.width, 0,
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
174 {stroke: 'red', strokeWidth: 2});
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
175 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
176
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
177 var actions = {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
178 "init" : function(options) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
179 var $digilib = this;
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
180 var data = $digilib.data('digilib');
788
ddb28f6b066a make plugins available to other plugins
hertzhaft
parents: 782
diff changeset
181 var plugins = data.plugins;
ddb28f6b066a make plugins available to other plugins
hertzhaft
parents: 782
diff changeset
182 geom = plugins.geometry.init();
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
183 var settings = $.extend({}, defaults, options);
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
184 // prepare the AJAX callback
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
185 // TODO: return unless interactiveMode === 'fullscreen'?
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
186 var onLoadXML = function (xml) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
187 settings.xml = xml;
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
188 settings.$toolBar = setupToolBar(settings);
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
189 $digilib.each(function() {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
190 var $elem = $(this);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
191 $elem.data(pluginName, settings);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
192 });
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
193 };
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
194 var onLoadScalerImg = function () {
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
195 var $svgDiv = $('<div id="svg" />');
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
196 $('body').append($svgDiv);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
197 // size SVG div like scaler img
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
198 var $scalerImg = $digilib.find('img.pic');
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
199 var scalerImgRect = geom.rectangle($scalerImg);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
200 scalerImgRect.adjustDiv($svgDiv);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
201 console.debug('$svgDiv', scalerImgRect);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
202 var $svg = $svgDiv.svg({
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
203 'onLoad' : drawInitial
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
204 });
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
205 settings.$elem = $digilib;
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
206 settings.$svgDiv = $svgDiv;
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
207 settings.$svg = $svg;
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
208 // set SVG data
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
209 $svg.data('digilib', data);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
210 $svg.data(pluginName, settings);
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
211 };
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
212 // fetch the XML measuring unit list
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
213 $.ajax({
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
214 type : "GET",
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
215 url : "svg/archimedes.xml",
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
216 dataType : "xml",
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
217 success : onLoadXML
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
218 });
782
7703ff1f2173 create SVG on top of scaler img
hertzhaft
parents: 781
diff changeset
219 data.$img.load(onLoadScalerImg);
778
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
220 return this;
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
221 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
222 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
223
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
224 // hook plugin into jquery
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
225 $.fn[pluginName] = function(action) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
226 if (actions[action]) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
227 // call action on this with the remaining arguments (inserting data as first argument)
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
228 var $elem = $(this);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
229 var data = $elem.data('digilib');
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
230 if (!data) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
231 return $.error(pluginName + ' action ' + action + ' needs a digilib element');
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
232 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
233 var args = Array.prototype.slice.call(arguments, 1);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
234 args.unshift(data);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
235 return actions[action].apply(this, args);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
236 } else if (typeof(action) === 'object' || !action) {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
237 // call init on this
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
238 return actions.init.apply(this, arguments);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
239 } else {
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
240 $.error('action ' + action + ' does not exist on jQuery.' + pluginName);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
241 }
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
242 };
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
243
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
244 })(jQuery);
f8235c42f4a0 more preparations for SVG measuring tool
hertzhaft
parents:
diff changeset
245