Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Double directive controller instantiation fix #931

Merged
merged 6 commits into from
May 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
*/

var jqCache = {},
jqName = 'ng-' + new Date().getTime(),
jqName = JQLite.expando = 'ng-' + new Date().getTime(),
jqId = 1,
addEventListenerFn = (window.document.addEventListener
? function(element, type, fn) {element.addEventListener(type, fn, false);}
Expand All @@ -84,7 +84,7 @@ var jqCache = {},
? function(element, type, fn) {element.removeEventListener(type, fn, false); }
: function(element, type, fn) {element.detachEvent('on' + type, fn); });

function jqNextId() { return (jqId++); }
function jqNextId() { return ++jqId; }


var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
Expand Down Expand Up @@ -187,7 +187,8 @@ function JQLiteDealoc(element){

function JQLiteRemoveData(element) {
var cacheId = element[jqName],
cache = jqCache[cacheId];
cache = jqCache[cacheId];

if (cache) {
if (cache.bind) {
forEach(cache.bind, function(fn, type){
Expand All @@ -206,14 +207,29 @@ function JQLiteRemoveData(element) {
function JQLiteData(element, key, value) {
var cacheId = element[jqName],
cache = jqCache[cacheId || -1];

if (isDefined(value)) {
if (!cache) {
element[jqName] = cacheId = jqNextId();
cache = jqCache[cacheId] = {};
}
cache[key] = value;
} else {
return cache ? cache[key] : null;
if (isDefined(key)) {
if (isObject(key)) {
if (!cacheId) element[jqName] = cacheId = jqNextId();
jqCache[cacheId] = cache = (jqCache[cacheId] || {});
extend(cache, key);
} else {
return cache ? cache[key] : undefined;
}
} else {
if (!cacheId) element[jqName] = cacheId = jqNextId();

return cache
? cache
: cache = jqCache[cacheId] = {};
}
}
}

Expand Down Expand Up @@ -452,10 +468,16 @@ forEach({
// in a way that survives minification.
if (((fn.length == 2 && (fn !== JQLiteHasClass && fn !== JQLiteController)) ? arg1 : arg2) === undefined) {
if (isObject(arg1)) {

// we are a write, but the object properties are the key/values
for(i=0; i < this.length; i++) {
for (key in arg1) {
fn(this[i], key, arg1[key]);
if (fn === JQLiteData) {
// data() takes the whole object in jQuery
fn(this[i], arg1);
} else {
for (key in arg1) {
fn(this[i], key, arg1[key]);
}
}
}
// return self for chaining
Expand Down
Loading