diff --git a/demos/step-by-step/06_top-level-linking.html b/demos/step-by-step/06_top-level-linking.html index d2ac5d4..82a052f 100644 --- a/demos/step-by-step/06_top-level-linking.html +++ b/demos/step-by-step/06_top-level-linking.html @@ -14,7 +14,7 @@

Data-Linking to static content in the page

- +

diff --git a/jsrender.js b/jsrender.js index 419fa45..6f4faf7 100644 --- a/jsrender.js +++ b/jsrender.js @@ -6,7 +6,7 @@ * Copyright 2012, Boris Moore * Released under the MIT License. */ -// informal pre beta commit counter: 3 +// informal pre beta commit counter: 5 this.jsviews || this.jQuery && jQuery.views || (function( window, undefined ) { @@ -81,7 +81,7 @@ function setDelimiters( openChars, closeChars ) { // Build regex with new delimiters jsv.rTag = rTag // make rTag available to JsViews (or other components) for parsing binding expressions = secondOpenChar - // tag (followed by / space or }) or colon or html or code + // tag (followed by / space or }) or colon or html or code + "(?:(?:(\\w+(?=[\\/\\s" + firstCloseChar + "]))|(?:(\\w+)?(:)|(>)|(\\*)))" // params + "\\s*((?:[^" + firstCloseChar + "]|" + firstCloseChar + "(?!" + secondCloseChar + "))*?)" @@ -466,10 +466,10 @@ function tmplFn( markup, tmpl, bind ) { for ( i = 0; i < l; i++ ) { // AST nodes: [ tagName, converter, params, content, hash, contentMarkup ] node = astTop[ i ]; - if ( node[ 0 ] === "*" ) { - code = code.slice( 0, i ? -1 : -3 ) + ";" + node[ 1 ] + (i + 1 < l ? "ret+=" : ""); - } else if ( "" + node === node ) { // type string + if ( "" + node === node ) { // type string code += '"' + node + '"+'; + } else if ( node[ 0 ] === "*" ) { + code = code.slice( 0, i ? -1 : -3 ) + ";" + node[ 1 ] + (i + 1 < l ? "ret+=" : ""); } else { tag = node[ 0 ]; converter = node[ 1 ]; @@ -626,8 +626,16 @@ function compile( name, tmpl, parent, options ) { // Return the template object, if already compiled, or the markup string if ( ("" + value === value) || value.nodeType > 0 ) { - // If selector is valid and returns at least one element, get first element - elem = value.nodeType > 0 ? value : !rTmplString.test( value ) && jQuery && jQuery( value )[0]; + try { + elem = value.nodeType > 0 + ? value + : !rTmplString.test( value ) + // If value is a string and does not contain HTML or tag content, then test as selector + && jQuery && jQuery( value )[0]; + // If selector is valid and returns at least one element, get first element + // If invalid, jQuery will throw. We will stay with the original string. + } catch(e) {} + if ( elem && elem.type ) { // It is a script element // Create a name for data linking if none provided