@glitchr/transparent 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.js +128 -132
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glitchr/transparent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Transparent SPA Application",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"access": "public",
|
|
7
7
|
"repository": {
|
|
8
8
|
"url": "ssh://git@gitlab.glitchr.dev:public-repository/javascript/transparent.git",
|
package/src/index.js
CHANGED
|
@@ -1,162 +1,158 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function (root, factory) {
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
if (typeof define === 'function' && define.amd) {
|
|
4
|
+
define(factory);
|
|
5
|
+
} else if (typeof exports === 'object') {
|
|
6
|
+
module.exports = factory();
|
|
7
|
+
} else {
|
|
8
|
+
root.Transparent = factory();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
})(this, function () {
|
|
12
|
+
|
|
13
|
+
window.replaceHash = function(newHash, triggerHashChange = true, skipIfEmptyIdentifier = true) {
|
|
4
14
|
|
|
5
15
|
if(!newHash) newHash = "";
|
|
6
16
|
if (newHash !== "" && (''+newHash).charAt(0) !== '#')
|
|
7
17
|
newHash = '#' + newHash;
|
|
8
|
-
|
|
18
|
+
|
|
9
19
|
var oldURL = location.origin+location.pathname+location.hash;
|
|
10
20
|
var newURL = location.origin+location.pathname+newHash;
|
|
11
|
-
|
|
21
|
+
|
|
12
22
|
var fallback = $(newHash).length === 0;
|
|
13
|
-
|
|
23
|
+
|
|
14
24
|
var hashElement = $(newHash)[0] ?? undefined;
|
|
15
25
|
if (hashElement !== undefined) // Update hash only if element is displayed
|
|
16
26
|
fallback |= window.getComputedStyle(hashElement)["display"] == "none";
|
|
17
|
-
|
|
27
|
+
|
|
18
28
|
if((skipIfEmptyIdentifier && !newHash) || fallback){
|
|
19
|
-
|
|
29
|
+
|
|
20
30
|
dispatchEvent(new HashChangeEvent("hashfallback", {oldURL:oldURL, newURL:newURL}));
|
|
21
31
|
newHash = "";
|
|
22
|
-
|
|
32
|
+
|
|
23
33
|
oldURL = location.origin+location.pathname+location.hash;
|
|
24
34
|
newURL = location.origin+location.pathname+newHash;
|
|
25
35
|
}
|
|
26
|
-
|
|
36
|
+
|
|
27
37
|
if(oldURL == newURL) return false;
|
|
28
|
-
|
|
38
|
+
|
|
29
39
|
var state = Object.assign({}, history.state, {href: newURL});
|
|
30
40
|
history.replaceState(state, '', newURL);
|
|
31
|
-
|
|
41
|
+
|
|
32
42
|
if(triggerHashChange)
|
|
33
43
|
dispatchEvent(new HashChangeEvent("hashchange", {oldURL:oldURL, newURL:newURL}));
|
|
34
|
-
|
|
44
|
+
|
|
35
45
|
return true;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
$.fn.serializeObject = function() {
|
|
49
|
+
var o = {};
|
|
50
|
+
var a = this.serializeArray();
|
|
51
|
+
$.each(a, function() {
|
|
52
|
+
if (o[this.name]) {
|
|
53
|
+
if (!o[this.name].push) {
|
|
54
|
+
o[this.name] = [o[this.name]];
|
|
55
|
+
}
|
|
56
|
+
o[this.name].push(this.value || '');
|
|
57
|
+
} else {
|
|
58
|
+
o[this.name] = this.value || '';
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return o;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
$.fn.isScrollable = function()
|
|
65
|
+
{
|
|
66
|
+
for (let el of $(this).isScrollableX())
|
|
67
|
+
if(el) return true;
|
|
68
|
+
|
|
69
|
+
for (let el of $(this).isScrollableY())
|
|
70
|
+
if(el) return true;
|
|
71
|
+
|
|
72
|
+
return false;
|
|
36
73
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
74
|
+
|
|
75
|
+
$.fn.isScrollableX = function() {
|
|
76
|
+
|
|
77
|
+
return $(this).map(function(i) {
|
|
78
|
+
|
|
79
|
+
var el = this[i] === window ? document.documentElement : this[i];
|
|
80
|
+
var isDom = el == document.documentElement;
|
|
81
|
+
|
|
82
|
+
var hasScrollableContent = el.scrollWidth > el.clientWidth;
|
|
83
|
+
|
|
84
|
+
var overflowStyle = window.getComputedStyle(el).overflowX;
|
|
85
|
+
var isOverflowScroll = overflowStyle.indexOf('scroll') !== -1;
|
|
86
|
+
|
|
87
|
+
return hasScrollableContent && (isOverflowScroll || isDom);
|
|
88
|
+
|
|
89
|
+
}.bind(this));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
$.fn.isScrollableY = function() {
|
|
93
|
+
|
|
94
|
+
return $(this).map(function(i) {
|
|
95
|
+
|
|
96
|
+
var el = this[i] === window ? document.documentElement : this[i];
|
|
97
|
+
var isDom = el == document.documentElement;
|
|
98
|
+
|
|
99
|
+
var hasScrollableContent = el.scrollHeight > el.clientHeight;
|
|
100
|
+
|
|
101
|
+
var overflowStyle = window.getComputedStyle(el).overflowY;
|
|
102
|
+
var isOverflowScroll = overflowStyle.indexOf('scroll') !== -1;
|
|
103
|
+
|
|
104
|
+
return hasScrollableContent && (isOverflowScroll || isDom);
|
|
105
|
+
|
|
106
|
+
}.bind(this));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
$.fn.closestScrollable = function()
|
|
110
|
+
{
|
|
111
|
+
return $(this).map((i) => {
|
|
112
|
+
|
|
113
|
+
var target = this[i] === window ? document.documentElement : this[i];
|
|
114
|
+
if (target === undefined) target = document.documentElement;
|
|
115
|
+
|
|
116
|
+
while (target !== document.documentElement) {
|
|
117
|
+
|
|
118
|
+
if($(target).isScrollable()) return target;
|
|
119
|
+
|
|
120
|
+
if(target.parentElement === undefined) return undefined;
|
|
121
|
+
if(target.parentElement === null) return null;
|
|
122
|
+
|
|
123
|
+
target = target.parentElement;
|
|
47
124
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
o[this.name] = this.value || '';
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
return o;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
$.fn.isScrollable = function()
|
|
57
|
-
{
|
|
58
|
-
for (let el of $(this).isScrollableX())
|
|
59
|
-
if(el) return true;
|
|
60
|
-
|
|
61
|
-
for (let el of $(this).isScrollableY())
|
|
62
|
-
if(el) return true;
|
|
63
|
-
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
$.fn.isScrollableX = function() {
|
|
68
|
-
|
|
69
|
-
return $(this).map(function(i) {
|
|
70
|
-
|
|
71
|
-
var el = this[i] === window ? document.documentElement : this[i];
|
|
72
|
-
var isDom = el == document.documentElement;
|
|
73
|
-
|
|
74
|
-
var hasScrollableContent = el.scrollWidth > el.clientWidth;
|
|
75
|
-
|
|
76
|
-
var overflowStyle = window.getComputedStyle(el).overflowX;
|
|
77
|
-
var isOverflowScroll = overflowStyle.indexOf('scroll') !== -1;
|
|
78
|
-
|
|
79
|
-
return hasScrollableContent && (isOverflowScroll || isDom);
|
|
80
|
-
|
|
81
|
-
}.bind(this));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
$.fn.isScrollableY = function() {
|
|
85
|
-
|
|
86
|
-
return $(this).map(function(i) {
|
|
87
|
-
|
|
88
|
-
var el = this[i] === window ? document.documentElement : this[i];
|
|
89
|
-
var isDom = el == document.documentElement;
|
|
90
|
-
|
|
91
|
-
var hasScrollableContent = el.scrollHeight > el.clientHeight;
|
|
92
|
-
|
|
93
|
-
var overflowStyle = window.getComputedStyle(el).overflowY;
|
|
94
|
-
var isOverflowScroll = overflowStyle.indexOf('scroll') !== -1;
|
|
95
|
-
|
|
96
|
-
return hasScrollableContent && (isOverflowScroll || isDom);
|
|
97
|
-
|
|
98
|
-
}.bind(this));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
$.fn.closestScrollable = function()
|
|
102
|
-
{
|
|
103
|
-
return $(this).map((i) => {
|
|
104
|
-
|
|
105
|
-
var target = this[i] === window ? document.documentElement : this[i];
|
|
106
|
-
if (target === undefined) target = document.documentElement;
|
|
107
|
-
|
|
108
|
-
while (target !== document.documentElement) {
|
|
109
|
-
|
|
110
|
-
if($(target).isScrollable()) return target;
|
|
111
|
-
|
|
112
|
-
if(target.parentElement === undefined) return undefined;
|
|
113
|
-
if(target.parentElement === null) return null;
|
|
114
|
-
|
|
115
|
-
target = target.parentElement;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return $(target).isScrollable() ? target : undefined;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
$.fn.repaint = function(duration = 1000, reiteration=5) {
|
|
123
|
-
|
|
124
|
-
var time = 0;
|
|
125
|
-
var interval = undefined;
|
|
126
|
-
var fn = function () {
|
|
127
|
-
|
|
128
|
-
$(this).each(function (_, el) {
|
|
129
|
-
|
|
130
|
-
var displayBak = el.style.display;
|
|
131
|
-
|
|
132
|
-
el.style.display = "none";
|
|
133
|
-
el.style.display = displayBak;
|
|
134
|
-
el.offsetHeight;
|
|
125
|
+
|
|
126
|
+
return $(target).isScrollable() ? target : undefined;
|
|
135
127
|
});
|
|
136
|
-
|
|
137
|
-
if (time > duration) clearInterval(interval);
|
|
138
|
-
time += duration/reiteration;
|
|
139
|
-
|
|
140
|
-
}.bind(this);
|
|
141
|
-
|
|
142
|
-
fn();
|
|
143
|
-
if(reiteration > 0)
|
|
144
|
-
interval = setInterval(fn, duration/reiteration);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
;(function (root, factory) {
|
|
148
|
-
|
|
149
|
-
if (typeof define === 'function' && define.amd) {
|
|
150
|
-
define(factory);
|
|
151
|
-
} else if (typeof exports === 'object') {
|
|
152
|
-
module.exports = factory();
|
|
153
|
-
} else {
|
|
154
|
-
root.Transparent = factory();
|
|
155
128
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
129
|
+
|
|
130
|
+
$.fn.repaint = function(duration = 1000, reiteration=5) {
|
|
131
|
+
|
|
132
|
+
var time = 0;
|
|
133
|
+
var interval = undefined;
|
|
134
|
+
var fn = function () {
|
|
135
|
+
|
|
136
|
+
$(this).each(function (_, el) {
|
|
137
|
+
|
|
138
|
+
var displayBak = el.style.display;
|
|
139
|
+
|
|
140
|
+
el.style.display = "none";
|
|
141
|
+
el.style.display = displayBak;
|
|
142
|
+
el.offsetHeight;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
if (time > duration) clearInterval(interval);
|
|
146
|
+
time += duration/reiteration;
|
|
147
|
+
|
|
148
|
+
}.bind(this);
|
|
149
|
+
|
|
150
|
+
fn();
|
|
151
|
+
if(reiteration > 0)
|
|
152
|
+
interval = setInterval(fn, duration/reiteration);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
var Transparent = window.Transparent = {};
|
|
160
156
|
Transparent.version = '0.1.0';
|
|
161
157
|
|
|
162
158
|
var Settings = Transparent.settings = {
|