| author | hamidouk |
| Mon, 09 Jan 2012 17:23:08 +0100 | |
| branch | popcorn-port |
| changeset 602 | b35862f9b0b0 |
| parent 581 | e13380588930 |
| child 619 | 2abc7d900f5e |
| 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)); |
|
39 |
this._Popcorn.trigger("IriSP.SliceWidget.position", [57, 24]); |
|
40 |
}; |
|
41 |
||
42 |
IriSP.SliceWidget.prototype.positionSliceHandler = function(params) { |
|
43 |
left = params[0]; |
|
44 |
width = params[1]; |
|
45 |
|
|
46 |
this.zoneLeft = left; |
|
47 |
this.zoneWidth = width; |
|
48 |
this.sliceZone.css("left", left + "px"); |
|
49 |
this.sliceZone.css("width", width + "px"); |
|
50 |
this.leftHandle.css("left", (left - 7) + "px"); |
|
51 |
this.rightHandle.css("left", left + width + "px"); |
|
| 581 | 52 |
|
53 |
this._leftHandleOldLeft = left - 7; |
|
54 |
this._rightHandleOldLeft = left + width; |
|
| 537 | 55 |
}; |
56 |
||
57 |
/** handle a dragging of the left handle */ |
|
58 |
IriSP.SliceWidget.prototype.leftHandleDragged = function(event, ui) { |
|
| 581 | 59 |
/* we have a special variable, this._leftHandleOldLeft, to keep the |
60 |
previous position of the handle. We do that to know in what direction |
|
61 |
is the handle being dragged |
|
62 |
*/ |
|
63 |
|
|
| 537 | 64 |
var currentX = this.leftHandle.position()["left"]; |
| 581 | 65 |
var rightHandleX = this.rightHandle.position()["left"]; |
66 |
|
|
67 |
if (currentX >= rightHandleX - 7 && ui.position.left >= this._leftHandleOldLeft) { |
|
68 |
/* prevent the handle from moving past the right handle */ |
|
69 |
ui.position.left = this._leftHandleOldLeft; |
|
70 |
} |
|
71 |
|
|
| 537 | 72 |
var increment = this.zoneLeft - (currentX + 7); |
73 |
|
|
74 |
this.zoneWidth += increment; |
|
75 |
this.zoneLeft = currentX + 7; |
|
76 |
this.sliceZone.css("width", this.zoneWidth); |
|
77 |
this.sliceZone.css("left", this.zoneLeft + "px"); |
|
78 |
this.broadcastChanges(); |
|
| 581 | 79 |
|
80 |
this._leftHandleOldLeft = ui.position.left; |
|
| 537 | 81 |
}; |
82 |
||
83 |
/** handle a dragging of the right handle */ |
|
84 |
IriSP.SliceWidget.prototype.rightHandleDragged = function(event, ui) { |
|
85 |
var currentX = this.rightHandle.position()["left"]; |
|
| 581 | 86 |
var leftHandleX = this.leftHandle.position()["left"]; |
87 |
|
|
88 |
if (currentX <= leftHandleX + 7 && ui.position.left <= this._rightHandleOldLeft) { |
|
89 |
/* prevent the handle from moving past the right handle */ |
|
90 |
ui.position.left = this._rightHandleOldLeft; |
|
91 |
} |
|
92 |
|
|
| 537 | 93 |
var increment = currentX - (this.zoneLeft + this.zoneWidth); |
94 |
||
95 |
this.zoneWidth += increment; |
|
96 |
this.sliceZone.css("width", this.zoneWidth); |
|
97 |
this.broadcastChanges(); |
|
| 581 | 98 |
|
99 |
this._rightHandleOldLeft = ui.position.left; |
|
| 537 | 100 |
}; |
101 |
||
102 |
/** tell to the world that the coordinates of the slice have |
|
103 |
changed |
|
104 |
*/ |
|
105 |
IriSP.SliceWidget.prototype.broadcastChanges = function() { |
|
106 |
var leftPercent = (this.zoneLeft / this.selector.width()) * 100; |
|
107 |
var zonePercent = (this.zoneWidth / this.selector.width()) * 100; |
|
108 |
|
|
| 581 | 109 |
this._Popcorn.trigger("IriSP.SliceWidget.zoneChange", [leftPercent, zonePercent]); |
| 537 | 110 |
}; |