|
1 | | -/*! jsviews.js v1.0.0 single-file version: http://jsviews.com/ */ |
| 1 | +/*! jsviews.js v1.0.1 single-file version: http://jsviews.com/ */ |
2 | 2 | /*! includes JsRender, JsObservable and JsViews - see: http://jsviews.com/#download */ |
3 | 3 |
|
4 | 4 | /* Interactive data-driven views using JsRender templates */ |
@@ -47,26 +47,20 @@ if (!$ || !$.fn) { |
47 | 47 | throw "JsViews requires jQuery"; // We require jQuery |
48 | 48 | } |
49 | 49 |
|
50 | | -var versionNumber = "v1.0.0", |
| 50 | +var versionNumber = "v1.0.1", |
51 | 51 |
|
52 | 52 | jsvStoreName, rTag, rTmplString, topView, $views, $observe, $observable, $expando, |
53 | 53 | _ocp = "_ocp", // Observable contextual parameter |
54 | 54 |
|
55 | 55 | //TODO tmplFnsCache = {}, |
56 | | - $isFunction, $isArray, $templates, $converters, $helpers, $tags, $sub, $subSettings, $subSettingsAdvanced, $viewsSettings, delimOpenChar0, delimOpenChar1, delimCloseChar0, delimCloseChar1, linkChar, setting, baseOnError, |
57 | | - |
58 | | - rPath = /^(!*?)(?:null|true|false|\d[\d.]*|([\w$]+|\.|~([\w$]+)|#(view|([\w$]+))?)([\w$.^]*?)(?:[.[^]([\w$]+)\]?)?)$/g, |
59 | | - // not object helper view viewProperty pathTokens leafToken |
60 | | - |
61 | | - rParams = /(\()(?=\s*\()|(?:([([])\s*)?(?:(\^?)(~?[\w$.^]+)?\s*((\+\+|--)|\+|-|~(?![\w$_])|&&|\|\||===|!==|==|!=|<=|>=|[<>%*:?\/]|(=))\s*|(!*?(@)?[#~]?[\w$.^]+)([([])?)|(,\s*)|(\(?)\\?(?:(')|("))|(?:\s*(([)\]])(?=[.^]|\s*$|[^([])|[)\]])([([]?))|(\s+)/g, |
62 | | - // lftPrn0 lftPrn bound path operator err eq path2 late prn comma lftPrn2 apos quot rtPrn rtPrnDot prn2 space |
63 | | - // (left paren? followed by (path? followed by operator) or (path followed by left paren?)) or comma or apos or quot or right paren or space |
| 56 | + $isFunction, $isArray, $templates, $converters, $helpers, $tags, $sub, $subSettings, $subSettingsAdvanced, $viewsSettings, |
| 57 | + delimOpenChar0, delimOpenChar1, delimCloseChar0, delimCloseChar1, linkChar, setting, baseOnError, |
64 | 58 |
|
65 | 59 | isRenderCall, |
66 | 60 | rNewLine = /[ \t]*(\r\n|\n|\r)/g, |
67 | 61 | rUnescapeQuotes = /\\(['"])/g, |
68 | 62 | rEscapeQuotes = /['"\\]/g, // Escape quotes and \ character |
69 | | - rBuildHash = /(?:\x08|^)(onerror:)?(?:(~?)(([\w$_\.]+):)?([^\x08]+))\x08(,)?([^\x08]+)/gi, |
| 63 | + rBuildHash = /(?:\x08|^)(onerror:)?(?:(~?)(([\w$.]+):)?([^\x08]+))\x08(,)?([^\x08]+)/gi, |
70 | 64 | rTestElseIf = /^if\s/, |
71 | 65 | rFirstElem = /<(\w+)[>\s]/, |
72 | 66 | rAttrEncode = /[\x00`><"'&=]/g, // Includes > encoding since rConvertMarkers in JsViews does not skip > characters in attribute strings |
@@ -122,6 +116,12 @@ var versionNumber = "v1.0.0", |
122 | 116 | jsviews: versionNumber, |
123 | 117 | sub: { |
124 | 118 | // subscription, e.g. JsViews integration |
| 119 | + rPath: /^(!*?)(?:null|true|false|\d[\d.]*|([\w$]+|\.|~([\w$]+)|#(view|([\w$]+))?)([\w$.^]*?)(?:[.[^]([\w$]+)\]?)?)$/g, |
| 120 | + // not object helper view viewProperty pathTokens leafToken |
| 121 | + |
| 122 | + rPrm: /(\()(?=\s*\()|(?:([([])\s*)?(?:(\^?)(~?[\w$.^]+)?\s*((\+\+|--)|\+|-|~(?![\w$])|&&|\|\||===|!==|==|!=|<=|>=|[<>%*:?\/]|(=))\s*|(!*?(@)?[#~]?[\w$.^]+)([([])?)|(,\s*)|(\(?)\\?(?:(')|("))|(?:\s*(([)\]])(?=[.^]|\s*$|[^([])|[)\]])([([]?))|(\s+)/g, |
| 123 | + // lftPrn0 lftPrn bound path operator err eq path2 late prn comma lftPrn2 apos quot rtPrn rtPrnDot prn2 space |
| 124 | + |
125 | 125 | View: View, |
126 | 126 | Err: JsViewsError, |
127 | 127 | tmplFn: tmplFn, |
@@ -2096,12 +2096,13 @@ function paramStructure(parts, type) { |
2096 | 2096 | function parseParams(params, pathBindings, tmpl, isLinkExpr) { |
2097 | 2097 |
|
2098 | 2098 | function parseTokens(all, lftPrn0, lftPrn, bound, path, operator, err, eq, path2, late, prn, comma, lftPrn2, apos, quot, rtPrn, rtPrnDot, prn2, space, index, full) { |
2099 | | - // /(\()(?=\s*\()|(?:([([])\s*)?(?:(\^?)(~?[\w$.^]+)?\s*((\+\+|--)|\+|-|&&|\|\||===|!==|==|!=|<=|>=|[<>%*:?\/]|(=))\s*|(!*?(@)?[#~]?[\w$.^]+)([([])?)|(,\s*)|(\(?)\\?(?:(')|("))|(?:\s*(([)\]])(?=[.^]|\s*$|[^([])|[)\]])([([]?))|(\s+)/g, |
2100 | | - // lftPrn0 lftPrn bound path operator err eq path2 late prn comma lftPrn2 apos quot rtPrn rtPrnDot prn2 space |
2101 | | - // (left paren? followed by (path? followed by operator) or (path followed by paren?)) or comma or apos or quot or right paren or space |
| 2099 | + // /(\()(?=\s*\()|(?:([([])\s*)?(?:(\^?)(~?[\w$.^]+)?\s*((\+\+|--)|\+|-|~(?![\w$])|&&|\|\||===|!==|==|!=|<=|>=|[<>%*:?\/]|(=))\s*|(!*?(@)?[#~]?[\w$.^]+)([([])?)|(,\s*)|(\(?)\\?(?:(')|("))|(?:\s*(([)\]])(?=[.^]|\s*$|[^([])|[)\]])([([]?))|(\s+)/g, |
| 2100 | + //lftPrn0 lftPrn bound path operator err eq path2 late prn comma lftPrn2 apos quot rtPrn rtPrnDot prn2 space |
| 2101 | + // (left paren? followed by (path? followed by operator) or (path followed by paren?)) or comma or apos or quot or right paren or space |
| 2102 | + |
2102 | 2103 | function parsePath(allPath, not, object, helper, view, viewProperty, pathTokens, leafToken) { |
2103 | | - //rPath = /^(!*?)(?:null|true|false|\d[\d.]*|([\w$]+|\.|~([\w$]+)|#(view|([\w$]+))?)([\w$.^]*?)(?:[.[^]([\w$]+)\]?)?)$/g, |
2104 | | - // not object helper view viewProperty pathTokens leafToken |
| 2104 | + // /^(!*?)(?:null|true|false|\d[\d.]*|([\w$]+|\.|~([\w$]+)|#(view|([\w$]+))?)([\w$.^]*?)(?:[.[^]([\w$]+)\]?)?)$/g, |
| 2105 | + // not object helper view viewProperty pathTokens leafToken |
2105 | 2106 | var subPath = object === "."; |
2106 | 2107 | if (object) { |
2107 | 2108 | path = path.slice(not.length); |
@@ -2250,7 +2251,7 @@ function parseParams(params, pathBindings, tmpl, isLinkExpr) { |
2250 | 2251 | bindings && ((bindings = bndCtx.bd = pathBindings[named] = []), bindings.skp = !bound), path + ':') |
2251 | 2252 | : path |
2252 | 2253 | // path |
2253 | | - ? (path.split("^").join(".").replace(rPath, parsePath) |
| 2254 | + ? (path.split("^").join(".").replace($sub.rPath, parsePath) |
2254 | 2255 | + (prn |
2255 | 2256 | // some.fncall( |
2256 | 2257 | ? (bndCtx = bndStack[++parenDepth] = {bd: []}, fnCall[parenDepth] = rtSq, prn) |
@@ -2294,7 +2295,7 @@ function parseParams(params, pathBindings, tmpl, isLinkExpr) { |
2294 | 2295 | if (params[0] === "@") { |
2295 | 2296 | params = params.replace(rBracketQuote, "."); |
2296 | 2297 | } |
2297 | | - result = (params + (tmpl ? " " : "")).replace(rParams, parseTokens); |
| 2298 | + result = (params + (tmpl ? " " : "")).replace($sub.rPrm, parseTokens); |
2298 | 2299 |
|
2299 | 2300 | return !parenDepth && result || syntaxError(params); // Syntax error if unbalanced parens in params expression |
2300 | 2301 | } |
@@ -3874,7 +3875,7 @@ if (!$.observe) { |
3874 | 3875 | self._srt = true; // Flag for sorting during refresh |
3875 | 3876 | for (j=k=0; j<newLength; j++) { |
3876 | 3877 | if ((newItem = newItems[j]) === data[j-k]) { |
3877 | | - insertAdded(); |
| 3878 | + insertAdded(); |
3878 | 3879 | } else { |
3879 | 3880 | for (i=j-k; i<dataLength; i++) { |
3880 | 3881 | if (newItem === data[i]) { |
@@ -3972,7 +3973,7 @@ if (!$.observe) { |
3972 | 3973 | } else if (!unbound) { |
3973 | 3974 | if (mapDef.obsSrc) { |
3974 | 3975 | $observable(map.src).observeAll(map.obs = function(ev, eventArgs) { |
3975 | | - if (!changing) { |
| 3976 | + if (!changing && !eventArgs.refresh) { |
3976 | 3977 | changing = true; |
3977 | 3978 | mapDef.obsSrc(map, ev, eventArgs); |
3978 | 3979 | changing = undefined; |
@@ -4118,7 +4119,7 @@ var activeBody, rTagDatalink, $view, $viewsLinkAttr, linkViewsSel, wrapMap, view |
4118 | 4119 | bindingStore = {}, |
4119 | 4120 | bindingKey = 1, |
4120 | 4121 | rViewPath = /^#(view\.?)?/, |
4121 | | - rConvertMarkers = /((\/>)|<\/(\w+)>|)(\s*)([#\/]\d+(?:_|(\^)))`(\s*)(<\w+(?=[\s\/>]))?|\s*(?:(<\w+(?=[\s\/>]))|<\/(\w+)>(\s*)|(\/>)\s*|(>)|$)/g, |
| 4122 | + rConvertMarkers = /((\/>)|<\/(\w+)>|)(\s*)([#/]\d+(?:_|(\^)))`(\s*)(<\w+(?=[\s\/>]))?|\s*(?:(<\w+(?=[\s\/>]))|<\/(\w+)>(\s*)|(\/>)\s*|(>)|$)/g, |
4122 | 4123 | rOpenViewMarkers = /(#)()(\d+)(_)/g, |
4123 | 4124 | rOpenMarkers = /(#)()(\d+)([_^])/g, |
4124 | 4125 | rViewMarkers = /(?:(#)|(\/))(\d+)(_)/g, |
@@ -5063,7 +5064,7 @@ function viewLink(outerData, parentNode, prevNode, nextNode, html, refresh, cont |
5063 | 5064 |
|
5064 | 5065 | //==== nested functions ==== |
5065 | 5066 | function convertMarkers(all, preceding, selfClose, closeTag, spaceBefore, id, boundId, spaceAfter, tag1, tag2, closeTag2, spaceAfterClose, selfClose2, endOpenTag) { |
5066 | | - // rConvertMarkers = /(^|(\/>)|<\/(\w+)>|)(\s*)([#\/]\d+(?:_|(\^)))`(\s*)(<\w+(?=[\s\/>]))?|\s*(?:(<\w+(?=[\s\/>]))|<\/(\w+)>(\s*)|(\/>)\s*|(>))/g, |
| 5067 | + // rConvertMarkers = /(^|(\/>)|<\/(\w+)>|)(\s*)([#/]\d+(?:_|(\^)))`(\s*)(<\w+(?=[\s\/>]))?|\s*(?:(<\w+(?=[\s\/>]))|<\/(\w+)>(\s*)|(\/>)\s*|(>))/g, |
5067 | 5068 | // prec, slfCl, clsTag, spBefore, id, bndId spAfter,tag1, tag2, clTag2,sac slfCl2, endOpenTag |
5068 | 5069 | // Convert the markers that were included by addBindingMarkers in template output, to appropriate DOM annotations: |
5069 | 5070 | // data-jsv attributes (for element-only content) or script marker nodes (within phrasing or flow content). |
@@ -7098,7 +7099,7 @@ $tags({ |
7098 | 7099 | if (!contextOb) { |
7099 | 7100 | // Get the path for the preceding object (context object) of handler (which is the last arg), compile function |
7100 | 7101 | // to return that context object, and run compiled function against data |
7101 | | - contextOb = /^(.*)[\.^][\w$]+$/.exec(tagCtx.params.args.slice(-params.length - 1)[0]); |
| 7102 | + contextOb = /^(.*)[.^][\w$]+$/.exec(tagCtx.params.args.slice(-params.length - 1)[0]); |
7102 | 7103 | contextOb = contextOb && $sub.tmplFn(delimOpenChar1 + ":" + contextOb[1] + delimCloseChar0, view.tmpl, true)(linkCtx.data, view); |
7103 | 7104 | } |
7104 | 7105 |
|
|
0 commit comments