3 $.widget('wl.pictureviewer', {
6 step: 20, // step in % of initial image
7 plus_button: undefined,
8 minus_button: undefined,
11 ORIGINAL_AVAILABLE: 1,
17 self.element.data('width'),
18 self.element.data('height')
20 self.original_size = [
21 self.element.data('original-width'),
22 self.element.data('original-height')
27 self.original = self.element.find('img.original').eq(0);
29 self._original_avaialble = self.ORIGINAL_LOADING;
30 function original_loaded() {
31 self._original_avaialble = self.ORIGINAL_AVAILABLE;
32 self.options.plus_button.removeClass('inactive');
33 self.options.minus_button.removeClass('inactive');
34 console.log("Original image available, sizes initial: " + self.initial_size + ", original: " + self.original_size);
36 self.original.load(original_loaded);
38 self.element.width(self.initial_size[0]);
39 self.element.height(self.initial_size[1]);
41 if (self.options.plus_button)
42 self.options.plus_button.click(
43 function(ev) { self.zoom(1); });
44 if (self.options.minus_button)
45 self.options.minus_button.click(
46 function(ev) { self.zoom(-1); });
48 self._initial_mark = null;
49 function clean_initial_mark() {
50 if (self._initial_mark) {
51 self._initial_mark.remove();
52 self._initial_mark = null;
55 var initial_hash = window.location.hash;
58 if (initial_hash.startsWith('#object-')) {
59 $("[href=#picture-objects]").trigger('click');
60 } else if (initial_hash.startsWith('#theme-')) {
61 $("[href=#picutre-themes]").trigger('click');
63 mk = $("[href=" + initial_hash + "]").eq(0);
64 self._initial_mark = self.createMark({
66 coords: mk.data('coords')
71 self.options.areas_links.hover(function() {
74 var coords = $this.data("coords");
75 this._picture_mark = self.createMark({
76 // label: $this.text(),
80 $(this._picture_mark).remove();
81 this._picture_mark = undefined;
82 }).click(function(ev) {
84 var $mark = self.element.find('.mark').eq(0);
85 var markPos = $mark.offset();
86 markPos = [markPos.left, markPos.top];
87 var markSize = [ $mark.width(), $mark.height() ]
88 var wSize = [ window.innerWidth, window.innerHeight ];
90 markPos[0] + markSize[0]/2 - wSize[0]/2,
91 markPos[1] + markSize[1]/2 - wSize[1]/2
101 currentSize: function() {
102 return [this.element.width(), this.element.height() ];
105 currentZoom: function() { return this._zoom; },
107 initOriginal: function() {
108 if (this._original_avaialble > this.ORIGINAL_LOADING &&
109 this._original_avaialble < this.ORIGINAL_SHOWN) {
110 this.element.css({'background-image': 'url('+ this.original.attr('src')+')', 'background-size': this.initial_size[0]+'px'});
111 this._original_avaialble = this.ORIGINAL_SHOWN;
115 zoom: function(steps) {
117 var t = this._zoom + steps;
118 return this.zoomTo(t);
121 zoomForStep: function(step) {
123 // max_step-1 => max %
124 if (step < 0) step = 0;
125 var zoomperc = 100 + step * this.options.step;
126 if (zoomperc * this.initial_size[0] > this.original_size[0] * 100) {
127 zoomperc = this.original_size[0] * 100 / this.initial_size[0];
132 zoomTo: function(level) {
133 var ratio = this.zoomForStep(level) / 100;
134 var new_width = ratio * this.initial_size[0];
135 var new_height = ratio * this.initial_size[1];
136 var cs = this.currentSize();
137 if (new_width == cs[0])
141 'width': new_width + 'px',
142 'height': new_height + 'px',
143 'background-size': new_width + 'px',
149 this.element.css(target);
152 allowedPosition: function(off) {
153 var x = undefined, fix_x = undefined;
154 var y = undefined, fix_y = undefined;
155 var w = this.element.width();
156 var h = this.element.height();
157 var cw = $(window).width();
158 var ch = $(window).height();
159 var off = off || this.element.offset();
186 if (fix_x !== undefined || fix_y !== undefined)
187 return { top: fix_y, left: fix_x };
195 // coords: [x, y, w, h]
197 createMark: function(mark) {
198 if (mark.label === undefined)
200 var $mark = $('<div class="mark"><div class="label">' +
201 mark.label + '</div></div>');
202 var cs = this.currentSize()
203 var ratio = cs[0] / this.original_size[0];
204 var scale = function (v) {
207 if (mark.coords[1][0] < 0 || mark.coords[1][1] < 0) { // whole
208 var s = this.original_size;
209 if (mark.coords[1][0] < 0) mark.coords[1][0] = s[0];
210 if (mark.coords[1][1] < 0) mark.coords[1][1] = s[1];
213 var coords = [[scale(mark.coords[0][0]), scale(mark.coords[0][1])],
214 [scale(mark.coords[1][0]), scale(mark.coords[1][1])]];
215 this.element.append($mark);
216 $mark.width(coords[1][0] - coords[0][0]);
217 $mark.height(coords[1][1] - coords[0][1]);
218 $mark.css({left: coords[0][0], top: coords[0][1]});
225 $(document).ready(function() {
226 $.highlightFade.defaults.speed = 3000;
228 $('.toolbar a.dropdown').each(function() {
230 $($t.attr('href')).hide().insertAfter(this);
234 $(this).removeClass('selected');
235 $($(this).attr('href')).slideUp('fast');
238 $('.toolbar a.dropdown').click(function(ev) {
239 $("#sponsors:not(:hidden)").fadeOut();
241 if ($(this).hasClass('selected')) {
244 $(this).addClass('selected');
245 $($(this).attr('href')).slideDown('fast');
246 $(this).parent().siblings(".button:has(.dropdown)").children(".dropdown").each(closeDD);
250 $(".picture-wrap").pictureviewer({
251 plus_button: $(".toolbar .button.plus"),
252 minus_button: $(".toolbar .button.minus"),
253 areas_links: $("#picture-objects a, #picture-themes a"),