/
flippant.js
83 lines (72 loc) · 2.64 KB
/
flippant.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(function(e){if("function"==typeof bootstrap)bootstrap("flippant",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeFlippant=e}else"undefined"!=typeof window?window.flippant=e():global.flippant=e()})(function(){var define,ses,bootstrap,module,exports;
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
exports.flip = flip
function flip(flipper, content, type, class_name, timeout) {
var position
, back
, style_func
timeout = timeout || 400
type = type || "card"
if (type === "modal") {
class_name = class_name || "flippant-modal-dark"
position = "fixed"
style_func = null_styles
}
if (type === "card") {
class_name = class_name || "flippant-modal-light"
position = "absolute"
style_func = card_styles
}
back = document.createElement('div')
document.body.appendChild(back)
set_styles(back, flipper, position)
back.innerHTML = content
flipper.classList.add('flippant')
back.classList.add('flippant-back')
back.classList.add(class_name)
if (position == "absolute") {
style_func(back)
} else {
window.setTimeout(function () {
style_func(back)
}, 0)
}
window.setTimeout(function () {
back.classList.add('flipper')
back.classList.add('flipped')
flipper.classList.add('flipped')
}, 0)
back.addEventListener('close', close)
back.close = close
function close() {
set_styles(back, flipper, position)
back.classList.remove('flipped')
back.classList.remove('flipped')
flipper.classList.remove('flipped')
window.setTimeout(function () {
back.classList.remove(class_name)
document.body.removeChild(back)
}, timeout)
}
return back
}
function set_styles(back, front, position) {
back.style.position = position
back.style.top = front.offsetTop + "px"
back.style.left = front.offsetLeft + "px"
back.style['min-height'] = front.offsetHeight + "px"
back.style.width = front.offsetWidth + "px"
back.style["z-index"] = 9999
}
function null_styles(back) {
back.style.top = null
back.style.left = null
back.style.height = null
back.style.width = null
}
function card_styles(back) {
back.style.height = 'auto'
}
},{}]},{},[1])(1)
});
;