Skip to content

Commit eff793d

Browse files
committed
Copied position plugin from /branches/dev/positionTo r2971.
1 parent bfca009 commit eff793d

9 files changed

Lines changed: 900 additions & 0 deletions

File tree

demos/position/cycler.html

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>jQuery UI Position - Default functionality</title>
5+
<link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
6+
<script type="text/javascript" src="../../jquery-1.3.2.js"></script>
7+
<script type="text/javascript" src="../../ui/ui.core.js"></script>
8+
<script type="text/javascript" src="../../ui/ui.draggable.js"></script>
9+
<script type="text/javascript" src="../../ui/ui.position.js"></script>
10+
<link type="text/css" href="../demos.css" rel="stylesheet" />
11+
12+
<style type="text/css">
13+
html, body {
14+
margin: 0;
15+
padding: 0
16+
}
17+
</style>
18+
19+
<script type="text/javascript">
20+
$(function() {
21+
22+
$.fn.position2 = function(options) {
23+
return this.position($.extend({
24+
of: window,
25+
by: function(to) {
26+
$(this).css({
27+
top: to.top,
28+
left: to.left
29+
})
30+
},
31+
collision: "none"
32+
}, options));
33+
}
34+
35+
$.fn.left = function(by) {
36+
return this.position2({
37+
my: "right middle",
38+
at: "left middle",
39+
offset: "25 0",
40+
by: by
41+
});
42+
}
43+
$.fn.right = function(by) {
44+
return this.position2({
45+
my: "left middle",
46+
at: "right middle",
47+
offset: "-25 0",
48+
by: by
49+
});
50+
}
51+
$.fn.center = function(by) {
52+
return this.position2({
53+
my: "center middle",
54+
at: "center middle",
55+
by: by
56+
});
57+
};
58+
59+
$("img:eq(0)").left();
60+
$("img:eq(1)").center();
61+
$("img:eq(2)").right();
62+
63+
$("body").css({
64+
overflow: "hidden"
65+
})
66+
$(".demo").css({
67+
position: "relative",
68+
});
69+
$(".demo img").css({
70+
position: "absolute",
71+
});
72+
73+
function animate(to) {
74+
$(this).animate(to);
75+
}
76+
function next() {
77+
$("img:eq(2)").center(animate);
78+
$("img:eq(1)").left(animate)
79+
$("img:eq(0)").right().appendTo(".demo");
80+
}
81+
function previous() {
82+
$("img:eq(0)").center(animate);
83+
$("img:eq(1)").right(animate);
84+
$("img:eq(2)").left().prependTo(".demo");
85+
}
86+
$("#previous").click(previous);
87+
$("#next").click(next);
88+
89+
$(".demo img").click(function() {
90+
$(".demo img").index(this) == 0 ? previous() : next();
91+
});
92+
93+
$(window).resize(function() {
94+
$("img:eq(0)").left(animate);
95+
$("img:eq(1)").center(animate);
96+
$("img:eq(2)").right(animate);
97+
})
98+
});
99+
</script>
100+
101+
</head>
102+
<body>
103+
104+
<div class="demo">
105+
106+
<img src="images/earth.jpg" />
107+
<img src="images/flight.jpg" />
108+
<img src="images/rocket.jpg" />
109+
110+
<a id="previous" href="#">Previous</a>
111+
<a id="next" href="#">Next</a>
112+
</div>
113+
114+
<div class="demo-description">
115+
116+
<p>A prototype for the <a href="http://wiki.jqueryui.com/Photoviewer">Photoviewer</a> using Position to place images at the center, left and right and cycle them.
117+
<br/>Use the links at the top to cycle, or click on the images on the left and right.
118+
<br/>Note how the images are repositioned when resizing the window.
119+
<br/>Warning: Doesn't currently work inside the demo viewer; open in a new window instead!</p>
120+
121+
</div><!-- End demo-description -->
122+
123+
</body>
124+
</html>

demos/position/default.html

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>jQuery UI Position - Default functionality</title>
5+
<link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
6+
<script type="text/javascript" src="../../jquery-1.3.2.js"></script>
7+
<script type="text/javascript" src="../../ui/ui.core.js"></script>
8+
<script type="text/javascript" src="../../ui/ui.draggable.js"></script>
9+
<script type="text/javascript" src="../../ui/ui.position.js"></script>
10+
<link type="text/css" href="../demos.css" rel="stylesheet" />
11+
12+
<style type="text/css">
13+
div#parent
14+
{
15+
width: 60%;
16+
margin: 10px auto;
17+
padding: 5px;
18+
19+
border: 1px solid #777;
20+
background-color: #fbca93;
21+
text-align: center;
22+
}
23+
24+
div.positionable
25+
{
26+
width: 75px;
27+
height: 75px;
28+
display: block;
29+
position: fixed;
30+
right: 0;
31+
bottom: 0;
32+
33+
background-color: #bcd5e6;
34+
text-align: center;
35+
}
36+
37+
select, input
38+
{
39+
margin-left: 15px;
40+
}
41+
</style>
42+
43+
<script type="text/javascript">
44+
$(function() {
45+
46+
function position(by) {
47+
$('.positionable').position({
48+
of: $('#parent'),
49+
my: $('#my_horizontal').val() + ' ' + $('#my_vertical').val(),
50+
at: $('#at_horizontal').val() + ' '+ $('#at_vertical').val(),
51+
offset: $('#offset').val(),
52+
by: by,
53+
collision: $("#collision_horizontal").val() + ' ' + $("#collision_vertical").val()
54+
});
55+
}
56+
57+
$('.positionable').css("opacity", 0.5);
58+
59+
$(':input').bind('click keyup change', position);
60+
61+
$("#parent").draggable({
62+
drag: position
63+
});
64+
65+
$('.positionable').draggable({
66+
drag: function(event, ui) {
67+
// reset offset before calculating it
68+
$("#offset").val("0");
69+
position(function(result) {
70+
$("#offset").val("" + (ui.offset.left - result.left) + " " + (ui.offset.top - result.top));
71+
position();
72+
});
73+
}
74+
});
75+
76+
position();
77+
});
78+
</script>
79+
80+
</head>
81+
<body>
82+
83+
<div class="demo">
84+
85+
<div id="parent">
86+
<p>
87+
This is the position parent element.
88+
</p>
89+
</div>
90+
91+
<div class="positionable">
92+
<p>
93+
to position
94+
</p>
95+
</div>
96+
97+
<div class="positionable" style="width:120px; height: 40px;">
98+
<p>
99+
to position 2
100+
</p>
101+
</div>
102+
103+
<div style="padding: 20px; margin-top: 75px;">
104+
position...
105+
<div style="padding-bottom: 20px;">
106+
<b>my:</b>
107+
<select id="my_horizontal">
108+
<option value="left">left</option>
109+
<option value="center">center</option>
110+
<option value="right">right</option>
111+
</select>
112+
<select id="my_vertical">
113+
<option value="top">top</option>
114+
<option value="middle">center</option>
115+
<option value="bottom">bottom</option>
116+
</select>
117+
</div>
118+
<div style="padding-bottom: 20px;">
119+
<b>at:</b>
120+
<select id="at_horizontal">
121+
<option value="left">left</option>
122+
<option value="center">center</option>
123+
<option value="right">right</option>
124+
</select>
125+
<select id="at_vertical">
126+
<option value="top">top</option>
127+
<option value="middle">center</option>
128+
<option value="bottom">bottom</option>
129+
</select>
130+
</div>
131+
<div style="padding-bottom: 20px;">
132+
<b>offset:</b>
133+
<input id="offset" type="text" size="15"/>
134+
</div>
135+
<div style="padding-bottom: 20px;">
136+
<b>collision:</b>
137+
<select id="collision_horizontal">
138+
<option value="flip">flip</option>
139+
<option value="fit">fit</option>
140+
<option value="none">none</option>
141+
</select>
142+
<select id="collision_vertical">
143+
<option value="flip">flip</option>
144+
<option value="fit">fit</option>
145+
<option value="none">none</option>
146+
</select>
147+
</div>
148+
</div>
149+
150+
<div class="demo-description">
151+
152+
<p>Use the form controls to configure the positioning, or drag the positioned element to modify its offset.
153+
<br/>Drag around the parent element to see collision detection in action.</p>
154+
155+
</div><!-- End demo-description -->
156+
157+
</body>
158+
</html>

demos/position/images/earth.jpg

34.2 KB
Loading

demos/position/images/flight.jpg

34.4 KB
Loading

demos/position/images/rocket.jpg

49.9 KB
Loading

demos/position/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>jQuery UI Position Demo</title>
5+
<link type="text/css" href="../demos.css" rel="stylesheet" />
6+
</head>
7+
<body>
8+
9+
<div class="demos-nav">
10+
<h4>Examples</h4>
11+
<ul>
12+
<li class="demo-config-on"><a href="default.html">Default functionality</a></li>
13+
<li><a href="cycler.html">Cycling images</a></li>
14+
</ul>
15+
</div>
16+
17+
</body>
18+
</html>

tests/unit/position/position.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>jQuery UI Position Test Suite</title>
5+
6+
<script type="text/javascript" src="../../../jquery-1.3.2.js"></script>
7+
<script type="text/javascript" src="../../../ui/ui.core.js"></script>
8+
<script type="text/javascript" src="../../../ui/ui.position.js"></script>
9+
10+
<link type="text/css" href="../testsuite.css" rel="stylesheet" />
11+
<script type="text/javascript" src="../testsuite.js"></script>
12+
<script type="text/javascript" src="../../../external/testrunner-r6343.js"></script>
13+
14+
<script type="text/javascript" src="position_core.js"></script>
15+
</head>
16+
<body>
17+
18+
<div id="main" style="top: 0; left: 0;">
19+
<div id="el1" style="position: absolute; width: 6px; height: 6px;"></div>
20+
<div id="el2" style="position: absolute; width: 6px; height: 6px;"></div>
21+
<div id="parent" style="position: absolute; width: 6px; height: 6px; top: 4px; left: 4px;"></div>
22+
</div>
23+
24+
<div style="position: absolute; top: 0px; left: 0px">
25+
<div id="elx" style="position: absolute; width: 10px; height: 10px;"></div>
26+
<div id="parentx" style="position: absolute; width: 20px; height: 20px; top: 40px; left: 40px;"></div>
27+
</div>
28+
29+
<div style="position: absolute; top: 200px; left: 100px;">
30+
<div id="el-offset-100-200" style="position: absolute; width: 10px; height: 10px;"></div>
31+
<div style="position: absolute; top: 100px; left: 50px;">
32+
<div id="el-two-offset-150-300" style="position: absolute; width: 10px; height: 10px;"></div>
33+
<div id="el-fixed" style="position: fixed; top: 200px; left: 200px;"></div>
34+
</div>
35+
</div>
36+
37+
<div style="position: absolute; height: 5000px; width: 5000px;"></div>
38+
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)