Skip to content

Commit

Permalink
Specify titleDateFormat when initialising ice, add option whether to …
Browse files Browse the repository at this point in the history
…selectdummycharacter when bubbling event from ice to browser, add delete key constant to dom.js
  • Loading branch information
Patrick Craston committed Jun 8, 2015
1 parent ad3025f commit fe8381a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
dom = {};

dom.DOM_VK_DELETE = 8;
dom.DOM_VK_DELETE_KEY = 46;
dom.DOM_VK_LEFT = 37;
dom.DOM_VK_UP = 38;
dom.DOM_VK_RIGHT = 39;
Expand Down
24 changes: 22 additions & 2 deletions src/ice.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
userNameAttribute: 'data-username',
timeAttribute: 'data-time',

// date format for changes popup title attribute
titleDateFormat: 'm/d/Y h:ia',

// setting this to true means that the dummy white space character that is inserted by ice
// is selected before the event bubbles up to the final handler.
// Issue in Chrome with tinyMCE:
// When the event bubbles up to tinyMCE, the selection gets removed which leaves
// the "insert" element empty. If the insert element is
// a non block element (like span or a custom element like insert), Chrome will delete it as soon
// as it is empty and before the content text can be inserted into the element. So ensure this variable
// is set to false for ice to work correctly. (TinyMCE removes the dummy whitespace character anyway)
selectDummyCharacter: false,

// Prepended to `changeType.alias` for classname uniqueness, if needed
attrValuePrefix: '',

Expand Down Expand Up @@ -912,13 +925,21 @@
range.insertNode(node);
range.setEnd(node, 1);

/*
Always collapse the range if selectDummyCharacter is false, otherwise select it.
See comment where selectDummyCharacter is defined
*/
if (self.selectDummyCharacter) {
if (insertingDummy) {
// Create a selection of the dummy character we inserted
// which will be removed after it bubbles up to the final handler.
range.setStart(node, 0);
} else {
range.collapse();
}
} else {
range.collapse();
}

this.selection.addRange(range);
},
Expand Down Expand Up @@ -1464,8 +1485,7 @@
preventDefault = this.deleteContents();
this.pluginsManager.fireKeyPressed(e);
break;
case 46:
// Key 46 is the DELETE key.
case ice.dom.DOM_VK_DELETE_KEY:
preventDefault = this.deleteContents(true);
this.pluginsManager.fireKeyPressed(e);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/IceAddTitlePlugin/IceAddTitlePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ IceAddTitlePlugin = function(ice_instance) {
IceAddTitlePlugin.prototype = {
nodeCreated: function(node, option) {
node.setAttribute('title', (option.action || 'Modified') + ' by ' + node.getAttribute(this._ice.userNameAttribute)
+ ' - ' + ice.dom.date('m/d/Y h:ia', parseInt(node.getAttribute(this._ice.timeAttribute))));
+ ' - ' + ice.dom.date(this._ice.titleDateFormat, parseInt(node.getAttribute(this._ice.timeAttribute))));
}
};

Expand Down

0 comments on commit fe8381a

Please sign in to comment.