MCPcopy
hub / github.com/angular-ui/ui-grid / addAttrInterpolateDirective

Function addAttrInterpolateDirective

lib/test/angular/1.5.0/angular.js:9337–9404  ·  view source on GitHub ↗
(node, directives, value, name, allOrNothing)

Source from the content-addressed store, hash-verified

9335
9336
9337 function addAttrInterpolateDirective(node, directives, value, name, allOrNothing) {
9338 var trustedContext = getTrustedContext(node, name);
9339 allOrNothing = ALL_OR_NOTHING_ATTRS[name] || allOrNothing;
9340
9341 var interpolateFn = $interpolate(value, true, trustedContext, allOrNothing);
9342
9343 // no interpolation found -> ignore
9344 if (!interpolateFn) return;
9345
9346
9347 if (name === "multiple" && nodeName_(node) === "select") {
9348 throw $compileMinErr("selmulti",
9349 "Binding to the 'multiple' attribute is not supported. Element: {0}",
9350 startingTag(node));
9351 }
9352
9353 directives.push({
9354 priority: 100,
9355 compile: function() {
9356 return {
9357 pre: function attrInterpolatePreLinkFn(scope, element, attr) {
9358 var $$observers = (attr.$$observers || (attr.$$observers = createMap()));
9359
9360 if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
9361 throw $compileMinErr('nodomevents',
9362 "Interpolations for HTML DOM event attributes are disallowed. Please use the " +
9363 "ng- versions (such as ng-click instead of onclick) instead.");
9364 }
9365
9366 // If the attribute has changed since last $interpolate()ed
9367 var newValue = attr[name];
9368 if (newValue !== value) {
9369 // we need to interpolate again since the attribute value has been updated
9370 // (e.g. by another directive's compile function)
9371 // ensure unset/empty values make interpolateFn falsy
9372 interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);
9373 value = newValue;
9374 }
9375
9376 // if attribute was updated so that there is no interpolation going on we don't want to
9377 // register any observers
9378 if (!interpolateFn) return;
9379
9380 // initialize attr object so that it's ready in case we need the value for isolate
9381 // scope initialization, otherwise the value would not be available from isolate
9382 // directive's linking fn during linking phase
9383 attr[name] = interpolateFn(scope);
9384
9385 ($$observers[name] || ($$observers[name] = [])).$$inter = true;
9386 (attr.$$observers && attr.$$observers[name].$$scope || scope).
9387 $watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {
9388 //special case for class attribute addition + removal
9389 //so that class changes can tap into the animation
9390 //hooks provided by the $animate service. Be sure to
9391 //skip animations when the first digest occurs (when
9392 //both the new and the old values are the same) since
9393 //the CSS classes are the non-interpolated values
9394 if (name === 'class' && newValue != oldValue) {

Callers 1

collectDirectivesFunction · 0.70

Calls 5

getTrustedContextFunction · 0.70
$interpolateFunction · 0.70
nodeName_Function · 0.70
startingTagFunction · 0.70
createMapFunction · 0.70

Tested by

no test coverage detected