| author | hamidouk |
| Fri, 03 Feb 2012 15:30:56 +0100 | |
| branch | popcorn-port |
| changeset 772 | feb3e5194502 |
| parent 770 | 14d56cb5d75d |
| child 774 | 25cb63882c3c |
| 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 |
||
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
24 |
var left = this.selector.offset().left; |
|
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
25 |
var top = this.selector.offset().top; |
| 772 | 26 |
|
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
27 |
// contain the handles correctly - we cannot set |
|
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
28 |
// containment: parent because it wouldn't allow to select the |
|
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
29 |
// whole slice, so we have to compute a box in which the slice is |
|
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
30 |
// allowed to move. |
|
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
31 |
var containment = [left - 8, top, this.selector.width() + left, top]; |
| 772 | 32 |
// var containment = [left - 16, top, this.selector.width() + left - 8, top]; |
| 537 | 33 |
this.leftHandle.draggable({axis: "x", |
34 |
drag: IriSP.wrap(this, this.leftHandleDragged), |
|
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
35 |
containment: containment |
| 537 | 36 |
}); |
37 |
||
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
38 |
containment = [left, top, this.selector.width() + left, top]; |
| 772 | 39 |
// containment = [left, top, this.selector.width() + left - 8, top]; |
| 537 | 40 |
this.rightHandle.draggable({axis: "x", |
41 |
drag: IriSP.wrap(this, this.rightHandleDragged), |
|
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
42 |
containment: containment |
| 537 | 43 |
}); |
44 |
||
|
551
2f883ad196b2
fixed display bug in webkit because jquery draggable automatically adds
hamidouk
parents:
537
diff
changeset
|
45 |
this.leftHandle.css("position", "absolute"); |
|
2f883ad196b2
fixed display bug in webkit because jquery draggable automatically adds
hamidouk
parents:
537
diff
changeset
|
46 |
this.rightHandle.css("position", "absolute"); |
| 537 | 47 |
|
48 |
this._Popcorn.listen("IriSP.SliceWidget.position", |
|
49 |
IriSP.wrap(this, this.positionSliceHandler)); |
|
| 619 | 50 |
|
51 |
this._Popcorn.listen("IriSP.SliceWidget.show", IriSP.wrap(this, this.show)); |
|
52 |
this._Popcorn.listen("IriSP.SliceWidget.hide", IriSP.wrap(this, this.hide)); |
|
53 |
this.selector.hide(); |
|
| 537 | 54 |
}; |
55 |
||
| 619 | 56 |
/** responds to an "IriSP.SliceWidget.position" message |
57 |
@param params an array with the first element being the left distance in |
|
58 |
percents and the second element the width of the slice in pixels |
|
59 |
*/ |
|
| 537 | 60 |
IriSP.SliceWidget.prototype.positionSliceHandler = function(params) { |
61 |
left = params[0]; |
|
62 |
width = params[1]; |
|
63 |
|
|
64 |
this.zoneLeft = left; |
|
65 |
this.zoneWidth = width; |
|
66 |
this.sliceZone.css("left", left + "px"); |
|
67 |
this.sliceZone.css("width", width + "px"); |
|
68 |
this.leftHandle.css("left", (left - 7) + "px"); |
|
69 |
this.rightHandle.css("left", left + width + "px"); |
|
| 581 | 70 |
|
71 |
this._leftHandleOldLeft = left - 7; |
|
72 |
this._rightHandleOldLeft = left + width; |
|
| 537 | 73 |
}; |
74 |
||
75 |
/** handle a dragging of the left handle */ |
|
76 |
IriSP.SliceWidget.prototype.leftHandleDragged = function(event, ui) { |
|
| 581 | 77 |
/* we have a special variable, this._leftHandleOldLeft, to keep the |
78 |
previous position of the handle. We do that to know in what direction |
|
79 |
is the handle being dragged |
|
80 |
*/ |
|
81 |
|
|
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
82 |
var currentX = this.leftHandle.offset().left; |
|
689
dfd601bd2ea8
WIP - redoing the resize slice function. do not use.
hamidouk
parents:
619
diff
changeset
|
83 |
var rightHandleX = Math.floor(this.rightHandle.position()["left"]); |
| 581 | 84 |
|
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
85 |
var container_offset = this.selector.offset().left; |
|
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
86 |
|
| 692 | 87 |
if (Math.floor(ui.position.left) >= rightHandleX - 7) { |
| 581 | 88 |
/* prevent the handle from moving past the right handle */ |
| 692 | 89 |
ui.position.left = rightHandleX - 7; |
| 581 | 90 |
} |
|
690
b7ac9cfefda4
WIP - nearly fixed all the bugs with the sliceWidget.js. I still have got to
hamidouk
parents:
689
diff
changeset
|
91 |
|
|
b7ac9cfefda4
WIP - nearly fixed all the bugs with the sliceWidget.js. I still have got to
hamidouk
parents:
689
diff
changeset
|
92 |
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
|
93 |
this.zoneLeft = Math.floor(ui.position.left) + 8; |
|
689
dfd601bd2ea8
WIP - redoing the resize slice function. do not use.
hamidouk
parents:
619
diff
changeset
|
94 |
|
| 537 | 95 |
this.sliceZone.css("width", this.zoneWidth); |
96 |
this.sliceZone.css("left", this.zoneLeft + "px"); |
|
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
97 |
|
|
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
98 |
this._leftHandleOldLeft = ui.position.left; |
| 537 | 99 |
this.broadcastChanges(); |
|
689
dfd601bd2ea8
WIP - redoing the resize slice function. do not use.
hamidouk
parents:
619
diff
changeset
|
100 |
|
| 537 | 101 |
}; |
102 |
||
103 |
/** handle a dragging of the right handle */ |
|
104 |
IriSP.SliceWidget.prototype.rightHandleDragged = function(event, ui) { |
|
| 691 | 105 |
/* we have a special variable, this._leftHandleOldLeft, to keep the |
106 |
previous position of the handle. We do that to know in what direction |
|
107 |
is the handle being dragged |
|
108 |
*/ |
|
| 581 | 109 |
|
| 691 | 110 |
var currentX = this.leftHandle.position()["left"]; |
111 |
var leftHandleX = Math.floor(this.leftHandle.position()["left"]); |
|
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
112 |
|
|
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
113 |
var container_offset = this.selector.offset().left + this.selector.width(); |
| 581 | 114 |
|
| 691 | 115 |
if (Math.floor(ui.position.left) < leftHandleX + 7) { |
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
116 |
/* prevent the handle from moving past the left handle */ |
| 691 | 117 |
ui.position.left = leftHandleX + 7; |
118 |
} |
|
| 537 | 119 |
|
| 691 | 120 |
this.zoneWidth = Math.floor(ui.position.left) - (leftHandleX + 7); |
121 |
|
|
| 537 | 122 |
this.sliceZone.css("width", this.zoneWidth); |
| 691 | 123 |
//this.sliceZone.css("left", this.zoneLeft + "px"); |
124 |
this._rightHandleOldLeft = Math.floor(this._rightHandleOldLeft); |
|
| 537 | 125 |
this.broadcastChanges(); |
126 |
}; |
|
127 |
||
128 |
/** tell to the world that the coordinates of the slice have |
|
129 |
changed |
|
130 |
*/ |
|
131 |
IriSP.SliceWidget.prototype.broadcastChanges = function() { |
|
132 |
var leftPercent = (this.zoneLeft / this.selector.width()) * 100; |
|
133 |
var zonePercent = (this.zoneWidth / this.selector.width()) * 100; |
|
|
770
14d56cb5d75d
fixed the sliceWidget to allow selecting the whole range.
hamidouk
parents:
692
diff
changeset
|
134 |
|
| 581 | 135 |
this._Popcorn.trigger("IriSP.SliceWidget.zoneChange", [leftPercent, zonePercent]); |
| 619 | 136 |
}; |
137 |
||
138 |
IriSP.SliceWidget.prototype.show = function() { |
|
139 |
this.selector.show(); |
|
140 |
}; |
|
141 |
||
142 |
IriSP.SliceWidget.prototype.hide = function() { |
|
143 |
this.selector.hide(); |
|
| 537 | 144 |
}; |