| author | hamidouk |
| Mon, 23 Jan 2012 11:19:47 +0100 | |
| branch | popcorn-port |
| changeset 692 | 4eca4ee558a3 |
| parent 691 | 2297203d7fa3 |
| child 770 | 14d56cb5d75d |
| 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"]; |
|
689
dfd601bd2ea8
WIP - redoing the resize slice function. do not use.
hamidouk
parents:
619
diff
changeset
|
72 |
var rightHandleX = Math.floor(this.rightHandle.position()["left"]); |
| 581 | 73 |
|
| 692 | 74 |
if (Math.floor(ui.position.left) >= rightHandleX - 7) { |
| 581 | 75 |
/* prevent the handle from moving past the right handle */ |
| 692 | 76 |
ui.position.left = rightHandleX - 7; |
| 581 | 77 |
} |
|
690
b7ac9cfefda4
WIP - nearly fixed all the bugs with the sliceWidget.js. I still have got to
hamidouk
parents:
689
diff
changeset
|
78 |
|
|
b7ac9cfefda4
WIP - nearly fixed all the bugs with the sliceWidget.js. I still have got to
hamidouk
parents:
689
diff
changeset
|
79 |
this.zoneWidth = rightHandleX - Math.floor(ui.position.left) - 7; |
|
b7ac9cfefda4
WIP - nearly fixed all the bugs with the sliceWidget.js. I still have got to
hamidouk
parents:
689
diff
changeset
|
80 |
this.zoneLeft = Math.floor(ui.position.left) + 8; |
|
689
dfd601bd2ea8
WIP - redoing the resize slice function. do not use.
hamidouk
parents:
619
diff
changeset
|
81 |
|
| 537 | 82 |
this.sliceZone.css("width", this.zoneWidth); |
83 |
this.sliceZone.css("left", this.zoneLeft + "px"); |
|
|
690
b7ac9cfefda4
WIP - nearly fixed all the bugs with the sliceWidget.js. I still have got to
hamidouk
parents:
689
diff
changeset
|
84 |
this._leftHandleOldLeft = Math.floor(this._leftHandleOldLeft); |
| 537 | 85 |
this.broadcastChanges(); |
|
689
dfd601bd2ea8
WIP - redoing the resize slice function. do not use.
hamidouk
parents:
619
diff
changeset
|
86 |
|
| 537 | 87 |
}; |
88 |
||
89 |
/** handle a dragging of the right handle */ |
|
90 |
IriSP.SliceWidget.prototype.rightHandleDragged = function(event, ui) { |
|
| 691 | 91 |
/* we have a special variable, this._leftHandleOldLeft, to keep the |
92 |
previous position of the handle. We do that to know in what direction |
|
93 |
is the handle being dragged |
|
94 |
*/ |
|
| 581 | 95 |
|
| 691 | 96 |
var currentX = this.leftHandle.position()["left"]; |
97 |
var leftHandleX = Math.floor(this.leftHandle.position()["left"]); |
|
| 581 | 98 |
|
| 691 | 99 |
if (Math.floor(ui.position.left) < leftHandleX + 7) { |
100 |
/* prevent the handle from moving past the right handle */ |
|
101 |
ui.position.left = leftHandleX + 7; |
|
102 |
} |
|
| 537 | 103 |
|
| 691 | 104 |
this.zoneWidth = Math.floor(ui.position.left) - (leftHandleX + 7); |
105 |
|
|
| 537 | 106 |
this.sliceZone.css("width", this.zoneWidth); |
| 691 | 107 |
//this.sliceZone.css("left", this.zoneLeft + "px"); |
108 |
this._rightHandleOldLeft = Math.floor(this._rightHandleOldLeft); |
|
| 537 | 109 |
this.broadcastChanges(); |
110 |
}; |
|
111 |
||
112 |
/** tell to the world that the coordinates of the slice have |
|
113 |
changed |
|
114 |
*/ |
|
115 |
IriSP.SliceWidget.prototype.broadcastChanges = function() { |
|
116 |
var leftPercent = (this.zoneLeft / this.selector.width()) * 100; |
|
117 |
var zonePercent = (this.zoneWidth / this.selector.width()) * 100; |
|
118 |
|
|
| 581 | 119 |
this._Popcorn.trigger("IriSP.SliceWidget.zoneChange", [leftPercent, zonePercent]); |
| 619 | 120 |
}; |
121 |
||
122 |
IriSP.SliceWidget.prototype.show = function() { |
|
123 |
this.selector.show(); |
|
124 |
}; |
|
125 |
||
126 |
IriSP.SliceWidget.prototype.hide = function() { |
|
127 |
this.selector.hide(); |
|
| 537 | 128 |
}; |