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