@litejs/ui 26.8.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/ui.js +35 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litejs/ui",
3
- "version": "26.8.0",
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.6.0"
30
+ "@litejs/cli": "26.8.0"
31
31
  }
32
32
  }
package/ui.js CHANGED
@@ -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, pushBase, styleNode
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
@@ -85,7 +85,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
85
85
  , i = 0
86
86
  , type = el.type
87
87
  , opts = el.options
88
- , checkbox = type === "checkbox" || type === "radio"
88
+ , isRadio = type === "radio"
89
+ , checkbox = type === "checkbox" || isRadio
89
90
 
90
91
  if (el.tagName === "FORM") {
91
92
  // Disabled controls do not receive focus,
@@ -118,7 +119,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
118
119
  } else if (el.val) {
119
120
  el.val(val)
120
121
  } else if (checkbox) {
121
- el.checked = !!val
122
+ el.checked = isRadio ? el.value == val : !!val
122
123
  } else {
123
124
  el.value = val
124
125
  }
@@ -139,8 +140,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
139
140
  el = value > -1 && opts[value] || el
140
141
  }
141
142
 
142
- return checkbox && !el.checked ?
143
- (type === "radio" ? UNDEF : NUL) :
143
+ return checkbox && !el.checked ? (isRadio ? UNDEF : NUL) :
144
144
  el.valObject !== UNDEF ? el.valObject : el.value
145
145
 
146
146
  function replacer(_, _key, offset) {
@@ -181,6 +181,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
181
181
  , fixEv = Event.fixEv || (Event.fixEv = {})
182
182
  , fixFn = Event.fixFn || (Event.fixFn = {})
183
183
 
184
+ , base = find(html, "base")
185
+ , pushBase = (base = base && base.href) && (LiteJS.push = replace(/.+?:\/\/[^/]+|[^\/]*$/g, "", base))
186
+
184
187
  /*** markup ***/
185
188
  , blockRe = /^(?:(=+|>| -| \d+\.) ([\s\S]+))/
186
189
  , tags = {
@@ -608,7 +611,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
608
611
  console.log("Outside view defined elements are rendered immediately into UI")
609
612
  /**/
610
613
  }
611
- if (parent.i) {
614
+ if (parent.I) {
612
615
  histStart(viewShow)
613
616
  }
614
617
 
@@ -616,7 +619,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
616
619
  if (offset && all === indent) return
617
620
 
618
621
  for (q = indent.length; q <= stack[0]; ) {
619
- if ((offset = parent.p)) {
622
+ if ((offset = parent.P)) {
620
623
  if (offset.c && !offset.e.childNodes[0]) break
621
624
  offset.d(offset)
622
625
  }
@@ -626,8 +629,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
626
629
  if (op === "@") {
627
630
  text = replace(/([\w,.]+)[!:]?/, /^\w+!/.test(text) ? "one!'$1'," : "on!'$1',", text)
628
631
  }
629
- if (parent.r) {
630
- parent.t += "\n" + all
632
+ if (parent.R) {
633
+ parent.T += "\n" + all
631
634
  } else if (plugin || mapStart && (sel = "map")) {
632
635
  if (plugins[sel]) {
633
636
  parentStack.push(parent)
@@ -678,7 +681,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
678
681
  // .n name .x parent view name .u parent DOM element
679
682
  // .e container el .d done callback .c saved elCache (for %el/%view)
680
683
  // When proto is a function, plugin accumulates raw text:
681
- // .r raw handler .t accumulated text .o original op+text .s separator
684
+ // .R raw handler .T accumulated text .o original op+text .s separator
682
685
  function addPlugin(name, proto, expectContent) {
683
686
  plugins[name] = Plugin
684
687
  function Plugin(parent, op, sep) {
@@ -687,9 +690,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
687
690
  plugin.n = arr[0] // name
688
691
  plugin.x = arr[1] // View parent
689
692
  plugin.u = parent
690
- if (plugin.r) {
691
- plugin.t = ""
692
- plugin.p = plugin.e = plugin
693
+ if (plugin.R) {
694
+ plugin.T = ""
695
+ plugin.P = plugin.e = plugin
693
696
  plugin.o = op
694
697
  plugin.s = sep
695
698
  } else {
@@ -697,10 +700,10 @@ console.log("LiteJS is in debug mode and that's fine for production")
697
700
  elCache = create(plugin.c = elCache)
698
701
  }
699
702
  plugin.e = El(name === "svg" ? name : "div")
700
- plugin.e.p = plugin
703
+ plugin.e.P = plugin
701
704
  }
702
705
  }
703
- assign(Plugin.prototype, isFn(proto) ? { d: Function("p", "p.r(p.o+p.t)"), r: proto } : proto)
706
+ assign(Plugin.prototype, isFn(proto) ? { d: Function("p", "p.R(p.o+p.T)"), R: proto } : proto)
704
707
  }
705
708
  function usePluginContent(plugin) {
706
709
  var el = plugin.e
@@ -715,12 +718,12 @@ console.log("LiteJS is in debug mode and that's fine for production")
715
718
  child._s = el._s
716
719
  }
717
720
  if (plugin.c) elCache = plugin.c
718
- el.p = plugin.e = plugin.u = UNDEF
721
+ el.P = plugin.e = plugin.u = UNDEF
719
722
  return child
720
723
  }
721
724
 
722
725
  addPlugin("ui", {
723
- d: Function("p", "p.u.i=1")
726
+ d: Function("p", "p.u.I=1")
724
727
  })
725
728
  plugins.start = plugins.ui
726
729
  addPlugin("slot", {
@@ -739,7 +742,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
739
742
  addPlugin("def", viewDef)
740
743
  addPlugin("js", viewEval)
741
744
  addPlugin("each", function() {
742
- var txt = this.t
745
+ var txt = this.T
743
746
  each(this.o, function(param) {
744
747
  viewParse(replace(/{key}/g, param, txt))
745
748
  })
@@ -1047,9 +1050,16 @@ console.log("LiteJS is in debug mode and that's fine for production")
1047
1050
  LiteJS.go = setUrl
1048
1051
  var histLast
1049
1052
  , hashFallback = getUrl()
1050
- , base = find(html, "base")
1051
- if ((base = base && base.href)) {
1052
- pushBase = LiteJS.push = replace(/.+?:\/\/[^/]+|[^\/]*$/g, "", base)
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]")
1053
1063
  }
1054
1064
  // Chrome and Safari emit a popstate event on page load, Firefox doesn't.
1055
1065
  // Firing popstate after onload is as designed.
@@ -1062,7 +1072,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
1062
1072
  }
1063
1073
  function getUrl() {
1064
1074
  return replace(/^[#\/\!]+|[\s\/]+$/g, "",
1065
- pushBase ? location.pathname.slice(pushBase.length) :
1075
+ pushBase && hashFallback !== UNDEF ? location.pathname.slice(pushBase.length) :
1066
1076
  // NOTE: in Firefox location.hash is decoded; in Safari location.pathname is decoded
1067
1077
  location.href.split("#")[1] || "")
1068
1078
  }
@@ -1723,8 +1733,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
1723
1733
  function moveTwo(e) {
1724
1734
  touches[ touches[0].pointerId == e.pointerId ? 0 : 1] = e
1725
1735
  var diff
1726
- , x = e0.clientX - touches[1].clientX
1727
- , y = e0.clientY - touches[1].clientY
1736
+ , x = touches[0].clientX - touches[1].clientX
1737
+ , y = touches[0].clientY - touches[1].clientY
1728
1738
  , dist = Math.sqrt(x*x + y*y) | 0
1729
1739
  , angle = Math.atan2(y, x)
1730
1740
 
@@ -1863,8 +1873,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
1863
1873
  }
1864
1874
  function injectCss(cssText) {
1865
1875
  if (!styleNode) {
1866
- // Safari and IE6-8 requires dynamically created
1867
- // <style> elements to be inserted into the <head>
1876
+ // Safari and IE6-8 requires dynamically created <style> elements to be in <head>
1868
1877
  append(find(html, "head"), styleNode = El("style"))
1869
1878
  }
1870
1879
  if (styleNode.styleSheet) styleNode.styleSheet.cssText += cssText