@litejs/ui 26.4.0 → 26.10.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/el/dialog.ui +1 -1
- package/el/menu.ui +5 -4
- package/el/slider.ui +1 -1
- package/package.json +2 -2
- package/shim.js +27 -17
- package/ui.js +141 -116
package/el/dialog.ui
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
tab: setFocus,
|
|
72
72
|
}
|
|
73
73
|
, body = doc.body
|
|
74
|
-
, scrollEl = doc.scrollingElement
|
|
74
|
+
, scrollEl = doc.scrollingElement
|
|
75
75
|
, vibrate = scope.vibrate && navigator.vibrate
|
|
76
76
|
, sound = scope.sound && window.Audio && new Audio(scope.sound)
|
|
77
77
|
scope.title = title
|
package/el/menu.ui
CHANGED
|
@@ -93,9 +93,10 @@
|
|
|
93
93
|
, html = document.documentElement
|
|
94
94
|
El.near = near
|
|
95
95
|
function near(source, target, x, y, margin) {
|
|
96
|
-
var rect =
|
|
97
|
-
,
|
|
98
|
-
,
|
|
96
|
+
var rect = El.rect(target)
|
|
97
|
+
, scroll = El.scroll()
|
|
98
|
+
, top = rect.top + scroll.y
|
|
99
|
+
, left = rect.left + scroll.x
|
|
99
100
|
// svg elements dont have offsetWidth, IE8 does not have rect.width
|
|
100
101
|
, width = rect.width || target.offsetWidth || 0
|
|
101
102
|
, height = rect.height || target.offsetHeight || 0
|
|
@@ -122,7 +123,7 @@
|
|
|
122
123
|
top += height + margin
|
|
123
124
|
y = " -50%"
|
|
124
125
|
setTimeout(function() {
|
|
125
|
-
var overflow = top + source.offsetHeight -
|
|
126
|
+
var overflow = top + source.offsetHeight - scroll.y - html.offsetHeight
|
|
126
127
|
if (overflow > 0) scrollBy({ top: overflow, left: 0, behavior: "smooth" })
|
|
127
128
|
}, 400)
|
|
128
129
|
} else {
|
package/el/slider.ui
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litejs/ui",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.10.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.8.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/shim.js
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
/*** debug ***/
|
|
36
36
|
, IS_NODE = !window.document
|
|
37
37
|
, document = patch("document", {body:{},documentElement:{}})
|
|
38
|
+
, history = patch("history", {})
|
|
38
39
|
, location = patch("location", {href:""})
|
|
39
40
|
, navigator = patch("navigator", {})
|
|
40
41
|
/*/
|
|
@@ -42,7 +43,6 @@
|
|
|
42
43
|
, IS_NODE = false
|
|
43
44
|
/**/
|
|
44
45
|
, html = document.documentElement
|
|
45
|
-
, body = document.body
|
|
46
46
|
// JScript engine in IE<9 does not recognize vertical tabulation character
|
|
47
47
|
// The documentMode is an IE only property, supported from IE8
|
|
48
48
|
, a = document.documentMode | 0
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
/* node:coverage ignore next 19 */
|
|
53
53
|
, ie678 = !+"\v1" && a < 9 // jshint ignore:line
|
|
54
54
|
, ie6789 = ie678 || a == 9
|
|
55
|
-
, ie67 = ie678 && a < 8
|
|
56
55
|
, EV = "Event"
|
|
57
56
|
, Event = patch(
|
|
58
57
|
EV,
|
|
@@ -103,8 +102,8 @@
|
|
|
103
102
|
c: "touchcancel"
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
,
|
|
107
|
-
,
|
|
105
|
+
, lastHref
|
|
106
|
+
, onpopstate = "onpopstate"
|
|
108
107
|
|
|
109
108
|
|
|
110
109
|
// Patch parameters support for setTimeout callback
|
|
@@ -120,13 +119,13 @@
|
|
|
120
119
|
// window.msRequestAnimationFrame || // IE 10 PP2+
|
|
121
120
|
patch("cancel" + a, "clearTimeout(a)")
|
|
122
121
|
|
|
123
|
-
|
|
124
122
|
/* node:coverage ignore next 8 */
|
|
125
|
-
if (!IS_NODE && !(
|
|
126
|
-
patch(
|
|
123
|
+
if (!IS_NODE && !(onpopstate in window)) {
|
|
124
|
+
patch(onpopstate, NULL)
|
|
127
125
|
setInterval(function() {
|
|
128
|
-
if (
|
|
129
|
-
window[
|
|
126
|
+
if (isFn(window[onpopstate]) && lastHref !== (lastHref = "" + location)) {
|
|
127
|
+
window[onpopstate]()
|
|
128
|
+
scroll(0, 0)
|
|
130
129
|
}
|
|
131
130
|
}, 60)
|
|
132
131
|
}
|
|
@@ -335,8 +334,16 @@
|
|
|
335
334
|
// Chrome7, FF4, IE9, Opera 11.60, Safari 5.1.4
|
|
336
335
|
patch("bind", "b=S.call(A,1);c=function(){return t.apply(this instanceof c?this:a,b.concat(S.call(arguments)))};if(t[P])c[P]=t[P];return c")
|
|
337
336
|
|
|
337
|
+
O = history
|
|
338
|
+
a = "replace"
|
|
339
|
+
b = "State"
|
|
340
|
+
c = "location[X](c)"
|
|
341
|
+
patch(a + b, c, 0, a)
|
|
342
|
+
a = "assign"
|
|
343
|
+
patch("push" + b, c, 0, a)
|
|
344
|
+
|
|
338
345
|
O = Object
|
|
339
|
-
patch(
|
|
346
|
+
patch(a, "for(var k,i=1,l=A.length;i<l;)if(t=A[i++])for(k in t)if(o.call(t,k))a[k]=t[k];return a")
|
|
340
347
|
patch("create", "X[P]=a||Y;return new X", 0, nop, {
|
|
341
348
|
// oKeys is undefined at this point
|
|
342
349
|
constructor: oKeys,
|
|
@@ -424,6 +431,9 @@
|
|
|
424
431
|
return false
|
|
425
432
|
})
|
|
426
433
|
|
|
434
|
+
O = document
|
|
435
|
+
var scrollEl = patch("scrollingElement", (document.compatMode === "CSS1Compat" ? html : document.body))
|
|
436
|
+
|
|
427
437
|
// The HTML5 document.head DOM tree accessor
|
|
428
438
|
// patch("head", document.getElementsByTagName("head")[0])
|
|
429
439
|
// HTMLElement (IE9) -> Element (IE8)
|
|
@@ -433,12 +443,12 @@
|
|
|
433
443
|
, selectorLastRe = /([\s>+~]*)(?:("|')(?:\\.|[^\\])*?\2|\((?:[^()]|\([^()]+\))+?\)|~=|[^'"()\s>+~])+$/
|
|
434
444
|
, selectorSplitRe = /\s*,\s*(?=(?:[^'"()]|"(?:\\.|[^\\"])*?"|'(?:\\.|[^\\'])*?'|\((?:[^()]|\([^()]+\))+?\))+$)/
|
|
435
445
|
, selectorMap = {
|
|
436
|
-
|
|
437
|
-
|
|
446
|
+
empty: "!_.lastChild",
|
|
447
|
+
enabled: "!m(_,':disabled')",
|
|
438
448
|
"first-child": "(a=_.parentNode)&&a.firstChild==_",
|
|
439
|
-
|
|
449
|
+
lang: "m(c(_,'[lang]'),'[lang|='+v+']')",
|
|
440
450
|
"last-child": "(a=_.parentNode)&&a.lastChild==_",
|
|
441
|
-
|
|
451
|
+
link: "m(_,'a[href]')",
|
|
442
452
|
"only-child": "(a=_.parentNode)&&a.firstChild==a.lastChild",
|
|
443
453
|
".": "~_.className.split(/\\s+/).indexOf(a)",
|
|
444
454
|
"#": "_.id==a",
|
|
@@ -455,11 +465,11 @@
|
|
|
455
465
|
, matches = patch("matches", "return!!X(a)(t)", 0, selectorFn)
|
|
456
466
|
|
|
457
467
|
/* node:coverage ignore next 13 */
|
|
468
|
+
b = "removeEventListener"
|
|
458
469
|
try {
|
|
459
470
|
O[a = "addEventListener"]("t", NULL, Object.defineProperties({}, {
|
|
460
471
|
capture: { get: function() { canCapture = 1 } }
|
|
461
472
|
}))
|
|
462
|
-
b = "removeEventListener"
|
|
463
473
|
c = "O.call(t,a,b,X(c)?!!c.capture:!!c)"
|
|
464
474
|
if (!canCapture) {
|
|
465
475
|
patch("c:" + a, c, 1, isObj)
|
|
@@ -474,8 +484,8 @@
|
|
|
474
484
|
return function() {
|
|
475
485
|
var e = new Event(ev)
|
|
476
486
|
if (e.clientX !== UNDEF) {
|
|
477
|
-
e.pageX = e.clientX + (window.pageXOffset ||
|
|
478
|
-
e.pageY = e.clientY + (window.pageYOffset ||
|
|
487
|
+
e.pageX = e.clientX + (window.pageXOffset || scrollEl.scrollLeft)
|
|
488
|
+
e.pageY = e.clientY + (window.pageYOffset || scrollEl.scrollTop)
|
|
479
489
|
}
|
|
480
490
|
fn.call(el, e)
|
|
481
491
|
}
|
package/ui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/* litejs.com/MIT-LICENSE.txt */
|
|
3
3
|
|
|
4
|
-
/* global
|
|
4
|
+
/* global xhr */
|
|
5
5
|
|
|
6
6
|
// Conditional compilation via toggle comments (processed by build tool):
|
|
7
7
|
// /*** name ***/ code /**/ - `code` active in source; build can strip it
|
|
@@ -15,7 +15,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
15
15
|
window.El = El
|
|
16
16
|
asEmitter(window.LiteJS = LiteJS)
|
|
17
17
|
|
|
18
|
-
var UNDEF, parser,
|
|
18
|
+
var UNDEF, parser, styleNode
|
|
19
19
|
, NUL = null
|
|
20
20
|
// THIS will be `undefined` in strict mode and `window` in sloppy mode
|
|
21
21
|
, THIS = this
|
|
@@ -57,8 +57,6 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
57
57
|
|
|
58
58
|
, elSeq = 0
|
|
59
59
|
, elCache = {}
|
|
60
|
-
// Parses ";name! args" binding expressions from _b attribute
|
|
61
|
-
, renderRe = /[;\s]*([-.\w$]+)(?:(!?)[ :]*((?:(["'\/])(?:\\.|[^\\])*?\4|[^;])*))?/g
|
|
62
60
|
// Parses CSS selectors: .class #id [attr=val] :pseudo
|
|
63
61
|
, selectorRe = /([.#:[])([-\w]+)(?:([~^$*|]?)=(("|')(?:\\.|[^\\])*?\5|[-\w]+))?]?/g
|
|
64
62
|
, fnCache = {}
|
|
@@ -72,6 +70,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
72
70
|
return current
|
|
73
71
|
})
|
|
74
72
|
, bindingsOn = acceptMany(addEvent, 1)
|
|
73
|
+
, bindingsOff = acceptMany(rmEvent)
|
|
75
74
|
, bindings = {
|
|
76
75
|
cls: bindingsCls,
|
|
77
76
|
css: bindingsCss,
|
|
@@ -86,7 +85,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
86
85
|
, i = 0
|
|
87
86
|
, type = el.type
|
|
88
87
|
, opts = el.options
|
|
89
|
-
,
|
|
88
|
+
, isRadio = type === "radio"
|
|
89
|
+
, checkbox = type === "checkbox" || isRadio
|
|
90
90
|
|
|
91
91
|
if (el.tagName === "FORM") {
|
|
92
92
|
// Disabled controls do not receive focus,
|
|
@@ -119,7 +119,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
119
119
|
} else if (el.val) {
|
|
120
120
|
el.val(val)
|
|
121
121
|
} else if (checkbox) {
|
|
122
|
-
el.checked = !!val
|
|
122
|
+
el.checked = isRadio ? el.value == val : !!val
|
|
123
123
|
} else {
|
|
124
124
|
el.value = val
|
|
125
125
|
}
|
|
@@ -140,8 +140,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
140
140
|
el = value > -1 && opts[value] || el
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
return checkbox && !el.checked ?
|
|
144
|
-
(type === "radio" ? UNDEF : NUL) :
|
|
143
|
+
return checkbox && !el.checked ? (isRadio ? UNDEF : NUL) :
|
|
145
144
|
el.valObject !== UNDEF ? el.valObject : el.value
|
|
146
145
|
|
|
147
146
|
function replacer(_, _key, offset) {
|
|
@@ -182,6 +181,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
182
181
|
, fixEv = Event.fixEv || (Event.fixEv = {})
|
|
183
182
|
, fixFn = Event.fixFn || (Event.fixFn = {})
|
|
184
183
|
|
|
184
|
+
, base = find(html, "base")
|
|
185
|
+
, pushBase = (base = base && base.href) && (LiteJS.push = replace(/.+?:\/\/[^/]+|[^\/]*$/g, "", base))
|
|
186
|
+
|
|
185
187
|
/*** markup ***/
|
|
186
188
|
, blockRe = /^(?:(=+|>| -| \d+\.) ([\s\S]+))/
|
|
187
189
|
, tags = {
|
|
@@ -358,10 +360,10 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
358
360
|
on(el, ev, fn2, el, fn)
|
|
359
361
|
}
|
|
360
362
|
function onceEvent(el, ev, fn, opts) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
+
if (ev) bindingsOn(el, ev, function remove() {
|
|
364
|
+
bindingsOff(el, ev, remove, 0, 0, opts)
|
|
363
365
|
fn.apply(el, arguments)
|
|
364
|
-
})
|
|
366
|
+
}, 0, 0, opts)
|
|
365
367
|
}
|
|
366
368
|
function rmEvent(el, ev, fn, opts) {
|
|
367
369
|
var evs = el._e && el._e[ev]
|
|
@@ -428,6 +430,10 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
428
430
|
|
|
429
431
|
asEmitter(View)
|
|
430
432
|
asEmitter(View.prototype = {
|
|
433
|
+
show: function(params) {
|
|
434
|
+
lastView = this
|
|
435
|
+
bubbleUp(lastParams = params || {})
|
|
436
|
+
},
|
|
431
437
|
wait: function() {
|
|
432
438
|
var params = lastParams
|
|
433
439
|
params._p = 1 + (params._p | 0) // pending
|
|
@@ -542,8 +548,6 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
542
548
|
viewEmit(view, "pong", params, View)
|
|
543
549
|
}
|
|
544
550
|
viewEmit(lastView, "show", params)
|
|
545
|
-
close = history.state || 0
|
|
546
|
-
scrollTo(close.x|0, close.y|0)
|
|
547
551
|
blur()
|
|
548
552
|
}
|
|
549
553
|
function viewClose(view, open) {
|
|
@@ -607,7 +611,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
607
611
|
console.log("Outside view defined elements are rendered immediately into UI")
|
|
608
612
|
/**/
|
|
609
613
|
}
|
|
610
|
-
if (parent.
|
|
614
|
+
if (parent.I) {
|
|
611
615
|
histStart(viewShow)
|
|
612
616
|
}
|
|
613
617
|
|
|
@@ -615,7 +619,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
615
619
|
if (offset && all === indent) return
|
|
616
620
|
|
|
617
621
|
for (q = indent.length; q <= stack[0]; ) {
|
|
618
|
-
if ((offset = parent.
|
|
622
|
+
if ((offset = parent.P)) {
|
|
619
623
|
if (offset.c && !offset.e.childNodes[0]) break
|
|
620
624
|
offset.d(offset)
|
|
621
625
|
}
|
|
@@ -625,8 +629,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
625
629
|
if (op === "@") {
|
|
626
630
|
text = replace(/([\w,.]+)[!:]?/, /^\w+!/.test(text) ? "one!'$1'," : "on!'$1',", text)
|
|
627
631
|
}
|
|
628
|
-
if (parent.
|
|
629
|
-
parent.
|
|
632
|
+
if (parent.R) {
|
|
633
|
+
parent.T += "\n" + all
|
|
630
634
|
} else if (plugin || mapStart && (sel = "map")) {
|
|
631
635
|
if (plugins[sel]) {
|
|
632
636
|
parentStack.push(parent)
|
|
@@ -677,7 +681,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
677
681
|
// .n name .x parent view name .u parent DOM element
|
|
678
682
|
// .e container el .d done callback .c saved elCache (for %el/%view)
|
|
679
683
|
// When proto is a function, plugin accumulates raw text:
|
|
680
|
-
// .
|
|
684
|
+
// .R raw handler .T accumulated text .o original op+text .s separator
|
|
681
685
|
function addPlugin(name, proto, expectContent) {
|
|
682
686
|
plugins[name] = Plugin
|
|
683
687
|
function Plugin(parent, op, sep) {
|
|
@@ -686,9 +690,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
686
690
|
plugin.n = arr[0] // name
|
|
687
691
|
plugin.x = arr[1] // View parent
|
|
688
692
|
plugin.u = parent
|
|
689
|
-
if (plugin.
|
|
690
|
-
plugin.
|
|
691
|
-
plugin.
|
|
693
|
+
if (plugin.R) {
|
|
694
|
+
plugin.T = ""
|
|
695
|
+
plugin.P = plugin.e = plugin
|
|
692
696
|
plugin.o = op
|
|
693
697
|
plugin.s = sep
|
|
694
698
|
} else {
|
|
@@ -696,10 +700,10 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
696
700
|
elCache = create(plugin.c = elCache)
|
|
697
701
|
}
|
|
698
702
|
plugin.e = El(name === "svg" ? name : "div")
|
|
699
|
-
plugin.e.
|
|
703
|
+
plugin.e.P = plugin
|
|
700
704
|
}
|
|
701
705
|
}
|
|
702
|
-
assign(Plugin.prototype, isFn(proto) ? { d: Function("p", "p.
|
|
706
|
+
assign(Plugin.prototype, isFn(proto) ? { d: Function("p", "p.R(p.o+p.T)"), R: proto } : proto)
|
|
703
707
|
}
|
|
704
708
|
function usePluginContent(plugin) {
|
|
705
709
|
var el = plugin.e
|
|
@@ -714,12 +718,12 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
714
718
|
child._s = el._s
|
|
715
719
|
}
|
|
716
720
|
if (plugin.c) elCache = plugin.c
|
|
717
|
-
el.
|
|
721
|
+
el.P = plugin.e = plugin.u = UNDEF
|
|
718
722
|
return child
|
|
719
723
|
}
|
|
720
724
|
|
|
721
725
|
addPlugin("ui", {
|
|
722
|
-
d: Function("p", "p.u.
|
|
726
|
+
d: Function("p", "p.u.I=1")
|
|
723
727
|
})
|
|
724
728
|
plugins.start = plugins.ui
|
|
725
729
|
addPlugin("slot", {
|
|
@@ -738,7 +742,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
738
742
|
addPlugin("def", viewDef)
|
|
739
743
|
addPlugin("js", viewEval)
|
|
740
744
|
addPlugin("each", function() {
|
|
741
|
-
var txt = this.
|
|
745
|
+
var txt = this.T
|
|
742
746
|
each(this.o, function(param) {
|
|
743
747
|
viewParse(replace(/{key}/g, param, txt))
|
|
744
748
|
})
|
|
@@ -762,9 +766,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
762
766
|
var expr = getAttr(plugin.e, "_b")
|
|
763
767
|
, view = View(plugin.n, usePluginContent(plugin), plugin.x)
|
|
764
768
|
if (expr) {
|
|
765
|
-
viewEval(
|
|
769
|
+
viewEval(renderEach(expr, function(_, name, op, args) {
|
|
766
770
|
return "($s." + name + (isFn(view[name]) ? "(" + (args || "") + ")" : "=" + args) + "),"
|
|
767
|
-
}
|
|
771
|
+
}) + "1", view)
|
|
768
772
|
}
|
|
769
773
|
}
|
|
770
774
|
}, 1)
|
|
@@ -989,11 +993,11 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
989
993
|
return format(iGet(translations, str, str || ""), data, getExt)
|
|
990
994
|
}
|
|
991
995
|
function getExt(obj, str) {
|
|
992
|
-
var fn = cache[str] || (cache[str] = (replace(
|
|
993
|
-
fn = (_ === name) ? name : "$el." + name + "(" + fn + (args ? "," + args : "") + ")"
|
|
994
|
-
}, replace(/;\s*([#*?@~])(.*)/, function(_, op, arg) {
|
|
996
|
+
var fn = cache[str] || (cache[str] = (renderEach(replace(/;\s*([#*?@~])(.*)/, function(_, op, arg) {
|
|
995
997
|
return ";" + iAlias[op] + " " + quote(arg)
|
|
996
|
-
}, str)
|
|
998
|
+
}, str), function(_, name, op, args) {
|
|
999
|
+
fn = (_ === name) ? name : "$el." + name + "(" + fn + (args ? "," + args : "") + ")"
|
|
1000
|
+
}), fn === str ? str : makeFn(fn, fn)))
|
|
997
1001
|
return str == "$" ? obj : isStr(fn) ? iGet(obj, str, "") : isFn(fn) ? fn(iExt, obj, translations) : ""
|
|
998
1002
|
}
|
|
999
1003
|
})
|
|
@@ -1005,22 +1009,20 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1005
1009
|
}
|
|
1006
1010
|
})
|
|
1007
1011
|
function format(str, data, getter) {
|
|
1008
|
-
for (var
|
|
1009
|
-
|
|
1010
|
-
if (
|
|
1011
|
-
inQuote = (!inExpr ||
|
|
1012
|
+
for (var ch, inQuote, inExpr, depth = 0, start = 0, pos = 0, len = str.length, result = ""; pos < len; ) {
|
|
1013
|
+
ch = str.charCodeAt(pos++)
|
|
1014
|
+
if (ch == 39 || ch == 34) { // '"
|
|
1015
|
+
inQuote = (!inExpr || ch === inQuote) ? 0 : ch
|
|
1012
1016
|
} else if (inQuote) {
|
|
1013
|
-
if (
|
|
1014
|
-
} else if (
|
|
1017
|
+
if (ch == 92) pos++
|
|
1018
|
+
} else if (ch == 123 && depth++ < 1) {
|
|
1015
1019
|
inExpr = pos
|
|
1016
|
-
} else if (
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
pos = inExpr + char.length - 1
|
|
1020
|
-
len = str.length
|
|
1020
|
+
} else if (ch == 125 && inExpr > start && --depth < 1) {
|
|
1021
|
+
result += str.slice(start, inExpr - 1) + getter(data, str.slice(inExpr, pos - 1), "")
|
|
1022
|
+
start = pos
|
|
1021
1023
|
}
|
|
1022
1024
|
}
|
|
1023
|
-
return str
|
|
1025
|
+
return result + str.slice(start)
|
|
1024
1026
|
}
|
|
1025
1027
|
function iGet(obj, path, fallback, tmp) {
|
|
1026
1028
|
return isStr(path) ? (
|
|
@@ -1043,53 +1045,41 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1043
1045
|
return View
|
|
1044
1046
|
}
|
|
1045
1047
|
|
|
1046
|
-
function setUrl(url, rep) {
|
|
1047
|
-
/*** pushState ***/
|
|
1048
|
-
if (pushBase) {
|
|
1049
|
-
history[rep ? "replaceState" : (history.replaceState({x: pageXOffset, y: pageYOffset}, NUL, location.href), "pushState")](NUL, NUL, pushBase + url)
|
|
1050
|
-
} else
|
|
1051
|
-
/**/
|
|
1052
|
-
location[rep ? "replace" : "assign"]("#" + url)
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
LiteJS.go = setUrl
|
|
1056
1048
|
LiteJS.start = histStart
|
|
1057
1049
|
function histStart(cb) {
|
|
1058
|
-
|
|
1059
|
-
// Chrome5, Firefox4, IE10, Safari5, Opera11.50
|
|
1050
|
+
LiteJS.go = setUrl
|
|
1060
1051
|
var histLast
|
|
1061
|
-
,
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
// http://html5.org/tools/web-apps-tracker?from=5345&to=5346.
|
|
1077
|
-
window.onpopstate = checkUrl
|
|
1078
|
-
} else
|
|
1079
|
-
/**/
|
|
1080
|
-
window.onhashchange = checkUrl
|
|
1081
|
-
readTemplates(checkUrl)
|
|
1052
|
+
, hashFallback = getUrl()
|
|
1053
|
+
if (pushBase) {
|
|
1054
|
+
bindingsOn(body, "click", function(e, el) {
|
|
1055
|
+
if (
|
|
1056
|
+
!(e.defaultPrevented || e.button || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || getAttr(el, "target") || el.href.indexOf(base)) &&
|
|
1057
|
+
getAttr(el, "download") == NUL
|
|
1058
|
+
) {
|
|
1059
|
+
eventStop(e)
|
|
1060
|
+
setUrl(el.href.slice(base.length))
|
|
1061
|
+
}
|
|
1062
|
+
}, "a[href]")
|
|
1063
|
+
}
|
|
1064
|
+
// Chrome and Safari emit a popstate event on page load, Firefox doesn't.
|
|
1065
|
+
// Firing popstate after onload is as designed.
|
|
1066
|
+
readTemplates(window.onpopstate = checkUrl)
|
|
1082
1067
|
function checkUrl() {
|
|
1083
|
-
if (cb && histLast != (histLast = getUrl()))
|
|
1068
|
+
if (cb && histLast != (histLast = getUrl() || hashFallback)) {
|
|
1069
|
+
hashFallback = ""
|
|
1070
|
+
cb(histLast)
|
|
1071
|
+
}
|
|
1084
1072
|
}
|
|
1085
1073
|
function getUrl() {
|
|
1086
1074
|
return replace(/^[#\/\!]+|[\s\/]+$/g, "",
|
|
1087
|
-
|
|
1088
|
-
pushBase ? location.pathname.slice(pushBase.length) :
|
|
1089
|
-
/**/
|
|
1075
|
+
pushBase && hashFallback !== UNDEF ? location.pathname.slice(pushBase.length) :
|
|
1090
1076
|
// NOTE: in Firefox location.hash is decoded; in Safari location.pathname is decoded
|
|
1091
1077
|
location.href.split("#")[1] || "")
|
|
1092
1078
|
}
|
|
1079
|
+
function setUrl(url, rep) {
|
|
1080
|
+
history[rep ? "replaceState" : "pushState"](NUL, NUL, (pushBase || "#") + url)
|
|
1081
|
+
checkUrl()
|
|
1082
|
+
}
|
|
1093
1083
|
}
|
|
1094
1084
|
|
|
1095
1085
|
function Comm(name, render) {
|
|
@@ -1139,7 +1129,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1139
1129
|
flip: elFlip,
|
|
1140
1130
|
kill: elKill,
|
|
1141
1131
|
morph: elMorph,
|
|
1142
|
-
off:
|
|
1132
|
+
off: bindingsOff,
|
|
1143
1133
|
render: render,
|
|
1144
1134
|
rect: rect,
|
|
1145
1135
|
rm: elRm
|
|
@@ -1180,8 +1170,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1180
1170
|
append(comm.parentNode, sub, (pos++ ? nodes[pos - 2] : comm).nextSibling)
|
|
1181
1171
|
elScope(sub, comm)
|
|
1182
1172
|
}
|
|
1183
|
-
for (; i--; ) {
|
|
1184
|
-
sub = nodes[i].$s
|
|
1173
|
+
for (; i--; ) if ((sub = nodes[i].$s)) {
|
|
1185
1174
|
sub[name] = list[sub.$k = keys[sub.$i = i]]
|
|
1186
1175
|
sub.$len = pos
|
|
1187
1176
|
render(nodes[i])
|
|
@@ -1227,7 +1216,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1227
1216
|
})
|
|
1228
1217
|
},
|
|
1229
1218
|
view: function(el, url) {
|
|
1230
|
-
|
|
1219
|
+
el.href = (pushBase || "#") + expand(url || "")
|
|
1231
1220
|
}
|
|
1232
1221
|
}),
|
|
1233
1222
|
$d: globalScope,
|
|
@@ -1243,8 +1232,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1243
1232
|
rate: rate,
|
|
1244
1233
|
replace: elReplace,
|
|
1245
1234
|
scope: elScope,
|
|
1246
|
-
|
|
1247
|
-
scrollTop: bind(scrollPos, NUL, "pageYOffset", "scrollTop"),
|
|
1235
|
+
scroll: elScroll,
|
|
1248
1236
|
step: step,
|
|
1249
1237
|
stop: eventStop
|
|
1250
1238
|
})
|
|
@@ -1460,6 +1448,12 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1460
1448
|
bindingsCss(to, "transform", "")
|
|
1461
1449
|
}
|
|
1462
1450
|
}
|
|
1451
|
+
function transit(fn, el, a, b) {
|
|
1452
|
+
if (canTransit && /[1-9]/.test(getComputedStyle(el).transitionDuration)) {
|
|
1453
|
+
onceEvent(el, canTransit, bind(fn, el, el, a, b))
|
|
1454
|
+
return 1
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1463
1457
|
function elKill(el, tr, delay) {
|
|
1464
1458
|
if (el) {
|
|
1465
1459
|
if (delay > 0) return setTimeout(elKill, delay, el, tr)
|
|
@@ -1467,7 +1461,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1467
1461
|
if (isStr(tr)) cls(el, tr)
|
|
1468
1462
|
if (isObj(tr)) bindingsCss(el, tr)
|
|
1469
1463
|
// transitionend fires for each property transitioned
|
|
1470
|
-
|
|
1464
|
+
if (transit(elKill, el)) return
|
|
1471
1465
|
}
|
|
1472
1466
|
if (el._e) {
|
|
1473
1467
|
emit(el, "kill")
|
|
@@ -1491,6 +1485,13 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1491
1485
|
}
|
|
1492
1486
|
return globalScope
|
|
1493
1487
|
}
|
|
1488
|
+
function elScroll(scrollEl) {
|
|
1489
|
+
scrollEl = document.scrollingElement
|
|
1490
|
+
return {
|
|
1491
|
+
x: window.pageXOffset || scrollEl.scrollLeft,
|
|
1492
|
+
y: window.pageYOffset || scrollEl.scrollTop
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1494
1495
|
|
|
1495
1496
|
function render(node, $s) {
|
|
1496
1497
|
if (!node || node.nodeType != 1) {
|
|
@@ -1529,15 +1530,33 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1529
1530
|
throw e + "\n" + attr + ": " + expr
|
|
1530
1531
|
}
|
|
1531
1532
|
}
|
|
1533
|
+
// Iterates ";name! args" binding expressions, handles ;{}() in args
|
|
1534
|
+
function renderEach(str, fn) {
|
|
1535
|
+
var m, tok, argStart
|
|
1536
|
+
, bindRe = /[;\s]*([-.\w$]+)(!?)[ :]*/g
|
|
1537
|
+
, tokRe = /(["'\/])(?:\\.|[^\\])*?\1|(([{(\[])|[})\]])|;/g
|
|
1538
|
+
, depth = 0
|
|
1539
|
+
, result = ""
|
|
1540
|
+
while ((m = bindRe.exec(str))) {
|
|
1541
|
+
argStart = tokRe.lastIndex = bindRe.lastIndex
|
|
1542
|
+
for (depth = 0; (tok = tokRe.exec(str)); ) {
|
|
1543
|
+
if (tok[0] === ";" && depth < 1) break
|
|
1544
|
+
else if (tok[2]) depth += tok[3] ? 1 : -1
|
|
1545
|
+
}
|
|
1546
|
+
depth = bindRe.lastIndex = tok ? tok.index : str.length
|
|
1547
|
+
result += fn(str.slice(m.index, depth), m[1], m[2], str.slice(argStart, depth))
|
|
1548
|
+
}
|
|
1549
|
+
return result
|
|
1550
|
+
}
|
|
1532
1551
|
// Compiles binding expression string (e.g. ";txt foo;cls 'active',bar") into a Function.
|
|
1533
1552
|
// Extracts free variable names and aliases them from scope ($s.varName).
|
|
1534
1553
|
// raw parameter bypasses the $s guard wrapper (used by i18n getExt).
|
|
1535
1554
|
function makeFn(fn, raw, i) {
|
|
1536
|
-
fn = raw || "$s&&(" +
|
|
1555
|
+
fn = raw || "$s&&(" + renderEach(fn, function(match, name, op, args) {
|
|
1537
1556
|
return (
|
|
1538
1557
|
op ? "($el[$a]=$el[$a].replace($o[" + (i = bindOnce.indexOf(match), i < 0 ? bindOnce.push(match) - 1 : i)+ "],''),0)||" : ""
|
|
1539
1558
|
) + "$b['" + (bindings[name] ? name + "'].call($s" + (name == "$s" ? "=$S($el,$el)": "") + ",$el" : "set']($el,'" + name + "'") + (args ? "," + args : "") + ")||"
|
|
1540
|
-
}
|
|
1559
|
+
}) + "$r)"
|
|
1541
1560
|
var vars = replace(fnRe, "", fn).match(wordRe) || []
|
|
1542
1561
|
for (i = vars.length; i--; ) {
|
|
1543
1562
|
if (window[vars[i]] || vars.indexOf(vars[i]) !== i) vars.splice(i, 1)
|
|
@@ -1599,7 +1618,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1599
1618
|
(map = kbMaps[i++]) && !(
|
|
1600
1619
|
fn = !input || map.input ? map[code] || map[chr] || map.num && code > 47 && code < 58 && (chr|=0, map.num) || map.all : fn
|
|
1601
1620
|
) && map.bubble; );
|
|
1602
|
-
if (isStr(fn))
|
|
1621
|
+
if (isStr(fn)) LiteJS.go(fn)
|
|
1603
1622
|
else if (isFn(fn)) fn(e, chr, el)
|
|
1604
1623
|
}
|
|
1605
1624
|
})
|
|
@@ -1714,8 +1733,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1714
1733
|
function moveTwo(e) {
|
|
1715
1734
|
touches[ touches[0].pointerId == e.pointerId ? 0 : 1] = e
|
|
1716
1735
|
var diff
|
|
1717
|
-
, x =
|
|
1718
|
-
, y =
|
|
1736
|
+
, x = touches[0].clientX - touches[1].clientX
|
|
1737
|
+
, y = touches[0].clientY - touches[1].clientY
|
|
1719
1738
|
, dist = Math.sqrt(x*x + y*y) | 0
|
|
1720
1739
|
, angle = Math.atan2(y, x)
|
|
1721
1740
|
|
|
@@ -1806,14 +1825,15 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1806
1825
|
} : val
|
|
1807
1826
|
, els = !prepareVal && selector ? findAll(el, selector) : isArr(el) ? el : [ el ]
|
|
1808
1827
|
for (; (node = els[i++]); ) for (delay = 0; delay < len; delay++) {
|
|
1809
|
-
if ((
|
|
1810
|
-
result = fn(node,
|
|
1811
|
-
if (
|
|
1812
|
-
if (fn ===
|
|
1813
|
-
|
|
1814
|
-
if (canTransit) onceEvent(node, canTransit, bind(f, node, node, name, result))
|
|
1815
|
-
else data = 1
|
|
1828
|
+
if ((name = arr[delay])) {
|
|
1829
|
+
result = fn(node, name, isArr(value) ? value[delay] : value && typeof value === "object" && !value.nodeType ? value[result] : value, data)
|
|
1830
|
+
if (prepareVal) {
|
|
1831
|
+
if (fn === addEvent && data) {
|
|
1832
|
+
onceEvent(data.el || node, data.until, bind(rmEvent, node, node, name, value, data))
|
|
1816
1833
|
}
|
|
1834
|
+
} else {
|
|
1835
|
+
if (fn === cls || data < -1) result = !val || ""
|
|
1836
|
+
if (data < 0 && !transit(f, node, name, result)) data = 1
|
|
1817
1837
|
if (data > 0) f(node, name, result, "", data)
|
|
1818
1838
|
}
|
|
1819
1839
|
}
|
|
@@ -1853,8 +1873,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1853
1873
|
}
|
|
1854
1874
|
function injectCss(cssText) {
|
|
1855
1875
|
if (!styleNode) {
|
|
1856
|
-
// Safari and IE6-8 requires dynamically created
|
|
1857
|
-
// <style> elements to be inserted into the <head>
|
|
1876
|
+
// Safari and IE6-8 requires dynamically created <style> elements to be in <head>
|
|
1858
1877
|
append(find(html, "head"), styleNode = El("style"))
|
|
1859
1878
|
}
|
|
1860
1879
|
if (styleNode.styleSheet) styleNode.styleSheet.cssText += cssText
|
|
@@ -1882,26 +1901,32 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1882
1901
|
, next = 0
|
|
1883
1902
|
onStart = isFn(onStart) ? onStart : (onStart === tick || onStart) && fn
|
|
1884
1903
|
onEnd = isFn(onEnd) ? onEnd : (onEnd === tick || onEnd) && fn
|
|
1885
|
-
return function() {
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1904
|
+
return function(e) {
|
|
1905
|
+
if (!ms) {
|
|
1906
|
+
next = e
|
|
1907
|
+
if (!tick) tick = requestAnimationFrame(callLast)
|
|
1908
|
+
} else {
|
|
1909
|
+
var now = Date.now()
|
|
1910
|
+
if (now >= next) {
|
|
1911
|
+
if (next < 1) {
|
|
1912
|
+
if (onStart) onStart(e)
|
|
1913
|
+
} else fn(e)
|
|
1914
|
+
next = now + ms
|
|
1915
|
+
}
|
|
1916
|
+
if (onEnd) {
|
|
1917
|
+
clearTimeout(tick)
|
|
1918
|
+
tick = setTimeout(onEnd, next - now, e)
|
|
1919
|
+
}
|
|
1896
1920
|
}
|
|
1897
1921
|
}
|
|
1922
|
+
function callLast() {
|
|
1923
|
+
fn(next)
|
|
1924
|
+
tick = 0
|
|
1925
|
+
}
|
|
1898
1926
|
}
|
|
1899
1927
|
function rect(el) {
|
|
1900
1928
|
return el && el.nodeType ? el.getBoundingClientRect() : el
|
|
1901
1929
|
}
|
|
1902
|
-
function scrollPos(page, key) {
|
|
1903
|
-
return window[page] || html[key] || body[key] || 0
|
|
1904
|
-
}
|
|
1905
1930
|
function step(num, factor, mid) {
|
|
1906
1931
|
var x = ("" + factor).split(".")
|
|
1907
1932
|
, steps = num / factor
|