Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
my-cucumbers-ru-github-io
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Лотуга Данила Сергеевич
my-cucumbers-ru-github-io
Commits
86b56ba2
Commit
86b56ba2
authored
Aug 09, 2011
by
Oleg Roschupkin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '#4_inner_navigation' into new
parents
bb7407a0
df3401ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
77 deletions
+137
-77
en.htm
en.htm
+3
-3
script.js
scripts/script.js
+134
-74
No files found.
en.htm
View file @
86b56ba2
...
...
@@ -172,7 +172,7 @@
After activation of the last child pressing next
button will turn next slide.
-->
<div
class=
"slide"
id=
"InnerNavigation"
><div>
<section>
<header>
...
...
@@ -185,7 +185,7 @@
<li>
Erase your hard drive.
</li>
</ol>
</section>
</div></div>
-->
</div></div>
<div
class=
"slide"
id=
"ThankYou"
><div>
<section>
<header>
...
...
@@ -208,4 +208,4 @@
<script
src=
"scripts/script.js"
></script>
<!-- Copyright © 2010–2011 Vadim Makeev, http://pepelsbey.net/ -->
</body>
</html>
\ No newline at end of file
</html>
scripts/script.js
View file @
86b56ba2
...
...
@@ -4,11 +4,13 @@
slides
=
document
.
querySelectorAll
(
'div.slide'
),
progress
=
document
.
querySelector
(
'div.progress div'
),
slideList
=
[],
l
=
slides
.
length
,
i
;
l
=
slides
.
length
,
i
;
for
(
i
=
0
;
i
<
l
;
i
++
)
{
slideList
.
push
(
slides
[
i
].
id
);
slideList
.
push
({
id
:
slides
[
i
].
id
,
hasInnerNavigation
:
null
!==
slides
[
i
].
querySelector
(
'.inner'
)
});
}
function
getTransform
()
{
...
...
@@ -28,62 +30,73 @@
body
.
style
.
transform
=
transform
;
}
function
enterS
ingleS
lideMode
()
{
function
enterSlideMode
()
{
body
.
className
=
'full'
;
applyTransform
(
getTransform
());
}
function
enter
Slide
ListMode
()
{
function
enterListMode
()
{
body
.
className
=
'list'
;
applyTransform
(
'none'
);
}
function
getCurrentSlideNumber
()
{
return
slideList
.
indexOf
(
url
.
hash
.
substr
(
1
));
var
i
,
l
=
slideList
.
length
,
currentSlideId
=
url
.
hash
.
substr
(
1
);
for
(
i
=
0
;
i
<
l
;
++
i
)
{
if
(
currentSlideId
===
slideList
[
i
].
id
)
{
return
i
;
}
}
return
-
1
;
}
function
scrollToCurrentSlide
()
{
var
current_slide
=
document
.
getElementById
(
slideList
[
getCurrentSlideNumber
()]);
var
currentSlide
=
document
.
getElementById
(
slideList
[
getCurrentSlideNumber
()].
id
);
if
(
null
!=
current
_s
lide
)
{
window
.
scrollTo
(
0
,
current
_s
lide
.
offsetTop
);
if
(
null
!=
current
S
lide
)
{
window
.
scrollTo
(
0
,
current
S
lide
.
offsetTop
);
}
}
function
is
Slide
ListMode
()
{
function
isListMode
()
{
return
'full'
!==
url
.
search
.
substr
(
1
);
}
function
normalizeSlideNumber
(
slide
_n
umber
)
{
if
(
0
>
slide
_n
umber
)
{
function
normalizeSlideNumber
(
slide
N
umber
)
{
if
(
0
>
slide
N
umber
)
{
return
slideList
.
length
-
1
;
}
else
if
(
slideList
.
length
<=
slide
_n
umber
)
{
}
else
if
(
slideList
.
length
<=
slide
N
umber
)
{
return
0
;
}
else
{
return
slide
_n
umber
;
return
slide
N
umber
;
}
}
function
updateProgress
(
slide
_n
umber
)
{
if
(
!
progress
)
return
;
progress
.
style
.
width
=
(
100
/
(
slideList
.
length
-
1
)
*
normalizeSlideNumber
(
slide
_n
umber
)).
toFixed
(
2
)
+
'%'
;
function
updateProgress
(
slide
N
umber
)
{
if
(
null
===
progress
)
{
return
;
}
progress
.
style
.
width
=
(
100
/
(
slideList
.
length
-
1
)
*
normalizeSlideNumber
(
slide
N
umber
)).
toFixed
(
2
)
+
'%'
;
}
function
getSlideHash
ByNumber
(
slide_n
umber
)
{
return
'#'
+
slideList
[
normalizeSlideNumber
(
slide
_number
)]
;
function
getSlideHash
(
slideN
umber
)
{
return
'#'
+
slideList
[
normalizeSlideNumber
(
slide
Number
)].
id
;
}
function
goToSlide
(
slide
_n
umber
)
{
url
.
hash
=
getSlideHash
ByNumber
(
slide_n
umber
);
function
goToSlide
(
slide
N
umber
)
{
url
.
hash
=
getSlideHash
(
slideN
umber
);
if
(
!
is
Slide
ListMode
())
{
updateProgress
(
slide
_n
umber
);
if
(
!
isListMode
())
{
updateProgress
(
slide
N
umber
);
}
}
function
getContainingSlideId
(
el
)
{
var
node
=
el
;
while
(
'BODY'
!==
node
.
nodeName
)
{
while
(
'BODY'
!==
node
.
nodeName
&&
'HTML'
!==
node
.
nodeName
)
{
if
(
-
1
!==
node
.
className
.
indexOf
(
'slide'
))
{
return
node
.
id
;
}
else
{
...
...
@@ -93,82 +106,115 @@
return
''
;
}
function
dispatchSingleSlideMode
(
e
)
{
var
slideId
=
getContainingSlideId
(
e
.
target
);
if
(
''
!==
slideId
&&
is
Slide
ListMode
())
{
if
(
''
!==
slideId
&&
isListMode
())
{
e
.
preventDefault
();
// NOTE: we should update hash to get things work properly
url
.
hash
=
'#'
+
slideId
;
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full#'
+
slideId
);
enterS
ingleS
lideMode
();
enterSlideMode
();
updateProgress
(
getCurrentSlideNumber
());
}
}
// Increases inner navigation by adding 'active' class to next inactive
// inner navigation item.
function
increaseInnerNavigation
(
slideNumber
)
{
// Shortcut for slides without inner navigation
if
(
true
!==
slideList
[
slideNumber
].
hasInnerNavigation
)
{
return
-
1
;
}
var
activeNodes
=
document
.
querySelectorAll
(
getSlideHash
(
slideNumber
)
+
' .active'
),
// NOTE: we assume there is no other elements in inner navigation
node
=
activeNodes
[
activeNodes
.
length
-
1
].
nextElementSibling
;
if
(
null
!==
node
)
{
node
.
classList
.
add
(
'active'
);
// NOTE: 'auto-added' class is used in resetInnerNavigation - to
// overcome problems with manually added 'active' class.
node
.
classList
.
add
(
'auto-added'
);
return
activeNodes
.
length
+
1
;
}
else
{
return
-
1
;
}
}
// Resets inner navigation by removing 'active' class from all previously
// activated elements.
function
resetInnerNavigation
(
slideNumber
)
{
// Shortcut for slides without inner navigation
if
(
true
!==
slideList
[
slideNumber
].
hasInnerNavigation
)
{
return
;
}
var
activeNodes
=
document
.
querySelectorAll
(
getSlideHash
(
slideNumber
)
+
' .active.auto-added'
),
i
=
0
,
l
;
for
(
l
=
activeNodes
.
length
;
i
<
l
;
i
++
)
{
activeNodes
[
i
].
classList
.
remove
(
'active'
);
activeNodes
[
i
].
classList
.
remove
(
'auto-added'
);
}
}
// Event handlers
window
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
if
(
!
is
Slide
ListMode
())
{
// "?full" is present without slide hash so we should display first
if
(
!
isListMode
())
{
// "?full" is present without slide hash
,
so we should display first
// slide
if
(
-
1
===
getCurrentSlideNumber
()
)
{
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full'
+
getSlideHash
ByNumber
(
0
)
);
if
(
-
1
===
getCurrentSlideNumber
()
)
{
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full'
+
getSlideHash
(
0
)
);
}
enterS
ingleS
lideMode
();
enterSlideMode
();
updateProgress
(
getCurrentSlideNumber
());
}
},
false
);
window
.
addEventListener
(
'popstate'
,
function
(
e
)
{
if
(
is
Slide
ListMode
())
{
enter
Slide
ListMode
();
if
(
isListMode
())
{
enterListMode
();
scrollToCurrentSlide
();
}
else
{
enterS
ingleS
lideMode
();
enterSlideMode
();
}
},
false
);
window
.
addEventListener
(
'resize'
,
function
(
e
)
{
if
(
!
is
Slide
ListMode
())
{
if
(
!
isListMode
())
{
applyTransform
(
getTransform
());
}
},
false
);
document
.
addEventListener
(
'keydown'
,
function
(
e
)
{
if
(
e
.
altKey
||
e
.
ctrlKey
||
e
.
metaKey
)
return
;
var
current_slide_number
=
getCurrentSlideNumber
();
// Shortcut for alt, shift and meta keys
if
(
e
.
altKey
||
e
.
ctrlKey
||
e
.
metaKey
)
{
return
;
}
switch
(
e
.
which
)
{
case
9
:
// Tab = +1; Shift + Tab = -1
if
(
isSlideListMode
())
{
e
.
preventDefault
();
current_slide_number
+=
e
.
shiftKey
?
-
1
:
1
;
url
.
hash
=
getSlideHashByNumber
(
current_slide_number
);
}
break
;
var
currentSlideNumber
=
getCurrentSlideNumber
();
switch
(
e
.
which
)
{
case
13
:
// Enter
if
(
is
Slide
ListMode
())
{
if
(
isListMode
())
{
e
.
preventDefault
();
history
.
pushState
(
null
,
null
,
url
.
pathname
+
'?full'
+
getSlideHash
ByNumber
(
current_slide_n
umber
));
enterS
ingleS
lideMode
();
history
.
pushState
(
null
,
null
,
url
.
pathname
+
'?full'
+
getSlideHash
(
currentSlideN
umber
));
enterSlideMode
();
updateProgress
(
current
_slide_n
umber
);
updateProgress
(
current
SlideN
umber
);
}
break
;
case
27
:
// Esc
if
(
!
is
Slide
ListMode
())
{
if
(
!
isListMode
())
{
e
.
preventDefault
();
history
.
pushState
(
null
,
null
,
url
.
pathname
+
getSlideHash
ByNumber
(
current_slide_n
umber
));
enter
Slide
ListMode
();
history
.
pushState
(
null
,
null
,
url
.
pathname
+
getSlideHash
(
currentSlideN
umber
));
enterListMode
();
scrollToCurrentSlide
();
}
break
;
...
...
@@ -180,8 +226,9 @@
case
75
:
// k
e
.
preventDefault
();
current_slide_number
--
;
goToSlide
(
current_slide_number
);
resetInnerNavigation
(
currentSlideNumber
);
currentSlideNumber
--
;
goToSlide
(
currentSlideNumber
);
break
;
case
34
:
// PgDown
...
...
@@ -191,29 +238,41 @@
case
74
:
// j
e
.
preventDefault
();
current_slide_number
++
;
goToSlide
(
current_slide_number
);
// Only go to next slide if current slide have no inner
// navigation or inner navigation is fully shown
if
(
!
slideList
[
currentSlideNumber
].
hasInnerNavigation
||
-
1
===
increaseInnerNavigation
(
currentSlideNumber
)
)
{
resetInnerNavigation
(
currentSlideNumber
);
currentSlideNumber
++
;
goToSlide
(
currentSlideNumber
);
}
break
;
case
36
:
// Home
e
.
preventDefault
();
current_slide_number
=
0
;
goToSlide
(
current_slide_number
);
resetInnerNavigation
(
currentSlideNumber
);
currentSlideNumber
=
0
;
goToSlide
(
currentSlideNumber
);
break
;
case
35
:
// End
e
.
preventDefault
();
current_slide_number
=
slideList
.
length
-
1
;
goToSlide
(
current_slide_number
);
resetInnerNavigation
(
currentSlideNumber
);
currentSlideNumber
=
slideList
.
length
-
1
;
goToSlide
(
currentSlideNumber
);
break
;
case
9
:
// Tab = +1; Shift + Tab = -1
case
32
:
// Space = +1; Shift + Space = -1
e
.
preventDefault
();
current_slide_number
+=
e
.
shiftKey
?
-
1
:
1
;
goToSlide
(
current_slide_number
);
resetInnerNavigation
(
currentSlideNumber
);
currentSlideNumber
+=
e
.
shiftKey
?
-
1
:
1
;
goToSlide
(
currentSlideNumber
);
break
;
default
:
...
...
@@ -225,20 +284,21 @@
document
.
addEventListener
(
'touchend'
,
dispatchSingleSlideMode
,
false
);
document
.
addEventListener
(
'touchstart'
,
function
(
e
)
{
if
(
!
isSlide
ListMode
())
{
var
current
_slide_n
umber
=
getCurrentSlideNumber
(),
if
(
!
is
ListMode
())
{
var
current
SlideN
umber
=
getCurrentSlideNumber
(),
x
=
e
.
touches
[
0
].
pageX
;
if
(
x
>
window
.
innerWidth
/
2
)
{
current
_slide_n
umber
++
;
if
(
x
>
window
.
innerWidth
/
2
)
{
current
SlideN
umber
++
;
}
else
{
current
_slide_n
umber
--
;
current
SlideN
umber
--
;
}
goToSlide
(
current_slide_number
);
goToSlide
(
currentSlideNumber
);
}
},
false
);
document
.
addEventListener
(
'touchmove'
,
function
(
e
)
{
if
(
!
isSlide
ListMode
())
{
if
(
!
is
ListMode
())
{
e
.
preventDefault
();
}
},
false
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment