can-stache-bindings
Advanced tools
Comparing version 3.4.5 to 3.5.0-pre.0
@@ -354,18 +354,44 @@ // # can-stache-bindings.js | ||
event: function(el, data) { | ||
// Get the `event` name and if we are listening to the element or viewModel. | ||
// The attribute name is the name of the event. | ||
var attributeName = data.attributeName, | ||
// the name of the event we are binding | ||
event, | ||
// if we are binding on the element or the VM | ||
bindingContext; | ||
// legacy binding | ||
if(attributeName.indexOf('can-') === 0) { | ||
event = attributeName.substr("can-".length); | ||
bindingContext = el; | ||
} else if(attributeName.indexOf("on:") === 0 ) { | ||
event = attributeName.substr("on:".length); | ||
var byIndex = event.indexOf(":by:"); | ||
if( byIndex >= 0 ) { | ||
bindingContext = data.scope.get(decodeAttrName(event.substr(byIndex+ ":by:".length))); | ||
event = event.substr(0, byIndex); | ||
} else { | ||
// bind on the element if there is not a viewModel | ||
var viewModel = domData.get.call(el, "viewModel"); | ||
bindingContext = viewModel !== undefined ? viewModel : el; | ||
} | ||
} else { | ||
event = removeBrackets(attributeName, '(', ')'); | ||
if(event.charAt(0) === "$") { | ||
event = event.substr(1); | ||
bindingContext = el; | ||
} else { | ||
if(event.indexOf("\\s") >= 0) { | ||
var eventSplit = event.split("\\s"); | ||
bindingContext = data.scope.get(decodeAttrName(eventSplit[0])); | ||
event = eventSplit[1]; | ||
}else{ | ||
bindingContext = canViewModel(el); | ||
} | ||
} | ||
} | ||
// The old way of binding is can-X | ||
legacyBinding = attributeName.indexOf('can-') === 0, | ||
event = attributeName.indexOf('can-') === 0 ? | ||
attributeName.substr("can-".length) : | ||
removeBrackets(attributeName, '(', ')'), | ||
onBindElement = legacyBinding; | ||
event = decodeAttrName(event); | ||
if(event.charAt(0) === "$") { | ||
event = event.substr(1); | ||
onBindElement = true; | ||
} | ||
@@ -452,15 +478,4 @@ // This is the method that the event will initially trigger. It will look up the method by the string name | ||
var context; | ||
if(onBindElement) { | ||
context = el; | ||
}else{ | ||
if(event.indexOf(" ") >= 0) { | ||
var eventSplit = event.split(" "); | ||
context = data.scope.get(eventSplit[0]); | ||
event = eventSplit[1]; | ||
}else{ | ||
context = canViewModel(el); | ||
} | ||
} | ||
// Unbind the event when the attribute is removed from the DOM | ||
@@ -480,3 +495,3 @@ var attributesHandler = function(ev) { | ||
var unbindEvent = function() { | ||
canEvent.off.call(context, event, handler); | ||
canEvent.off.call(bindingContext, event, handler); | ||
canEvent.off.call(el, 'attributes', attributesHandler); | ||
@@ -488,3 +503,3 @@ canEvent.off.call(el, 'removed', removedHandler); | ||
// attribute name (can-click="foo") | ||
canEvent.on.call(context, event, handler); | ||
canEvent.on.call(bindingContext, event, handler); | ||
canEvent.on.call(el, 'attributes', attributesHandler); | ||
@@ -587,2 +602,3 @@ canEvent.on.call(el, 'removed', removedHandler); | ||
// `(EVENT)` event bindings. | ||
viewCallbacks.attr(/on:[\w\.]+/, behaviors.event); | ||
viewCallbacks.attr(/^\([\$?\w\.\\]+\)$/, behaviors.event); | ||
@@ -817,3 +833,5 @@ | ||
}; | ||
var endsWith = String.prototype.endsWith || function(text){ | ||
return this.lastIndexOf(text) === (this.length - text.length); | ||
}; | ||
// Regular expressions for getBindingInfo | ||
@@ -840,6 +858,51 @@ var bindingsRegExp = /\{(\()?(\^)?([^\}\)]+)\)?\}/, | ||
var getBindingInfo = function(node, attributeViewModelBindings, templateType, tagName) { | ||
var bindingInfo, | ||
attributeName = node.name, | ||
attributeValue = node.value || ""; | ||
attributeValue = node.value || "", | ||
childName; | ||
// check new binding syntaxes | ||
if(endsWith.call(attributeName, ":from")) { | ||
childName = attributeName.substr(0, attributeName.length - ":from".length); | ||
return { | ||
parent: "scope", | ||
child: "viewModel", | ||
childToParent: false, | ||
parentToChild: true, | ||
bindingAttributeName: attributeName, | ||
childName: decodeAttrName(string.camelize(childName)), | ||
parentName: attributeValue, | ||
initializeValues: true, | ||
syncChildWithParent: false | ||
}; | ||
} else if(endsWith.call(attributeName, ":to")) { | ||
childName = attributeName.substr(0, attributeName.length - ":to".length); | ||
return { | ||
parent: "scope", | ||
child: "viewModel", | ||
childToParent: true, | ||
parentToChild: false, | ||
bindingAttributeName: attributeName, | ||
childName: decodeAttrName(string.camelize(childName)), | ||
parentName: attributeValue, | ||
initializeValues: true, | ||
syncChildWithParent: false | ||
}; | ||
} else if(endsWith.call(attributeName, ":bind")) { | ||
childName = attributeName.substr(0, attributeName.length - ":bind".length); | ||
return { | ||
parent: "scope", | ||
child: "viewModel", | ||
childToParent: true, | ||
parentToChild: true, | ||
bindingAttributeName: attributeName, | ||
childName: decodeAttrName(string.camelize(childName)), | ||
parentName: attributeValue, | ||
initializeValues: true, | ||
syncChildWithParent: true | ||
}; | ||
} | ||
// Does this match the new binding syntax? | ||
@@ -896,3 +959,3 @@ var matches = attributeName.match(bindingsRegExp); | ||
var childName = matches[3]; | ||
childName = matches[3]; | ||
var isDOM = childName.charAt(0) === "$"; | ||
@@ -899,0 +962,0 @@ if(isDOM) { |
{ | ||
"name": "can-stache-bindings", | ||
"version": "3.4.5", | ||
"version": "3.5.0-pre.0", | ||
"description": "Default binding syntaxes for can-stache", | ||
@@ -41,11 +41,11 @@ "homepage": "http://canjs.com", | ||
"can-reflect": "^1.2.1", | ||
"can-simple-map": "^3.3.0-pre.2", | ||
"can-stache": "^3.2.0-pre.0", | ||
"can-simple-map": "^3.3.0", | ||
"can-stache": "^3.3.0", | ||
"can-symbol": "^1.0.0", | ||
"can-types": "^1.1.0", | ||
"can-util": "^3.9.0", | ||
"can-view-callbacks": "^3.2.0-pre.0", | ||
"can-view-live": "^3.2.0-pre.0", | ||
"can-view-model": "^3.4.0-pre.0", | ||
"can-view-scope": "^3.3.0-pre.3", | ||
"can-view-callbacks": "^3.2.0", | ||
"can-view-live": "^3.2.0", | ||
"can-view-model": "^3.4.0", | ||
"can-view-scope": "^3.3.0", | ||
"can-stache-key": "^0.0.2" | ||
@@ -55,4 +55,4 @@ }, | ||
"bit-docs": "0.0.7", | ||
"can-define": "^1.3.0-pre.1", | ||
"can-list": "^3.2.0-pre.1", | ||
"can-define": "^1.3.0", | ||
"can-list": "^3.2.0", | ||
"can-map": "^3.3.1", | ||
@@ -59,0 +59,0 @@ "can-vdom": "^3.1.0", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
182477
34
4090
1
Updatedcan-simple-map@^3.3.0
Updatedcan-stache@^3.3.0
Updatedcan-view-callbacks@^3.2.0
Updatedcan-view-live@^3.2.0
Updatedcan-view-model@^3.4.0
Updatedcan-view-scope@^3.3.0