From f0e4f7fccdca937225c2e5f3e0c1d765f6892cdd Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Mon, 5 Mar 2012 21:05:29 -0500 Subject: [PATCH 1/3] allowing actions to be defined for new changeTypes --- src/ice.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ice.js b/src/ice.js index 9c9e7eb9..a1bf0649 100644 --- a/src/ice.js +++ b/src/ice.js @@ -485,11 +485,15 @@ InlineChangeEditor.prototype = { /** * Add a new change tracking typeName with the given tag and alias. */ - addChangeType: function(typeName, tag, alias) { - this.changeTypes[typeName] = { + addChangeType: function(typeName, tag, alias, action) { + var changeType = this.changeTypes[typeName]; + + changeType = { tag: tag, alias: alias }; + + if (action) changeType.action = action; }, /** From f16b8e1500edb5f7fa3e3496ab423eb228fb0621 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Mon, 5 Mar 2012 21:09:36 -0500 Subject: [PATCH 2/3] fixing bug with changeTypes array --- src/ice.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ice.js b/src/ice.js index a1bf0649..70d57cfa 100644 --- a/src/ice.js +++ b/src/ice.js @@ -486,14 +486,14 @@ InlineChangeEditor.prototype = { * Add a new change tracking typeName with the given tag and alias. */ addChangeType: function(typeName, tag, alias, action) { - var changeType = this.changeTypes[typeName]; - - changeType = { + var changeType = { tag: tag, alias: alias }; if (action) changeType.action = action; + + this.changeTypes[typeName] = changeType; }, /** From a0e9ed2afd5e8e9ef87c8a90f30a4736ebc99ca9 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Mon, 5 Mar 2012 21:35:10 -0500 Subject: [PATCH 3/3] recognize custom change types on initialization --- src/ice.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ice.js b/src/ice.js index 70d57cfa..43728704 100644 --- a/src/ice.js +++ b/src/ice.js @@ -139,17 +139,21 @@ InlineChangeEditor.prototype = { body.appendChild(ice.dom.create('<' + this.blockEl + ' >
')); } this.element.innerHTML = body.innerHTML; - - // Find and load all of the changes and users/styles, present in the element. - var ins = this._getIceNodeClass('insertType'), del = this._getIceNodeClass('deleteType'); - ice.dom.each(ice.dom.find(this.element, '.'+ins+','+'.'+del), function(i, el) { + + // Grab class for each changeType + var changeTypeClasses = new Array(); + for (var changeType in this.changeTypes) { + changeTypeClasses.push(this._getIceNodeClass(changeType)); + } + + ice.dom.each(ice.dom.find(this.element, '.'+changeTypeClasses.join(', .')), function(i, el) { var styleIndex = 0; var ctnType = ''; var classList = el.className.split(' '); for(var i = 0; i < classList.length; i++) { var styleReg = new RegExp(self.stylePrefix + '-(\\d+)').exec(classList[i]); if(styleReg) styleIndex = styleReg[1]; - var ctnReg = new RegExp('('+ins+'|'+del+')').exec(classList[i]); + var ctnReg = new RegExp('('+changeTypeClasses.join('|')+')').exec(classList[i]); if(ctnReg) ctnType = self._getChangeTypeFromAlias(ctnReg[1]); } var userid = ice.dom.attr(el, self.userIdAttribute);