Skip to content

Commit 6129086

Browse files
committed
Init
First upload and last if no changes or files are needed
1 parent 3ebb4d4 commit 6129086

File tree

6 files changed

+195
-0
lines changed

6 files changed

+195
-0
lines changed

Heart.png

4.34 KB
Loading

Junk.png

7.91 KB
Loading

Star.png

4.2 KB
Loading

arguments.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//Purpose: Defines all the functionality that the Gallery needs
2+
function imageGallery()
3+
{
4+
var current = 0;
5+
var overall = arguments.length - 1;
6+
var images = arguments;
7+
8+
var Gallery =
9+
{
10+
11+
Next: function()
12+
{
13+
current++
14+
15+
//Checking if it is the last image
16+
if( this.showsLastImage() )
17+
{
18+
return images[overall];
19+
}
20+
21+
return images[current];
22+
23+
},
24+
Previous: function()
25+
{
26+
current--;
27+
28+
//Checking if it is the first image
29+
if( this.showsFirstImage() )
30+
{
31+
return images[0];
32+
}
33+
34+
35+
return images[current];
36+
37+
},
38+
showsFirstImage: function()
39+
{
40+
41+
if(current < 0)
42+
{
43+
alert("This is the first image. There are no previous images!");
44+
45+
current = 0;
46+
47+
return true;
48+
}
49+
50+
},
51+
showsLastImage: function()
52+
{
53+
54+
if(current > overall)
55+
{
56+
alert("This is the last image. There are no next images!");
57+
58+
current = overall;
59+
60+
return true;
61+
}
62+
63+
}
64+
65+
}
66+
67+
return Gallery;
68+
69+
}
70+
71+
72+
73+
//Initializing Gallery
74+
var initGallery = imageGallery( "Heart.png", "Junk.png", "Star.png" );
75+
76+
77+
//Purpose: Checks which button is pressed and changes the needed Picture if possible
78+
function buttonPressed(Button)
79+
{
80+
var picture = document.getElementById('picture');
81+
82+
if(Button === "Next")
83+
{
84+
85+
picture.src = initGallery.Next();
86+
87+
}
88+
else if(Button === "Previous")
89+
{
90+
91+
picture.src = initGallery.Previous();
92+
93+
}
94+
95+
96+
}
97+
98+

index.html

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<!DOCTYPE HTML>
2+
3+
<html>
4+
5+
<head>
6+
7+
<title>"arguments" in variable</title>
8+
<meta charset = "UTF-8">
9+
10+
</head>
11+
12+
13+
<!--
14+
NOTE:
15+
===============================================================================================
16+
17+
Because of simplicity & demonstration purposes, the "style" attribute is used within html tags.
18+
Nevertheless it is recommended to use CSS for styling.
19+
20+
===============================================================================================
21+
-->
22+
23+
<!--The "style" attribute in "body" centers the whole content-->
24+
<body style="text-align: center; margin-left: auto; margin-right: auto;">
25+
26+
<h2>Image Gallery</h2>
27+
28+
<!--Also centering and defining a fixed width size-->
29+
<section style="width: 596px;
30+
margin-left: auto;
31+
margin-right: auto;">
32+
33+
34+
<!--Without "position:absolute;" resizing will not work here-->
35+
<div style="position:absolute;">
36+
37+
38+
<!--width consumes 10%-->
39+
<button style=" height: 375px;
40+
width: 10%;
41+
background-color: lightgrey;
42+
border: none;
43+
opacity: 0.5;
44+
float: left;"
45+
onclick="buttonPressed('Previous');">
46+
47+
<<
48+
</button>
49+
50+
51+
<!--width consumes 80%-->
52+
<img id="picture" src="Heart.png" style="height:375px; width:80%;">
53+
54+
55+
<!--width consumes 10% and adding all percentages results in 100% of the "div" container-->
56+
<button style=" height: 375px;
57+
width: 10%;
58+
background-color: lightgrey;
59+
border: none;
60+
opacity: 0.5;
61+
float: right;"
62+
onclick="buttonPressed('Next');">
63+
64+
>>
65+
</button>
66+
67+
68+
</div>
69+
70+
71+
</section>
72+
73+
74+
<!--An artifical gap to make the following html content beneath visible -->
75+
<div style="padding-top: 400px;"></div>
76+
77+
78+
<section>
79+
80+
81+
<hr style="width:50%;">
82+
83+
For more explanation please visit -
84+
<a href = "https://github.com/Incrementis/Javascript-save-arguments-into-a-variable-/wiki">
85+
Save arguments to a variable Wiki</a>
86+
87+
88+
</section>
89+
90+
91+
92+
</body>
93+
94+
95+
<script language="javascript" type="text/javascript" src="arguments.js"></script>
96+
97+
</html>

wiki_images/Figure1.gif

201 KB
Loading

0 commit comments

Comments
 (0)