Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for custom change types #12

Merged
merged 3 commits into from
Jun 1, 2012
Merged
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
22 changes: 15 additions & 7 deletions src/ice.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,21 @@ InlineChangeEditor.prototype = {
body.appendChild(ice.dom.create('<' + this.blockEl + ' ><br/></' + 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);
Expand Down Expand Up @@ -485,11 +489,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 = {
tag: tag,
alias: alias
};

if (action) changeType.action = action;

this.changeTypes[typeName] = changeType;
},

/**
Expand Down