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