mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
pad_editbar: Convert registerDefaultCommands()
into a method
This commit is contained in:
parent
0d4f147349
commit
4b4eef5f4a
1 changed files with 104 additions and 107 deletions
|
@ -125,7 +125,7 @@ const padeditbar = (() => {
|
||||||
};
|
};
|
||||||
const syncAnimation = syncAnimationFn();
|
const syncAnimation = syncAnimationFn();
|
||||||
|
|
||||||
const self = {
|
return {
|
||||||
_editbarPosition: 0,
|
_editbarPosition: 0,
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -150,7 +150,7 @@ const padeditbar = (() => {
|
||||||
this.checkAllIconsAreDisplayedInToolbar();
|
this.checkAllIconsAreDisplayedInToolbar();
|
||||||
$(window).resize(_.debounce(() => this.checkAllIconsAreDisplayedInToolbar(), 100));
|
$(window).resize(_.debounce(() => this.checkAllIconsAreDisplayedInToolbar(), 100));
|
||||||
|
|
||||||
registerDefaultCommands(this);
|
this._registerDefaultCommands();
|
||||||
|
|
||||||
hooks.callAll('postToolbarInit', {
|
hooks.callAll('postToolbarInit', {
|
||||||
toolbar: this,
|
toolbar: this,
|
||||||
|
@ -356,136 +356,133 @@ const padeditbar = (() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
|
||||||
|
|
||||||
const aceAttributeCommand = (cmd, ace) => {
|
_registerDefaultCommands() {
|
||||||
ace.ace_toggleAttributeOnSelection(cmd);
|
this.registerDropdownCommand('showusers', 'users');
|
||||||
};
|
this.registerDropdownCommand('settings');
|
||||||
|
this.registerDropdownCommand('connectivity');
|
||||||
|
this.registerDropdownCommand('import_export');
|
||||||
|
this.registerDropdownCommand('embed');
|
||||||
|
|
||||||
const registerDefaultCommands = (toolbar) => {
|
this.registerCommand('settings', () => {
|
||||||
toolbar.registerDropdownCommand('showusers', 'users');
|
this.toggleDropDown('settings', () => {
|
||||||
toolbar.registerDropdownCommand('settings');
|
$('#options-stickychat').focus();
|
||||||
toolbar.registerDropdownCommand('connectivity');
|
});
|
||||||
toolbar.registerDropdownCommand('import_export');
|
|
||||||
toolbar.registerDropdownCommand('embed');
|
|
||||||
|
|
||||||
toolbar.registerCommand('settings', () => {
|
|
||||||
toolbar.toggleDropDown('settings', () => {
|
|
||||||
$('#options-stickychat').focus();
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
toolbar.registerCommand('import_export', () => {
|
this.registerCommand('import_export', () => {
|
||||||
toolbar.toggleDropDown('import_export', () => {
|
this.toggleDropDown('import_export', () => {
|
||||||
// If Import file input exists then focus on it..
|
// If Import file input exists then focus on it..
|
||||||
if ($('#importfileinput').length !== 0) {
|
if ($('#importfileinput').length !== 0) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$('#importfileinput').focus();
|
$('#importfileinput').focus();
|
||||||
}, 100);
|
}, 100);
|
||||||
} else {
|
} else {
|
||||||
$('.exportlink').first().focus();
|
$('.exportlink').first().focus();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
toolbar.registerCommand('showusers', () => {
|
this.registerCommand('showusers', () => {
|
||||||
toolbar.toggleDropDown('users', () => {
|
this.toggleDropDown('users', () => {
|
||||||
$('#myusernameedit').focus();
|
$('#myusernameedit').focus();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
toolbar.registerCommand('embed', () => {
|
this.registerCommand('embed', () => {
|
||||||
toolbar.setEmbedLinks();
|
this.setEmbedLinks();
|
||||||
toolbar.toggleDropDown('embed', () => {
|
this.toggleDropDown('embed', () => {
|
||||||
$('#linkinput').focus().select();
|
$('#linkinput').focus().select();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
toolbar.registerCommand('savedRevision', () => {
|
this.registerCommand('savedRevision', () => {
|
||||||
padsavedrevs.saveNow();
|
padsavedrevs.saveNow();
|
||||||
});
|
});
|
||||||
|
|
||||||
toolbar.registerCommand('showTimeSlider', () => {
|
this.registerCommand('showTimeSlider', () => {
|
||||||
document.location = `${document.location.pathname}/timeslider`;
|
document.location = `${document.location.pathname}/timeslider`;
|
||||||
});
|
});
|
||||||
|
|
||||||
toolbar.registerAceCommand('bold', aceAttributeCommand);
|
const aceAttributeCommand = (cmd, ace) => {
|
||||||
toolbar.registerAceCommand('italic', aceAttributeCommand);
|
ace.ace_toggleAttributeOnSelection(cmd);
|
||||||
toolbar.registerAceCommand('underline', aceAttributeCommand);
|
};
|
||||||
toolbar.registerAceCommand('strikethrough', aceAttributeCommand);
|
this.registerAceCommand('bold', aceAttributeCommand);
|
||||||
|
this.registerAceCommand('italic', aceAttributeCommand);
|
||||||
|
this.registerAceCommand('underline', aceAttributeCommand);
|
||||||
|
this.registerAceCommand('strikethrough', aceAttributeCommand);
|
||||||
|
|
||||||
toolbar.registerAceCommand('undo', (cmd, ace) => {
|
this.registerAceCommand('undo', (cmd, ace) => {
|
||||||
ace.ace_doUndoRedo(cmd);
|
ace.ace_doUndoRedo(cmd);
|
||||||
});
|
});
|
||||||
|
|
||||||
toolbar.registerAceCommand('redo', (cmd, ace) => {
|
this.registerAceCommand('redo', (cmd, ace) => {
|
||||||
ace.ace_doUndoRedo(cmd);
|
ace.ace_doUndoRedo(cmd);
|
||||||
});
|
});
|
||||||
|
|
||||||
toolbar.registerAceCommand('insertunorderedlist', (cmd, ace) => {
|
this.registerAceCommand('insertunorderedlist', (cmd, ace) => {
|
||||||
ace.ace_doInsertUnorderedList();
|
|
||||||
});
|
|
||||||
|
|
||||||
toolbar.registerAceCommand('insertorderedlist', (cmd, ace) => {
|
|
||||||
ace.ace_doInsertOrderedList();
|
|
||||||
});
|
|
||||||
|
|
||||||
toolbar.registerAceCommand('indent', (cmd, ace) => {
|
|
||||||
if (!ace.ace_doIndentOutdent(false)) {
|
|
||||||
ace.ace_doInsertUnorderedList();
|
ace.ace_doInsertUnorderedList();
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
toolbar.registerAceCommand('outdent', (cmd, ace) => {
|
this.registerAceCommand('insertorderedlist', (cmd, ace) => {
|
||||||
ace.ace_doIndentOutdent(true);
|
ace.ace_doInsertOrderedList();
|
||||||
});
|
});
|
||||||
|
|
||||||
toolbar.registerAceCommand('clearauthorship', (cmd, ace) => {
|
this.registerAceCommand('indent', (cmd, ace) => {
|
||||||
// If we have the whole document selected IE control A has been hit
|
if (!ace.ace_doIndentOutdent(false)) {
|
||||||
const rep = ace.ace_getRep();
|
ace.ace_doInsertUnorderedList();
|
||||||
let doPrompt = false;
|
|
||||||
const lastChar = rep.lines.atIndex(rep.lines.length() - 1).width - 1;
|
|
||||||
const lastLineIndex = rep.lines.length() - 1;
|
|
||||||
if (rep.selStart[0] === 0 && rep.selStart[1] === 0) {
|
|
||||||
// nesting intentionally here to make things readable
|
|
||||||
if (rep.selEnd[0] === lastLineIndex && rep.selEnd[1] === lastChar) {
|
|
||||||
doPrompt = true;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
/*
|
|
||||||
* NOTICE: This command isn't fired on Control Shift C.
|
|
||||||
* I intentionally didn't create duplicate code because if you are hitting
|
|
||||||
* Control Shift C we make the assumption you are a "power user"
|
|
||||||
* and as such we assume you don't need the prompt to bug you each time!
|
|
||||||
* This does make wonder if it's worth having a checkbox to avoid being
|
|
||||||
* prompted again but that's probably overkill for this contribution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// if we don't have any text selected, we have a caret or we have already said to prompt
|
this.registerAceCommand('outdent', (cmd, ace) => {
|
||||||
if ((!(rep.selStart && rep.selEnd)) || ace.ace_isCaret() || doPrompt) {
|
ace.ace_doIndentOutdent(true);
|
||||||
if (window.confirm(html10n.get('pad.editbar.clearcolors'))) {
|
});
|
||||||
ace.ace_performDocumentApplyAttributesToCharRange(0, ace.ace_getRep().alltext.length, [
|
|
||||||
['author', ''],
|
this.registerAceCommand('clearauthorship', (cmd, ace) => {
|
||||||
]);
|
// If we have the whole document selected IE control A has been hit
|
||||||
|
const rep = ace.ace_getRep();
|
||||||
|
let doPrompt = false;
|
||||||
|
const lastChar = rep.lines.atIndex(rep.lines.length() - 1).width - 1;
|
||||||
|
const lastLineIndex = rep.lines.length() - 1;
|
||||||
|
if (rep.selStart[0] === 0 && rep.selStart[1] === 0) {
|
||||||
|
// nesting intentionally here to make things readable
|
||||||
|
if (rep.selEnd[0] === lastLineIndex && rep.selEnd[1] === lastChar) {
|
||||||
|
doPrompt = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
/*
|
||||||
ace.ace_setAttributeOnSelection('author', '');
|
* NOTICE: This command isn't fired on Control Shift C.
|
||||||
}
|
* I intentionally didn't create duplicate code because if you are hitting
|
||||||
});
|
* Control Shift C we make the assumption you are a "power user"
|
||||||
|
* and as such we assume you don't need the prompt to bug you each time!
|
||||||
|
* This does make wonder if it's worth having a checkbox to avoid being
|
||||||
|
* prompted again but that's probably overkill for this contribution.
|
||||||
|
*/
|
||||||
|
|
||||||
toolbar.registerCommand('timeslider_returnToPad', (cmd) => {
|
// if we don't have any text selected, we have a caret or we have already said to prompt
|
||||||
if (document.referrer.length > 0 &&
|
if ((!(rep.selStart && rep.selEnd)) || ace.ace_isCaret() || doPrompt) {
|
||||||
|
if (window.confirm(html10n.get('pad.editbar.clearcolors'))) {
|
||||||
|
ace.ace_performDocumentApplyAttributesToCharRange(0, ace.ace_getRep().alltext.length, [
|
||||||
|
['author', ''],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ace.ace_setAttributeOnSelection('author', '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.registerCommand('timeslider_returnToPad', (cmd) => {
|
||||||
|
if (document.referrer.length > 0 &&
|
||||||
document.referrer.substring(document.referrer.lastIndexOf('/') - 1,
|
document.referrer.substring(document.referrer.lastIndexOf('/') - 1,
|
||||||
document.referrer.lastIndexOf('/')) === 'p') {
|
document.referrer.lastIndexOf('/')) === 'p') {
|
||||||
document.location = document.referrer;
|
document.location = document.referrer;
|
||||||
} else {
|
} else {
|
||||||
document.location = document.location.href
|
document.location = document.location.href
|
||||||
.substring(0, document.location.href.lastIndexOf('/'));
|
.substring(0, document.location.href.lastIndexOf('/'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
exports.padeditbar = padeditbar;
|
exports.padeditbar = padeditbar;
|
||||||
|
|
Loading…
Reference in a new issue