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
df8c4f89
Commit
df8c4f89
authored
Jan 20, 2013
by
Vadim Makeev
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #112 from miripiruni/master
Refactoring, fix for presenter notes, fix for inner nav timing
parents
6a9c68b8
8cd2aa35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
96 deletions
+101
-96
shower.js
shower.js
+101
-96
No files found.
shower.js
View file @
df8c4f89
...
@@ -75,7 +75,7 @@ window.shower = (function(window, document, undefined) {
...
@@ -75,7 +75,7 @@ window.shower = (function(window, document, undefined) {
* @returns {Boolean}
* @returns {Boolean}
*/
*/
shower
.
_isNumber
=
function
(
arg
)
{
shower
.
_isNumber
=
function
(
arg
)
{
return
!
isNaN
(
parseFloat
(
arg
))
&&
isFinite
(
arg
);
return
!
isNaN
(
parseFloat
(
arg
))
&&
isFinite
(
arg
);
};
};
/**
/**
...
@@ -128,7 +128,7 @@ window.shower = (function(window, document, undefined) {
...
@@ -128,7 +128,7 @@ window.shower = (function(window, document, undefined) {
* @returns {Boolean}
* @returns {Boolean}
*/
*/
shower
.
_checkInteractiveElement
=
function
(
e
)
{
shower
.
_checkInteractiveElement
=
function
(
e
)
{
return
'A'
===
e
.
target
.
nodeName
;
return
'A'
===
e
.
target
.
nodeName
;
};
};
/**
/**
...
@@ -158,8 +158,37 @@ window.shower = (function(window, document, undefined) {
...
@@ -158,8 +158,37 @@ window.shower = (function(window, document, undefined) {
/**
/**
* Show next slide. If slide is last returns false, otherwise return slide
* Go to slide number...
* number which been shown.
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
* @param {Function} [callback] runs only if you not in List mode
* @returns {Number}
*/
shower
.
go
=
function
(
slideNumber
,
callback
)
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as Number, baby!'
);
}
// Also triggers popstate and invoke shower.enter__Mode()
url
.
hash
=
shower
.
getSlideHash
(
slideNumber
);
if
(
shower
.
isSlideMode
())
{
shower
.
showPresenterNotes
(
slideNumber
);
shower
.
updateProgress
(
slideNumber
);
shower
.
updateCurrentAndPassedSlides
(
slideNumber
);
shower
.
runInnerNavigation
(
slideNumber
);
}
if
(
typeof
(
callback
)
===
'function'
)
{
callback
();
}
return
slideNumber
;
};
/**
* Show next slide or show next item of Inner navigation. If slide is last
* returns false, otherwise return slide number which been shown.
* @param {Function} [callback] runs only if shower.next() complete successfully
* @param {Function} [callback] runs only if shower.next() complete successfully
* @returns {Number|Boolean}
* @returns {Number|Boolean}
*/
*/
...
@@ -171,17 +200,25 @@ window.shower = (function(window, document, undefined) {
...
@@ -171,17 +200,25 @@ window.shower = (function(window, document, undefined) {
// navigation or inner navigation is fully shown
// navigation or inner navigation is fully shown
// NOTE: But first of all check if there is no current slide
// NOTE: But first of all check if there is no current slide
if
(
if
(
-
1
===
currentSlideNumber
||
(
!
slideList
[
currentSlideNumber
].
hasInnerNavigation
||
-
1
===
currentSlideNumber
||
-
1
===
shower
.
increaseInnerNavigation
(
currentSlideNumber
)
!
slideList
[
currentSlideNumber
].
hasInnerNavigation
||
!
shower
.
increaseInnerNavigation
(
currentSlideNumber
)
)
&&
// If exist next slide
(
currentSlideNumber
+
2
)
<=
slideList
.
length
)
{
)
{
shower
.
go
(
currentSlideNumber
+
1
);
shower
.
go
(
currentSlideNumber
+
1
);
//
slides starts from 0
//
Slides starts from 0. So return next slide number.
ret
=
currentSlideNumber
+
2
;
ret
=
currentSlideNumber
+
2
;
}
if
(
typeof
(
callback
)
===
'function'
)
{
if
(
shower
.
isSlideMode
())
{
callback
();
shower
.
runInnerNavigation
(
currentSlideNumber
+
1
);
}
}
if
(
typeof
(
callback
)
===
'function'
)
{
callback
();
}
}
return
ret
;
return
ret
;
...
@@ -243,33 +280,22 @@ window.shower = (function(window, document, undefined) {
...
@@ -243,33 +280,22 @@ window.shower = (function(window, document, undefined) {
shower
.
enterSlideMode
=
function
(
callback
)
{
shower
.
enterSlideMode
=
function
(
callback
)
{
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
();
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
();
if
(
currentSlideNumber
===
-
1
)
{
// Anyway: change body class (@TODO: refactoring)
currentSlideNumber
=
0
;
}
shower
.
go
(
currentSlideNumber
);
shower
.
showPresenterNotes
(
currentSlideNumber
);
if
(
shower
.
isListMode
()
&&
isHistoryApiSupported
)
{
history
.
pushState
(
null
,
null
,
url
.
pathname
+
'?full'
+
shower
.
getSlideHash
(
currentSlideNumber
));
}
body
.
classList
.
remove
(
'list'
);
body
.
classList
.
remove
(
'list'
);
body
.
classList
.
add
(
'full'
);
body
.
classList
.
add
(
'full'
);
if
(
window
.
console
&&
window
.
console
.
clear
)
{
// Preparing URL for shower.go()
console
.
clear
();
if
(
shower
.
isListMode
()
&&
isHistoryApiSupported
)
{
history
.
pushState
(
null
,
null
,
url
.
pathname
+
'?full'
+
shower
.
getSlideHash
(
currentSlideNumber
));
}
}
shower
.
updateProgress
(
currentSlideNumber
);
shower
.
_applyTransform
(
shower
.
_getTransform
());
shower
.
updateCurrentAndPassedSlides
(
currentSlideNumber
);
shower
.
runInnerNavigation
(
currentSlideNumber
);
if
(
typeof
(
callback
)
===
'function'
)
{
if
(
typeof
(
callback
)
===
'function'
)
{
callback
();
callback
();
}
}
return
shower
.
_applyTransform
(
shower
.
_getTransform
())
;
return
true
;
};
};
/**
/**
...
@@ -278,24 +304,32 @@ window.shower = (function(window, document, undefined) {
...
@@ -278,24 +304,32 @@ window.shower = (function(window, document, undefined) {
* @returns {Boolean}
* @returns {Boolean}
*/
*/
shower
.
enterListMode
=
function
(
callback
)
{
shower
.
enterListMode
=
function
(
callback
)
{
// Anyway: change body class (@TODO: refactoring)
body
.
classList
.
remove
(
'full'
);
body
.
classList
.
add
(
'list'
);
shower
.
clearPresenterNotes
();
if
(
shower
.
isListMode
())
{
return
false
;
}
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
();
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
();
clearTimeout
(
timer
);
clearTimeout
(
timer
);
body
.
classList
.
remove
(
'full'
);
body
.
classList
.
add
(
'list'
);
if
(
shower
.
isSlideMode
()
&&
isHistoryApiSupported
)
{
if
(
shower
.
isSlideMode
()
&&
isHistoryApiSupported
)
{
history
.
pushState
(
null
,
null
,
url
.
pathname
+
shower
.
getSlideHash
(
currentSlideNumber
));
history
.
pushState
(
null
,
null
,
url
.
pathname
+
shower
.
getSlideHash
(
currentSlideNumber
));
}
}
shower
.
scrollToSlide
(
currentSlideNumber
);
shower
.
scrollToSlide
(
currentSlideNumber
);
shower
.
_applyTransform
(
'none'
);
if
(
typeof
(
callback
)
===
'function'
)
{
if
(
typeof
(
callback
)
===
'function'
)
{
callback
();
callback
();
}
}
return
shower
.
_applyTransform
(
'none'
)
;
return
true
;
};
};
/**
/**
...
@@ -440,11 +474,22 @@ window.shower = (function(window, document, undefined) {
...
@@ -440,11 +474,22 @@ window.shower = (function(window, document, undefined) {
return
true
;
return
true
;
};
};
/**
* Clear presenter notes in console.
*/
shower
.
clearPresenterNotes
=
function
()
{
if
(
window
.
console
&&
window
.
console
.
clear
)
{
console
.
clear
();
}
};
/**
/**
* Show presenter notes in console.
* Show presenter notes in console.
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
*/
*/
shower
.
showPresenterNotes
=
function
(
slideNumber
)
{
shower
.
showPresenterNotes
=
function
(
slideNumber
)
{
shower
.
clearPresenterNotes
();
if
(
window
.
console
)
{
if
(
window
.
console
)
{
slideNumber
=
shower
.
_normalizeSlideNumber
(
slideNumber
);
slideNumber
=
shower
.
_normalizeSlideNumber
(
slideNumber
);
...
@@ -452,11 +497,12 @@ window.shower = (function(window, document, undefined) {
...
@@ -452,11 +497,12 @@ window.shower = (function(window, document, undefined) {
nextSlideId
=
slideList
[
slideNumber
+
1
]
?
slideList
[
slideNumber
+
1
].
id
:
null
,
nextSlideId
=
slideList
[
slideNumber
+
1
]
?
slideList
[
slideNumber
+
1
].
id
:
null
,
notes
=
document
.
getElementById
(
slideId
).
querySelector
(
'footer'
);
notes
=
document
.
getElementById
(
slideId
).
querySelector
(
'footer'
);
if
(
notes
)
{
if
(
notes
&&
notes
.
innerHTML
)
{
console
.
info
(
notes
.
innerHTML
.
replace
(
/
\n\s
+/g
,
'
\
n'
));
console
.
info
(
notes
.
innerHTML
.
replace
(
/
\n\s
+/g
,
'
\
n'
));
}
}
if
(
nextSlideId
)
{
if
(
nextSlideId
)
{
var
next
=
document
.
getElementById
(
nextSlideId
).
querySelector
(
'h2'
);
var
next
=
document
.
getElementById
(
nextSlideId
).
querySelector
(
'h2'
);
if
(
next
)
{
if
(
next
)
{
...
@@ -482,32 +528,6 @@ window.shower = (function(window, document, undefined) {
...
@@ -482,32 +528,6 @@ window.shower = (function(window, document, undefined) {
return
'#'
+
slideList
[
slideNumber
].
id
;
return
'#'
+
slideList
[
slideNumber
].
id
;
};
};
/**
* Go to slide number...
* @param {Number} slideNumber slide number (sic!). Attention: starts from zero.
* @param {Function} [callback] runs only if you not in List mode
* @returns {Number}
*/
shower
.
go
=
function
(
slideNumber
,
callback
)
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as Number, baby!'
);
}
url
.
hash
=
shower
.
getSlideHash
(
slideNumber
);
if
(
shower
.
isSlideMode
())
{
shower
.
updateProgress
(
slideNumber
);
shower
.
updateCurrentAndPassedSlides
(
slideNumber
);
shower
.
showPresenterNotes
(
slideNumber
);
if
(
typeof
(
callback
)
===
'function'
)
{
callback
();
}
}
return
slideNumber
;
};
/**
/**
* Run slide show if presented.
* Run slide show if presented.
* @param {Number} slideNumber
* @param {Number} slideNumber
...
@@ -529,24 +549,22 @@ window.shower = (function(window, document, undefined) {
...
@@ -529,24 +549,22 @@ window.shower = (function(window, document, undefined) {
timing
=
parseInt
(
timing
[
0
],
10
)
*
60
*
1000
+
parseInt
(
timing
[
1
],
10
)
*
1000
;
timing
=
parseInt
(
timing
[
0
],
10
)
*
60
*
1000
+
parseInt
(
timing
[
1
],
10
)
*
1000
;
timer
=
setTimeout
(
function
()
{
timer
=
setTimeout
(
function
()
{
shower
.
go
(
slideNumber
+
1
);
shower
.
next
();
shower
.
runInnerNavigation
(
slideNumber
+
1
);
},
},
timing
);
timing
);
}
}
return
true
;
return
true
;
};
};
/**
/**
* Increases inner navigation by adding 'active' class to next inactive inner navigation item
* Increases inner navigation by adding 'active' class to next inactive inner navigation item
* @param {Number} slideNumber
* @param {Number} slideNumber
* @returns {
Number
}
* @returns {
Boolean
}
*/
*/
shower
.
increaseInnerNavigation
=
function
(
slideNumber
)
{
shower
.
increaseInnerNavigation
=
function
(
slideNumber
)
{
var
nextNodes
,
var
nextNodes
,
node
,
node
;
ret
=
-
1
;
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as Number, baby!'
);
throw
new
Error
(
'Gimme slide number as Number, baby!'
);
...
@@ -559,20 +577,18 @@ window.shower = (function(window, document, undefined) {
...
@@ -559,20 +577,18 @@ window.shower = (function(window, document, undefined) {
if
(
0
!==
nextNodes
.
length
)
{
if
(
0
!==
nextNodes
.
length
)
{
node
=
nextNodes
[
0
];
node
=
nextNodes
[
0
];
node
.
classList
.
add
(
'active'
);
node
.
classList
.
add
(
'active'
);
ret
=
nextNodes
.
length
-
1
;
ret
urn
true
;
}
}
}
}
return
ret
;
return
false
;
};
};
// Event handlers
// Event handlers
window
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
window
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
if
(
body
.
classList
.
contains
(
'full'
))
{
if
(
body
.
classList
.
contains
(
'full'
)
||
shower
.
isSlideMode
())
{
shower
.
go
(
shower
.
getCurrentSlideNumber
());
shower
.
enterSlideMode
();
shower
.
enterSlideMode
();
}
}
},
false
);
},
false
);
...
@@ -596,7 +612,7 @@ window.shower = (function(window, document, undefined) {
...
@@ -596,7 +612,7 @@ window.shower = (function(window, document, undefined) {
if
(
e
.
altKey
||
e
.
ctrlKey
||
e
.
metaKey
)
{
return
;
}
if
(
e
.
altKey
||
e
.
ctrlKey
||
e
.
metaKey
)
{
return
;
}
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
(),
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
(),
i
nnerNavigation
Completed
=
true
;
i
sInnerNav
Completed
=
true
;
switch
(
e
.
which
)
{
switch
(
e
.
which
)
{
case
116
:
// F5
case
116
:
// F5
...
@@ -605,8 +621,11 @@ window.shower = (function(window, document, undefined) {
...
@@ -605,8 +621,11 @@ window.shower = (function(window, document, undefined) {
if
(
shower
.
isListMode
())
{
if
(
shower
.
isListMode
())
{
var
slideNumber
=
e
.
shiftKey
?
currentSlideNumber
:
0
;
var
slideNumber
=
e
.
shiftKey
?
currentSlideNumber
:
0
;
// Warning: go must be before enterSlideMode. Else there are
// bug in Chrome
shower
.
go
(
slideNumber
);
shower
.
go
(
slideNumber
);
shower
.
enterSlideMode
();
shower
.
enterSlideMode
();
shower
.
showPresenterNotes
(
slideNumber
);
}
else
{
}
else
{
shower
.
enterListMode
();
shower
.
enterListMode
();
}
}
...
@@ -641,28 +660,7 @@ window.shower = (function(window, document, undefined) {
...
@@ -641,28 +660,7 @@ window.shower = (function(window, document, undefined) {
case
76
:
// l
case
76
:
// l
case
74
:
// j
case
74
:
// j
e
.
preventDefault
();
e
.
preventDefault
();
shower
.
next
();
if
(
shower
.
isSlideMode
())
{
// Inner navigation is "completed" if current slide have
// no inner navigation or inner navigation is fully shown
innerNavigationCompleted
=
!
slideList
[
currentSlideNumber
].
hasInnerNavigation
||
-
1
===
shower
.
increaseInnerNavigation
(
currentSlideNumber
);
}
else
{
// Also inner navigation is always "completed" if we are in
// list mode
innerNavigationCompleted
=
true
;
}
// NOTE: First of all check if there is no current slide
if
(
-
1
===
currentSlideNumber
||
innerNavigationCompleted
)
{
currentSlideNumber
++
;
shower
.
go
(
currentSlideNumber
);
// We must run slideshow only in full mode
if
(
shower
.
isSlideMode
())
{
shower
.
runInnerNavigation
(
currentSlideNumber
);
}
}
break
;
break
;
case
36
:
// Home
case
36
:
// Home
...
@@ -687,10 +685,17 @@ window.shower = (function(window, document, undefined) {
...
@@ -687,10 +685,17 @@ window.shower = (function(window, document, undefined) {
},
false
);
},
false
);
document
.
addEventListener
(
'click'
,
function
(
e
)
{
document
.
addEventListener
(
'click'
,
function
(
e
)
{
e
.
preventDefault
();
var
slideNumber
=
shower
.
getSlideNumber
(
shower
.
_getSlideIdByEl
(
e
.
target
));
// Click on slide in List mode
if
(
shower
.
isListMode
()
&&
shower
.
_getSlideIdByEl
(
e
.
target
))
{
if
(
shower
.
isListMode
()
&&
shower
.
_getSlideIdByEl
(
e
.
target
))
{
e
.
preventDefault
();
// Warning: go must be before enterSlideMode. Else there are
shower
.
go
(
shower
.
getSlideNumber
(
shower
.
_getSlideIdByEl
(
e
.
target
)));
// bug in Chrome
shower
.
go
(
slideNumber
);
shower
.
enterSlideMode
();
shower
.
enterSlideMode
();
shower
.
showPresenterNotes
(
slideNumber
);
}
}
},
false
);
},
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