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
6724b0cd
Commit
6724b0cd
authored
Oct 05, 2012
by
Vadim Makeev
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #84 from aliem/feature/public_api
Feature/public api
parents
d7bd266b
a68a7b5c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
61 deletions
+73
-61
script.js
scripts/script.js
+73
-61
No files found.
scripts/script.js
View file @
6724b0cd
(
function
()
{
window
.
shower
=
(
function
()
{
var
url
=
window
.
location
,
var
_
=
{},
url
=
window
.
location
,
body
=
document
.
body
,
body
=
document
.
body
,
slides
=
document
.
querySelectorAll
(
'div.slide'
),
slides
=
document
.
querySelectorAll
(
'div.slide'
),
progress
=
document
.
querySelector
(
'div.progress div'
),
progress
=
document
.
querySelector
(
'div.progress div'
),
...
@@ -30,17 +31,42 @@
...
@@ -30,17 +31,42 @@
body
.
style
.
transform
=
transform
;
body
.
style
.
transform
=
transform
;
}
}
function
enterSlideMode
()
{
_
.
next
=
function
()
{
var
currentSlideNumber
=
_
.
getCurrentSlideNumber
();
// Only go to next slide if current slide have no inner
// navigation or inner navigation is fully shown
// NOTE: But first of all check if there is no current slide
if
(
-
1
===
currentSlideNumber
||
!
slideList
[
currentSlideNumber
].
hasInnerNavigation
||
-
1
===
increaseInnerNavigation
(
currentSlideNumber
)
)
{
currentSlideNumber
++
;
_
.
go
(
currentSlideNumber
);
}
}
_
.
previous
=
function
()
{
_
.
go
(
_
.
getCurrentSlideNumber
()
-
1
);
}
_
.
first
=
function
()
{
_
.
go
(
0
)
}
_
.
last
=
function
()
{
_
.
go
(
slideList
.
length
-
1
);
}
_
.
enterSlideMode
=
function
()
{
body
.
className
=
'full'
;
body
.
className
=
'full'
;
applyTransform
(
getTransform
());
applyTransform
(
getTransform
());
}
}
function
enterListMode
()
{
_
.
enterListMode
=
function
()
{
body
.
className
=
'list'
;
body
.
className
=
'list'
;
applyTransform
(
'none'
);
applyTransform
(
'none'
);
}
}
function
getCurrentSlideNumber
()
{
_
.
getCurrentSlideNumber
=
function
()
{
var
i
,
l
=
slideList
.
length
,
var
i
,
l
=
slideList
.
length
,
currentSlideId
=
url
.
hash
.
substr
(
1
);
currentSlideId
=
url
.
hash
.
substr
(
1
);
...
@@ -63,7 +89,7 @@
...
@@ -63,7 +89,7 @@
}
}
}
}
function
isListMode
()
{
_
.
isListMode
=
function
()
{
return
'full'
!==
url
.
search
.
substr
(
1
);
return
'full'
!==
url
.
search
.
substr
(
1
);
}
}
...
@@ -77,21 +103,24 @@
...
@@ -77,21 +103,24 @@
}
}
}
}
function
updateProgress
(
slideNumber
)
{
_
.
updateProgress
=
function
(
slideNumber
)
{
if
(
null
===
progress
)
{
return
;
}
if
(
null
===
progress
)
{
return
;
}
progress
.
style
.
width
=
(
100
/
(
slideList
.
length
-
1
)
*
normalizeSlideNumber
(
slideNumber
)).
toFixed
(
2
)
+
'%'
;
progress
.
style
.
width
=
(
100
/
(
slideList
.
length
-
1
)
*
normalizeSlideNumber
(
slideNumber
)).
toFixed
(
2
)
+
'%'
;
}
}
function
getSlideHash
(
slideNumber
)
{
_
.
getSlideHash
=
function
(
slideNumber
)
{
return
'#'
+
slideList
[
normalizeSlideNumber
(
slideNumber
)].
id
;
return
'#'
+
slideList
[
normalizeSlideNumber
(
slideNumber
)].
id
;
}
}
function
goToSlide
(
slideNumber
)
{
_
.
go
=
function
(
slideNumber
)
{
url
.
hash
=
getSlideHash
(
slideNumber
);
url
.
hash
=
_
.
getSlideHash
(
slideNumber
);
if
(
!
isListMode
())
{
if
(
!
_
.
isListMode
())
{
updateProgress
(
slideNumber
);
_
.
updateProgress
(
slideNumber
);
}
}
if
(
typeof
_
.
onchange
==
'function'
)
_
.
onchange
(
slideNumber
);
}
}
function
getContainingSlideId
(
el
)
{
function
getContainingSlideId
(
el
)
{
...
@@ -110,15 +139,15 @@
...
@@ -110,15 +139,15 @@
function
dispatchSingleSlideMode
(
e
)
{
function
dispatchSingleSlideMode
(
e
)
{
var
slideId
=
getContainingSlideId
(
e
.
target
);
var
slideId
=
getContainingSlideId
(
e
.
target
);
if
(
''
!==
slideId
&&
isListMode
())
{
if
(
''
!==
slideId
&&
_
.
isListMode
())
{
e
.
preventDefault
();
e
.
preventDefault
();
// NOTE: we should update hash to get things work properly
// NOTE: we should update hash to get things work properly
url
.
hash
=
'#'
+
slideId
;
url
.
hash
=
'#'
+
slideId
;
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full#'
+
slideId
);
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full#'
+
slideId
);
enterSlideMode
();
_
.
enterSlideMode
();
updateProgress
(
getCurrentSlideNumber
());
_
.
updateProgress
(
_
.
getCurrentSlideNumber
());
}
}
}
}
...
@@ -127,7 +156,7 @@
...
@@ -127,7 +156,7 @@
// Shortcut for slides without inner navigation
// Shortcut for slides without inner navigation
if
(
true
!==
slideList
[
slideNumber
].
hasInnerNavigation
)
{
return
-
1
;
}
if
(
true
!==
slideList
[
slideNumber
].
hasInnerNavigation
)
{
return
-
1
;
}
var
activeNodes
=
document
.
querySelectorAll
(
getSlideHash
(
slideNumber
)
+
' .active'
),
var
activeNodes
=
document
.
querySelectorAll
(
_
.
getSlideHash
(
slideNumber
)
+
' .active'
),
// NOTE: we assume there is no other elements in inner navigation
// NOTE: we assume there is no other elements in inner navigation
node
=
activeNodes
[
activeNodes
.
length
-
1
].
nextElementSibling
;
node
=
activeNodes
[
activeNodes
.
length
-
1
].
nextElementSibling
;
...
@@ -142,28 +171,28 @@
...
@@ -142,28 +171,28 @@
// Event handlers
// Event handlers
window
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
window
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
if
(
!
isListMode
())
{
if
(
!
_
.
isListMode
())
{
// "?full" is present without slide hash, so we should display first slide
// "?full" is present without slide hash, so we should display first slide
if
(
-
1
===
getCurrentSlideNumber
())
{
if
(
-
1
===
_
.
getCurrentSlideNumber
())
{
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full'
+
getSlideHash
(
0
));
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full'
+
_
.
getSlideHash
(
0
));
}
}
enterSlideMode
();
_
.
enterSlideMode
();
updateProgress
(
getCurrentSlideNumber
());
_
.
updateProgress
(
_
.
getCurrentSlideNumber
());
}
}
},
false
);
},
false
);
window
.
addEventListener
(
'popstate'
,
function
(
e
)
{
window
.
addEventListener
(
'popstate'
,
function
(
e
)
{
if
(
isListMode
())
{
if
(
_
.
isListMode
())
{
enterListMode
();
_
.
enterListMode
();
scrollToSlide
(
getCurrentSlideNumber
());
scrollToSlide
(
_
.
getCurrentSlideNumber
());
}
else
{
}
else
{
enterSlideMode
();
_
.
enterSlideMode
();
}
}
},
false
);
},
false
);
window
.
addEventListener
(
'resize'
,
function
(
e
)
{
window
.
addEventListener
(
'resize'
,
function
(
e
)
{
if
(
!
isListMode
())
{
if
(
!
_
.
isListMode
())
{
applyTransform
(
getTransform
());
applyTransform
(
getTransform
());
}
}
},
false
);
},
false
);
...
@@ -171,28 +200,27 @@
...
@@ -171,28 +200,27 @@
document
.
addEventListener
(
'keydown'
,
function
(
e
)
{
document
.
addEventListener
(
'keydown'
,
function
(
e
)
{
// Shortcut for alt, shift and meta keys
// Shortcut for alt, shift and meta keys
if
(
e
.
altKey
||
e
.
ctrlKey
||
e
.
metaKey
)
{
return
;
}
if
(
e
.
altKey
||
e
.
ctrlKey
||
e
.
metaKey
)
{
return
;
}
var
currentSlideNumber
=
_
.
getCurrentSlideNumber
();
var
currentSlideNumber
=
getCurrentSlideNumber
();
switch
(
e
.
which
)
{
switch
(
e
.
which
)
{
case
116
:
// F5
case
116
:
// F5
case
13
:
// Enter
case
13
:
// Enter
if
(
isListMode
()
&&
-
1
!==
currentSlideNumber
)
{
if
(
_
.
isListMode
()
&&
-
1
!==
currentSlideNumber
)
{
e
.
preventDefault
();
e
.
preventDefault
();
history
.
pushState
(
null
,
null
,
url
.
pathname
+
'?full'
+
getSlideHash
(
currentSlideNumber
));
history
.
pushState
(
null
,
null
,
url
.
pathname
+
'?full'
+
_
.
getSlideHash
(
currentSlideNumber
));
enterSlideMode
();
_
.
enterSlideMode
();
updateProgress
(
currentSlideNumber
);
_
.
updateProgress
(
currentSlideNumber
);
}
}
break
;
break
;
case
27
:
// Esc
case
27
:
// Esc
if
(
!
isListMode
())
{
if
(
!
_
.
isListMode
())
{
e
.
preventDefault
();
e
.
preventDefault
();
history
.
pushState
(
null
,
null
,
url
.
pathname
+
getSlideHash
(
currentSlideNumber
));
history
.
pushState
(
null
,
null
,
url
.
pathname
+
_
.
getSlideHash
(
currentSlideNumber
));
enterListMode
();
_
.
enterListMode
();
scrollToSlide
(
currentSlideNumber
);
scrollToSlide
(
currentSlideNumber
);
}
}
break
;
break
;
...
@@ -203,9 +231,7 @@
...
@@ -203,9 +231,7 @@
case
72
:
// h
case
72
:
// h
case
75
:
// k
case
75
:
// k
e
.
preventDefault
();
e
.
preventDefault
();
_
.
previous
();
currentSlideNumber
--
;
goToSlide
(
currentSlideNumber
);
break
;
break
;
case
34
:
// PgDown
case
34
:
// PgDown
...
@@ -215,39 +241,24 @@
...
@@ -215,39 +241,24 @@
case
74
:
// j
case
74
:
// j
e
.
preventDefault
();
e
.
preventDefault
();
// Only go to next slide if current slide have no inner
_
.
next
();
// navigation or inner navigation is fully shown
// NOTE: But first of all check if there is no current slide
if
(
-
1
===
currentSlideNumber
||
!
slideList
[
currentSlideNumber
].
hasInnerNavigation
||
-
1
===
increaseInnerNavigation
(
currentSlideNumber
)
)
{
currentSlideNumber
++
;
goToSlide
(
currentSlideNumber
);
}
break
;
break
;
case
36
:
// Home
case
36
:
// Home
e
.
preventDefault
();
e
.
preventDefault
();
_
.
first
();
currentSlideNumber
=
0
;
goToSlide
(
currentSlideNumber
);
break
;
break
;
case
35
:
// End
case
35
:
// End
e
.
preventDefault
();
e
.
preventDefault
();
_
.
last
();
currentSlideNumber
=
slideList
.
length
-
1
;
goToSlide
(
currentSlideNumber
);
break
;
break
;
case
9
:
// Tab = +1; Shift + Tab = -1
case
9
:
// Tab = +1; Shift + Tab = -1
case
32
:
// Space = +1; Shift + Space = -1
case
32
:
// Space = +1; Shift + Space = -1
e
.
preventDefault
();
e
.
preventDefault
();
currentSlideNumber
+=
e
.
shiftKey
?
-
1
:
1
;
_
[
e
.
shiftKey
?
'previous'
:
'next'
]();
goToSlide
(
currentSlideNumber
);
break
;
break
;
default
:
default
:
...
@@ -259,8 +270,8 @@
...
@@ -259,8 +270,8 @@
document
.
addEventListener
(
'touchend'
,
dispatchSingleSlideMode
,
false
);
document
.
addEventListener
(
'touchend'
,
dispatchSingleSlideMode
,
false
);
document
.
addEventListener
(
'touchstart'
,
function
(
e
)
{
document
.
addEventListener
(
'touchstart'
,
function
(
e
)
{
if
(
!
isListMode
())
{
if
(
!
_
.
isListMode
())
{
var
currentSlideNumber
=
getCurrentSlideNumber
(),
var
currentSlideNumber
=
_
.
getCurrentSlideNumber
(),
x
=
e
.
touches
[
0
].
pageX
;
x
=
e
.
touches
[
0
].
pageX
;
if
(
x
>
window
.
innerWidth
/
2
)
{
if
(
x
>
window
.
innerWidth
/
2
)
{
currentSlideNumber
++
;
currentSlideNumber
++
;
...
@@ -268,14 +279,15 @@
...
@@ -268,14 +279,15 @@
currentSlideNumber
--
;
currentSlideNumber
--
;
}
}
goToSlide
(
currentSlideNumber
);
_
.
go
(
currentSlideNumber
);
}
}
},
false
);
},
false
);
document
.
addEventListener
(
'touchmove'
,
function
(
e
)
{
document
.
addEventListener
(
'touchmove'
,
function
(
e
)
{
if
(
!
isListMode
())
{
if
(
!
_
.
isListMode
())
{
e
.
preventDefault
();
e
.
preventDefault
();
}
}
},
false
);
},
false
);
return
_
;
}());
}());
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