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
42c215bb
Commit
42c215bb
authored
Jan 18, 2013
by
Vadim Makeev
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #106 from miripiruni/master
Fix for #77
parents
0f449f8d
031f4b4f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
191 additions
and
149 deletions
+191
-149
shower.js
shower.js
+191
-149
No files found.
shower.js
View file @
42c215bb
...
...
@@ -17,8 +17,8 @@ window.shower = (function(window, document, undefined) {
* Get value at named data store for the DOM element.
* @private
* @param {domElem} element
* @param {
s
tring} name
* @returns {
s
tring}
* @param {
S
tring} name
* @returns {
S
tring}
*/
shower
.
_getData
=
function
(
element
,
name
)
{
return
element
.
dataset
?
element
.
dataset
[
name
]
:
element
.
getAttribute
(
'data-'
+
name
);
...
...
@@ -55,7 +55,7 @@ window.shower = (function(window, document, undefined) {
/**
* Set CSS transform with prefixes to body
* @private
* @returns {
true
}
* @returns {
Boolean
}
*/
shower
.
_applyTransform
=
function
(
transform
)
{
body
.
style
.
WebkitTransform
=
transform
;
...
...
@@ -67,12 +67,104 @@ window.shower = (function(window, document, undefined) {
return
true
;
};
/**
* Check if arg is number.
* @private
* @param {Number|whatelse} arg Any type
* @returns {Boolean}
*/
shower
.
_isNumber
=
function
(
arg
)
{
if
(
!
(
!
isNaN
(
parseFloat
(
arg
))
&&
isFinite
(
arg
)))
{
return
false
;
}
return
true
;
};
/**
* Normalize slide number.
* @private
* @param {Number} slideNumber slide number (sic!)
* @returns {Number}
*/
shower
.
_normalizeSlideNumber
=
function
(
slideNumber
)
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as Number, baby!'
);
}
if
(
slideNumber
<
0
)
{
slideNumber
=
0
;
}
if
(
slideNumber
>=
slideList
.
length
)
{
slideNumber
=
slideList
.
length
-
1
;
}
return
slideNumber
;
};
/**
* Get containing slide id.
* @private
* @param {domElem} el
* @returns {String}
*/
shower
.
_getContainingSlideId
=
function
(
el
)
{
while
(
'BODY'
!==
el
.
nodeName
&&
'HTML'
!==
el
.
nodeName
)
{
if
(
el
.
classList
.
contains
(
'slide'
))
{
return
el
.
id
;
}
else
{
el
=
el
.
parentNode
;
}
}
return
''
;
};
/**
* Dispatch single slide mode.
* @TODO: Renaming needed? Or just some handlers rewriting?
* @private
* @param {domElem} e
* @returns {Undefined}
*/
shower
.
_dispatchSingleSlideMode
=
function
(
e
)
{
// Process links
// @TODO: presentation links support
if
(
'A'
===
e
.
target
.
nodeName
)
{
e
.
preventDefault
();
window
.
open
(
e
.
target
.
getAttribute
(
'href'
));
return
;
}
var
slideId
=
shower
.
_getContainingSlideId
(
e
.
target
);
if
(
''
!==
slideId
&&
shower
.
isListMode
())
{
e
.
preventDefault
();
// NOTE: we should update hash to get things work properly
url
.
hash
=
'#'
+
slideId
;
if
(
isHistoryApiSupported
)
{
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full#'
+
slideId
);
}
shower
.
enterSlideMode
();
shower
.
updateProgress
(
shower
.
getCurrentSlideNumber
());
shower
.
updateCurrentAndPassedSlides
(
shower
.
getCurrentSlideNumber
());
shower
.
runSlideshowIfPresented
(
shower
.
getCurrentSlideNumber
());
}
return
;
};
/**
* Show next slide. If slide is last returns false, otherwise return slide
* number which been shown.
* @returns {number|false}
* @param {Function} callback runs only if shower.next() complete successfully
* @returns {Number|Boolean}
*/
shower
.
next
=
function
(
)
{
shower
.
next
=
function
(
callback
)
{
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
(),
ret
;
...
...
@@ -87,6 +179,10 @@ window.shower = (function(window, document, undefined) {
shower
.
go
(
currentSlideNumber
+
1
);
// slides starts from 0
ret
=
currentSlideNumber
+
2
;
if
(
typeof
(
callback
)
===
"function"
)
{
callback
();
}
}
else
{
ret
=
false
;
}
...
...
@@ -97,9 +193,10 @@ window.shower = (function(window, document, undefined) {
/**
* Show previous slide. If slide is first returns false, otherwise return slide
* number which been shown.
* @returns {number|false}
* @param {Function} callback runs only if shower.previous() complete successfully
* @returns {Number|Boolean}
*/
shower
.
previous
=
function
(
)
{
shower
.
previous
=
function
(
callback
)
{
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
(),
ret
;
...
...
@@ -107,6 +204,10 @@ window.shower = (function(window, document, undefined) {
if
(
currentSlideNumber
>
0
)
{
ret
=
currentSlideNumber
;
shower
.
go
(
currentSlideNumber
-
1
);
if
(
typeof
(
callback
)
===
"function"
)
{
callback
();
}
}
else
{
ret
=
false
;
}
...
...
@@ -116,47 +217,74 @@ window.shower = (function(window, document, undefined) {
/**
* Show first slide.
* @returns {number}
* @param {Function} callback
* @returns {Number}
*/
shower
.
first
=
function
()
{
shower
.
first
=
function
(
callback
)
{
if
(
typeof
(
callback
)
===
"function"
)
{
callback
();
}
return
shower
.
go
(
0
);
};
/**
* Show last slide.
* @returns {number}
* @param {Function} callback
* @returns {Number}
*/
shower
.
last
=
function
()
{
shower
.
last
=
function
(
callback
)
{
if
(
typeof
(
callback
)
===
"function"
)
{
callback
();
}
return
shower
.
go
(
slideList
.
length
-
1
);
};
/**
* Switch to slide view.
* @returns {number}
* @param {Function} callback runs only if shower.enterSlideMode() complete successfully
* @returns {Number|Boolean}
*/
shower
.
enterSlideMode
=
function
()
{
shower
.
enterSlideMode
=
function
(
callback
)
{
// check if it's already in slide mode...
if
(
body
.
classList
.
contains
(
'full'
))
{
return
;
}
if
(
body
.
classList
.
contains
(
'full'
))
{
return
false
;
}
body
.
classList
.
remove
(
'list'
);
body
.
classList
.
add
(
'full'
);
if
(
window
.
console
&&
window
.
console
.
clear
)
{
console
.
clear
();
}
if
(
window
.
console
&&
window
.
console
.
clear
)
{
console
.
clear
();
}
shower
.
showPresenterNotes
(
shower
.
getCurrentSlideNumber
());
if
(
typeof
(
callback
)
===
"function"
)
{
callback
();
}
return
shower
.
_applyTransform
(
shower
.
_getTransform
());
};
/**
* Switch to list view.
* @returns {number}
* @param {Function} callback runs only if shower.enterListMode() complete successfully
* @returns {Number}
*/
shower
.
enterListMode
=
function
()
{
shower
.
enterListMode
=
function
(
callback
)
{
// check if it's already in list mode...
if
(
body
.
classList
.
contains
(
'list'
))
{
return
;
}
if
(
body
.
classList
.
contains
(
'list'
))
{
return
false
;
}
body
.
classList
.
remove
(
'full'
);
body
.
classList
.
add
(
'list'
);
if
(
typeof
(
callback
)
===
"function"
)
{
callback
();
}
return
shower
.
_applyTransform
(
'none'
);
};
...
...
@@ -166,7 +294,7 @@ window.shower = (function(window, document, undefined) {
* Get current slide number. Starts from zero. Warning: when in url you have
* slide number 1 this method will return 0.
* If something wrong return -1.
* @returns {
n
umber}
* @returns {
N
umber}
*/
shower
.
getCurrentSlideNumber
=
function
()
{
var
i
=
slideList
.
length
-
1
,
...
...
@@ -183,35 +311,21 @@ window.shower = (function(window, document, undefined) {
return
-
1
;
};
/**
* Check if arg is number.
* @private
* @param {number|whatelse} arg Any type
* @returns {boolean}
*/
shower
.
_isNumber
=
function
(
arg
)
{
if
(
!
(
!
isNaN
(
parseFloat
(
arg
))
&&
isFinite
(
arg
)))
{
return
false
;
}
return
true
;
};
/**
* Scroll to slide.
* @param {
n
umber} slideNumber slide number (sic!)
* @returns {
undefined|b
oolean}
* @param {
N
umber} slideNumber slide number (sic!)
* @returns {
Undefined|B
oolean}
*/
shower
.
scrollToSlide
=
function
(
slideNumber
)
{
var
currentSlide
,
ret
;
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
n
umber, baby!'
);
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
N
umber, baby!'
);
}
if
(
!
shower
.
isListMode
())
{
throw
new
Error
(
'You can
\'
t
to scroll
cause you in slide mode. Please, switch to list mode.'
);
if
(
!
shower
.
isListMode
())
{
throw
new
Error
(
'You can
\'
t
scroll to be
cause you in slide mode. Please, switch to list mode.'
);
}
// @TODO: WTF?
...
...
@@ -232,38 +346,16 @@ window.shower = (function(window, document, undefined) {
/**
* Chech if it's list mode.
* @returns {
b
oolean}
* @returns {
B
oolean}
*/
shower
.
isListMode
=
function
()
{
return
isHistoryApiSupported
?
!
/^full.*/
.
test
(
url
.
search
.
substr
(
1
))
:
body
.
classList
.
contains
(
'list'
);
};
/**
* Normalize slide number.
* @private
* @param {number} slideNumber slide number (sic!)
* @returns {number}
*/
shower
.
_normalizeSlideNumber
=
function
(
slideNumber
)
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as number, baby!'
);
}
if
(
slideNumber
<
0
)
{
slideNumber
=
0
;
}
if
(
slideNumber
>=
slideList
.
length
)
{
slideNumber
=
slideList
.
length
-
1
;
}
return
slideNumber
;
};
/**
* Update progress bar.
* @param {
n
umber} slideNumber slide number (sic!)
* @returns {
b
oolean}
* @param {
N
umber} slideNumber slide number (sic!)
* @returns {
B
oolean}
*/
shower
.
updateProgress
=
function
(
slideNumber
)
{
// if progress bar doesn't exist
...
...
@@ -271,8 +363,8 @@ window.shower = (function(window, document, undefined) {
return
false
;
}
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
n
umber, baby!'
);
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
N
umber, baby!'
);
}
progress
.
style
.
width
=
(
100
/
(
slideList
.
length
-
1
)
*
shower
.
_normalizeSlideNumber
(
slideNumber
)).
toFixed
(
2
)
+
'%'
;
...
...
@@ -282,8 +374,8 @@ window.shower = (function(window, document, undefined) {
/**
* Update current and passed slides.
* @param {
n
umber} slideNumber slide number (sic!)
* @returns {
b
oolean}
* @param {
N
umber} slideNumber slide number (sic!)
* @returns {
B
oolean}
*/
shower
.
updateCurrentAndPassedSlides
=
function
(
slideNumber
)
{
var
i
,
...
...
@@ -292,8 +384,8 @@ window.shower = (function(window, document, undefined) {
slideNumber
=
shower
.
_normalizeSlideNumber
(
slideNumber
);
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
n
umber, baby!'
);
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
N
umber, baby!'
);
}
for
(
i
=
0
;
i
<
l
;
++
i
)
{
...
...
@@ -316,7 +408,7 @@ window.shower = (function(window, document, undefined) {
/**
* Show presenter notes in console.
* @param {
n
umber} slideNumber slide number (sic!). Attention: starts from zero.
* @param {
N
umber} slideNumber slide number (sic!). Attention: starts from zero.
*/
shower
.
showPresenterNotes
=
function
(
slideNumber
)
{
if
(
window
.
console
)
{
...
...
@@ -341,12 +433,12 @@ window.shower = (function(window, document, undefined) {
/**
* Get slide hash.
* @param {
n
umber} slideNumber slide number (sic!). Attention: starts from zero.
* @returns {
b
oolean}
* @param {
N
umber} slideNumber slide number (sic!). Attention: starts from zero.
* @returns {
B
oolean}
*/
shower
.
getSlideHash
=
function
(
slideNumber
)
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
n
umber, baby!'
);
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
N
umber, baby!'
);
}
slideNumber
=
shower
.
_normalizeSlideNumber
(
slideNumber
);
...
...
@@ -356,12 +448,13 @@ window.shower = (function(window, document, undefined) {
/**
* Go to slide number...
* @param {number} slideNumber slide number (sic!). Attention: starts from zero.
* @returns {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
)
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
n
umber, baby!'
);
shower
.
go
=
function
(
slideNumber
,
callback
)
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
N
umber, baby!'
);
}
url
.
hash
=
shower
.
getSlideHash
(
slideNumber
);
...
...
@@ -370,74 +463,23 @@ window.shower = (function(window, document, undefined) {
shower
.
updateProgress
(
slideNumber
);
shower
.
updateCurrentAndPassedSlides
(
slideNumber
);
shower
.
showPresenterNotes
(
slideNumber
);
}
return
slideNumber
;
};
/**
* Get containing slide id.
* @private
* @param {domElem} el
* @returns {string}
*/
shower
.
_getContainingSlideId
=
function
(
el
)
{
while
(
'BODY'
!==
el
.
nodeName
&&
'HTML'
!==
el
.
nodeName
)
{
if
(
el
.
classList
.
contains
(
'slide'
))
{
return
el
.
id
;
}
else
{
el
=
el
.
parentNode
;
}
}
return
''
;
};
/**
* Dispatch single slide mode.
* @TODO: Renaming needed? Or just some handlers rewriting?
* @private
* @param {domElem} e
* @returns {undefined}
*/
shower
.
_dispatchSingleSlideMode
=
function
(
e
)
{
// Process links
// @TODO: presentation links support
if
(
'A'
===
e
.
target
.
nodeName
)
{
e
.
preventDefault
();
window
.
open
(
e
.
target
.
getAttribute
(
'href'
));
return
;
if
(
typeof
(
callback
)
===
"function"
)
{
callback
()
;
}
var
slideId
=
shower
.
_getContainingSlideId
(
e
.
target
);
if
(
''
!==
slideId
&&
shower
.
isListMode
())
{
e
.
preventDefault
();
// NOTE: we should update hash to get things work properly
url
.
hash
=
'#'
+
slideId
;
if
(
isHistoryApiSupported
)
{
history
.
replaceState
(
null
,
null
,
url
.
pathname
+
'?full#'
+
slideId
);
}
shower
.
enterSlideMode
();
shower
.
updateProgress
(
shower
.
getCurrentSlideNumber
());
shower
.
updateCurrentAndPassedSlides
(
shower
.
getCurrentSlideNumber
());
shower
.
runSlideshowIfPresented
(
shower
.
getCurrentSlideNumber
());
}
return
;
return
slideNumber
;
};
/**
* Run slide show i
n
presented.
* @param {
n
umber} slideNumber
* @returns {
u
ndefined}
* Run slide show i
f
presented.
* @param {
N
umber} slideNumber
* @returns {
U
ndefined}
*/
shower
.
runSlideshowIfPresented
=
function
(
slideNumber
)
{
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
n
umber, baby!'
);
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
N
umber, baby!'
);
}
slideNumber
=
shower
.
_normalizeSlideNumber
(
slideNumber
);
...
...
@@ -460,16 +502,16 @@ window.shower = (function(window, document, undefined) {
/**
* Increases inner navigation by adding 'active' class to next inactive inner navigation item
* @param {
n
umber} slideNumber
* @returns {
n
umber}
* @param {
N
umber} slideNumber
* @returns {
N
umber}
*/
shower
.
increaseInnerNavigation
=
function
(
slideNumber
)
{
var
nextNodes
,
node
,
ret
=
-
1
;
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
n
umber, baby!'
);
if
(
!
shower
.
_isNumber
(
slideNumber
))
{
throw
new
Error
(
'Gimme slide number as
N
umber, baby!'
);
}
// If inner navigation in this slide...
...
...
@@ -491,7 +533,7 @@ window.shower = (function(window, document, undefined) {
// Event handlers
window
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
window
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
if
(
!
shower
.
isListMode
())
{
// "?full" is present without slide hash, so we should display first slide
if
(
-
1
===
shower
.
getCurrentSlideNumber
())
{
...
...
@@ -507,7 +549,7 @@ window.shower = (function(window, document, undefined) {
}
},
false
);
window
.
addEventListener
(
'popstate'
,
function
(
e
)
{
window
.
addEventListener
(
'popstate'
,
function
(
e
)
{
if
(
shower
.
isListMode
())
{
shower
.
enterListMode
();
shower
.
scrollToSlide
(
shower
.
getCurrentSlideNumber
());
...
...
@@ -516,13 +558,13 @@ window.shower = (function(window, document, undefined) {
}
},
false
);
window
.
addEventListener
(
'resize'
,
function
(
e
)
{
window
.
addEventListener
(
'resize'
,
function
(
e
)
{
if
(
!
shower
.
isListMode
())
{
shower
.
_applyTransform
(
shower
.
_getTransform
());
}
},
false
);
document
.
addEventListener
(
'keydown'
,
function
(
e
)
{
document
.
addEventListener
(
'keydown'
,
function
(
e
)
{
// Shortcut for alt, ctrl and meta keys
if
(
e
.
altKey
||
e
.
ctrlKey
||
e
.
metaKey
)
{
return
;
}
...
...
@@ -648,7 +690,7 @@ window.shower = (function(window, document, undefined) {
document
.
addEventListener
(
'click'
,
shower
.
_dispatchSingleSlideMode
,
false
);
document
.
addEventListener
(
'touchend'
,
shower
.
_dispatchSingleSlideMode
,
false
);
document
.
addEventListener
(
'touchstart'
,
function
(
e
)
{
document
.
addEventListener
(
'touchstart'
,
function
(
e
)
{
if
(
!
shower
.
isListMode
())
{
var
currentSlideNumber
=
shower
.
getCurrentSlideNumber
(),
x
=
e
.
touches
[
0
].
pageX
;
...
...
@@ -662,7 +704,7 @@ window.shower = (function(window, document, undefined) {
}
},
false
);
document
.
addEventListener
(
'touchmove'
,
function
(
e
)
{
document
.
addEventListener
(
'touchmove'
,
function
(
e
)
{
if
(
!
shower
.
isListMode
())
{
e
.
preventDefault
();
}
...
...
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