@litejs/ui 26.3.0 → 26.4.0
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/README.md +2 -1
- package/css/anim.css +14 -2
- package/css/global.css +6 -0
- package/el/dialog.ui +41 -32
- package/el/gallery.ui +187 -0
- package/el/slider.ui +7 -7
- package/el/sortable.ui +85 -0
- package/load.js +1 -1
- package/package.json +2 -2
- package/ui.js +226 -95
package/README.md
CHANGED
|
@@ -16,7 +16,8 @@ used on heavy-traffic websites since 2006.
|
|
|
16
16
|
Works seamlessly in ESM projects too.
|
|
17
17
|
- No transpiling/compiling/bundling headache, just write working code.
|
|
18
18
|
|
|
19
|
-
Includes templates, view routing, data binding, i18n, keyboard shortcuts,
|
|
19
|
+
Includes templates, view routing, data binding, i18n, keyboard shortcuts,
|
|
20
|
+
touch gestures, FLIP animations.
|
|
20
21
|
|
|
21
22
|
For usage instructions, see [Quick-Start](https://github.com/litejs/litejs/wiki/Quick-Start) guide
|
|
22
23
|
and [wiki](https://github.com/litejs/ui/wiki).
|
package/css/anim.css
CHANGED
|
@@ -3,11 +3,23 @@
|
|
|
3
3
|
.anim,
|
|
4
4
|
.anim:after,
|
|
5
5
|
.anim:before {
|
|
6
|
-
transition: all .
|
|
6
|
+
transition: all .35s;
|
|
7
7
|
|
|
8
8
|
/* Trigger GPU acceleration. Remove first flicker on iphone. */
|
|
9
9
|
transform: translate3d(0, 0, 0);
|
|
10
10
|
|
|
11
|
-
perspective:
|
|
11
|
+
perspective: 1000px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.flip {
|
|
15
|
+
transform-origin: 0 0;
|
|
16
|
+
transition: transform .4s, width .4s, height .4s, opacity .4s;
|
|
17
|
+
}
|
|
18
|
+
.is-lifted {
|
|
19
|
+
animation: .4s lift;
|
|
20
|
+
z-index: 3;
|
|
21
|
+
}
|
|
22
|
+
@keyframes lift {
|
|
23
|
+
70% { scale: 1.06; box-shadow: 0 5px 20px rgba(0, 0, 0, .8); }
|
|
12
24
|
}
|
|
13
25
|
|
package/css/global.css
CHANGED
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
min-height: 100%;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
.no,
|
|
15
|
+
.no-empty:empty,
|
|
16
|
+
.sm .no-sm,
|
|
17
|
+
.md .no-md,
|
|
18
|
+
.lg .no-lg,
|
|
14
19
|
.sm .sm-hide,
|
|
15
20
|
.md .md-hide,
|
|
16
21
|
.lg .lg-hide,
|
|
@@ -19,6 +24,7 @@
|
|
|
19
24
|
display: none !important;
|
|
20
25
|
visibility: hidden;
|
|
21
26
|
}
|
|
27
|
+
.op0,
|
|
22
28
|
.transparent {
|
|
23
29
|
opacity: 0 !important;
|
|
24
30
|
filter: alpha(opacity=0) !important;
|
package/el/dialog.ui
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
.Modal {
|
|
4
4
|
overflow: auto;
|
|
5
5
|
overscroll-behavior: contain;
|
|
6
|
-
z-index:
|
|
6
|
+
z-index: 8;
|
|
7
7
|
}
|
|
8
8
|
.Modal-bg {
|
|
9
|
-
background-color: rgba(0, 0, 0, .
|
|
10
|
-
pointer-events: none;
|
|
9
|
+
background-color: rgba(0, 0, 0, .8);
|
|
11
10
|
}
|
|
12
11
|
.Modal-content {
|
|
13
12
|
left: 0;
|
|
@@ -60,30 +59,26 @@
|
|
|
60
59
|
// ]
|
|
61
60
|
%js
|
|
62
61
|
$ui.on("modal", function(title, opts) {
|
|
63
|
-
var
|
|
62
|
+
var a
|
|
63
|
+
, i = 0
|
|
64
|
+
, doc = document
|
|
65
|
+
, oldFocus = doc.activeElement
|
|
64
66
|
, modal = El("Modal")
|
|
65
|
-
,
|
|
66
|
-
,
|
|
67
|
+
, scope = El.scope(modal, opts && opts.modalContent || modal, typeof opts === "string" ? { body: opts } : opts)
|
|
68
|
+
, el = scope.modalContent || El("Dialog.Modal-content.Modal--blur.abs")
|
|
67
69
|
, kbMap = {
|
|
68
70
|
bubble: 1, input: 1,
|
|
69
|
-
tab:
|
|
70
|
-
var items = $$("a[href],:is(button,input,select,textarea):not(:disabled),[tabindex]:not([tabindex='-1'])", modal)
|
|
71
|
-
, last = items.length - 1
|
|
72
|
-
if (document.activeElement === items[e.shiftKey ? 0 : last]) {
|
|
73
|
-
items[e.shiftKey ? last : 0].focus()
|
|
74
|
-
El.stop(e)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
71
|
+
tab: setFocus,
|
|
77
72
|
}
|
|
78
|
-
, body =
|
|
79
|
-
, scrollEl =
|
|
73
|
+
, body = doc.body
|
|
74
|
+
, scrollEl = doc.scrollingElement || doc.documentElement
|
|
80
75
|
, vibrate = scope.vibrate && navigator.vibrate
|
|
81
76
|
, sound = scope.sound && window.Audio && new Audio(scope.sound)
|
|
82
77
|
scope.title = title
|
|
83
78
|
if (!scope.actions) scope.actions = [
|
|
84
79
|
{ title: "Close", key: "esc" }
|
|
85
80
|
]
|
|
86
|
-
for (
|
|
81
|
+
for (; (a = scope.actions[i++]); ) {
|
|
87
82
|
if (typeof a === "string") a = scope.actions[i - 1] = { title: a, action: a }
|
|
88
83
|
if (a.key) kbMap[a.key] = resolve.bind(el, a.action)
|
|
89
84
|
}
|
|
@@ -92,28 +87,25 @@
|
|
|
92
87
|
El.append(body, modal)
|
|
93
88
|
El.render(modal)
|
|
94
89
|
El.addKb(kbMap, modal)
|
|
95
|
-
if (El.closest(
|
|
96
|
-
|
|
90
|
+
if (El.closest(doc.activeElement, 'form') !== el) {
|
|
91
|
+
setFocus()
|
|
97
92
|
}
|
|
98
|
-
El.on(el, "click", function(e) {
|
|
99
|
-
|
|
100
|
-
resolve(El.get(e.target, "data-action"), e)
|
|
93
|
+
El.on(el, "click", function(e, btn) {
|
|
94
|
+
resolve(El.get(btn, "data-action"), e)
|
|
101
95
|
}, "[data-action]")
|
|
102
96
|
El.cls(el, "Modal--blur",!1,1)
|
|
103
97
|
$ui.emit("modalOpen", scope)
|
|
104
98
|
$ui.one("show", function() { resolve() })
|
|
105
|
-
El.on(modal.firstChild, "click",
|
|
106
|
-
console.log("click resolve")
|
|
107
|
-
resolve()
|
|
108
|
-
})
|
|
99
|
+
El.on(modal.firstChild, "click", resolve)
|
|
109
100
|
if (vibrate) vibrate(scope.vibrate)
|
|
110
101
|
if (sound) sound.play()
|
|
111
102
|
El.cls(scrollEl, "no-scroll")
|
|
112
103
|
function resolve(action, e) {
|
|
113
104
|
if (modal) {
|
|
114
105
|
El.stop(e)
|
|
115
|
-
|
|
106
|
+
if (scope.beforeKill) scope.beforeKill(modal)
|
|
116
107
|
El.kill(modal, "transparent", 1)
|
|
108
|
+
El.cls(scrollEl, "no-scroll", 0)
|
|
117
109
|
if (vibrate) vibrate(0)
|
|
118
110
|
if (sound) sound.pause()
|
|
119
111
|
modal = null
|
|
@@ -124,13 +116,27 @@
|
|
|
124
116
|
if (oldFocus) oldFocus.focus()
|
|
125
117
|
}
|
|
126
118
|
}
|
|
119
|
+
function setFocus(e) {
|
|
120
|
+
El.stop(e)
|
|
121
|
+
var items = $$("a[href],button,input,select,textarea,[tabindex]", modal)
|
|
122
|
+
, len = items.length
|
|
123
|
+
, tries = len
|
|
124
|
+
, pos = items.indexOf(doc.activeElement)
|
|
125
|
+
for (; tries--; ) {
|
|
126
|
+
pos += e && e.shiftKey ? -1 : 1
|
|
127
|
+
if (pos < 0) pos = len - 1
|
|
128
|
+
else if (pos >= len) pos = 0
|
|
129
|
+
items[pos].focus()
|
|
130
|
+
if (doc.activeElement === items[pos]) return
|
|
131
|
+
}
|
|
132
|
+
}
|
|
127
133
|
})
|
|
128
134
|
|
|
129
135
|
%el Modal
|
|
130
|
-
.Modal.fix.max.anim>.Modal-bg.abs.max
|
|
136
|
+
.Modal.fix.max.anim>.Modal-bg.abs.max.anim.op0;cls!'op0',0,1
|
|
131
137
|
|
|
132
138
|
%el Dialog
|
|
133
|
-
form.Dialog.grid.p2.anim[action="javascript:"][method=POST][
|
|
139
|
+
form.Dialog.grid.p2.anim[action="javascript:"][method=POST][role=dialog]
|
|
134
140
|
.col>h1 ;txt title
|
|
135
141
|
.col ;if body; d body
|
|
136
142
|
%slot
|
|
@@ -144,13 +150,16 @@ form.Dialog.grid.p2.anim[action="javascript:"][method=POST][tabindex='-1']
|
|
|
144
150
|
|
|
145
151
|
%el Dialog-input
|
|
146
152
|
.col
|
|
147
|
-
input
|
|
153
|
+
input[type=hidden][name=hi]
|
|
154
|
+
input.field[name=value][type=text][placeholder="Enter value"]
|
|
148
155
|
|
|
149
156
|
%el Dialog-numpad
|
|
150
157
|
.grid.p1.js-numpad
|
|
151
158
|
@click function(e,b,n,v){$s.in.value=(v=$s.in.value,n=b[El.T])>-1?v+n:n=='DEL'?v.slice(0,-1):'',$s.in.focus()},'.btn'
|
|
152
|
-
;kb!{num:function(e,b,n){$s.in.value=(n)>-1?$s.in.value+n:''},del:function(e,b,n){$s.in.value=$s.in.value.slice(
|
|
153
|
-
.col
|
|
159
|
+
;kb!{num:function(e,b,n){$s.in.value=(n)>-1?$s.in.value+n:''},del:function(e,b,n){$s.in.value=$s.in.value.slice(0,-1)}}
|
|
160
|
+
.col
|
|
161
|
+
input[type=hidden][name=hi]
|
|
162
|
+
input[name=code] ;ref!'in';focus
|
|
154
163
|
.col.w4
|
|
155
164
|
;each! "num",[1,2,3,4,5,6,7,8,9,"CLEAR",0,"DEL"]
|
|
156
165
|
button.btn.w12[type=button]
|
package/el/gallery.ui
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
|
|
2
|
+
%css
|
|
3
|
+
.Gallery {
|
|
4
|
+
display: grid;
|
|
5
|
+
place-items: center;
|
|
6
|
+
}
|
|
7
|
+
.Gallery-img {
|
|
8
|
+
grid-area: 1 / 1;
|
|
9
|
+
max-width: 90%;
|
|
10
|
+
max-height: 90%;
|
|
11
|
+
object-fit: contain;
|
|
12
|
+
opacity: 0;
|
|
13
|
+
transition: opacity .3s;
|
|
14
|
+
}
|
|
15
|
+
.Gallery-img.is-active {
|
|
16
|
+
opacity: 1;
|
|
17
|
+
}
|
|
18
|
+
.Gallery-nav {
|
|
19
|
+
grid-area: 1 / 1;
|
|
20
|
+
position: relative;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
z-index: 1;
|
|
24
|
+
}
|
|
25
|
+
.Gallery-nav > button {
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 50%;
|
|
28
|
+
transform: translateY(-50%);
|
|
29
|
+
background: none;
|
|
30
|
+
border: none;
|
|
31
|
+
color: #fff;
|
|
32
|
+
font-size: 2em;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
opacity: .5;
|
|
35
|
+
padding: .5em;
|
|
36
|
+
}
|
|
37
|
+
.Gallery-nav > button:hover {
|
|
38
|
+
opacity: 1;
|
|
39
|
+
}
|
|
40
|
+
.Gallery-nav--prev {
|
|
41
|
+
left: 0;
|
|
42
|
+
}
|
|
43
|
+
.Gallery-nav--next {
|
|
44
|
+
right: 0;
|
|
45
|
+
}
|
|
46
|
+
.Gallery-counter {
|
|
47
|
+
position: absolute;
|
|
48
|
+
bottom: 1em;
|
|
49
|
+
left: 50%;
|
|
50
|
+
transform: translateX(-50%);
|
|
51
|
+
color: #fff;
|
|
52
|
+
opacity: .7;
|
|
53
|
+
z-index: 2;
|
|
54
|
+
}
|
|
55
|
+
.Gallery-anim {
|
|
56
|
+
transition: transform .3s ease;
|
|
57
|
+
transform-origin: 0 0;
|
|
58
|
+
}
|
|
59
|
+
.ImageGrid {
|
|
60
|
+
display: grid;
|
|
61
|
+
grid-template-columns: 2fr 1fr;
|
|
62
|
+
grid-template-rows: repeat(3, 1fr);
|
|
63
|
+
gap: 2px;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
max-width: 600px;
|
|
66
|
+
}
|
|
67
|
+
.ImageGrid-frame {
|
|
68
|
+
overflow: hidden;
|
|
69
|
+
position: relative;
|
|
70
|
+
transform-origin: 0 0;
|
|
71
|
+
}
|
|
72
|
+
.ImageGrid-anim {
|
|
73
|
+
transform-origin: 0 0;
|
|
74
|
+
}
|
|
75
|
+
.ImageGrid-frame:first-child {
|
|
76
|
+
grid-row: 1 / -1;
|
|
77
|
+
}
|
|
78
|
+
.ImageGrid-frame>img {
|
|
79
|
+
width: 100%;
|
|
80
|
+
height: 100%;
|
|
81
|
+
object-fit: cover;
|
|
82
|
+
display: block;
|
|
83
|
+
}
|
|
84
|
+
.ImageGrid-count {
|
|
85
|
+
position: absolute;
|
|
86
|
+
bottom: 2px;
|
|
87
|
+
right: 2px;
|
|
88
|
+
background: rgba(0, 0, 0, .6);
|
|
89
|
+
color: #fff;
|
|
90
|
+
font-size: 1.5em;
|
|
91
|
+
font-weight: 700;
|
|
92
|
+
border-radius: 20px;
|
|
93
|
+
border: 1px solid #999;
|
|
94
|
+
z-index: 2;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
%js
|
|
98
|
+
$d.initGalleryImages = function(el) {
|
|
99
|
+
for (var images = $$("img[src]", el), i = images.length, arr = []; i--; ) arr[i] = images[i].src
|
|
100
|
+
images.kill()
|
|
101
|
+
return arr
|
|
102
|
+
}
|
|
103
|
+
$ui.on("flipToFirst", function toFirst(ev, el) {
|
|
104
|
+
var parent = el.parentNode
|
|
105
|
+
, first = parent.firstChild
|
|
106
|
+
if (el !== first) {
|
|
107
|
+
El.stop(ev)
|
|
108
|
+
El.flip(parent, 0, function() {
|
|
109
|
+
El.append(parent, el, first)
|
|
110
|
+
}, {scale:1})
|
|
111
|
+
El.cls(el, "is-lifted", toFirst._prev, 1, -1)
|
|
112
|
+
toFirst._prev = el
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
$ui.on("gallery", function(ev, thumb) {
|
|
116
|
+
var preview = El.closest(thumb, ".ImageGrid")
|
|
117
|
+
if (!preview) return
|
|
118
|
+
var images = El.scope(preview).images
|
|
119
|
+
, current = +El.get(thumb, "data-index") || 0
|
|
120
|
+
, el = El("Gallery")
|
|
121
|
+
, img1 = el.querySelector(".Gallery-img")
|
|
122
|
+
, img2 = img1.nextSibling
|
|
123
|
+
, counter = el.querySelector(".Gallery-counter")
|
|
124
|
+
, activeImg = img1
|
|
125
|
+
, thumbImg = thumb.querySelector("img") || thumb
|
|
126
|
+
, scope = El.scope(el, el, {
|
|
127
|
+
images: images,
|
|
128
|
+
nav: function(e, btn) {
|
|
129
|
+
El.stop(e)
|
|
130
|
+
show(current + (El.matches(btn, ".Gallery-nav--prev") ? -1 : 1))
|
|
131
|
+
},
|
|
132
|
+
flipIn: function() {
|
|
133
|
+
El.morph(thumbImg, activeImg, { anim: "Gallery-anim", scale:1 })
|
|
134
|
+
},
|
|
135
|
+
beforeKill: function() {
|
|
136
|
+
var thumbs = $$("[data-index]", preview)
|
|
137
|
+
, target = thumbs[current] || thumbs.pop()
|
|
138
|
+
if (target) {
|
|
139
|
+
El.morph(activeImg, target, { scale:1 })
|
|
140
|
+
El.css(target, "z-index", 10, 0, -2)
|
|
141
|
+
El.kill(activeImg)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
show(current, 1)
|
|
146
|
+
$ui.emit("modal", "", {
|
|
147
|
+
modalContent: el,
|
|
148
|
+
actions: [{ title: "Close", key: "esc" }]
|
|
149
|
+
})
|
|
150
|
+
activeImg.src = thumbImg.src
|
|
151
|
+
function show(idx, initial) {
|
|
152
|
+
current = scope.current = ((idx % images.length) + images.length) % images.length
|
|
153
|
+
var nextImg = activeImg === img1 ? img2 : img1
|
|
154
|
+
if (initial && activeImg.src === images[current]) return
|
|
155
|
+
nextImg.src = images[current]
|
|
156
|
+
nextImg.onload = function() {
|
|
157
|
+
El.cls(nextImg, "is-active", activeImg)
|
|
158
|
+
activeImg = nextImg
|
|
159
|
+
}
|
|
160
|
+
El.render(el)
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
%el Gallery
|
|
165
|
+
.Gallery.abs.max
|
|
166
|
+
img.Gallery-img
|
|
167
|
+
@load!flipIn
|
|
168
|
+
img.Gallery-img
|
|
169
|
+
.Gallery-nav
|
|
170
|
+
;if images.length > 1
|
|
171
|
+
@tap nav,"button"
|
|
172
|
+
button.Gallery-nav--prev[aria-label=Previous] ;txt! "\u276E"
|
|
173
|
+
button.Gallery-nav--next[aria-label=Next] ;txt! "\u276F"
|
|
174
|
+
.Gallery-counter
|
|
175
|
+
;txt (current+1)+" / "+images.length
|
|
176
|
+
|
|
177
|
+
%el ImageGrid
|
|
178
|
+
.ImageGrid.rel
|
|
179
|
+
;$s!{images:initGalleryImages($el)}
|
|
180
|
+
.ImageGrid-frame[data-index=0]
|
|
181
|
+
img ;src!images[0]
|
|
182
|
+
.ImageGrid-frame
|
|
183
|
+
;each! "src", images.slice(1, 4)
|
|
184
|
+
;data-index!$i+1
|
|
185
|
+
img ;src!src
|
|
186
|
+
.ImageGrid-count.p02 ;if images.length > 4
|
|
187
|
+
;txt '+' + (images.length - 4)
|
package/el/slider.ui
CHANGED
|
@@ -160,17 +160,17 @@
|
|
|
160
160
|
elOn(el, "pointerdown", function(e) {
|
|
161
161
|
drag = true
|
|
162
162
|
load()
|
|
163
|
-
var tmp =
|
|
163
|
+
var tmp = El.rect(el)
|
|
164
164
|
offset = tmp.left + El.scrollLeft() + knobLen
|
|
165
|
-
var next, i
|
|
165
|
+
var next, i = 0
|
|
166
166
|
, x = maxPx
|
|
167
167
|
, diff = e.pageX - offset
|
|
168
|
-
for (
|
|
168
|
+
for (; i < fills.length; i++) {
|
|
169
169
|
next = diff - fills[i].offsetWidth + knobLen
|
|
170
|
-
if (next < 0 ?
|
|
170
|
+
if ((next < 0 ? next*=-1 : next) <= x) {
|
|
171
171
|
idx = i
|
|
172
172
|
fill = fills[i]
|
|
173
|
-
x = next
|
|
173
|
+
x = next
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
tmp = offset - e.pageX + (values[idx]-min||0)*px
|
|
@@ -185,9 +185,9 @@
|
|
|
185
185
|
emit(e)
|
|
186
186
|
return El.stop(e)
|
|
187
187
|
}
|
|
188
|
-
function stop(
|
|
188
|
+
function stop() {
|
|
189
189
|
if (drag) {
|
|
190
|
-
drag =
|
|
190
|
+
drag = 0
|
|
191
191
|
listen(elOff)
|
|
192
192
|
setVal(idx, values[idx])
|
|
193
193
|
}
|
package/el/sortable.ui
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
|
|
2
|
+
%css
|
|
3
|
+
.sortable{margin:-8px}
|
|
4
|
+
.sortable:after{content:"";display:block;clear:both;}
|
|
5
|
+
.sortItem{padding:8px 12px;background:#f5f5f5;border:1px solid #ddd;border-radius:4px;}
|
|
6
|
+
.is-dragging{box-shadow:0 4px 12px rgba(0,0,0,.3);cursor:grabbing;z-index:2;position:relative;pointer-events:none;}
|
|
7
|
+
.grip{font-size:2em;cursor:grab;float:left;}
|
|
8
|
+
.is-active{outline:2px dashed #4a90d9;position:relative;z-index:1;perspective:1000px;}
|
|
9
|
+
|
|
10
|
+
%js
|
|
11
|
+
var closest = El.closest, cls = El.cls, css = El.css
|
|
12
|
+
$ui.on("dragSort", function(e0, handle, sel, cols) {
|
|
13
|
+
var mode = e0.mode
|
|
14
|
+
, el = e0.el
|
|
15
|
+
, item = closest(handle, sel)
|
|
16
|
+
if (!item) return
|
|
17
|
+
var items = El.flip(el, sel)
|
|
18
|
+
, fromIdx = items.indexOf(item)
|
|
19
|
+
, toIdx = fromIdx
|
|
20
|
+
, fromCol = cols && item.parentNode
|
|
21
|
+
, toCol = fromCol
|
|
22
|
+
, flipSel = cols ? sel + "," + cols : sel
|
|
23
|
+
e0.left = items[fromIdx + 1].left
|
|
24
|
+
e0.top = items[fromIdx + 1].top
|
|
25
|
+
cls(item, "is-dragging")
|
|
26
|
+
cls(el, "no-select")
|
|
27
|
+
cls(toCol, "is-active")
|
|
28
|
+
El.on(el, mode, move)
|
|
29
|
+
El.on(el, mode + "end", end)
|
|
30
|
+
function move(e) {
|
|
31
|
+
if (!item) return
|
|
32
|
+
El.stop(e)
|
|
33
|
+
var dist, dx, dy
|
|
34
|
+
, i = items.length
|
|
35
|
+
, idx = toIdx
|
|
36
|
+
, min = Infinity
|
|
37
|
+
, col = cols && closest(document.elementFromPoint(e.clientX, e.clientY), cols)
|
|
38
|
+
if (col && col !== toCol) {
|
|
39
|
+
cls(col, "is-active", toCol)
|
|
40
|
+
toCol = col
|
|
41
|
+
if (!$ui.$(sel, col)) idx = -1
|
|
42
|
+
}
|
|
43
|
+
if (idx > -1) for (; i > 0; i -= 2) {
|
|
44
|
+
if (cols && items[i - 2].parentNode !== (col || toCol)) continue
|
|
45
|
+
dx = e.ex - items[i - 1].left
|
|
46
|
+
dy = e.ey - items[i - 1].top
|
|
47
|
+
dist = dx * dx + dy * dy
|
|
48
|
+
if (dist < min) {
|
|
49
|
+
min = dist
|
|
50
|
+
idx = i - 2
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
dx = dy = 0
|
|
54
|
+
if (idx - toIdx) {
|
|
55
|
+
items = El.flip(el, flipSel, function() {
|
|
56
|
+
if (idx < 0) return col.appendChild(item)
|
|
57
|
+
var target = items[idx]
|
|
58
|
+
, rect = items[idx + 1]
|
|
59
|
+
, after = col && target.parentNode !== item.parentNode ? e.ey > rect.top : toIdx < idx
|
|
60
|
+
target.parentNode.insertBefore(item, after ? target.nextSibling : target)
|
|
61
|
+
}, { skip: item, height: 1 })
|
|
62
|
+
toIdx = items.indexOf(item)
|
|
63
|
+
dx = e0.left - items[toIdx + 1].left
|
|
64
|
+
dy = e0.top - items[toIdx + 1].top
|
|
65
|
+
e0.x0 -= dx
|
|
66
|
+
e0.y0 -= dy
|
|
67
|
+
e0.left -= dx
|
|
68
|
+
e0.top -= dy
|
|
69
|
+
}
|
|
70
|
+
css(item, "transform", "translate3d(" + (e.dx + dx) + "px," + (e.dy + dy) + "px,20px)")
|
|
71
|
+
}
|
|
72
|
+
function end() {
|
|
73
|
+
if (item) {
|
|
74
|
+
El.off(el, mode, move)
|
|
75
|
+
El.off(el, mode + "end", end)
|
|
76
|
+
cls(el, "no-select", 0)
|
|
77
|
+
cls(item, "anim,is-dragging", 1, 0, -1)
|
|
78
|
+
cls(toCol, "is-active", 0, 350)
|
|
79
|
+
css(item, "transform", "")
|
|
80
|
+
css(item, "box-shadow", "0 0 0 rgba(0,0,0,0)",0,-2)
|
|
81
|
+
if (fromIdx - toIdx || fromCol !== toCol) El.emit(el, "sorted")
|
|
82
|
+
item = null
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
})
|
package/load.js
CHANGED
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
)
|
|
170
170
|
/*** ie9 ***/
|
|
171
171
|
// ActiveXObject does not accept `null` for onreadystatechange
|
|
172
|
-
req.onreadystatechange = next = nop
|
|
172
|
+
req.onreadystatechange = req.onabort = req.onerror = req.ontimeout = next = nop
|
|
173
173
|
xhrs.push(req)
|
|
174
174
|
/*/
|
|
175
175
|
req.onreadystatechange = next = null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litejs/ui",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.4.0",
|
|
4
4
|
"description": "UI engine for LiteJS full-stack framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lauri Rooden <lauri@rooden.ee>",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"test": "lj t test/index.js"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@litejs/cli": "26.
|
|
30
|
+
"@litejs/cli": "26.4.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/ui.js
CHANGED
|
@@ -21,6 +21,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
21
21
|
, THIS = this
|
|
22
22
|
, html = document.documentElement
|
|
23
23
|
, body = document.body
|
|
24
|
+
, canTransit = "on" + (canTransit = "transitionend") in body && canTransit
|
|
24
25
|
, splitRe = /[,\s]+/
|
|
25
26
|
, emptyArr = []
|
|
26
27
|
, plugins = {}
|
|
@@ -32,12 +33,11 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
32
33
|
, hasOwn = bind(plugins.hasOwnProperty)
|
|
33
34
|
, isArr = Array.isArray
|
|
34
35
|
, slice = emptyArr.slice
|
|
35
|
-
|
|
36
|
-
,
|
|
37
|
-
,
|
|
38
|
-
,
|
|
39
|
-
,
|
|
40
|
-
, toCamel = replace.bind(NUL, /\-([a-z])/g, Function("a,b", "return b.toUpperCase()"))
|
|
36
|
+
, elReplace = function(el, to, p) { if (el && to && (p = el.parentNode)) p.replaceChild(to, el) }
|
|
37
|
+
, elRm = function(el, p) { if (el && (p = el.parentNode)) p.removeChild(el) }
|
|
38
|
+
, getAttr = function(el, key) { return el && el.getAttribute && el.getAttribute(key) }
|
|
39
|
+
, replace = function(re, to, str) { return str.replace(re, to) }
|
|
40
|
+
, toCamel = function(str) { return str.replace(/\-([a-z])/g, function(_, ch) { return ch.toUpperCase() }) }
|
|
41
41
|
|
|
42
42
|
/*** ie9 ***/
|
|
43
43
|
// JScript engine in IE8 and below does not recognize vertical tabulation character `\v`.
|
|
@@ -65,6 +65,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
65
65
|
// Matches tokens to exclude from scope variable extraction: strings, keywords, member access, labels
|
|
66
66
|
, fnRe = /('|")(?:\\.|[^\\])*?\1|\/(?:\\.|[^\\])+?\/[gim]*|\$el\b|\$[aorsS]\b|\b(?:false|in|if|new|null|this|true|typeof|void|function|var|else|return)\b|\.\w+|\w+:/g
|
|
67
67
|
, wordRe = /[a-z_$][\w$]*/ig
|
|
68
|
+
, bindingsCls = acceptMany(cls)
|
|
68
69
|
, bindingsCss = acceptMany(function(el, key, val, current) {
|
|
69
70
|
current = el.style[key = toCamel(key)]
|
|
70
71
|
el.style[key] = val
|
|
@@ -72,15 +73,10 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
72
73
|
})
|
|
73
74
|
, bindingsOn = acceptMany(addEvent, 1)
|
|
74
75
|
, bindings = {
|
|
75
|
-
cls:
|
|
76
|
+
cls: bindingsCls,
|
|
76
77
|
css: bindingsCss,
|
|
77
78
|
on: bindingsOn,
|
|
78
|
-
one: acceptMany(
|
|
79
|
-
addEvent(el, ev, function remove() {
|
|
80
|
-
rmEvent(el, ev, remove)
|
|
81
|
-
fn.apply(el, arguments)
|
|
82
|
-
})
|
|
83
|
-
}, 1),
|
|
79
|
+
one: acceptMany(onceEvent, 1),
|
|
84
80
|
set: acceptMany(setAttr),
|
|
85
81
|
txt: elTxt,
|
|
86
82
|
/*** form ***/
|
|
@@ -187,10 +183,12 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
187
183
|
, fixFn = Event.fixFn || (Event.fixFn = {})
|
|
188
184
|
|
|
189
185
|
/*** markup ***/
|
|
190
|
-
, blockRe = /^(?:(=+|>|
|
|
186
|
+
, blockRe = /^(?:(=+|>| -| \d+\.) ([\s\S]+))/
|
|
191
187
|
, tags = {
|
|
192
188
|
" -": "ul",
|
|
193
|
-
"
|
|
189
|
+
"\"": "q",
|
|
190
|
+
"%": "small",
|
|
191
|
+
"&": "kbd",
|
|
194
192
|
"*": "b",
|
|
195
193
|
"+": "ins",
|
|
196
194
|
",": "sub",
|
|
@@ -199,33 +197,57 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
199
197
|
":": "mark",
|
|
200
198
|
";": "span",
|
|
201
199
|
">": "blockquote",
|
|
200
|
+
"?": "abbr",
|
|
202
201
|
"@": "time",
|
|
203
202
|
"^": "sup",
|
|
204
203
|
"_": "u",
|
|
205
204
|
"`": "code",
|
|
206
205
|
"~": "s"
|
|
207
206
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
)
|
|
218
|
-
"
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
207
|
+
, abbrs = {}
|
|
208
|
+
, embeds = {}
|
|
209
|
+
function a(name, val) {
|
|
210
|
+
return val ? " " + name + "=\"" + replace(/"/g, """, val) + "\"" : ""
|
|
211
|
+
}
|
|
212
|
+
function renderOp(op, text, extra) {
|
|
213
|
+
var num = parseInt(op, 10)
|
|
214
|
+
, tag = num >= 0 ? (extra += a("start", num != 1 && "" + num), "ol") : tags[op] || "h" + op.length
|
|
215
|
+
return "<" + (extra ? tag + extra : tag) + ">" + (
|
|
216
|
+
op === ">" ? doc(replace(/^> ?/gm, "", text)) :
|
|
217
|
+
tag == "ul" || num >= 0 ? "<li>" + text.split(/\n (?:\d+\.|-) (?=\S)/).map(inline).join("</li>\n<li>") + "</li>" :
|
|
218
|
+
inline(text)
|
|
219
|
+
) + "</" + tag + ">"
|
|
220
|
+
}
|
|
221
|
+
function inline(tag, text, url, op, content, attr) {
|
|
222
|
+
var extra = attr ? a("class", attr.slice(1)) : ""
|
|
223
|
+
if (url && !isArr(url)) {
|
|
224
|
+
return "<a" + a("href", url) + extra + ">" + inline(text || url) + "</a>"
|
|
225
|
+
}
|
|
226
|
+
if (op) {
|
|
227
|
+
if (op == "!") {
|
|
228
|
+
var fn = embeds[content.split(":")[0]]
|
|
229
|
+
return fn ? fn(content, text, extra, a) :
|
|
230
|
+
"<img" + a("src", content) + a("alt", text || replace(/.*\//, "", content)) + extra + ">"
|
|
231
|
+
}
|
|
232
|
+
if (op == "?") {
|
|
233
|
+
if (text) abbrs[content] = text
|
|
234
|
+
else text = abbrs[content]
|
|
235
|
+
}
|
|
236
|
+
extra += op == "@" ? a("datetime", content) : a(op == "\"" ? "cite" : "title", text)
|
|
237
|
+
if (op == "@") {
|
|
238
|
+
content = text || content
|
|
239
|
+
}
|
|
240
|
+
return renderOp(op, content, extra)
|
|
241
|
+
}
|
|
242
|
+
return replace(/\[(?:(.+?) )?(?:<([^>]+)>|([-!"%&*+,/:;?@^_`~])(.+?)\3)(\.[\w.]+)?]/g, inline, tag)
|
|
243
|
+
}
|
|
244
|
+
function block(tag, op, text) {
|
|
245
|
+
return op && !isArr(text) ? renderOp(op, text, "") :
|
|
224
246
|
blockRe.test(tag) ? replace(blockRe, block, tag) :
|
|
225
247
|
tag === "---" ? "<hr>" : "<p>" + inline(tag) + "</p>"
|
|
226
248
|
}
|
|
227
249
|
function doc(txt) {
|
|
228
|
-
return replace(/^ \b/gm, "<br>", txt.trim()).split(/\n\n+/).map(block).join("\n")
|
|
250
|
+
return replace(/^ (?!\d+\. )\b/gm, "<br>", txt.trim()).split(/\n\n+/).map(block).join("\n")
|
|
229
251
|
}
|
|
230
252
|
bindings.t = function(el, text) {
|
|
231
253
|
el.innerHTML = inline(replace(/</g, "<", text))
|
|
@@ -233,6 +255,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
233
255
|
bindings.d = function(el, text) {
|
|
234
256
|
el.innerHTML = doc(replace(/</g, "<", text))
|
|
235
257
|
}
|
|
258
|
+
bindings.d.embed = embeds
|
|
236
259
|
/**/
|
|
237
260
|
|
|
238
261
|
/*** svg ***/
|
|
@@ -305,17 +328,23 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
305
328
|
if (emitter === window) emitter = emptyArr
|
|
306
329
|
var args, i
|
|
307
330
|
, _e = emitter._e
|
|
308
|
-
, arr = _e
|
|
309
|
-
|
|
310
|
-
|
|
331
|
+
, arr = _e && _e[type] || emptyArr
|
|
332
|
+
, wild = _e && _e["*"] || emptyArr
|
|
333
|
+
, len = arr.length + wild.length
|
|
334
|
+
if (len) {
|
|
335
|
+
args = slice.call(arguments, 2)
|
|
336
|
+
for (i = arr.length - 1; i > 1; i -= 3) {
|
|
311
337
|
if (arr[i]) arr[i].apply(arr[i - 2] || emitter, args)
|
|
312
338
|
}
|
|
339
|
+
for (i = wild.length - 1; i > 1; i -= 3) {
|
|
340
|
+
if (wild[i]) wild[i].apply(wild[i - 2] || emitter, args)
|
|
341
|
+
}
|
|
313
342
|
}
|
|
314
|
-
return
|
|
343
|
+
return len / 3
|
|
315
344
|
}
|
|
316
345
|
|
|
317
|
-
function addEvent(el, ev, fn, opts) {
|
|
318
|
-
var fn2 = fixFn[ev] && fixFn[ev](el, fn, ev) || fn
|
|
346
|
+
function addEvent(el, ev, fn, opts, fix) {
|
|
347
|
+
var fn2 = fix || fixFn[ev] && fixFn[ev](el, fn, ev) || fn
|
|
319
348
|
, ev2 = fixEv[ev] || ev
|
|
320
349
|
|
|
321
350
|
if (ev2 !== "") {
|
|
@@ -328,7 +357,12 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
328
357
|
|
|
329
358
|
on(el, ev, fn2, el, fn)
|
|
330
359
|
}
|
|
331
|
-
|
|
360
|
+
function onceEvent(el, ev, fn, opts) {
|
|
361
|
+
addEvent(el, ev, fn, opts, function remove() {
|
|
362
|
+
rmEvent(el, ev, fn, opts)
|
|
363
|
+
fn.apply(el, arguments)
|
|
364
|
+
})
|
|
365
|
+
}
|
|
332
366
|
function rmEvent(el, ev, fn, opts) {
|
|
333
367
|
var evs = el._e && el._e[ev]
|
|
334
368
|
, id = evs && evs.indexOf(fn)
|
|
@@ -1102,9 +1136,12 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1102
1136
|
assign(El, bindings, {
|
|
1103
1137
|
emit: emit,
|
|
1104
1138
|
empty: elEmpty,
|
|
1139
|
+
flip: elFlip,
|
|
1105
1140
|
kill: elKill,
|
|
1141
|
+
morph: elMorph,
|
|
1106
1142
|
off: acceptMany(rmEvent),
|
|
1107
1143
|
render: render,
|
|
1144
|
+
rect: rect,
|
|
1108
1145
|
rm: elRm
|
|
1109
1146
|
})
|
|
1110
1147
|
|
|
@@ -1293,12 +1330,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1293
1330
|
|
|
1294
1331
|
function hasClass(el, name) {
|
|
1295
1332
|
var current = el.className || ""
|
|
1296
|
-
|
|
1297
|
-
if (!isStr(current)) {
|
|
1298
|
-
current = getAttr(el, "class") || ""
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
return !!current && current.split(splitRe).indexOf(name) > -1
|
|
1333
|
+
return (" " + (isStr(current) ? current : getAttr(el, "class") || "-") + " ").indexOf(" " + name + " ") > -1
|
|
1302
1334
|
}
|
|
1303
1335
|
|
|
1304
1336
|
function cls(el, name, set) {
|
|
@@ -1334,15 +1366,108 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1334
1366
|
function elEmpty(el) {
|
|
1335
1367
|
for (; el.lastChild; elKill(el.lastChild));
|
|
1336
1368
|
}
|
|
1369
|
+
function elFlip(el, sel, fn, opts) {
|
|
1370
|
+
opts = assign({ anim: "flip", enter: "op0", leave: "op0" }, opts)
|
|
1371
|
+
var newPos, c, idx, r1
|
|
1372
|
+
, i = 0
|
|
1373
|
+
, anim = 0
|
|
1374
|
+
, anims = []
|
|
1375
|
+
, parent = rect(el)
|
|
1376
|
+
, oldPos = opts.old || rects()
|
|
1377
|
+
, leave = opts.leave
|
|
1378
|
+
, stagger = opts.stagger|0
|
|
1379
|
+
, transformTransition = "transform,transition"
|
|
1380
|
+
if (!fn) return oldPos
|
|
1381
|
+
fn()
|
|
1382
|
+
newPos = rects(1)
|
|
1383
|
+
for (; (c = oldPos[i]); i += 2) if (c !== opts.skip) {
|
|
1384
|
+
idx = newPos.indexOf(c)
|
|
1385
|
+
r1 = oldPos[i + 1]
|
|
1386
|
+
if (idx > -1) {
|
|
1387
|
+
if (addTransform(c, r1, newPos[idx + 1], opts)) anims[anim++] = c
|
|
1388
|
+
} else if (leave) {
|
|
1389
|
+
bindingsCss(c, {
|
|
1390
|
+
position: "absolute",
|
|
1391
|
+
left: (r1.left - parent.left) + "px",
|
|
1392
|
+
top: (r1.top - parent.top) + "px",
|
|
1393
|
+
width: r1.width + "px",
|
|
1394
|
+
height: r1.height + "px",
|
|
1395
|
+
})
|
|
1396
|
+
c._flip = 1
|
|
1397
|
+
append(el, (anims[anim++] = c))
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
if ((r1 = opts.enter)) for (i = 0; (c = newPos[i]); i += 2) if (oldPos.indexOf(c) < 0) {
|
|
1401
|
+
bindingsCls(c, r1, 1, 0, anim*stagger || 1)
|
|
1402
|
+
anims[anim++] = c
|
|
1403
|
+
}
|
|
1404
|
+
for (el.offsetHeight; anim; ) {
|
|
1405
|
+
c = anims[--anim]
|
|
1406
|
+
bindingsCls(c, opts.anim, 1, 0, -1)
|
|
1407
|
+
if (c._flip) {
|
|
1408
|
+
elKill(c, leave, anim*stagger)
|
|
1409
|
+
} else {
|
|
1410
|
+
bindingsCss(c, transformTransition, "", anim*stagger)
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
return newPos
|
|
1414
|
+
function rects(reset) {
|
|
1415
|
+
var child
|
|
1416
|
+
, j = 0
|
|
1417
|
+
, arr = sel ? findAll(el, sel) : el.children
|
|
1418
|
+
, res = []
|
|
1419
|
+
if (reset) {
|
|
1420
|
+
for (el.offsetHeight; (child = arr[j++]); ) if (!child._flip) {
|
|
1421
|
+
cls(child, opts.anim, 0)
|
|
1422
|
+
bindingsCss(child, transformTransition, "none")
|
|
1423
|
+
}
|
|
1424
|
+
j = 0
|
|
1425
|
+
}
|
|
1426
|
+
for (el.offsetHeight; (child = arr[j++]); ) if (!child._flip) {
|
|
1427
|
+
res.push(child, rect(child))
|
|
1428
|
+
bindingsCss(child, transformTransition, "")
|
|
1429
|
+
}
|
|
1430
|
+
return res
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
function addTransform(el, from, to, opts) {
|
|
1434
|
+
var a = rect(from)
|
|
1435
|
+
, b = rect(to)
|
|
1436
|
+
, dx = a.left - b.left
|
|
1437
|
+
, dy = a.top - b.top
|
|
1438
|
+
, aw = a.width
|
|
1439
|
+
, ah = a.height
|
|
1440
|
+
, bw = b.width
|
|
1441
|
+
, bh = b.height
|
|
1442
|
+
if (canTransit && (dx || dy || (aw - bw) || (ah - bh))) {
|
|
1443
|
+
bindingsCss(el, "transform", "translate(" + dx + "px," + dy + "px)" + (opts.scale ? " scale(" + (aw / bw) + "," + (ah / bh) + ")" : ""))
|
|
1444
|
+
swap("height", ah, bh)
|
|
1445
|
+
swap("width", aw, bw)
|
|
1446
|
+
return el
|
|
1447
|
+
}
|
|
1448
|
+
function swap(key, from, to) {
|
|
1449
|
+
if (opts[key] && (from - to)) {
|
|
1450
|
+
bindingsCss(el, key, to + "px", 1, -2)
|
|
1451
|
+
bindingsCss(el, key, from + "px")
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
function elMorph(from, to, opts) {
|
|
1456
|
+
opts = assign({ anim: "flip" }, opts)
|
|
1457
|
+
if (from && to && addTransform(to, from, to, opts)) {
|
|
1458
|
+
void to.offsetWidth
|
|
1459
|
+
bindingsCls(to, opts.anim, 1, 0, -1)
|
|
1460
|
+
bindingsCss(to, "transform", "")
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1337
1463
|
function elKill(el, tr, delay) {
|
|
1338
1464
|
if (el) {
|
|
1339
1465
|
if (delay > 0) return setTimeout(elKill, delay, el, tr)
|
|
1340
|
-
if (tr) {
|
|
1466
|
+
if (tr && canTransit) {
|
|
1341
1467
|
if (isStr(tr)) cls(el, tr)
|
|
1342
1468
|
if (isObj(tr)) bindingsCss(el, tr)
|
|
1343
|
-
tr = "transitionend"
|
|
1344
1469
|
// transitionend fires for each property transitioned
|
|
1345
|
-
|
|
1470
|
+
return onceEvent(el, canTransit, bind(elKill, el, el, UNDEF))
|
|
1346
1471
|
}
|
|
1347
1472
|
if (el._e) {
|
|
1348
1473
|
emit(el, "kill")
|
|
@@ -1350,27 +1475,19 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1350
1475
|
}
|
|
1351
1476
|
elRm(el)
|
|
1352
1477
|
if (el.nodeType < 2) {
|
|
1353
|
-
el.$s = UNDEF
|
|
1354
1478
|
elKill(el._r) // Replacement element like comment from if binding
|
|
1355
1479
|
elEmpty(el)
|
|
1356
|
-
|
|
1357
|
-
el.valObject = UNDEF
|
|
1358
|
-
}
|
|
1480
|
+
el.$s = el.valObject = UNDEF
|
|
1359
1481
|
} else {
|
|
1360
1482
|
if (el.kill) el.kill()
|
|
1361
1483
|
}
|
|
1362
1484
|
}
|
|
1363
1485
|
}
|
|
1364
1486
|
function elScope(el, parent, opts) {
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
function closestScope(node) {
|
|
1372
|
-
for (; (node = node.parentNode); ) {
|
|
1373
|
-
if (node.$s) return node.$s
|
|
1487
|
+
if (el.$s) return el.$s
|
|
1488
|
+
if (parent) return (el.$s = assign(create(parent = elScope(parent)), opts, { $up: parent }))
|
|
1489
|
+
for (; (el = el.parentNode); ) {
|
|
1490
|
+
if (el.$s) return el.$s
|
|
1374
1491
|
}
|
|
1375
1492
|
return globalScope
|
|
1376
1493
|
}
|
|
@@ -1382,7 +1499,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1382
1499
|
}
|
|
1383
1500
|
|
|
1384
1501
|
var el, next
|
|
1385
|
-
, scope = node.$s || $s ||
|
|
1502
|
+
, scope = node.$s || $s || elScope(node)
|
|
1386
1503
|
|
|
1387
1504
|
/*** ie9 ***/
|
|
1388
1505
|
if (ie678 && node.tagName === "SELECT") {
|
|
@@ -1391,6 +1508,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1391
1508
|
/**/
|
|
1392
1509
|
|
|
1393
1510
|
if (hydrate(node, "_b", scope)) return
|
|
1511
|
+
scope = node.$s || scope
|
|
1394
1512
|
for (el = node.firstChild; el; el = next) {
|
|
1395
1513
|
next = el.nextSibling
|
|
1396
1514
|
render(el, scope)
|
|
@@ -1488,7 +1606,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1488
1606
|
/**/
|
|
1489
1607
|
|
|
1490
1608
|
/*** touch ***/
|
|
1491
|
-
var e0, touchDist,
|
|
1609
|
+
var e0, touchAngle, touchDist, touchEl, touchMode, touchTick
|
|
1492
1610
|
, START = "start"
|
|
1493
1611
|
, END = "end"
|
|
1494
1612
|
, touches = []
|
|
@@ -1500,6 +1618,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1500
1618
|
fixEv[name] = fixEv[name + START] = fixEv[name + END] = ""
|
|
1501
1619
|
fixFn[name] = fixFn[name + START] = fixFn[name + END] = touchInit
|
|
1502
1620
|
})
|
|
1621
|
+
function haveEv(evs, name, set) {
|
|
1622
|
+
return set && (evs[name] || evs[name + START] || evs[name + END]) && name
|
|
1623
|
+
}
|
|
1503
1624
|
function touchInit(el) {
|
|
1504
1625
|
if (!el._ti) {
|
|
1505
1626
|
addEvent(el, "pointerdown", touchDown)
|
|
@@ -1524,8 +1645,11 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1524
1645
|
if (len === 1) {
|
|
1525
1646
|
if (e) {
|
|
1526
1647
|
e0 = e
|
|
1527
|
-
|
|
1528
|
-
|
|
1648
|
+
e.x0 = e.clientX
|
|
1649
|
+
e.y0 = e.clientY
|
|
1650
|
+
touchEl = el
|
|
1651
|
+
touchPos("x", "left", "offsetWidth")
|
|
1652
|
+
touchPos("y", "top", "offsetHeight")
|
|
1529
1653
|
if (e.button === 2 || matches(el, "INPUT,TEXTAREA,SELECT,.no-drag")) return
|
|
1530
1654
|
touchTick = setTimeout(moveOne, LiteJS.holdDelay || 800, e, 1)
|
|
1531
1655
|
}
|
|
@@ -1536,9 +1660,11 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1536
1660
|
moveTwo(e)
|
|
1537
1661
|
}
|
|
1538
1662
|
;(len === 1 ? addEvent : rmEvent)(document, MOVE, moveOne)
|
|
1663
|
+
// TODO:2026-03-24:lauri:touches are shared, touchDown is per-element closures, move out
|
|
1664
|
+
;(len === 1 ? addEvent : rmEvent)(document, "pointerup", touchUp)
|
|
1539
1665
|
;(len === 2 ? addEvent : rmEvent)(document, MOVE, moveTwo)
|
|
1540
|
-
function touchPos(name, offset) {
|
|
1541
|
-
var val = getAttr(el,
|
|
1666
|
+
function touchPos(coord, name, offset) {
|
|
1667
|
+
var val = getAttr(el, coord) || getComputedStyle(el)[name]
|
|
1542
1668
|
, num = parseInt(val, 10) || 0
|
|
1543
1669
|
e0[name] = val && val.indexOf("%") > -1 ? num * el.parentNode[offset] / 100 : num
|
|
1544
1670
|
}
|
|
@@ -1568,26 +1694,22 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1568
1694
|
if (touches[0].buttons && touches[0].buttons !== (e.buttons || [0, 1, 4, 2][e.which || 0])) {
|
|
1569
1695
|
return touchUp(e)
|
|
1570
1696
|
}
|
|
1571
|
-
e.
|
|
1572
|
-
e.
|
|
1573
|
-
e.
|
|
1574
|
-
e.
|
|
1575
|
-
e.
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
haveEv("pan", e.dx > 10 || e.dx < -10 || e.dy > 10 || e.dy < -10) ||
|
|
1581
|
-
haveEv("hold", fromTimer)
|
|
1582
|
-
)
|
|
1583
|
-
if (!touchMode) return
|
|
1697
|
+
e.el = touchEl
|
|
1698
|
+
e.x0 = e0.x0
|
|
1699
|
+
e.y0 = e0.y0
|
|
1700
|
+
var dx = e.dx = e.clientX - e.x0
|
|
1701
|
+
, dy = e.dy = e.clientY - e.y0
|
|
1702
|
+
if (!touchMode && (touchMode = touchEl._e) && (touchMode = (
|
|
1703
|
+
haveEv(touchMode, "pan", dx > 10 || dx < -10 || dy > 10 || dy < -10) ||
|
|
1704
|
+
haveEv(touchMode, "hold", fromTimer)
|
|
1705
|
+
))) {
|
|
1584
1706
|
clearTimeout(touchTick)
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
emit(el, touchMode, e, el)
|
|
1588
|
-
function haveEv(name, set) {
|
|
1589
|
-
return set && (evs[name] || evs[name + START] || evs[name + END]) && name
|
|
1707
|
+
e0.mode = touchMode
|
|
1708
|
+
emit(el, touchMode + START, e0, el)
|
|
1590
1709
|
}
|
|
1710
|
+
e.ex = dx + e0.left
|
|
1711
|
+
e.ey = dy + e0.top
|
|
1712
|
+
if (touchMode) emit(el, touchMode, e, el)
|
|
1591
1713
|
}
|
|
1592
1714
|
function moveTwo(e) {
|
|
1593
1715
|
touches[ touches[0].pointerId == e.pointerId ? 0 : 1] = e
|
|
@@ -1653,13 +1775,14 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1653
1775
|
function acceptMany(fn, prepareVal) {
|
|
1654
1776
|
return function f(el, name, val, selector, delay, data) {
|
|
1655
1777
|
if (el && name) {
|
|
1656
|
-
if (
|
|
1778
|
+
if (!isStr(selector)) {
|
|
1657
1779
|
data = delay
|
|
1658
1780
|
delay = selector
|
|
1659
|
-
selector =
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1781
|
+
selector = ""
|
|
1782
|
+
}
|
|
1783
|
+
if (!isNum(delay)) {
|
|
1784
|
+
data = delay
|
|
1785
|
+
delay = 0
|
|
1663
1786
|
}
|
|
1664
1787
|
if (delay > 0) {
|
|
1665
1788
|
setTimeout(f, delay, el, name, val, selector, 0, data)
|
|
@@ -1682,11 +1805,16 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1682
1805
|
}
|
|
1683
1806
|
} : val
|
|
1684
1807
|
, els = !prepareVal && selector ? findAll(el, selector) : isArr(el) ? el : [ el ]
|
|
1685
|
-
for (; (node = els[i++]); ) {
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
if (
|
|
1808
|
+
for (; (node = els[i++]); ) for (delay = 0; delay < len; delay++) {
|
|
1809
|
+
if ((result = arr[delay])) {
|
|
1810
|
+
result = fn(node, result, isArr(value) ? value[delay] : value && typeof value === "object" && !value.nodeType ? value[result] : value, data)
|
|
1811
|
+
if (!prepareVal) {
|
|
1812
|
+
if (fn === cls || data < -1) result = !val || ""
|
|
1813
|
+
if (data < 0) {
|
|
1814
|
+
if (canTransit) onceEvent(node, canTransit, bind(f, node, node, name, result))
|
|
1815
|
+
else data = 1
|
|
1816
|
+
}
|
|
1817
|
+
if (data > 0) f(node, name, result, "", data)
|
|
1690
1818
|
}
|
|
1691
1819
|
}
|
|
1692
1820
|
}
|
|
@@ -1768,6 +1896,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1768
1896
|
}
|
|
1769
1897
|
}
|
|
1770
1898
|
}
|
|
1899
|
+
function rect(el) {
|
|
1900
|
+
return el && el.nodeType ? el.getBoundingClientRect() : el
|
|
1901
|
+
}
|
|
1771
1902
|
function scrollPos(page, key) {
|
|
1772
1903
|
return window[page] || html[key] || body[key] || 0
|
|
1773
1904
|
}
|