Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Synced to latest JsRender
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisMoore committed Apr 19, 2012
1 parent dc0510c commit fc9ff01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion demos/step-by-step/06_top-level-linking.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h3>Data-Linking to static content in the page</h3>
<button onclick="showData()">show data</button>

<button onclick="setNameAndCityAndColorAndCars()">Modify name, city, color and cars</button>
<button onclick="setCity()">set city</button>
<button onclick="setCity()">Modify city</button>
<hr /><br />

<div id="myLinkedContent">
Expand Down
22 changes: 15 additions & 7 deletions jsrender.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down Expand Up @@ -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 + "))*?)"
Expand Down Expand Up @@ -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 ];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fc9ff01

Please sign in to comment.