3 $.widget('wl.pictureviewer', {
6 steps: 6, // steps of zoom
7 max: -1, // max zoom in percent
8 plus_button: undefined,
9 minus_button: undefined,
10 height: 500, // height to scale to initially
19 // the initial thumbnailed picture
22 var img = self.element.find('img.initial').get(0);
29 self.element.width(self.initial_size[0]);
30 self.element.height(self.initial_size[1]);
32 self.initial_position = self.element.offset();
34 var original = self.element.find('img.original').get(0);
35 self._original = false;
36 self.original_loeaded = undefined; // callback
37 self._original_loaded = false;
39 self.spinner = $("#spinner").progressSpin();
41 $(original).load(function() {
42 self._original_loaded = true;
44 var cb = self.original_loaded;
45 self.original_loaded = undefined;
50 if (self.options.max <= 0) {
51 self.options.max = original.naturalWidth
52 * 100 / self.initial_size[0];
59 self.element.offset(self.initial_position);
60 self.element.draggable({containment:"parent"});
62 if (self.options.plus_button)
63 self.options.plus_button.click(
64 function(ev) { self.zoom(1); });
65 if (self.options.minus_button)
66 self.options.minus_button.click(
67 function(ev) { self.zoom(-1); });
69 self.options.areas_links.hover(function() {
71 var coords = $this.data("coords");
72 this._picture_mark = self.createMark({
77 $(this._picture_mark).remove();
78 this._picture_mark = undefined;
83 natural_size: function() {
84 var img = this.element.find('img').get(0);
85 return [ img.naturalWidth, img.naturalHeight ]
88 currentZoom: function() { return this._zoom; },
90 initOriginal: function() {
92 function subst_original() {
93 self.element.find("img.initial").remove();
94 self.element.find("img.loading").removeClass("loading");
95 self._original = true;
97 if (!this._original) {
98 if (this._original_loaded) {
99 return subst_original();
101 self.original_loaded = subst_original;
102 self.spinner.start();
108 zoom: function(steps) {
110 var t = this._zoom + steps;
111 return this.zoomTo(t);
114 zoomForStep: function(step) {
116 // max_step-1 => max %
117 return 100 + (this.options.max - 100) / this.options.steps * step
120 zoomTo: function(level) {
121 if (level < 0 || level > this.options.steps)
123 var ratio = this.zoomForStep(level) / 100;
124 var new_width = ratio * this.initial_size[0];
125 var new_height = ratio * this.initial_size[1];
129 this.initial_position.left
130 - (new_width - this.initial_size[0])/2),
132 this.initial_position.top
133 - (new_height - this.initial_size[1])/2),
137 this.element.animate(target, 200); // default duration=400
140 allowedPosition: function(off) {
141 var x = undefined, fix_x = undefined;
142 var y = undefined, fix_y = undefined;
143 var w = this.element.width();
144 var h = this.element.height();
145 var cw = $(window).width();
146 var ch = $(window).height();
147 var off = off || this.element.offset();
174 if (fix_x !== undefined || fix_y !== undefined)
175 return { top: fix_y, left: fix_x };
183 // coords: [x, y, w, h]
185 createMark: function(mark) {
186 var $mark = $('<div class="mark"><div class="label">' +
187 mark.label + '</div></div>');
188 var ratio = this.zoomForStep(this.currentZoom()) *
189 this.initial_size[0] / (100 * this.natural_size()[0]);
190 var scale = function (v) {
193 if (mark.coords[1][0] < 0 || mark.coords[1][1] < 0) { // whole
194 var s = self.natural_size();
195 if (mark.coords[1][0] < 0) mark.coords[1][0] = s[0];
196 if (mark.coords[1][1] < 0) mark.coords[1][1] = s[1];
199 var coords = [[scale(mark.coords[0][0]), scale(mark.coords[0][1])],
200 [scale(mark.coords[1][0]), scale(mark.coords[1][1])]];
201 this.element.append($mark);
202 $mark.width(coords[1][0] - coords[0][0]);
203 $mark.height(coords[1][1] - coords[0][1]);
204 $mark.css({left: coords[0][0], top: coords[0][1]});
211 $(document).ready(function(){
212 $(".picture-wrap").pictureviewer({
213 plus_button: $(".toolbar .button.plus"),
214 minus_button: $(".toolbar .button.minus"),
215 areas_links: $("#picture-objects a, #picture-themes a"),
218 $.highlightFade.defaults.speed = 3000;
220 $('.toolbar a.dropdown').each(function() {
222 $($t.attr('href')).hide().insertAfter(this);
225 $('.toolbar a.dropdown').toggle(function() {
226 $(this).addClass('selected');
227 $($(this).attr('href')).slideDown('fast');
229 $(this).removeClass('selected');
230 $($(this).attr('href')).slideUp('fast');