diff --git a/src/jqLite.js b/src/jqLite.js index ef5082ed2233..0548806c7248 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -409,25 +409,22 @@ function jqLiteController(element, name) { } function jqLiteInheritedData(element, name, value) { - element = jqLite(element); - // if element is the document object work with the html element instead // this makes $(document).scope() possible - if(element[0].nodeType == 9) { - element = element.find('html'); + if(element.nodeType == 9) { + element = element.documentElement; } var names = isArray(name) ? name : [name]; - while (element.length) { - var node = element[0]; + while (element) { for (var i = 0, ii = names.length; i < ii; i++) { - if ((value = element.data(names[i])) !== undefined) return value; + if ((value = jqLite.data(element, names[i])) !== undefined) return value; } // If dealing with a document fragment node with a host element, and no parent, use the host // element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM // to lookup parent controllers. - element = jqLite(node.parentNode || (node.nodeType === 11 && node.host)); + element = element.parentNode || (element.nodeType === 11 && element.host); } } @@ -512,18 +509,25 @@ function getAliasedAttrName(element, name) { return (nodeName === 'INPUT' || nodeName === 'TEXTAREA') && ALIASED_ATTR[name]; } +forEach({ + data: jqLiteData, + removeData: jqLiteRemoveData +}, function(fn, name) { + JQLite[name] = fn; +}); + forEach({ data: jqLiteData, inheritedData: jqLiteInheritedData, scope: function(element) { // Can't use jqLiteData here directly so we stay compatible with jQuery! - return jqLite(element).data('$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']); + return jqLite.data(element, '$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']); }, isolateScope: function(element) { // Can't use jqLiteData here directly so we stay compatible with jQuery! - return jqLite(element).data('$isolateScope') || jqLite(element).data('$isolateScopeNoTemplate'); + return jqLite.data(element, '$isolateScope') || jqLite.data(element, '$isolateScopeNoTemplate'); }, controller: jqLiteController, diff --git a/src/ng/compile.js b/src/ng/compile.js index 5d3cfed694a6..8c9a26094b37 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -922,7 +922,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { : null; if (nodeLinkFn && nodeLinkFn.scope) { - safeAddClass(jqLite(nodeList[i]), 'ng-scope'); + safeAddClass(attrs.$$element, 'ng-scope'); } childLinkFn = (nodeLinkFn && nodeLinkFn.terminal || @@ -944,7 +944,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { return linkFnFound ? compositeLinkFn : null; function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) { - var nodeLinkFn, childLinkFn, node, $node, childScope, i, ii, n, childBoundTranscludeFn; + var nodeLinkFn, childLinkFn, node, childScope, i, ii, n, childBoundTranscludeFn; // copy nodeList so that linking doesn't break due to live list updates. var nodeListLength = nodeList.length, @@ -957,12 +957,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { node = stableNodeList[n]; nodeLinkFn = linkFns[i++]; childLinkFn = linkFns[i++]; - $node = jqLite(node); if (nodeLinkFn) { if (nodeLinkFn.scope) { childScope = scope.$new(); - $node.data('$scope', childScope); + jqLite.data(node, '$scope', childScope); } else { childScope = scope; } @@ -1262,12 +1261,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { if (directiveValue == 'element') { hasElementTranscludeDirective = true; terminalPriority = directive.priority; - $template = groupScan(compileNode, attrStart, attrEnd); + $template = $compileNode; $compileNode = templateAttrs.$$element = jqLite(document.createComment(' ' + directiveName + ': ' + templateAttrs[directiveName] + ' ')); compileNode = $compileNode[0]; - replaceWith(jqCollection, jqLite(sliceArgs($template)), compileNode); + replaceWith(jqCollection, sliceArgs($template), compileNode); childTranscludeFn = compile($template, transcludeFn, terminalPriority, replaceDirective && replaceDirective.name, { @@ -1453,20 +1452,19 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { if (newIsolateScopeDirective) { var LOCAL_REGEXP = /^\s*([@=&])(\??)\s*(\w*)\s*$/; - var $linkNode = jqLite(linkNode); isolateScope = scope.$new(true); if (templateDirective && (templateDirective === newIsolateScopeDirective || templateDirective === newIsolateScopeDirective.$$originalDirective)) { - $linkNode.data('$isolateScope', isolateScope) ; + $element.data('$isolateScope', isolateScope) ; } else { - $linkNode.data('$isolateScopeNoTemplate', isolateScope); + $element.data('$isolateScopeNoTemplate', isolateScope); } - safeAddClass($linkNode, 'ng-isolate-scope'); + safeAddClass($element, 'ng-isolate-scope'); forEach(newIsolateScopeDirective.scope, function(definition, scopeName) { var match = definition.match(LOCAL_REGEXP) || [], diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index cf880aef0382..b6d20a932a48 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -386,6 +386,26 @@ describe('jqLite', function() { selected.removeData('prop2'); }); + it('should provide the non-wrapped data calls', function() { + var node = document.createElement('div'); + + expect(jqLite.data(node, "foo")).toBeUndefined(); + + jqLite.data(node, "foo", "bar"); + + expect(jqLite.data(node, "foo")).toBe("bar"); + expect(jqLite(node).data("foo")).toBe("bar"); + + expect(jqLite.data(node)).toBe(jqLite(node).data()); + + jqLite.removeData(node, "foo"); + expect(jqLite.data(node, "foo")).toBeUndefined(); + + jqLite.data(node, "bar", "baz"); + jqLite.removeData(node); + jqLite.removeData(node); + expect(jqLite.data(node, "bar")).toBeUndefined(); + }); it('should not add to the cache if the node is a comment or text node', function() { var calcCacheSize = function() {