mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
Add option to make button toggleable
This commit is contained in:
parent
67246f8c80
commit
a5c24aaca0
1 changed files with 15 additions and 3 deletions
|
@ -125,6 +125,14 @@ function updateButtonState() {
|
||||||
// 'col': document.queryCommandValue("forecolor")
|
// 'col': document.queryCommandValue("forecolor")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function toggleEditorButton(buttonid) {
|
||||||
|
if ($(buttonid).hasClass("highlighted")) {
|
||||||
|
$(buttonid).removeClass("highlighted");
|
||||||
|
} else {
|
||||||
|
$(buttonid).addClass("highlighted");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function setFormat(cmd, arg, nosave) {
|
function setFormat(cmd, arg, nosave) {
|
||||||
document.execCommand(cmd, false, arg);
|
document.execCommand(cmd, false, arg);
|
||||||
if (!nosave) {
|
if (!nosave) {
|
||||||
|
@ -486,7 +494,7 @@ class Editor(object):
|
||||||
data64 = b''.join(base64.encodestring(data).splitlines())
|
data64 = b''.join(base64.encodestring(data).splitlines())
|
||||||
return 'data:%s;base64,%s' % (mime, data64.decode('ascii'))
|
return 'data:%s;base64,%s' % (mime, data64.decode('ascii'))
|
||||||
|
|
||||||
def _addButton(self, icon, cmd, tip="", id=None):
|
def _addButton(self, icon, cmd, tip="", id=None, toggleable=False):
|
||||||
if os.path.isabs(icon):
|
if os.path.isabs(icon):
|
||||||
iconstr = self.resourceToData(icon)
|
iconstr = self.resourceToData(icon)
|
||||||
else:
|
else:
|
||||||
|
@ -495,8 +503,12 @@ class Editor(object):
|
||||||
idstr = 'id={}'.format(id)
|
idstr = 'id={}'.format(id)
|
||||||
else:
|
else:
|
||||||
idstr = ""
|
idstr = ""
|
||||||
return '''<button tabindex=-1 {id} class=linkb type="button" title="{tip}" onclick="pycmd('{cmd}');return false;">
|
if toggleable:
|
||||||
<img class=topbut src="{icon}"></button>'''.format(icon=iconstr, cmd=cmd, tip=_(tip), id=idstr)
|
toggleScript = 'toggleEditorButton(this);'
|
||||||
|
else:
|
||||||
|
toggleScript = ''
|
||||||
|
return '''<button tabindex=-1 {id} class=linkb type="button" title="{tip}" onclick="pycmd('{cmd}');{togglesc}return false;">
|
||||||
|
<img class=topbut src="{icon}"></button>'''.format(icon=iconstr, cmd=cmd, tip=_(tip), id=idstr, togglesc=toggleScript)
|
||||||
|
|
||||||
def setupShortcuts(self):
|
def setupShortcuts(self):
|
||||||
cuts = [
|
cuts = [
|
||||||
|
|
Loading…
Reference in a new issue