3 $.widget('wl.pictureviewer', {
6 steps: 6, // steps of zoom
7 max: 300, // max zoom in percent
8 plus_button: undefined,
9 minus_button: undefined
19 self.initial_position = self.element.offset();
23 'position': 'absolute',
25 self.element.offset(self.initial_position);
27 if (self.options.plus_button)
28 self.options.plus_button.click(
29 function(ev) { self.zoom(1); });
30 if (self.options.minus_button)
31 self.options.minus_button.click(
32 function(ev) { self.zoom(-1); });
34 function contain(event, ui) {
35 var fix = self.allowedPosition(ui.position);
36 console.log("fix: ", fix);
37 if (fix !== undefined) {
41 self.element.draggable({drag: contain});
46 zoom: function(steps) {
47 var t = this._zoom + steps;
48 return this.zoomTo(t);
51 zoomForStep: function(step) {
53 // max_step-1 => max %
54 return 100 + (this.options.max - 100) / this.options.steps * step
57 zoomTo: function(level) {
58 if (level < 0 || level > this.options.steps)
60 var ratio = this.zoomForStep(level) / 100;
61 var new_width = ratio * this.initial_size[0];
62 var new_height = ratio * this.initial_size[1];
65 'left': this.initial_position.left - (new_width - this.initial_size[0])/2,
66 'top': this.initial_position.top - (new_height - this.initial_size[1])/2,
69 this.element.animate(target, 200); // default duration=400
72 allowedPosition: function(off) {
73 var x = undefined, fix_x = undefined;
74 var y = undefined, fix_y = undefined;
75 var w = this.element.width();
76 var h = this.element.height();
77 var cw = $(window).width();
78 var ch = $(window).height();
79 var off = off || this.element.offset();
106 if (fix_x !== undefined || fix_y !== undefined)
107 return { top: fix_y, left: fix_x };
115 $(document).ready(function(){
116 $("img.canvas").pictureviewer({
117 plus_button: $(".toolbar .button.plus"),
118 minus_button: $(".toolbar .button.minus")