Skip to content

Commit

Permalink
Updated plugin to allow disable/enable buttons
Browse files Browse the repository at this point in the history
Updated to allow actions to disable/enable buttons using TinyMCE4.

Also added a couple menu items for accept and reject.
  • Loading branch information
danransom committed Aug 21, 2013
1 parent 59d022b commit 92c3cf4
Showing 1 changed file with 107 additions and 20 deletions.
127 changes: 107 additions & 20 deletions lib/tinymce/jscripts/tinymce4/plugins/ice/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
afterClean: function(body) { return body; },
beforePasteClean: function(body) { return body; },
afterPasteClean: function(body) { return body; },
//buttons to activate/deactivate
trackChangesButton: function () { },
showChangesButton: function () { },
acceptButton: function () { },
rejectButton: function () { },
acceptAllButton: function () { },
rejectAllButton: function () { },

/**
* Plugin initialization - register buttons, commands, and take care of setup.
Expand Down Expand Up @@ -276,17 +283,21 @@
var body = ed.getBody(), cm = ed.controlManager, disabled = true;

if(ed.dom.hasClass(body,'CT-hide')) {
//cm.setActive('ice_toggleshowchanges', true);
//activate show changes button
ed.plugins.ice.showChangesButton.active(true);
ed.dom.removeClass(body, 'CT-hide');
disabled = false;
} else {
//cm.setActive('ice_toggleshowchanges', false);
//deactivate show changes button
ed.plugins.ice.showChangesButton.active(false);
ed.dom.addClass(body, 'CT-hide');
}

tinymce.each(['iceacceptall','icerejectall'], function(button){
//cm.setDisabled(button, disabled);
});
//toggle button disabling
ed.plugins.ice.acceptAllButton.disabled(disabled);
ed.plugins.ice.rejectAllButton.disabled(disabled);
ed.plugins.ice.acceptButton.disabled(disabled);
ed.plugins.ice.rejectButton.disabled(disabled);

ed.execCommand('mceRepaint');
});
Expand Down Expand Up @@ -315,7 +326,10 @@
*/
ed.addCommand('ice_enable', function() {
changeEditor.enableChangeTracking();
//ed.controlManager.setActive('ice_togglechanges', true);
//toggle buttons and call show changes
ed.plugins.ice.trackChangesButton.active(true);
ed.plugins.ice.showChangesButton.disabled(false);
ed.execCommand('ice_toggleshowchanges');
self.isTracking = true;
});

Expand All @@ -324,8 +338,17 @@
* or act on events.
*/
ed.addCommand('ice_disable', function() {
//hide changes and toggle buttons
var body = ed.getBody();
ed.dom.addClass(body, 'CT-hide');
ed.plugins.ice.trackChangesButton.active(false);
ed.plugins.ice.showChangesButton.active(false);
ed.plugins.ice.showChangesButton.disabled(true);
ed.plugins.ice.acceptAllButton.disabled(true);
ed.plugins.ice.rejectAllButton.disabled(true);
ed.plugins.ice.acceptButton.disabled(true);
ed.plugins.ice.rejectButton.disabled(true);
changeEditor.disableChangeTracking();
//ed.controlManager.setActive('ice_togglechanges', false);
self.isTracking = false;
});

Expand Down Expand Up @@ -365,31 +388,76 @@
ed.addButton('iceaccept', {
title : 'Accept Change',
image : url + '/img/accept.gif',
cmd : 'iceaccept'
cmd : 'iceaccept',
onPostRender: function () { //assigns button and changes disabled status on node change
var self = this;
ed.plugins.ice.acceptButton = self;
ed.plugins.ice.acceptButton.disabled = self.disabled;

ed.on('NodeChange', function (e) {
if (isInsideChangeTag(e.element)) {
self.disabled(false);
} else {
self.disabled(true);
}
});
}
});

ed.addButton('icereject', {
title : 'Reject Change',
image : url + '/img/reject.gif',
cmd : 'icereject'
cmd : 'icereject',
onPostRender: function () {//assigns button and changes disabled status on node change
var self = this;
ed.plugins.ice.rejectButton = self;
ed.plugins.ice.rejectButton.disabled = self.disabled;

ed.on('NodeChange', function (e) {
if (isInsideChangeTag(e.element)) {
self.disabled(false);
} else {
self.disabled(true);
}
});
}
});

ed.addButton('iceacceptall', {
title : 'Accept All Changes',
image : url + '/img/ice-accept.png',
cmd : 'iceacceptall'
cmd : 'iceacceptall',
onPostRender: function () { //assigns button
var self = this;
ed.plugins.ice.acceptAllButton = self;
ed.plugins.ice.acceptAllButton.disabled = self.disabled;
}
});

ed.addButton('icerejectall', {
title : 'Reject All Changes',
image : url + '/img/ice-reject.png',
cmd : 'icerejectall'
cmd : 'icerejectall',
onPostRender: function () { //assigns button
var self = this;
ed.plugins.ice.rejectAllButton = self;
ed.plugins.ice.rejectAllButton.disabled = self.disabled;
}
});

ed.addButton('ice_toggleshowchanges', {
title : 'Show/Hide Track Changes',
image : url + '/img/ice-showchanges.png',
cmd : 'ice_toggleshowchanges'
onclick: function () {
ed.fire('ice_toggleshowchanges');
ed.execCommand('ice_toggleshowchanges');
},
onPostRender: function () { //assigns button
var self = this;
ed.plugins.ice.showChangesButton = self;
ed.plugins.ice.showChangesButton.disabled = self.disabled;
ed.plugins.ice.showChangesButton.active = self.active;
}
});

ed.addButton('ice_smartquotes', {
Expand All @@ -401,9 +469,35 @@
ed.addButton('ice_togglechanges', {
title : 'Turn On Track Changes ',
image : url + '/img/ice-togglechanges.png',
cmd : 'ice_togglechanges'
cmd : 'ice_togglechanges',
onPostRender: function () { //assigns button
var self = this;
ed.plugins.ice.trackChangesButton = self;
ed.plugins.ice.trackChangesButton.disabled = self.disabled;
ed.plugins.ice.trackChangesButton.active = self.active;
}
});

ed.addMenuItem('iceaccept', {
icon: 'accept',
text: 'Accept Change',
onclick: function () {
ed.execCommand('iceaccept');
},
context: 'tools',
prependToContext: true
});

ed.addMenuItem('icereject', {
icon: 'reject',
text: 'Reject Change',
onclick: function () {
ed.execCommand('icereject');
},
context: 'tools',
prependToContext: true
});

if(ed.plugins.contextmenu) {
ed.plugins.contextmenu.onContextMenu.add(function(th, menu, node) {
if(isInsideChangeTag(node)) {
Expand All @@ -425,13 +519,6 @@
* Node Change event - watch for node changes and toggle buttons.
*/
ed.on('NodeChange',function(e) {
if (isInsideChangeTag(e.element)) {
//cm.setDisabled('iceaccept', false);
//cm.setDisabled('icereject', false);
} else {
//cm.setDisabled('iceaccept', true);
//cm.setDisabled('icereject', true);
}
cleanup();
});

Expand Down

0 comments on commit 92c3cf4

Please sign in to comment.