| author | hamidouk |
| Tue, 03 Jan 2012 12:25:57 +0100 | |
| branch | popcorn-port |
| changeset 567 | ada550479aaf |
| parent 551 | 2f883ad196b2 |
| child 581 | e13380588930 |
| 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"); |
|
52 |
}; |
|
53 |
||
54 |
/** handle a dragging of the left handle */ |
|
55 |
IriSP.SliceWidget.prototype.leftHandleDragged = function(event, ui) { |
|
56 |
var currentX = this.leftHandle.position()["left"]; |
|
57 |
|
|
58 |
var increment = this.zoneLeft - (currentX + 7); |
|
59 |
|
|
60 |
this.zoneWidth += increment; |
|
61 |
this.zoneLeft = currentX + 7; |
|
62 |
this.sliceZone.css("width", this.zoneWidth); |
|
63 |
this.sliceZone.css("left", this.zoneLeft + "px"); |
|
64 |
this.broadcastChanges(); |
|
65 |
}; |
|
66 |
||
67 |
/** handle a dragging of the right handle */ |
|
68 |
IriSP.SliceWidget.prototype.rightHandleDragged = function(event, ui) { |
|
69 |
var currentX = this.rightHandle.position()["left"]; |
|
70 |
|
|
71 |
var increment = currentX - (this.zoneLeft + this.zoneWidth); |
|
72 |
||
73 |
this.zoneWidth += increment; |
|
74 |
this.sliceZone.css("width", this.zoneWidth); |
|
75 |
this.broadcastChanges(); |
|
76 |
}; |
|
77 |
||
78 |
/** tell to the world that the coordinates of the slice have |
|
79 |
changed |
|
80 |
*/ |
|
81 |
IriSP.SliceWidget.prototype.broadcastChanges = function() { |
|
82 |
var leftPercent = (this.zoneLeft / this.selector.width()) * 100; |
|
83 |
var zonePercent = (this.zoneWidth / this.selector.width()) * 100; |
|
84 |
console.log(leftPercent, zonePercent); |
|
85 |
|
|
86 |
this._Popcorn.trigger("IriSP.SliceWidget.zoneChange", [leftPercent, zonePercent]); |
|
87 |
|
|
88 |
}; |