| author | veltr |
| Wed, 18 Jan 2012 10:21:23 +0100 | |
| branch | popcorn-port |
| changeset 657 | 138160f52f14 |
| parent 619 | 2abc7d900f5e |
| child 689 | dfd601bd2ea8 |
| permissions | -rw-r--r-- |
| 537 | 1 |
/** A widget to create a new segment */ |
2 |
IriSP.SliceWidget = function(Popcorn, config, Serializer) { |
|
3 |
IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
4 |
|
|
5 |
}; |
|
6 |
||
7 |
IriSP.SliceWidget.prototype = new IriSP.Widget(); |
|
8 |
||
9 |
IriSP.SliceWidget.prototype.draw = function() { |
|
10 |
var templ = Mustache.to_html(IriSP.sliceWidget_template); |
|
11 |
this.selector.append(templ); |
|
12 |
|
|
13 |
this.sliceZone = this.selector.find(".Ldt-sliceZone"); |
|
14 |
|
|
15 |
/* global variables used to keep the position and width |
|
16 |
of the zone. |
|
17 |
*/ |
|
18 |
this.zoneLeft = 0; |
|
19 |
this.zoneWidth = 0; |
|
20 |
|
|
21 |
this.leftHandle = this.selector.find(".Ldt-sliceLeftHandle"); |
|
22 |
this.rightHandle = this.selector.find(".Ldt-sliceRightHandle"); |
|
23 |
||
24 |
this.leftHandle.draggable({axis: "x", |
|
25 |
drag: IriSP.wrap(this, this.leftHandleDragged), |
|
26 |
containment: "parent" |
|
27 |
}); |
|
28 |
||
29 |
this.rightHandle.draggable({axis: "x", |
|
30 |
drag: IriSP.wrap(this, this.rightHandleDragged), |
|
31 |
containment: "parent" |
|
32 |
}); |
|
33 |
||
|
551
2f883ad196b2
fixed display bug in webkit because jquery draggable automatically adds
hamidouk
parents:
537
diff
changeset
|
34 |
this.leftHandle.css("position", "absolute"); |
|
2f883ad196b2
fixed display bug in webkit because jquery draggable automatically adds
hamidouk
parents:
537
diff
changeset
|
35 |
this.rightHandle.css("position", "absolute"); |
| 537 | 36 |
|
37 |
this._Popcorn.listen("IriSP.SliceWidget.position", |
|
38 |
IriSP.wrap(this, this.positionSliceHandler)); |
|
| 619 | 39 |
|
40 |
this._Popcorn.listen("IriSP.SliceWidget.show", IriSP.wrap(this, this.show)); |
|
41 |
this._Popcorn.listen("IriSP.SliceWidget.hide", IriSP.wrap(this, this.hide)); |
|
42 |
this.selector.hide(); |
|
| 537 | 43 |
}; |
44 |
||
| 619 | 45 |
/** responds to an "IriSP.SliceWidget.position" message |
46 |
@param params an array with the first element being the left distance in |
|
47 |
percents and the second element the width of the slice in pixels |
|
48 |
*/ |
|
| 537 | 49 |
IriSP.SliceWidget.prototype.positionSliceHandler = function(params) { |
50 |
left = params[0]; |
|
51 |
width = params[1]; |
|
52 |
|
|
53 |
this.zoneLeft = left; |
|
54 |
this.zoneWidth = width; |
|
55 |
this.sliceZone.css("left", left + "px"); |
|
56 |
this.sliceZone.css("width", width + "px"); |
|
57 |
this.leftHandle.css("left", (left - 7) + "px"); |
|
58 |
this.rightHandle.css("left", left + width + "px"); |
|
| 581 | 59 |
|
60 |
this._leftHandleOldLeft = left - 7; |
|
61 |
this._rightHandleOldLeft = left + width; |
|
| 537 | 62 |
}; |
63 |
||
64 |
/** handle a dragging of the left handle */ |
|
65 |
IriSP.SliceWidget.prototype.leftHandleDragged = function(event, ui) { |
|
| 581 | 66 |
/* we have a special variable, this._leftHandleOldLeft, to keep the |
67 |
previous position of the handle. We do that to know in what direction |
|
68 |
is the handle being dragged |
|
69 |
*/ |
|
70 |
|
|
| 537 | 71 |
var currentX = this.leftHandle.position()["left"]; |
| 581 | 72 |
var rightHandleX = this.rightHandle.position()["left"]; |
73 |
|
|
74 |
if (currentX >= rightHandleX - 7 && ui.position.left >= this._leftHandleOldLeft) { |
|
75 |
/* prevent the handle from moving past the right handle */ |
|
76 |
ui.position.left = this._leftHandleOldLeft; |
|
77 |
} |
|
78 |
|
|
| 537 | 79 |
var increment = this.zoneLeft - (currentX + 7); |
80 |
|
|
81 |
this.zoneWidth += increment; |
|
82 |
this.zoneLeft = currentX + 7; |
|
83 |
this.sliceZone.css("width", this.zoneWidth); |
|
84 |
this.sliceZone.css("left", this.zoneLeft + "px"); |
|
85 |
this.broadcastChanges(); |
|
| 581 | 86 |
|
87 |
this._leftHandleOldLeft = ui.position.left; |
|
| 537 | 88 |
}; |
89 |
||
90 |
/** handle a dragging of the right handle */ |
|
91 |
IriSP.SliceWidget.prototype.rightHandleDragged = function(event, ui) { |
|
92 |
var currentX = this.rightHandle.position()["left"]; |
|
| 581 | 93 |
var leftHandleX = this.leftHandle.position()["left"]; |
94 |
|
|
95 |
if (currentX <= leftHandleX + 7 && ui.position.left <= this._rightHandleOldLeft) { |
|
96 |
/* prevent the handle from moving past the right handle */ |
|
97 |
ui.position.left = this._rightHandleOldLeft; |
|
98 |
} |
|
99 |
|
|
| 537 | 100 |
var increment = currentX - (this.zoneLeft + this.zoneWidth); |
101 |
||
102 |
this.zoneWidth += increment; |
|
103 |
this.sliceZone.css("width", this.zoneWidth); |
|
104 |
this.broadcastChanges(); |
|
| 581 | 105 |
|
106 |
this._rightHandleOldLeft = ui.position.left; |
|
| 537 | 107 |
}; |
108 |
||
109 |
/** tell to the world that the coordinates of the slice have |
|
110 |
changed |
|
111 |
*/ |
|
112 |
IriSP.SliceWidget.prototype.broadcastChanges = function() { |
|
113 |
var leftPercent = (this.zoneLeft / this.selector.width()) * 100; |
|
114 |
var zonePercent = (this.zoneWidth / this.selector.width()) * 100; |
|
115 |
|
|
| 581 | 116 |
this._Popcorn.trigger("IriSP.SliceWidget.zoneChange", [leftPercent, zonePercent]); |
| 619 | 117 |
}; |
118 |
||
119 |
IriSP.SliceWidget.prototype.show = function() { |
|
120 |
this.selector.show(); |
|
121 |
}; |
|
122 |
||
123 |
IriSP.SliceWidget.prototype.hide = function() { |
|
124 |
this.selector.hide(); |
|
| 537 | 125 |
}; |