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 console.log("loaded original");
43 self._original_loaded = true;
45 var cb = self.original_loaded;
46 self.original_loaded = undefined;
51 if (self.options.max <= 0) {
52 self.options.max = original.naturalWidth
53 * 100 / self.initial_size[0];
60 self.element.offset(self.initial_position);
61 // self.element.draggable({containment:"parent"});
63 if (self.options.plus_button)
64 self.options.plus_button.click(
65 function(ev) { self.zoom(1); });
66 if (self.options.minus_button)
67 self.options.minus_button.click(
68 function(ev) { self.zoom(-1); });
70 self.options.areas_links.hover(function() {
72 var coords = $this.data("coords");
73 this._picture_mark = self.createMark({
78 $(this._picture_mark).remove();
79 this._picture_mark = undefined;
84 natural_size: function() {
85 var img = this.element.find('img.original').get(0);
86 return [ img.naturalWidth, img.naturalHeight ]
89 currentZoom: function() { return this._zoom; },
91 initOriginal: function() {
93 function subst_original() {
94 self.element.find("img.initial").remove();
95 self.element.find("img.loading").removeClass("loading");
96 self._original = true;
98 if (!this._original) {
99 if (this._original_loaded) {
100 return subst_original();
102 self.original_loaded = subst_original;
103 self.spinner.start();
109 zoom: function(steps) {
111 var t = this._zoom + steps;
112 return this.zoomTo(t);
115 zoomForStep: function(step) {
117 // max_step-1 => max %
118 return 100 + (this.options.max - 100) / this.options.steps * step
121 zoomTo: function(level) {
122 if (level < 0 || level > this.options.steps)
124 var ratio = this.zoomForStep(level) / 100;
125 var new_width = ratio * this.initial_size[0];
126 var new_height = ratio * this.initial_size[1];
130 this.initial_position.left
131 - (new_width - this.initial_size[0])/2),
133 this.initial_position.top
134 - (new_height - this.initial_size[1])/2),
139 this.element.css(target);
142 // this.element.animate(target, 1200); // default duration=400
145 allowedPosition: function(off) {
146 var x = undefined, fix_x = undefined;
147 var y = undefined, fix_y = undefined;
148 var w = this.element.width();
149 var h = this.element.height();
150 var cw = $(window).width();
151 var ch = $(window).height();
152 var off = off || this.element.offset();
179 if (fix_x !== undefined || fix_y !== undefined)
180 return { top: fix_y, left: fix_x };
188 // coords: [x, y, w, h]
190 createMark: function(mark) {
191 var $mark = $('<div class="mark"><div class="label">' +
192 mark.label + '</div></div>');
193 var ratio = this.zoomForStep(this.currentZoom()) *
194 this.initial_size[0] / (100 * this.natural_size()[0]);
195 var scale = function (v) {
198 if (mark.coords[1][0] < 0 || mark.coords[1][1] < 0) { // whole
199 var s = self.natural_size();
200 if (mark.coords[1][0] < 0) mark.coords[1][0] = s[0];
201 if (mark.coords[1][1] < 0) mark.coords[1][1] = s[1];
204 var coords = [[scale(mark.coords[0][0]), scale(mark.coords[0][1])],
205 [scale(mark.coords[1][0]), scale(mark.coords[1][1])]];
206 this.element.append($mark);
207 $mark.width(coords[1][0] - coords[0][0]);
208 $mark.height(coords[1][1] - coords[0][1]);
209 $mark.css({left: coords[0][0], top: coords[0][1]});
216 $(document).ready(function(){
217 $(".picture-wrap").pictureviewer({
218 plus_button: $(".toolbar .button.plus"),
219 minus_button: $(".toolbar .button.minus"),
220 areas_links: $("#picture-objects a, #picture-themes a"),
223 $.highlightFade.defaults.speed = 3000;
225 $('.toolbar a.dropdown').each(function() {
227 $($t.attr('href')).hide().insertAfter(this);
231 $(this).removeClass('selected');
232 $($(this).attr('href')).slideUp('fast');
235 $('.toolbar a.dropdown').click(function() {
236 if ($(this).hasClass('selected')) {
239 $(this).addClass('selected');
240 $($(this).attr('href')).slideDown('fast');
241 $(this).parent().siblings(".button:has(.dropdown)").children(".dropdown").each(closeDD);